diff --git a/BetterSecondBot.sln b/BetterSecondBot.sln index 7ff6317..f21e3c4 100644 --- a/BetterSecondBot.sln +++ b/BetterSecondBot.sln @@ -5,8 +5,6 @@ VisualStudioVersion = 17.1.32228.430 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Secondbot", "Secondbot", "{4388BA41-F3FC-4A0E-AA00-50E9ED45A027}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Metaverse", "Metaverse", "{E9B97D05-D5FB-4CA9-99C3-839248621C21}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Project Items", "Project Items", "{C343303B-F9BF-46B3-BBB5-5596823EC71C}" ProjectSection(SolutionItems) = preProject .gitignore = .gitignore @@ -21,13 +19,15 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Core", "Core\Core.csproj", EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BetterSecondbot", "BetterSecondbot\BetterSecondbot.csproj", "{452CA177-FFD1-4248-93C0-09AFF1060E34}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LibreMetaverse", "LibreMetaverse\LibreMetaverse.csproj", "{27C70F3A-0000-0000-0000-000000000000}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SecondBotEvents", "SecondBotEvents\SecondBotEvents.csproj", "{571AB1AF-4C74-4C37-AC5B-9B63383AC791}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LibreMetaverse.StructuredData", "LibreMetaverse.StructuredData\LibreMetaverse.StructuredData.csproj", "{89D7A3E5-0000-0000-0000-000000000000}" +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Meta", "Meta", "{EB0A1951-FA28-4D7C-9550-EB0724D3612D}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LibreMetaverse.Types", "LibreMetaverse.Types\LibreMetaverse.Types.csproj", "{B37B02AD-0000-0000-0000-000000000000}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LibreMetaverse", "LibreMetaverse\LibreMetaverse.csproj", "{19773905-4530-444E-A51D-00C210C2A807}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SecondBotEvents", "SecondBotEvents\SecondBotEvents.csproj", "{571AB1AF-4C74-4C37-AC5B-9B63383AC791}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LibreMetaverse.Types", "LibreMetaverse.Types\LibreMetaverse.Types.csproj", "{1E51D4CA-564A-4EF5-AD7A-5FCD4BD065D0}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LibreMetaverse.StructuredData", "LibreMetaverse.StructuredData\LibreMetaverse.StructuredData.csproj", "{82CF657E-0AA9-43C3-A19C-3617A643251F}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -96,60 +96,6 @@ Global {452CA177-FFD1-4248-93C0-09AFF1060E34}.Release|x64.Build.0 = Release|Any CPU {452CA177-FFD1-4248-93C0-09AFF1060E34}.Release|x86.ActiveCfg = Release|Any CPU {452CA177-FFD1-4248-93C0-09AFF1060E34}.Release|x86.Build.0 = Release|Any CPU - {27C70F3A-0000-0000-0000-000000000000}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {27C70F3A-0000-0000-0000-000000000000}.Debug|Any CPU.Build.0 = Debug|Any CPU - {27C70F3A-0000-0000-0000-000000000000}.Debug|x64.ActiveCfg = Debug|x64 - {27C70F3A-0000-0000-0000-000000000000}.Debug|x64.Build.0 = Debug|x64 - {27C70F3A-0000-0000-0000-000000000000}.Debug|x86.ActiveCfg = Debug|x86 - {27C70F3A-0000-0000-0000-000000000000}.Debug|x86.Build.0 = Debug|x86 - {27C70F3A-0000-0000-0000-000000000000}.DockerBuild|Any CPU.ActiveCfg = Debug|Any CPU - {27C70F3A-0000-0000-0000-000000000000}.DockerBuild|Any CPU.Build.0 = Debug|Any CPU - {27C70F3A-0000-0000-0000-000000000000}.DockerBuild|x64.ActiveCfg = Debug|x64 - {27C70F3A-0000-0000-0000-000000000000}.DockerBuild|x64.Build.0 = Debug|x64 - {27C70F3A-0000-0000-0000-000000000000}.DockerBuild|x86.ActiveCfg = Debug|x86 - {27C70F3A-0000-0000-0000-000000000000}.DockerBuild|x86.Build.0 = Debug|x86 - {27C70F3A-0000-0000-0000-000000000000}.Release|Any CPU.ActiveCfg = Release|Any CPU - {27C70F3A-0000-0000-0000-000000000000}.Release|Any CPU.Build.0 = Release|Any CPU - {27C70F3A-0000-0000-0000-000000000000}.Release|x64.ActiveCfg = Release|x64 - {27C70F3A-0000-0000-0000-000000000000}.Release|x64.Build.0 = Release|x64 - {27C70F3A-0000-0000-0000-000000000000}.Release|x86.ActiveCfg = Release|x86 - {27C70F3A-0000-0000-0000-000000000000}.Release|x86.Build.0 = Release|x86 - {89D7A3E5-0000-0000-0000-000000000000}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {89D7A3E5-0000-0000-0000-000000000000}.Debug|Any CPU.Build.0 = Debug|Any CPU - {89D7A3E5-0000-0000-0000-000000000000}.Debug|x64.ActiveCfg = Debug|x64 - {89D7A3E5-0000-0000-0000-000000000000}.Debug|x64.Build.0 = Debug|x64 - {89D7A3E5-0000-0000-0000-000000000000}.Debug|x86.ActiveCfg = Debug|x86 - {89D7A3E5-0000-0000-0000-000000000000}.Debug|x86.Build.0 = Debug|x86 - {89D7A3E5-0000-0000-0000-000000000000}.DockerBuild|Any CPU.ActiveCfg = Debug|Any CPU - {89D7A3E5-0000-0000-0000-000000000000}.DockerBuild|Any CPU.Build.0 = Debug|Any CPU - {89D7A3E5-0000-0000-0000-000000000000}.DockerBuild|x64.ActiveCfg = Debug|x64 - {89D7A3E5-0000-0000-0000-000000000000}.DockerBuild|x64.Build.0 = Debug|x64 - {89D7A3E5-0000-0000-0000-000000000000}.DockerBuild|x86.ActiveCfg = Debug|x86 - {89D7A3E5-0000-0000-0000-000000000000}.DockerBuild|x86.Build.0 = Debug|x86 - {89D7A3E5-0000-0000-0000-000000000000}.Release|Any CPU.ActiveCfg = Release|Any CPU - {89D7A3E5-0000-0000-0000-000000000000}.Release|Any CPU.Build.0 = Release|Any CPU - {89D7A3E5-0000-0000-0000-000000000000}.Release|x64.ActiveCfg = Release|x64 - {89D7A3E5-0000-0000-0000-000000000000}.Release|x64.Build.0 = Release|x64 - {89D7A3E5-0000-0000-0000-000000000000}.Release|x86.ActiveCfg = Release|x86 - {89D7A3E5-0000-0000-0000-000000000000}.Release|x86.Build.0 = Release|x86 - {B37B02AD-0000-0000-0000-000000000000}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {B37B02AD-0000-0000-0000-000000000000}.Debug|Any CPU.Build.0 = Debug|Any CPU - {B37B02AD-0000-0000-0000-000000000000}.Debug|x64.ActiveCfg = Debug|x64 - {B37B02AD-0000-0000-0000-000000000000}.Debug|x64.Build.0 = Debug|x64 - {B37B02AD-0000-0000-0000-000000000000}.Debug|x86.ActiveCfg = Debug|x86 - {B37B02AD-0000-0000-0000-000000000000}.Debug|x86.Build.0 = Debug|x86 - {B37B02AD-0000-0000-0000-000000000000}.DockerBuild|Any CPU.ActiveCfg = Debug|Any CPU - {B37B02AD-0000-0000-0000-000000000000}.DockerBuild|Any CPU.Build.0 = Debug|Any CPU - {B37B02AD-0000-0000-0000-000000000000}.DockerBuild|x64.ActiveCfg = Debug|x64 - {B37B02AD-0000-0000-0000-000000000000}.DockerBuild|x64.Build.0 = Debug|x64 - {B37B02AD-0000-0000-0000-000000000000}.DockerBuild|x86.ActiveCfg = Debug|x86 - {B37B02AD-0000-0000-0000-000000000000}.DockerBuild|x86.Build.0 = Debug|x86 - {B37B02AD-0000-0000-0000-000000000000}.Release|Any CPU.ActiveCfg = Release|Any CPU - {B37B02AD-0000-0000-0000-000000000000}.Release|Any CPU.Build.0 = Release|Any CPU - {B37B02AD-0000-0000-0000-000000000000}.Release|x64.ActiveCfg = Release|x64 - {B37B02AD-0000-0000-0000-000000000000}.Release|x64.Build.0 = Release|x64 - {B37B02AD-0000-0000-0000-000000000000}.Release|x86.ActiveCfg = Release|x86 - {B37B02AD-0000-0000-0000-000000000000}.Release|x86.Build.0 = Release|x86 {571AB1AF-4C74-4C37-AC5B-9B63383AC791}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {571AB1AF-4C74-4C37-AC5B-9B63383AC791}.Debug|Any CPU.Build.0 = Debug|Any CPU {571AB1AF-4C74-4C37-AC5B-9B63383AC791}.Debug|x64.ActiveCfg = Debug|Any CPU @@ -168,6 +114,60 @@ Global {571AB1AF-4C74-4C37-AC5B-9B63383AC791}.Release|x64.Build.0 = Release|Any CPU {571AB1AF-4C74-4C37-AC5B-9B63383AC791}.Release|x86.ActiveCfg = Release|Any CPU {571AB1AF-4C74-4C37-AC5B-9B63383AC791}.Release|x86.Build.0 = Release|Any CPU + {19773905-4530-444E-A51D-00C210C2A807}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {19773905-4530-444E-A51D-00C210C2A807}.Debug|Any CPU.Build.0 = Debug|Any CPU + {19773905-4530-444E-A51D-00C210C2A807}.Debug|x64.ActiveCfg = Debug|x64 + {19773905-4530-444E-A51D-00C210C2A807}.Debug|x64.Build.0 = Debug|x64 + {19773905-4530-444E-A51D-00C210C2A807}.Debug|x86.ActiveCfg = Debug|x86 + {19773905-4530-444E-A51D-00C210C2A807}.Debug|x86.Build.0 = Debug|x86 + {19773905-4530-444E-A51D-00C210C2A807}.DockerBuild|Any CPU.ActiveCfg = Debug|Any CPU + {19773905-4530-444E-A51D-00C210C2A807}.DockerBuild|Any CPU.Build.0 = Debug|Any CPU + {19773905-4530-444E-A51D-00C210C2A807}.DockerBuild|x64.ActiveCfg = Debug|x64 + {19773905-4530-444E-A51D-00C210C2A807}.DockerBuild|x64.Build.0 = Debug|x64 + {19773905-4530-444E-A51D-00C210C2A807}.DockerBuild|x86.ActiveCfg = Debug|x86 + {19773905-4530-444E-A51D-00C210C2A807}.DockerBuild|x86.Build.0 = Debug|x86 + {19773905-4530-444E-A51D-00C210C2A807}.Release|Any CPU.ActiveCfg = Release|Any CPU + {19773905-4530-444E-A51D-00C210C2A807}.Release|Any CPU.Build.0 = Release|Any CPU + {19773905-4530-444E-A51D-00C210C2A807}.Release|x64.ActiveCfg = Release|x64 + {19773905-4530-444E-A51D-00C210C2A807}.Release|x64.Build.0 = Release|x64 + {19773905-4530-444E-A51D-00C210C2A807}.Release|x86.ActiveCfg = Release|x86 + {19773905-4530-444E-A51D-00C210C2A807}.Release|x86.Build.0 = Release|x86 + {1E51D4CA-564A-4EF5-AD7A-5FCD4BD065D0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1E51D4CA-564A-4EF5-AD7A-5FCD4BD065D0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1E51D4CA-564A-4EF5-AD7A-5FCD4BD065D0}.Debug|x64.ActiveCfg = Debug|x64 + {1E51D4CA-564A-4EF5-AD7A-5FCD4BD065D0}.Debug|x64.Build.0 = Debug|x64 + {1E51D4CA-564A-4EF5-AD7A-5FCD4BD065D0}.Debug|x86.ActiveCfg = Debug|x86 + {1E51D4CA-564A-4EF5-AD7A-5FCD4BD065D0}.Debug|x86.Build.0 = Debug|x86 + {1E51D4CA-564A-4EF5-AD7A-5FCD4BD065D0}.DockerBuild|Any CPU.ActiveCfg = Debug|Any CPU + {1E51D4CA-564A-4EF5-AD7A-5FCD4BD065D0}.DockerBuild|Any CPU.Build.0 = Debug|Any CPU + {1E51D4CA-564A-4EF5-AD7A-5FCD4BD065D0}.DockerBuild|x64.ActiveCfg = Debug|x64 + {1E51D4CA-564A-4EF5-AD7A-5FCD4BD065D0}.DockerBuild|x64.Build.0 = Debug|x64 + {1E51D4CA-564A-4EF5-AD7A-5FCD4BD065D0}.DockerBuild|x86.ActiveCfg = Debug|x86 + {1E51D4CA-564A-4EF5-AD7A-5FCD4BD065D0}.DockerBuild|x86.Build.0 = Debug|x86 + {1E51D4CA-564A-4EF5-AD7A-5FCD4BD065D0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1E51D4CA-564A-4EF5-AD7A-5FCD4BD065D0}.Release|Any CPU.Build.0 = Release|Any CPU + {1E51D4CA-564A-4EF5-AD7A-5FCD4BD065D0}.Release|x64.ActiveCfg = Release|x64 + {1E51D4CA-564A-4EF5-AD7A-5FCD4BD065D0}.Release|x64.Build.0 = Release|x64 + {1E51D4CA-564A-4EF5-AD7A-5FCD4BD065D0}.Release|x86.ActiveCfg = Release|x86 + {1E51D4CA-564A-4EF5-AD7A-5FCD4BD065D0}.Release|x86.Build.0 = Release|x86 + {82CF657E-0AA9-43C3-A19C-3617A643251F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {82CF657E-0AA9-43C3-A19C-3617A643251F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {82CF657E-0AA9-43C3-A19C-3617A643251F}.Debug|x64.ActiveCfg = Debug|x64 + {82CF657E-0AA9-43C3-A19C-3617A643251F}.Debug|x64.Build.0 = Debug|x64 + {82CF657E-0AA9-43C3-A19C-3617A643251F}.Debug|x86.ActiveCfg = Debug|x86 + {82CF657E-0AA9-43C3-A19C-3617A643251F}.Debug|x86.Build.0 = Debug|x86 + {82CF657E-0AA9-43C3-A19C-3617A643251F}.DockerBuild|Any CPU.ActiveCfg = Debug|Any CPU + {82CF657E-0AA9-43C3-A19C-3617A643251F}.DockerBuild|Any CPU.Build.0 = Debug|Any CPU + {82CF657E-0AA9-43C3-A19C-3617A643251F}.DockerBuild|x64.ActiveCfg = Debug|x64 + {82CF657E-0AA9-43C3-A19C-3617A643251F}.DockerBuild|x64.Build.0 = Debug|x64 + {82CF657E-0AA9-43C3-A19C-3617A643251F}.DockerBuild|x86.ActiveCfg = Debug|x86 + {82CF657E-0AA9-43C3-A19C-3617A643251F}.DockerBuild|x86.Build.0 = Debug|x86 + {82CF657E-0AA9-43C3-A19C-3617A643251F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {82CF657E-0AA9-43C3-A19C-3617A643251F}.Release|Any CPU.Build.0 = Release|Any CPU + {82CF657E-0AA9-43C3-A19C-3617A643251F}.Release|x64.ActiveCfg = Release|x64 + {82CF657E-0AA9-43C3-A19C-3617A643251F}.Release|x64.Build.0 = Release|x64 + {82CF657E-0AA9-43C3-A19C-3617A643251F}.Release|x86.ActiveCfg = Release|x86 + {82CF657E-0AA9-43C3-A19C-3617A643251F}.Release|x86.Build.0 = Release|x86 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -176,10 +176,10 @@ Global {554DA151-71C4-4C1D-97D5-F89F13D31299} = {4388BA41-F3FC-4A0E-AA00-50E9ED45A027} {BED23EA8-0E8F-4B4C-BFA4-74DFDFD05859} = {4388BA41-F3FC-4A0E-AA00-50E9ED45A027} {452CA177-FFD1-4248-93C0-09AFF1060E34} = {4388BA41-F3FC-4A0E-AA00-50E9ED45A027} - {27C70F3A-0000-0000-0000-000000000000} = {E9B97D05-D5FB-4CA9-99C3-839248621C21} - {89D7A3E5-0000-0000-0000-000000000000} = {E9B97D05-D5FB-4CA9-99C3-839248621C21} - {B37B02AD-0000-0000-0000-000000000000} = {E9B97D05-D5FB-4CA9-99C3-839248621C21} {571AB1AF-4C74-4C37-AC5B-9B63383AC791} = {4388BA41-F3FC-4A0E-AA00-50E9ED45A027} + {19773905-4530-444E-A51D-00C210C2A807} = {EB0A1951-FA28-4D7C-9550-EB0724D3612D} + {1E51D4CA-564A-4EF5-AD7A-5FCD4BD065D0} = {EB0A1951-FA28-4D7C-9550-EB0724D3612D} + {82CF657E-0AA9-43C3-A19C-3617A643251F} = {EB0A1951-FA28-4D7C-9550-EB0724D3612D} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {EC43F382-FAF2-49CC-8E23-5DDF87592DFA} diff --git a/BetterSecondbot/BetterSecondbot.csproj b/BetterSecondbot/BetterSecondbot.csproj index fe558ec..ff9bf97 100644 --- a/BetterSecondbot/BetterSecondbot.csproj +++ b/BetterSecondbot/BetterSecondbot.csproj @@ -53,294 +53,6 @@ Always - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - diff --git a/BetterSecondbot/openmetaverse_data/attentions.xml b/BetterSecondbot/openmetaverse_data/attentions.xml deleted file mode 100644 index be9a2b2..0000000 --- a/BetterSecondbot/openmetaverse_data/attentions.xml +++ /dev/null @@ -1,51 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/BetterSecondbot/openmetaverse_data/attentionsN.xml b/BetterSecondbot/openmetaverse_data/attentionsN.xml deleted file mode 100644 index e7d9bb6..0000000 --- a/BetterSecondbot/openmetaverse_data/attentionsN.xml +++ /dev/null @@ -1,51 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/BetterSecondbot/openmetaverse_data/aux_base.tga b/BetterSecondbot/openmetaverse_data/aux_base.tga deleted file mode 100644 index dbcaaaf..0000000 Binary files a/BetterSecondbot/openmetaverse_data/aux_base.tga and /dev/null differ diff --git a/BetterSecondbot/openmetaverse_data/avatar_eye.llm b/BetterSecondbot/openmetaverse_data/avatar_eye.llm deleted file mode 100644 index 8c6e74e..0000000 Binary files a/BetterSecondbot/openmetaverse_data/avatar_eye.llm and /dev/null differ diff --git a/BetterSecondbot/openmetaverse_data/avatar_eye_1.llm b/BetterSecondbot/openmetaverse_data/avatar_eye_1.llm deleted file mode 100644 index 7a3b0d6..0000000 Binary files a/BetterSecondbot/openmetaverse_data/avatar_eye_1.llm and /dev/null differ diff --git a/BetterSecondbot/openmetaverse_data/avatar_eyelashes.llm b/BetterSecondbot/openmetaverse_data/avatar_eyelashes.llm deleted file mode 100644 index 99995b5..0000000 Binary files a/BetterSecondbot/openmetaverse_data/avatar_eyelashes.llm and /dev/null differ diff --git a/BetterSecondbot/openmetaverse_data/avatar_hair.llm b/BetterSecondbot/openmetaverse_data/avatar_hair.llm deleted file mode 100644 index df99de8..0000000 Binary files a/BetterSecondbot/openmetaverse_data/avatar_hair.llm and /dev/null differ diff --git a/BetterSecondbot/openmetaverse_data/avatar_hair_1.llm b/BetterSecondbot/openmetaverse_data/avatar_hair_1.llm deleted file mode 100644 index 6de31fd..0000000 Binary files a/BetterSecondbot/openmetaverse_data/avatar_hair_1.llm and /dev/null differ diff --git a/BetterSecondbot/openmetaverse_data/avatar_hair_2.llm b/BetterSecondbot/openmetaverse_data/avatar_hair_2.llm deleted file mode 100644 index 47d02ba..0000000 Binary files a/BetterSecondbot/openmetaverse_data/avatar_hair_2.llm and /dev/null differ diff --git a/BetterSecondbot/openmetaverse_data/avatar_hair_3.llm b/BetterSecondbot/openmetaverse_data/avatar_hair_3.llm deleted file mode 100644 index 107f9e2..0000000 Binary files a/BetterSecondbot/openmetaverse_data/avatar_hair_3.llm and /dev/null differ diff --git a/BetterSecondbot/openmetaverse_data/avatar_hair_4.llm b/BetterSecondbot/openmetaverse_data/avatar_hair_4.llm deleted file mode 100644 index 1b9a12a..0000000 Binary files a/BetterSecondbot/openmetaverse_data/avatar_hair_4.llm and /dev/null differ diff --git a/BetterSecondbot/openmetaverse_data/avatar_hair_5.llm b/BetterSecondbot/openmetaverse_data/avatar_hair_5.llm deleted file mode 100644 index 1b9a12a..0000000 Binary files a/BetterSecondbot/openmetaverse_data/avatar_hair_5.llm and /dev/null differ diff --git a/BetterSecondbot/openmetaverse_data/avatar_head.llm b/BetterSecondbot/openmetaverse_data/avatar_head.llm deleted file mode 100644 index 8d8b5e0..0000000 Binary files a/BetterSecondbot/openmetaverse_data/avatar_head.llm and /dev/null differ diff --git a/BetterSecondbot/openmetaverse_data/avatar_head_1.llm b/BetterSecondbot/openmetaverse_data/avatar_head_1.llm deleted file mode 100644 index 26291e6..0000000 Binary files a/BetterSecondbot/openmetaverse_data/avatar_head_1.llm and /dev/null differ diff --git a/BetterSecondbot/openmetaverse_data/avatar_head_2.llm b/BetterSecondbot/openmetaverse_data/avatar_head_2.llm deleted file mode 100644 index c2b808b..0000000 Binary files a/BetterSecondbot/openmetaverse_data/avatar_head_2.llm and /dev/null differ diff --git a/BetterSecondbot/openmetaverse_data/avatar_head_3.llm b/BetterSecondbot/openmetaverse_data/avatar_head_3.llm deleted file mode 100644 index a0676b1..0000000 Binary files a/BetterSecondbot/openmetaverse_data/avatar_head_3.llm and /dev/null differ diff --git a/BetterSecondbot/openmetaverse_data/avatar_head_4.llm b/BetterSecondbot/openmetaverse_data/avatar_head_4.llm deleted file mode 100644 index 5035585..0000000 Binary files a/BetterSecondbot/openmetaverse_data/avatar_head_4.llm and /dev/null differ diff --git a/BetterSecondbot/openmetaverse_data/avatar_lad.xml b/BetterSecondbot/openmetaverse_data/avatar_lad.xml deleted file mode 100644 index ed9a824..0000000 --- a/BetterSecondbot/openmetaverse_data/avatar_lad.xml +++ /dev/null @@ -1,17475 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/BetterSecondbot/openmetaverse_data/avatar_lower_body.llm b/BetterSecondbot/openmetaverse_data/avatar_lower_body.llm deleted file mode 100644 index 0420899..0000000 Binary files a/BetterSecondbot/openmetaverse_data/avatar_lower_body.llm and /dev/null differ diff --git a/BetterSecondbot/openmetaverse_data/avatar_lower_body_1.llm b/BetterSecondbot/openmetaverse_data/avatar_lower_body_1.llm deleted file mode 100644 index 1394eb8..0000000 Binary files a/BetterSecondbot/openmetaverse_data/avatar_lower_body_1.llm and /dev/null differ diff --git a/BetterSecondbot/openmetaverse_data/avatar_lower_body_2.llm b/BetterSecondbot/openmetaverse_data/avatar_lower_body_2.llm deleted file mode 100644 index 0da9c12..0000000 Binary files a/BetterSecondbot/openmetaverse_data/avatar_lower_body_2.llm and /dev/null differ diff --git a/BetterSecondbot/openmetaverse_data/avatar_lower_body_3.llm b/BetterSecondbot/openmetaverse_data/avatar_lower_body_3.llm deleted file mode 100644 index f3c49a1..0000000 Binary files a/BetterSecondbot/openmetaverse_data/avatar_lower_body_3.llm and /dev/null differ diff --git a/BetterSecondbot/openmetaverse_data/avatar_lower_body_4.llm b/BetterSecondbot/openmetaverse_data/avatar_lower_body_4.llm deleted file mode 100644 index e717210..0000000 Binary files a/BetterSecondbot/openmetaverse_data/avatar_lower_body_4.llm and /dev/null differ diff --git a/BetterSecondbot/openmetaverse_data/avatar_skeleton.xml b/BetterSecondbot/openmetaverse_data/avatar_skeleton.xml deleted file mode 100644 index 2241a12..0000000 --- a/BetterSecondbot/openmetaverse_data/avatar_skeleton.xml +++ /dev/null @@ -1,232 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/BetterSecondbot/openmetaverse_data/avatar_skirt.llm b/BetterSecondbot/openmetaverse_data/avatar_skirt.llm deleted file mode 100644 index 08ce3d1..0000000 Binary files a/BetterSecondbot/openmetaverse_data/avatar_skirt.llm and /dev/null differ diff --git a/BetterSecondbot/openmetaverse_data/avatar_skirt_1.llm b/BetterSecondbot/openmetaverse_data/avatar_skirt_1.llm deleted file mode 100644 index 88076c3..0000000 Binary files a/BetterSecondbot/openmetaverse_data/avatar_skirt_1.llm and /dev/null differ diff --git a/BetterSecondbot/openmetaverse_data/avatar_skirt_2.llm b/BetterSecondbot/openmetaverse_data/avatar_skirt_2.llm deleted file mode 100644 index 73b3eff..0000000 Binary files a/BetterSecondbot/openmetaverse_data/avatar_skirt_2.llm and /dev/null differ diff --git a/BetterSecondbot/openmetaverse_data/avatar_skirt_3.llm b/BetterSecondbot/openmetaverse_data/avatar_skirt_3.llm deleted file mode 100644 index ded546f..0000000 Binary files a/BetterSecondbot/openmetaverse_data/avatar_skirt_3.llm and /dev/null differ diff --git a/BetterSecondbot/openmetaverse_data/avatar_skirt_4.llm b/BetterSecondbot/openmetaverse_data/avatar_skirt_4.llm deleted file mode 100644 index b9d5cb9..0000000 Binary files a/BetterSecondbot/openmetaverse_data/avatar_skirt_4.llm and /dev/null differ diff --git a/BetterSecondbot/openmetaverse_data/avatar_upper_body.llm b/BetterSecondbot/openmetaverse_data/avatar_upper_body.llm deleted file mode 100644 index da7d990..0000000 Binary files a/BetterSecondbot/openmetaverse_data/avatar_upper_body.llm and /dev/null differ diff --git a/BetterSecondbot/openmetaverse_data/avatar_upper_body_1.llm b/BetterSecondbot/openmetaverse_data/avatar_upper_body_1.llm deleted file mode 100644 index 31e104c..0000000 Binary files a/BetterSecondbot/openmetaverse_data/avatar_upper_body_1.llm and /dev/null differ diff --git a/BetterSecondbot/openmetaverse_data/avatar_upper_body_2.llm b/BetterSecondbot/openmetaverse_data/avatar_upper_body_2.llm deleted file mode 100644 index c1f4199..0000000 Binary files a/BetterSecondbot/openmetaverse_data/avatar_upper_body_2.llm and /dev/null differ diff --git a/BetterSecondbot/openmetaverse_data/avatar_upper_body_3.llm b/BetterSecondbot/openmetaverse_data/avatar_upper_body_3.llm deleted file mode 100644 index 9e89ed8..0000000 Binary files a/BetterSecondbot/openmetaverse_data/avatar_upper_body_3.llm and /dev/null differ diff --git a/BetterSecondbot/openmetaverse_data/avatar_upper_body_4.llm b/BetterSecondbot/openmetaverse_data/avatar_upper_body_4.llm deleted file mode 100644 index ec836d1..0000000 Binary files a/BetterSecondbot/openmetaverse_data/avatar_upper_body_4.llm and /dev/null differ diff --git a/BetterSecondbot/openmetaverse_data/blush_alpha.tga b/BetterSecondbot/openmetaverse_data/blush_alpha.tga deleted file mode 100644 index 05be7e7..0000000 Binary files a/BetterSecondbot/openmetaverse_data/blush_alpha.tga and /dev/null differ diff --git a/BetterSecondbot/openmetaverse_data/body_skingrain.tga b/BetterSecondbot/openmetaverse_data/body_skingrain.tga deleted file mode 100644 index 7264baa..0000000 Binary files a/BetterSecondbot/openmetaverse_data/body_skingrain.tga and /dev/null differ diff --git a/BetterSecondbot/openmetaverse_data/bodyfreckles_alpha.tga b/BetterSecondbot/openmetaverse_data/bodyfreckles_alpha.tga deleted file mode 100644 index d30ab3d..0000000 Binary files a/BetterSecondbot/openmetaverse_data/bodyfreckles_alpha.tga and /dev/null differ diff --git a/BetterSecondbot/openmetaverse_data/bump_face_wrinkles.tga b/BetterSecondbot/openmetaverse_data/bump_face_wrinkles.tga deleted file mode 100644 index 54bf7a5..0000000 Binary files a/BetterSecondbot/openmetaverse_data/bump_face_wrinkles.tga and /dev/null differ diff --git a/BetterSecondbot/openmetaverse_data/bump_head_base.tga b/BetterSecondbot/openmetaverse_data/bump_head_base.tga deleted file mode 100644 index fa35685..0000000 Binary files a/BetterSecondbot/openmetaverse_data/bump_head_base.tga and /dev/null differ diff --git a/BetterSecondbot/openmetaverse_data/bump_lowerbody_base.tga b/BetterSecondbot/openmetaverse_data/bump_lowerbody_base.tga deleted file mode 100644 index 498ea3c..0000000 Binary files a/BetterSecondbot/openmetaverse_data/bump_lowerbody_base.tga and /dev/null differ diff --git a/BetterSecondbot/openmetaverse_data/bump_pants_wrinkles.tga b/BetterSecondbot/openmetaverse_data/bump_pants_wrinkles.tga deleted file mode 100644 index cca7241..0000000 Binary files a/BetterSecondbot/openmetaverse_data/bump_pants_wrinkles.tga and /dev/null differ diff --git a/BetterSecondbot/openmetaverse_data/bump_shirt_wrinkles.tga b/BetterSecondbot/openmetaverse_data/bump_shirt_wrinkles.tga deleted file mode 100644 index 9e0d757..0000000 Binary files a/BetterSecondbot/openmetaverse_data/bump_shirt_wrinkles.tga and /dev/null differ diff --git a/BetterSecondbot/openmetaverse_data/bump_upperbody_base.tga b/BetterSecondbot/openmetaverse_data/bump_upperbody_base.tga deleted file mode 100644 index e57d635..0000000 Binary files a/BetterSecondbot/openmetaverse_data/bump_upperbody_base.tga and /dev/null differ diff --git a/BetterSecondbot/openmetaverse_data/checkerboard.tga b/BetterSecondbot/openmetaverse_data/checkerboard.tga deleted file mode 100644 index 1950d74..0000000 Binary files a/BetterSecondbot/openmetaverse_data/checkerboard.tga and /dev/null differ diff --git a/BetterSecondbot/openmetaverse_data/eyebrows_alpha.tga b/BetterSecondbot/openmetaverse_data/eyebrows_alpha.tga deleted file mode 100644 index c363e48..0000000 Binary files a/BetterSecondbot/openmetaverse_data/eyebrows_alpha.tga and /dev/null differ diff --git a/BetterSecondbot/openmetaverse_data/eyeliner_alpha.tga b/BetterSecondbot/openmetaverse_data/eyeliner_alpha.tga deleted file mode 100644 index 1611eb3..0000000 Binary files a/BetterSecondbot/openmetaverse_data/eyeliner_alpha.tga and /dev/null differ diff --git a/BetterSecondbot/openmetaverse_data/eyeshadow_inner_alpha.tga b/BetterSecondbot/openmetaverse_data/eyeshadow_inner_alpha.tga deleted file mode 100644 index 37d7919..0000000 Binary files a/BetterSecondbot/openmetaverse_data/eyeshadow_inner_alpha.tga and /dev/null differ diff --git a/BetterSecondbot/openmetaverse_data/eyeshadow_outer_alpha.tga b/BetterSecondbot/openmetaverse_data/eyeshadow_outer_alpha.tga deleted file mode 100644 index 00eef9d..0000000 Binary files a/BetterSecondbot/openmetaverse_data/eyeshadow_outer_alpha.tga and /dev/null differ diff --git a/BetterSecondbot/openmetaverse_data/eyewhite.tga b/BetterSecondbot/openmetaverse_data/eyewhite.tga deleted file mode 100644 index a720496..0000000 Binary files a/BetterSecondbot/openmetaverse_data/eyewhite.tga and /dev/null differ diff --git a/BetterSecondbot/openmetaverse_data/facehair_chincurtains_alpha.tga b/BetterSecondbot/openmetaverse_data/facehair_chincurtains_alpha.tga deleted file mode 100644 index b103970..0000000 Binary files a/BetterSecondbot/openmetaverse_data/facehair_chincurtains_alpha.tga and /dev/null differ diff --git a/BetterSecondbot/openmetaverse_data/facehair_moustache_alpha.tga b/BetterSecondbot/openmetaverse_data/facehair_moustache_alpha.tga deleted file mode 100644 index 4068c4f..0000000 Binary files a/BetterSecondbot/openmetaverse_data/facehair_moustache_alpha.tga and /dev/null differ diff --git a/BetterSecondbot/openmetaverse_data/facehair_sideburns_alpha.tga b/BetterSecondbot/openmetaverse_data/facehair_sideburns_alpha.tga deleted file mode 100644 index acddc2d..0000000 Binary files a/BetterSecondbot/openmetaverse_data/facehair_sideburns_alpha.tga and /dev/null differ diff --git a/BetterSecondbot/openmetaverse_data/facehair_soulpatch_alpha.tga b/BetterSecondbot/openmetaverse_data/facehair_soulpatch_alpha.tga deleted file mode 100644 index 687091a..0000000 Binary files a/BetterSecondbot/openmetaverse_data/facehair_soulpatch_alpha.tga and /dev/null differ diff --git a/BetterSecondbot/openmetaverse_data/freckles_alpha.tga b/BetterSecondbot/openmetaverse_data/freckles_alpha.tga deleted file mode 100644 index a9a4ec0..0000000 Binary files a/BetterSecondbot/openmetaverse_data/freckles_alpha.tga and /dev/null differ diff --git a/BetterSecondbot/openmetaverse_data/genepool.xml b/BetterSecondbot/openmetaverse_data/genepool.xml deleted file mode 100644 index 52300c2..0000000 --- a/BetterSecondbot/openmetaverse_data/genepool.xml +++ /dev/null @@ -1,7107 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/BetterSecondbot/openmetaverse_data/glove_length_alpha.tga b/BetterSecondbot/openmetaverse_data/glove_length_alpha.tga deleted file mode 100644 index db89ad5..0000000 Binary files a/BetterSecondbot/openmetaverse_data/glove_length_alpha.tga and /dev/null differ diff --git a/BetterSecondbot/openmetaverse_data/gloves_fingers_alpha.tga b/BetterSecondbot/openmetaverse_data/gloves_fingers_alpha.tga deleted file mode 100644 index dba2eec..0000000 Binary files a/BetterSecondbot/openmetaverse_data/gloves_fingers_alpha.tga and /dev/null differ diff --git a/BetterSecondbot/openmetaverse_data/head_alpha.tga b/BetterSecondbot/openmetaverse_data/head_alpha.tga deleted file mode 100644 index 8164525..0000000 Binary files a/BetterSecondbot/openmetaverse_data/head_alpha.tga and /dev/null differ diff --git a/BetterSecondbot/openmetaverse_data/head_color.tga b/BetterSecondbot/openmetaverse_data/head_color.tga deleted file mode 100644 index 74b1b30..0000000 Binary files a/BetterSecondbot/openmetaverse_data/head_color.tga and /dev/null differ diff --git a/BetterSecondbot/openmetaverse_data/head_hair.tga b/BetterSecondbot/openmetaverse_data/head_hair.tga deleted file mode 100644 index 5321f35..0000000 Binary files a/BetterSecondbot/openmetaverse_data/head_hair.tga and /dev/null differ diff --git a/BetterSecondbot/openmetaverse_data/head_highlights_alpha.tga b/BetterSecondbot/openmetaverse_data/head_highlights_alpha.tga deleted file mode 100644 index 8dc5239..0000000 Binary files a/BetterSecondbot/openmetaverse_data/head_highlights_alpha.tga and /dev/null differ diff --git a/BetterSecondbot/openmetaverse_data/head_shading_alpha.tga b/BetterSecondbot/openmetaverse_data/head_shading_alpha.tga deleted file mode 100644 index e8ea490..0000000 Binary files a/BetterSecondbot/openmetaverse_data/head_shading_alpha.tga and /dev/null differ diff --git a/BetterSecondbot/openmetaverse_data/head_skingrain.tga b/BetterSecondbot/openmetaverse_data/head_skingrain.tga deleted file mode 100644 index b42dee0..0000000 Binary files a/BetterSecondbot/openmetaverse_data/head_skingrain.tga and /dev/null differ diff --git a/BetterSecondbot/openmetaverse_data/invisible_head.tga b/BetterSecondbot/openmetaverse_data/invisible_head.tga deleted file mode 100644 index 2673a23..0000000 Binary files a/BetterSecondbot/openmetaverse_data/invisible_head.tga and /dev/null differ diff --git a/BetterSecondbot/openmetaverse_data/jacket_length_lower_alpha.tga b/BetterSecondbot/openmetaverse_data/jacket_length_lower_alpha.tga deleted file mode 100644 index 722bc19..0000000 Binary files a/BetterSecondbot/openmetaverse_data/jacket_length_lower_alpha.tga and /dev/null differ diff --git a/BetterSecondbot/openmetaverse_data/jacket_length_upper_alpha.tga b/BetterSecondbot/openmetaverse_data/jacket_length_upper_alpha.tga deleted file mode 100644 index e9db7e7..0000000 Binary files a/BetterSecondbot/openmetaverse_data/jacket_length_upper_alpha.tga and /dev/null differ diff --git a/BetterSecondbot/openmetaverse_data/jacket_open_lower_alpha.tga b/BetterSecondbot/openmetaverse_data/jacket_open_lower_alpha.tga deleted file mode 100644 index db0c2fb..0000000 Binary files a/BetterSecondbot/openmetaverse_data/jacket_open_lower_alpha.tga and /dev/null differ diff --git a/BetterSecondbot/openmetaverse_data/jacket_open_upper_alpha.tga b/BetterSecondbot/openmetaverse_data/jacket_open_upper_alpha.tga deleted file mode 100644 index 71b8a0b..0000000 Binary files a/BetterSecondbot/openmetaverse_data/jacket_open_upper_alpha.tga and /dev/null differ diff --git a/BetterSecondbot/openmetaverse_data/lipgloss_alpha.tga b/BetterSecondbot/openmetaverse_data/lipgloss_alpha.tga deleted file mode 100644 index 78ceeca..0000000 Binary files a/BetterSecondbot/openmetaverse_data/lipgloss_alpha.tga and /dev/null differ diff --git a/BetterSecondbot/openmetaverse_data/lips_mask.tga b/BetterSecondbot/openmetaverse_data/lips_mask.tga deleted file mode 100644 index ae1401c..0000000 Binary files a/BetterSecondbot/openmetaverse_data/lips_mask.tga and /dev/null differ diff --git a/BetterSecondbot/openmetaverse_data/lipstick_alpha.tga b/BetterSecondbot/openmetaverse_data/lipstick_alpha.tga deleted file mode 100644 index 2795f1b..0000000 Binary files a/BetterSecondbot/openmetaverse_data/lipstick_alpha.tga and /dev/null differ diff --git a/BetterSecondbot/openmetaverse_data/lowerbody_color.tga b/BetterSecondbot/openmetaverse_data/lowerbody_color.tga deleted file mode 100644 index a63aa12..0000000 Binary files a/BetterSecondbot/openmetaverse_data/lowerbody_color.tga and /dev/null differ diff --git a/BetterSecondbot/openmetaverse_data/lowerbody_highlights_alpha.tga b/BetterSecondbot/openmetaverse_data/lowerbody_highlights_alpha.tga deleted file mode 100644 index ae3413a..0000000 Binary files a/BetterSecondbot/openmetaverse_data/lowerbody_highlights_alpha.tga and /dev/null differ diff --git a/BetterSecondbot/openmetaverse_data/lowerbody_shading_alpha.tga b/BetterSecondbot/openmetaverse_data/lowerbody_shading_alpha.tga deleted file mode 100644 index 0242663..0000000 Binary files a/BetterSecondbot/openmetaverse_data/lowerbody_shading_alpha.tga and /dev/null differ diff --git a/BetterSecondbot/openmetaverse_data/nailpolish_alpha.tga b/BetterSecondbot/openmetaverse_data/nailpolish_alpha.tga deleted file mode 100644 index 91af762..0000000 Binary files a/BetterSecondbot/openmetaverse_data/nailpolish_alpha.tga and /dev/null differ diff --git a/BetterSecondbot/openmetaverse_data/pants_length_alpha.tga b/BetterSecondbot/openmetaverse_data/pants_length_alpha.tga deleted file mode 100644 index 3c4f21c..0000000 Binary files a/BetterSecondbot/openmetaverse_data/pants_length_alpha.tga and /dev/null differ diff --git a/BetterSecondbot/openmetaverse_data/pants_waist_alpha.tga b/BetterSecondbot/openmetaverse_data/pants_waist_alpha.tga deleted file mode 100644 index 35658c0..0000000 Binary files a/BetterSecondbot/openmetaverse_data/pants_waist_alpha.tga and /dev/null differ diff --git a/BetterSecondbot/openmetaverse_data/rosyface_alpha.tga b/BetterSecondbot/openmetaverse_data/rosyface_alpha.tga deleted file mode 100644 index a0c8513..0000000 Binary files a/BetterSecondbot/openmetaverse_data/rosyface_alpha.tga and /dev/null differ diff --git a/BetterSecondbot/openmetaverse_data/rouge_alpha.tga b/BetterSecondbot/openmetaverse_data/rouge_alpha.tga deleted file mode 100644 index a0c8513..0000000 Binary files a/BetterSecondbot/openmetaverse_data/rouge_alpha.tga and /dev/null differ diff --git a/BetterSecondbot/openmetaverse_data/shirt_bottom_alpha.tga b/BetterSecondbot/openmetaverse_data/shirt_bottom_alpha.tga deleted file mode 100644 index 7cce03d..0000000 Binary files a/BetterSecondbot/openmetaverse_data/shirt_bottom_alpha.tga and /dev/null differ diff --git a/BetterSecondbot/openmetaverse_data/shirt_collar_alpha.tga b/BetterSecondbot/openmetaverse_data/shirt_collar_alpha.tga deleted file mode 100644 index f55f635..0000000 Binary files a/BetterSecondbot/openmetaverse_data/shirt_collar_alpha.tga and /dev/null differ diff --git a/BetterSecondbot/openmetaverse_data/shirt_collar_back_alpha.tga b/BetterSecondbot/openmetaverse_data/shirt_collar_back_alpha.tga deleted file mode 100644 index 43a6453..0000000 Binary files a/BetterSecondbot/openmetaverse_data/shirt_collar_back_alpha.tga and /dev/null differ diff --git a/BetterSecondbot/openmetaverse_data/shirt_sleeve_alpha.tga b/BetterSecondbot/openmetaverse_data/shirt_sleeve_alpha.tga deleted file mode 100644 index e3b18f4..0000000 Binary files a/BetterSecondbot/openmetaverse_data/shirt_sleeve_alpha.tga and /dev/null differ diff --git a/BetterSecondbot/openmetaverse_data/shoe_height_alpha.tga b/BetterSecondbot/openmetaverse_data/shoe_height_alpha.tga deleted file mode 100644 index d08dd75..0000000 Binary files a/BetterSecondbot/openmetaverse_data/shoe_height_alpha.tga and /dev/null differ diff --git a/BetterSecondbot/openmetaverse_data/skirt_length_alpha.tga b/BetterSecondbot/openmetaverse_data/skirt_length_alpha.tga deleted file mode 100644 index c867994..0000000 Binary files a/BetterSecondbot/openmetaverse_data/skirt_length_alpha.tga and /dev/null differ diff --git a/BetterSecondbot/openmetaverse_data/skirt_slit_back_alpha.tga b/BetterSecondbot/openmetaverse_data/skirt_slit_back_alpha.tga deleted file mode 100644 index 0e49688..0000000 Binary files a/BetterSecondbot/openmetaverse_data/skirt_slit_back_alpha.tga and /dev/null differ diff --git a/BetterSecondbot/openmetaverse_data/skirt_slit_front_alpha.tga b/BetterSecondbot/openmetaverse_data/skirt_slit_front_alpha.tga deleted file mode 100644 index 888bbf7..0000000 Binary files a/BetterSecondbot/openmetaverse_data/skirt_slit_front_alpha.tga and /dev/null differ diff --git a/BetterSecondbot/openmetaverse_data/skirt_slit_left_alpha.tga b/BetterSecondbot/openmetaverse_data/skirt_slit_left_alpha.tga deleted file mode 100644 index 210feac..0000000 Binary files a/BetterSecondbot/openmetaverse_data/skirt_slit_left_alpha.tga and /dev/null differ diff --git a/BetterSecondbot/openmetaverse_data/skirt_slit_right_alpha.tga b/BetterSecondbot/openmetaverse_data/skirt_slit_right_alpha.tga deleted file mode 100644 index ce11c64..0000000 Binary files a/BetterSecondbot/openmetaverse_data/skirt_slit_right_alpha.tga and /dev/null differ diff --git a/BetterSecondbot/openmetaverse_data/underpants_trial_female.tga b/BetterSecondbot/openmetaverse_data/underpants_trial_female.tga deleted file mode 100644 index 96bf732..0000000 Binary files a/BetterSecondbot/openmetaverse_data/underpants_trial_female.tga and /dev/null differ diff --git a/BetterSecondbot/openmetaverse_data/underpants_trial_male.tga b/BetterSecondbot/openmetaverse_data/underpants_trial_male.tga deleted file mode 100644 index 095695c..0000000 Binary files a/BetterSecondbot/openmetaverse_data/underpants_trial_male.tga and /dev/null differ diff --git a/BetterSecondbot/openmetaverse_data/undershirt_trial_female.tga b/BetterSecondbot/openmetaverse_data/undershirt_trial_female.tga deleted file mode 100644 index e17a309..0000000 Binary files a/BetterSecondbot/openmetaverse_data/undershirt_trial_female.tga and /dev/null differ diff --git a/BetterSecondbot/openmetaverse_data/upperbody_color.tga b/BetterSecondbot/openmetaverse_data/upperbody_color.tga deleted file mode 100644 index 85fcc41..0000000 Binary files a/BetterSecondbot/openmetaverse_data/upperbody_color.tga and /dev/null differ diff --git a/BetterSecondbot/openmetaverse_data/upperbody_highlights_alpha.tga b/BetterSecondbot/openmetaverse_data/upperbody_highlights_alpha.tga deleted file mode 100644 index 2d8102b..0000000 Binary files a/BetterSecondbot/openmetaverse_data/upperbody_highlights_alpha.tga and /dev/null differ diff --git a/BetterSecondbot/openmetaverse_data/upperbody_shading_alpha.tga b/BetterSecondbot/openmetaverse_data/upperbody_shading_alpha.tga deleted file mode 100644 index b420506..0000000 Binary files a/BetterSecondbot/openmetaverse_data/upperbody_shading_alpha.tga and /dev/null differ diff --git a/BetterSecondbot/openmetaverse_data/upperbodyfreckles_alpha.tga b/BetterSecondbot/openmetaverse_data/upperbodyfreckles_alpha.tga deleted file mode 100644 index 76c7ce8..0000000 Binary files a/BetterSecondbot/openmetaverse_data/upperbodyfreckles_alpha.tga and /dev/null differ diff --git a/LibreMetaverse.StructuredData/JSON/JsonData.cs b/LibreMetaverse.StructuredData/JSON/JsonData.cs index 64bfe96..51ce37d 100644 --- a/LibreMetaverse.StructuredData/JSON/JsonData.cs +++ b/LibreMetaverse.StructuredData/JSON/JsonData.cs @@ -122,18 +122,16 @@ namespace LitJson #region IDictionary Indexer object IDictionary.this[object key] { - get { - return EnsureDictionary ()[key]; - } + get => EnsureDictionary ()[key]; set { - if (! (key is String)) + if (! (key is string str)) throw new ArgumentException ( "The key has to be a string"); JsonData data = ToJsonData (value); - this[(string) key] = data; + this[str] = data; } } #endregion diff --git a/LibreMetaverse.StructuredData/JSON/JsonMapper.cs b/LibreMetaverse.StructuredData/JSON/JsonMapper.cs index 975fcf3..fc41c49 100644 --- a/LibreMetaverse.StructuredData/JSON/JsonMapper.cs +++ b/LibreMetaverse.StructuredData/JSON/JsonMapper.cs @@ -30,8 +30,6 @@ namespace LitJson internal struct ArrayMetadata { private Type element_type; - private bool is_array; - private bool is_list; public Type ElementType { @@ -45,24 +43,15 @@ namespace LitJson set { element_type = value; } } - public bool IsArray { - get { return is_array; } - set { is_array = value; } - } + public bool IsArray { get; set; } - public bool IsList { - get { return is_list; } - set { is_list = value; } - } + public bool IsList { get; set; } } internal struct ObjectMetadata { private Type element_type; - private bool is_dictionary; - - private IDictionary properties; public Type ElementType { @@ -76,15 +65,9 @@ namespace LitJson set { element_type = value; } } - public bool IsDictionary { - get { return is_dictionary; } - set { is_dictionary = value; } - } + public bool IsDictionary { get; set; } - public IDictionary Properties { - get { return properties; } - set { properties = value; } - } + public IDictionary Properties { get; set; } } diff --git a/LibreMetaverse.StructuredData/JSON/JsonReader.cs b/LibreMetaverse.StructuredData/JSON/JsonReader.cs index a327300..75052bb 100644 --- a/LibreMetaverse.StructuredData/JSON/JsonReader.cs +++ b/LibreMetaverse.StructuredData/JSON/JsonReader.cs @@ -46,16 +46,13 @@ namespace LitJson private Stack automaton_stack; private int current_input; private int current_symbol; - private bool end_of_json; - private bool end_of_input; private Lexer lexer; private bool parser_in_string; private bool parser_return; private bool read_started; private TextReader reader; private bool reader_is_owned; - private object token_value; - private JsonToken token; + #endregion @@ -70,13 +67,13 @@ namespace LitJson set { lexer.AllowSingleQuotedStrings = value; } } - public bool EndOfInput => end_of_input; + public bool EndOfInput { get; private set; } - public bool EndOfJson => end_of_json; + public bool EndOfJson { get; private set; } - public JsonToken Token => token; + public JsonToken Token { get; private set; } - public object Value => token_value; + public object Value { get; private set; } #endregion @@ -112,8 +109,8 @@ namespace LitJson lexer = new Lexer (reader); - end_of_input = false; - end_of_json = false; + EndOfInput = false; + EndOfJson = false; this.reader = reader; reader_is_owned = owned; @@ -250,8 +247,8 @@ namespace LitJson double n_double; if (Double.TryParse (number, out n_double)) { - token = JsonToken.Double; - token_value = n_double; + Token = JsonToken.Double; + Value = n_double; return; } @@ -259,41 +256,41 @@ namespace LitJson int n_int32; if (Int32.TryParse (number, out n_int32)) { - token = JsonToken.Int; - token_value = n_int32; + Token = JsonToken.Int; + Value = n_int32; return; } long n_int64; if (Int64.TryParse (number, out n_int64)) { - token = JsonToken.Long; - token_value = n_int64; + Token = JsonToken.Long; + Value = n_int64; return; } // Shouldn't happen, but just in case, return something - token = JsonToken.Int; - token_value = 0; + Token = JsonToken.Int; + Value = 0; } private void ProcessSymbol () { if (current_symbol == '[') { - token = JsonToken.ArrayStart; + Token = JsonToken.ArrayStart; parser_return = true; } else if (current_symbol == ']') { - token = JsonToken.ArrayEnd; + Token = JsonToken.ArrayEnd; parser_return = true; } else if (current_symbol == '{') { - token = JsonToken.ObjectStart; + Token = JsonToken.ObjectStart; parser_return = true; } else if (current_symbol == '}') { - token = JsonToken.ObjectEnd; + Token = JsonToken.ObjectEnd; parser_return = true; } else if (current_symbol == '"') { @@ -303,22 +300,22 @@ namespace LitJson parser_return = true; } else { - if (token == JsonToken.None) - token = JsonToken.String; + if (Token == JsonToken.None) + Token = JsonToken.String; parser_in_string = true; } } else if (current_symbol == (int) ParserToken.CharSeq) { - token_value = lexer.StringValue; + Value = lexer.StringValue; } else if (current_symbol == (int) ParserToken.False) { - token = JsonToken.Boolean; - token_value = false; + Token = JsonToken.Boolean; + Value = false; parser_return = true; } else if (current_symbol == (int) ParserToken.Null) { - token = JsonToken.Null; + Token = JsonToken.Null; parser_return = true; } else if (current_symbol == (int) ParserToken.Number) { @@ -327,11 +324,11 @@ namespace LitJson parser_return = true; } else if (current_symbol == (int) ParserToken.Pair) { - token = JsonToken.PropertyName; + Token = JsonToken.PropertyName; } else if (current_symbol == (int) ParserToken.True) { - token = JsonToken.Boolean; - token_value = true; + Token = JsonToken.Boolean; + Value = true; parser_return = true; } @@ -339,7 +336,7 @@ namespace LitJson private bool ReadToken () { - if (end_of_input) + if (EndOfInput) return false; lexer.NextToken (); @@ -359,11 +356,11 @@ namespace LitJson public void Close () { - if (end_of_input) + if (EndOfInput) return; - end_of_input = true; - end_of_json = true; + EndOfInput = true; + EndOfJson = true; if (reader_is_owned) reader.Close (); @@ -373,11 +370,11 @@ namespace LitJson public bool Read () { - if (end_of_input) + if (EndOfInput) return false; - if (end_of_json) { - end_of_json = false; + if (EndOfJson) { + EndOfJson = false; automaton_stack.Clear (); automaton_stack.Push ((int) ParserToken.End); automaton_stack.Push ((int) ParserToken.Text); @@ -386,8 +383,8 @@ namespace LitJson parser_in_string = false; parser_return = false; - token = JsonToken.None; - token_value = null; + Token = JsonToken.None; + Value = null; if (! read_started) { read_started = true; @@ -400,7 +397,7 @@ namespace LitJson while (true) { if (parser_return) { if (automaton_stack.Peek () == (int) ParserToken.End) - end_of_json = true; + EndOfJson = true; return true; } diff --git a/LibreMetaverse.StructuredData/LLSD/BinaryLLSD.cs b/LibreMetaverse.StructuredData/LLSD/BinaryLLSD.cs index dcfd17d..4298ab7 100644 --- a/LibreMetaverse.StructuredData/LLSD/BinaryLLSD.cs +++ b/LibreMetaverse.StructuredData/LLSD/BinaryLLSD.cs @@ -38,7 +38,6 @@ using System; using System.IO; -using System.Collections; using System.Collections.Generic; using System.Text; diff --git a/LibreMetaverse.StructuredData/LLSD/XmlLLSD.cs b/LibreMetaverse.StructuredData/LLSD/XmlLLSD.cs index e3c168c..179c90e 100644 --- a/LibreMetaverse.StructuredData/LLSD/XmlLLSD.cs +++ b/LibreMetaverse.StructuredData/LLSD/XmlLLSD.cs @@ -1,6 +1,6 @@ /* * Copyright (c) 2006-2016, openmetaverse.co - * Copyright (c) 2021, Sjofn LLC. + * Copyright (c) 2021-2022, Sjofn LLC. * All rights reserved. * * - Redistribution and use in source and binary forms, with or without diff --git a/LibreMetaverse.StructuredData/LibreMetaverse.StructuredData.XML b/LibreMetaverse.StructuredData/LibreMetaverse.StructuredData.XML deleted file mode 100644 index e7c5f6a..0000000 --- a/LibreMetaverse.StructuredData/LibreMetaverse.StructuredData.XML +++ /dev/null @@ -1,316 +0,0 @@ - - - - LibreMetaverse.StructuredData - - - - - - - - - - - - - - - - Deserializes binary LLSD - - Serialized data - OSD containting deserialized data - - - - Deserializes binary LLSD - - Stream to read the data from - OSD containting deserialized data - - - - Serializes OSD to binary format. It does no prepend header - - OSD to serialize - Serialized data - - - - Serializes OSD to binary format - - OSD to serialize - - Serialized data - - - - Serializes OSD to binary format. It does no prepend header - - OSD to serialize - Serialized data - - - - Serializes OSD to binary format - - OSD to serialize - - Serialized data - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Deserialize LLSD/XML stream - - a containing the serialized data - - - - - Deserialize LLSD/XML stream - - Data as a byte array - - - - - Deserialize LLSD/XML stream - - Serialized data as a - - - - - Deserialize LLSD/XML stream - - Serialized data as a - - - - - Serialize an OSD object in LLSD/XML - - OSD object to serialize - Serialized data as a byte aray - - - - - - - - - - - - - - - - - - - - - - - - - - OSD Exception - - - - - OSD element base class - - - - - Uses reflection to create an SDMap from all of the SD - serializable types in an object - - Class or struct containing serializable types - An SDMap holding the serialized values from the - container object - - - - Uses reflection to deserialize member variables in an object from - an SDMap - - Reference to an object to fill with deserialized - values - Serialized values to put in the target - object - - - - OSD Boolean Element - - - - - OSD Integer Element - - - - - OSD Floating point Element - - - - - OSD LLSD-XML Element - - - - - OSD String Element - - - - - OSD UUID Element - - - - - OSD DateTime Element - - - - - OSD Uri Element - - - - - OSD Binary Element - - - - - OSD Map Element - - - - - OSD Array Element - - - - diff --git a/LibreMetaverse.StructuredData/LibreMetaverse.StructuredData.csproj b/LibreMetaverse.StructuredData/LibreMetaverse.StructuredData.csproj index 64e06ce..03797b9 100644 --- a/LibreMetaverse.StructuredData/LibreMetaverse.StructuredData.csproj +++ b/LibreMetaverse.StructuredData/LibreMetaverse.StructuredData.csproj @@ -1,154 +1,54 @@ - - - Local - 14.0.25123 - 2.0 - {89D7A3E5-0000-0000-0000-000000000000} - Debug - LibreMetaverse.StructuredData - JScript - Grid - IE50 - false - netstandard2.0;netstandard2.1;net5.0 - Library - LibreMetaverse.StructuredData - true - AnyCPU;x64;x86 - - - True - 285212672 - False - - - TRACE;DEBUG - True - 4096 - False - ..\bin\ - False - False - False - 4 - False - 1591,1574,0419 - AnyCPU - - - True - 285212672 - False - - - TRACE;DEBUG - True - 4096 - False - ..\bin\ - False - False - False - 4 - False - 1591,1574,0419 - AnyCPU - - - True - 285212672 - False - - - TRACE;DEBUG - True - 4096 - False - ..\bin\ - False - False - False - 4 - False - 1591,1574,0419 - AnyCPU - - - True - 285212672 - False - TRACE - LibreMetaverse.StructuredData.XML - False - 4096 - True - ..\bin\ - False - False - False - 4 - False - 1591,1574,0419 - AnyCPU - - - True - 285212672 - False - TRACE - LibreMetaverse.StructuredData.XML - False - 4096 - True - ..\bin\ - False - False - False - 4 - False - 1591,1574,0419 - AnyCPU - - - True - 285212672 - False - TRACE - LibreMetaverse.StructuredData.XML - False - 4096 - True - ..\bin\ - False - False - False - 4 - False - 1591,1574,0419 - AnyCPU - - - - - - - - - - True - - - - - - - - - 1.2.0 - Sjofn LLC, OpenMetaverse Developers - LibreMetaverse.StructuredData - Copyright © OpenMetaverse Developers 2008, 2017. Copyright © Sjofn LLC 2018-2021. All rights reserved. - LICENSE.txt - https://github.com/cinderblocks/libremetaverse - + + + LibreMetaverse.StructuredData + LibreMetaverse structured data library + LibreMetaverse.StructuredData + netstandard2.0;netstandard2.1;net5.0 + Library + LibreMetaverse.StructuredData + true + true + snupkg + 0419,1574,1591 + x64;x86;AnyCPU + ..\bin\ + + + TRACE;DEBUG + False + + + TRACE;DEBUG + False + + + TRACE;DEBUG + False + + + true + pdbonly + TRACE + True + + + true + pdbonly + TRACE + True + + + true + pdbonly + TRACE + True + + + + + + + + + \ No newline at end of file diff --git a/LibreMetaverse.StructuredData/LibreMetaverse.StructuredData.nuspec b/LibreMetaverse.StructuredData/LibreMetaverse.StructuredData.nuspec deleted file mode 100644 index aac0f8b..0000000 --- a/LibreMetaverse.StructuredData/LibreMetaverse.StructuredData.nuspec +++ /dev/null @@ -1,15 +0,0 @@ - - - - LibreMetaverse.StructuredData - $version$ - Cinder Biscuits - Cinder Biscuits - https://github.com/cinderblocks/libremetaverse/blob/master/LICENSE.txt - https://github.com/cinderblocks/libremetaverse - false - LibreMetaverse structured data library - Copyright 2017 - LMV OMV OpenMetaverse OpenSim Halcyon OpenMetaverseFoundation VirtualWorld Radegast SecondLife - - \ No newline at end of file diff --git a/LibreMetaverse.StructuredData/StructuredData.cs b/LibreMetaverse.StructuredData/StructuredData.cs index 73dbb20..714c0d9 100644 --- a/LibreMetaverse.StructuredData/StructuredData.cs +++ b/LibreMetaverse.StructuredData/StructuredData.cs @@ -1,6 +1,6 @@ /* * Copyright (c) 2006-2016, openmetaverse.co - * Copyright (c) 2021, Sjofn LLC. + * Copyright (c) 2021-2022, Sjofn LLC. * All rights reserved. * * - Redistribution and use in source and binary forms, with or without @@ -893,6 +893,11 @@ namespace OpenMetaverse.StructuredData return new OSDMap(new Dictionary(_mMap)); } + public Hashtable ToHashtable() + { + return new Hashtable(_mMap); + } + #region IDictionary Implementation public int Count => _mMap.Count; @@ -1125,6 +1130,11 @@ namespace OpenMetaverse.StructuredData return OSDParser.SerializeJsonString(this, true); } + public ArrayList ToArrayList() + { + return new ArrayList(_mArray); + } + #region IList Implementation public int Count => _mArray.Count; diff --git a/LibreMetaverse.Types/CRC32.cs b/LibreMetaverse.Types/CRC32.cs index eb32dee..8811889 100644 --- a/LibreMetaverse.Types/CRC32.cs +++ b/LibreMetaverse.Types/CRC32.cs @@ -24,8 +24,6 @@ * POSSIBILITY OF SUCH DAMAGE. */ -using System; - namespace OpenMetaverse { public class CRC32 diff --git a/LibreMetaverse.Types/LibreMetaverse.Types.XML b/LibreMetaverse.Types/LibreMetaverse.Types.XML deleted file mode 100644 index cb0f674..0000000 --- a/LibreMetaverse.Types/LibreMetaverse.Types.XML +++ /dev/null @@ -1,2583 +0,0 @@ - - - - LibreMetaverse.Types - - - - - An 8-bit color structure including an alpha channel - - - - Red - - - Green - - - Blue - - - Alpha - - - - - - - - - - - - - Builds a color from a byte array - - Byte array containing a 16 byte color - Beginning position in the byte array - True if the byte array stores inverted values, - otherwise false. For example the color black (fully opaque) inverted - would be 0xFF 0xFF 0xFF 0x00 - - - - Returns the raw bytes for this vector - - Byte array containing a 16 byte color - Beginning position in the byte array - True if the byte array stores inverted values, - otherwise false. For example the color black (fully opaque) inverted - would be 0xFF 0xFF 0xFF 0x00 - True if the alpha value is inverted in - addition to whatever the inverted parameter is. Setting inverted true - and alphaInverted true will flip the alpha value back to non-inverted, - but keep the other color bytes inverted - A 16 byte array containing R, G, B, and A - - - - Copy constructor - - Color to copy - - - - IComparable.CompareTo implementation - - Sorting ends up like this: |--Grayscale--||--Color--|. - Alpha is only used when the colors are otherwise equivalent - - - - Builds a color from a byte array - - Byte array containing a 16 byte color - Beginning position in the byte array - True if the byte array stores inverted values, - otherwise false. For example the color black (fully opaque) inverted - would be 0xFF 0xFF 0xFF 0x00 - True if the alpha value is inverted in - addition to whatever the inverted parameter is. Setting inverted true - and alphaInverted true will flip the alpha value back to non-inverted, - but keep the other color bytes inverted - - - - Writes the raw bytes for this color to a byte array - - Destination byte array - Position in the destination array to start - writing. Must be at least 16 bytes before the end of the array - - - - Serializes this color into four bytes in a byte array - - Destination byte array - Position in the destination array to start - writing. Must be at least 4 bytes before the end of the array - True to invert the output (1.0 becomes 0 - instead of 255) - - - - Writes the raw bytes for this color to a byte array - - Destination byte array - Position in the destination array to start - writing. Must be at least 16 bytes before the end of the array - - - - Ensures that values are in range 0-1 - - - - - Create an RGB color from a hue, saturation, value combination - - Hue - Saturation - Value - An fully opaque RGB color (alpha is 1.0) - - - - Performs linear interpolation between two colors - - Color to start at - Color to end at - Amount to interpolate - The interpolated color - - - A Color4 with zero RGB values and fully opaque (alpha 1.0) - - - A Color4 with full RGB values (1.0) and fully opaque (alpha 1.0) - - - - Attribute class that allows extra attributes to be attached to ENUMs - - - - Text used when presenting ENUM to user - - - Default initializer - - - Text used when presenting ENUM to user - - - - The different types of grid assets - - - - Unknown asset type - - - Texture asset, stores in JPEG2000 J2C stream format - - - Sound asset - - - Calling card for another avatar - - - Link to a location in world - - - Collection of textures and parameters that can be worn by an avatar - - - Primitive that can contain textures, sounds, scripts and more - - - Notecard asset - - - Holds a collection of inventory items. "Category" in the Linden viewer - - - Linden scripting language script - - - LSO bytecode for a script - - - Uncompressed TGA texture - - - Collection of textures and shape parameters that can be worn - - - Uncompressed sound - - - Uncompressed TGA non-square image, not to be used as a texture - - - Compressed JPEG non-square image, not to be used as a texture - - - Animation - - - Sequence of animations, sounds, chat, and pauses - - - Simstate file - - - Asset is a link to another inventory item - - - Asset is a link to another inventory folder - - - Linden mesh format - - - widget? - - - Person? - - - - The different types of folder. - - - - None folder type - - - Texture folder type - - - Sound folder type - - - Calling card folder type - - - Landmark folder type - - - Clothing folder type - - - Object folder type - - - Notecard folder type - - - The root folder type - - - Non-conformant OpenSim root folder type - - - LSLText folder - - - Bodyparts folder - - - Trash folder - - - Snapshot folder - - - Lost And Found folder - - - Animation folder - - - Gesture folder - - - Favorites folder - - - Ensemble beginning range - - - Ensemble ending range - - - Current outfit folder - - - Outfit folder - - - My outfits folder - - - Mesh folder - - - Marketplace direct delivery inbox ("Received Items") - - - Marketplace direct delivery outbox - - - Basic root folder - - - Marketplace listings folder - - - Marketplace stock folder - - - Marketplace version. We *never* actually create folder of this type - - - Hypergrid Suitcase folder - - - - Inventory Item Types, eg Script, Notecard, Folder, etc - - - - Unknown - - - Texture - - - Sound - - - Calling Card - - - Landmark - - - Notecard - - - - - - Folder - - - - - - an LSL Script - - - - - - - - - - - - - - - - - - - - - - Item Sale Status - - - - Not for sale - - - The original is for sale - - - Copies are for sale - - - The contents of the object are for sale - - - - Types of wearable assets - - - - Body shape - - - Skin textures and attributes - - - Hair - - - Eyes - - - Shirt - - - Pants - - - Shoes - - - Socks - - - Jacket - - - Gloves - - - Undershirt - - - Underpants - - - Skirt - - - Alpha mask to hide parts of the avatar - - - Tattoo - - - Physics - - - Universal - - - Invalid wearable asset - - - - Identifier code for primitive types - - - - None - - - A Primitive - - - A Avatar - - - Linden grass - - - Linden tree - - - A primitive that acts as the source for a particle stream - - - A Linden tree - - - - Primary parameters for primitives such as Physics Enabled or Phantom - - - - Deprecated - - - Whether physics are enabled for this object - - - - - - - - - - - - - - - - - - - - - Whether this object contains an active touch script - - - - - - Whether this object can receive payments - - - Whether this object is phantom (no collisions) - - - - - - - - - - - - - - - Deprecated - - - - - - - - - - - - Deprecated - - - - - - - - - - - - - - - Server flag, will not be sent to clients. Specifies that - the object is destroyed when it touches a simulator edge - - - Server flag, will not be sent to clients. Specifies that - the object will be returned to the owner's inventory when it - touches a simulator edge - - - Server flag, will not be sent to clients. - - - Server flag, will not be sent to client. Specifies that - the object is hovering/flying - - - - - - - - - - - - - - - - Sound flags for sounds attached to primitives - - - - - - - - - - - - - - - - - - - - - - - - - - Material type for a primitive - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Used in a helper function to roughly determine prim shape - - - - - Extra parameters for primitives, these flags are for features that have - been added after the original ObjectFlags that has all eight bits - reserved already - - - - Whether this object has flexible parameters - - - Whether this object has light parameters - - - Whether this object is a sculpted prim - - - Whether this object is a light image map - - - Whether this object is a mesh - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Attachment points for objects on avatar bodies - - - Both InventoryObject and InventoryAttachment types can be attached - - - - Right hand if object was not previously attached - - - Chest - - - Skull - - - Left shoulder - - - Right shoulder - - - Left hand - - - Right hand - - - Left foot - - - Right foot - - - Spine - - - Pelvis - - - Mouth - - - Chin - - - Left ear - - - Right ear - - - Left eyeball - - - Right eyeball - - - Nose - - - Right upper arm - - - Right forearm - - - Left upper arm - - - Left forearm - - - Right hip - - - Right upper leg - - - Right lower leg - - - Left hip - - - Left upper leg - - - Left lower leg - - - Stomach - - - Left pectoral - - - Right pectoral - - - HUD Center position 2 - - - HUD Top-right - - - HUD Top - - - HUD Top-left - - - HUD Center - - - HUD Bottom-left - - - HUD Bottom - - - HUD Bottom-right - - - Neck - - - Avatar Center - - - Left Ring Finger - - - Right Ring Finger - - - Tail Base - - - Tail Tip - - - Left Wing - - - Right Wing - - - Jaw - - - Alt Left Ear - - - Alt Right Ear - - - Alt Left Eye - - - Alt Right Eye - - - Tongue - - - Groin - - - Left Hind Foot - - - Right Hind Foot - - - - Tree foliage types - - - - Pine1 tree - - - Oak tree - - - Tropical Bush1 - - - Palm1 tree - - - Dogwood tree - - - Tropical Bush2 - - - Palm2 tree - - - Cypress1 tree - - - Cypress2 tree - - - Pine2 tree - - - Plumeria - - - Winter pinetree1 - - - Winter Aspen tree - - - Winter pinetree2 - - - Eucalyptus tree - - - Fern - - - Eelgrass - - - Sea Sword - - - Kelp1 plant - - - Beach grass - - - Kelp2 plant - - - - Grass foliage types - - - - - - - - - - - - - - - - - - - - - - - Action associated with clicking on an object - - - - Touch object - - - Sit on object - - - Purchase object or contents - - - Pay the object - - - Open task inventory - - - Play parcel media - - - Open parcel media - - - - Type of physics representation used for this prim in the simulator - - - - Use prim physics form this object - - - No physics, prim doesn't collide - - - Use convex hull represantion of this prim - - - For thread safety - - - For thread safety - - - - Purges expired objects from the cache. Called automatically by the purge timer. - - - - - Convert this matrix to euler rotations - - X euler angle - Y euler angle - Z euler angle - - - - Convert this matrix to a quaternion rotation - - A quaternion representation of this rotation matrix - - - - Construct a matrix from euler rotation values in radians - - X euler angle in radians - Y euler angle in radians - Z euler angle in radians - - - - Get a formatted string representation of the vector - - A string representation of the vector - - - A 4x4 matrix containing all zeroes - - - A 4x4 identity matrix - - - X value - - - Y value - - - Z value - - - W value - - - - Build a quaternion from normalized float values - - X value from -1.0 to 1.0 - Y value from -1.0 to 1.0 - Z value from -1.0 to 1.0 - - - - Constructor, builds a quaternion object from a byte array - - Byte array containing four four-byte floats - Offset in the byte array to start reading at - Whether the source data is normalized or - not. If this is true 12 bytes will be read, otherwise 16 bytes will - be read. - - - - Normalizes the quaternion - - - - - Builds a quaternion object from a byte array - - The source byte array - Offset in the byte array to start reading at - Whether the source data is normalized or - not. If this is true 12 bytes will be read, otherwise 16 bytes will - be read. - - - - Normalize this quaternion and serialize it to a byte array - - A 12 byte array containing normalized X, Y, and Z floating - point values in order using little endian byte ordering - - - - Writes the raw bytes for this quaternion to a byte array - - Destination byte array - Position in the destination array to start - writing. Must be at least 12 bytes before the end of the array - - - - Convert this quaternion to euler angles - - X euler angle - Y euler angle - Z euler angle - - - - Convert this quaternion to an angle around an axis - - Unit vector describing the axis - Angle around the axis, in radians - - - - Returns the conjugate (spatial inverse) of a quaternion - - - - - Build a quaternion from an axis and an angle of rotation around - that axis - - - - - Build a quaternion from an axis and an angle of rotation around - that axis - - Axis of rotation - Angle of rotation - - - - Creates a quaternion from a vector containing roll, pitch, and yaw - in radians - - Vector representation of the euler angles in - radians - Quaternion representation of the euler angles - - - - Creates a quaternion from roll, pitch, and yaw euler angles in - radians - - X angle in radians - Y angle in radians - Z angle in radians - Quaternion representation of the euler angles - - - - Conjugates and renormalizes a vector - - - - - Spherical linear interpolation between two quaternions - - - - - Get a string representation of the quaternion elements with up to three - decimal digits and separated by spaces only - - Raw string representation of the quaternion - - - A quaternion with a value of 0,0,0,1 - - - - A hierarchical token bucket for bandwidth throttling. See - http://en.wikipedia.org/wiki/Token_bucket for more information - - - - Parent bucket to this bucket, or null if this is a root - bucket - - - Size of the bucket in bytes. If zero, the bucket has - infinite capacity - - - Rate that the bucket fills, in bytes per millisecond. If - zero, the bucket always remains full - - - Number of tokens currently in the bucket - - - Time of the last drip, in system ticks - - - - The parent bucket of this bucket, or null if this bucket has no - parent. The parent bucket will limit the aggregate bandwidth of all - of its children buckets - - - - - Maximum burst rate in bytes per second. This is the maximum number - of tokens that can accumulate in the bucket at any one time - - - - - The speed limit of this bucket in bytes per second. This is the - number of tokens that are added to the bucket per second - - Tokens are added to the bucket any time - is called, at the granularity of - the system tick interval (typically around 15-22ms) - - - - The number of bytes that can be sent at this moment. This is the - current number of tokens in the bucket - If this bucket has a parent bucket that does not have - enough tokens for a request, will - return false regardless of the content of this bucket - - - - - Default constructor - - Parent bucket if this is a child bucket, or - null if this is a root bucket - Maximum size of the bucket in bytes, or - zero if this bucket has no maximum capacity - Rate that the bucket fills, in bytes per - second. If zero, the bucket always remains full - - - - Remove a given number of tokens from the bucket - - Number of tokens to remove from the bucket - True if the requested number of tokens were removed from - the bucket, otherwise false - - - - Remove a given number of tokens from the bucket - - Number of tokens to remove from the bucket - True if tokens were added to the bucket - during this call, otherwise false - True if the requested number of tokens were removed from - the bucket, otherwise false - - - - Add tokens to the bucket over time. The number of tokens added each - call depends on the length of time that has passed since the last - call to Drip - - True if tokens were added to the bucket, otherwise false - - - - Operating system - - - - Unknown - - - Microsoft Windows - - - Microsoft Windows CE - - - Linux - - - Apple OSX - - - - Runtime platform - - - - .NET runtime - - - Mono runtime: http://www.mono-project.com/ - - - Used for converting degrees to radians - - - Used for converting radians to degrees - - - - Provide a single instance of the CultureInfo class to help - parsing in situations where the grid assumes an en-us culture - - - - UNIX epoch in DateTime format - - - - Provide a single instance of the MD5 class to avoid making - duplicate copies and handle thread safety - - - - - Provide a single instance of the SHA-1 class to avoid - making duplicate copies and handle thread safety - - - - - Provide a single instance of a random number generator - to avoid making duplicate copies and handle thread safety - - - - - Clamp a given value between a range - - Value to clamp - Minimum allowable value - Maximum allowable value - A value inclusively between lower and upper - - - - Clamp a given value between a range - - Value to clamp - Minimum allowable value - Maximum allowable value - A value inclusively between lower and upper - - - - Clamp a given value between a range - - Value to clamp - Minimum allowable value - Maximum allowable value - A value inclusively between lower and upper - - - - Round a floating-point value to the nearest integer - - Floating point number to round - Integer - - - - Test if a single precision float is a finite number - - - - - Test if a double precision float is a finite number - - - - - Get the distance between two floating-point values - - First value - Second value - The distance between the two values - - - - Compute the MD5 hash for a byte array - - Byte array to compute the hash for - MD5 hash of the input data - - - - Compute the SHA1 hash for a byte array - - Byte array to compute the hash for - SHA1 hash of the input data - - - - Calculate the SHA1 hash of a given string - - The string to hash - The SHA1 hash as a string - - - - Compute the SHA256 hash for a byte array - - Byte array to compute the hash for - SHA256 hash of the input data - - - - Calculate the SHA256 hash of a given string - - The string to hash - The SHA256 hash as a string - - - - Calculate the MD5 hash of a given string - - The string to hash - An MD5 hash in string format, with $1$ prepended - - - - Calculate the MD5 hash of a given string - - The string to hash - The MD5 hash as a string - - - - Calculates a PBKDF2 hash of a given string - - The string to hash - The PBKDF2 hash of the supplied string - - - - Generate a random double precision floating point value - - Random value of type double - - - - Get the current running platform - - Enumeration of the current platform we are running on - - - - Get the current running runtime - - Enumeration of the current runtime we are running on - - - - Convert the first two bytes starting in the byte array in - little endian ordering to a signed short integer - - An array two bytes or longer - A signed short integer, will be zero if a short can't be - read at the given position - - - - Convert the first two bytes starting at the given position in - little endian ordering to a signed short integer - - An array two bytes or longer - Position in the array to start reading - A signed short integer, will be zero if a short can't be - read at the given position - - - - Convert the first four bytes starting at the given position in - little endian ordering to a signed integer - - An array four bytes or longer - Position to start reading the int from - A signed integer, will be zero if an int can't be read - at the given position - - - - Convert the first four bytes of the given array in little endian - ordering to a signed integer - - An array four bytes or longer - A signed integer, will be zero if the array contains - less than four bytes - - - - Convert the first eight bytes of the given array in little endian - ordering to a signed long integer - - An array eight bytes or longer - A signed long integer, will be zero if the array contains - less than eight bytes - - - - Convert the first eight bytes starting at the given position in - little endian ordering to a signed long integer - - An array eight bytes or longer - Position to start reading the long from - A signed long integer, will be zero if a long can't be read - at the given position - - - - Convert the first two bytes starting at the given position in - little endian ordering to an unsigned short - - Byte array containing the ushort - Position to start reading the ushort from - An unsigned short, will be zero if a ushort can't be read - at the given position - - - - Convert two bytes in little endian ordering to an unsigned short - - Byte array containing the ushort - An unsigned short, will be zero if a ushort can't be - read - - - - Convert the first four bytes starting at the given position in - little endian ordering to an unsigned integer - - Byte array containing the uint - Position to start reading the uint from - An unsigned integer, will be zero if a uint can't be read - at the given position - - - - Convert the first four bytes of the given array in little endian - ordering to an unsigned integer - - An array four bytes or longer - An unsigned integer, will be zero if the array contains - less than four bytes - - - - Convert the first eight bytes of the given array in little endian - ordering to an unsigned 64-bit integer - - An array eight bytes or longer - An unsigned 64-bit integer, will be zero if the array - contains less than eight bytes - - - - Convert four bytes in little endian ordering to a floating point - value - - Byte array containing a little ending floating - point value - Starting position of the floating point value in - the byte array - Single precision value - - - - Convert an integer to a byte array in little endian format - - The integer to convert - A four byte little endian array - - - - Convert an integer to a byte array in big endian format - - The integer to convert - A four byte big endian array - - - - Convert a 64-bit integer to a byte array in little endian format - - The value to convert - An 8 byte little endian array - - - - Convert a 64-bit unsigned integer to a byte array in little endian - format - - The value to convert - An 8 byte little endian array - - - - Convert a floating point value to four bytes in little endian - ordering - - A floating point value - A four byte array containing the value in little endian - ordering - - - - Converts an unsigned integer to a hexadecimal string - - An unsigned integer to convert to a string - A hexadecimal string 10 characters long - 0x7fffffff - - - - Convert a variable length UTF8 byte array to a string - - The UTF8 encoded byte array to convert - The decoded string - - - - Converts a byte array to a string containing hexadecimal characters - - The byte array to convert to a string - The name of the field to prepend to each - line of the string - A string containing hexadecimal characters on multiple - lines. Each line is prepended with the field name - - - - Converts a byte array to a string containing hexadecimal characters - - The byte array to convert to a string - Number of bytes in the array to parse - A string to prepend to each line of the hex - dump - A string containing hexadecimal characters on multiple - lines. Each line is prepended with the field name - - - - Convert a string to a UTF8 encoded byte array - - The string to convert - A null-terminated UTF8 byte array - - - - Converts a string containing hexadecimal characters to a byte array - - String containing hexadecimal characters - If true, gracefully handles null, empty and - uneven strings as well as stripping unconvertable characters - The converted byte array - - - - Returns true is c is a hexadecimal digit (A-F, a-f, 0-9) - - Character to test - true if hex digit, false if not - - - - Converts 1 or 2 character string into equivalant byte value - - 1 or 2 character string - byte - - - - Convert a float value to a byte given a minimum and maximum range - - Value to convert to a byte - Minimum value range - Maximum value range - A single byte representing the original float value - - - - Convert a byte to a float value given a minimum and maximum range - - Byte array to get the byte from - Position in the byte array the desired byte is at - Minimum value range - Maximum value range - A float value inclusively between lower and upper - - - - Convert a byte to a float value given a minimum and maximum range - - Byte to convert to a float value - Minimum value range - Maximum value range - A float value inclusively between lower and upper - - - - Attempts to parse a floating point value from a string, using an - EN-US number format - - String to parse - Resulting floating point number - True if the parse was successful, otherwise false - - - - Attempts to parse a floating point value from a string, using an - EN-US number format - - String to parse - Resulting floating point number - True if the parse was successful, otherwise false - - - - Tries to parse an unsigned 32-bit integer from a hexadecimal string - - String to parse - Resulting integer - True if the parse was successful, otherwise false - - - - Returns text specified in EnumInfo attribute of the enumerator - To add the text use [EnumInfo(Text = "Some nice text here")] before declaration - of enum values - - Enum value - Text representation of the enum - - - - Takes an AssetType and returns the string representation - - The source - The string version of the AssetType - - - - Translate a string name of an AssetType into the proper Type - - A string containing the AssetType name - The AssetType which matches the string name, or AssetType.Unknown if no match was found - - - - Takes a FolderType and returns the string representation - - The source - The string version of the FolderType - - - - Translate a string name of an FolderType into the proper Type - - A string containing the FolderType name - The FolderType which matches the string name, or FolderType. None if no match was found - - - - Convert an InventoryType to a string - - The to convert - A string representation of the source - - - - Convert a string into a valid InventoryType - - A string representation of the InventoryType to convert - A InventoryType object which matched the type - - - - Convert a SaleType to a string - - The to convert - A string representation of the source - - - - Convert a string into a valid SaleType - - A string representation of the SaleType to convert - A SaleType object which matched the type - - - - Converts a string used in LLSD to AttachmentPoint type - - String representation of AttachmentPoint to convert - AttachmentPoint enum - - - - Copy a byte array - - Byte array to copy - A copy of the given byte array - - - - Packs to 32-bit unsigned integers in to a 64-bit unsigned integer - - The left-hand (or X) value - The right-hand (or Y) value - A 64-bit integer containing the two 32-bit input values - - - - Unpacks two 32-bit unsigned integers from a 64-bit unsigned integer - - The 64-bit input integer - The left-hand (or X) output value - The right-hand (or Y) output value - - - - Convert an IP address object to an unsigned 32-bit integer - - IP address to convert - 32-bit unsigned integer holding the IP address bits - - - - Gets a unix timestamp for the current time - - An unsigned integer representing a unix timestamp for now - - - - Convert a UNIX timestamp to a native DateTime object - - An unsigned integer representing a UNIX - timestamp - A DateTime object containing the same time specified in - the given timestamp - - - - Convert a UNIX timestamp to a native DateTime object - - A signed integer representing a UNIX - timestamp - A DateTime object containing the same time specified in - the given timestamp - - - - Convert a native DateTime object to a UNIX timestamp - - A DateTime object you want to convert to a - timestamp - An unsigned integer representing a UNIX timestamp - - - - Swap two values - - Type of the values to swap - First value - Second value - - - - Try to parse an enumeration value from a string - - Enumeration type - String value to parse - Enumeration value on success - True if the parsing succeeded, otherwise false - - - - Swaps the high and low words in a byte. Converts aaaabbbb to bbbbaaaa - - Byte to swap the words in - Byte value with the words swapped - - - - Attempts to convert a string representation of a hostname or IP - address to a - - Hostname to convert to an IPAddress - Converted IP address object, or null if the conversion - failed - - - - A 128-bit Universally Unique Identifier, used throughout the Second - Life networking protocol - - - - The System.Guid object this struct wraps around - - - - Constructor that takes a string UUID representation - - A string representation of a UUID, case - insensitive and can either be hyphenated or non-hyphenated - UUID("11f8aa9c-b071-4242-836b-13b7abe0d489") - - - - Constructor that takes a System.Guid object - - A Guid object that contains the unique identifier - to be represented by this UUID - - - - Constructor that takes a byte array containing a UUID - - Byte array containing a 16 byte UUID - Beginning offset in the array - - - - Constructor that takes an unsigned 64-bit unsigned integer to - convert to a UUID - - 64-bit unsigned integer to convert to a UUID - - - - Copy constructor - - UUID to copy - - - - IComparable.CompareTo implementation - - - - - Assigns this UUID from 16 bytes out of a byte array - - Byte array containing the UUID to assign this UUID to - Starting position of the UUID in the byte array - - - - Returns a copy of the raw bytes for this UUID - - A 16 byte array containing this UUID - - - - Writes the raw bytes for this UUID to a byte array - - Destination byte array - Position in the destination array to start - writing. Must be at least 16 bytes before the end of the array - - - - Calculate an LLCRC (cyclic redundancy check) for this UUID - - The CRC checksum for this UUID - - - - Create a 64-bit integer representation from the second half of this UUID - - An integer created from the last eight bytes of this UUID - - - - Generate a UUID from a string - - A string representation of a UUID, case - insensitive and can either be hyphenated or non-hyphenated - UUID.Parse("11f8aa9c-b071-4242-836b-13b7abe0d489") - - - - Generate a UUID from a string - - A string representation of a UUID, case - insensitive and can either be hyphenated or non-hyphenated - Will contain the parsed UUID if successful, - otherwise null - True if the string was successfully parse, otherwise false - UUID.TryParse("11f8aa9c-b071-4242-836b-13b7abe0d489", result) - - - - Combine two UUIDs together by taking the MD5 hash of a byte array - containing both UUIDs - - First UUID to combine - Second UUID to combine - The UUID product of the combination - - - - - - UUID - - - - Slower than Random(), but generates a cryptographically secure UUID - - UUID - - - - Return a hash code for this UUID, used by .NET for hash tables - - An integer composed of all the UUID bytes XORed together - - - - Comparison function - - An object to compare to this UUID - True if the object is a UUID and both UUIDs are equal - - - - Comparison function - - UUID to compare to - True if the UUIDs are equal, otherwise false - - - - Get a hyphenated string representation of this UUID - - A string representation of this UUID, lowercase and - with hyphens - 11f8aa9c-b071-4242-836b-13b7abe0d489 - - - - Equals operator - - First UUID for comparison - Second UUID for comparison - True if the UUIDs are byte for byte equal, otherwise false - - - - Not equals operator - - First UUID for comparison - Second UUID for comparison - True if the UUIDs are not equal, otherwise true - - - - XOR operator - - First UUID - Second UUID - A UUID that is a XOR combination of the two input UUIDs - - - - String typecasting operator - - A UUID in string form. Case insensitive, - hyphenated or non-hyphenated - A UUID built from the string representation - - - An UUID with a value of all zeroes - - - A cache of UUID.Zero as a string to optimize a common path - - - - A two-dimensional vector with floating-point values - - - - X value - - - Y value - - - - Test if this vector is equal to another vector, within a given - tolerance range - - Vector to test against - The acceptable magnitude of difference - between the two vectors - True if the magnitude of difference between the two vectors - is less than the given tolerance, otherwise false - - - - Test if this vector is composed of all finite numbers - - - - - IComparable.CompareTo implementation - - - - - Builds a vector from a byte array - - Byte array containing two four-byte floats - Beginning position in the byte array - - - - Returns the raw bytes for this vector - - An eight-byte array containing X and Y - - - - Writes the raw bytes for this vector to a byte array - - Destination byte array - Position in the destination array to start - writing. Must be at least 8 bytes before the end of the array - - - - Parse a vector from a string - - A string representation of a 2D vector, enclosed - in arrow brackets and separated by commas - - - - Interpolates between two vectors using a cubic equation - - - - - Get a formatted string representation of the vector - - A string representation of the vector - - - - Get a string representation of the vector elements with up to three - decimal digits and separated by spaces only - - Raw string representation of the vector - - - A vector with a value of 0,0 - - - A vector with a value of 1,1 - - - A vector with a value of 1,0 - - - A vector with a value of 0,1 - - - - A three-dimensional vector with floating-point values - - - - X value - - - Y value - - - Z value - - - - Constructor, builds a vector from a byte array - - Byte array containing three four-byte floats - Beginning position in the byte array - - - - Test if this vector is equal to another vector, within a given - tolerance range - - Vector to test against - The acceptable magnitude of difference - between the two vectors - True if the magnitude of difference between the two vectors - is less than the given tolerance, otherwise false - - - - IComparable.CompareTo implementation - - - - - Test if this vector is composed of all finite numbers - - - - - Builds a vector from a byte array - - Byte array containing a 12 byte vector - Beginning position in the byte array - - - - Returns the raw bytes for this vector - - A 12 byte array containing X, Y, and Z - - - - Writes the raw bytes for this vector to a byte array - - Destination byte array - Position in the destination array to start - writing. Must be at least 12 bytes before the end of the array - - - - Parse a vector from a string - - A string representation of a 3D vector, enclosed - in arrow brackets and separated by commas - - - - Calculate the rotation between two vectors - - Normalized directional vector (such as 1,0,0 for forward facing) - Normalized target vector - - - - Interpolates between two vectors using a cubic equation - - - - - Get a formatted string representation of the vector - - A string representation of the vector - - - - Get a string representation of the vector elements with up to three - decimal digits and separated by spaces only - - Raw string representation of the vector - - - - Cross product between two vectors - - - - - Explicit casting for Vector3d > Vector3 - - - - - - A vector with a value of 0,0,0 - - - A vector with a value of 1,1,1 - - - A unit vector facing forward (X axis), value 1,0,0 - - - A unit vector facing left (Y axis), value 0,1,0 - - - A unit vector facing up (Z axis), value 0,0,1 - - - - A three-dimensional vector with doubleing-point values - - - - X value - - - Y value - - - Z value - - - - Constructor, builds a vector from a byte array - - Byte array containing three eight-byte doubles - Beginning position in the byte array - - - - Test if this vector is equal to another vector, within a given - tolerance range - - Vector to test against - The acceptable magnitude of difference - between the two vectors - True if the magnitude of difference between the two vectors - is less than the given tolerance, otherwise false - - - - IComparable.CompareTo implementation - - - - - Test if this vector is composed of all finite numbers - - - - - Builds a vector from a byte array - - Byte array containing a 24 byte vector - Beginning position in the byte array - - - - Returns the raw bytes for this vector - - A 24 byte array containing X, Y, and Z - - - - Writes the raw bytes for this vector to a byte array - - Destination byte array - Position in the destination array to start - writing. Must be at least 24 bytes before the end of the array - - - - Parse a vector from a string - - A string representation of a 3D vector, enclosed - in arrow brackets and separated by commas - - - - Interpolates between two vectors using a cubic equation - - - - - Get a formatted string representation of the vector - - A string representation of the vector - - - - Get a string representation of the vector elements with up to three - decimal digits and separated by spaces only - - Raw string representation of the vector - - - - Cross product between two vectors - - - - - Implicit casting for Vector3 > Vector3d - - - - - - A vector with a value of 0,0,0 - - - A vector with a value of 1,1,1 - - - A unit vector facing forward (X axis), value of 1,0,0 - - - A unit vector facing left (Y axis), value of 0,1,0 - - - A unit vector facing up (Z axis), value of 0,0,1 - - - X value - - - Y value - - - Z value - - - W value - - - - Constructor, builds a vector from a byte array - - Byte array containing four four-byte floats - Beginning position in the byte array - - - - Test if this vector is equal to another vector, within a given - tolerance range - - Vector to test against - The acceptable magnitude of difference - between the two vectors - True if the magnitude of difference between the two vectors - is less than the given tolerance, otherwise false - - - - IComparable.CompareTo implementation - - - - - Test if this vector is composed of all finite numbers - - - - - Builds a vector from a byte array - - Byte array containing a 16 byte vector - Beginning position in the byte array - - - - Returns the raw bytes for this vector - - A 16 byte array containing X, Y, Z, and W - - - - Writes the raw bytes for this vector to a byte array - - Destination byte array - Position in the destination array to start - writing. Must be at least 16 bytes before the end of the array - - - - Get a string representation of the vector elements with up to three - decimal digits and separated by spaces only - - Raw string representation of the vector - - - A vector with a value of 0,0,0,0 - - - A vector with a value of 1,1,1,1 - - - A vector with a value of 1,0,0,0 - - - A vector with a value of 0,1,0,0 - - - A vector with a value of 0,0,1,0 - - - A vector with a value of 0,0,0,1 - - - diff --git a/LibreMetaverse.Types/LibreMetaverse.Types.csproj b/LibreMetaverse.Types/LibreMetaverse.Types.csproj index f34673f..eae1dd2 100644 --- a/LibreMetaverse.Types/LibreMetaverse.Types.csproj +++ b/LibreMetaverse.Types/LibreMetaverse.Types.csproj @@ -1,144 +1,51 @@  - Local - 14.0.25123 - 2.0 - {B37B02AD-0000-0000-0000-000000000000} - Debug LibreMetaverse.Types - JScript - Grid - IE50 - false + LibreMetaverse.Types + LibreMetaverse type library netstandard2.0;netstandard2.1;net5.0 Library LibreMetaverse true - AnyCPU;x64;x86 - - - True - 285212672 - False - TRACE;DEBUG - True - 4096 - False - ..\bin\ - False - False - False - 4 - False - 1591,1574,0419 - AnyCPU + true + snupkg + 0419,1574,1591 + x64;x86;AnyCPU + ..\bin\ - True - 285212672 - False TRACE;DEBUG - True - 4096 False - ..\bin\ - False - False - False - 4 - False - 1591,1574,0419 - AnyCPU - True - 285212672 - False TRACE;DEBUG - True - 4096 False - ..\bin\ - False - False - False - 4 - False - 1591,1574,0419 - AnyCPU - - True - 285212672 - False - TRACE - LibreMetaverse.Types.XML - False - 4096 - True - ..\bin\ - False - False - False - 4 - False - 1591,1574,0419 - AnyCPU + + TRACE;DEBUG + False - True - 285212672 - False - TRACE - LibreMetaverse.Types.XML - False - 4096 + true + pdbonly + TRACE True - ..\bin\ - False - False - False - 4 - False - 1591,1574,0419 - AnyCPU - True - 285212672 - False - TRACE - LibreMetaverse.Types.XML - False - 4096 + true + pdbonly + TRACE + True + + + true + pdbonly + TRACE True - ..\bin\ - False - False - False - 4 - False - 1591,1574,0419 - AnyCPU - + + + - - - True - - - - - - - - - 1.2.0 - Sjofn LLC, Openmetaverse Developers - Copyright © OpenMetaverse Developers 2008, 2017. Copyright © Sjofn LLC 2018-2021. All rights reserved. - LICENSE.txt - https://github.com/cinderblocks/libremetaverse - \ No newline at end of file diff --git a/LibreMetaverse.Types/LibreMetaverse.Types.nuspec b/LibreMetaverse.Types/LibreMetaverse.Types.nuspec deleted file mode 100644 index 2d87b09..0000000 --- a/LibreMetaverse.Types/LibreMetaverse.Types.nuspec +++ /dev/null @@ -1,15 +0,0 @@ - - - - LibreMetaverse.Types - $version$ - Cinder Biscuits - Cinder Biscuits - https://github.com/cinderblocks/libremetaverse/blob/master/LICENSE.txt - https://github.com/cinderblocks/libremetaverse - false - LibreMetaverse type library - Copyright 2017 - LMV OMV OpenMetaverse OpenSim Halcyon OpenMetaverseFoundation VirtualWorld Radegast SecondLife - - \ No newline at end of file diff --git a/LibreMetaverse.Types/Quaternion.cs b/LibreMetaverse.Types/Quaternion.cs index f4ffdf0..1dae88a 100644 --- a/LibreMetaverse.Types/Quaternion.cs +++ b/LibreMetaverse.Types/Quaternion.cs @@ -321,6 +321,15 @@ namespace OpenMetaverse //} } + /// + /// Convert quaternion to euler angles vector + /// + /// + public Vector3 ToEulerVector() { + GetEulerAngles(out float r, out float p, out float y); + return new Vector3(r, p, y); + } + /// /// Convert this quaternion to an angle around an axis /// diff --git a/LibreMetaverse/Imaging/NativeMethods.cs b/LibreMetaverse.Types/Ray.cs similarity index 50% rename from LibreMetaverse/Imaging/NativeMethods.cs rename to LibreMetaverse.Types/Ray.cs index 075508e..18fd694 100644 --- a/LibreMetaverse/Imaging/NativeMethods.cs +++ b/LibreMetaverse.Types/Ray.cs @@ -1,5 +1,5 @@ -/* - * Copyright (c) 2021, Sjofn LLC. +/* + * Copyright (c) 2006-2016, openmetaverse.co * All rights reserved. * * - Redistribution and use in source and binary forms, with or without @@ -24,48 +24,17 @@ * POSSIBILITY OF SUCH DAMAGE. */ -using System; -using System.Runtime.InteropServices; - -namespace LibreMetaverse.Imaging +namespace OpenMetaverse { - internal sealed partial class NativeMethods + public struct Ray { + public Vector3 Origin; + public Vector3 Direction; - #region Fields - - // Native library file name. - // If Linux, it will be converted to libOpenJpegDotNetNative.so - // If MacOSX, it will be converted to libOpenJpegDotNetNative.dylib - // If Windows, it will be available after call LoadLibrary. - // And this file name must not contain period. If it does, - // CLR does not add extension (.dll) and CLR fails to load library - internal const string NativeLibrary = "OpenJpegDotNetNative"; - - public const CallingConvention CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl; - - private static readonly WindowsLibraryLoader WindowsLibraryLoader = new WindowsLibraryLoader(); - - #endregion - - #region Constructors - - static NativeMethods() + public Ray(Vector3 origin, Vector3 direction) { - WindowsLibraryLoader.LoadLibraries(new[] - { - $"{NativeLibrary}" - }); + Origin = origin; + Direction = direction; } - - #endregion - - #region cstd - - [DllImport(NativeLibrary, CallingConvention = CallingConvention)] - public static extern IntPtr cstd_memcpy(IntPtr dest, IntPtr src, int count); - - #endregion - } } diff --git a/LibreMetaverse.Types/TokenBucket.cs b/LibreMetaverse.Types/TokenBucket.cs index 2b1b381..3dab44a 100644 --- a/LibreMetaverse.Types/TokenBucket.cs +++ b/LibreMetaverse.Types/TokenBucket.cs @@ -55,10 +55,7 @@ namespace OpenMetaverse /// parent. The parent bucket will limit the aggregate bandwidth of all /// of its children buckets /// - public TokenBucket Parent - { - get { return parent; } - } + public TokenBucket Parent => parent; /// /// Maximum burst rate in bytes per second. This is the maximum number @@ -66,8 +63,8 @@ namespace OpenMetaverse /// public int MaxBurst { - get { return maxBurst; } - set { maxBurst = (value >= 0 ? value : 0); } + get => maxBurst; + set => maxBurst = (value >= 0 ? value : 0); } /// @@ -75,11 +72,11 @@ namespace OpenMetaverse /// number of tokens that are added to the bucket per second /// /// Tokens are added to the bucket any time - /// is called, at the granularity of + /// is called, at the granularity of /// the system tick interval (typically around 15-22ms) public int DripRate { - get { return tokensPerMS * 1000; } + get => tokensPerMS * 1000; set { if (value == 0) @@ -95,13 +92,10 @@ namespace OpenMetaverse /// The number of bytes that can be sent at this moment. This is the /// current number of tokens in the bucket /// If this bucket has a parent bucket that does not have - /// enough tokens for a request, will + /// enough tokens for a request, will /// return false regardless of the content of this bucket /// - public int Content - { - get { return content; } - } + public int Content => content; #endregion Properties diff --git a/LibreMetaverse.Types/UUID.cs b/LibreMetaverse.Types/UUID.cs index 2ed7d65..1f76844 100644 --- a/LibreMetaverse.Types/UUID.cs +++ b/LibreMetaverse.Types/UUID.cs @@ -297,9 +297,8 @@ namespace OpenMetaverse /// True if the object is a UUID and both UUIDs are equal public override bool Equals(object o) { - if (!(o is UUID)) return false; + if (!(o is UUID uuid)) return false; - UUID uuid = (UUID)o; return Guid == uuid.Guid; } diff --git a/LibreMetaverse.Types/UtilsConversions.cs b/LibreMetaverse.Types/UtilsConversions.cs index 501f3a8..50f0cfc 100644 --- a/LibreMetaverse.Types/UtilsConversions.cs +++ b/LibreMetaverse.Types/UtilsConversions.cs @@ -25,6 +25,7 @@ */ using System; +using System.Collections; using System.Linq; using System.Net; using System.Text; @@ -654,7 +655,7 @@ namespace OpenMetaverse /// 0x7fffffff public static string UIntToHexString(uint i) { - return string.Format("{0:x8}", i); + return $"{i:x8}"; } /// @@ -680,7 +681,7 @@ namespace OpenMetaverse private static string GetString(byte[] bytes, int index, int count) { - string cnv = UTF8Encoding.UTF8.GetString(bytes, index, count); + string cnv = Encoding.UTF8.GetString(bytes, index, count); return InternStrings ? string.Intern(cnv) : cnv; } @@ -729,7 +730,7 @@ namespace OpenMetaverse if (j != 0) output.Append(' '); - output.Append(String.Format("{0:X2}", bytes[i + j])); + output.Append($"{bytes[i + j]:X2}"); } } } @@ -744,9 +745,11 @@ namespace OpenMetaverse /// A null-terminated UTF8 byte array public static byte[] StringToBytes(string str) { - if (String.IsNullOrEmpty(str)) { return EmptyBytes; } - if (!str.EndsWith("\0")) { str += "\0"; } - return UTF8Encoding.UTF8.GetBytes(str); + if (string.IsNullOrEmpty(str)) { return EmptyBytes; } + // HACK: Say it ain't so .NET5 + return str.EndsWith("\0", StringComparison.Ordinal) + ? Encoding.UTF8.GetBytes(str) + : Encoding.UTF8.GetBytes(str + '\0'); } /// @@ -801,14 +804,14 @@ namespace OpenMetaverse /// /// Character to test /// true if hex digit, false if not - private static bool IsHexDigit(Char c) + private static bool IsHexDigit(char c) { const int numA = 65; const int num0 = 48; int numChar; - c = Char.ToUpper(c); + c = char.ToUpper(c); numChar = Convert.ToInt32(c); if (numChar >= numA && numChar < (numA + 6)) @@ -1217,9 +1220,7 @@ namespace OpenMetaverse /// Second value public static void Swap(ref T lhs, ref T rhs) { - T temp = lhs; - lhs = rhs; - rhs = temp; + (lhs, rhs) = (rhs, lhs); } /// diff --git a/LibreMetaverse/AgentManager.cs b/LibreMetaverse/AgentManager.cs index 81b9e25..e7247cf 100644 --- a/LibreMetaverse/AgentManager.cs +++ b/LibreMetaverse/AgentManager.cs @@ -1,6 +1,6 @@ /* * Copyright (c) 2006-2016, openmetaverse.co - * Copyright (c) 2019-2021, Sjofn LLC + * Copyright (c) 2019-2022, Sjofn LLC * All rights reserved. * * - Redistribution and use in source and binary forms, with or without @@ -1271,24 +1271,24 @@ namespace OpenMetaverse /// Your (client) avatars /// "client", "agent", and "avatar" all represent the same thing - public UUID AgentID => id; + public UUID AgentID { get; private set; } /// Temporary assigned to this session, used for /// verifying our identity in packets - public UUID SessionID => sessionID; + public UUID SessionID { get; private set; } /// Shared secret that is never sent over the wire - public UUID SecureSessionID => secureSessionID; + public UUID SecureSessionID { get; private set; } /// Your (client) avatar ID, local to the current region/sim public uint LocalID => localID; /// Where the avatar started at login. Can be "last", "home" /// or a login - public string StartLocation => startLocation; + public string StartLocation { get; private set; } = string.Empty; /// The access level of this agent, usually M, PG or A - public string AgentAccess => agentAccess; + public string AgentAccess { get; private set; } = string.Empty; /// The CollisionPlane of Agent public Vector4 CollisionPlane => collisionPlane; @@ -1302,21 +1302,24 @@ namespace OpenMetaverse /// A which specifies the angular speed, and axis about which an Avatar is rotating. public Vector3 AngularVelocity => angularVelocity; + /// Region handle for 'home' region + public ulong HomeRegionHandle => home.RegionHandle; + /// Position avatar client will goto when login to 'home' or during /// teleport request to 'home' region. - public Vector3 HomePosition => homePosition; + public Vector3 HomePosition => home.Position; /// LookAt point saved/restored with HomePosition - public Vector3 HomeLookAt => homeLookAt; + public Vector3 HomeLookAt => home.LookAt; /// Avatar First Name (i.e. Philip) - public string FirstName => firstName; + public string FirstName { get; private set; } = string.Empty; /// Avatar Last Name (i.e. Linden) - public string LastName => lastName; + public string LastName { get; private set; } = string.Empty; /// LookAt point received with the login response message - public Vector3 LookAt => lookAt; + public Vector3 LookAt { get; private set; } /// Avatar Full Name (i.e. Philip Linden) public string Name @@ -1326,28 +1329,28 @@ namespace OpenMetaverse // This is a fairly common request, so assume the name doesn't // change mid-session and cache the result if (fullName == null || fullName.Length < 2) - fullName = $"{firstName} {lastName}"; + fullName = $"{FirstName} {LastName}"; return fullName; } } /// Gets the health of the agent - public float Health => health; + public float Health { get; private set; } /// Gets the current balance of the agent - public int Balance => balance; + public int Balance { get; private set; } /// Gets the local ID of the prim the agent is sitting on, /// zero if the avatar is not currently sitting public uint SittingOn => sittingOn; /// Gets the of the agents active group. - public UUID ActiveGroup => activeGroup; + public UUID ActiveGroup { get; private set; } /// Gets the Agents powers in the currently active group - public GroupPowers ActiveGroupPowers => activeGroupPowers; + public GroupPowers ActiveGroupPowers { get; private set; } /// Current status message for teleporting - public string TeleportMessage => teleportMessage; + public string TeleportMessage { get; private set; } = string.Empty; /// Current position of the agent as a relative offset from /// the simulator, or the parent object if we are sitting on something @@ -1467,25 +1470,11 @@ namespace OpenMetaverse #region Private Members - private UUID id; - private UUID sessionID; - private UUID secureSessionID; - private string startLocation = string.Empty; - private string agentAccess = string.Empty; - private Vector3 homePosition; - private Vector3 homeLookAt; - private Vector3 lookAt; - private string firstName = string.Empty; - private string lastName = string.Empty; + private HomeInfo home; private string fullName; - private string teleportMessage = string.Empty; private TeleportStatus teleportStat = TeleportStatus.None; private ManualResetEvent teleportEvent = new ManualResetEvent(false); private uint heightWidthGenCounter; - private float health; - private int balance; - private UUID activeGroup; - private GroupPowers activeGroupPowers; private Dictionary gestureCache = new Dictionary(); #endregion Private Members @@ -1580,17 +1569,17 @@ namespace OpenMetaverse { int group_id = message_chunk_group_id; message_chunk_group_id++; - if (message_chunk_group_id > 500) message_chunk_group_id = 1; + if (message_chunk_group_id > 500) { message_chunk_group_id = 1; } string[] chunks = message.SplitBy(900).ToArray(); int chunkid = 1; - foreach(string C in chunks) + foreach(string chunk in chunks) { string chunk_grouping = ""; if(hide_chunk_grouping == false) { - chunk_grouping = "[" + group_id.ToString() + "|" + chunkid.ToString() + "|"+chunks.Length.ToString()+"]"; + chunk_grouping = $"[{group_id}|{chunkid}|{chunks.Length}]"; } - Chat(""+ chunk_grouping+"" + C + "", channel, type, false); + Chat($"{chunk_grouping}{chunk}", channel, type, false); chunkid++; } } @@ -1600,7 +1589,7 @@ namespace OpenMetaverse { AgentData = { - AgentID = id, + AgentID = AgentID, SessionID = Client.Self.SessionID }, ChatData = @@ -2512,8 +2501,8 @@ namespace OpenMetaverse /// /// The Objects Simulator Local ID /// - /// - /// + /// + /// public void DeGrab(uint objectLocalID) { DeGrab(objectLocalID, TOUCH_INVALID_TEXCOORD, TOUCH_INVALID_TEXCOORD, @@ -2680,14 +2669,14 @@ namespace OpenMetaverse { AgentData = { - AgentID = id, + AgentID = AgentID, SessionID = Client.Self.SessionID }, MoneyData = { Description = Utils.StringToBytes(description), DestID = target, - SourceID = id, + SourceID = AgentID, TransactionType = (int) type, AggregatePermInventory = 0, AggregatePermNextOwner = 0, @@ -2979,7 +2968,7 @@ namespace OpenMetaverse teleportStat == TeleportStatus.Start || teleportStat == TeleportStatus.Progress) { - teleportMessage = "Teleport timed out."; + TeleportMessage = "Teleport timed out."; teleportStat = TeleportStatus.Failed; } @@ -3026,7 +3015,7 @@ namespace OpenMetaverse } else { - teleportMessage = "Unable to resolve name: " + simName; + TeleportMessage = "Unable to resolve name: " + simName; teleportStat = TeleportStatus.Failed; return false; } @@ -3089,7 +3078,7 @@ namespace OpenMetaverse teleportStat == TeleportStatus.Start || teleportStat == TeleportStatus.Progress) { - teleportMessage = "Teleport timed out."; + TeleportMessage = "Teleport timed out."; teleportStat = TeleportStatus.Failed; } @@ -3131,7 +3120,7 @@ namespace OpenMetaverse } else { - teleportMessage = "CAPS event queue is not running"; + TeleportMessage = "CAPS event queue is not running"; teleportEvent.Set(); teleportStat = TeleportStatus.Failed; } @@ -3175,7 +3164,7 @@ namespace OpenMetaverse { AgentData = { - AgentID = Client.Self.id, + AgentID = Client.Self.AgentID, SessionID = Client.Self.SessionID }, Info = @@ -3258,8 +3247,8 @@ namespace OpenMetaverse { AgentData = { - AgentID = id, - SessionID = sessionID + AgentID = AgentID, + SessionID = SessionID }, PropertiesData = { @@ -3286,8 +3275,8 @@ namespace OpenMetaverse { AgentData = { - AgentID = id, - SessionID = sessionID + AgentID = AgentID, + SessionID = SessionID }, PropertiesData = { @@ -3313,8 +3302,8 @@ namespace OpenMetaverse { AgentData = { - AgentID = id, - SessionID = sessionID + AgentID = AgentID, + SessionID = SessionID }, Data = { @@ -3628,7 +3617,7 @@ namespace OpenMetaverse AgentData = { AgentID = Client.Self.AgentID, - SessionID = Client.Self.sessionID + SessionID = Client.Self.SessionID }, Data = {PickID = pickID} }; @@ -3830,15 +3819,15 @@ namespace OpenMetaverse { bool success = true; - if (error == null && result is OSDMap) + if (error == null && result is OSDMap osdMap) { - var map = ((OSDMap)result)["access_prefs"]; - agentAccess = ((OSDMap)map)["max"]; - Logger.Log($"Max maturity access set to {agentAccess}", Helpers.LogLevel.Info, Client ); + var map = osdMap["access_prefs"]; + AgentAccess = ((OSDMap)map)["max"]; + Logger.Log($"Max maturity access set to {AgentAccess}", Helpers.LogLevel.Info, Client ); } else if (error == null) { - Logger.Log($"Max maturity unchanged at {agentAccess}", Helpers.LogLevel.Info, Client); + Logger.Log($"Max maturity unchanged at {AgentAccess}", Helpers.LogLevel.Info, Client); } else { @@ -3848,7 +3837,7 @@ namespace OpenMetaverse if (callback != null) { - try { callback(new AgentAccessEventArgs(success, agentAccess)); } + try { callback(new AgentAccessEventArgs(success, AgentAccess)); } catch { } // *TODO: So gross } @@ -3951,10 +3940,9 @@ namespace OpenMetaverse if (m_InstantMessage == null) return; // don't bother if we don't have any listeners - if (response == null || !(response is OSDMap respMap) - || respMap.Count == 0 || respMap.ContainsKey("messages")) + if (!(response is OSDMap respMap) || respMap.Count == 0 || respMap.ContainsKey("messages")) { - Logger.Log($"Failed to retrieve offline messages because the capability returned some goofy shit.", + Logger.Log("Failed to retrieve offline messages because the capability returned some goofy shit.", Helpers.LogLevel.Warning); RetrieveInstantMessagesLegacy(); return; @@ -3985,8 +3973,7 @@ namespace OpenMetaverse : new Vector3(msg["local_x"], msg["local_y"], msg["local_z"]); message.BinaryBucket = msg.ContainsKey("binary_bucket") ? msg["binary_bucket"].AsBinary() : new byte[] { 0 }; - message.GroupIM = msg.ContainsKey("from_group") - ? msg["from_group"].AsBoolean() : false; + message.GroupIM = msg.ContainsKey("from_group") && msg["from_group"].AsBoolean(); OnInstantMessage(new InstantMessageEventArgs(message, null)); } @@ -4135,7 +4122,7 @@ namespace OpenMetaverse protected void HealthHandler(object sender, PacketReceivedEventArgs e) { Packet packet = e.Packet; - health = ((HealthMessagePacket)packet).HealthData.Health; + Health = ((HealthMessagePacket)packet).HealthData.Health; } /// Process an incoming packet and raise the appropriate events @@ -4150,17 +4137,17 @@ namespace OpenMetaverse if (p.AgentData.AgentID == simulator.Client.Self.AgentID) { - firstName = Utils.BytesToString(p.AgentData.FirstName); - lastName = Utils.BytesToString(p.AgentData.LastName); - activeGroup = p.AgentData.ActiveGroupID; - activeGroupPowers = (GroupPowers)p.AgentData.GroupPowers; + FirstName = Utils.BytesToString(p.AgentData.FirstName); + LastName = Utils.BytesToString(p.AgentData.LastName); + ActiveGroup = p.AgentData.ActiveGroupID; + ActiveGroupPowers = (GroupPowers)p.AgentData.GroupPowers; if (m_AgentData == null) return; string groupTitle = Utils.BytesToString(p.AgentData.GroupTitle); string groupName = Utils.BytesToString(p.AgentData.GroupName); - OnAgentData(new AgentDataReplyEventArgs(firstName, lastName, activeGroup, groupTitle, activeGroupPowers, groupName)); + OnAgentData(new AgentDataReplyEventArgs(FirstName, LastName, ActiveGroup, groupTitle, ActiveGroupPowers, groupName)); } else { @@ -4179,7 +4166,7 @@ namespace OpenMetaverse if (packet.Type == PacketType.MoneyBalanceReply) { MoneyBalanceReplyPacket reply = (MoneyBalanceReplyPacket)packet; - this.balance = reply.MoneyData.MoneyBalance; + this.Balance = reply.MoneyData.MoneyBalance; if (m_MoneyBalance != null) { @@ -4206,7 +4193,7 @@ namespace OpenMetaverse if (m_Balance != null) { - OnBalance(new BalanceEventArgs(balance)); + OnBalance(new BalanceEventArgs(Balance)); } } @@ -4322,7 +4309,7 @@ namespace OpenMetaverse { TeleportStartPacket start = (TeleportStartPacket)packet; - teleportMessage = "Teleport started"; + TeleportMessage = "Teleport started"; flags = (TeleportFlags)start.Info.TeleportFlags; teleportStat = TeleportStatus.Start; @@ -4332,21 +4319,21 @@ namespace OpenMetaverse { TeleportProgressPacket progress = (TeleportProgressPacket)packet; - teleportMessage = Utils.BytesToString(progress.Info.Message); + TeleportMessage = Utils.BytesToString(progress.Info.Message); flags = (TeleportFlags)progress.Info.TeleportFlags; teleportStat = TeleportStatus.Progress; - Logger.DebugLog($"TeleportProgress received, Message: {teleportMessage}, Flags: {flags}", Client); + Logger.DebugLog($"TeleportProgress received, Message: {TeleportMessage}, Flags: {flags}", Client); } else if (packet.Type == PacketType.TeleportFailed) { TeleportFailedPacket failed = (TeleportFailedPacket)packet; - teleportMessage = Utils.BytesToString(failed.Info.Reason); + TeleportMessage = Utils.BytesToString(failed.Info.Reason); teleportStat = TeleportStatus.Failed; finished = true; - Logger.DebugLog($"TeleportFailed received, Reason: {teleportMessage}", Client); + Logger.DebugLog($"TeleportFailed received, Reason: {TeleportMessage}", Client); } else if (packet.Type == PacketType.TeleportFinish) { @@ -4365,25 +4352,25 @@ namespace OpenMetaverse if (newSimulator != null) { - teleportMessage = "Teleport finished"; + TeleportMessage = "Teleport finished"; teleportStat = TeleportStatus.Finished; Logger.Log($"Moved to new sim {newSimulator}", Helpers.LogLevel.Info, Client); } else { - teleportMessage = "Failed to connect to the new sim after a teleport"; + TeleportMessage = "Failed to connect to the new sim after a teleport"; teleportStat = TeleportStatus.Failed; // We're going to get disconnected now - Logger.Log(teleportMessage, Helpers.LogLevel.Error, Client); + Logger.Log(TeleportMessage, Helpers.LogLevel.Error, Client); } } else if (packet.Type == PacketType.TeleportCancel) { //TeleportCancelPacket cancel = (TeleportCancelPacket)packet; - teleportMessage = "Cancelled"; + TeleportMessage = "Cancelled"; teleportStat = TeleportStatus.Cancelled; finished = true; @@ -4393,7 +4380,7 @@ namespace OpenMetaverse { TeleportLocalPacket local = (TeleportLocalPacket)packet; - teleportMessage = "Teleport finished"; + TeleportMessage = "Teleport finished"; flags = (TeleportFlags)local.Info.TeleportFlags; teleportStat = TeleportStatus.Finished; relativePosition = local.Info.Position; @@ -4407,7 +4394,7 @@ namespace OpenMetaverse if (m_Teleport != null) { - OnTeleport(new TeleportEventArgs(teleportMessage, teleportStat, flags)); + OnTeleport(new TeleportEventArgs(TeleportMessage, teleportStat, flags)); } if (finished) teleportEvent.Set(); @@ -4493,17 +4480,16 @@ namespace OpenMetaverse private void Network_OnLoginResponse(bool loginSuccess, bool redirect, string message, string reason, LoginResponseData reply) { - id = reply.AgentID; - sessionID = reply.SessionID; - secureSessionID = reply.SecureSessionID; - firstName = reply.FirstName; - lastName = reply.LastName; - startLocation = reply.StartLocation; - agentAccess = reply.AgentAccess; + AgentID = reply.AgentID; + SessionID = reply.SessionID; + SecureSessionID = reply.SecureSessionID; + FirstName = reply.FirstName; + LastName = reply.LastName; + StartLocation = reply.StartLocation; + AgentAccess = reply.AgentAccess; Movement.Camera.LookDirection(reply.LookAt); - homePosition = reply.HomePosition; - homeLookAt = reply.HomeLookAt; - lookAt = reply.LookAt; + home = reply.Home; + LookAt = reply.LookAt; if (reply.Gestures != null) { diff --git a/LibreMetaverse/AgentManagerMovement.cs b/LibreMetaverse/AgentManagerMovement.cs index fa4dbdc..d16f227 100644 --- a/LibreMetaverse/AgentManagerMovement.cs +++ b/LibreMetaverse/AgentManagerMovement.cs @@ -377,10 +377,7 @@ namespace OpenMetaverse } } /// The current value of the agent control flags - public uint AgentControls - { - get { return agentControls; } - } + public uint AgentControls { get; private set; } /// Gets or sets the interval in milliseconds at which /// AgentUpdate packets are sent to the current simulator. Setting @@ -420,11 +417,7 @@ namespace OpenMetaverse } /// Reset movement controls every time we send an update - public bool AutoResetControls - { - get { return autoResetControls; } - set { autoResetControls = value; } - } + public bool AutoResetControls { get; set; } #endregion Properties @@ -459,13 +452,11 @@ namespace OpenMetaverse private bool alwaysRun; private GridClient Client; - private uint agentControls; private int duplicateCount; private AgentState lastState; /// Timer for sending AgentUpdate packets private Timer updateTimer; private int updateInterval; - private bool autoResetControls; /// Default constructor public AgentMovement(GridClient client) @@ -609,7 +600,7 @@ namespace OpenMetaverse Vector3 zAxis = Camera.UpAxis; // Attempted to sort these in a rough order of how often they might change - if (agentControls == 0 && + if (AgentControls == 0 && yAxis == LastCameraYAxis && origin == LastCameraCenter && State == lastState && @@ -652,12 +643,12 @@ namespace OpenMetaverse update.AgentData.CameraUpAxis = zAxis; update.AgentData.Far = Camera.Far; update.AgentData.State = (byte)State; - update.AgentData.ControlFlags = agentControls; + update.AgentData.ControlFlags = AgentControls; update.AgentData.Flags = (byte)Flags; Client.Network.SendPacket(update, simulator); - if (autoResetControls) { + if (AutoResetControls) { ResetControlFlags(); } } @@ -710,20 +701,20 @@ namespace OpenMetaverse private bool GetControlFlag(ControlFlags flag) { - return (agentControls & (uint)flag) != 0; + return (AgentControls & (uint)flag) != 0; } private void SetControlFlag(ControlFlags flag, bool value) { - if (value) agentControls |= (uint)flag; - else agentControls &= ~((uint)flag); + if (value) AgentControls |= (uint)flag; + else AgentControls &= ~((uint)flag); } public void ResetControlFlags() { // Reset all of the flags except for persistent settings like // away, fly, mouselook, and crouching - agentControls &= + AgentControls &= (uint)(ControlFlags.AGENT_CONTROL_AWAY | ControlFlags.AGENT_CONTROL_FLY | ControlFlags.AGENT_CONTROL_MOUSELOOK | diff --git a/LibreMetaverse/AppearanceManager.cs b/LibreMetaverse/AppearanceManager.cs index d2aa091..45ae186 100644 --- a/LibreMetaverse/AppearanceManager.cs +++ b/LibreMetaverse/AppearanceManager.cs @@ -30,7 +30,6 @@ using System.Collections.Generic; using System.Threading; using System.Linq; using System.Threading.Tasks; -using LibreMetaverse; using Microsoft.Collections.Extensions; using OpenMetaverse.Packets; using OpenMetaverse.Imaging; @@ -999,8 +998,8 @@ namespace OpenMetaverse } /// - /// Calls either or - /// depending on the value of + /// Calls either or + /// depending on the value of /// replaceItems /// /// List of wearable inventory items to add diff --git a/LibreMetaverse/AssetManager.cs b/LibreMetaverse/AssetManager.cs index ff5d567..b1374e2 100644 --- a/LibreMetaverse/AssetManager.cs +++ b/LibreMetaverse/AssetManager.cs @@ -28,7 +28,6 @@ using System; using System.Collections.Generic; using System.Threading; -using System.Net; using OpenMetaverse.Packets; using OpenMetaverse.Assets; using OpenMetaverse.Http; @@ -163,7 +162,7 @@ namespace OpenMetaverse { public UUID ID; public int Size; - public byte[] AssetData = Utils.EmptyBytes; + public byte[] AssetData; public int Transferred; public bool Success; public AssetType AssetType; diff --git a/LibreMetaverse/Assets/Archiving/ArchiveConstants.cs b/LibreMetaverse/Assets/Archiving/ArchiveConstants.cs index d9c0ae8..24a5a76 100644 --- a/LibreMetaverse/Assets/Archiving/ArchiveConstants.cs +++ b/LibreMetaverse/Assets/Archiving/ArchiveConstants.cs @@ -25,7 +25,6 @@ */ using System.Collections.Generic; -using OpenMetaverse; namespace OpenMetaverse.Assets { diff --git a/LibreMetaverse/Assets/Archiving/AssetsArchiver.cs b/LibreMetaverse/Assets/Archiving/AssetsArchiver.cs index 0aad995..7f78fc9 100644 --- a/LibreMetaverse/Assets/Archiving/AssetsArchiver.cs +++ b/LibreMetaverse/Assets/Archiving/AssetsArchiver.cs @@ -27,9 +27,7 @@ using System; using System.Collections.Generic; using System.IO; -using System.Reflection; using System.Xml; -using OpenMetaverse; namespace OpenMetaverse.Assets { diff --git a/LibreMetaverse/Assets/Archiving/OarFile.cs b/LibreMetaverse/Assets/Archiving/OarFile.cs index b1f5684..5f5ec35 100644 --- a/LibreMetaverse/Assets/Archiving/OarFile.cs +++ b/LibreMetaverse/Assets/Archiving/OarFile.cs @@ -28,10 +28,8 @@ using System; using System.Collections.Generic; using System.IO; using System.IO.Compression; -using System.Text; using System.Xml; using System.Threading; -using OpenMetaverse; namespace OpenMetaverse.Assets { diff --git a/LibreMetaverse/Assets/Archiving/TarArchiveReader.cs b/LibreMetaverse/Assets/Archiving/TarArchiveReader.cs index 88ca460..257dba8 100644 --- a/LibreMetaverse/Assets/Archiving/TarArchiveReader.cs +++ b/LibreMetaverse/Assets/Archiving/TarArchiveReader.cs @@ -26,7 +26,6 @@ using System; using System.IO; -using System.Reflection; using System.Text; namespace OpenMetaverse.Assets diff --git a/LibreMetaverse/Assets/Archiving/TarArchiveWriter.cs b/LibreMetaverse/Assets/Archiving/TarArchiveWriter.cs index 7cdfdcc..45ddbba 100644 --- a/LibreMetaverse/Assets/Archiving/TarArchiveWriter.cs +++ b/LibreMetaverse/Assets/Archiving/TarArchiveWriter.cs @@ -25,7 +25,6 @@ */ using System; -using System.Collections.Generic; using System.IO; using System.Text; diff --git a/LibreMetaverse/Assets/Asset.cs b/LibreMetaverse/Assets/Asset.cs index 4ee9511..7935dfb 100644 --- a/LibreMetaverse/Assets/Asset.cs +++ b/LibreMetaverse/Assets/Asset.cs @@ -24,9 +24,6 @@ * POSSIBILITY OF SUCH DAMAGE. */ -using System; -using OpenMetaverse; - namespace OpenMetaverse.Assets { /// diff --git a/LibreMetaverse/Assets/AssetTypes/AssetAnimation.cs b/LibreMetaverse/Assets/AssetTypes/AssetAnimation.cs index c47bf4e..ed4e223 100644 --- a/LibreMetaverse/Assets/AssetTypes/AssetAnimation.cs +++ b/LibreMetaverse/Assets/AssetTypes/AssetAnimation.cs @@ -24,9 +24,6 @@ * POSSIBILITY OF SUCH DAMAGE. */ -using System; -using OpenMetaverse; - namespace OpenMetaverse.Assets { /// diff --git a/LibreMetaverse/Assets/AssetTypes/AssetBodypart.cs b/LibreMetaverse/Assets/AssetTypes/AssetBodypart.cs index e45b932..71c46c4 100644 --- a/LibreMetaverse/Assets/AssetTypes/AssetBodypart.cs +++ b/LibreMetaverse/Assets/AssetTypes/AssetBodypart.cs @@ -24,9 +24,6 @@ * POSSIBILITY OF SUCH DAMAGE. */ -using System; -using OpenMetaverse; - namespace OpenMetaverse.Assets { /// diff --git a/LibreMetaverse/Assets/AssetTypes/AssetCallingCard.cs b/LibreMetaverse/Assets/AssetTypes/AssetCallingCard.cs index fefbbb6..5ee378f 100644 --- a/LibreMetaverse/Assets/AssetTypes/AssetCallingCard.cs +++ b/LibreMetaverse/Assets/AssetTypes/AssetCallingCard.cs @@ -25,7 +25,6 @@ */ using System; -using OpenMetaverse; namespace OpenMetaverse.Assets { diff --git a/LibreMetaverse/Assets/AssetTypes/AssetClothing.cs b/LibreMetaverse/Assets/AssetTypes/AssetClothing.cs index f040f7d..863468c 100644 --- a/LibreMetaverse/Assets/AssetTypes/AssetClothing.cs +++ b/LibreMetaverse/Assets/AssetTypes/AssetClothing.cs @@ -24,9 +24,6 @@ * POSSIBILITY OF SUCH DAMAGE. */ -using System; -using OpenMetaverse; - namespace OpenMetaverse.Assets { /// diff --git a/LibreMetaverse/Assets/AssetTypes/AssetGesture.cs b/LibreMetaverse/Assets/AssetTypes/AssetGesture.cs index 7e86d9e..398449d 100644 --- a/LibreMetaverse/Assets/AssetTypes/AssetGesture.cs +++ b/LibreMetaverse/Assets/AssetTypes/AssetGesture.cs @@ -27,8 +27,6 @@ using System; using System.Collections.Generic; using System.Text; -using System.Text.RegularExpressions; -using OpenMetaverse; namespace OpenMetaverse.Assets { diff --git a/LibreMetaverse/Assets/AssetTypes/AssetLandmark.cs b/LibreMetaverse/Assets/AssetTypes/AssetLandmark.cs index e9aeb19..f8ec9af 100644 --- a/LibreMetaverse/Assets/AssetTypes/AssetLandmark.cs +++ b/LibreMetaverse/Assets/AssetTypes/AssetLandmark.cs @@ -25,7 +25,6 @@ */ using System; -using OpenMetaverse; namespace OpenMetaverse.Assets { diff --git a/LibreMetaverse/Assets/AssetTypes/AssetMutable.cs b/LibreMetaverse/Assets/AssetTypes/AssetMutable.cs index b74f1c1..0525539 100644 --- a/LibreMetaverse/Assets/AssetTypes/AssetMutable.cs +++ b/LibreMetaverse/Assets/AssetTypes/AssetMutable.cs @@ -24,9 +24,6 @@ * POSSIBILITY OF SUCH DAMAGE. */ -using System; -using OpenMetaverse; - namespace OpenMetaverse.Assets { /// diff --git a/LibreMetaverse/Assets/AssetTypes/AssetNotecard.cs b/LibreMetaverse/Assets/AssetTypes/AssetNotecard.cs index 6db3058..2a5e2ea 100644 --- a/LibreMetaverse/Assets/AssetTypes/AssetNotecard.cs +++ b/LibreMetaverse/Assets/AssetTypes/AssetNotecard.cs @@ -28,7 +28,6 @@ using System; using System.Collections.Generic; using System.Text; using System.Text.RegularExpressions; -using OpenMetaverse; namespace OpenMetaverse.Assets { diff --git a/LibreMetaverse/Assets/AssetTypes/AssetPrim.cs b/LibreMetaverse/Assets/AssetTypes/AssetPrim.cs index d6f475d..b5bb560 100644 --- a/LibreMetaverse/Assets/AssetTypes/AssetPrim.cs +++ b/LibreMetaverse/Assets/AssetTypes/AssetPrim.cs @@ -28,7 +28,6 @@ using System; using System.Collections.Generic; using System.IO; using System.Xml; -using OpenMetaverse; using OpenMetaverse.StructuredData; namespace OpenMetaverse.Assets diff --git a/LibreMetaverse/Assets/AssetTypes/AssetScriptBinary.cs b/LibreMetaverse/Assets/AssetTypes/AssetScriptBinary.cs index 1953bff..886de29 100644 --- a/LibreMetaverse/Assets/AssetTypes/AssetScriptBinary.cs +++ b/LibreMetaverse/Assets/AssetTypes/AssetScriptBinary.cs @@ -24,9 +24,6 @@ * POSSIBILITY OF SUCH DAMAGE. */ -using System; -using OpenMetaverse; - namespace OpenMetaverse.Assets { /// diff --git a/LibreMetaverse/Assets/AssetTypes/AssetScriptText.cs b/LibreMetaverse/Assets/AssetTypes/AssetScriptText.cs index b7aa240..563a65f 100644 --- a/LibreMetaverse/Assets/AssetTypes/AssetScriptText.cs +++ b/LibreMetaverse/Assets/AssetTypes/AssetScriptText.cs @@ -24,9 +24,6 @@ * POSSIBILITY OF SUCH DAMAGE. */ -using System; -using OpenMetaverse; - namespace OpenMetaverse.Assets { /// diff --git a/LibreMetaverse/Assets/AssetTypes/AssetTexture.cs b/LibreMetaverse/Assets/AssetTypes/AssetTexture.cs index 5514968..eec2b33 100644 --- a/LibreMetaverse/Assets/AssetTypes/AssetTexture.cs +++ b/LibreMetaverse/Assets/AssetTypes/AssetTexture.cs @@ -1,6 +1,6 @@ /* * Copyright (c) 2006-2016, openmetaverse.co - * Copyright (c) 2021, Sjofn LLC. + * Copyright (c) 2021-2022, Sjofn LLC. * All rights reserved. * * - Redistribution and use in source and binary forms, with or without @@ -25,7 +25,6 @@ * POSSIBILITY OF SUCH DAMAGE. */ -using System; using OpenMetaverse.Imaging; namespace OpenMetaverse.Assets diff --git a/LibreMetaverse/Assets/AssetTypes/AssetWearable.cs b/LibreMetaverse/Assets/AssetTypes/AssetWearable.cs index c1f3411..67a8c6e 100644 --- a/LibreMetaverse/Assets/AssetTypes/AssetWearable.cs +++ b/LibreMetaverse/Assets/AssetTypes/AssetWearable.cs @@ -27,7 +27,6 @@ using System; using System.Collections.Generic; using System.Text; -using OpenMetaverse; namespace OpenMetaverse.Assets { diff --git a/LibreMetaverse/AvatarManager.cs b/LibreMetaverse/AvatarManager.cs index 2ad4de0..c287647 100644 --- a/LibreMetaverse/AvatarManager.cs +++ b/LibreMetaverse/AvatarManager.cs @@ -1,6 +1,6 @@ /* * Copyright (c) 2006-2016, openmetaverse.co - * Copyright (c) 2021, Sjofn LLC. + * Copyright (c) 2021-2022, Sjofn LLC. * All rights reserved. * * - Redistribution and use in source and binary forms, with or without diff --git a/LibreMetaverse/BitPack.cs b/LibreMetaverse/BitPack.cs index 8134a36..65cb070 100644 --- a/LibreMetaverse/BitPack.cs +++ b/LibreMetaverse/BitPack.cs @@ -43,14 +43,14 @@ namespace OpenMetaverse { get { - if (bytePos != 0 && bitPos == 0) + if (bytePos != 0 && BitPos == 0) return bytePos - 1; return bytePos; } } /// - public int BitPos => bitPos; + public int BitPos { get; private set; } private const int MAX_BITS = 8; @@ -58,8 +58,7 @@ namespace OpenMetaverse private static readonly byte[] Off = { 0 }; private int bytePos; - private int bitPos; - + /// /// Default constructor, initialize the bit packer / bit unpacker /// with a byte array and starting position @@ -301,7 +300,7 @@ namespace OpenMetaverse public string UnpackString(int size) { - if (bitPos != 0 || bytePos + size > Data.Length) throw new IndexOutOfRangeException(); + if (BitPos != 0 || bytePos + size > Data.Length) throw new IndexOutOfRangeException(); string str = System.Text.Encoding.UTF8.GetString(Data, bytePos, size); bytePos += size; @@ -310,7 +309,7 @@ namespace OpenMetaverse public UUID UnpackUUID() { - if (bitPos != 0) throw new IndexOutOfRangeException(); + if (BitPos != 0) throw new IndexOutOfRangeException(); UUID val = new UUID(Data, bytePos); bytePos += 16; @@ -338,7 +337,7 @@ namespace OpenMetaverse while (count > 0) { - byte curBit = (byte)(0x80 >> bitPos); + byte curBit = (byte)(0x80 >> BitPos); if ((data[curBytePos] & (0x01 << (count - 1))) != 0) Data[bytePos] |= curBit; @@ -346,12 +345,12 @@ namespace OpenMetaverse Data[bytePos] &= (byte)~curBit; --count; - ++bitPos; + ++BitPos; ++curBitPos; - if (bitPos >= MAX_BITS) + if (BitPos >= MAX_BITS) { - bitPos = 0; + BitPos = 0; ++bytePos; } if (curBitPos >= MAX_BITS) @@ -389,15 +388,15 @@ namespace OpenMetaverse output[curBytePos] <<= 1; // Grab one bit - if ((Data[bytePos] & (0x80 >> bitPos++)) != 0) + if ((Data[bytePos] & (0x80 >> BitPos++)) != 0) ++output[curBytePos]; --count; ++curBitPos; - if (bitPos >= MAX_BITS) + if (BitPos >= MAX_BITS) { - bitPos = 0; + BitPos = 0; ++bytePos; } if (curBitPos >= MAX_BITS) diff --git a/LibreMetaverse/Capabilities/CapsBase.cs b/LibreMetaverse/Capabilities/CapsBase.cs index 8f3da07..c9076db 100644 --- a/LibreMetaverse/Capabilities/CapsBase.cs +++ b/LibreMetaverse/Capabilities/CapsBase.cs @@ -1,6 +1,6 @@ /* * Copyright (c) 2006-2016, openmetaverse.co - * Copyright (c) 2019-2021, Sjofn LLC. + * Copyright (c) 2019-2022, Sjofn LLC. * All rights reserved. * * - Redistribution and use in source and binary forms, with or without @@ -279,7 +279,7 @@ namespace OpenMetaverse.Http int totalBytesRead = 0; int totalSize = nolength ? 0 : size; - while ((bytesRead = responseStream.Read(buffer, offset, size)) != 0) + while (responseStream != null && (bytesRead = responseStream.Read(buffer, offset, size)) != 0) { totalBytesRead += bytesRead; diff --git a/LibreMetaverse/Capabilities/CapsClient.cs b/LibreMetaverse/Capabilities/CapsClient.cs index 9a374e8..de5d78b 100644 --- a/LibreMetaverse/Capabilities/CapsClient.cs +++ b/LibreMetaverse/Capabilities/CapsClient.cs @@ -1,6 +1,6 @@ /* * Copyright (c) 2006-2016, openmetaverse.co - * Copyright (c) 2019-2021, Sjofn, LLC. + * Copyright (c) 2019-2022, Sjofn, LLC. * All rights reserved. * * - Redistribution and use in source and binary forms, with or without diff --git a/LibreMetaverse/DirectoryManager.cs b/LibreMetaverse/DirectoryManager.cs index 01798d9..fdc964d 100644 --- a/LibreMetaverse/DirectoryManager.cs +++ b/LibreMetaverse/DirectoryManager.cs @@ -355,7 +355,7 @@ namespace OpenMetaverse } /// - /// Parcel information returned from a request + /// Parcel information returned from a request /// /// Represents one of the following: /// A parcel of land on the grid that has its Show In Search flag set @@ -514,8 +514,7 @@ namespace OpenMetaverse protected virtual void OnEventInfo(EventInfoReplyEventArgs e) { EventHandler handler = m_EventInfoReply; - if (handler != null) - handler(this, e); + handler?.Invoke(this, e); } /// Thread sync lock object @@ -537,21 +536,20 @@ namespace OpenMetaverse protected virtual void OnDirEvents(DirEventsReplyEventArgs e) { EventHandler handler = m_DirEvents; - if (handler != null) - handler(this, e); + handler?.Invoke(this, e); } /// Thread sync lock object private readonly object m_DirEventsLock = new object(); - /// Raised when the data server responds to a request. + /// Raised when the data server responds to a request. public event EventHandler DirEventsReply { add { lock (m_DirEventsLock) { m_DirEvents += value; } } remove { lock (m_DirEventsLock) { m_DirEvents -= value; } } } - /// The event subscribers. null if no subcribers + /// The event subscribers. null if no subscribers private EventHandler m_Places; /// Raises the PlacesReply event @@ -560,21 +558,20 @@ namespace OpenMetaverse protected virtual void OnPlaces(PlacesReplyEventArgs e) { EventHandler handler = m_Places; - if (handler != null) - handler(this, e); + handler?.Invoke(this, e); } /// Thread sync lock object private readonly object m_PlacesLock = new object(); - /// Raised when the data server responds to a request. + /// Raised when the data server responds to a request. public event EventHandler PlacesReply { add { lock (m_PlacesLock) { m_Places += value; } } remove { lock (m_PlacesLock) { m_Places -= value; } } } - /// The event subscribers. null if no subcribers + /// The event subscribers. null if no subscribers private EventHandler m_DirPlaces; /// Raises the DirPlacesReply event @@ -583,14 +580,13 @@ namespace OpenMetaverse protected virtual void OnDirPlaces(DirPlacesReplyEventArgs e) { EventHandler handler = m_DirPlaces; - if (handler != null) - handler(this, e); + handler?.Invoke(this, e); } /// Thread sync lock object private readonly object m_DirPlacesLock = new object(); - /// Raised when the data server responds to a request. + /// Raised when the data server responds to a request. public event EventHandler DirPlacesReply { add { lock (m_DirPlacesLock) { m_DirPlaces += value; } } @@ -606,14 +602,13 @@ namespace OpenMetaverse protected virtual void OnDirClassifieds(DirClassifiedsReplyEventArgs e) { EventHandler handler = m_DirClassifieds; - if (handler != null) - handler(this, e); + handler?.Invoke(this, e); } /// Thread sync lock object private readonly object m_DirClassifiedsLock = new object(); - /// Raised when the data server responds to a request. + /// Raised when the data server responds to a request. public event EventHandler DirClassifiedsReply { add { lock (m_DirClassifiedsLock) { m_DirClassifieds += value; } } @@ -629,14 +624,13 @@ namespace OpenMetaverse protected virtual void OnDirGroups(DirGroupsReplyEventArgs e) { EventHandler handler = m_DirGroups; - if (handler != null) - handler(this, e); + handler?.Invoke(this, e); } /// Thread sync lock object private readonly object m_DirGroupsLock = new object(); - /// Raised when the data server responds to a request. + /// Raised when the data server responds to a request. public event EventHandler DirGroupsReply { add { lock (m_DirGroupsLock) { m_DirGroups += value; } } @@ -652,14 +646,13 @@ namespace OpenMetaverse protected virtual void OnDirPeople(DirPeopleReplyEventArgs e) { EventHandler handler = m_DirPeople; - if (handler != null) - handler(this, e); + handler?.Invoke(this, e); } /// Thread sync lock object private readonly object m_DirPeopleLock = new object(); - /// Raised when the data server responds to a request. + /// Raised when the data server responds to a request. public event EventHandler DirPeopleReply { add { lock (m_DirPeopleLock) { m_DirPeople += value; } } @@ -675,14 +668,13 @@ namespace OpenMetaverse protected virtual void OnDirLand(DirLandReplyEventArgs e) { EventHandler handler = m_DirLandReply; - if (handler != null) - handler(this, e); + handler?.Invoke(this, e); } /// Thread sync lock object private readonly object m_DirLandLock = new object(); - /// Raised when the data server responds to a request. + /// Raised when the data server responds to a request. public event EventHandler DirLandReply { add { lock (m_DirLandLock) { m_DirLandReply += value; } } @@ -1446,32 +1438,27 @@ namespace OpenMetaverse /// Contains the Event data returned from the data server from an EventInfoRequest public class EventInfoReplyEventArgs : EventArgs { - private readonly DirectoryManager.EventInfo m_MatchedEvent; - /// /// A single EventInfo object containing the details of an event /// - public DirectoryManager.EventInfo MatchedEvent { get { return m_MatchedEvent; } } + public DirectoryManager.EventInfo MatchedEvent { get; } /// Construct a new instance of the EventInfoReplyEventArgs class /// A single EventInfo object containing the details of an event public EventInfoReplyEventArgs(DirectoryManager.EventInfo matchedEvent) { - this.m_MatchedEvent = matchedEvent; + this.MatchedEvent = matchedEvent; } } /// Contains the "Event" detail data returned from the data server public class DirEventsReplyEventArgs : EventArgs { - private readonly UUID m_QueryID; /// The ID returned by - public UUID QueryID { get { return m_QueryID; } } - - private readonly List m_matchedEvents; + public UUID QueryID { get; } /// A list of "Events" returned by the data server - public List MatchedEvents { get { return m_matchedEvents; } } + public List MatchedEvents { get; } /// Construct a new instance of the DirEventsReplyEventArgs class /// The ID of the query returned by the data server. @@ -1479,22 +1466,19 @@ namespace OpenMetaverse /// A list containing the "Events" returned by the search query public DirEventsReplyEventArgs(UUID queryID, List matchedEvents) { - this.m_QueryID = queryID; - this.m_matchedEvents = matchedEvents; + this.QueryID = queryID; + this.MatchedEvents = matchedEvents; } } /// Contains the "Event" list data returned from the data server public class PlacesReplyEventArgs : EventArgs { - private readonly UUID m_QueryID; /// The ID returned by - public UUID QueryID { get { return m_QueryID; } } - - private readonly List m_MatchedPlaces; + public UUID QueryID { get; } /// A list of "Places" returned by the data server - public List MatchedPlaces { get { return m_MatchedPlaces; } } + public List MatchedPlaces { get; } /// Construct a new instance of PlacesReplyEventArgs class /// The ID of the query returned by the data server. @@ -1502,60 +1486,53 @@ namespace OpenMetaverse /// A list containing the "Places" returned by the data server query public PlacesReplyEventArgs(UUID queryID, List matchedPlaces) { - this.m_QueryID = queryID; - this.m_MatchedPlaces = matchedPlaces; + this.QueryID = queryID; + this.MatchedPlaces = matchedPlaces; } } /// Contains the places data returned from the data server public class DirPlacesReplyEventArgs : EventArgs { - private readonly UUID m_QueryID; /// The ID returned by - public UUID QueryID { get { return m_QueryID; } } - - private readonly List m_MatchedParcels; + public UUID QueryID { get; } /// A list containing Places data returned by the data server - public List MatchedParcels { get { return m_MatchedParcels; } } - + public List MatchedParcels { get; } + /// Construct a new instance of the DirPlacesReplyEventArgs class /// The ID of the query returned by the data server. /// This will correlate to the ID returned by the method /// A list containing land data returned by the data server public DirPlacesReplyEventArgs(UUID queryID, List matchedParcels) { - this.m_QueryID = queryID; - this.m_MatchedParcels = matchedParcels; + this.QueryID = queryID; + this.MatchedParcels = matchedParcels; } } /// Contains the classified data returned from the data server public class DirClassifiedsReplyEventArgs : EventArgs { - private readonly List m_Classifieds; /// A list containing Classified Ads returned by the data server - public List Classifieds { get { return m_Classifieds; } } + public List Classifieds { get; } /// Construct a new instance of the DirClassifiedsReplyEventArgs class /// A list of classified ad data returned from the data server public DirClassifiedsReplyEventArgs(List classifieds) { - this.m_Classifieds = classifieds; + this.Classifieds = classifieds; } } /// Contains the group data returned from the data server public class DirGroupsReplyEventArgs : EventArgs { - private readonly UUID m_QueryID; /// The ID returned by - public UUID QueryID { get { return m_QueryID; } } - - private readonly List m_matchedGroups; + public UUID QueryID { get; } /// A list containing Groups data returned by the data server - public List MatchedGroups { get { return m_matchedGroups; } } + public List MatchedGroups { get; } /// Construct a new instance of the DirGroupsReplyEventArgs class /// The ID of the query returned by the data server. @@ -1563,22 +1540,19 @@ namespace OpenMetaverse /// A list of groups data returned by the data server public DirGroupsReplyEventArgs(UUID queryID, List matchedGroups) { - this.m_QueryID = queryID; - this.m_matchedGroups = matchedGroups; + this.QueryID = queryID; + this.MatchedGroups = matchedGroups; } } /// Contains the people data returned from the data server public class DirPeopleReplyEventArgs : EventArgs { - private readonly UUID m_QueryID; /// The ID returned by - public UUID QueryID { get { return m_QueryID; } } - - private readonly List m_MatchedPeople; + public UUID QueryID { get; } /// A list containing People data returned by the data server - public List MatchedPeople { get { return m_MatchedPeople; } } + public List MatchedPeople { get; } /// Construct a new instance of the DirPeopleReplyEventArgs class /// The ID of the query returned by the data server. @@ -1586,24 +1560,22 @@ namespace OpenMetaverse /// A list of people data returned by the data server public DirPeopleReplyEventArgs(UUID queryID, List matchedPeople) { - this.m_QueryID = queryID; - this.m_MatchedPeople = matchedPeople; + this.QueryID = queryID; + this.MatchedPeople = matchedPeople; } } /// Contains the land sales data returned from the data server public class DirLandReplyEventArgs : EventArgs { - private readonly List m_DirParcels; - /// A list containing land forsale data returned by the data server - public List DirParcels { get { return m_DirParcels; } } + public List DirParcels { get; } /// Construct a new instance of the DirLandReplyEventArgs class /// A list of parcels for sale returned by the data server public DirLandReplyEventArgs(List dirParcels) { - this.m_DirParcels = dirParcels; + this.DirParcels = dirParcels; } } #endregion diff --git a/LibreMetaverse/DownloadManager.cs b/LibreMetaverse/DownloadManager.cs index bdc76b0..806fc54 100644 --- a/LibreMetaverse/DownloadManager.cs +++ b/LibreMetaverse/DownloadManager.cs @@ -130,7 +130,7 @@ namespace OpenMetaverse request.ClientCertificates.Add(ClientCert); // Leave idle connections to this endpoint open for up to 60 seconds - request.ServicePoint.MaxIdleTime = 0; + request.ServicePoint.MaxIdleTime = 1000 * 60; // Disable stupid Expect-100: Continue header request.ServicePoint.Expect100Continue = false; // Crank up the max number of connections per endpoint diff --git a/LibreMetaverse/EstateTools.cs b/LibreMetaverse/EstateTools.cs index 1930e74..a498e8d 100644 --- a/LibreMetaverse/EstateTools.cs +++ b/LibreMetaverse/EstateTools.cs @@ -984,72 +984,66 @@ namespace OpenMetaverse /// Raised on LandStatReply when the report type is for "top colliders" public class TopCollidersReplyEventArgs : EventArgs { - private readonly int m_objectCount; - private readonly Dictionary m_Tasks; - /// /// The number of returned items in LandStatReply /// - public int ObjectCount { get { return m_objectCount; } } + public int ObjectCount { get; } + /// /// A Dictionary of Object UUIDs to tasks returned in LandStatReply /// - public Dictionary Tasks { get { return m_Tasks; } } + public Dictionary Tasks { get; } /// Construct a new instance of the TopCollidersReplyEventArgs class /// The number of returned items in LandStatReply /// Dictionary of Object UUIDs to tasks returned in LandStatReply public TopCollidersReplyEventArgs(int objectCount, Dictionary tasks) { - this.m_objectCount = objectCount; - this.m_Tasks = tasks; + this.ObjectCount = objectCount; + this.Tasks = tasks; } } /// Raised on LandStatReply when the report type is for "top Scripts" public class TopScriptsReplyEventArgs : EventArgs { - private readonly int m_objectCount; - private readonly Dictionary m_Tasks; - /// /// The number of scripts returned in LandStatReply /// - public int ObjectCount { get { return m_objectCount; } } + public int ObjectCount { get; } + /// /// A Dictionary of Object UUIDs to tasks returned in LandStatReply /// - public Dictionary Tasks { get { return m_Tasks; } } + public Dictionary Tasks { get; } /// Construct a new instance of the TopScriptsReplyEventArgs class /// The number of returned items in LandStatReply /// Dictionary of Object UUIDs to tasks returned in LandStatReply public TopScriptsReplyEventArgs(int objectCount, Dictionary tasks) { - this.m_objectCount = objectCount; - this.m_Tasks = tasks; + this.ObjectCount = objectCount; + this.Tasks = tasks; } } /// Returned, along with other info, upon a successful .RequestInfo() public class EstateBansReplyEventArgs : EventArgs { - private readonly uint m_estateID; - private readonly int m_count; - private readonly List m_banned; - /// /// The identifier of the estate /// - public uint EstateID { get { return m_estateID; } } + public uint EstateID { get; } + /// /// The number of returned itmes /// - public int Count { get { return m_count; } } + public int Count { get; } + /// /// List of UUIDs of Banned Users /// - public List Banned { get { return m_banned; } } + public List Banned { get; } /// Construct a new instance of the EstateBansReplyEventArgs class /// The estate's identifier on the grid @@ -1057,31 +1051,29 @@ namespace OpenMetaverse /// User UUIDs banned public EstateBansReplyEventArgs(uint estateID, int count, List banned) { - this.m_estateID = estateID; - this.m_count = count; - this.m_banned = banned; + this.EstateID = estateID; + this.Count = count; + this.Banned = banned; } } /// Returned, along with other info, upon a successful .RequestInfo() public class EstateUsersReplyEventArgs : EventArgs { - private readonly uint m_estateID; - private readonly int m_count; - private readonly List m_allowedUsers; - /// /// The identifier of the estate /// - public uint EstateID { get { return m_estateID; } } + public uint EstateID { get; } + /// /// The number of returned items /// - public int Count { get { return m_count; } } + public int Count { get; } + /// /// List of UUIDs of Allowed Users /// - public List AllowedUsers { get { return m_allowedUsers; } } + public List AllowedUsers { get; } /// Construct a new instance of the EstateUsersReplyEventArgs class /// The estate's identifier on the grid @@ -1089,31 +1081,29 @@ namespace OpenMetaverse /// Allowed users UUIDs public EstateUsersReplyEventArgs(uint estateID, int count, List allowedUsers) { - this.m_estateID = estateID; - this.m_count = count; - this.m_allowedUsers = allowedUsers; + this.EstateID = estateID; + this.Count = count; + this.AllowedUsers = allowedUsers; } } /// Returned, along with other info, upon a successful .RequestInfo() public class EstateGroupsReplyEventArgs : EventArgs { - private readonly uint m_estateID; - private readonly int m_count; - private readonly List m_allowedGroups; - /// /// The identifier of the estate /// - public uint EstateID { get { return m_estateID; } } + public uint EstateID { get; } + /// /// The number of returned items /// - public int Count { get { return m_count; } } + public int Count { get; } + /// /// List of UUIDs of Allowed Groups /// - public List AllowedGroups { get { return m_allowedGroups; } } + public List AllowedGroups { get; } /// Construct a new instance of the EstateGroupsReplyEventArgs class /// The estate's identifier on the grid @@ -1121,31 +1111,29 @@ namespace OpenMetaverse /// Allowed Groups UUIDs public EstateGroupsReplyEventArgs(uint estateID, int count, List allowedGroups) { - this.m_estateID = estateID; - this.m_count = count; - this.m_allowedGroups = allowedGroups; + this.EstateID = estateID; + this.Count = count; + this.AllowedGroups = allowedGroups; } } /// Returned, along with other info, upon a successful .RequestInfo() public class EstateManagersReplyEventArgs : EventArgs { - private readonly uint m_estateID; - private readonly int m_count; - private readonly List m_Managers; - /// /// The identifier of the estate /// - public uint EstateID { get { return m_estateID; } } + public uint EstateID { get; } + /// /// The number of returned items /// - public int Count { get { return m_count; } } + public int Count { get; } + /// /// List of UUIDs of the Estate's Managers /// - public List Managers { get { return m_Managers; } } + public List Managers { get; } /// Construct a new instance of the EstateManagersReplyEventArgs class /// The estate's identifier on the grid @@ -1153,36 +1141,34 @@ namespace OpenMetaverse /// Managers UUIDs public EstateManagersReplyEventArgs(uint estateID, int count, List managers) { - this.m_estateID = estateID; - this.m_count = count; - this.m_Managers = managers; + this.EstateID = estateID; + this.Count = count; + this.Managers = managers; } } /// Returned, along with other info, upon a successful .RequestInfo() public class EstateCovenantReplyEventArgs : EventArgs { - private readonly UUID m_covenantID; - private readonly long m_timestamp; - private readonly string m_estateName; - private readonly UUID m_estateOwnerID; - /// /// The Covenant /// - public UUID CovenantID { get { return m_covenantID; } } + public UUID CovenantID { get; } + /// /// The timestamp /// - public long Timestamp { get { return m_timestamp; } } + public long Timestamp { get; } + /// /// The Estate name /// - public String EstateName { get { return m_estateName; } } + public String EstateName { get; } + /// /// The Estate Owner's ID (can be a GroupID) /// - public UUID EstateOwnerID { get { return m_estateOwnerID; } } + public UUID EstateOwnerID { get; } /// Construct a new instance of the EstateCovenantReplyEventArgs class /// The Covenant ID @@ -1191,10 +1177,10 @@ namespace OpenMetaverse /// The Estate Owner's ID (can be a GroupID) public EstateCovenantReplyEventArgs(UUID covenantID, long timestamp, string estateName, UUID estateOwnerID) { - this.m_covenantID = covenantID; - this.m_timestamp = timestamp; - this.m_estateName = estateName; - this.m_estateOwnerID = estateOwnerID; + this.CovenantID = covenantID; + this.Timestamp = timestamp; + this.EstateName = estateName; + this.EstateOwnerID = estateOwnerID; } } @@ -1203,25 +1189,23 @@ namespace OpenMetaverse /// Returned, along with other info, upon a successful .RequestInfo() public class EstateUpdateInfoReplyEventArgs : EventArgs { - private readonly uint m_estateID; - private readonly bool m_denyNoPaymentInfo; - private readonly string m_estateName; - private readonly UUID m_estateOwner; - /// /// The estate's name /// - public String EstateName { get { return m_estateName; } } + public String EstateName { get; } + /// /// The Estate Owner's ID (can be a GroupID) /// - public UUID EstateOwner { get { return m_estateOwner; } } + public UUID EstateOwner { get; } + /// /// The identifier of the estate on the grid /// - public uint EstateID { get { return m_estateID; } } + public uint EstateID { get; } + /// - public bool DenyNoPaymentInfo { get { return m_denyNoPaymentInfo; } } + public bool DenyNoPaymentInfo { get; } /// Construct a new instance of the EstateUpdateInfoReplyEventArgs class /// The estate's name @@ -1230,10 +1214,10 @@ namespace OpenMetaverse /// public EstateUpdateInfoReplyEventArgs(string estateName, UUID estateOwner, uint estateID, bool denyNoPaymentInfo) { - this.m_estateName = estateName; - this.m_estateOwner = estateOwner; - this.m_estateID = estateID; - this.m_denyNoPaymentInfo = denyNoPaymentInfo; + this.EstateName = estateName; + this.EstateOwner = estateOwner; + this.EstateID = estateID; + this.DenyNoPaymentInfo = denyNoPaymentInfo; } } diff --git a/LibreMetaverse/FriendsManager.cs b/LibreMetaverse/FriendsManager.cs index df1b5d4..f0536f5 100644 --- a/LibreMetaverse/FriendsManager.cs +++ b/LibreMetaverse/FriendsManager.cs @@ -55,40 +55,25 @@ namespace OpenMetaverse /// public class FriendInfo { - private UUID m_id; - private string m_name; - private bool m_isOnline; private bool m_canSeeMeOnline; private bool m_canSeeMeOnMap; - private bool m_canModifyMyObjects; - private bool m_canSeeThemOnline; - private bool m_canSeeThemOnMap; - private bool m_canModifyTheirObjects; #region Properties /// /// System ID of the avatar /// - public UUID UUID { get { return m_id; } } + public UUID UUID { get; } /// /// full name of the avatar /// - public string Name - { - get { return m_name; } - set { m_name = value; } - } + public string Name { get; set; } /// /// True if the avatar is online /// - public bool IsOnline - { - get { return m_isOnline; } - set { m_isOnline = value; } - } + public bool IsOnline { get; set; } /// /// True if the friend can see if I am online @@ -123,26 +108,22 @@ namespace OpenMetaverse /// /// True if the freind can modify my objects /// - public bool CanModifyMyObjects - { - get { return m_canModifyMyObjects; } - set { m_canModifyMyObjects = value; } - } + public bool CanModifyMyObjects { get; set; } /// /// True if I can see if my friend is online /// - public bool CanSeeThemOnline { get { return m_canSeeThemOnline; } } + public bool CanSeeThemOnline { get; private set; } /// /// True if I can see if my friend is on the map /// - public bool CanSeeThemOnMap { get { return m_canSeeThemOnMap; } } + public bool CanSeeThemOnMap { get; private set; } /// /// True if I can modify my friend's objects /// - public bool CanModifyTheirObjects { get { return m_canModifyTheirObjects; } } + public bool CanModifyTheirObjects { get; private set; } /// /// My friend's rights represented as bitmapped flags @@ -156,7 +137,7 @@ namespace OpenMetaverse results |= FriendRights.CanSeeOnline; if (m_canSeeMeOnMap) results |= FriendRights.CanSeeOnMap; - if (m_canModifyMyObjects) + if (CanModifyMyObjects) results |= FriendRights.CanModifyObjects; return results; @@ -165,7 +146,7 @@ namespace OpenMetaverse { m_canSeeMeOnline = (value & FriendRights.CanSeeOnline) != 0; m_canSeeMeOnMap = (value & FriendRights.CanSeeOnMap) != 0; - m_canModifyMyObjects = (value & FriendRights.CanModifyObjects) != 0; + CanModifyMyObjects = (value & FriendRights.CanModifyObjects) != 0; } } @@ -177,20 +158,20 @@ namespace OpenMetaverse get { FriendRights results = FriendRights.None; - if (m_canSeeThemOnline) + if (CanSeeThemOnline) results |= FriendRights.CanSeeOnline; - if (m_canSeeThemOnMap) + if (CanSeeThemOnMap) results |= FriendRights.CanSeeOnMap; - if (m_canModifyTheirObjects) + if (CanModifyTheirObjects) results |= FriendRights.CanModifyObjects; return results; } set { - m_canSeeThemOnline = (value & FriendRights.CanSeeOnline) != 0; - m_canSeeThemOnMap = (value & FriendRights.CanSeeOnMap) != 0; - m_canModifyTheirObjects = (value & FriendRights.CanModifyObjects) != 0; + CanSeeThemOnline = (value & FriendRights.CanSeeOnline) != 0; + CanSeeThemOnMap = (value & FriendRights.CanSeeOnMap) != 0; + CanModifyTheirObjects = (value & FriendRights.CanModifyObjects) != 0; } } @@ -204,14 +185,14 @@ namespace OpenMetaverse /// Rights you have to see your friend online and to modify their objects internal FriendInfo(UUID id, FriendRights theirRights, FriendRights myRights) { - m_id = id; + UUID = id; m_canSeeMeOnline = (theirRights & FriendRights.CanSeeOnline) != 0; m_canSeeMeOnMap = (theirRights & FriendRights.CanSeeOnMap) != 0; - m_canModifyMyObjects = (theirRights & FriendRights.CanModifyObjects) != 0; + CanModifyMyObjects = (theirRights & FriendRights.CanModifyObjects) != 0; - m_canSeeThemOnline = (myRights & FriendRights.CanSeeOnline) != 0; - m_canSeeThemOnMap = (myRights & FriendRights.CanSeeOnMap) != 0; - m_canModifyTheirObjects = (myRights & FriendRights.CanModifyObjects) != 0; + CanSeeThemOnline = (myRights & FriendRights.CanSeeOnline) != 0; + CanSeeThemOnMap = (myRights & FriendRights.CanSeeOnMap) != 0; + CanModifyTheirObjects = (myRights & FriendRights.CanModifyObjects) != 0; } /// @@ -220,11 +201,11 @@ namespace OpenMetaverse /// A string reprentation of both my rights and my friends rights public override string ToString() { - if (!String.IsNullOrEmpty(m_name)) - return String.Format("{0} (Their Rights: {1}, My Rights: {2})", m_name, TheirFriendRights, + if (!String.IsNullOrEmpty(Name)) + return String.Format("{0} (Their Rights: {1}, My Rights: {2})", Name, TheirFriendRights, MyFriendRights); else - return String.Format("{0} (Their Rights: {1}, My Rights: {2})", m_id, TheirFriendRights, + return String.Format("{0} (Their Rights: {1}, My Rights: {2})", UUID, TheirFriendRights, MyFriendRights); } } @@ -555,8 +536,8 @@ namespace OpenMetaverse if (result != null) { - var resMap = result as OSDMap; - if (!(resMap.ContainsKey("success") && resMap["success"].AsBoolean())) { return; } + if (result is OSDMap resMap + && !(resMap.ContainsKey("success") && resMap["success"].AsBoolean())) { return; } FriendInfo friend = new FriendInfo(fromAgentID, FriendRights.CanSeeOnline, FriendRights.CanSeeOnline); @@ -598,7 +579,7 @@ namespace OpenMetaverse /// This can be determined by the presence of a /// value in /// - /// of friend + /// of friend public void DeclineFriendshipCap(UUID fromAgentID) { Uri declineFriendshipCap = Client.Network.CurrentSim.Caps.CapabilityURI("DeclineFriendship"); @@ -626,8 +607,8 @@ namespace OpenMetaverse if (result != null) { - var resMap = result as OSDMap; - if (!(resMap.ContainsKey("success") && resMap["success"].AsBoolean())) { return; } + if (result is OSDMap resMap && + !(resMap.ContainsKey("success") && resMap["success"].AsBoolean())) { return; } if (FriendRequests.ContainsKey(fromAgentID)) { @@ -1051,10 +1032,9 @@ namespace OpenMetaverse public class FriendsReadyEventArgs : EventArgs { - private readonly int m_count; - /// Number of friends we have - public int Count { get { return m_count; } } + public int Count { get; } + /// Get the name of the agent we requested a friendship with /// @@ -1063,17 +1043,15 @@ namespace OpenMetaverse /// The total number of people loaded into the friend list. public FriendsReadyEventArgs(int count) { - this.m_count = count; + this.Count = count; } } /// Contains information on a member of our friends list public class FriendInfoEventArgs : EventArgs { - private readonly FriendInfo m_Friend; - /// Get the FriendInfo - public FriendInfo Friend { get { return m_Friend; } } + public FriendInfo Friend { get; } /// /// Construct a new instance of the FriendInfoEventArgs class @@ -1081,18 +1059,16 @@ namespace OpenMetaverse /// The FriendInfo public FriendInfoEventArgs(FriendInfo friend) { - this.m_Friend = friend; + this.Friend = friend; } } /// Contains Friend Names public class FriendNamesEventArgs : EventArgs { - private readonly Dictionary m_Names; - /// A dictionary where the Key is the ID of the Agent, /// and the Value is a string containing their name - public Dictionary Names { get { return m_Names; } } + public Dictionary Names { get; } /// /// Construct a new instance of the FriendNamesEventArgs class @@ -1101,24 +1077,22 @@ namespace OpenMetaverse /// and the Value is a string containing their name public FriendNamesEventArgs(Dictionary names) { - this.m_Names = names; + this.Names = names; } } /// Sent when another agent requests a friendship with our agent public class FriendshipOfferedEventArgs : EventArgs { - private readonly UUID m_AgentID; - private readonly string m_AgentName; - private readonly UUID m_SessionID; - /// Get the ID of the agent requesting friendship - public UUID AgentID { get { return m_AgentID; } } + public UUID AgentID { get; } + /// Get the name of the agent requesting friendship - public string AgentName { get { return m_AgentName; } } + public string AgentName { get; } + /// Get the ID of the session, used in accepting or declining the /// friendship offer - public UUID SessionID { get { return m_SessionID; } } + public UUID SessionID { get; } /// /// Construct a new instance of the FriendshipOfferedEventArgs class @@ -1129,25 +1103,23 @@ namespace OpenMetaverse /// friendship offer public FriendshipOfferedEventArgs(UUID agentID, string agentName, UUID imSessionID) { - this.m_AgentID = agentID; - this.m_AgentName = agentName; - this.m_SessionID = imSessionID; + this.AgentID = agentID; + this.AgentName = agentName; + this.SessionID = imSessionID; } } /// A response containing the results of our request to form a friendship with another agent public class FriendshipResponseEventArgs : EventArgs { - private readonly UUID m_AgentID; - private readonly string m_AgentName; - private readonly bool m_Accepted; - /// Get the ID of the agent we requested a friendship with - public UUID AgentID { get { return m_AgentID; } } + public UUID AgentID { get; } + /// Get the name of the agent we requested a friendship with - public string AgentName { get { return m_AgentName; } } + public string AgentName { get; } + /// true if the agent accepted our friendship offer - public bool Accepted { get { return m_Accepted; } } + public bool Accepted { get; } /// /// Construct a new instance of the FriendShipResponseEventArgs class @@ -1157,22 +1129,20 @@ namespace OpenMetaverse /// true if the agent accepted our friendship offer public FriendshipResponseEventArgs(UUID agentID, string agentName, bool accepted) { - this.m_AgentID = agentID; - this.m_AgentName = agentName; - this.m_Accepted = accepted; + this.AgentID = agentID; + this.AgentName = agentName; + this.Accepted = accepted; } } /// Contains data sent when a friend terminates a friendship with us public class FriendshipTerminatedEventArgs : EventArgs { - private readonly UUID m_AgentID; - private readonly string m_AgentName; - /// Get the ID of the agent that terminated the friendship with us - public UUID AgentID { get { return m_AgentID; } } + public UUID AgentID { get; } + /// Get the name of the agent that terminated the friendship with us - public string AgentName { get { return m_AgentName; } } + public string AgentName { get; } /// /// Construct a new instance of the FrindshipTerminatedEventArgs class @@ -1181,8 +1151,8 @@ namespace OpenMetaverse /// The name of the friend who terminated the friendship with us public FriendshipTerminatedEventArgs(UUID agentID, string agentName) { - this.m_AgentID = agentID; - this.m_AgentName = agentName; + this.AgentID = agentID; + this.AgentName = agentName; } } @@ -1191,16 +1161,14 @@ namespace OpenMetaverse /// public class FriendFoundReplyEventArgs : EventArgs { - private readonly UUID m_AgentID; - private readonly ulong m_RegionHandle; - private readonly Vector3 m_Location; - /// Get the ID of the agent we have received location information for - public UUID AgentID { get { return m_AgentID; } } + public UUID AgentID { get; } + /// Get the region handle where our mapped friend is located - public ulong RegionHandle { get { return m_RegionHandle; } } + public ulong RegionHandle { get; } + /// Get the simulator local position where our friend is located - public Vector3 Location { get { return m_Location; } } + public Vector3 Location { get; } /// /// Construct a new instance of the FriendFoundReplyEventArgs class @@ -1210,9 +1178,9 @@ namespace OpenMetaverse /// The simulator local position our friend is located public FriendFoundReplyEventArgs(UUID agentID, ulong regionHandle, Vector3 location) { - this.m_AgentID = agentID; - this.m_RegionHandle = regionHandle; - this.m_Location = location; + this.AgentID = agentID; + this.RegionHandle = regionHandle; + this.Location = location; } } #endregion diff --git a/LibreMetaverse/GridClient.cs b/LibreMetaverse/GridClient.cs index 1c1d21e..a6c845d 100644 --- a/LibreMetaverse/GridClient.cs +++ b/LibreMetaverse/GridClient.cs @@ -24,7 +24,6 @@ * POSSIBILITY OF SUCH DAMAGE. */ -using System; using LibreMetaverse; namespace OpenMetaverse diff --git a/LibreMetaverse/GridManager.cs b/LibreMetaverse/GridManager.cs index 56ee35c..ab87359 100644 --- a/LibreMetaverse/GridManager.cs +++ b/LibreMetaverse/GridManager.cs @@ -382,13 +382,16 @@ namespace OpenMetaverse #endregion Delegates /// Unknown - public float SunPhase { get { return sunPhase; } } - /// Current direction of the sun - public Vector3 SunDirection { get { return sunDirection; } } + public float SunPhase { get; private set; } + + /// Current direction of the sun + public Vector3 SunDirection { get; private set; } + /// Current angular velocity of the sun - public Vector3 SunAngVelocity { get { return sunAngVelocity; } } + public Vector3 SunAngVelocity { get; private set; } + /// Microseconds since the start of SL 4-hour day - public ulong TimeOfDay { get { return timeOfDay; } } + public ulong TimeOfDay { get; private set; } /// A dictionary of all the regions, indexed by region name internal Dictionary Regions = new Dictionary(); @@ -396,10 +399,6 @@ namespace OpenMetaverse internal Dictionary RegionsByHandle = new Dictionary(); private GridClient Client; - private float sunPhase; - private Vector3 sunDirection; - private Vector3 sunAngVelocity; - private ulong timeOfDay; /// /// Constructor @@ -784,10 +783,10 @@ namespace OpenMetaverse { SimulatorViewerTimeMessagePacket time = (SimulatorViewerTimeMessagePacket)e.Packet; - sunPhase = time.TimeInfo.SunPhase; - sunDirection = time.TimeInfo.SunDirection; - sunAngVelocity = time.TimeInfo.SunAngVelocity; - timeOfDay = time.TimeInfo.UsecSinceStart; + SunPhase = time.TimeInfo.SunPhase; + SunDirection = time.TimeInfo.SunDirection; + SunAngVelocity = time.TimeInfo.SunAngVelocity; + TimeOfDay = time.TimeInfo.UsecSinceStart; // TODO: Does anyone have a use for the time stuff? } @@ -857,72 +856,59 @@ namespace OpenMetaverse public class CoarseLocationUpdateEventArgs : EventArgs { - private readonly Simulator m_Simulator; - private readonly List m_NewEntries; - private readonly List m_RemovedEntries; - - public Simulator Simulator { get { return m_Simulator; } } - public List NewEntries { get { return m_NewEntries; } } - public List RemovedEntries { get { return m_RemovedEntries; } } + public Simulator Simulator { get; } + public List NewEntries { get; } + public List RemovedEntries { get; } public CoarseLocationUpdateEventArgs(Simulator simulator, List newEntries, List removedEntries) { - this.m_Simulator = simulator; - this.m_NewEntries = newEntries; - this.m_RemovedEntries = removedEntries; + this.Simulator = simulator; + this.NewEntries = newEntries; + this.RemovedEntries = removedEntries; } } public class GridRegionEventArgs : EventArgs { - private readonly GridRegion m_Region; - public GridRegion Region { get { return m_Region; } } + public GridRegion Region { get; } public GridRegionEventArgs(GridRegion region) { - this.m_Region = region; + this.Region = region; } } public class GridLayerEventArgs : EventArgs { - private readonly GridLayer m_Layer; - - public GridLayer Layer { get { return m_Layer; } } + public GridLayer Layer { get; } public GridLayerEventArgs(GridLayer layer) { - this.m_Layer = layer; + this.Layer = layer; } } public class GridItemsEventArgs : EventArgs { - private readonly GridItemType m_Type; - private readonly List m_Items; - - public GridItemType Type { get { return m_Type; } } - public List Items { get { return m_Items; } } + public GridItemType Type { get; } + public List Items { get; } public GridItemsEventArgs(GridItemType type, List items) { - this.m_Type = type; - this.m_Items = items; + this.Type = type; + this.Items = items; } } public class RegionHandleReplyEventArgs : EventArgs { - private readonly UUID m_RegionID; - private readonly ulong m_RegionHandle; - - public UUID RegionID { get { return m_RegionID; } } - public ulong RegionHandle { get { return m_RegionHandle; } } + public UUID RegionID { get; } + public ulong RegionHandle { get; } public RegionHandleReplyEventArgs(UUID regionID, ulong regionHandle) { - this.m_RegionID = regionID; - this.m_RegionHandle = regionHandle; + this.RegionID = regionID; + this.RegionHandle = regionHandle; } } diff --git a/LibreMetaverse/Imaging/BakeLayer.cs b/LibreMetaverse/Imaging/BakeLayer.cs index d91fe23..7e733dd 100644 --- a/LibreMetaverse/Imaging/BakeLayer.cs +++ b/LibreMetaverse/Imaging/BakeLayer.cs @@ -25,7 +25,6 @@ */ using System; -using System.Reflection; using System.Collections.Generic; using System.IO; using System.Drawing; @@ -536,7 +535,7 @@ namespace OpenMetaverse.Imaging /// /// Destination image /// Source image - /// Sanitization was succefull + /// Sanitization was successful private bool SanitizeLayers(ManagedImage dest, ManagedImage src) { if (dest == null || src == null) return false; diff --git a/LibreMetaverse/Imaging/TGALoader.cs b/LibreMetaverse/Imaging/TGALoader.cs index dd309bb..a484a1a 100644 --- a/LibreMetaverse/Imaging/TGALoader.cs +++ b/LibreMetaverse/Imaging/TGALoader.cs @@ -517,7 +517,7 @@ namespace OpenMetaverse.Imaging } } - public static unsafe ManagedImage LoadTGAImage(System.IO.Stream source) + public static ManagedImage LoadTGAImage(System.IO.Stream source) { return LoadTGAImage(source, false); } diff --git a/LibreMetaverse/ImportExport/ColladalLoader.cs b/LibreMetaverse/ImportExport/ColladalLoader.cs index 9794687..dbf67a1 100644 --- a/LibreMetaverse/ImportExport/ColladalLoader.cs +++ b/LibreMetaverse/ImportExport/ColladalLoader.cs @@ -1,6 +1,6 @@ /* * Copyright (c) 2006-2016, openmetaverse.co - * Copyright (c) 2021, Sjofn LLC. + * Copyright (c) 2021-2022, Sjofn LLC. * All rights reserved. * * - Redistribution and use in source and binary forms, with or without @@ -199,14 +199,12 @@ namespace OpenMetaverse.ImportExport ModelMaterial ExtractMaterial(object diffuse) { ModelMaterial ret = new ModelMaterial(); - if (diffuse is common_color_or_texture_typeColor) + if (diffuse is common_color_or_texture_typeColor color) { - var col = (common_color_or_texture_typeColor)diffuse; - ret.DiffuseColor = new Color4((float)col.Values[0], (float)col.Values[1], (float)col.Values[2], (float)col.Values[3]); + ret.DiffuseColor = new Color4((float)color.Values[0], (float)color.Values[1], (float)color.Values[2], (float)color.Values[3]); } - else if (diffuse is common_color_or_texture_typeTexture) + else if (diffuse is common_color_or_texture_typeTexture tex) { - var tex = (common_color_or_texture_typeTexture)diffuse; ret.Texture = tex.texcoord; } return ret; @@ -229,18 +227,17 @@ namespace OpenMetaverse.ImportExport foreach (var item in Model.Items) { - if (item is library_images) + if (item is library_images images) { - var images = (library_images)item; if (images.image != null) { foreach (var image in images.image) { var img = (image)image; string ID = img.id; - if (img.Item is string) + if (img.Item is string imgItem) { - imgMap[ID] = (string)img.Item; + imgMap[ID] = imgItem; } } } @@ -249,9 +246,8 @@ namespace OpenMetaverse.ImportExport foreach (var item in Model.Items) { - if (item is library_materials) + if (item is library_materials materials) { - var materials = (library_materials)item; if (materials.material != null) { foreach (var material in materials.material) @@ -268,9 +264,8 @@ namespace OpenMetaverse.ImportExport foreach (var item in Model.Items) { - if (item is library_effects) + if (item is library_effects effects) { - var effects = (library_effects)item; if (effects.effect != null) { foreach (var effect in effects.effect) @@ -278,24 +273,22 @@ namespace OpenMetaverse.ImportExport string ID = effect.id; foreach (var effItem in effect.Items) { - if (effItem is effectFx_profile_abstractProfile_COMMON) + if (effItem is effectFx_profile_abstractProfile_COMMON common) { - var teq = ((effectFx_profile_abstractProfile_COMMON)effItem).technique; + var teq = common.technique; if (teq != null) { - if (teq.Item is effectFx_profile_abstractProfile_COMMONTechniquePhong) + if (teq.Item is effectFx_profile_abstractProfile_COMMONTechniquePhong phong) { - var shader = (effectFx_profile_abstractProfile_COMMONTechniquePhong)teq.Item; - if (shader.diffuse != null) + if (phong.diffuse != null) { - var material = ExtractMaterial(shader.diffuse.Item); + var material = ExtractMaterial(phong.diffuse.Item); material.ID = ID; tmpEffects.Add(material); } } - else if (teq.Item is effectFx_profile_abstractProfile_COMMONTechniqueLambert) + else if (teq.Item is effectFx_profile_abstractProfile_COMMONTechniqueLambert shader) { - var shader = (effectFx_profile_abstractProfile_COMMONTechniqueLambert)teq.Item; if (shader.diffuse != null) { var material = ExtractMaterial(shader.diffuse.Item); @@ -336,13 +329,12 @@ namespace OpenMetaverse.ImportExport // Try finding matrix foreach (var i in node.Items) { - if (i is matrix) + if (i is matrix mtx) { - var m = (matrix)i; for (int a = 0; a < 4; a++) for (int b = 0; b < 4; b++) { - n.Transform[b, a] = (float)m.Values[a * 4 + b]; + n.Transform[b, a] = (float)mtx.Values[a * 4 + b]; } } } @@ -386,9 +378,9 @@ namespace OpenMetaverse.ImportExport foreach (var item in Model.Items) { - if (item is library_visual_scenes) + if (item is library_visual_scenes scenes) { - var scene = ((library_visual_scenes)item).visual_scene[0]; + var scene = scenes.visual_scene[0]; foreach (var node in scene.node) { ProcessNode(node); @@ -440,8 +432,7 @@ namespace OpenMetaverse.ImportExport ParseMaterials(); foreach (var item in Model.Items) { - if (item is library_geometries) { - var geometries = (library_geometries)item; + if (item is library_geometries geometries) { foreach (var geo in geometries.geometry) { var mesh = geo.Item as mesh; if (mesh == null) @@ -455,8 +446,10 @@ namespace OpenMetaverse.ImportExport Vector3 asset_offset = new Vector3(0, 0, 0); // Scale and offset between Collada and OS asset (Which is always in a unit cube) foreach (var node in nodes) { - var prim = new ModelPrim(); - prim.ID = node.ID; + var prim = new ModelPrim + { + ID = node.ID + }; Prims.Add(prim); // First node is used to create the asset. This is as the code to crate the byte array is somewhat @@ -466,10 +459,10 @@ namespace OpenMetaverse.ImportExport AddPositions(out asset_scale, out asset_offset, mesh, prim, transform); // transform is used only for inch -> meter and up axis transform. foreach (var mitem in mesh.Items) { - if (mitem is triangles) - AddFacesFromPolyList(Triangles2Polylist((triangles)mitem), mesh, prim, transform); // Transform is used to turn normals according to up axis - if (mitem is polylist) - AddFacesFromPolyList((polylist)mitem, mesh, prim, transform); + if (mitem is triangles triangles) + AddFacesFromPolyList(Triangles2Polylist(triangles), mesh, prim, transform); // Transform is used to turn normals according to up axis + if (mitem is polylist polylist) + AddFacesFromPolyList(polylist, mesh, prim, transform); } prim.CreateAsset(UUID.Zero); diff --git a/LibreMetaverse/ImportExport/ModelUploader.cs b/LibreMetaverse/ImportExport/ModelUploader.cs index 2b99945..34fbcce 100644 --- a/LibreMetaverse/ImportExport/ModelUploader.cs +++ b/LibreMetaverse/ImportExport/ModelUploader.cs @@ -26,10 +26,6 @@ using System; using System.Collections.Generic; -using System.Text.RegularExpressions; -using System.IO; -using System.Xml; -using System.Xml.Serialization; using OpenMetaverse.StructuredData; using OpenMetaverse.Http; @@ -183,9 +179,8 @@ namespace OpenMetaverse.ImportExport return; } - if (result is OSDMap) + if (result is OSDMap res) { - var res = (OSDMap)result; Uri uploader = new Uri(res["uploader"]); PerformUpload(uploader, (contents => { diff --git a/LibreMetaverse/Interfaces/IByteBufferPool.cs b/LibreMetaverse/Interfaces/IByteBufferPool.cs index fbfb6fa..63a7747 100644 --- a/LibreMetaverse/Interfaces/IByteBufferPool.cs +++ b/LibreMetaverse/Interfaces/IByteBufferPool.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace OpenMetaverse.Interfaces +namespace OpenMetaverse.Interfaces { /// /// Interface to a class that can supply cached byte arrays diff --git a/LibreMetaverse/Interfaces/IMessage.cs b/LibreMetaverse/Interfaces/IMessage.cs index 6c515a4..9dcea87 100644 --- a/LibreMetaverse/Interfaces/IMessage.cs +++ b/LibreMetaverse/Interfaces/IMessage.cs @@ -24,9 +24,6 @@ * POSSIBILITY OF SUCH DAMAGE. */ -using System; -using System.Collections.Generic; -using System.Text; using OpenMetaverse.StructuredData; diff --git a/LibreMetaverse/Inventory.cs b/LibreMetaverse/Inventory.cs index 7d10001..66a1291 100644 --- a/LibreMetaverse/Inventory.cs +++ b/LibreMetaverse/Inventory.cs @@ -1,6 +1,6 @@ /* * Copyright (c) 2006-2016, openmetaverse.co - * Copyright (c) 2021, Sjofn LLC. + * Copyright (c) 2021-2022, Sjofn LLC. * All rights reserved. * * - Redistribution and use in source and binary forms, with or without @@ -133,7 +133,7 @@ namespace OpenMetaverse set { UpdateNodeFor(value); - _RootNode = Items[value.UUID]; + RootNode = Items[value.UUID]; } } @@ -146,28 +146,25 @@ namespace OpenMetaverse set { UpdateNodeFor(value); - _LibraryRootNode = Items[value.UUID]; + LibraryRootNode = Items[value.UUID]; } } - private InventoryNode _LibraryRootNode; - private InventoryNode _RootNode; - /// /// The root node of the avatars inventory /// - public InventoryNode RootNode => _RootNode; + public InventoryNode RootNode { get; private set; } /// /// The root node of the default shared library /// - public InventoryNode LibraryRootNode => _LibraryRootNode; + public InventoryNode LibraryRootNode { get; private set; } - public UUID Owner { get; } + public UUID Owner { get; private set; } private GridClient Client; //private InventoryManager Manager; - public Dictionary Items = new Dictionary(); + public Dictionary Items; public Inventory(GridClient client, InventoryManager manager) : this(client, manager, client.Self.AgentID) { } @@ -345,7 +342,7 @@ namespace OpenMetaverse BinaryFormatter bformatter = new BinaryFormatter(); lock (Items) { - Logger.Log("Caching " + Items.Count.ToString() + " inventory items to " + filename, Helpers.LogLevel.Info); + Logger.Log($"Caching {Items.Count} inventory items to {filename}", Helpers.LogLevel.Info); foreach (KeyValuePair kvp in Items) { bformatter.Serialize(stream, kvp.Value); @@ -355,7 +352,7 @@ namespace OpenMetaverse } catch (Exception e) { - Logger.Log("Error saving inventory cache to disk :"+e.Message,Helpers.LogLevel.Error); + Logger.Log("Error saving inventory cache to disk", Helpers.LogLevel.Error, e); } } @@ -387,11 +384,11 @@ namespace OpenMetaverse } catch (Exception e) { - Logger.Log("Error accessing inventory cache file :" + e.Message, Helpers.LogLevel.Error); + Logger.Log("Error accessing inventory cache file", Helpers.LogLevel.Error, e); return -1; } - Logger.Log("Read " + item_count.ToString() + " items from inventory cache file", Helpers.LogLevel.Info); + Logger.Log($"Read {item_count} items from inventory cache file", Helpers.LogLevel.Info); item_count = 0; List del_nodes = new List(); //nodes that we have processed and will delete @@ -473,7 +470,7 @@ namespace OpenMetaverse del_nodes.Clear(); } - Logger.Log("Reassembled " + item_count.ToString() + " items from inventory cache file", Helpers.LogLevel.Info); + Logger.Log($"Reassembled {item_count} items from inventory cache file", Helpers.LogLevel.Info); return item_count; } @@ -501,9 +498,10 @@ namespace OpenMetaverse { // Log a warning if there is a UUID mismatch, this will cause problems if (value.UUID != uuid) - Logger.Log("Inventory[uuid]: uuid " + uuid.ToString() + " is not equal to value.UUID " + - value.UUID.ToString(), Helpers.LogLevel.Warning, Client); - + { + Logger.Log($"Inventory[uuid]: uuid {uuid} is not equal to value.UUID {value.UUID}", + Helpers.LogLevel.Warning, Client); + } UpdateNodeFor(value); } else diff --git a/LibreMetaverse/InventoryAISClient.cs b/LibreMetaverse/InventoryAISClient.cs index 512eb55..a0ecdde 100644 --- a/LibreMetaverse/InventoryAISClient.cs +++ b/LibreMetaverse/InventoryAISClient.cs @@ -1,530 +1,530 @@ -/* - * Copyright (c) 2019-2021, Sjofn LLC - * 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 openmetaverse.co 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 System.Collections.Generic; -using System.Linq; -using System.Net.Http; -using System.Text; -using System.Threading.Tasks; -using OpenMetaverse; -using OpenMetaverse.StructuredData; - -namespace LibreMetaverse -{ - public class InventoryAISClient - { - public const string INVENTORY_CAP_NAME = "InventoryAPIv3"; - public const string LIBRARY_CAP_NAME = "LibraryAPIv3"; - - [NonSerialized] - private readonly GridClient Client; - - private static readonly HttpClient httpClient = new HttpClient(); - - public InventoryAISClient(GridClient client) - { - Client = client; - httpClient.DefaultRequestHeaders.Accept.Clear(); - httpClient.DefaultRequestHeaders.Add("User-Agent", $"{Settings.USER_AGENT} AIS Client"); - } - - public bool IsAvailable => (Client.Network.CurrentSim.Caps != null && - Client.Network.CurrentSim.Caps.CapabilityURI(INVENTORY_CAP_NAME) != null); - - public async Task CreateInventory(UUID parentUuid, OSD newInventory, bool createLink, InventoryManager.ItemCreatedCallback callback) - { - var cap = getInventoryCap(); - if (cap == null) - { - Logger.Log("No AIS3 Capability!", Helpers.LogLevel.Warning, Client); - return; - } - - var success = false; - InventoryItem item = null; - - try - { - var tid = UUID.Random(); - - var url = $"{cap}/category/{parentUuid}?tid={tid}"; - - if (!Uri.TryCreate(url, UriKind.Absolute, out var uri)) - { - success = false; - - return; - } - - var payload = OSDParser.SerializeLLSDXmlString(newInventory); - - using (var content = new StringContent(payload, Encoding.UTF8, "application/llsd+xml")) - { - using (var reply = await httpClient.PostAsync(uri, content)) - { - success = reply.IsSuccessStatusCode; - - if (!success) - { - Logger.Log("Could not create inventory: " + reply.ReasonPhrase, Helpers.LogLevel.Warning); - - return; - } - - var data = await reply.Content.ReadAsStringAsync(); - - if (OSDParser.Deserialize(data) is OSDMap map && map["_embedded"] is OSDMap embedded) - { - var items = !createLink ? - parseItemsFromResponse((OSDMap)embedded["items"]) : - parseLinksFromResponse((OSDMap)embedded["links"]); - - item = items.First(); - } - } - } - } - catch (Exception ex) - { - Logger.Log(ex.Message, Helpers.LogLevel.Warning); - } - finally - { - callback(success, item); - } - } - - public async Task SlamFolder(UUID folderUuid, OSD newInventory, Action callback) - { - var cap = getInventoryCap(); - if (cap == null) - { - Logger.Log("No AIS3 Capability!", Helpers.LogLevel.Warning, Client); - return; - } - - var success = false; - - try - { - var tid = UUID.Random(); - var url = $"{cap}/category/{folderUuid}/links?tid={tid}"; - - if (!Uri.TryCreate(url, UriKind.Absolute, out var uri)) - { - success = false; - - return; - } - - var payload = OSDParser.SerializeLLSDXmlString(newInventory); - - using (var content = new StringContent(payload, Encoding.UTF8, "application/llsd+xml")) - { - using (var reply = await httpClient.PutAsync(uri, content)) - { - success = reply.IsSuccessStatusCode; - - if (!success) - { - Logger.Log("Could not slam folder: " + reply.ReasonPhrase, Helpers.LogLevel.Warning); - } - } - } - } - catch (Exception ex) - { - Logger.Log(ex.Message, Helpers.LogLevel.Warning); - } - finally - { - callback?.Invoke(success); - } - } - - public async Task RemoveCategory(UUID categoryUuid, Action callback) - { - var cap = getInventoryCap(); - if (cap == null) - { - Logger.Log("No AIS3 Capability!", Helpers.LogLevel.Warning, Client); - return; - } - - var success = false; - - try - { - var url = $"{cap}/category/{categoryUuid}"; - - if (!Uri.TryCreate(url, UriKind.Absolute, out var uri)) - { - success = false; - - return; - } - - using (var reply = await httpClient.DeleteAsync(uri)) - { - success = reply.IsSuccessStatusCode; - - if (!success) - { - Logger.Log("Could not remove folder: " + reply.ReasonPhrase, Helpers.LogLevel.Warning); - } - } - } - catch (Exception ex) - { - Logger.Log(ex.Message, Helpers.LogLevel.Warning); - } - finally - { - callback?.Invoke(success); - } - } - - public async Task RemoveItem(UUID itemUuid, Action callback) - { - var cap = getInventoryCap(); - if (cap == null) - { - Logger.Log("No AIS3 Capability!", Helpers.LogLevel.Warning, Client); - return; - } - - var success = false; - - try - { - var url = $"{cap}/item/{itemUuid}"; - - if (!Uri.TryCreate(url, UriKind.Absolute, out var uri)) - { - success = false; - - return; - } - - using (var reply = await httpClient.DeleteAsync(uri)) - { - success = reply.IsSuccessStatusCode; - - if (!success) - { - Logger.Log("Could not remove item: " + itemUuid + " " + reply.ReasonPhrase, - Helpers.LogLevel.Warning); - } - } - } - catch (Exception ex) - { - Logger.Log(ex.Message, Helpers.LogLevel.Warning); - } - finally - { - callback?.Invoke(success); - } - } - - public async Task CopyLibraryCategory(UUID sourceUuid, UUID destUuid, bool copySubfolders, Action callback) - { - var cap = getLibraryCap(); - if (cap == null) - { - Logger.Log("No AIS3 Capability!", Helpers.LogLevel.Warning, Client); - return; - } - - var success = false; - - try - { - UUID tid = UUID.Random(); - - var url = new StringBuilder($"{cap}/category/{sourceUuid}?tid={tid}"); - - if (copySubfolders) - url.Append(",depth=0"); - - if (!Uri.TryCreate(url.ToString(), UriKind.Absolute, out var uri)) - { - success = false; - - return; - } - - using (var message = new HttpRequestMessage()) - { - message.RequestUri = uri; - message.Method = new HttpMethod("COPY"); - message.Headers.Add("Destination", destUuid.ToString()); - - using (var reply = await httpClient.SendAsync(message)) - { - success = reply.IsSuccessStatusCode; - - if (!success) - { - Logger.Log("Could not copy library folder: " + reply.ReasonPhrase, Helpers.LogLevel.Warning); - } - } - } - } - catch (Exception ex) - { - Logger.Log(ex.Message, Helpers.LogLevel.Warning); - } - finally - { - callback?.Invoke(success); - } - } - - public async Task PurgeDescendents(UUID categoryUuid, Action callback) - { - var cap = getInventoryCap(); - if (cap == null) - { - Logger.Log("No AIS3 Capability!", Helpers.LogLevel.Warning, Client); - return; - } - - var success = false; - - try - { - var url = $"{cap}/category/{categoryUuid}/children"; - - if (!Uri.TryCreate(url, UriKind.Absolute, out var uri)) - { - success = false; - - return; - } - - using (var reply = await httpClient.DeleteAsync(uri)) - { - success = reply.IsSuccessStatusCode; - - if (!success) - { - Logger.Log("Could not purge descendents: " + reply.ReasonPhrase, Helpers.LogLevel.Warning); - } - } - } - catch (Exception ex) - { - Logger.Log(ex.Message, Helpers.LogLevel.Warning); - } - finally - { - callback?.Invoke(success, categoryUuid); - } - } - - public async Task UpdateCategory(UUID categoryUuid, OSD updates, Action callback) - { - var cap = getInventoryCap(); - if (cap == null) - { - Logger.Log("No AIS3 Capability!", Helpers.LogLevel.Warning, Client); - return; - } - - var success = false; - - try - { - var url = $"{cap}/category/{categoryUuid}"; - - if (!Uri.TryCreate(url, UriKind.Absolute, out var uri)) - { - success = false; - - return; - } - - var method = new HttpMethod("PATCH"); - - using (var message = new HttpRequestMessage(method, uri)) - { - var payload = OSDParser.SerializeLLSDXmlString(updates); - - using (var content = new StringContent(payload, Encoding.UTF8, "application/llsd+xml")) - { - message.Content = content; - - using (var reply = await httpClient.SendAsync(message)) - { - success = reply.IsSuccessStatusCode; - - if (!success) - { - Logger.Log("Could not update folder: " + reply.ReasonPhrase, - Helpers.LogLevel.Warning); - } - } - } - } - } - catch (Exception ex) - { - Logger.Log(ex.Message, Helpers.LogLevel.Warning); - } - finally - { - callback?.Invoke(success); - } - } - - public async Task UpdateItem(UUID itemUuid, OSD updates, Action callback) - { - var cap = getInventoryCap(); - if (cap == null) - { - Logger.Log("No AIS3 Capability!", Helpers.LogLevel.Warning, Client); - return; - } - - var success = false; - - try - { - var url = $"{cap}/item/{itemUuid}"; - - if (!Uri.TryCreate(url, UriKind.Absolute, out var uri)) - { - success = false; - - return; - } - - var method = new HttpMethod("PATCH"); - - using (var message = new HttpRequestMessage(method, uri)) - { - var payload = OSDParser.SerializeLLSDXmlString(updates); - - using (var content = new StringContent(payload, Encoding.UTF8, "application/llsd+xml")) - { - message.Content = content; - - using (var reply = await httpClient.SendAsync(message)) - { - success = reply.IsSuccessStatusCode; - - if (!success) - { - Logger.Log("Could not update item: " + reply.ReasonPhrase, - Helpers.LogLevel.Warning); - } - } - } - } - } - catch (Exception ex) - { - Logger.Log(ex.Message, Helpers.LogLevel.Warning); - } - finally - { - callback?.Invoke(success); - } - } - - private List parseItemsFromResponse(OSDMap itemsOsd) - { - List ret = new List(); - - foreach (KeyValuePair o in itemsOsd) - { - var item = (OSDMap)o.Value; - ret.Add(InventoryItem.FromOSD(item)); - } - return ret; - } - - private List parseLinksFromResponse(OSDMap linksOsd) - { - List ret = new List(); - - foreach (KeyValuePair o in linksOsd) - { - var link = (OSDMap)o.Value; - InventoryType type = (InventoryType)link["inv_type"].AsInteger(); - if (type == InventoryType.Texture && (AssetType)link["type"].AsInteger() == AssetType.Object) - { - type = InventoryType.Attachment; - } - InventoryItem item = InventoryManager.CreateInventoryItem(type, link["item_id"]); - - item.ParentUUID = link["parent_id"]; - item.Name = link["name"]; - item.Description = link["desc"]; - item.OwnerID = link["agent_id"]; - item.ParentUUID = link["parent_id"]; - item.AssetUUID = link["linked_id"]; - item.AssetType = AssetType.Link; - item.CreationDate = Utils.UnixTimeToDateTime(link["created_at"]); - - item.CreatorID = link["agent_id"]; // hack - item.LastOwnerID = link["agent_id"]; // hack - item.Permissions = Permissions.NoPermissions; - item.GroupOwned = false; - item.GroupID = UUID.Zero; - - item.SalePrice = 0; - item.SaleType = SaleType.Not; - - ret.Add(item); - } - - return ret; - } - - private Uri getInventoryCap() - { - Uri cap = null; - if (Client.Network.CurrentSim.Caps != null) - { - cap = Client.Network.CurrentSim.Caps.CapabilityURI(INVENTORY_CAP_NAME); - } - return cap; - } - - private Uri getLibraryCap() - { - Uri cap = null; - if (Client.Network.CurrentSim.Caps != null) - { - cap = Client.Network.CurrentSim.Caps.CapabilityURI(LIBRARY_CAP_NAME); - } - return cap; - } - } -} +/* + * Copyright (c) 2019-2022, Sjofn LLC + * 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 openmetaverse.co 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 System.Collections.Generic; +using System.Linq; +using System.Net.Http; +using System.Text; +using System.Threading.Tasks; +using OpenMetaverse; +using OpenMetaverse.StructuredData; + +namespace LibreMetaverse +{ + public class InventoryAISClient + { + public const string INVENTORY_CAP_NAME = "InventoryAPIv3"; + public const string LIBRARY_CAP_NAME = "LibraryAPIv3"; + + [NonSerialized] + private readonly GridClient Client; + + private static readonly HttpClient httpClient = new HttpClient(); + + public InventoryAISClient(GridClient client) + { + Client = client; + httpClient.DefaultRequestHeaders.Accept.Clear(); + httpClient.DefaultRequestHeaders.Add("User-Agent", $"{Settings.USER_AGENT} AIS Client"); + } + + public bool IsAvailable => (Client.Network.CurrentSim.Caps != null && + Client.Network.CurrentSim.Caps.CapabilityURI(INVENTORY_CAP_NAME) != null); + + public async Task CreateInventory(UUID parentUuid, OSD newInventory, bool createLink, InventoryManager.ItemCreatedCallback callback) + { + var cap = getInventoryCap(); + if (cap == null) + { + Logger.Log("No AIS3 Capability!", Helpers.LogLevel.Warning, Client); + return; + } + + var success = false; + InventoryItem item = null; + + try + { + var tid = UUID.Random(); + + var url = $"{cap}/category/{parentUuid}?tid={tid}"; + + if (!Uri.TryCreate(url, UriKind.Absolute, out var uri)) + { + success = false; + + return; + } + + var payload = OSDParser.SerializeLLSDXmlString(newInventory); + + using (var content = new StringContent(payload, Encoding.UTF8, "application/llsd+xml")) + { + using (var reply = await httpClient.PostAsync(uri, content)) + { + success = reply.IsSuccessStatusCode; + + if (!success) + { + Logger.Log("Could not create inventory: " + reply.ReasonPhrase, Helpers.LogLevel.Warning); + + return; + } + + var data = await reply.Content.ReadAsStringAsync(); + + if (OSDParser.Deserialize(data) is OSDMap map && map["_embedded"] is OSDMap embedded) + { + var items = !createLink ? + parseItemsFromResponse((OSDMap)embedded["items"]) : + parseLinksFromResponse((OSDMap)embedded["links"]); + + item = items.First(); + } + } + } + } + catch (Exception ex) + { + Logger.Log(ex.Message, Helpers.LogLevel.Warning); + } + finally + { + callback(success, item); + } + } + + public async Task SlamFolder(UUID folderUuid, OSD newInventory, Action callback) + { + var cap = getInventoryCap(); + if (cap == null) + { + Logger.Log("No AIS3 Capability!", Helpers.LogLevel.Warning, Client); + return; + } + + var success = false; + + try + { + var tid = UUID.Random(); + var url = $"{cap}/category/{folderUuid}/links?tid={tid}"; + + if (!Uri.TryCreate(url, UriKind.Absolute, out var uri)) + { + success = false; + + return; + } + + var payload = OSDParser.SerializeLLSDXmlString(newInventory); + + using (var content = new StringContent(payload, Encoding.UTF8, "application/llsd+xml")) + { + using (var reply = await httpClient.PutAsync(uri, content)) + { + success = reply.IsSuccessStatusCode; + + if (!success) + { + Logger.Log("Could not slam folder: " + reply.ReasonPhrase, Helpers.LogLevel.Warning); + } + } + } + } + catch (Exception ex) + { + Logger.Log(ex.Message, Helpers.LogLevel.Warning); + } + finally + { + callback?.Invoke(success); + } + } + + public async Task RemoveCategory(UUID categoryUuid, Action callback) + { + var cap = getInventoryCap(); + if (cap == null) + { + Logger.Log("No AIS3 Capability!", Helpers.LogLevel.Warning, Client); + return; + } + + var success = false; + + try + { + var url = $"{cap}/category/{categoryUuid}"; + + if (!Uri.TryCreate(url, UriKind.Absolute, out var uri)) + { + success = false; + + return; + } + + using (var reply = await httpClient.DeleteAsync(uri)) + { + success = reply.IsSuccessStatusCode; + + if (!success) + { + Logger.Log("Could not remove folder: " + reply.ReasonPhrase, Helpers.LogLevel.Warning); + } + } + } + catch (Exception ex) + { + Logger.Log(ex.Message, Helpers.LogLevel.Warning); + } + finally + { + callback?.Invoke(success, categoryUuid); + } + } + + public async Task RemoveItem(UUID itemUuid, Action callback) + { + var cap = getInventoryCap(); + if (cap == null) + { + Logger.Log("No AIS3 Capability!", Helpers.LogLevel.Warning, Client); + return; + } + + var success = false; + + try + { + var url = $"{cap}/item/{itemUuid}"; + + if (!Uri.TryCreate(url, UriKind.Absolute, out var uri)) + { + success = false; + + return; + } + + using (var reply = await httpClient.DeleteAsync(uri)) + { + success = reply.IsSuccessStatusCode; + + if (!success) + { + Logger.Log("Could not remove item: " + itemUuid + " " + reply.ReasonPhrase, + Helpers.LogLevel.Warning); + } + } + } + catch (Exception ex) + { + Logger.Log(ex.Message, Helpers.LogLevel.Warning); + } + finally + { + callback?.Invoke(success, itemUuid); + } + } + + public async Task CopyLibraryCategory(UUID sourceUuid, UUID destUuid, bool copySubfolders, Action callback) + { + var cap = getLibraryCap(); + if (cap == null) + { + Logger.Log("No AIS3 Capability!", Helpers.LogLevel.Warning, Client); + return; + } + + var success = false; + + try + { + UUID tid = UUID.Random(); + + var url = new StringBuilder($"{cap}/category/{sourceUuid}?tid={tid}"); + + if (copySubfolders) + url.Append(",depth=0"); + + if (!Uri.TryCreate(url.ToString(), UriKind.Absolute, out var uri)) + { + success = false; + + return; + } + + using (var message = new HttpRequestMessage()) + { + message.RequestUri = uri; + message.Method = new HttpMethod("COPY"); + message.Headers.Add("Destination", destUuid.ToString()); + + using (var reply = await httpClient.SendAsync(message)) + { + success = reply.IsSuccessStatusCode; + + if (!success) + { + Logger.Log("Could not copy library folder: " + reply.ReasonPhrase, Helpers.LogLevel.Warning); + } + } + } + } + catch (Exception ex) + { + Logger.Log(ex.Message, Helpers.LogLevel.Warning); + } + finally + { + callback?.Invoke(success); + } + } + + public async Task PurgeDescendents(UUID categoryUuid, Action callback) + { + var cap = getInventoryCap(); + if (cap == null) + { + Logger.Log("No AIS3 Capability!", Helpers.LogLevel.Warning, Client); + return; + } + + var success = false; + + try + { + var url = $"{cap}/category/{categoryUuid}/children"; + + if (!Uri.TryCreate(url, UriKind.Absolute, out var uri)) + { + success = false; + + return; + } + + using (var reply = await httpClient.DeleteAsync(uri)) + { + success = reply.IsSuccessStatusCode; + + if (!success) + { + Logger.Log("Could not purge descendents: " + reply.ReasonPhrase, Helpers.LogLevel.Warning); + } + } + } + catch (Exception ex) + { + Logger.Log(ex.Message, Helpers.LogLevel.Warning); + } + finally + { + callback?.Invoke(success, categoryUuid); + } + } + + public async Task UpdateCategory(UUID categoryUuid, OSD updates, Action callback) + { + var cap = getInventoryCap(); + if (cap == null) + { + Logger.Log("No AIS3 Capability!", Helpers.LogLevel.Warning, Client); + return; + } + + var success = false; + + try + { + var url = $"{cap}/category/{categoryUuid}"; + + if (!Uri.TryCreate(url, UriKind.Absolute, out var uri)) + { + success = false; + + return; + } + + var method = new HttpMethod("PATCH"); + + using (var message = new HttpRequestMessage(method, uri)) + { + var payload = OSDParser.SerializeLLSDXmlString(updates); + + using (var content = new StringContent(payload, Encoding.UTF8, "application/llsd+xml")) + { + message.Content = content; + + using (var reply = await httpClient.SendAsync(message)) + { + success = reply.IsSuccessStatusCode; + + if (!success) + { + Logger.Log("Could not update folder: " + reply.ReasonPhrase, + Helpers.LogLevel.Warning); + } + } + } + } + } + catch (Exception ex) + { + Logger.Log(ex.Message, Helpers.LogLevel.Warning); + } + finally + { + callback?.Invoke(success); + } + } + + public async Task UpdateItem(UUID itemUuid, OSD updates, Action callback) + { + var cap = getInventoryCap(); + if (cap == null) + { + Logger.Log("No AIS3 Capability!", Helpers.LogLevel.Warning, Client); + return; + } + + var success = false; + + try + { + var url = $"{cap}/item/{itemUuid}"; + + if (!Uri.TryCreate(url, UriKind.Absolute, out var uri)) + { + success = false; + + return; + } + + var method = new HttpMethod("PATCH"); + + using (var message = new HttpRequestMessage(method, uri)) + { + var payload = OSDParser.SerializeLLSDXmlString(updates); + + using (var content = new StringContent(payload, Encoding.UTF8, "application/llsd+xml")) + { + message.Content = content; + + using (var reply = await httpClient.SendAsync(message)) + { + success = reply.IsSuccessStatusCode; + + if (!success) + { + Logger.Log("Could not update item: " + reply.ReasonPhrase, + Helpers.LogLevel.Warning); + } + } + } + } + } + catch (Exception ex) + { + Logger.Log(ex.Message, Helpers.LogLevel.Warning); + } + finally + { + callback?.Invoke(success); + } + } + + private List parseItemsFromResponse(OSDMap itemsOsd) + { + List ret = new List(); + + foreach (KeyValuePair o in itemsOsd) + { + var item = (OSDMap)o.Value; + ret.Add(InventoryItem.FromOSD(item)); + } + return ret; + } + + private List parseLinksFromResponse(OSDMap linksOsd) + { + List ret = new List(); + + foreach (KeyValuePair o in linksOsd) + { + var link = (OSDMap)o.Value; + InventoryType type = (InventoryType)link["inv_type"].AsInteger(); + if (type == InventoryType.Texture && (AssetType)link["type"].AsInteger() == AssetType.Object) + { + type = InventoryType.Attachment; + } + InventoryItem item = InventoryManager.CreateInventoryItem(type, link["item_id"]); + + item.ParentUUID = link["parent_id"]; + item.Name = link["name"]; + item.Description = link["desc"]; + item.OwnerID = link["agent_id"]; + item.ParentUUID = link["parent_id"]; + item.AssetUUID = link["linked_id"]; + item.AssetType = AssetType.Link; + item.CreationDate = Utils.UnixTimeToDateTime(link["created_at"]); + + item.CreatorID = link["agent_id"]; // hack + item.LastOwnerID = link["agent_id"]; // hack + item.Permissions = Permissions.NoPermissions; + item.GroupOwned = false; + item.GroupID = UUID.Zero; + + item.SalePrice = 0; + item.SaleType = SaleType.Not; + + ret.Add(item); + } + + return ret; + } + + private Uri getInventoryCap() + { + Uri cap = null; + if (Client.Network.CurrentSim.Caps != null) + { + cap = Client.Network.CurrentSim.Caps.CapabilityURI(INVENTORY_CAP_NAME); + } + return cap; + } + + private Uri getLibraryCap() + { + Uri cap = null; + if (Client.Network.CurrentSim.Caps != null) + { + cap = Client.Network.CurrentSim.Caps.CapabilityURI(LIBRARY_CAP_NAME); + } + return cap; + } + } +} diff --git a/LibreMetaverse/InventoryBase.cs b/LibreMetaverse/InventoryBase.cs index a7c8c52..5fd4d94 100644 --- a/LibreMetaverse/InventoryBase.cs +++ b/LibreMetaverse/InventoryBase.cs @@ -1,7 +1,32 @@ -using System; -using System.Collections.Generic; +/* + * Copyright (c) 2006-2016, openmetaverse.co + * Copyright (c) 2021-2022, Sjofn LLC. + * 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 openmetaverse.co 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 System.Runtime.Serialization; -using System.Text; using OpenMetaverse.StructuredData; namespace OpenMetaverse @@ -9,7 +34,7 @@ namespace OpenMetaverse /// /// Base Class for Inventory Items /// - [Serializable()] + [Serializable] public abstract class InventoryBase : ISerializable { /// of item/folder @@ -69,7 +94,7 @@ namespace OpenMetaverse } /// - /// Determine whether the specified object is equal to the current object + /// Determine whether the specified object is equal to the current object /// /// InventoryBase object to compare against /// true if objects are the same @@ -79,7 +104,7 @@ namespace OpenMetaverse } /// - /// Determine whether the specified object is equal to the current object + /// Determine whether the specified object is equal to the current object /// /// InventoryBase object to compare against /// true if objects are the same @@ -106,10 +131,9 @@ namespace OpenMetaverse { public override string ToString() { - return AssetType + " " + AssetUUID + " (" + InventoryType + " " + UUID + ") '" + Name + "'/'" + - Description + "' " + Permissions; + return $"{AssetType} {AssetUUID} ({InventoryType} {UUID}) '{Name}'/'{Description}' {Permissions}"; } - /// The of this item + /// The of this item public UUID AssetUUID; /// The combined of this item public Permissions Permissions; @@ -117,11 +141,11 @@ namespace OpenMetaverse public AssetType AssetType; /// The type of item from the enum public InventoryType InventoryType; - /// The of the creator of this item + /// The of the creator of this item public UUID CreatorID; /// A Description of this item public string Description; - /// The s this item is set to or owned by + /// The s this item is set to or owned by public UUID GroupID; /// If true, item is owned by a group public bool GroupOwned; @@ -129,20 +153,20 @@ namespace OpenMetaverse public int SalePrice; /// The type of sale from the enum public SaleType SaleType; - /// Combined flags from + /// Combined flags from public uint Flags; /// Time and date this inventory item was created, stored as /// UTC (Coordinated Universal Time) public DateTime CreationDate; /// Used to update the AssetID in requests sent to the server public UUID TransactionID; - /// The of the previous owner of the item + /// The of the previous owner of the item public UUID LastOwnerID; /// /// Construct a new InventoryItem object /// - /// The of the item + /// The of the item public InventoryItem(UUID itemID) : base(itemID) { } @@ -245,9 +269,9 @@ namespace OpenMetaverse } /// - /// Determine whether the specified object is equal to the current object + /// Determine whether the specified object is equal to the current object /// - /// The object to compare against + /// The object to compare against /// true if objects are the same public bool Equals(InventoryItem o) { @@ -348,14 +372,14 @@ namespace OpenMetaverse /// InventoryTexture Class representing a graphical image /// /// - [Serializable()] + [Serializable] public class InventoryTexture : InventoryItem { /// /// Construct an InventoryTexture object /// - /// A which becomes the - /// objects AssetUUID + /// A which becomes the + /// objects AssetUUID public InventoryTexture(UUID itemID) : base(itemID) { @@ -376,14 +400,14 @@ namespace OpenMetaverse /// /// InventorySound Class representing a playable sound /// - [Serializable()] + [Serializable] public class InventorySound : InventoryItem { /// /// Construct an InventorySound object /// - /// A which becomes the - /// objects AssetUUID + /// A which becomes the + /// objects AssetUUID public InventorySound(UUID itemID) : base(itemID) { @@ -404,14 +428,14 @@ namespace OpenMetaverse /// /// InventoryCallingCard Class, contains information on another avatar /// - [Serializable()] + [Serializable] public class InventoryCallingCard : InventoryItem { /// /// Construct an InventoryCallingCard object /// - /// A which becomes the - /// objects AssetUUID + /// A which becomes the + /// objects AssetUUID public InventoryCallingCard(UUID itemID) : base(itemID) { @@ -432,14 +456,14 @@ namespace OpenMetaverse /// /// InventoryLandmark Class, contains details on a specific location /// - [Serializable()] + [Serializable] public class InventoryLandmark : InventoryItem { /// /// Construct an InventoryLandmark object /// - /// A which becomes the - /// objects AssetUUID + /// A which becomes the + /// objects AssetUUID public InventoryLandmark(UUID itemID) : base(itemID) { @@ -474,14 +498,14 @@ namespace OpenMetaverse /// /// InventoryObject Class contains details on a primitive or coalesced set of primitives /// - [Serializable()] + [Serializable] public class InventoryObject : InventoryItem { /// /// Construct an InventoryObject object /// - /// A which becomes the - /// objects AssetUUID + /// A which becomes the + /// objects AssetUUID public InventoryObject(UUID itemID) : base(itemID) { @@ -520,14 +544,14 @@ namespace OpenMetaverse /// /// InventoryNotecard Class, contains details on an encoded text document /// - [Serializable()] + [Serializable] public class InventoryNotecard : InventoryItem { /// /// Construct an InventoryNotecard object /// - /// A which becomes the - /// objects AssetUUID + /// A which becomes the + /// objects AssetUUID public InventoryNotecard(UUID itemID) : base(itemID) { @@ -549,14 +573,14 @@ namespace OpenMetaverse /// InventoryCategory Class /// /// TODO: Is this even used for anything? - [Serializable()] + [Serializable] public class InventoryCategory : InventoryItem { /// /// Construct an InventoryCategory object /// - /// A which becomes the - /// objects AssetUUID + /// A which becomes the + /// objects AssetUUID public InventoryCategory(UUID itemID) : base(itemID) { @@ -577,14 +601,14 @@ namespace OpenMetaverse /// /// InventoryLSL Class, represents a Linden Scripting Language object /// - [Serializable()] + [Serializable] public class InventoryLSL : InventoryItem { /// /// Construct an InventoryLSL object /// - /// A which becomes the - /// objects AssetUUID + /// A which becomes the + /// objects AssetUUID public InventoryLSL(UUID itemID) : base(itemID) { @@ -605,7 +629,7 @@ namespace OpenMetaverse /// /// InventorySnapshot Class, an image taken with the viewer /// - [Serializable()] + [Serializable] public class InventorySnapshot : InventoryItem { /// @@ -633,14 +657,14 @@ namespace OpenMetaverse /// /// InventoryAttachment Class, contains details on an attachable object /// - [Serializable()] + [Serializable] public class InventoryAttachment : InventoryItem { /// /// Construct an InventoryAttachment object /// - /// A which becomes the - /// objects AssetUUID + /// A which becomes the + /// objects AssetUUID public InventoryAttachment(UUID itemID) : base(itemID) { @@ -670,14 +694,14 @@ namespace OpenMetaverse /// /// InventoryWearable Class, details on a clothing item or body part /// - [Serializable()] + [Serializable] public class InventoryWearable : InventoryItem { /// /// Construct an InventoryWearable object /// - /// A which becomes the - /// objects AssetUUID + /// A which becomes the + /// objects AssetUUID public InventoryWearable(UUID itemID) : base(itemID) { InventoryType = InventoryType.Wearable; } /// @@ -703,14 +727,14 @@ namespace OpenMetaverse /// /// InventoryAnimation Class, A bvh encoded object which animates an avatar /// - [Serializable()] + [Serializable] public class InventoryAnimation : InventoryItem { /// /// Construct an InventoryAnimation object /// - /// A which becomes the - /// objects AssetUUID + /// A which becomes the + /// objects AssetUUID public InventoryAnimation(UUID itemID) : base(itemID) { @@ -731,14 +755,14 @@ namespace OpenMetaverse /// /// InventoryGesture Class, details on a series of animations, sounds, and actions /// - [Serializable()] + [Serializable] public class InventoryGesture : InventoryItem { /// /// Construct an InventoryGesture object /// - /// A which becomes the - /// objects AssetUUID + /// A which becomes the + /// objects AssetUUID public InventoryGesture(UUID itemID) : base(itemID) { @@ -760,7 +784,7 @@ namespace OpenMetaverse /// A folder contains s and has certain attributes specific /// to itself /// - [Serializable()] + [Serializable] public class InventoryFolder : InventoryBase { /// The Preferred for a folder. diff --git a/LibreMetaverse/InventoryManager.cs b/LibreMetaverse/InventoryManager.cs index 8a079d8..7ca7a96 100644 --- a/LibreMetaverse/InventoryManager.cs +++ b/LibreMetaverse/InventoryManager.cs @@ -1449,8 +1449,17 @@ namespace OpenMetaverse /// The of the inventory item to remove public void RemoveItem(UUID item) { - List items = new List(1) { item }; - Remove(items, null); + if (Client.AisClient.IsAvailable) + { + Client.AisClient.RemoveItem(item, RemoveLocalUi).ConfigureAwait(false); + } + else + { + List items = new List(1) { item }; +#pragma warning disable CS0612 // Type or member is obsolete + Remove(items, null); +#pragma warning restore CS0612 // Type or member is obsolete + } } /// @@ -1459,15 +1468,26 @@ namespace OpenMetaverse /// The of the folder to remove public void RemoveFolder(UUID folder) { - List folders = new List(1) { folder }; - Remove(null, folders); + if (Client.AisClient.IsAvailable) + { + Client.AisClient.RemoveCategory(folder, RemoveLocalUi).ConfigureAwait(false); + } + else + { + List folders = new List(1) { folder }; +#pragma warning disable CS0612 // Type or member is obsolete + Remove(null, folders); +#pragma warning restore CS0612 // Type or member is obsolete + } } /// - /// Remove multiple items or folders from inventory + /// Remove multiple items or folders from inventory. Note that this uses the LLUDP method + /// which Second Life has deprecated and removed. /// /// A List containing the s of items to remove /// A List containing the s of the folders to remove + [Obsolete] public void Remove(List items, List folders) { if ((items == null || items.Count == 0) && (folders == null || folders.Count == 0)) @@ -1583,7 +1603,9 @@ namespace OpenMetaverse } } +#pragma warning disable CS0612 // Type or member is obsolete Remove(remItems, remFolders); +#pragma warning restore CS0612 // Type or member is obsolete } } #endregion Remove diff --git a/LibreMetaverse/InventoryNode.cs b/LibreMetaverse/InventoryNode.cs index 6916121..65d5196 100644 --- a/LibreMetaverse/InventoryNode.cs +++ b/LibreMetaverse/InventoryNode.cs @@ -1,6 +1,6 @@ /* * Copyright (c) 2006-2016, openmetaverse.co - * Copyright (c) 2021, Sjofn LLC. + * Copyright (c) 2021-2022, Sjofn LLC. * All rights reserved. * * - Redistribution and use in source and binary forms, with or without @@ -35,13 +35,12 @@ namespace OpenMetaverse { private InventoryBase data; private InventoryNode parent; - private UUID parentID; //used for deseralization + private UUID parentID; //used for deseralization private InventoryNodeDictionary nodes; private bool needsUpdate = true; [NonSerialized] private object tag; - /// public InventoryBase Data { get => data; @@ -55,24 +54,35 @@ namespace OpenMetaverse set => tag = value; } - /// public InventoryNode Parent { get => parent; set => parent = value; } - /// - public UUID ParentID => parentID; + public UUID ParentID + { + get => parentID; + private set => parentID = value; + } - /// public InventoryNodeDictionary Nodes { get => nodes ?? (nodes = new InventoryNodeDictionary(this)); set => nodes = value; } - public System.DateTime ModifyTime + /// + /// For inventory folder nodes specifies weather the folder needs to be + /// refreshed from the server + /// + public bool NeedsUpdate + { + get => needsUpdate; + set => needsUpdate = value; + } + + public DateTime ModifyTime { get { @@ -98,16 +108,6 @@ namespace OpenMetaverse Nodes.Sort(); } - /// - /// For inventory folder nodes specifies weather the folder needs to be - /// refreshed from the server - /// - public bool NeedsUpdate - { - get => needsUpdate; - set => needsUpdate = value; - } - public InventoryNode() { } @@ -153,7 +153,7 @@ namespace OpenMetaverse // Construct a new inventory object based on the Type stored in Type System.Reflection.ConstructorInfo ctr = type.GetConstructor(new[] {typeof(SerializationInfo),typeof(StreamingContext)}); - data = (InventoryBase) ctr.Invoke(new object[] { info, ctxt }); + if (ctr != null) data = (InventoryBase)ctr.Invoke(new object[] { info, ctxt }); } public override string ToString() diff --git a/LibreMetaverse/LibreMetaverse.XML b/LibreMetaverse/LibreMetaverse.XML deleted file mode 100644 index bb216c1..0000000 --- a/LibreMetaverse/LibreMetaverse.XML +++ /dev/null @@ -1,36693 +0,0 @@ - - - - LibreMetaverse - - - - - Permission request flags, asked when a script wants to control an Avatar - - - - Placeholder for empty values, shouldn't ever see this - - - Script wants ability to take money from you - - - Script wants to take camera controls for you - - - Script wants to remap avatars controls - - - Script wants to trigger avatar animations - This function is not implemented on the grid - - - Script wants to attach or detach the prim or primset to your avatar - - - Script wants permission to release ownership - This function is not implemented on the grid - The concept of "public" objects does not exist anymore. - - - Script wants ability to link/delink with other prims - - - Script wants permission to change joints - This function is not implemented on the grid - - - Script wants permissions to change permissions - This function is not implemented on the grid - - - Script wants to track avatars camera position and rotation - - - Script wants to control your camera - - - Script wants the ability to teleport you - - - - Special commands used in Instant Messages - - - - Indicates a regular IM from another agent - - - Simple notification box with an OK button - - - You've been invited to join a group. - - - Inventory offer - - - Accepted inventory offer - - - Declined inventory offer - - - Group vote - - - An object is offering its inventory - - - Accept an inventory offer from an object - - - Decline an inventory offer from an object - - - Unknown - - - Start a session, or add users to a session - - - Start a session, but don't prune offline users - - - Start a session with your group - - - Start a session without a calling card (finder or objects) - - - Send a message to a session - - - Leave a session - - - Indicates that the IM is from an object - - - Sent an IM to a busy user, this is the auto response - - - Shows the message in the console and chat history - - - Send a teleport lure - - - Response sent to the agent which inititiated a teleport invitation - - - Response sent to the agent which inititiated a teleport invitation - - - Only useful if you have Linden permissions - - - Request a teleport lure - - - IM to tell the user to go to an URL - - - IM for help - - - IM sent automatically on call for help, sends a lure - to each Helper reached - - - Like an IM but won't go to email - - - IM from a group officer to all group members - - - Unknown - - - Unknown - - - Accept a group invitation - - - Decline a group invitation - - - Unknown - - - An avatar is offering you friendship - - - An avatar has accepted your friendship offer - - - An avatar has declined your friendship offer - - - Indicates that a user has started typing - - - Indicates that a user has stopped typing - - - - Flag in Instant Messages, whether the IM should be delivered to - offline avatars as well - - - - Only deliver to online avatars - - - If the avatar is offline the message will be held until - they login next, and possibly forwarded to their e-mail account - - - - Conversion type to denote Chat Packet types in an easier-to-understand format - - - - Whisper (5m radius) - - - Normal chat (10/20m radius), what the official viewer typically sends - - - Shouting! (100m radius) - - - Event message when an Avatar has begun to type - - - Event message when an Avatar has stopped typing - - - Send the message to the debug channel - - - Event message when an object uses llOwnerSay - - - Event message when an object uses llRegionSayTo - - - Special value to support llRegionSay, never sent to the client - - - - Identifies the source of a chat message - - - - Chat from the grid or simulator - - - Chat from another avatar - - - Chat from an object - - - - - - - - - - - - - - - - - - Effect type used in ViewerEffect packets - - - - - - - - - - - - - - - - - - - - - - - - - Project a beam from a source to a destination, such as - the one used when editing an object - - - - - - - - - - - - Create a swirl of particles around an object - - - - - - - - - Cause an avatar to look at an object - - - Cause an avatar to point at an object - - - - The action an avatar is doing when looking at something, used in - ViewerEffect packets for the LookAt effect - - - - - - - - - - - - - - - - - - - - - - Deprecated - - - - - - - - - - - - - - - - The action an avatar is doing when pointing at something, used in - ViewerEffect packets for the PointAt effect - - - - - - - - - - - - - - - - - Money transaction types - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Flags sent when a script takes or releases a control - - NOTE: (need to verify) These might be a subset of the ControlFlags enum in Movement, - - - No Flags set - - - Forward (W or up Arrow) - - - Back (S or down arrow) - - - Move left (shift+A or left arrow) - - - Move right (shift+D or right arrow) - - - Up (E or PgUp) - - - Down (C or PgDown) - - - Rotate left (A or left arrow) - - - Rotate right (D or right arrow) - - - Left Mouse Button - - - Left Mouse button in MouseLook - - - - Currently only used to hide your group title - - - - No flags set - - - Hide your group title - - - - Action state of the avatar, which can currently be typing and - editing - - - - - - - - - - - - - - Current teleport status - - - - Unknown status - - - Teleport initialized - - - Teleport in progress - - - Teleport failed - - - Teleport completed - - - Teleport cancelled - - - - - - - - No flags set, or teleport failed - - - Set when newbie leaves help island for first time - - - - - - Via Lure - - - Via Landmark - - - Via Location - - - Via Home - - - Via Telehub - - - Via Login - - - Linden Summoned - - - Linden Forced me - - - - - - Agent Teleported Home via Script - - - - - - - - - - - - forced to new location for example when avatar is banned or ejected - - - Teleport Finished via a Lure - - - Finished, Sim Changed - - - Finished, Same Sim - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Type of mute entry - - - - Object muted by name - - - Muted residet - - - Object muted by UUID - - - Muted group - - - Muted external entry - - - - Flags of mute entry - - - - No exceptions - - - Don't mute text chat - - - Don't mute voice chat - - - Don't mute particles - - - Don't mute sounds - - - Don't mute - - - - Instant Message - - - - Key of sender - - - Name of sender - - - Key of destination avatar - - - ID of originating estate - - - Key of originating region - - - Coordinates in originating region - - - Instant message type - - - Group IM session toggle - - - Key of IM session, for Group Messages, the groups UUID - - - Timestamp of the instant message - - - Instant message text - - - Whether this message is held for offline avatars - - - Context specific packed data - - - Print the struct data as a string - A string containing the field name, and field value - - - Represents muted object or resident - - - Type of the mute entry - - - UUID of the mute etnry - - - Mute entry name - - - Mute flags - - - Transaction detail sent with MoneyBalanceReply message - - - Type of the transaction - - - UUID of the transaction source - - - Is the transaction source a group - - - UUID of the transaction destination - - - Is transaction destination a group - - - Transaction amount - - - Transaction description - - - - Manager class for our own avatar - - - - - Called once attachment resource usage information has been collected - - Indicates if operation was successfull - Attachment resource usage information - - - The event subscribers. null if no subcribers - - - Raises the ChatFromSimulator event - A ChatEventArgs object containing the - data returned from the data server - - - Thread sync lock object - - - Raised when a scripted object or agent within range sends a public message - - - The event subscribers. null if no subcribers - - - Raises the ScriptDialog event - A SctriptDialogEventArgs object containing the - data returned from the data server - - - Thread sync lock object - - - Raised when a scripted object sends a dialog box containing possible - options an agent can respond to - - - The event subscribers. null if no subcribers - - - Raises the ScriptQuestion event - A ScriptQuestionEventArgs object containing the - data returned from the data server - - - Thread sync lock object - - - Raised when an object requests a change in the permissions an agent has permitted - - - The event subscribers. null if no subcribers - - - Raises the LoadURL event - A LoadUrlEventArgs object containing the - data returned from the data server - - - Thread sync lock object - - - Raised when a script requests an agent open the specified URL - - - The event subscribers. null if no subcribers - - - Raises the MoneyBalance event - A BalanceEventArgs object containing the - data returned from the data server - - - Thread sync lock object - - - Raised when an agents currency balance is updated - - - The event subscribers. null if no subcribers - - - Raises the MoneyBalanceReply event - A MoneyBalanceReplyEventArgs object containing the - data returned from the data server - - - Thread sync lock object - - - Raised when a transaction occurs involving currency such as a land purchase - - - The event subscribers. null if no subcribers - - - Raises the IM event - A InstantMessageEventArgs object containing the - data returned from the data server - - - Thread sync lock object - - - Raised when an ImprovedInstantMessage packet is recieved from the simulator, this is used for everything from - private messaging to friendship offers. The Dialog field defines what type of message has arrived - - - The event subscribers. null if no subcribers - - - Raises the TeleportProgress event - A TeleportEventArgs object containing the - data returned from the data server - - - Thread sync lock object - - - Raised when an agent has requested a teleport to another location, or when responding to a lure. Raised multiple times - for each teleport indicating the progress of the request - - - The event subscribers. null if no subcribers - - - Raises the AgentDataReply event - A AgentDataReplyEventArgs object containing the - data returned from the data server - - - Thread sync lock object - - - Raised when a simulator sends agent specific information for our avatar. - - - The event subscribers. null if no subcribers - - - Raises the AnimationsChanged event - A AnimationsChangedEventArgs object containing the - data returned from the data server - - - Thread sync lock object - - - Raised when our agents animation playlist changes - - - The event subscribers. null if no subcribers - - - Raises the MeanCollision event - A MeanCollisionEventArgs object containing the - data returned from the data server - - - Thread sync lock object - - - Raised when an object or avatar forcefully collides with our agent - - - The event subscribers. null if no subcribers - - - Raises the RegionCrossed event - A RegionCrossedEventArgs object containing the - data returned from the data server - - - Thread sync lock object - - - Raised when our agent crosses a region border into another region - - - The event subscribers. null if no subcribers - - - Raises the GroupChatJoined event - A GroupChatJoinedEventArgs object containing the - data returned from the data server - - - Thread sync lock object - - - Raised when our agent succeeds or fails to join a group chat session - - - The event subscribers. null if no subscribers - - - Raises the AlertMessage event - A AlertMessageEventArgs object containing the - data returned from the data server - - - Thread sync lock object - - - Raised when a simulator sends an urgent message usually indication the recent failure of - another action we have attempted to take such as an attempt to enter a parcel where we are denied access - - - The event subscribers. null if no subcribers - - - Raises the ScriptControlChange event - A ScriptControlEventArgs object containing the - data returned from the data server - - - Thread sync lock object - - - Raised when a script attempts to take or release specified controls for our agent - - - The event subscribers. null if no subcribers - - - Raises the CameraConstraint event - A CameraConstraintEventArgs object containing the - data returned from the data server - - - Thread sync lock object - - - Raised when the simulator detects our agent is trying to view something - beyond its limits - - - The event subscribers. null if no subcribers - - - Raises the ScriptSensorReply event - A ScriptSensorReplyEventArgs object containing the - data returned from the data server - - - Thread sync lock object - - - Raised when a script sensor reply is received from a simulator - - - The event subscribers. null if no subcribers - - - Raises the AvatarSitResponse event - A AvatarSitResponseEventArgs object containing the - data returned from the data server - - - Thread sync lock object - - - Raised in response to a request - - - The event subscribers. null if no subcribers - - - Raises the ChatSessionMemberAdded event - A ChatSessionMemberAddedEventArgs object containing the - data returned from the data server - - - Thread sync lock object - - - Raised when an avatar enters a group chat session we are participating in - - - The event subscribers. null if no subcribers - - - Raises the ChatSessionMemberLeft event - A ChatSessionMemberLeftEventArgs object containing the - data returned from the data server - - - Thread sync lock object - - - Raised when an agent exits a group chat session we are participating in - - - The event subscribers, null of no subscribers - - - Raises the SetDisplayNameReply Event - A SetDisplayNameReplyEventArgs object containing - the data sent from the simulator - - - Thread sync lock object - - - Raised when the simulator sends us data containing - the details of display name change - - - The event subscribers. null if no subcribers - - - Raises the MuteListUpdated event - A EventArgs object containing the - data returned from the data server - - - Thread sync lock object - - - Raised when a scripted object or agent within range sends a public message - - - Reference to the GridClient instance - - - Used for movement and camera tracking - - - Currently playing animations for the agent. Can be used to - check the current movement status such as walking, hovering, aiming, - etc. by checking against system animations found in the Animations class - - - Dictionary containing current Group Chat sessions and members - - - Dictionary containing mute list keyead on mute name and key - - - Your (client) avatars - "client", "agent", and "avatar" all represent the same thing - - - Temporary assigned to this session, used for - verifying our identity in packets - - - Shared secret that is never sent over the wire - - - Your (client) avatar ID, local to the current region/sim - - - Where the avatar started at login. Can be "last", "home" - or a login - - - The access level of this agent, usually M, PG or A - - - The CollisionPlane of Agent - - - An representing the velocity of our agent - - - An representing the acceleration of our agent - - - A which specifies the angular speed, and axis about which an Avatar is rotating. - - - Position avatar client will goto when login to 'home' or during - teleport request to 'home' region. - - - LookAt point saved/restored with HomePosition - - - Avatar First Name (i.e. Philip) - - - Avatar Last Name (i.e. Linden) - - - LookAt point received with the login response message - - - Avatar Full Name (i.e. Philip Linden) - - - Gets the health of the agent - - - Gets the current balance of the agent - - - Gets the local ID of the prim the agent is sitting on, - zero if the avatar is not currently sitting - - - Gets the of the agents active group. - - - Gets the Agents powers in the currently active group - - - Current status message for teleporting - - - Current position of the agent as a relative offset from - the simulator, or the parent object if we are sitting on something - - - Current rotation of the agent as a relative rotation from - the simulator, or the parent object if we are sitting on something - - - Current position of the agent in the simulator - - - - A representing the agents current rotation - - - - Returns the global grid position of the avatar - - - Various abilities and preferences sent by the grid - - - - Constructor, setup callbacks for packets related to our avatar - - A reference to the Class - - - - Send a text message from the Agent to the Simulator - - A containing the message - The channel to send the message on, 0 is the public channel. Channels above 0 - can be used however only scripts listening on the specified channel will see the message - Denotes the type of message being sent, shout, whisper, etc. - Enables large messages to be split into chunks of 900 with [CHUNKGROUPID|CHUNKID|TOTALCHUNKS] at the start - Hides [CHUNKGROUPID|CHUNKID|TOTALCHUNKS] at the start of chunked messages - - - - Request any instant messages sent while the client was offline to be resent. - - - - - Request offline instant messages via the legacy LLUDP packet - - - - - Send an Instant Message to another Avatar - - The recipients - A containing the message to send - - - - Send an Instant Message to an existing group chat or conference chat - - The recipients - A containing the message to send - IM session ID (to differentiate between IM windows) - - - - Send an Instant Message - - The name this IM will show up as being from - Key of Avatar - Text message being sent - IM session ID (to differentiate between IM windows) - IDs of sessions for a conference - - - - Send an Instant Message - - The name this IM will show up as being from - Key of Avatar - Text message being sent - IM session ID (to differentiate between IM windows) - Type of instant message to send - Whether to IM offline avatars as well - Senders Position - RegionID Sender is In - Packed binary data that is specific to - the dialog type - - - - Send an Instant Message to a group - - of the group to send message to - Text Message being sent. - - - - Send an Instant Message to a group the agent is a member of - - The name this IM will show up as being from - of the group to send message to - Text message being sent - - - - Send a request to join a group chat session - - of Group to leave - - - - Exit a group chat session. This will stop further Group chat messages - from being sent until session is rejoined. - - of Group chat session to leave - - - - Reply to script dialog questions. - - Channel initial request came on - Index of button you're "clicking" - Label of button you're "clicking" - of Object that sent the dialog request - - - - - Accept invite for to a chatterbox session - - of session to accept invite to - - - - Start a friends conference - - List of UUIDs to start a conference with - the temporary session ID returned in the callback> - - - - Start a particle stream between an agent and an object - - Key of the source agent - Key of the target object - - The type from the enum - A unique for this effect - - - - Start a particle stream between an agent and an object - - Key of the source agent - Key of the target object - A representing the beams offset from the source - A which sets the avatars lookat animation - of the Effect - - - - Create a particle beam between an avatar and an primitive - - The ID of source avatar - The ID of the target primitive - global offset - A object containing the combined red, green, blue and alpha - color values of particle beam - a float representing the duration the parcicle beam will last - A Unique ID for the beam - - - - - Create a particle swirl around a target position using a packet - - global offset - A object containing the combined red, green, blue and alpha - color values of particle beam - a float representing the duration the parcicle beam will last - A Unique ID for the beam - - - - Sends a request to sit on the specified object - - of the object to sit on - Sit at offset - - - - Follows a call to to actually sit on the object - - - - Stands up from sitting on a prim or the ground - true of AgentUpdate was sent - - - - Does a "ground sit" at the avatar's current position - - - - - Starts or stops flying - - True to start flying, false to stop flying - - - - Starts or stops crouching - - True to start crouching, false to stop crouching - - - - Starts a jump (begin holding the jump key) - - - - - Use the autopilot sim function to move the avatar to a new - position. Uses double precision to get precise movements - - The z value is currently not handled properly by the simulator - Global X coordinate to move to - Global Y coordinate to move to - Z coordinate to move to - - - - Use the autopilot sim function to move the avatar to a new position - - The z value is currently not handled properly by the simulator - Integer value for the global X coordinate to move to - Integer value for the global Y coordinate to move to - Floating-point value for the Z coordinate to move to - - - - Use the autopilot sim function to move the avatar to a new position - - The z value is currently not handled properly by the simulator - Integer value for the local X coordinate to move to - Integer value for the local Y coordinate to move to - Floating-point value for the Z coordinate to move to - - - Macro to cancel autopilot sim function - Not certain if this is how it is really done - true if control flags were set and AgentUpdate was sent to the simulator - - - - Grabs an object - - an unsigned integer of the objects ID within the simulator - - - - - Overload: Grab a simulated object - - an unsigned integer of the objects ID within the simulator - - The texture coordinates to grab - The surface coordinates to grab - The face of the position to grab - The region coordinates of the position to grab - The surface normal of the position to grab (A normal is a vector perpendicular to the surface) - The surface bi-normal of the position to grab (A bi-normal is a vector tangent to the surface - pointing along the U direction of the tangent space - - - - Drag an object - - of the object to drag - Drag target in region coordinates - - - - Overload: Drag an object - - of the object to drag - Drag target in region coordinates - - The texture coordinates to grab - The surface coordinates to grab - The face of the position to grab - The region coordinates of the position to grab - The surface normal of the position to grab (A normal is a vector perpendicular to the surface) - The surface bi-normal of the position to grab (A bi-normal is a vector tangent to the surface - pointing along the U direction of the tangent space - - - - Release a grabbed object - - The Objects Simulator Local ID - - - - - - - Release a grabbed object - - The Objects Simulator Local ID - The texture coordinates to grab - The surface coordinates to grab - The face of the position to grab - The region coordinates of the position to grab - The surface normal of the position to grab (A normal is a vector perpendicular to the surface) - The surface bi-normal of the position to grab (A bi-normal is a vector tangent to the surface - pointing along the U direction of the tangent space - - - - Touches an object - - an unsigned integer of the objects ID within the simulator - - - - - Request the current L$ balance - - - - - Give Money to destination Avatar - - UUID of the Target Avatar - Amount in L$ - - - - Give Money to destination Avatar - - UUID of the Target Avatar - Amount in L$ - Description that will show up in the - recipients transaction history - - - - Give L$ to an object - - object to give money to - amount of L$ to give - name of object - - - - Give L$ to a group - - group to give money to - amount of L$ to give - - - - Give L$ to a group - - group to give money to - amount of L$ to give - description of transaction - - - - Pay texture/animation upload fee - - - - - Pay texture/animation upload fee - - description of the transaction - - - - Give Money to destination Object or Avatar - - UUID of the Target Object/Avatar - Amount in L$ - Reason (Optional normally) - The type of transaction - Transaction flags, mostly for identifying group - transactions - - - - Plays a gesture - - Asset of the gesture - - - - Mark gesture active - - Inventory of the gesture - Asset of the gesture - - - - Mark gesture inactive - - Inventory of the gesture - - - - Send an AgentAnimation packet that toggles a single animation on - - The of the animation to start playing - Whether to ensure delivery of this packet or not - - - - Send an AgentAnimation packet that toggles a single animation off - - The of a - currently playing animation to stop playing - Whether to ensure delivery of this packet or not - - - - Send an AgentAnimation packet that will toggle animations on or off - - A list of animation s, and whether to - turn that animation on or off - Whether to ensure delivery of this packet or not - - - - Teleports agent to their stored home location - - true on successful teleport to home location - - - - Teleport agent to a landmark - - of the landmark to teleport agent to - true on success, false on failure - - - - Attempt to look up a simulator name and teleport to the discovered - destination - - Region name to look up - Position to teleport to - True if the lookup and teleport were successful, otherwise - false - - - - Attempt to look up a simulator name and teleport to the discovered - destination - - Region name to look up - Position to teleport to - Target to look at - True if the lookup and teleport were successful, otherwise - false - - - - Teleport agent to another region - - handle of region to teleport agent to - position in destination sim to teleport to - true on success, false on failure - This call is blocking - - - - Teleport agent to another region - - handle of region to teleport agent to - position in destination sim to teleport to - direction in destination sim agent will look at - true on success, false on failure - This call is blocking - - - - Request teleport to a another simulator - - handle of region to teleport agent to - position in destination sim to teleport to - - - - Request teleport to a another simulator - - handle of region to teleport agent to - position in destination sim to teleport to - direction in destination sim agent will look at - - - - Teleport agent to a landmark - - of the landmark to teleport agent to - - - - Send a teleport lure to another avatar with default "Join me in ..." invitation message - - target avatars to lure - - - - Send a teleport lure to another avatar with custom invitation message - - target avatars to lure - custom message to send with invitation - - - - Respond to a teleport lure by either accepting it and initiating - the teleport, or denying it - - of the avatar sending the lure - IM session of the incoming lure request - true to accept the lure, false to decline it - - - - Request a teleport lure from another agent - - of the avatar lure is being requested from - IM session - message to send with request - - - - Update agent profile - - struct containing updated - profile information - - - - Update agent's profile interests - - selection of interests from struct - - - - Update agent's private notes for target avatar - - target avatar for notes - notes to store - - - - Set the height and the width of the client window. This is used - by the server to build a virtual camera frustum for our avatar - - New height of the viewer window - New width of the viewer window - - - - Request the list of muted objects and avatars for this agent - - - - - Mute an object, resident, etc. - - Mute type - Mute UUID - Mute name - - - - Mute an object, resident, etc. - - Mute type - Mute UUID - Mute name - Mute flags - - - - Unmute an object, resident, etc. - - Mute UUID - Mute name - - - - Sets home location to agents current position - - will fire an AlertMessage () with - success or failure message - - - - Move an agent in to a simulator. This packet is the last packet - needed to complete the transition in to a new simulator - - Object - - - - Reply to script permissions request - - Object - of the itemID requesting permissions - of the taskID requesting permissions - list of permissions to allow - - - - Respond to a group invitation by either accepting or denying it - - UUID of the group (sent in the AgentID field of the invite message) - IM Session ID from the group invitation message - Accept the group invitation or deny it - - - - Requests script detection of objects and avatars - - name of the object/avatar to search for - UUID of the object or avatar to search for - Type of search from ScriptSensorTypeFlags - range of scan (96 max?) - the arc in radians to search within - an user generated ID to correlate replies with - Simulator to perform search in - - - - Create or update profile pick - - UUID of the pick to update, or random UUID to create a new pick - Is this a top pick? (typically false) - UUID of the parcel (UUID.Zero for the current parcel) - Name of the pick - Global position of the pick landmark - UUID of the image displayed with the pick - Long description of the pick - - - - Delete profile pick - - UUID of the pick to delete - - - - Create or update profile Classified - - UUID of the classified to update, or random UUID to create a new classified - Defines what category the classified is in - UUID of the image displayed with the classified - Price that the classified will cost to place for a week - Global position of the classified landmark - Name of the classified - Long description of the classified - if true, auto renew classified after expiration - - - - Create or update profile Classified - - UUID of the classified to update, or random UUID to create a new classified - Defines what category the classified is in - UUID of the image displayed with the classified - Price that the classified will cost to place for a week - Name of the classified - Long description of the classified - if true, auto renew classified after expiration - - - - Delete a classified ad - - The classified ads ID - - - - Fetches resource usage by agents attachments - - Called when the requested information is collected - - - - Initiates request to set a new display name - - Previous display name - Desired new display name - - - - Tells the sim what UI language is used, and if it's ok to share that with scripts - - Two letter language code - Share language info with scripts - - - - Sets agents maturity access level - - PG, M or A - - - - Sets agents maturity access level - - PG, M or A - Callback function - - - - Sets agents hover height. - - Hover height [-2.0, 2.0] - - - - Take an incoming ImprovedInstantMessage packet, auto-parse, and if - OnInstantMessage is defined call that with the appropriate arguments - - The sender - The EventArgs object containing the packet data - - - - Take an incoming Chat packet, auto-parse, and if OnChat is defined call - that with the appropriate arguments. - - The sender - The EventArgs object containing the packet data - - - - Used for parsing llDialogs - - The sender - The EventArgs object containing the packet data - - - - Used for parsing llRequestPermissions dialogs - - The sender - The EventArgs object containing the packet data - - - - Handles Script Control changes when Script with permissions releases or takes a control - - The sender - The EventArgs object containing the packet data - - - - Used for parsing llLoadURL Dialogs - - The sender - The EventArgs object containing the packet data - - - - Update client's Position, LookAt and region handle from incoming packet - - The sender - The EventArgs object containing the packet data - This occurs when after an avatar moves into a new sim - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - - - - EQ Message fired with the result of SetDisplayName request - - The message key - the IMessage object containing the deserialized data sent from the simulator - The which originated the packet - - - - Process TeleportFailed message sent via EventQueue, informs agent its last teleport has failed and why. - - The Message Key - An IMessage object Deserialized from the recieved message event - The simulator originating the event message - - - - Process TeleportFinish from Event Queue and pass it onto our TeleportHandler - - The message system key for this event - IMessage object containing decoded data from OSD - The simulator originating the event message - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - - - - Crossed region handler for message that comes across the EventQueue. Sent to an agent - when the agent crosses a sim border into a new region. - - The message key - the IMessage object containing the deserialized data sent from the simulator - The which originated the packet - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - This packet is now being sent via the EventQueue - - - - Group Chat event handler - - The capability Key - IMessage object containing decoded data from OSD - - - - - Response from request to join a group chat - - - IMessage object containing decoded data from OSD - - - - - Someone joined or left group chat - - - IMessage object containing decoded data from OSD - - - - - Handle a group chat Invitation - - Caps Key - IMessage object containing decoded data from OSD - Originating Simulator - - - - Moderate a chat session - - the of the session to moderate, for group chats this will be the groups UUID - the of the avatar to moderate - Either "voice" to moderate users voice, or "text" to moderate users text session - true to moderate (silence user), false to allow avatar to speak - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - - - - Agent movement and camera control - - Agent movement is controlled by setting specific - After the control flags are set, An AgentUpdate is required to update the simulator of the specified flags - This is most easily accomplished by setting one or more of the AgentMovement properties - - Movement of an avatar is always based on a compass direction, for example AtPos will move the - agent from West to East or forward on the X Axis, AtNeg will of course move agent from - East to West or backward on the X Axis, LeftPos will be South to North or forward on the Y Axis - The Z axis is Up, finer grained control of movements can be done using the Nudge properties - - - - - Camera controls for the agent, mostly a thin wrapper around - CoordinateFrame. This class is only responsible for state - tracking and math, it does not send any packets - - - - - - - The camera is a local frame of reference inside of - the larger grid space. This is where the math happens - - - - - - - - - - - - - - - - Default constructor - - - - Move agent positive along the X axis - - - Move agent negative along the X axis - - - Move agent positive along the Y axis - - - Move agent negative along the Y axis - - - Move agent positive along the Z axis - - - Move agent negative along the Z axis - - - - - - - - - - - - - - - - - - - - - - - - Causes simulator to make agent fly - - - Stop movement - - - Finish animation - - - Stand up from a sit - - - Tells simulator to sit agent on ground - - - Place agent into mouselook mode - - - Nudge agent positive along the X axis - - - Nudge agent negative along the X axis - - - Nudge agent positive along the Y axis - - - Nudge agent negative along the Y axis - - - Nudge agent positive along the Z axis - - - Nudge agent negative along the Z axis - - - - - - - - - Tell simulator to mark agent as away - - - - - - - - - - - - - - - - Returns "always run" value, or changes it by sending a SetAlwaysRunPacket - - - - The current value of the agent control flags - - - Gets or sets the interval in milliseconds at which - AgentUpdate packets are sent to the current simulator. Setting - this to a non-zero value will also enable the packet sending if - it was previously off, and setting it to zero will disable - - - Gets or sets whether AgentUpdate packets are sent to - the current simulator - - - Reset movement controls every time we send an update - - - Agent camera controls - - - Currently only used for hiding your group title - - - Action state of the avatar, which can currently be - typing and editing - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Timer for sending AgentUpdate packets - - - Default constructor - - - - Send an AgentUpdate with the camera set at the current agent - position and pointing towards the heading specified - - Camera rotation in radians - Whether to send the AgentUpdate reliable - or not - - - - Rotates the avatar body and camera toward a target position. - This will also anchor the camera position on the avatar - - Region coordinates to turn toward - - - - Rotates the avatar body and camera toward a target position. - This will also anchor the camera position on the avatar - - Region coordinates to turn toward - whether to send update or not - - - - Send new AgentUpdate packet to update our current camera - position and rotation - - - - - Send new AgentUpdate packet to update our current camera - position and rotation - - Whether to require server acknowledgement - of this packet - - - - Send new AgentUpdate packet to update our current camera - position and rotation - - Whether to require server acknowledgement - of this packet - Simulator to send the update to - - - - Builds an AgentUpdate packet entirely from parameters. This - will not touch the state of Self.Movement or - Self.Movement.Camera in any way - - - - - - - - - - - - - - - - Sends update of Field of Vision vertical angle to the simulator - - Angle in radians - - - - Used to specify movement actions for your agent - - - - Empty flag - - - Move Forward (SL Keybinding: W/Up Arrow) - - - Move Backward (SL Keybinding: S/Down Arrow) - - - Move Left (SL Keybinding: Shift-(A/Left Arrow)) - - - Move Right (SL Keybinding: Shift-(D/Right Arrow)) - - - Not Flying: Jump/Flying: Move Up (SL Keybinding: E) - - - Not Flying: Croutch/Flying: Move Down (SL Keybinding: C) - - - Unused - - - Unused - - - Unused - - - Unused - - - ORed with AGENT_CONTROL_AT_* if the keyboard is being used - - - ORed with AGENT_CONTROL_LEFT_* if the keyboard is being used - - - ORed with AGENT_CONTROL_UP_* if the keyboard is being used - - - Fly - - - - - - Finish our current animation - - - Stand up from the ground or a prim seat - - - Sit on the ground at our current location - - - Whether mouselook is currently enabled - - - Legacy, used if a key was pressed for less than a certain amount of time - - - Legacy, used if a key was pressed for less than a certain amount of time - - - Legacy, used if a key was pressed for less than a certain amount of time - - - Legacy, used if a key was pressed for less than a certain amount of time - - - Legacy, used if a key was pressed for less than a certain amount of time - - - Legacy, used if a key was pressed for less than a certain amount of time - - - - - - - - - Set when the avatar is idled or set to away. Note that the away animation is - activated separately from setting this flag - - - - - - - - - - - - - - - - Class for sending info on the success of the opration - of setting the maturity access level - - - - - New maturity accesss level returned from the sim - - - - - True if setting the new maturity access level has succedded - - - - - Creates new instance of the EventArgs class - - Has setting new maturty access level succeeded - New maturity access level as returned by the simulator - - - - - - - - Get the simulator sending the message - - - Get the message sent - - - Get the audible level of the message - - - Get the type of message sent: whisper, shout, etc - - - Get the source type of the message sender - - - Get the name of the agent or object sending the message - - - Get the ID of the agent or object sending the message - - - Get the ID of the object owner, or the agent ID sending the message - - - Get the position of the agent or object sending the message - - - - Construct a new instance of the ChatEventArgs object - - Sim from which the message originates - The message sent - The audible level of the message - The type of message sent: whisper, shout, etc - The source type of the message sender - The name of the agent or object sending the message - The ID of the agent or object sending the message - The ID of the object owner, or the agent ID sending the message - The position of the agent or object sending the message - - - Contains the data sent when a primitive opens a dialog with this agent - - - Get the dialog message - - - Get the name of the object that sent the dialog request - - - Get the ID of the image to be displayed - - - Get the ID of the primitive sending the dialog - - - Get the first name of the senders owner - - - Get the last name of the senders owner - - - Get the communication channel the dialog was sent on, responses - should also send responses on this same channel - - - Get the string labels containing the options presented in this dialog - - - UUID of the scritped object owner - - - - Construct a new instance of the ScriptDialogEventArgs - - The dialog message - The name of the object that sent the dialog request - The ID of the image to be displayed - The ID of the primitive sending the dialog - The first name of the senders owner - The last name of the senders owner - The communication channel the dialog was sent on - The string labels containing the options presented in this dialog - UUID of the scritped object owner - - - Contains the data sent when a primitive requests debit or other permissions - requesting a YES or NO answer - - - Get the simulator containing the object sending the request - - - Get the ID of the script making the request - - - Get the ID of the primitive containing the script making the request - - - Get the name of the primitive making the request - - - Get the name of the owner of the object making the request - - - Get the permissions being requested - - - - Construct a new instance of the ScriptQuestionEventArgs - - The simulator containing the object sending the request - The ID of the script making the request - The ID of the primitive containing the script making the request - The name of the primitive making the request - The name of the owner of the object making the request - The permissions being requested - - - Contains the data sent when a primitive sends a request - to an agent to open the specified URL - - - Get the name of the object sending the request - - - Get the ID of the object sending the request - - - Get the ID of the owner of the object sending the request - - - True if the object is owned by a group - - - Get the message sent with the request - - - Get the URL the object sent - - - - Construct a new instance of the LoadUrlEventArgs - - The name of the object sending the request - The ID of the object sending the request - The ID of the owner of the object sending the request - True if the object is owned by a group - The message sent with the request - The URL the object sent - - - The date received from an ImprovedInstantMessage - - - Get the InstantMessage object - - - Get the simulator where the InstantMessage origniated - - - - Construct a new instance of the InstantMessageEventArgs object - - the InstantMessage object - the simulator where the InstantMessage origniated - - - Contains the currency balance - - - - Get the currenct balance - - - - - Construct a new BalanceEventArgs object - - The currenct balance - - - Contains the transaction summary when an item is purchased, - money is given, or land is purchased - - - Get the ID of the transaction - - - True of the transaction was successful - - - Get the remaining currency balance - - - Get the meters credited - - - Get the meters comitted - - - Get the description of the transaction - - - Detailed transaction information - - - - Construct a new instance of the MoneyBalanceReplyEventArgs object - - The ID of the transaction - True of the transaction was successful - The current currency balance - The meters credited - The meters comitted - A brief description of the transaction - Transaction info - - - Data sent from the simulator containing information about your agent and active group information - - - Get the agents first name - - - Get the agents last name - - - Get the active group ID of your agent - - - Get the active groups title of your agent - - - Get the combined group powers of your agent - - - Get the active group name of your agent - - - - Construct a new instance of the AgentDataReplyEventArgs object - - The agents first name - The agents last name - The agents active group ID - The group title of the agents active group - The combined group powers the agent has in the active group - The name of the group the agent has currently active - - - Data sent by the simulator to indicate the active/changed animations - applied to your agent - - - Get the dictionary that contains the changed animations - - - - Construct a new instance of the AnimationsChangedEventArgs class - - The dictionary that contains the changed animations - - - - Data sent from a simulator indicating a collision with your agent - - - - Get the Type of collision - - - Get the ID of the agent or object that collided with your agent - - - Get the ID of the agent that was attacked - - - A value indicating the strength of the collision - - - Get the time the collision occurred - - - - Construct a new instance of the MeanCollisionEventArgs class - - The type of collision that occurred - The ID of the agent or object that perpetrated the agression - The ID of the Victim - The strength of the collision - The Time the collision occurred - - - Data sent to your agent when it crosses region boundaries - - - Get the simulator your agent just left - - - Get the simulator your agent is now in - - - - Construct a new instance of the RegionCrossedEventArgs class - - The simulator your agent just left - The simulator your agent is now in - - - Data sent from the simulator when your agent joins a group chat session - - - Get the ID of the group chat session - - - Get the name of the session - - - Get the temporary session ID used for establishing new sessions - - - True if your agent successfully joined the session - - - - Construct a new instance of the GroupChatJoinedEventArgs class - - The ID of the session - The name of the session - A temporary session id used for establishing new sessions - True of your agent successfully joined the session - - - Data sent by the simulator containing urgent messages - - - - Construct a new instance of the AlertMessageEventArgs class - - user readable message - notification id for alert, may be null - any extra params in OSD format, may be null - - - Data sent by a script requesting to take or release specified controls to your agent - - - Get the controls the script is attempting to take or release to the agent - - - True if the script is passing controls back to the agent - - - True if the script is requesting controls be released to the script - - - - Construct a new instance of the ScriptControlEventArgs class - - The controls the script is attempting to take or release to the agent - True if the script is passing controls back to the agent - True if the script is requesting controls be released to the script - - - - Data sent from the simulator to an agent to indicate its view limits - - - - Get the collision plane - - - - Construct a new instance of the CameraConstraintEventArgs class - - The collision plane - - - - Data containing script sensor requests which allow an agent to know the specific details - of a primitive sending script sensor requests - - - - Get the ID of the primitive sending the sensor - - - Get the ID of the group associated with the primitive - - - Get the name of the primitive sending the sensor - - - Get the ID of the primitive sending the sensor - - - Get the ID of the owner of the primitive sending the sensor - - - Get the position of the primitive sending the sensor - - - Get the range the primitive specified to scan - - - Get the rotation of the primitive sending the sensor - - - Get the type of sensor the primitive sent - - - Get the velocity of the primitive sending the sensor - - - - Construct a new instance of the ScriptSensorReplyEventArgs - - The ID of the primitive sending the sensor - The ID of the group associated with the primitive - The name of the primitive sending the sensor - The ID of the primitive sending the sensor - The ID of the owner of the primitive sending the sensor - The position of the primitive sending the sensor - The range the primitive specified to scan - The rotation of the primitive sending the sensor - The type of sensor the primitive sent - The velocity of the primitive sending the sensor - - - Contains the response data returned from the simulator in response to a - - - Get the ID of the primitive the agent will be sitting on - - - True if the simulator Autopilot functions were involved - - - Get the camera offset of the agent when seated - - - Get the camera eye offset of the agent when seated - - - True of the agent will be in mouselook mode when seated - - - Get the position of the agent when seated - - - Get the rotation of the agent when seated - - - Construct a new instance of the AvatarSitResponseEventArgs object - - - Data sent when an agent joins a chat session your agent is currently participating in - - - Get the ID of the chat session - - - Get the ID of the agent that joined - - - - Construct a new instance of the ChatSessionMemberAddedEventArgs object - - The ID of the chat session - The ID of the agent joining - - - Data sent when an agent exits a chat session your agent is currently participating in - - - Get the ID of the chat session - - - Get the ID of the agent that left - - - - Construct a new instance of the ChatSessionMemberLeftEventArgs object - - The ID of the chat session - The ID of the Agent that left - - - Event arguments with the result of setting display name operation - - - Status code, 200 indicates settign display name was successful - - - Textual description of the status - - - Details of the newly set display name - - - Default constructor - - - - Throttles the network traffic for various different traffic types. - Access this class through GridClient.Throttle - - - - Maximum bits per second for resending unacknowledged packets - - - Maximum bits per second for LayerData terrain - - - Maximum bits per second for LayerData wind data - - - Maximum bits per second for LayerData clouds - - - Unknown, includes object data - - - Maximum bits per second for textures - - - Maximum bits per second for downloaded assets - - - Maximum bits per second the entire connection, divided up - between invidiual streams using default multipliers - - - - Default constructor, uses a default high total of 1500 KBps (1536000) - - - - - Constructor that decodes an existing AgentThrottle packet in to - individual values - - Reference to the throttle data in an AgentThrottle - packet - Offset position to start reading at in the - throttle data - This is generally not needed in clients as the server will - never send a throttle packet to the client - - - - Send an AgentThrottle packet to the current server using the - current values - - - - - Send an AgentThrottle packet to the specified server using the - current values - - - - - Convert the current throttle values to a byte array that can be put - in an AgentThrottle packet - - Byte array containing all the throttle values - - - - Static pre-defined animations available to all agents - - - - Agent with afraid expression on face - - - Agent aiming a bazooka (right handed) - - - Agent aiming a bow (left handed) - - - Agent aiming a hand gun (right handed) - - - Agent aiming a rifle (right handed) - - - Agent with angry expression on face - - - Agent hunched over (away) - - - Agent doing a backflip - - - Agent laughing while holding belly - - - Agent blowing a kiss - - - Agent with bored expression on face - - - Agent bowing to audience - - - Agent brushing himself/herself off - - - Agent in busy mode - - - Agent clapping hands - - - Agent doing a curtsey bow - - - Agent crouching - - - Agent crouching while walking - - - Agent crying - - - Agent unanimated with arms out (e.g. setting appearance) - - - Agent re-animated after set appearance finished - - - Agent dancing - - - Agent dancing - - - Agent dancing - - - Agent dancing - - - Agent dancing - - - Agent dancing - - - Agent dancing - - - Agent dancing - - - Agent on ground unanimated - - - Agent boozing it up - - - Agent with embarassed expression on face - - - Agent with afraid expression on face - - - Agent with angry expression on face - - - Agent with bored expression on face - - - Agent crying - - - Agent showing disdain (dislike) for something - - - Agent with embarassed expression on face - - - Agent with frowning expression on face - - - Agent with kissy face - - - Agent expressing laughgter - - - Agent with open mouth - - - Agent with repulsed expression on face - - - Agent expressing sadness - - - Agent shrugging shoulders - - - Agent with a smile - - - Agent expressing surprise - - - Agent sticking tongue out - - - Agent with big toothy smile - - - Agent winking - - - Agent expressing worry - - - Agent falling down - - - Agent walking (feminine version) - - - Agent wagging finger (disapproval) - - - I'm not sure I want to know - - - Agent in superman position - - - Agent in superman position - - - Agent greeting another - - - Agent holding bazooka (right handed) - - - Agent holding a bow (left handed) - - - Agent holding a handgun (right handed) - - - Agent holding a rifle (right handed) - - - Agent throwing an object (right handed) - - - Agent in static hover - - - Agent hovering downward - - - Agent hovering upward - - - Agent being impatient - - - Agent jumping - - - Agent jumping with fervor - - - Agent point to lips then rear end - - - Agent landing from jump, finished flight, etc - - - Agent laughing - - - Agent landing from jump, finished flight, etc - - - Agent sitting on a motorcycle - - - - - - Agent moving head side to side - - - Agent moving head side to side with unhappy expression - - - Agent taunting another - - - - - - Agent giving peace sign - - - Agent pointing at self - - - Agent pointing at another - - - Agent preparing for jump (bending knees) - - - Agent punching with left hand - - - Agent punching with right hand - - - Agent acting repulsed - - - Agent trying to be Chuck Norris - - - Rocks, Paper, Scissors 1, 2, 3 - - - Agent with hand flat over other hand - - - Agent with fist over other hand - - - Agent with two fingers spread over other hand - - - Agent running - - - Agent appearing sad - - - Agent saluting - - - Agent shooting bow (left handed) - - - Agent cupping mouth as if shouting - - - Agent shrugging shoulders - - - Agent in sit position - - - Agent in sit position (feminine) - - - Agent in sit position (generic) - - - Agent sitting on ground - - - Agent sitting on ground - - - - - - Agent sleeping on side - - - Agent smoking - - - Agent inhaling smoke - - - - - - Agent taking a picture - - - Agent standing - - - Agent standing up - - - Agent standing - - - Agent standing - - - Agent standing - - - Agent standing - - - Agent stretching - - - Agent in stride (fast walk) - - - Agent surfing - - - Agent acting surprised - - - Agent striking with a sword - - - Agent talking (lips moving) - - - Agent throwing a tantrum - - - Agent throwing an object (right handed) - - - Agent trying on a shirt - - - Agent turning to the left - - - Agent turning to the right - - - Agent typing - - - Agent walking - - - Agent whispering - - - Agent whispering with fingers in mouth - - - Agent winking - - - Agent winking - - - Agent worried - - - Agent nodding yes - - - Agent nodding yes with happy face - - - Agent floating with legs and arms crossed - - - - A dictionary containing all pre-defined animations - - A dictionary containing the pre-defined animations, - where the key is the animations ID, and the value is a string - containing a name to identify the purpose of the animation - - - - Index of TextureEntry slots for avatar appearances - - - - - Bake layers for avatar appearance - - - - - Appearance Flags, introdued with server side baking, currently unused - - - - Mask for multiple attachments - - - Mapping between BakeType and AvatarTextureIndex - - - Maximum number of concurrent downloads for wearable assets and textures - - - Maximum number of concurrent uploads for baked textures - - - Timeout for fetching inventory listings - - - Timeout for fetching a single wearable, or receiving a single packet response - - - Timeout for fetching a single texture - - - Timeout for uploading a single baked texture - - - Number of times to retry bake upload - - - When changing outfit, kick off rebake after - 20 seconds has passed since the last change - - - Total number of wearables allowed for each avatar - - - Total number of wearables for each avatar - - - Total number of baked textures on each avatar - - - Total number of wearables per bake layer - - - Map of what wearables are included in each bake - - - Magic values to finalize the cache check hashes for each - bake - - - Default avatar texture, used to detect when a custom - texture is not set for a face - - - - Contains information about a wearable inventory item - - - - Inventory ItemID of the wearable - - - AssetID of the wearable asset - - - WearableType of the wearable - - - AssetType of the wearable - - - Asset data for the wearable - - - - Data collected from visual params for each wearable - needed for the calculation of the color - - - - - Holds a texture assetID and the data needed to bake this layer into - an outfit texture. Used to keep track of currently worn textures - and baking data - - - - A texture AssetID - - - Asset data for the texture - - - Collection of alpha masks that needs applying - - - Tint that should be applied to the texture - - - Where on avatar does this texture belong - - - The event subscribers. null if no subcribers - - - Raises the AgentWearablesReply event - An AgentWearablesReplyEventArgs object containing the - data returned from the data server - - - Thread sync lock object - - - Triggered when an AgentWearablesUpdate packet is received, - telling us what our avatar is currently wearing - request. - - - The event subscribers. null if no subcribers - - - Raises the CachedBakesReply event - An AgentCachedBakesReplyEventArgs object containing the - data returned from the data server AgentCachedTextureResponse - - - Thread sync lock object - - - Raised when an AgentCachedTextureResponse packet is - received, giving a list of cached bakes that were found on the - simulator - request. - - - The event subscribers. null if no subcribers - - - Raises the AppearanceSet event - An AppearanceSetEventArgs object indicating if the operatin was successfull - - - Thread sync lock object - - - - Raised when appearance data is sent to the simulator, also indicates - the main appearance thread is finished. - - request. - - - The event subscribers. null if no subcribers - - - Raises the RebakeAvatarRequested event - An RebakeAvatarTexturesEventArgs object containing the - data returned from the data server - - - Thread sync lock object - - - - Triggered when the simulator requests the agent rebake its appearance. - - - - - - Returns true if AppearanceManager is busy and trying to set or change appearance will fail - - - - Visual parameters last sent to the sim - - - Textures about this client sent to the sim - - - A cache of wearables currently being worn - - - A cache of attachments currently being worn - - - A cache of textures currently being worn - - - Incrementing serial number for AgentCachedTexture packets - - - Incrementing serial number for AgentSetAppearance packets - - - Indicates if WearablesRequest succeeded - - - Indicates whether or not the appearance thread is currently - running, to prevent multiple appearance threads from running - simultaneously - - - Reference to our agent - - - - Timer used for delaying rebake on changing outfit - - - - - Main appearance thread - - - - - Main appearance cancellation token source - - - - - Is server baking complete. It needs doing only once - - - - - Default constructor - - A reference to our agent - - - - Obsolete method for setting appearance. This function no longer does anything. - Use RequestSetAppearance() to manually start the appearance thread - - - - - Obsolete method for setting appearance. This function no longer does anything. - Use RequestSetAppearance() to manually start the appearance thread - - Unused parameter - - - - Starts the appearance setting thread - - - - - Starts the appearance setting thread - - True to force rebaking, otherwise false - - - - Check if current region supports server side baking - - True if server side baking support is detected - - - - Ask the server what textures our agent is currently wearing - - - - - Build hashes out of the texture assetIDs for each baking layer to - ask the simulator whether it has cached copies of each baked texture - - - - - OBSOLETE! Returns the AssetID of the first asset that is currently - being worn in a given WearableType slot - - WearableType slot to get the AssetID for - The UUID of the asset being worn in the given slot, or - UUID.Zero if no wearable is attached to the given slot or wearables - have not been downloaded yet - - - - Add a wearable to the current outfit and set appearance - - Wearable to be added to the outfit - - - - Add a wearable to the current outfit and set appearance - - Wearable to be added to the outfit - Should existing item on the same point or of the same type be replaced - - - - Add a list of wearables to the current outfit and set appearance - - List of wearable inventory items to - be added to the outfit - - - - Add a list of wearables to the current outfit and set appearance - - List of wearable inventory items to - be added to the outfit - Should existing item on the same point or of the same type be replaced - - - - Remove a wearable from the current outfit and set appearance - - Wearable to be removed from the outfit - - - - Removes a list of wearables from the current outfit and set appearance - - List of wearable inventory items to - be removed from the outfit - - - - Replace the current outfit with a list of wearables and set appearance - - List of wearable inventory items that - define a new outfit - - - - Replace the current outfit with a list of wearables and set appearance - - List of wearable inventory items that - define a new outfit - Check if we have all body parts, set this to false only - if you know what you're doing - - - - Checks if an inventory item is currently being worn - - The inventory item to check against the agent - wearables - The WearableType slot that the item is being worn in, - or WearbleType.Invalid if it is not currently being worn - - - - Returns a collection of the agents currently worn wearables - - A copy of the agents currently worn wearables - Avoid calling this function multiple times as it will make - a copy of all of the wearable data each time - - - - Calls either or - depending on the value of - replaceItems - - List of wearable inventory items to add - to the outfit or become a new outfit - True to replace existing items with the - new list of items, false to add these items to the existing outfit - - - - Adds a list of attachments to our agent - - A List containing the attachments to add - If true, tells simulator to remove existing attachment - If true replace existing attachment on this attachment point, otherwise add to it (multi-attachments) - first - - - - Attach an item to our agent at a specific attach point - - A to attach - the on the avatar - to attach the item to - - - - Attach an item to our agent at a specific attach point - - A to attach - the on the avatar - If true replace existing attachment on this attachment point, otherwise add to it (multi-attachments) - to attach the item to - - - - Attach an item to our agent specifying attachment details - - The of the item to attach - The attachments owner - The name of the attachment - The description of the attahment - The to apply when attached - The of the attachment - The on the agent - to attach the item to - - - - Attach an item to our agent specifying attachment details - - The of the item to attach - The attachments owner - The name of the attachment - The description of the attahment - The to apply when attached - The of the attachment - The on the agent - If true replace existing attachment on this attachment point, otherwise add to it (multi-attachments) - to attach the item to - - - - Detach an item from our agent using an object - - An object - - - - Detach an item from our agent - - The inventory itemID of the item to detach - - - - Retrieves the currently worn attachments. - removed async and Task due to no await. - - - - - - Returns a collection of the agents currently worn wearables - - A copy of the agents currently worn wearables - Avoid calling this function multiple times as it will make - a copy of all of the wearable data each time - - - - Inform the sim which wearables are part of our current outfit - - - - - Replaces the Wearables collection with a list of new wearable items - - Wearable items to replace the Wearables collection with - - - - Calculates base color/tint for a specific wearable - based on its params - - All the color info gathered from wearable's VisualParams - passed as list of ColorParamInfo tuples - Base color/tint for the wearable - - - - Blocking method to populate the Wearables dictionary - - True on success, otherwise false - - - - Blocking method to populate the Textures array with cached bakes - - True on success, otherwise false - - - - Populates textures and visual params from a decoded asset - - Wearable to decode - Texture data - - - - Blocking method to download and parse currently worn wearable assets - - True on success, otherwise false - - - - Get a list of all of the textures that need to be downloaded for a - single bake layer - - Bake layer to get texture AssetIDs for - A list of texture AssetIDs to download - - - - Blocking method to download all of the textures needed for baking - the given bake layers - - A list of layers that need baking - No return value is given because the baking will happen - whether or not all textures are successfully downloaded - - - - Blocking method to create and upload baked textures for all of the - missing bakes - - True on success, otherwise false - - - - Blocking method to create and upload a baked texture for a single - bake layer - - Layer to bake - True on success, otherwise false - - - - Blocking method to upload a baked texture - - Five channel JPEG2000 texture data to upload - UUID of the newly created asset on success, otherwise UUID.Zero - - - - Creates a dictionary of visual param values from the downloaded wearables - - A dictionary of visual param indices mapping to visual param - values for our agent that can be fed to the Baker class - - - - Initate server baking process - - True if the server baking was successful - - - - Get the latest version of COF - - Current Outfit Folder (or null if getting the data failed) - - - - Create an AgentSetAppearance packet from Wearables data and the - Textures array and send it - - - - - Converts a WearableType to a bodypart or clothing WearableType - - A WearableType - AssetType.Bodypart or AssetType.Clothing or AssetType.Unknown - - - - Converts a BakeType to the corresponding baked texture slot in AvatarTextureIndex - - A BakeType - The AvatarTextureIndex slot that holds the given BakeType - - - - Gives the layer number that is used for morph mask - - >A BakeType - Which layer number as defined in BakeTypeToTextures is used for morph mask - - - - Converts a BakeType to a list of the texture slots that make up that bake - - A BakeType - A list of texture slots that are inputs for the given bake - - - Contains the Event data returned from the data server from an AgentWearablesRequest - - - Contains the Event data returned from the data server from an AgentCachedTextureResponse - - - Contains the Event data returned from an AppearanceSetRequest - - - Indicates whether appearance setting was successful - - - - Triggered when appearance data is sent to the sim and - the main appearance thread is done. - Indicates whether appearance setting was successful - - - Contains the Event data returned from the data server from an RebakeAvatarTextures - - - The ID of the Texture Layer to bake - - - - Triggered when the simulator sends a request for this agent to rebake - its appearance - - The ID of the Texture Layer to bake - - - - Class that handles the local asset cache - - - - - Allows setting weather to periodicale prune the cache if it grows too big - Default is enabled, when caching is enabled - - - - - How long (in ms) between cache checks (default is 5 min.) - - - - - Default constructor - - A reference to the GridClient object - - - - Disposes cleanup timer - - - - - Only create timer when needed - - - - - Return bytes read from the local asset cache, null if it does not exist - - UUID of the asset we want to get - Raw bytes of the asset, or null on failure - - - - Returns ImageDownload object of the - image from the local image cache, null if it does not exist - - UUID of the image we want to get - ImageDownload object containing the image, or null on failure - - - - Constructs a file name of the cached asset - - UUID of the asset - String with the file name of the cahced asset - - - - Constructs a file name of the static cached asset - - UUID of the asset - String with the file name of the static cached asset - - - - Saves an asset to the local cache - - UUID of the asset - Raw bytes the asset consists of - Weather the operation was successfull - - - - Get the file name of the asset stored with gived UUID - - UUID of the asset - Null if we don't have that UUID cached on disk, file name if found in the cache folder - - - - Checks if the asset exists in the local cache - - UUID of the asset - True is the asset is stored in the cache, otherwise false - - - - Wipes out entire cache - - - - - Brings cache size to the 90% of the max size - - - - - Asynchronously brings cache size to the 90% of the max size - - - - - Adds up file sizes passes in a FileInfo array - - - - - Checks whether caching is enabled - - - - - Periodically prune the cache - - - - - Nicely formats file sizes - - Byte size we want to output - String with humanly readable file size - - - - Helper class for sorting files by their last accessed time - - - - - - - - - OK - - - Transfer completed - - - - - - - - - Unknown error occurred - - - Equivalent to a 404 error - - - Client does not have permission for that resource - - - Unknown status - - - - - - - - - - - Unknown - - - Virtually all asset transfers use this channel - - - - - - - - - - - Asset from the asset server - - - Inventory item - - - Estate asset, such as an estate covenant - - - - - - - - - - - - - - - - - - When requesting image download, type of the image requested - - - - Normal in-world object texture - - - Avatar texture - - - Server baked avatar texture - - - - Image file format - - - - - - - - - Number of milliseconds passed since the last transfer - packet was received - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Number of milliseconds to wait for a transfer header packet if out of order data was received - - - - Callback used for various asset download requests - - Transfer information - Downloaded asset, null on fail - - - - Callback used upon competition of baked texture upload - - Asset UUID of the newly uploaded baked texture - - - - A callback that fires upon the completion of the RequestMesh call - - Was the download successful - Resulting mesh or null on problems - - - The event subscribers. null if no subcribers - - - Raises the XferReceived event - A XferReceivedEventArgs object containing the - data returned from the simulator - - - Thread sync lock object - - - Raised when the simulator responds sends - - - The event subscribers. null if no subcribers - - - Raises the AssetUploaded event - A AssetUploadedEventArgs object containing the - data returned from the simulator - - - Thread sync lock object - - - Raised during upload completes - - - The event subscribers. null if no subcribers - - - Raises the UploadProgress event - A UploadProgressEventArgs object containing the - data returned from the simulator - - - Thread sync lock object - - - Raised during upload with progres update - - - The event subscribers. null if no subcribers - - - Raises the InitiateDownload event - A InitiateDownloadEventArgs object containing the - data returned from the simulator - - - Thread sync lock object - - - Fired when the simulator sends an InitiateDownloadPacket, used to download terrain .raw files - - - The event subscribers. null if no subcribers - - - Raises the ImageReceiveProgress event - A ImageReceiveProgressEventArgs object containing the - data returned from the simulator - - - Thread sync lock object - - - Fired when a texture is in the process of being downloaded by the TexturePipeline class - - - Texture download cache - - - - Default constructor - - A reference to the GridClient object - - - - Returns type name as string for a given AssetType - - - Type name - - - - Build uri for requesting an asset from ViewerAsset capability - - - - Request URI for an asset - - - - Request an asset download - - Asset UUID - Asset type, must be correct for the transfer to succeed - Whether to give this transfer an elevated priority - The callback to fire when the simulator responds with the asset data - - - - Request an asset download - - Asset UUID - Asset type, must be correct for the transfer to succeed - Whether to give this transfer an elevated priority - Source location of the requested asset - The callback to fire when the simulator responds with the asset data - - - - Request an asset download - - Asset UUID - Asset type, must be correct for the transfer to succeed - Whether to give this transfer an elevated priority - Source location of the requested asset - UUID of the transaction - The callback to fire when the simulator responds with the asset data - - - - - - - - - - - - - - - - - - - - - - - - - Request an asset download via LLUDP - - Asset UUID - task ID - - The callback to fire when the simulator responds with the asset data - Item ID - - - - Request an asset download through the almost deprecated Xfer system - - Filename of the asset to request - Whether or not to delete the asset - off the server after it is retrieved - Use large transfer packets or not - UUID of the file to request, if filename is - left empty - Asset type of vFileID, or - AssetType.Unknown if filename is not empty - Sets the FilePath in the request to Cache - (4) if true, otherwise Unknown (0) is used - - - - - Request Inventory Asset from UDP - - Use UUID.Zero if you do not have the - asset ID but have all the necessary permissions - - - - - - Request Inventory Asset from UDP - - Use UUID.Zero if you do not have the - asset ID but have all the necessary permissions - The item ID of this asset in the inventory - Use UUID.Zero if you are not requesting an - asset from an object inventory - The owner of this asset - - - - - - Used to force asset data into the PendingUpload property, ie: for raw terrain uploads - - An AssetUpload object containing the data to upload to the simulator - - - - Request an asset be uploaded to the simulator - - The Object containing the asset data - If True, the asset once uploaded will be stored on the simulator - in which the client was connected in addition to being stored on the asset server - The of the transfer, can be used to correlate the upload with - events being fired - - - - Request an asset be uploaded to the simulator - - The of the asset being uploaded - A byte array containing the encoded asset data - If True, the asset once uploaded will be stored on the simulator - in which the client was connected in addition to being stored on the asset server - The of the transfer, can be used to correlate the upload with - events being fired - - - - Request an asset be uploaded to the simulator - - - Asset type to upload this data as - A byte array containing the encoded asset data - If True, the asset once uploaded will be stored on the simulator - in which the client was connected in addition to being stored on the asset server - The of the transfer, can be used to correlate the upload with - events being fired - - - - Initiate an asset upload - - The ID this asset will have if the - upload succeeds - Asset type to upload this data as - Raw asset data to upload - Whether to store this asset on the local - simulator or the grid-wide asset server - The tranaction id for the upload - The transaction ID of this transfer - - - - Requests download of a mesh asset - - UUID of the mesh asset - Callback when the request completes - - - - Request a texture asset from the simulator using the system to - manage the requests and re-assemble the image from the packets received from the simulator - - The of the texture asset to download - The of the texture asset. - Use for most textures, or for baked layer texture assets - A float indicating the requested priority for the transfer. Higher priority values tell the simulator - to prioritize the request before lower valued requests. An image already being transferred using the can have - its priority changed by resending the request with the new priority value - Number of quality layers to discard. - This controls the end marker of the data sent. Sending with value -1 combined with priority of 0 cancels an in-progress - transfer. - A bug exists in the Linden Simulator where a -1 will occasionally be sent with a non-zero priority - indicating an off-by-one error. - The packet number to begin the request at. A value of 0 begins the request - from the start of the asset texture - The callback to fire when the image is retrieved. The callback - will contain the result of the request and the texture asset data - If true, the callback will be fired for each chunk of the downloaded image. - The callback asset parameter will contain all previously received chunks of the texture asset starting - from the beginning of the request - - Request an image and fire a callback when the request is complete - - Client.Assets.RequestImage(UUID.Parse("c307629f-e3a1-4487-5e88-0d96ac9d4965"), ImageType.Normal, TextureDownloader_OnDownloadFinished); - - private void TextureDownloader_OnDownloadFinished(TextureRequestState state, AssetTexture asset) - { - if(state == TextureRequestState.Finished) - { - Console.WriteLine("Texture {0} ({1} bytes) has been successfully downloaded", - asset.AssetID, - asset.AssetData.Length); - } - } - - Request an image and use an inline anonymous method to handle the downloaded texture data - - Client.Assets.RequestImage(UUID.Parse("c307629f-e3a1-4487-5e88-0d96ac9d4965"), ImageType.Normal, delegate(TextureRequestState state, AssetTexture asset) - { - if(state == TextureRequestState.Finished) - { - Console.WriteLine("Texture {0} ({1} bytes) has been successfully downloaded", - asset.AssetID, - asset.AssetData.Length); - } - } - ); - - Request a texture, decode the texture to a bitmap image and apply it to a imagebox - - Client.Assets.RequestImage(UUID.Parse("c307629f-e3a1-4487-5e88-0d96ac9d4965"), ImageType.Normal, TextureDownloader_OnDownloadFinished); - - private void TextureDownloader_OnDownloadFinished(TextureRequestState state, AssetTexture asset) - { - if(state == TextureRequestState.Finished) - { - ManagedImage imgData; - Image bitmap; - - if (state == TextureRequestState.Finished) - { - OpenJPEG.DecodeToImage(assetTexture.AssetData, out imgData, out bitmap); - picInsignia.Image = bitmap; - } - } - } - - - - - - Overload: Request a texture asset from the simulator using the system to - manage the requests and re-assemble the image from the packets received from the simulator - - The of the texture asset to download - The callback to fire when the image is retrieved. The callback - will contain the result of the request and the texture asset data - - - - Overload: Request a texture asset from the simulator using the system to - manage the requests and re-assemble the image from the packets received from the simulator - - The of the texture asset to download - The of the texture asset. - Use for most textures, or for baked layer texture assets - The callback to fire when the image is retrieved. The callback - will contain the result of the request and the texture asset data - - - - Overload: Request a texture asset from the simulator using the system to - manage the requests and re-assemble the image from the packets received from the simulator - - The of the texture asset to download - The of the texture asset. - Use for most textures, or for baked layer texture assets - The callback to fire when the image is retrieved. The callback - will contain the result of the request and the texture asset data - If true, the callback will be fired for each chunk of the downloaded image. - The callback asset parameter will contain all previously received chunks of the texture asset starting - from the beginning of the request - - - - Cancel a texture request - - The texture assets - - - - Fetch avatar texture on a grid capable of server side baking - - ID of the avatar - ID of the texture - Name of the part of the avatar texture applies to - Callback invoked on operation completion - - - - Lets TexturePipeline class fire the progress event - - The texture ID currently being downloaded - the number of bytes transferred - the total number of bytes expected - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - - - Xfer data - - - Upload data - - - Filename used on the simulator - - - Filename used by the client - - - UUID of the image that is in progress - - - Number of bytes received so far - - - Image size in bytes - - - - Constants for the archiving module - - - - - The location of the archive control file - - - - - Path for the assets held in an archive - - - - - Path for the prims file - - - - - Path for terrains. Technically these may be assets, but I think it's quite nice to split them out. - - - - - Path for region settings. - - - - - Path for region settings. - - - - - The character the separates the uuid from extension information in an archived asset filename - - - - - Extensions used for asset types in the archive - - - - - Archives assets - - - - - Archive assets - - - - - Archive the assets given to this archiver to the given archive. - - - - - - Write an assets metadata file to the given archive - - - - - - Write asset data files to the given archive - - - - - - Temporary code to do the bare minimum required to read a tar archive for our purposes - - - - - Binary reader for the underlying stream - - - - - Used to trim off null chars - - - - - Used to trim off space chars - - - - - Generate a tar reader which reads from the given stream. - - - - - - Read the next entry in the tar file. - - - - the data for the entry. Returns null if there are no more entries - - - - Read the next 512 byte chunk of data as a tar header. - - A tar header struct. null if we have reached the end of the archive. - - - - Read data following a header - - - - - - - Convert octal bytes to a decimal representation - - - - - - - - - Temporary code to produce a tar archive in tar v7 format - - - - - Binary writer for the underlying stream - - - - - Write a directory entry to the tar archive. We can only handle one path level right now! - - - - - - Write a file to the tar archive - - - - - - - Write a file to the tar archive - - - - - - - Finish writing the raw tar archive data to a stream. The stream will be closed on completion. - - - - - Write a particular entry - - - - - - - - Base class for all Asset types - - - - A byte array containing the raw asset data - - - True if the asset it only stored on the server temporarily - - - A unique ID - - - The assets unique ID - - - - The "type" of asset, Notecard, Animation, etc - - - - - Construct a new Asset object - - - - - Construct a new Asset object - - A unique specific to this asset - A byte array containing the raw asset data - - - - Regenerates the AssetData byte array from the properties - of the derived class. - - - - - Decodes the AssetData, placing it in appropriate properties of the derived - class. - - True if the asset decoding succeeded, otherwise false - - - - Represents an Animation - - - - Override the base classes AssetType - - - Default Constructor - - - - Construct an Asset object of type Animation - - A unique specific to this asset - A byte array containing the raw asset data - - - - Represents an that represents an avatars body ie: Hair, Etc. - - - - Override the base classes AssetType - - - Initializes a new instance of an AssetBodyPart object - - - Initializes a new instance of an AssetBodyPart object with parameters - A unique specific to this asset - A byte array containing the raw asset data - - - - Represents a Callingcard with AvatarID and Position vector - - - - Override the base classes AssetType - - - UUID of the Callingcard target avatar - - - Construct an Asset of type Callingcard - - - - Construct an Asset object of type Callingcard - - A unique specific to this asset - A byte array containing the raw asset data - - - - Constuct an asset of type Callingcard - - UUID of the target avatar - - - - Encode the raw contents of a string with the specific Callingcard format - - - - - Decode the raw asset data, populating the AvatarID and Position - - true if the AssetData was successfully decoded to a UUID and Vector - - - - Represents an that can be worn on an avatar - such as a Shirt, Pants, etc. - - - - Override the base classes AssetType - - - Initializes a new instance of an AssetScriptBinary object - - - Initializes a new instance of an AssetScriptBinary object with parameters - A unique specific to this asset - A byte array containing the raw asset data - - - - Type of gesture step - - - - - Base class for gesture steps - - - - - Retururns what kind of gesture step this is - - - - - Describes animation step of a gesture - - - - - Returns what kind of gesture step this is - - - - - If true, this step represents start of animation, otherwise animation stop - - - - - Animation asset - - - - - Animation inventory name - - - - - Describes sound step of a gesture - - - - - Returns what kind of gesture step this is - - - - - Sound asset - - - - - Sound inventory name - - - - - Describes sound step of a gesture - - - - - Returns what kind of gesture step this is - - - - - Text to output in chat - - - - - Describes sound step of a gesture - - - - - Returns what kind of gesture step this is - - - - - If true in this step we wait for all animations to finish - - - - - If true gesture player should wait for the specified amount of time - - - - - Time in seconds to wait if WaitForAnimation is false - - - - - Describes the final step of a gesture - - - - - Returns what kind of gesture step this is - - - - - Represents a sequence of animations, sounds, and chat actions - - - - - Returns asset type - - - - - Keyboard key that triggers the gestyre - - - - - Modifier to the trigger key - - - - - String that triggers playing of the gesture sequence - - - - - Text that replaces trigger in chat once gesture is triggered - - - - - Sequence of gesture steps - - - - - Constructs guesture asset - - - - - Constructs guesture asset - - A unique specific to this asset - A byte array containing the raw asset data - - - - Encodes gesture asset suitable for uplaod - - - - - Decodes gesture assset into play sequence - - true if the asset data was decoded successfully - - - - Represents a Landmark with RegionID and Position vector - - - - Override the base classes AssetType - - - UUID of the Landmark target region - - - Local position of the target - - - Construct an Asset of type Landmark - - - - Construct an Asset object of type Landmark - - A unique specific to this asset - A byte array containing the raw asset data - - - - Encode the raw contents of a string with the specific Landmark format - - - - - Decode the raw asset data, populating the RegionID and Position - - true if the AssetData was successfully decoded to a UUID and Vector - - - - Represents Mesh asset - - - - Override the base classes AssetType - - - - Decoded mesh data - - - - Initializes a new instance of an AssetMesh object - - - Initializes a new instance of an AssetMesh object with parameters - A unique specific to this asset - A byte array containing the raw asset data - - - - TODO: Encodes Collada file into LLMesh format - - - - - Decodes mesh asset. See - to furter decode it for rendering - true - - - - Represents an Animation - - - - Override the base classes AssetType - - - Default Constructor - - - - Construct an Asset object of type Animation - - Asset type - A unique specific to this asset - A byte array containing the raw asset data - - - - Represents a string of characters encoded with specific formatting properties - - - - Override the base classes AssetType - - - A text string containing main text of the notecard - - - List of s embedded on the notecard - - - Construct an Asset of type Notecard - - - - Construct an Asset object of type Notecard - - A unique specific to this asset - A byte array containing the raw asset data - - - - Encode the raw contents of a string with the specific Linden Text properties - - - - - Decode the raw asset data including the Linden Text properties - - true if the AssetData was successfully decoded - - - - A linkset asset, containing a parent primitive and zero or more children - - - - - Only used internally for XML serialization/deserialization - - - - Override the base classes AssetType - - - Initializes a new instance of an AssetPrim object - - - - Initializes a new instance of an AssetPrim object - - A unique specific to this asset - A byte array containing the raw asset data - - - - - - - - - - - - - - - The deserialized form of a single primitive in a linkset asset - - - - - Represents an AssetScriptBinary object containing the - LSO compiled bytecode of an LSL script - - - - Override the base classes AssetType - - - Initializes a new instance of an AssetScriptBinary object - - - Initializes a new instance of an AssetScriptBinary object with parameters - A unique specific to this asset - A byte array containing the raw asset data - - - - TODO: Encodes a scripts contents into a LSO Bytecode file - - - - - TODO: Decode LSO Bytecode into a string - - true - - - - Represents an LSL Text object containing a string of UTF encoded characters - - - - Override the base classes AssetType - - - A string of characters represting the script contents - - - Initializes a new AssetScriptText object - - - - Initializes a new AssetScriptText object with parameters - - A unique specific to this asset - A byte array containing the raw asset data - - - - Encode a string containing the scripts contents into byte encoded AssetData - - - - - Decode a byte array containing the scripts contents into a string - - true if decoding is successful - - - - Represents a Sound Asset - - - - Override the base classes AssetType - - - Initializes a new instance of an AssetSound object - - - Initializes a new instance of an AssetSound object with parameters - A unique specific to this asset - A byte array containing the raw asset data - - - - Converts a byte data for a wave PCM file @ 44100 to a OGG encoding - - - - - its already ogg just play it or convert it yourself - - true - - - - Represents a texture - - - - Override the base classes AssetType - - - A object containing image data - - - - - - Initializes a new instance of an AssetTexture object - - - - Initializes a new instance of an AssetTexture object - - A unique specific to this asset - A byte array containing the raw asset data - - - - Initializes a new instance of an AssetTexture object - - A object containing texture data - - - - Populates the byte array with a JPEG2000 - encoded image created from the data in - - - - - Decodes the JPEG2000 data in AssetData to the - object - - True if the decoding was successful, otherwise false - - - - Represents a Wearable Asset, Clothing, Hair, Skin, Etc - - - - A string containing the name of the asset - - - A string containing a short description of the asset - - - The Assets WearableType - - - The For-Sale status of the object - - - An Integer representing the purchase price of the asset - - - The of the assets creator - - - The of the assets current owner - - - The of the assets prior owner - - - The of the Group this asset is set to - - - True if the asset is owned by a - - - The Permissions mask of the asset - - - A Dictionary containing Key/Value pairs of the objects parameters - - - A Dictionary containing Key/Value pairs where the Key is the textures Index and the Value is the Textures - - - Initializes a new instance of an AssetWearable object - - - Initializes a new instance of an AssetWearable object with parameters - A unique specific to this asset - A byte array containing the raw asset data - - - - Decode an assets byte encoded data to a string - - true if the asset data was decoded successfully - - - - Encode the assets string represantion into a format consumable by the asset server - - - - - Avatar profile flags - - - - - Represents an avatar (other than your own) - - - - - Positive and negative ratings - - - - Positive ratings for Behavior - - - Negative ratings for Behavior - - - Positive ratings for Appearance - - - Negative ratings for Appearance - - - Positive ratings for Building - - - Negative ratings for Building - - - Positive ratings given by this avatar - - - Negative ratings given by this avatar - - - - Avatar properties including about text, profile URL, image IDs and - publishing settings - - - - First Life about text - - - First Life image ID - - - - - - - - - - - - - - - Profile image ID - - - Flags of the profile - - - Web URL for this profile - - - Should this profile be published on the web - - - Avatar Online Status - - - Is this a mature profile - - - - - - - - - - Avatar interests including spoken languages, skills, and "want to" - choices - - - - Languages profile field - - - - - - - - - - - - - - - Groups that this avatar is a member of - - - Positive and negative ratings - - - Avatar properties including about text, profile URL, image IDs and - publishing settings - - - Avatar interests including spoken languages, skills, and "want to" - choices - - - Movement control flags for avatars. Typically not set or used by - clients. To move your avatar, use Client.Self.Movement instead - - - - Contains the visual parameters describing the deformation of the avatar - - - - - Appearance version. Value greater than 0 indicates using server side baking - - - - - Version of the Current Outfit Folder that the appearance is based on - - - - - Appearance flags. Introduced with server side baking, currently unused. - - - - - List of current avatar animations - - - - First name - - - Last name - - - Full name - - - Active group - - - Information about agents display name - - - Agent UUID - - - Username - - - Display name - - - First name (legacy) - - - Last name (legacy) - - - Full name (legacy) - - - Is display name default display name - - - Cache display name until - - - Last updated timestamp - - - - Creates AgentDisplayName object from OSD - - Incoming OSD data - AgentDisplayName object - - - - Return object as OSD map - - OSD containing agent's display name data - - - - Holds group information for Avatars such as those you might find in a profile - - - - true of Avatar accepts group notices - - - Groups Key - - - Texture Key for groups insignia - - - Name of the group - - - Powers avatar has in the group - - - Avatars Currently selected title - - - true of Avatar has chosen to list this in their profile - - - - Contains an animation currently being played by an agent - - - - The ID of the animation asset - - - A number to indicate start order of currently playing animations - On Linden Grids this number is unique per region, with OpenSim it is per client - - - - - - - Holds group information on an individual profile pick - - - - - Retrieve friend status notifications, and retrieve avatar names and - profiles - - - - The event subscribers, null of no subscribers - - - Raises the AvatarAnimation Event - An AvatarAnimationEventArgs object containing - the data sent from the simulator - - - Thread sync lock object - - - Raised when the simulator sends us data containing - an agents animation playlist - - - The event subscribers, null of no subscribers - - - Raises the AvatarAppearance Event - A AvatarAppearanceEventArgs object containing - the data sent from the simulator - - - Thread sync lock object - - - Raised when the simulator sends us data containing - the appearance information for an agent - - - The event subscribers, null of no subscribers - - - Raises the UUIDNameReply Event - A UUIDNameReplyEventArgs object containing - the data sent from the simulator - - - Thread sync lock object - - - Raised when the simulator sends us data containing - agent names/id values - - - The event subscribers, null of no subscribers - - - Raises the AvatarInterestsReply Event - A AvatarInterestsReplyEventArgs object containing - the data sent from the simulator - - - Thread sync lock object - - - Raised when the simulator sends us data containing - the interests listed in an agents profile - - - The event subscribers, null of no subscribers - - - Raises the AvatarNotesReply Event - A AvatarNotesReplyEventArgs object containing - the data sent from the simulator - - - Thread sync lock object - - - Raised when the simulator sends us data containing - the private notes listed in an agents profile - - - The event subscribers, null of no subscribers - - - Raises the AvatarPropertiesReply Event - A AvatarPropertiesReplyEventArgs object containing - the data sent from the simulator - - - Thread sync lock object - - - Raised when the simulator sends us data containing - profile property information for an agent - - - The event subscribers, null of no subscribers - - - Raises the AvatarGroupsReply Event - A AvatarGroupsReplyEventArgs object containing - the data sent from the simulator - - - Thread sync lock object - - - Raised when the simulator sends us data containing - the group membership an agent is a member of - - - The event subscribers, null of no subscribers - - - Raises the AvatarPickerReply Event - A AvatarPickerReplyEventArgs object containing - the data sent from the simulator - - - Thread sync lock object - - - Raised when the simulator sends us data containing - name/id pair - - - The event subscribers, null of no subscribers - - - Raises the ViewerEffectPointAt Event - A ViewerEffectPointAtEventArgs object containing - the data sent from the simulator - - - Thread sync lock object - - - Raised when the simulator sends us data containing - the objects and effect when an agent is pointing at - - - The event subscribers, null of no subscribers - - - Raises the ViewerEffectLookAt Event - A ViewerEffectLookAtEventArgs object containing - the data sent from the simulator - - - Thread sync lock object - - - Raised when the simulator sends us data containing - the objects and effect when an agent is looking at - - - The event subscribers, null of no subscribers - - - Raises the ViewerEffect Event - A ViewerEffectEventArgs object containing - the data sent from the simulator - - - Thread sync lock object - - - Raised when the simulator sends us data containing - an agents viewer effect information - - - The event subscribers, null of no subscribers - - - Raises the AvatarPicksReply Event - A AvatarPicksReplyEventArgs object containing - the data sent from the simulator - - - Thread sync lock object - - - Raised when the simulator sends us data containing - the top picks from an agents profile - - - The event subscribers, null of no subscribers - - - Raises the PickInfoReply Event - A PickInfoReplyEventArgs object containing - the data sent from the simulator - - - Thread sync lock object - - - Raised when the simulator sends us data containing - the Pick details - - - The event subscribers, null of no subscribers - - - Raises the AvatarClassifiedReply Event - A AvatarClassifiedReplyEventArgs object containing - the data sent from the simulator - - - Thread sync lock object - - - Raised when the simulator sends us data containing - the classified ads an agent has placed - - - The event subscribers, null of no subscribers - - - Raises the ClassifiedInfoReply Event - A ClassifiedInfoReplyEventArgs object containing - the data sent from the simulator - - - Thread sync lock object - - - Raised when the simulator sends us data containing - the details of a classified ad - - - The event subscribers, null of no subscribers - - - Raises the DisplayNameUpdate Event - A DisplayNameUpdateEventArgs object containing - the data sent from the simulator - - - Thread sync lock object - - - Raised when the simulator sends us data containing - the details of display name change - - - - Callback giving results when fetching display names - - If the request was successful - Array of display names - Array of UUIDs that could not be fetched - - - - Represents other avatars - - - - - Tracks the specified avatar on your map - Avatar ID to track - - - - Request a single avatar name - - The avatar key to retrieve a name for - - - - Request a list of avatar names - - The avatar keys to retrieve names for - - - - Check if Display Names functionality is available - - True if Display name functionality is available - - - - Request retrieval of display names (max 90 names per request) - - List of UUIDs to lookup - Callback to report result of the operation - - - - Start a request for Avatar Properties - - - - - - Search for an avatar (first name, last name) - - The name to search for - An ID to associate with this query - - - - Request avatar notes from simulator - - Target agent UUID - - - - Start a request for Avatar Picks - - UUID of the avatar - - - - Start a request for Avatar Classifieds - - UUID of the avatar - - - - Start a request for details of a specific profile pick - - UUID of the avatar - UUID of the profile pick - - - - Start a request for details of a specific profile classified - - UUID of the avatar - UUID of the profile classified - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - - - - EQ Message fired when someone nearby changes their display name - - The message key - the IMessage object containing the deserialized data sent from the simulator - The which originated the packet - - - - Crossed region handler for message that comes across the EventQueue. Sent to an agent - when the agent crosses a sim border into a new region. - - The message key - the IMessage object containing the deserialized data sent from the simulator - The which originated the packet - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - - - Provides data for the event - The event occurs when the simulator sends - the animation playlist for an agent - - The following code example uses the and - properties to display the animation playlist of an avatar on the window. - - // subscribe to the event - Client.Avatars.AvatarAnimation += Avatars_AvatarAnimation; - - private void Avatars_AvatarAnimation(object sender, AvatarAnimationEventArgs e) - { - // create a dictionary of "known" animations from the Animations class using System.Reflection - Dictionary<UUID, string> systemAnimations = new Dictionary<UUID, string>(); - Type type = typeof(Animations); - System.Reflection.FieldInfo[] fields = type.GetFields(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static); - foreach (System.Reflection.FieldInfo field in fields) - { - systemAnimations.Add((UUID)field.GetValue(type), field.Name); - } - - // find out which animations being played are known animations and which are assets - foreach (Animation animation in e.Animations) - { - if (systemAnimations.ContainsKey(animation.AnimationID)) - { - Console.WriteLine("{0} is playing {1} ({2}) sequence {3}", e.AvatarID, - systemAnimations[animation.AnimationID], animation.AnimationSequence); - } - else - { - Console.WriteLine("{0} is playing {1} (Asset) sequence {2}", e.AvatarID, - animation.AnimationID, animation.AnimationSequence); - } - } - } - - - - - Get the ID of the agent - - - Get the list of animations to start - - - - Construct a new instance of the AvatarAnimationEventArgs class - - The ID of the agent - The list of animations to start - - - Provides data for the event - The event occurs when the simulator sends - the appearance data for an avatar - - The following code example uses the and - properties to display the selected shape of an avatar on the window. - - // subscribe to the event - Client.Avatars.AvatarAppearance += Avatars_AvatarAppearance; - - // handle the data when the event is raised - void Avatars_AvatarAppearance(object sender, AvatarAppearanceEventArgs e) - { - Console.WriteLine("The Agent {0} is using a {1} shape.", e.AvatarID, (e.VisualParams[31] > 0) : "male" ? "female") - } - - - - - Get the Simulator this request is from of the agent - - - Get the ID of the agent - - - true if the agent is a trial account - - - Get the default agent texture - - - Get the agents appearance layer textures - - - Get the for the agent - - - Version of the appearance system used. - Value greater than 0 indicates that server side baking is used - - - Version of the Current Outfit Folder the appearance is based on - - - Appearance flags, introduced with server side baking, currently unused - - - - Construct a new instance of the AvatarAppearanceEventArgs class - - The simulator request was from - The ID of the agent - true of the agent is a trial account - The default agent texture - The agents appearance layer textures - The for the agent - Appearance Version - Current outfit folder version - Appearance Flags - - - Represents the interests from the profile of an agent - - - Get the ID of the agent - - - Get the interests of the agent - - - Represents the private notes from the profile of an agent - - - Get the ID of the agent - - - Get the interests of the agent - - - The properties of an agent - - - Get the ID of the agent - - - Get the ID of the agent - - - Get the ID of the agent - - - Get the ID of the avatar - - - - Event args class for display name notification messages - - - - - Wrapper around a byte array that allows bit to be packed and unpacked - one at a time or by a variable amount. Useful for very tightly packed - data like LayerData packets - - - - - - - - - - - - - - Default constructor, initialize the bit packer / bit unpacker - with a byte array and starting position - - Byte array to pack bits in to or unpack from - Starting position in the byte array - - - - Pack a floating point value in to the data - - Floating point value to pack - - - - Pack part or all of an integer in to the data - - Integer containing the data to pack - Number of bits of the integer to pack - - - - Pack part or all of an unsigned integer in to the data - - Unsigned integer containing the data to pack - Number of bits of the integer to pack - - - - Pack a single bit in to the data - - Bit to pack - - - - - - - - - - - - - - - - - - - - - - - - - Unpacking a floating point value from the data - - Unpacked floating point value - - - - Unpack a variable number of bits from the data in to integer format - - Number of bits to unpack - An integer containing the unpacked bits - This function is only useful up to 32 bits - - - - Unpack a variable number of bits from the data in to unsigned - integer format - - Number of bits to unpack - An unsigned integer containing the unpacked bits - This function is only useful up to 32 bits - - - - Unpack a 16-bit signed integer - - 16-bit signed integer - - - - Unpack a 16-bit unsigned integer - - 16-bit unsigned integer - - - - Unpack a 32-bit signed integer - - 32-bit signed integer - - - - Unpack a 32-bit unsigned integer - - 32-bit unsigned integer - - - - Reads in a byte array of an Animation Asset created by the SecondLife(tm) client. - - - - - Rotation Keyframe count (used internally) - - - - - Position Keyframe count (used internally) - - - - - Animation Priority - - - - - The animation length in seconds. - - - - - Expression set in the client. Null if [None] is selected - - - - - The time in seconds to start the animation - - - - - The time in seconds to end the animation - - - - - Loop the animation - - - - - Meta data. Ease in Seconds. - - - - - Meta data. Ease out seconds. - - - - - Meta Data for the Hand Pose - - - - - Number of joints defined in the animation - - - - - Contains an array of joints - - - - - Searialize an animation asset into it's joints/keyframes/meta data - - - - - - Variable length strings seem to be null terminated in the animation asset.. but.. - use with caution, home grown. - advances the index. - - The animation asset byte array - The offset to start reading - a string - - - - Read in a Joint from an animation asset byte array - Variable length Joint fields, yay! - Advances the index - - animation asset byte array - Byte Offset of the start of the joint - The Joint data serialized into the binBVHJoint structure - - - - Read Keyframes of a certain type - advance i - - Animation Byte array - Offset in the Byte Array. Will be advanced - Number of Keyframes - Scaling Min to pass to the Uint16ToFloat method - Scaling Max to pass to the Uint16ToFloat method - - - - - Determines whether the specified is equal to the current . - - - true if the specified is equal to the current ; otherwise, false. - - The to compare with the current . - The parameter is null. - 2 - - - - Serves as a hash function for a particular type. - - - A hash code for the current . - - 2 - - - - A Joint and it's associated meta data and keyframes - - - - - Indicates whether this instance and a specified object are equal. - - - true if and this instance are the same type and represent the same value; otherwise, false. - - Another object to compare to. - 2 - - - - Returns the hash code for this instance. - - - A 32-bit signed integer that is the hash code for this instance. - - 2 - - - - Name of the Joint. Matches the avatar_skeleton.xml in client distros - - - - - Joint Animation Override? Was the same as the Priority in testing.. - - - - - Array of Rotation Keyframes in order from earliest to latest - - - - - Array of Position Keyframes in order from earliest to latest - This seems to only be for the Pelvis? - - - - - Custom application data that can be attached to a joint - - - - - A Joint Keyframe. This is either a position or a rotation. - - - - - Either a Vector3 position or a Vector3 Euler rotation - - - - - Poses set in the animation metadata for the hands. - - - - - CapsClient Ctor - - for simulator capability - - - - CapsClient Ctor with name - - for simulator capability - Simulator capability name - - - - CapsClient Ctor with name and certificate - - for simulator capability - Simulator capability name - client certificate - - - - Serializes OSD data for http request - - formatted data for input - Format to serialize data to - Output serialized data as byte array - content-type string of serialized data - - - Viewer defauls to 30 for main grid, 60 for others - - - For exponential backoff on error. - - - Number of times we've received an unknown CAPS exception in series. - - - - Capabilities is the name of the bi-directional HTTP REST protocol - used to communicate non real-time transactions such as teleporting or - group messaging - - - - - Triggered when an event is received via the EventQueueGet - capability - - Event name - Decoded event data - The simulator that generated the event - - - Reference to the simulator this system is connected to - - - Capabilities URI this system was initialized with - - - Whether the capabilities event queue is connected and - listening for incoming events - - - - Default constructor - - - - - - - Request the URI of a named capability - - Name of the capability to request - The URI of the requested capability, or null if not found - - - - Create a new CapsClient for specified capability - - Capability name - Newly created CapsClient or null of capability does not exist - - - - Useful for debugging, but not particularly a good idea - - Capability address - Name of capability if it exists - - - - Request preferred URI for texture fetch capability - - URI of preferred capability or null, or null if not found - - - - Request preferred URI for object mesh fetch capability - - URI of preferred capability or null, or null if not found - - - - Process any incoming events, check to see if we have a message created for the event, - - - - - - Raised whenever the capabilities have been received from a simulator - - - - Raises the CapabilitiesReceived event - - Simulator we received the capabilities from - - - The simulator that received a capabilities - - - - Attempts to convert an LLSD structure to a known Packet type - - Event name, this must match an actual - packet name for a Packet to be successfully built - LLSD to convert to a Packet - A Packet on success, otherwise null - - - - Creates a formatted string containing the values of a Packet - - The Packet - A formatted string of values of the nested items in the Packet object - - - - Decode an IMessage object into a beautifully formatted string - - The IMessage object - Recursion level (used for indenting) - A formatted string containing the names and values of the source object - - - - Thrown when a packet could not be successfully deserialized - - - - - Default constructor - - - - - Constructor that takes an additional error message - - An error message to attach to this exception - - - - The header of a message template packet. Holds packet flags, sequence - number, packet ID, and any ACKs that will be appended at the end of - the packet - - - - - Convert the AckList to a byte array, used for packet serializing - - Reference to the target byte array - Beginning position to start writing to in the byte - array, will be updated with the ending position of the ACK list - - - - - - - - - - - - - - - - - - - - - A block of data in a packet. Packets are composed of one or more blocks, - each block containing one or more fields - - - - Current length of the data in this packet - - - - Create a block from a byte array - - Byte array containing the serialized block - Starting position of the block in the byte array. - This will point to the data after the end of the block when the - call returns - - - - Serialize this block into a byte array - - Byte array to serialize this block into - Starting position in the byte array to serialize to. - This will point to the position directly after the end of the - serialized block when the call returns - - - A generic value, not an actual packet type - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Origin position of this coordinate frame - - - X axis of this coordinate frame, or Forward/At in grid terms - - - Y axis of this coordinate frame, or Left in grid terms - - - Z axis of this coordinate frame, or Up in grid terms - - - - - - Looking direction, must be a normalized vector - Up direction, must be a normalized vector - - - - Align the coordinate frame X and Y axis with a given rotation - around the Z axis in radians - - Absolute rotation around the Z axis in - radians - - - - Access to the data server which allows searching for land, events, people, etc - - - - Classified Ad categories - - - Classified is listed in the Any category - - - Classified is shopping related - - - Classified is - - - - - - - - - - - - - - - - - - - - - - - - Event Categories - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Query Flags used in many of the DirectoryManager methods to specify which query to execute and how to return the results. - - Flags can be combined using the | (pipe) character, not all flags are available in all queries - - - - Query the People database - - - - - - - - - Query the Groups database - - - Query the Events database - - - Query the land holdings database for land owned by the currently connected agent - - - - - - Query the land holdings database for land which is owned by a Group - - - Specifies the query should pre sort the results based upon traffic - when searching the Places database - - - - - - - - - - - - - - - Specifies the query should pre sort the results in an ascending order when searching the land sales database. - This flag is only used when searching the land sales database - - - Specifies the query should pre sort the results using the SalePrice field when searching the land sales database. - This flag is only used when searching the land sales database - - - Specifies the query should pre sort the results by calculating the average price/sq.m (SalePrice / Area) when searching the land sales database. - This flag is only used when searching the land sales database - - - Specifies the query should pre sort the results using the ParcelSize field when searching the land sales database. - This flag is only used when searching the land sales database - - - Specifies the query should pre sort the results using the Name field when searching the land sales database. - This flag is only used when searching the land sales database - - - When set, only parcels less than the specified Price will be included when searching the land sales database. - This flag is only used when searching the land sales database - - - When set, only parcels greater than the specified Size will be included when searching the land sales database. - This flag is only used when searching the land sales database - - - - - - - - - Include PG land in results. This flag is used when searching both the Groups, Events and Land sales databases - - - Include Mature land in results. This flag is used when searching both the Groups, Events and Land sales databases - - - Include Adult land in results. This flag is used when searching both the Groups, Events and Land sales databases - - - - - - - Land types to search dataserver for - - - - Search Auction, Mainland and Estate - - - Land which is currently up for auction - - - Parcels which are on the mainland (Linden owned) continents - - - Parcels which are on privately owned simulators - - - - The content rating of the event - - - - Event is PG - - - Event is Mature - - - Event is Adult - - - - Classified Ad Options - - There appear to be two formats the flags are packed in. - This set of flags is for the newer style - - - - - - - - - - - - - - - - - - - Classified ad query options - - - - Include all ads in results - - - Include PG ads in results - - - Include Mature ads in results - - - Include Adult ads in results - - - - The For Sale flag in PlacesReplyData - - - - Parcel is not listed for sale - - - Parcel is For Sale - - - - A classified ad on the grid - - - - UUID for this ad, useful for looking up detailed - information about it - - - The title of this classified ad - - - Flags that show certain options applied to the classified - - - Creation date of the ad - - - Expiration date of the ad - - - Price that was paid for this ad - - - Print the struct data as a string - A string containing the field name, and field value - - - - A parcel retrieved from the dataserver such as results from the - "For-Sale" listings or "Places" Search - - - - The unique dataserver parcel ID - This id is used to obtain additional information from the entry - by using the method - - - A string containing the name of the parcel - - - The size of the parcel - This field is not returned for Places searches - - - The price of the parcel - This field is not returned for Places searches - - - If True, this parcel is flagged to be auctioned - - - If true, this parcel is currently set for sale - - - Parcel traffic - - - Print the struct data as a string - A string containing the field name, and field value - - - - An Avatar returned from the dataserver - - - - Online status of agent - This field appears to be obsolete and always returns false - - - The agents first name - - - The agents last name - - - The agents - - - Print the struct data as a string - A string containing the field name, and field value - - - - Response to a "Groups" Search - - - - The Group ID - - - The name of the group - - - The current number of members - - - Print the struct data as a string - A string containing the field name, and field value - - - - Parcel information returned from a request - - Represents one of the following: - A parcel of land on the grid that has its Show In Search flag set - A parcel of land owned by the agent making the request - A parcel of land owned by a group the agent making the request is a member of - - - In a request for Group Land, the First record will contain an empty record - - Note: This is not the same as searching the land for sale data source - - - - The ID of the Agent of Group that owns the parcel - - - The name - - - The description - - - The Size of the parcel - - - The billable Size of the parcel, for mainland - parcels this will match the ActualArea field. For Group owned land this will be 10 percent smaller - than the ActualArea. For Estate land this will always be 0 - - - Indicates the ForSale status of the parcel - - - The Gridwide X position - - - The Gridwide Y position - - - The Z position of the parcel, or 0 if no landing point set - - - The name of the Region the parcel is located in - - - The Asset ID of the parcels Snapshot texture - - - The calculated visitor traffic - - - The billing product SKU - Known values are: - - 023Mainland / Full Region - 024Estate / Full Region - 027Estate / Openspace - 029Estate / Homestead - 129Mainland / Homestead (Linden Owned) - - - - - No longer used, will always be 0 - - - Get a SL URL for the parcel - A string, containing a standard SLURL - - - Print the struct data as a string - A string containing the field name, and field value - - - - An "Event" Listing summary - - - - The ID of the event creator - - - The name of the event - - - The events ID - - - A string containing the short date/time the event will begin - - - The event start time in Unixtime (seconds since epoch) - - - The events maturity rating - - - Print the struct data as a string - A string containing the field name, and field value - - - - The details of an "Event" - - - - The events ID - - - The ID of the event creator - - - The name of the event - - - The category - - - The events description - - - The short date/time the event will begin - - - The event start time in Unixtime (seconds since epoch) UTC adjusted - - - The length of the event in minutes - - - 0 if no cover charge applies - - - The cover charge amount in L$ if applicable - - - The name of the region where the event is being held - - - The gridwide location of the event - - - The maturity rating - - - Get a SL URL for the parcel where the event is hosted - A string, containing a standard SLURL - - - Print the struct data as a string - A string containing the field name, and field value - - - The event subscribers. null if no subcribers - - - Raises the EventInfoReply event - An EventInfoReplyEventArgs object containing the - data returned from the data server - - - Thread sync lock object - - - Raised when the data server responds to a request. - - - The event subscribers. null if no subcribers - - - Raises the DirEventsReply event - An DirEventsReplyEventArgs object containing the - data returned from the data server - - - Thread sync lock object - - - Raised when the data server responds to a request. - - - The event subscribers. null if no subcribers - - - Raises the PlacesReply event - A PlacesReplyEventArgs object containing the - data returned from the data server - - - Thread sync lock object - - - Raised when the data server responds to a request. - - - The event subscribers. null if no subcribers - - - Raises the DirPlacesReply event - A DirPlacesReplyEventArgs object containing the - data returned from the data server - - - Thread sync lock object - - - Raised when the data server responds to a request. - - - The event subscribers. null if no subcribers - - - Raises the DirClassifiedsReply event - A DirClassifiedsReplyEventArgs object containing the - data returned from the data server - - - Thread sync lock object - - - Raised when the data server responds to a request. - - - The event subscribers. null if no subcribers - - - Raises the DirGroupsReply event - A DirGroupsReplyEventArgs object containing the - data returned from the data server - - - Thread sync lock object - - - Raised when the data server responds to a request. - - - The event subscribers. null if no subcribers - - - Raises the DirPeopleReply event - A DirPeopleReplyEventArgs object containing the - data returned from the data server - - - Thread sync lock object - - - Raised when the data server responds to a request. - - - The event subscribers. null if no subcribers - - - Raises the DirLandReply event - A DirLandReplyEventArgs object containing the - data returned from the data server - - - Thread sync lock object - - - Raised when the data server responds to a request. - - - - Constructs a new instance of the DirectoryManager class - - An instance of GridClient - - - - Query the data server for a list of classified ads containing the specified string. - Defaults to searching for classified placed in any category, and includes PG, Adult and Mature - results. - - Responses are sent 16 per response packet, there is no way to know how many results a query reply will contain however assuming - the reply packets arrived ordered, a response with less than 16 entries would indicate all results have been received - - The event is raised when a response is received from the simulator - - A string containing a list of keywords to search for - A UUID to correlate the results when the event is raised - - - - Query the data server for a list of classified ads which contain specified keywords (Overload) - - The event is raised when a response is received from the simulator - - A string containing a list of keywords to search for - The category to search - A set of flags which can be ORed to modify query options - such as classified maturity rating. - A UUID to correlate the results when the event is raised - - Search classified ads containing the key words "foo" and "bar" in the "Any" category that are either PG or Mature - - UUID searchID = StartClassifiedSearch("foo bar", ClassifiedCategories.Any, ClassifiedQueryFlags.PG | ClassifiedQueryFlags.Mature); - - - - Responses are sent 16 at a time, there is no way to know how many results a query reply will contain however assuming - the reply packets arrived ordered, a response with less than 16 entries would indicate all results have been received - - - - - Starts search for places (Overloaded) - - The event is raised when a response is received from the simulator - - Search text - Each request is limited to 100 places - being returned. To get the first 100 result entries of a request use 0, - from 100-199 use 1, 200-299 use 2, etc. - A UUID to correlate the results when the event is raised - - - - Queries the dataserver for parcels of land which are flagged to be shown in search - - The event is raised when a response is received from the simulator - - A string containing a list of keywords to search for separated by a space character - A set of flags which can be ORed to modify query options - such as classified maturity rating. - The category to search - Each request is limited to 100 places - being returned. To get the first 100 result entries of a request use 0, - from 100-199 use 1, 200-299 use 2, etc. - A UUID to correlate the results when the event is raised - - Search places containing the key words "foo" and "bar" in the "Any" category that are either PG or Adult - - UUID searchID = StartDirPlacesSearch("foo bar", DirFindFlags.DwellSort | DirFindFlags.IncludePG | DirFindFlags.IncludeAdult, ParcelCategory.Any, 0); - - - - Additional information on the results can be obtained by using the ParcelManager.InfoRequest method - - - - - Starts a search for land sales using the directory - - The event is raised when a response is received from the simulator - - What type of land to search for. Auction, - estate, mainland, "first land", etc - The OnDirLandReply event handler must be registered before - calling this function. There is no way to determine how many - results will be returned, or how many times the callback will be - fired other than you won't get more than 100 total parcels from - each query. - - - - Starts a search for land sales using the directory - - The event is raised when a response is received from the simulator - - What type of land to search for. Auction, - estate, mainland, "first land", etc - Maximum price to search for - Maximum area to search for - Each request is limited to 100 parcels - being returned. To get the first 100 parcels of a request use 0, - from 100-199 use 1, 200-299 use 2, etc. - The OnDirLandReply event handler must be registered before - calling this function. There is no way to determine how many - results will be returned, or how many times the callback will be - fired other than you won't get more than 100 total parcels from - each query. - - - - Send a request to the data server for land sales listings - - - Flags sent to specify query options - - Available flags: - Specify the parcel rating with one or more of the following: - IncludePG IncludeMature IncludeAdult - - Specify the field to pre sort the results with ONLY ONE of the following: - PerMeterSort NameSort AreaSort PricesSort - - Specify the order the results are returned in, if not specified the results are pre sorted in a Descending Order - SortAsc - - Specify additional filters to limit the results with one or both of the following: - LimitByPrice LimitByArea - - Flags can be combined by separating them with the | (pipe) character - - Additional details can be found in - - What type of land to search for. Auction, - Estate or Mainland - Maximum price to search for when the - DirFindFlags.LimitByPrice flag is specified in findFlags - Maximum area to search for when the - DirFindFlags.LimitByArea flag is specified in findFlags - Each request is limited to 100 parcels - being returned. To get the first 100 parcels of a request use 0, - from 100-199 use 100, 200-299 use 200, etc. - The event will be raised with the response from the simulator - - There is no way to determine how many results will be returned, or how many times the callback will be - fired other than you won't get more than 100 total parcels from - each reply. - - Any land set for sale to either anybody or specific to the connected agent will be included in the - results if the land is included in the query - - - // request all mainland, any maturity rating that is larger than 512 sq.m - StartLandSearch(DirFindFlags.SortAsc | DirFindFlags.PerMeterSort | DirFindFlags.LimitByArea | DirFindFlags.IncludePG | DirFindFlags.IncludeMature | DirFindFlags.IncludeAdult, SearchTypeFlags.Mainland, 0, 512, 0); - - - - - Search for Groups - - The name or portion of the name of the group you wish to search for - Start from the match number - - - - - Search for Groups - - The name or portion of the name of the group you wish to search for - Start from the match number - Search flags - - - - - Search the People directory for other avatars - - The name or portion of the name of the avatar you wish to search for - - - - - - Search Places for parcels of land you personally own - - - - - Searches Places for land owned by the specified group - - ID of the group you want to recieve land list for (You must be a member of the group) - Transaction (Query) ID which can be associated with results from your request. - - - - Search the Places directory for parcels that are listed in search and contain the specified keywords - - A string containing the keywords to search for - Transaction (Query) ID which can be associated with results from your request. - - - - Search Places - All Options - - One of the Values from the DirFindFlags struct, ie: AgentOwned, GroupOwned, etc. - One of the values from the SearchCategory Struct, ie: Any, Linden, Newcomer - A string containing a list of keywords to search for separated by a space character - String Simulator Name to search in - LLUID of group you want to recieve results for - Transaction (Query) ID which can be associated with results from your request. - Transaction (Query) ID which can be associated with results from your request. - - - - Search All Events with specifid searchText in all categories, includes PG, Mature and Adult - - A string containing a list of keywords to search for separated by a space character - Each request is limited to 100 entries - being returned. To get the first group of entries of a request use 0, - from 100-199 use 100, 200-299 use 200, etc. - UUID of query to correlate results in callback. - - - - Search Events - - A string containing a list of keywords to search for separated by a space character - One or more of the following flags: DateEvents, IncludePG, IncludeMature, IncludeAdult - from the Enum - - Multiple flags can be combined by separating the flags with the | (pipe) character - "u" for in-progress and upcoming events, -or- number of days since/until event is scheduled - For example "0" = Today, "1" = tomorrow, "2" = following day, "-1" = yesterday, etc. - Each request is limited to 100 entries - being returned. To get the first group of entries of a request use 0, - from 100-199 use 100, 200-299 use 200, etc. - EventCategory event is listed under. - UUID of query to correlate results in callback. - - - Requests Event Details - ID of Event returned from the method - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - - - Process an incoming event message - The Unique Capabilities Key - The event message containing the data - The simulator the message originated from - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - - - Process an incoming event message - The Unique Capabilities Key - The event message containing the data - The simulator the message originated from - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - - - Contains the Event data returned from the data server from an EventInfoRequest - - - - A single EventInfo object containing the details of an event - - - - Construct a new instance of the EventInfoReplyEventArgs class - A single EventInfo object containing the details of an event - - - Contains the "Event" detail data returned from the data server - - - The ID returned by - - - A list of "Events" returned by the data server - - - Construct a new instance of the DirEventsReplyEventArgs class - The ID of the query returned by the data server. - This will correlate to the ID returned by the method - A list containing the "Events" returned by the search query - - - Contains the "Event" list data returned from the data server - - - The ID returned by - - - A list of "Places" returned by the data server - - - Construct a new instance of PlacesReplyEventArgs class - The ID of the query returned by the data server. - This will correlate to the ID returned by the method - A list containing the "Places" returned by the data server query - - - Contains the places data returned from the data server - - - The ID returned by - - - A list containing Places data returned by the data server - - - Construct a new instance of the DirPlacesReplyEventArgs class - The ID of the query returned by the data server. - This will correlate to the ID returned by the method - A list containing land data returned by the data server - - - Contains the classified data returned from the data server - - - A list containing Classified Ads returned by the data server - - - Construct a new instance of the DirClassifiedsReplyEventArgs class - A list of classified ad data returned from the data server - - - Contains the group data returned from the data server - - - The ID returned by - - - A list containing Groups data returned by the data server - - - Construct a new instance of the DirGroupsReplyEventArgs class - The ID of the query returned by the data server. - This will correlate to the ID returned by the method - A list of groups data returned by the data server - - - Contains the people data returned from the data server - - - The ID returned by - - - A list containing People data returned by the data server - - - Construct a new instance of the DirPeopleReplyEventArgs class - The ID of the query returned by the data server. - This will correlate to the ID returned by the method - A list of people data returned by the data server - - - Contains the land sales data returned from the data server - - - A list containing land forsale data returned by the data server - - - Construct a new instance of the DirLandReplyEventArgs class - A list of parcels for sale returned by the data server - - - - Represents individual HTTP Download request - - - - URI of the item to fetch - - - Timout specified in milliseconds - - - Download progress callback - - - Download completed callback - - - Accept the following content type - - - How many times will this request be retried - - - Current fetch attempt - - - Default constructor - - - Constructor - - - - Manages async HTTP downloads with a limit on maximum - concurrent downloads - - - - Maximum number of parallel downloads from a single endpoint - - - Client certificate - - - Default constructor - - - Cleanup method - - - Setup http download request - - - Check the queue for pending work - - - Enqueue a new HTTP download - - - Describes tasks returned in LandStatReply - - - - Estate level administration and utilities - - - - Textures for each of the four terrain height levels - - - Upper/lower texture boundaries for each corner of the sim - - - - Constructor for EstateTools class - - - - - Used in the ReportType field of a LandStatRequest - - - Used by EstateOwnerMessage packets - - - Used by EstateOwnerMessage packets - - - - - - - - No flags set - - - Only return targets scripted objects - - - Only return targets objects if on others land - - - Returns target's scripted objects and objects on other parcels - - - Ground texture settings for each corner of the region - - - Used by GroundTextureHeightSettings - - - The high and low texture thresholds for each corner of the sim - - - The event subscribers. null if no subcribers - - - Raises the TopCollidersReply event - A TopCollidersReplyEventArgs object containing the - data returned from the data server - - - Thread sync lock object - - - Raised when the data server responds to a request. - - - The event subscribers. null if no subcribers - - - Raises the TopScriptsReply event - A TopScriptsReplyEventArgs object containing the - data returned from the data server - - - Thread sync lock object - - - Raised when the data server responds to a request. - - - The event subscribers. null if no subcribers - - - Raises the EstateUsersReply event - A EstateUsersReplyEventArgs object containing the - data returned from the data server - - - Thread sync lock object - - - Raised when the data server responds to a request. - - - The event subscribers. null if no subcribers - - - Raises the EstateGroupsReply event - A EstateGroupsReplyEventArgs object containing the - data returned from the data server - - - Thread sync lock object - - - Raised when the data server responds to a request. - - - The event subscribers. null if no subcribers - - - Raises the EstateManagersReply event - A EstateManagersReplyEventArgs object containing the - data returned from the data server - - - Thread sync lock object - - - Raised when the data server responds to a request. - - - The event subscribers. null if no subcribers - - - Raises the EstateBansReply event - A EstateBansReplyEventArgs object containing the - data returned from the data server - - - Thread sync lock object - - - Raised when the data server responds to a request. - - - The event subscribers. null if no subcribers - - - Raises the EstateCovenantReply event - A EstateCovenantReplyEventArgs object containing the - data returned from the data server - - - Thread sync lock object - - - Raised when the data server responds to a request. - - - The event subscribers. null if no subcribers - - - Raises the EstateUpdateInfoReply event - A EstateUpdateInfoReplyEventArgs object containing the - data returned from the data server - - - Thread sync lock object - - - Raised when the data server responds to a request. - - - - Requests estate information such as top scripts and colliders - - - - - - - - Requests estate settings, including estate manager and access/ban lists - - - Requests the "Top Scripts" list for the current region - - - Requests the "Top Colliders" list for the current region - - - - Set several estate specific configuration variables - - The Height of the waterlevel over the entire estate. Defaults to 20 - The maximum height change allowed above the baked terrain. Defaults to 4 - The minimum height change allowed below the baked terrain. Defaults to -4 - true to use - if True forces the sun position to the position in SunPosition - The current position of the sun on the estate, or when FixedSun is true the static position - the sun will remain. 6.0 = Sunrise, 30.0 = Sunset - - - - Request return of objects owned by specified avatar - - The Agents owning the primitives to return - specify the coverage and type of objects to be included in the return - true to perform return on entire estate - - - - - - - - - Used for setting and retrieving various estate panel settings - - EstateOwnerMessage Method field - List of parameters to include - - - - Kick an avatar from an estate - - Key of Agent to remove - - - - Ban an avatar from an estate - Key of Agent to remove - Ban user from this estate and all others owned by the estate owner - - - Unban an avatar from an estate - Key of Agent to remove - /// Unban user from this estate and all others owned by the estate owner - - - - Send a message dialog to everyone in an entire estate - - Message to send all users in the estate - - - - Send a message dialog to everyone in a simulator - - Message to send all users in the simulator - - - - Send an avatar back to their home location - - Key of avatar to send home - - - - Begin the region restart process - - - - - Cancels a region restart - - - - Estate panel "Region" tab settings - - - Estate panel "Debug" tab settings - - - Used for setting the region's terrain textures for its four height levels - - - - - - - Used for setting sim terrain texture heights - - - Requests the estate covenant - - - - Upload a terrain RAW file - - A byte array containing the encoded terrain data - The name of the file being uploaded - The Id of the transfer request - - - - Teleports all users home in current Estate - - - - - Remove estate manager - Key of Agent to Remove - removes manager to this estate and all others owned by the estate owner - - - - Add estate manager - Key of Agent to Add - Add agent as manager to this estate and all others owned by the estate owner - - - - Add's an agent to the estate Allowed list - Key of Agent to Add - Add agent as an allowed reisdent to All estates if true - - - - Removes an agent from the estate Allowed list - Key of Agent to Remove - Removes agent as an allowed reisdent from All estates if true - - - - - Add's a group to the estate Allowed list - Key of Group to Add - Add Group as an allowed group to All estates if true - - - - - Removes a group from the estate Allowed list - Key of Group to Remove - Removes Group as an allowed Group from All estates if true - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - - - Raised on LandStatReply when the report type is for "top colliders" - - - - The number of returned items in LandStatReply - - - - - A Dictionary of Object UUIDs to tasks returned in LandStatReply - - - - Construct a new instance of the TopCollidersReplyEventArgs class - The number of returned items in LandStatReply - Dictionary of Object UUIDs to tasks returned in LandStatReply - - - Raised on LandStatReply when the report type is for "top Scripts" - - - - The number of scripts returned in LandStatReply - - - - - A Dictionary of Object UUIDs to tasks returned in LandStatReply - - - - Construct a new instance of the TopScriptsReplyEventArgs class - The number of returned items in LandStatReply - Dictionary of Object UUIDs to tasks returned in LandStatReply - - - Returned, along with other info, upon a successful .RequestInfo() - - - - The identifier of the estate - - - - - The number of returned itmes - - - - - List of UUIDs of Banned Users - - - - Construct a new instance of the EstateBansReplyEventArgs class - The estate's identifier on the grid - The number of returned items in LandStatReply - User UUIDs banned - - - Returned, along with other info, upon a successful .RequestInfo() - - - - The identifier of the estate - - - - - The number of returned items - - - - - List of UUIDs of Allowed Users - - - - Construct a new instance of the EstateUsersReplyEventArgs class - The estate's identifier on the grid - The number of users - Allowed users UUIDs - - - Returned, along with other info, upon a successful .RequestInfo() - - - - The identifier of the estate - - - - - The number of returned items - - - - - List of UUIDs of Allowed Groups - - - - Construct a new instance of the EstateGroupsReplyEventArgs class - The estate's identifier on the grid - The number of Groups - Allowed Groups UUIDs - - - Returned, along with other info, upon a successful .RequestInfo() - - - - The identifier of the estate - - - - - The number of returned items - - - - - List of UUIDs of the Estate's Managers - - - - Construct a new instance of the EstateManagersReplyEventArgs class - The estate's identifier on the grid - The number of Managers - Managers UUIDs - - - Returned, along with other info, upon a successful .RequestInfo() - - - - The Covenant - - - - - The timestamp - - - - - The Estate name - - - - - The Estate Owner's ID (can be a GroupID) - - - - Construct a new instance of the EstateCovenantReplyEventArgs class - The Covenant ID - The timestamp - The estate's name - The Estate Owner's ID (can be a GroupID) - - - Returned, along with other info, upon a successful .RequestInfo() - - - - The estate's name - - - - - The Estate Owner's ID (can be a GroupID) - - - - - The identifier of the estate on the grid - - - - - - - Construct a new instance of the EstateUpdateInfoReplyEventArgs class - The estate's name - The Estate Owners ID (can be a GroupID) - The estate's identifier on the grid - - - - - Registers, unregisters, and fires events generated by incoming packets - - - - - Object that is passed to worker threads in the ThreadPool for - firing packet callbacks - - - - Callback to fire for this packet - - - Reference to the simulator that this packet came from - - - The packet that needs to be processed - - - Reference to the GridClient object - - - - Default constructor - - - - - - Register an event handler - - Use PacketType.Default to fire this event on every - incoming packet - Packet type to register the handler for - Callback to be fired - True if this callback should be ran - asynchronously, false to run it synchronous - - - - Unregister an event handler - - Packet type to unregister the handler for - Callback to be unregistered - - - - Fire the events registered for this packet type - - Incoming packet type - Incoming packet - Simulator this packet was received from - - - - Registers, unregisters, and fires events generated by the Capabilities - event queue - - - - Reference to the GridClient object - - - - Default constructor - - Reference to the GridClient object - - - - Register an new event handler for a capabilities event sent via the EventQueue - - Use String.Empty to fire this event on every CAPS event - Capability event name to register the - handler for - Callback to fire - - - - Unregister a previously registered capabilities handler - - Capability event name unregister the - handler for - Callback to unregister - - - - Fire the events registered for this event type synchronously - - Capability name - Decoded event body - Reference to the simulator that - generated this event - - - - Fire the events registered for this event type asynchronously - - Capability name - Decoded event body - Reference to the simulator that - generated this event - - - - - - - - The avatar has no rights - - - The avatar can see the online status of the target avatar - - - The avatar can see the location of the target avatar on the map - - - The avatar can modify the ojects of the target avatar - - - - This class holds information about an avatar in the friends list. There are two ways - to interface to this class. The first is through the set of boolean properties. This is the typical - way clients of this class will use it. The second interface is through two bitflag properties, - TheirFriendsRights and MyFriendsRights - - - - - System ID of the avatar - - - - - full name of the avatar - - - - - True if the avatar is online - - - - - True if the friend can see if I am online - - - - - True if the friend can see me on the map - - - - - True if the freind can modify my objects - - - - - True if I can see if my friend is online - - - - - True if I can see if my friend is on the map - - - - - True if I can modify my friend's objects - - - - - My friend's rights represented as bitmapped flags - - - - - My rights represented as bitmapped flags - - - - - Used internally when building the initial list of friends at login time - - System ID of the avatar being prepesented - Rights the friend has to see you online and to modify your objects - Rights you have to see your friend online and to modify their objects - - - - FriendInfo represented as a string - - A string reprentation of both my rights and my friends rights - - - - This class is used to add and remove avatars from your friends list and to manage their permission. - - - - Thread sync lock object - - - The event subscribers. null if no subcribers - - - Raises the FriendOnline event - A FriendInfoEventArgs object containing the - data returned from the data server - - - Thread sync lock object - - - Raised when the simulator sends notification one of the members in our friends list comes online - - - The event subscribers. null if no subcribers - - - Raises the FriendOffline event - A FriendInfoEventArgs object containing the - data returned from the data server - - - Thread sync lock object - - - Raised when the simulator sends notification one of the members in our friends list goes offline - - - The event subscribers. null if no subcribers - - - Raises the FriendRightsUpdate event - A FriendInfoEventArgs object containing the - data returned from the data server - - - Thread sync lock object - - - Raised when the simulator sends notification one of the members in our friends list grants or revokes permissions - - - The event subscribers. null if no subcribers - - - Raises the FriendNames event - A FriendNamesEventArgs object containing the - data returned from the data server - - - Thread sync lock object - - - Raised when the simulator sends us the names on our friends list - - - The event subscribers. null if no subcribers - - - Raises the FriendshipOffered event - A FriendshipOfferedEventArgs object containing the - data returned from the data server - - - Thread sync lock object - - - Raised when the simulator sends notification another agent is offering us friendship - - - The event subscribers. null if no subcribers - - - Raises the FriendshipResponse event - A FriendshipResponseEventArgs object containing the - data returned from the data server - - - Thread sync lock object - - - Raised when a request we sent to friend another agent is accepted or declined - - - The event subscribers. null if no subcribers - - - Raises the FriendshipTerminated event - A FriendshipTerminatedEventArgs object containing the - data returned from the data server - - - Thread sync lock object - - - Raised when the simulator sends notification one of the members in our friends list has terminated - our friendship - - - The event subscribers. null if no subcribers - - - Raises the FriendFoundReply event - A FriendFoundReplyEventArgs object containing the - data returned from the data server - - - Thread sync lock object - - - Raised when the simulator sends the location of a friend we have - requested map location info for - - - - A dictionary of key/value pairs containing known friends of this avatar. - - The Key is the of the friend, the value is a - object that contains detailed information including permissions you have and have given to the friend - - - - - A Dictionary of key/value pairs containing current pending frienship offers. - - The key is the of the avatar making the request, - the value is the of the request which is used to accept - or decline the friendship offer - - - - - Internal constructor - - A reference to the GridClient Object - - - - Accept a friendship request - - agentID of avatar to form friendship with - imSessionID of the friendship request message - - - - Accept friendship request. Only to be used if request was sent via Offline Msg cap - This can be determined by the presence of a - value in - - agentID of avatar to form friendship with - - - - Decline a friendship request - - of friend - imSessionID of the friendship request message - - - - Decline friendship request. Only to be used if request was sent via Offline Msg cap - This can be determined by the presence of a - value in - - of friend - - - - Overload: Offer friendship to an avatar. - - System ID of the avatar you are offering friendship to - - - - Offer friendship to an avatar. - - System ID of the avatar you are offering friendship to - A message to send with the request - - - - Terminate a friendship with an avatar - - System ID of the avatar you are terminating the friendship with - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - - - - Change the rights of a friend avatar. - - the of the friend - the new rights to give the friend - This method will implicitly set the rights to those passed in the rights parameter. - - - - Use to map a friends location on the grid. - - Friends UUID to find - - - - - Use to track a friends movement on the grid - - Friends Key - - - - Ask for a notification of friend's online status - - Friend's UUID - - - - This handles the asynchronous response of a RequestAvatarNames call. - - - names cooresponding to the the list of IDs sent the the RequestAvatarNames call. - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - - - - Populate FriendList with data from the login reply - - true if login was successful - true if login request is requiring a redirect - A string containing the response to the login request - A string containing the reason for the request - A object containing the decoded - reply from the login server - - - Number of friends we have - - - Get the name of the agent we requested a friendship with - - Construct a new instance of the FriendsReadyEventArgs class - - The total number of people loaded into the friend list. - - - Contains information on a member of our friends list - - - Get the FriendInfo - - - - Construct a new instance of the FriendInfoEventArgs class - - The FriendInfo - - - Contains Friend Names - - - A dictionary where the Key is the ID of the Agent, - and the Value is a string containing their name - - - - Construct a new instance of the FriendNamesEventArgs class - - A dictionary where the Key is the ID of the Agent, - and the Value is a string containing their name - - - Sent when another agent requests a friendship with our agent - - - Get the ID of the agent requesting friendship - - - Get the name of the agent requesting friendship - - - Get the ID of the session, used in accepting or declining the - friendship offer - - - - Construct a new instance of the FriendshipOfferedEventArgs class - - The ID of the agent requesting friendship - The name of the agent requesting friendship - The ID of the session, used in accepting or declining the - friendship offer - - - A response containing the results of our request to form a friendship with another agent - - - Get the ID of the agent we requested a friendship with - - - Get the name of the agent we requested a friendship with - - - true if the agent accepted our friendship offer - - - - Construct a new instance of the FriendShipResponseEventArgs class - - The ID of the agent we requested a friendship with - The name of the agent we requested a friendship with - true if the agent accepted our friendship offer - - - Contains data sent when a friend terminates a friendship with us - - - Get the ID of the agent that terminated the friendship with us - - - Get the name of the agent that terminated the friendship with us - - - - Construct a new instance of the FrindshipTerminatedEventArgs class - - The ID of the friend who terminated the friendship with us - The name of the friend who terminated the friendship with us - - - - Data sent in response to a request which contains the information to allow us to map the friends location - - - - Get the ID of the agent we have received location information for - - - Get the region handle where our mapped friend is located - - - Get the simulator local position where our friend is located - - - - Construct a new instance of the FriendFoundReplyEventArgs class - - The ID of the agent we have requested location information for - The region handle where our friend is located - The simulator local position our friend is located - - - - Main class to expose grid functionality to clients. All of the - classes needed for sending and receiving data are accessible through - this class. - - - - // Example minimum code required to instantiate class and - // connect to a simulator. - using System; - using System.Collections.Generic; - using System.Text; - using OpenMetaverse; - - namespace FirstBot - { - class Bot - { - public static GridClient Client; - static void Main(string[] args) - { - Client = new GridClient(); // instantiates the GridClient class - // to the global Client object - // Login to Simulator - Client.Network.Login("FirstName", "LastName", "Password", "FirstBot", "1.0"); - // Wait for a Keypress - Console.ReadLine(); - // Logout of simulator - Client.Network.Logout(); - } - } - } - - - - - Networking subsystem - - - Settings class including constant values and changeable - parameters for everything - - - Parcel (subdivided simulator lots) subsystem - - - Our own avatars subsystem - - - Other avatars subsystem - - - Estate subsystem - - - Friends list subsystem - - - Grid (aka simulator group) subsystem - - - Object subsystem - - - Group subsystem - - - Asset subsystem - - - Inventory AIS client - - - Appearance subsystem - - - Inventory subsystem - - - Directory searches including classifieds, people, land sales, etc - - - Handles land, wind, and cloud heightmaps - - - Handles sound-related networking - - - Throttling total bandwidth usage, or allocating bandwidth - for specific data stream types - - - - Default constructor - - - - - Return the full name of this instance - - Client avatars full name - - - - Map layer request type - - - - Objects and terrain are shown - - - Only the terrain is shown, no objects - - - Overlay showing land for sale and for auction - - - - Type of grid item, such as telehub, event, populator location, etc. - - - - Telehub - - - PG rated event - - - Mature rated event - - - Popular location - - - Locations of avatar groups in a region - - - Land for sale - - - Classified ad - - - Adult rated event - - - Adult land for sale - - - - Information about a region on the grid map - - - - Sim X position on World Map - - - Sim Y position on World Map - - - Sim Name (NOTE: In lowercase!) - - - - - - Appears to always be zero (None) - - - Sim's defined Water Height - - - - - - UUID of the World Map image - - - Unique identifier for this region, a combination of the X - and Y position - - - - - - - - - - - - - - - - - - - - - - - Visual chunk of the grid map - - - - - Base class for Map Items - - - - The Global X position of the item - - - The Global Y position of the item - - - Get the Local X position of the item - - - Get the Local Y position of the item - - - Get the Handle of the region - - - - Represents an agent or group of agents location - - - - - Represents a Telehub location - - - - - Represents a non-adult parcel of land for sale - - - - - Represents an Adult parcel of land for sale - - - - - Represents a PG Event - - - - - Represents a Mature event - - - - - Represents an Adult event - - - - - Manages grid-wide tasks such as the world map - - - - The event subscribers. null if no subcribers - - - Raises the CoarseLocationUpdate event - A CoarseLocationUpdateEventArgs object containing the - data sent by simulator - - - Thread sync lock object - - - Raised when the simulator sends a - containing the location of agents in the simulator - - - The event subscribers. null if no subcribers - - - Raises the GridRegion event - A GridRegionEventArgs object containing the - data sent by simulator - - - Thread sync lock object - - - Raised when the simulator sends a Region Data in response to - a Map request - - - The event subscribers. null if no subcribers - - - Raises the GridLayer event - A GridLayerEventArgs object containing the - data sent by simulator - - - Thread sync lock object - - - Raised when the simulator sends GridLayer object containing - a map tile coordinates and texture information - - - The event subscribers. null if no subcribers - - - Raises the GridItems event - A GridItemEventArgs object containing the - data sent by simulator - - - Thread sync lock object - - - Raised when the simulator sends GridItems object containing - details on events, land sales at a specific location - - - The event subscribers. null if no subcribers - - - Raises the RegionHandleReply event - A RegionHandleReplyEventArgs object containing the - data sent by simulator - - - Thread sync lock object - - - Raised in response to a Region lookup - - - Unknown - - - Current direction of the sun - - - Current angular velocity of the sun - - - Microseconds since the start of SL 4-hour day - - - A dictionary of all the regions, indexed by region name - - - A dictionary of all the regions, indexed by region handle - - - - Constructor - - Instance of GridClient object to associate with this GridManager instance - - - - - - - - - - Request a map layer - - The name of the region - The type of layer - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Request data for all mainland (Linden managed) simulators - - - - - Request the region handle for the specified region UUID - - UUID of the region to look up - - - - Get grid region information using the region name, this function - will block until it can find the region or gives up - - Name of sim you're looking for - Layer that you are requesting - Will contain a GridRegion for the sim you're - looking for if successful, otherwise an empty structure - True if the GridRegion was successfully fetched, otherwise - false - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - - - - Avatar group management - - - - Key of Group Member - - - Total land contribution - - - Online status information - - - Abilities that the Group Member has - - - Current group title - - - Is a group owner - - - - Role manager for a group - - - - Key of the group - - - Key of Role - - - Name of Role - - - Group Title associated with Role - - - Description of Role - - - Abilities Associated with Role - - - Returns the role's title - The role's title - - - - Class to represent Group Title - - - - Key of the group - - - ID of the role title belongs to - - - Group Title - - - Whether title is Active - - - Returns group title - - - - Represents a group on the grid - - - - Key of Group - - - Key of Group Insignia - - - Key of Group Founder - - - Key of Group Role for Owners - - - Name of Group - - - Text of Group Charter - - - Title of "everyone" role - - - Is the group open for enrolement to everyone - - - Will group show up in search - - - Group powers - - - Accepts notices - - - Allow publish - - - Is the group Mature - - - Cost of group membership - - - Group money - - - Group contribution - - - The total number of current members this group has - - - The number of roles this group has configured - - - Show this group in agent's profile - - - Returns the name of the group - A string containing the name of the group - - - - A group Vote - - - - Key of Avatar who created Vote - - - Text of the Vote proposal - - - Total number of votes - - - - A group proposal - - - - The Text of the proposal - - - The minimum number of members that must vote before proposal passes or failes - - - The required ration of yes/no votes required for vote to pass - The three options are Simple Majority, 2/3 Majority, and Unanimous - TODO: this should be an enum - - - The duration in days votes are accepted - - - - Account summary - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Struct representing a group notice - - - - Subject of notice - - - Notice message - - - Object ID of attachment - - - Notice owner - - - - OSD Serialize object for attaching - - - - - - Struct representing a group notice list entry - - - - Notice ID - - - Creation timestamp of notice - - - Agent name who created notice - - - Notice subject - - - Is there an attachment? - - - Attachment Type - - - - Struct representing a member of a group chat session and their settings - - - - The of the Avatar - - - True if user has voice chat enabled - - - True of Avatar has moderator abilities - - - True if a moderator has muted this avatars chat - - - True if a moderator has muted this avatars voice - - - - Role update flags - - - - - - - - - - - - - - - - - - - - - - Can send invitations to groups default role - - - Can eject members from group - - - Can toggle 'Open Enrollment' and change 'Signup fee' - - - Member is visible in the public member list - - - Can create new roles - - - Can delete existing roles - - - Can change Role names, titles and descriptions - - - Can assign other members to assigners role - - - Can assign other members to any role - - - Can remove members from roles - - - Can assign and remove abilities in roles - - - Can change group Charter, Insignia, 'Publish on the web' and which - members are publicly visible in group member listings - - - Can buy land or deed land to group - - - Can abandon group owned land to Governor Linden on mainland, or Estate owner for - private estates - - - Can set land for-sale information on group owned parcels - - - Can subdivide and join parcels - - - Can toggle "Show in Find Places" and set search category - - - Can change parcel name, description, and 'Publish on web' settings - - - Can set the landing point and teleport routing on group land - - - Can change music and media settings - - - Can toggle 'Edit Terrain' option in Land settings - - - Can toggle various About Land > Options settings - - - Can always terraform land, even if parcel settings have it turned off - - - Can always fly while over group owned land - - - Can always rez objects on group owned land - - - Can always create landmarks for group owned parcels - - - Can set home location on any group owned parcel - - - Can modify public access settings for group owned parcels - - - Can manager parcel ban lists on group owned land - - - Can manage pass list sales information - - - Can eject and freeze other avatars on group owned land - - - Can return objects set to group - - - Can return non-group owned/set objects - - - Can return group owned objects - - - Can landscape using Linden plants - - - Can deed objects to group - - - Can move group owned objects - - - Can set group owned objects for-sale - - - Pay group liabilities and receive group dividends - - - List and Host group events - - - Can send group notices - - - Can receive group notices - - - Can create group proposals - - - Can vote on group proposals - - - Can join group chat sessions - - - Can use voice chat in Group Chat sessions - - - Can moderate group chat sessions - - - Has admin rights to any experiences owned by this group - - - Can sign scripts for experiences owned by this group - - - Allows access to ban / un-ban agents from a group - - - - Ban actions available for group members - - - - Ban agent from joining a group - - - Remove restriction on agent jointing a group - - - - Handles all network traffic related to reading and writing group - information - - - - The event subscribers. null if no subcribers - - - Raises the CurrentGroups event - A CurrentGroupsEventArgs object containing the - data sent from the simulator - - - Thread sync lock object - - - Raised when the simulator sends us data containing - our current group membership - - - The event subscribers. null if no subcribers - - - Raises the GroupNamesReply event - A GroupNamesEventArgs object containing the - data response from the simulator - - - Thread sync lock object - - - Raised when the simulator responds to a RequestGroupName - or RequestGroupNames request - - - The event subscribers. null if no subcribers - - - Raises the GroupProfile event - An GroupProfileEventArgs object containing the - data returned from the simulator - - - Thread sync lock object - - - Raised when the simulator responds to a request - - - The event subscribers. null if no subcribers - - - Raises the GroupMembers event - A GroupMembersEventArgs object containing the - data returned from the simulator - - - Thread sync lock object - - - Raised when the simulator responds to a request - - - The event subscribers. null if no subcribers - - - Raises the GroupRolesDataReply event - A GroupRolesDataReplyEventArgs object containing the - data returned from the simulator - - - Thread sync lock object - - - Raised when the simulator responds to a request - - - The event subscribers. null if no subcribers - - - Raises the GroupRoleMembersReply event - A GroupRolesRoleMembersReplyEventArgs object containing the - data returned from the simulator - - - Thread sync lock object - - - Raised when the simulator responds to a request - - - The event subscribers. null if no subcribers - - - Raises the GroupTitlesReply event - A GroupTitlesReplyEventArgs object containing the - data returned from the simulator - - - Thread sync lock object - - - Raised when the simulator responds to a request - - - The event subscribers. null if no subcribers - - - Raises the GroupAccountSummary event - A GroupAccountSummaryReplyEventArgs object containing the - data returned from the simulator - - - Thread sync lock object - - - Raised when a response to a RequestGroupAccountSummary is returned - by the simulator - - - The event subscribers. null if no subcribers - - - Raises the GroupCreated event - An GroupCreatedEventArgs object containing the - data returned from the simulator - - - Thread sync lock object - - - Raised when a request to create a group is successful - - - The event subscribers. null if no subcribers - - - Raises the GroupJoined event - A GroupOperationEventArgs object containing the - result of the operation returned from the simulator - - - Thread sync lock object - - - Raised when a request to join a group either - fails or succeeds - - - The event subscribers. null if no subcribers - - - Raises the GroupLeft event - A GroupOperationEventArgs object containing the - result of the operation returned from the simulator - - - Thread sync lock object - - - Raised when a request to leave a group either - fails or succeeds - - - The event subscribers. null if no subcribers - - - Raises the GroupDropped event - An GroupDroppedEventArgs object containing the - the group your agent left - - - Thread sync lock object - - - Raised when A group is removed from the group server - - - The event subscribers. null if no subcribers - - - Raises the GroupMemberEjected event - An GroupMemberEjectedEventArgs object containing the - data returned from the simulator - - - Thread sync lock object - - - Raised when a request to eject a member from a group either - fails or succeeds - - - The event subscribers. null if no subcribers - - - Raises the GroupNoticesListReply event - An GroupNoticesListReplyEventArgs object containing the - data returned from the simulator - - - Thread sync lock object - - - Raised when the simulator sends us group notices - - - - The event subscribers. null if no subcribers - - - Raises the GroupInvitation event - An GroupInvitationEventArgs object containing the - data returned from the simulator - - - Thread sync lock object - - - Raised when another agent invites our avatar to join a group - - - The event subscribers. null if no subcribers - - - Raises the BannedAgents event - An BannedAgentsEventArgs object containing the - data returned from the simulator - - - Thread sync lock object - - - Raised when another agent invites our avatar to join a group - - - A reference to the current instance - - - Currently-active group members requests - - - Currently-active group roles requests - - - Currently-active group role-member requests - - - Dictionary keeping group members while request is in progress - - - Dictionary keeping mebmer/role mapping while request is in progress - - - Dictionary keeping GroupRole information while request is in progress - - - Caches group name lookups - - - - Construct a new instance of the GroupManager class - - A reference to the current instance - - - - Request a current list of groups the avatar is a member of. - - CAPS Event Queue must be running for this to work since the results - come across CAPS. - - - - Lookup name of group based on groupID - - groupID of group to lookup name for. - - - - Request lookup of multiple group names - - List of group IDs to request. - - - Lookup group profile data such as name, enrollment, founder, logo, etc - Subscribe to OnGroupProfile event to receive the results. - group ID (UUID) - - - Request a list of group members. - Subscribe to OnGroupMembers event to receive the results. - group ID (UUID) - UUID of the request, use to index into cache - - - Request group roles - Subscribe to OnGroupRoles event to receive the results. - group ID (UUID) - UUID of the request, use to index into cache - - - Request members (members,role) role mapping for a group. - Subscribe to OnGroupRolesMembers event to receive the results. - group ID (UUID) - UUID of the request, use to index into cache - - - Request a groups Titles - Subscribe to OnGroupTitles event to receive the results. - group ID (UUID) - UUID of the request, use to index into cache - - - Begin to get the group account summary - Subscribe to the OnGroupAccountSummary event to receive the results. - group ID (UUID) - How long of an interval - Which interval (0 for current, 1 for last) - - - Invites a user to a group - The group to invite to - A list of roles to invite a person to - Key of person to invite - - - Set a group as the current active group - group ID (UUID) - - - Change the role that determines your active title - Group ID to use - Role ID to change to - - - Set this avatar's tier contribution - Group ID to change tier in - amount of tier to donate - - - - Save wheather agent wants to accept group notices and list this group in their profile - - Group - Accept notices from this group - List this group in the profile - - - Request to join a group - Subscribe to OnGroupJoined event for confirmation. - group ID (UUID) to join. - - - - Request to create a new group. If the group is successfully - created, L$100 will automatically be deducted - - Subscribe to OnGroupCreated event to receive confirmation. - Group struct containing the new group info - - - Update a group's profile and other information - Groups ID (UUID) to update. - Group struct to update. - - - Eject a user from a group - Group ID to eject the user from - Avatar's key to eject - - - Update role information - Modified role to be updated - - - Create a new group role - Group ID to update - Role to create - - - Delete a group role - Group ID to update - Role to delete - - - Remove an avatar from a role - Group ID to update - Role ID to be removed from - Avatar's Key to remove - - - Assign an avatar to a role - Group ID to update - Role ID to assign to - Avatar's ID to assign to role - - - Request the group notices list - Group ID to fetch notices for - - - Request a group notice by key - ID of group notice - - - Send out a group notice - Group ID to update - GroupNotice structure containing notice data - - - Start a group proposal (vote) - The Group ID to send proposal to - GroupProposal structure containing the proposal - - - Request to leave a group - Subscribe to OnGroupLeft event to receive confirmation - The group to leave - - - - Gets the URI of the cpability for handling group bans - - Group ID - null, if the feature is not supported, or URI of the capability - - - - Request a list of residents banned from joining a group - - UUID of the group - - - - Request a list of residents banned from joining a group - - UUID of the group - Callback on request completition - - - - Request that group of agents be banned or unbanned from the group - - Group ID - Ban/Unban action - Array of agents UUIDs to ban - - - - Request that group of agents be banned or unbanned from the group - - Group ID - Ban/Unban action - Array of agents UUIDs to ban - Callback - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - - - Contains the current groups your agent is a member of - - - Get the current groups your agent is a member of - - - Construct a new instance of the CurrentGroupsEventArgs class - The current groups your agent is a member of - - - A Dictionary of group names, where the Key is the groups ID and the value is the groups name - - - Get the Group Names dictionary - - - Construct a new instance of the GroupNamesEventArgs class - The Group names dictionary - - - Represents the members of a group - - - Get the ID as returned by the request to correlate - this result set and the request - - - Get the ID of the group - - - Get the dictionary of members - - - - Construct a new instance of the GroupMembersReplyEventArgs class - - The ID of the request - The ID of the group - The membership list of the group - - - Represents the roles associated with a group - - - Get the ID as returned by the request to correlate - this result set and the request - - - Get the ID of the group - - - Get the dictionary containing the roles - - - Construct a new instance of the GroupRolesDataReplyEventArgs class - The ID as returned by the request to correlate - this result set and the request - The ID of the group - The dictionary containing the roles - - - Represents the Role to Member mappings for a group - - - Get the ID as returned by the request to correlate - this result set and the request - - - Get the ID of the group - - - Get the member to roles map - - - Construct a new instance of the GroupRolesMembersReplyEventArgs class - The ID as returned by the request to correlate - this result set and the request - The ID of the group - The member to roles map - - - Represents the titles for a group - - - Get the ID as returned by the request to correlate - this result set and the request - - - Get the ID of the group - - - Get the titles - - - Construct a new instance of the GroupTitlesReplyEventArgs class - The ID as returned by the request to correlate - this result set and the request - The ID of the group - The titles - - - Represents the summary data for a group - - - Get the ID of the group - - - Get the summary data - - - Construct a new instance of the GroupAccountSummaryReplyEventArgs class - The ID of the group - The summary data - - - A response to a group create request - - - Get the ID of the group - - - true of the group was created successfully - - - A string containing the message - - - Construct a new instance of the GroupCreatedReplyEventArgs class - The ID of the group - the success or faulure of the request - A string containing additional information - - - Represents a response to a request - - - Get the ID of the group - - - true of the request was successful - - - Construct a new instance of the GroupOperationEventArgs class - The ID of the group - true of the request was successful - - - Represents your agent leaving a group - - - Get the ID of the group - - - Construct a new instance of the GroupDroppedEventArgs class - The ID of the group - - - Represents a list of active group notices - - - Get the ID of the group - - - Get the notices list - - - Construct a new instance of the GroupNoticesListReplyEventArgs class - The ID of the group - The list containing active notices - - - Represents the profile of a group - - - Get the group profile - - - Construct a new instance of the GroupProfileEventArgs class - The group profile - - - - Provides notification of a group invitation request sent by another Avatar - - The invitation is raised when another avatar makes an offer for our avatar - to join a group. - - - The ID of the Avatar sending the group invitation - - - The name of the Avatar sending the group invitation - - - A message containing the request information which includes - the name of the group, the groups charter and the fee to join details - - - The Simulator - - - Set to true to accept invitation, false to decline - - - - Result of the request for list of agents banned from a group - - - - Indicates if list of banned agents for a group was successfully retrieved - - - Indicates if list of banned agents for a group was successfully retrieved - - - Array containing a list of UUIDs of the agents banned from a group - - - - Static helper functions and global variables - - - - This header flag signals that ACKs are appended to the packet - - - This header flag signals that this packet has been sent before - - - This header flags signals that an ACK is expected for this packet - - - This header flag signals that the message is compressed using zerocoding - - - - Passed to Logger.Log() to identify the severity of a log entry - - - - No logging information will be output - - - Non-noisy useful information, may be helpful in - debugging a problem - - - A non-critical error occurred. A warning will not - prevent the rest of the library from operating as usual, - although it may be indicative of an underlying issue - - - A critical error has occurred. Generally this will - be followed by the network layer shutting down, although the - stability of the library after an error is uncertain - - - Used for internal testing, this logging level can - generate very noisy (long and/or repetitive) messages. Don't - pass this to the Log() function, use DebugLog() instead. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Given an X/Y location in absolute (grid-relative) terms, a region - handle is returned along with the local X/Y location in that region - - The absolute X location, a number such as - 255360.35 - The absolute Y location, a number such as - 255360.35 - The sim-local X position of the global X - position, a value from 0.0 to 256.0 - The sim-local Y position of the global Y - position, a value from 0.0 to 256.0 - A 64-bit region handle that can be used to teleport to - - - - Converts a floating point number to a terse string format used for - transmitting numbers in wearable asset files - - Floating point number to convert to a string - A terse string representation of the input number - - - - Convert a variable length field (byte array) to a string, with a - field name prepended to each line of the output - - If the byte array has unprintable characters in it, a - hex dump will be written instead - The StringBuilder object to write to - The byte array to convert to a string - A field name to prepend to each line of output - - - - Decode a zerocoded byte array, used to decompress packets marked - with the zerocoded flag - - Any time a zero is encountered, the next byte is a count - of how many zeroes to expand. One zero is encoded with 0x00 0x01, - two zeroes is 0x00 0x02, three zeroes is 0x00 0x03, etc. The - first four bytes are copied directly to the output buffer. - - The byte array to decode - The length of the byte array to decode. This - would be the length of the packet up to (but not including) any - appended ACKs - The output byte array to decode to - The length of the output buffer - - - - Encode a byte array with zerocoding. Used to compress packets marked - with the zerocoded flag. Any zeroes in the array are compressed down - to a single zero byte followed by a count of how many zeroes to expand - out. A single zero becomes 0x00 0x01, two zeroes becomes 0x00 0x02, - three zeroes becomes 0x00 0x03, etc. The first four bytes are copied - directly to the output buffer. - - The byte array to encode - The length of the byte array to encode - The output byte array to encode to - The length of the output buffer - - - - Calculates the CRC (cyclic redundancy check) needed to upload inventory. - - Creation date - Sale type - Inventory type - Type - Asset ID - Group ID - Sale price - Owner ID - Creator ID - Item ID - Folder ID - Everyone mask (permissions) - Flags - Next owner mask (permissions) - Group mask (permissions) - Owner mask (permissions) - The calculated CRC - - - - Attempts to load a file embedded in the assembly - - The filename of the resource to load - A Stream for the requested file, or null if the resource - was not successfully loaded - - - - Attempts to load a file either embedded in the assembly or found in - a given search path - - The filename of the resource to load - An optional path that will be searched if - the asset is not found embedded in the assembly - A Stream for the requested file, or null if the resource - was not successfully loaded - - - - Converts a list of primitives to an object that can be serialized - with the LLSD system - - Primitives to convert to a serializable object - An object that can be serialized with LLSD - - - - Deserializes OSD in to a list of primitives - - Structure holding the serialized primitive list, - must be of the SDMap type - A list of deserialized primitives - - - - Converts a struct or class object containing fields only into a key value separated string - - The struct object - A string containing the struct fields as the keys, and the field value as the value separated - - - // Add the following code to any struct or class containing only fields to override the ToString() - // method to display the values of the passed object - - /// Print the struct data as a string - ///A string containing the field name, and field value - public override string ToString() - { - return Helpers.StructToString(this); - } - - - - - - decompresses a gzipped OSD object - - - the OSD object - - - - A set of textures that are layered on texture of each other and "baked" - in to a single texture, for avatar appearances - - - - Final baked texture - - - Component layers - - - Width of the final baked image and scratchpad - - - Height of the final baked image and scratchpad - - - Bake type - - - Is this one of the 3 skin bakes - - - Final baked texture - - - Component layers - - - Width of the final baked image and scratchpad - - - Height of the final baked image and scratchpad - - - Bake type - - - - Default constructor - - Bake type - - - - Adds layer for baking - - TexturaData struct that contains texture and its params - - - - Converts avatar texture index (face) to Bake type - - Face number (AvatarTextureIndex) - BakeType, layer to which this texture belongs to - - - - Make sure images exist, resize source if needed to match the destination - - Destination image - Source image - Sanitization was succefull - - - - Fills a baked layer as a solid *appearing* color. The colors are - subtly dithered on a 16x16 grid to prevent the JPEG2000 stage from - compressing it too far since it seems to cause upload failures if - the image is a pure solid color - - Color of the base of this layer - - - - Fills a baked layer as a solid *appearing* color. The colors are - subtly dithered on a 16x16 grid to prevent the JPEG2000 stage from - compressing it too far since it seems to cause upload failures if - the image is a pure solid color - - Red value - Green value - Blue value - - - - Image width - - - - - Image height - - - - - Image channel flags - - - - - Red channel data - - - - - Green channel data - - - - - Blue channel data - - - - - Alpha channel data - - - - - Bump channel data - - - - - Create a new blank image - - width - height - channel flags - - - - - - - - - - Convert the channels in the image. Channels are created or destroyed as required. - - new channel flags - - - - Resize or stretch the image using nearest neighbor (ugly) resampling - - new width - new height - - - - Create a byte array containing 32-bit RGBA data with a bottom-left - origin, suitable for feeding directly into OpenGL - - A byte array containing raw texture data - - - - Create a byte array containing 32-bit RGBA data with a bottom-left - origin, suitable for feeding directly into OpenGL - - A byte array containing raw texture data - - - - Capability to load TGAs to Bitmap - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Parsing Collada model files into data structures - - - - - Parses Collada document - - Load .dae model from this file - Load and decode images for uploading with model - A list of mesh prims that were parsed from the collada file - - - - Implements mesh upload communications with the simulator - - - - - Inlcude stub convex hull physics, required for uploading to Second Life - - - - - Use the same mesh used for geometry as the physical mesh upload - - - - - Callback for mesh upload operations - - null on failure, result from server on success - - - - Creates instance of the mesh uploader - - GridClient instance to communicate with the simulator - List of ModelPrimitive objects to upload as a linkset - Inventory name for newly uploaded object - Inventory description for newly upload object - - - - Performs model upload in one go, without first checking for the price - - - - - Performs model upload in one go, without first checking for the price - - Callback that will be invoke upon completion of the upload. Null is sent on request failure - - - - Ask server for details of cost and impact of the mesh upload - - Callback that will be invoke upon completion of the upload. Null is sent on request failure - - - - Performas actual mesh and image upload - - Uri recieved in the upload prepare stage - Callback that will be invoke upon completion of the upload. Null is sent on request failure - - - - Interface to a class that can supply cached byte arrays - - - - - Leases a byte array from the pool - - Minimum size the array must be to satisfy this request - A poooled array that is at least minSize - - - - Returns a byte array to the pool - - The bytes being returned - - - - Interface requirements for Messaging system - - - - - Abstract base for rendering plugins - - - - - Generates a basic mesh structure from a primitive - - Primitive to generate the mesh from - Level of detail to generate the mesh at - The generated mesh - - - - Generates a basic mesh structure from a sculpted primitive and - texture - - Sculpted primitive to generate the mesh from - Sculpt texture - Level of detail to generate the mesh at - The generated mesh - - - - Generates a series of faces, each face containing a mesh and - metadata - - Primitive to generate the mesh from - Level of detail to generate the mesh at - The generated mesh - - - - Generates a series of faces for a sculpted prim, each face - containing a mesh and metadata - - Sculpted primitive to generate the mesh from - Sculpt texture - Level of detail to generate the mesh at - The generated mesh - - - - Apply texture coordinate modifications from a - to a list of vertices - - Vertex list to modify texture coordinates for - Center-point of the face - Face texture parameters - Scale of the prim - - - - Binary reader, which is endian aware - - - - What is the format of the source file - - - - Construct a reader from a stream - - The stream to read from - - - - Construct a reader from a stream - - The stream to read from - What is the format of the file, assumes PC and similar architecture - - - - Read a 32 bit integer - - A 32 bit integer in the system's endianness - - - - Read a 16 bit integer - - A 16 bit integer in the system's endianness - - - - Read a 64 bit integer - - A 64 bit integer in the system's endianness - - - - Read an unsigned 32 bit integer - - A 32 bit unsigned integer in the system's endianness - - - - Read a single precision floating point value - - A single precision floating point value in the system's endianness - - - - Read a double precision floating point value - - A double precision floating point value in the system's endianness - - - - Read a UTF-8 string - - A standard system string - - - - Read a UTF-8 string - - length of string to read - A standard system string - - - - Load and handle Linden Lab binary meshes. - - - The exact definition of this file is a bit sketchy, especially concerning skin weights. - A good starting point is on the - second life wiki - - - - - Defines a polygon - - - - - Structure of a vertex, No surprises there, except for the Detail tex coord - - - The skinweights are a tad unconventional. The best explanation found is: - >Each weight actually contains two pieces of information. The number to the - >left of the decimal point is the index of the joint and also implicitly - >indexes to the following joint. The actual weight is to the right of the - >decimal point and interpolates between these two joints. The index is into - >an "expanded" list of joints, not just a linear array of the joints as - >defined in the skeleton file. In particular, any joint that has more than - >one child will be repeated in the list for each of its children. - - Maybe I'm dense, but that description seems to be a bit hard to build an - algorithm on. - - Esentially the weights are compressed into one floating point value. - 1. The whole number part is an index into an array of joints - 2. The fractional part is the weight that joint has - 3. If the fractional part is 0 (x.0000) then the vertex is 100% influenced by the specified joint - - - - - Provide a nice format for debugging - - Vertex definition as a string - - - - Describes deltas to apply to a vertex in order to morph a vertex - - - - - Provide a nice format for debugging - - MorphVertex definition as a string - - - - Describes a named mesh morph, essentially a named list of MorphVertices - - - - - Provide a nice format for debugging - - The name of the morph - - - - Don't really know what this does - - - - - Provide a nice format for debugging - - Human friendly format - - - - A reference mesh is one way to implement level of detail - - - Reference meshes are supplemental meshes to full meshes. For all practical - purposes almost all lod meshes are implemented as reference meshes, except for - 'avatar_eye_1.llm' which for some reason is implemented as a full mesh. - - - - - Load a mesh from a stream - - Filename and path of the file containing the reference mesh - - - - Level of Detail mesh - - - - - Construct a linden mesh with the given name - - the name of the mesh - - - - Construct a linden mesh with the given name - - the name of the mesh - The skeleton governing mesh deformation - - - - Load the mesh from a stream - - The filename and path of the file containing the mesh data - - - - Layout of one skinweight element - - - - List of skinweights, in the same order as the mesh vertices - - - - Decompress the skinweights - - the expanded joint list, used to index which bones should influece the vertex - - - - Load a reference mesh from a given stream - - The lod level of this reference mesh - the name and path of the file containing the mesh data - the loaded reference mesh - - - - Trim a string at the first occurence of NUL - - - The llm file uses null terminated strings (C/C++ style), this is where - the conversion is made. - - The string to trim - A standard .Net string - - - - load the 'avatar_skeleton.xml' - - - Partial class which extends the auto-generated 'LindenSkeleton.Xsd.cs'.eton.xsd - - - - - - Load a skeleton from a given file. - - - We use xml scema validation on top of the xml de-serializer, since the schema has - some stricter checks than the de-serializer provides. E.g. the vector attributes - are guaranteed to hold only 3 float values. This reduces the need for error checking - while working with the loaded skeleton. - - A valid recursive skeleton - - - - Load a skeleton from a given file. - - - We use xml scema validation on top of the xml de-serializer, since the schema has - some stricter checks than the de-serializer provides. E.g. the vector attributes - are guaranteed to hold only 3 float values. This reduces the need for error checking - while working with the loaded skeleton. - - The path to the skeleton definition file - A valid recursive skeleton - - - - Build and "expanded" list of joints - - - The algorithm is based on this description: - - >An "expanded" list of joints, not just a - >linear array of the joints as defined in the skeleton file. - >In particular, any joint that has more than one child will - >be repeated in the list for each of its children. - - The list should only take these joint names in consideration - An "expanded" joints list as a flat list of bone names - - - - Expand one joint - - The parent of the joint we are operating on - The joint we are supposed to expand - Joint list that we will extend upon - The expanded list should only contain these joints - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Contains all mesh faces that belong to a prim - - - - List of primitive faces - - - - Decodes mesh asset into FacetedMesh - - Mesh primitive - Asset retrieved from the asset server - Level of detail - Resulting decoded FacetedMesh - True if mesh asset decoding was successful - - - - The InternalDictionary class is used through the library for storing key/value pairs. - It is intended to be a replacement for the generic Dictionary class and should - be used in its place. It contains several methods for allowing access to the data from - outside the library that are read only and thread safe. - - - Key - Value - - - Internal dictionary that this class wraps around. Do not - modify or enumerate the contents of this dictionary without locking - on this member - - - - Gets the number of Key/Value pairs contained in the - - - - - Initializes a new instance of the Class - with the specified key/value, has the default initial capacity. - - - - // initialize a new InternalDictionary named testDict with a string as the key and an int as the value. - public InternalDictionary<string, int> testDict = new InternalDictionary<string, int>(); - - - - - - Initializes a new instance of the Class - with the specified key/value, has its initial valies copied from the specified - - - - to copy initial values from - - - // initialize a new InternalDictionary named testAvName with a UUID as the key and an string as the value. - // populates with copied values from example KeyNameCache Dictionary. - - // create source dictionary - Dictionary<UUID, string> KeyNameCache = new Dictionary<UUID, string>(); - KeyNameCache.Add("8300f94a-7970-7810-cf2c-fc9aa6cdda24", "Jack Avatar"); - KeyNameCache.Add("27ba1e40-13f7-0708-3e98-5819d780bd62", "Jill Avatar"); - - // Initialize new dictionary. - public InternalDictionary<UUID, string> testAvName = new InternalDictionary<UUID, string>(KeyNameCache); - - - - - - Initializes a new instance of the Class - with the specified key/value, With its initial capacity specified. - - Initial size of dictionary - - - // initialize a new InternalDictionary named testDict with a string as the key and an int as the value, - // initially allocated room for 10 entries. - public InternalDictionary<string, int> testDict = new InternalDictionary<string, int>(10); - - - - - - Try to get entry from with specified key - - Key to use for lookup - Value returned - if specified key exists, if not found - - - // find your avatar using the Simulator.ObjectsAvatars InternalDictionary: - Avatar av; - if (Client.Network.CurrentSim.ObjectsAvatars.TryGetValue(Client.Self.AgentID, out av)) - Console.WriteLine("Found Avatar {0}", av.Name); - - - - - - - Finds the specified match. - - The match. - Matched value - - - // use a delegate to find a prim in the ObjectsPrimitives InternalDictionary - // with the ID 95683496 - uint findID = 95683496; - Primitive findPrim = sim.ObjectsPrimitives.Find( - delegate(Primitive prim) { return prim.ID == findID; }); - - - - - Find All items in an - return matching items. - a containing found items. - - Find All prims within 20 meters and store them in a List - - int radius = 20; - List<Primitive> prims = Client.Network.CurrentSim.ObjectsPrimitives.FindAll( - delegate(Primitive prim) { - Vector3 pos = prim.Position; - return ((prim.ParentID == 0) && (pos != Vector3.Zero) && (Vector3.Distance(pos, location) < radius)); - } - ); - - - - - Find All items in an - return matching keys. - a containing found keys. - - Find All keys which also exist in another dictionary - - List<UUID> matches = myDict.FindAll( - delegate(UUID id) { - return myOtherDict.ContainsKey(id); - } - ); - - - - - Perform an on each entry in an - to perform - - - // Iterates over the ObjectsPrimitives InternalDictionary and prints out some information. - Client.Network.CurrentSim.ObjectsPrimitives.ForEach( - delegate(Primitive prim) - { - if (prim.Text != null) - { - Console.WriteLine("NAME={0} ID = {1} TEXT = '{2}'", - prim.PropertiesFamily.Name, prim.ID, prim.Text); - } - }); - - - - - Perform an on each key of an - to perform - - - - Perform an on each KeyValuePair of an - - to perform - - - Check if Key exists in Dictionary - Key to check for - if found, otherwise - - - Check if Value exists in Dictionary - Value to check for - if found, otherwise - - - - Adds the specified key to the dictionary, dictionary locking is not performed, - - - The key - The value - - - - Removes the specified key, dictionary locking is not performed - - The key. - if successful, otherwise - - - - Indexer for the dictionary - - The key - The value - - - - - Exception class to identify inventory exceptions - - - - - Responsible for maintaining inventory structure. Inventory constructs nodes - and manages node children as is necessary to maintain a coherant hirarchy. - Other classes should not manipulate or create InventoryNodes explicitly. When - A node's parent changes (when a folder is moved, for example) simply pass - Inventory the updated InventoryFolder and it will make the appropriate changes - to its internal representation. - - - - The event subscribers, null of no subscribers - - - Raises the InventoryObjectUpdated Event - A InventoryObjectUpdatedEventArgs object containing - the data sent from the simulator - - - Thread sync lock object - - - Raised when the simulator sends us data containing - ... - - - The event subscribers, null of no subscribers - - - Raises the InventoryObjectRemoved Event - A InventoryObjectRemovedEventArgs object containing - the data sent from the simulator - - - Thread sync lock object - - - Raised when the simulator sends us data containing - ... - - - The event subscribers, null of no subscribers - - - Raises the InventoryObjectAdded Event - A InventoryObjectAddedEventArgs object containing - the data sent from the simulator - - - Thread sync lock object - - - Raised when the simulator sends us data containing - ... - - - - The root folder of this avatars inventory - - - - - The default shared library folder - - - - - The root node of the avatars inventory - - - - - The root node of the default shared library - - - - - Returns the contents of the specified folder - - A folder's UUID - The contents of the folder corresponding to folder - When folder does not exist in the inventory - - - - Updates the state of the InventoryNode and inventory data structure that - is responsible for the InventoryObject. If the item was previously not added to inventory, - it adds the item, and updates structure accordingly. If it was, it updates the - InventoryNode, changing the parent node if item.parentUUID does - not match node.Parent.Data.UUID. - - You can not set the inventory root folder using this method - - The InventoryObject to store - - - - Removes the InventoryObject and all related node data from Inventory. - - The InventoryObject to remove. - - - - Used to find out if Inventory contains the InventoryObject - specified by uuid. - - The UUID to check. - true if inventory contains uuid, false otherwise - - - - Saves the current inventory structure to a cache file - - Name of the cache file to save to - - - - Loads in inventory cache file into the inventory structure. Note only valid to call after login has been successful. - - Name of the cache file to load - The number of inventory items successfully reconstructed into the inventory node tree - - - - By using the bracket operator on this class, the program can get the - InventoryObject designated by the specified uuid. If the value for the corresponding - UUID is null, the call is equivelant to a call to RemoveNodeFor(this[uuid]). - If the value is non-null, it is equivelant to a call to UpdateNodeFor(value), - the uuid parameter is ignored. - - The UUID of the InventoryObject to get or set, ignored if set to non-null value. - The InventoryObject corresponding to uuid. - - - - Base Class for Inventory Items - - - - of item/folder - - - of parent folder - - - Name of item/folder - - - Item/Folder Owners - - - - Constructor, takes an itemID as a parameter - - The of the item - - - - Get object data - - - - - - - Inventory base ctor - - - - - - - Generates a number corresponding to the value of the object to support the use of a hash table, - suitable for use in hashing algorithms and data structures such as a hash table - - A Hashcode of all the combined InventoryBase fields - - - - Determine whether the specified object is equal to the current object - - InventoryBase object to compare against - true if objects are the same - - - - Determine whether the specified object is equal to the current object - - InventoryBase object to compare against - true if objects are the same - - - - Convert inventory to OSD - - OSD representation - - - - An Item in Inventory - - - - The of this item - - - The combined of this item - - - The type of item from - - - The type of item from the enum - - - The of the creator of this item - - - A Description of this item - - - The s this item is set to or owned by - - - If true, item is owned by a group - - - The price this item can be purchased for - - - The type of sale from the enum - - - Combined flags from - - - Time and date this inventory item was created, stored as - UTC (Coordinated Universal Time) - - - Used to update the AssetID in requests sent to the server - - - The of the previous owner of the item - - - - Construct a new InventoryItem object - - The of the item - - - - Construct a new InventoryItem object of a specific Type - - The type of item from - of the item - - - - Indicates inventory item is a link - - True if inventory item is a link to another inventory item - - - - - Get object data - - - - - - - Inventory item ctor - - - - - - - Generates a number corresponding to the value of the object to support the use of a hash table. - Suitable for use in hashing algorithms and data structures such as a hash table - - A Hashcode of all the combined InventoryItem fields - - - - - Compares an object - - The object to compare - true if comparison object matches - - - - - Determine whether the specified object is equal to the current object - - The object to compare against - true if objects are the same - - - - Determine whether the specified object is equal to the current object - - The object to compare against - true if objects are the same - - - - Create InventoryItem from OSD - - OSD Data that makes up InventoryItem - Inventory item created - - - - Convert InventoryItem to OSD - - OSD representation of InventoryItem - - - - - InventoryTexture Class representing a graphical image - - - - - - Construct an InventoryTexture object - - A which becomes the - objects AssetUUID - - - - Construct an InventoryTexture object from a serialization stream - - - - - - InventorySound Class representing a playable sound - - - - - Construct an InventorySound object - - A which becomes the - objects AssetUUID - - - - Construct an InventorySound object from a serialization stream - - - - - - InventoryCallingCard Class, contains information on another avatar - - - - - Construct an InventoryCallingCard object - - A which becomes the - objects AssetUUID - - - - Construct an InventoryCallingCard object from a serialization stream - - - - - - InventoryLandmark Class, contains details on a specific location - - - - - Construct an InventoryLandmark object - - A which becomes the - objects AssetUUID - - - - Construct an InventoryLandmark object from a serialization stream - - - - - Landmarks use the InventoryItemFlags struct and will have a flag of 1 set if they have been visited - - - - - - InventoryObject Class contains details on a primitive or coalesced set of primitives - - - - - Construct an InventoryObject object - - A which becomes the - objects AssetUUID - - - - Construct an InventoryObject object from a serialization stream - - - - - Gets or sets the upper byte of the Flags value - - - - - Gets or sets the object attachment point, the lower byte of the Flags value - - - - - - InventoryNotecard Class, contains details on an encoded text document - - - - - Construct an InventoryNotecard object - - A which becomes the - objects AssetUUID - - - - Construct an InventoryNotecard object from a serialization stream - - - - - - InventoryCategory Class - - TODO: Is this even used for anything? - - - - Construct an InventoryCategory object - - A which becomes the - objects AssetUUID - - - - Construct an InventoryCategory object from a serialization stream - - - - - - InventoryLSL Class, represents a Linden Scripting Language object - - - - - Construct an InventoryLSL object - - A which becomes the - objects AssetUUID - - - - Construct an InventoryLSL object from a serialization stream - - - - - - InventorySnapshot Class, an image taken with the viewer - - - - - - Construct an InventorySnapshot object - - A which becomes the - objects AssetUUID - - - - Construct an InventorySnapshot object from a serialization stream - - - - - InventoryAttachment Class, contains details on an attachable object - - - - - Construct an InventoryAttachment object - - A which becomes the - objects AssetUUID - - - - Construct an InventoryAttachment object from a serialization stream - - - - - Get the last AttachmentPoint this object was attached to - - - - - - InventoryWearable Class, details on a clothing item or body part - - - - - Construct an InventoryWearable object - - A which becomes the - objects AssetUUID - - - - Construct an InventoryWearable object from a serialization stream - - - - - The , Skin, Shape, Skirt, Etc - - - - - - InventoryAnimation Class, A bvh encoded object which animates an avatar - - - - - Construct an InventoryAnimation object - - A which becomes the - objects AssetUUID - - - - Construct an InventoryAnimation object from a serialization stream - - - - - - InventoryGesture Class, details on a series of animations, sounds, and actions - - - - - Construct an InventoryGesture object - - A which becomes the - objects AssetUUID - - - - Construct an InventoryGesture object from a serialization stream - - - - - - A folder contains s and has certain attributes specific - to itself - - - - The Preferred for a folder. - - - The Version of this folder - - - Number of child items this folder contains. - - - - Constructor - - UUID of the folder - - - - Returns folder name - - Return folder name as string - - - - Get Serilization data for this InventoryFolder object - - - - - - - Construct an InventoryFolder object from a serialization stream - - - - - Return int hash code - - Hash code as integer - - - - Create InventoryFolder from OSD - - OSD Data that makes up InventoryFolder - Inventory folder created - - - - Convert InventoryFolder to OSD - - OSD representation of InventoryFolder - - - Sort by name - - - Sort by date - - - Sort folders by name, regardless of whether items are - sorted by name or date - - - Place system folders at the top - - - - Possible destinations for DeRezObject request - - - - - - - Copy from in-world to agent inventory - - - Derez to TaskInventory - - - - - - Take Object - - - God force to inventory - - - Delete Object - - - Put an avatar attachment into agent inventory - - - - - - Return an object back to the owner's inventory - - - Return a deeded object back to the last owner's inventory - - - - Upper half of the Flags field for inventory items - - - - Indicates that the NextOwner permission will be set to the - most restrictive set of permissions found in the object set - (including linkset items and object inventory items) on next rez - - - Indicates that the object sale information has been - changed - - - If set, and a slam bit is set, indicates BaseMask will be overwritten on Rez - - - If set, and a slam bit is set, indicates OwnerMask will be overwritten on Rez - - - If set, and a slam bit is set, indicates GroupMask will be overwritten on Rez - - - If set, and a slam bit is set, indicates EveryoneMask will be overwritten on Rez - - - If set, and a slam bit is set, indicates NextOwnerMask will be overwritten on Rez - - - Indicates whether this object is composed of multiple - items or not - - - Indicates that the asset is only referenced by this - inventory item. If this item is deleted or updated to reference a - new assetID, the asset can be deleted - - - - Tools for dealing with agents inventory - - - - Used for converting shadow_id to asset_id - - - Maximum items allowed to give - - - - Callback for inventory item creation finishing - - Whether the request to create an inventory - item succeeded or not - Inventory item being created. If success is - false this will be null - - - - Callback for an inventory item being create from an uploaded asset - - true if inventory item creation was successful - - - - - - - - - - - - The event subscribers, null of no subscribers - - - Raises the ItemReceived Event - A ItemReceivedEventArgs object containing - the data sent from the simulator - - - Thread sync lock object - - - Raised when the simulator sends us data containing - ... - - - The event subscribers, null of no subscribers - - - Raises the FolderUpdated Event - A FolderUpdatedEventArgs object containing - the data sent from the simulator - - - Thread sync lock object - - - Raised when the simulator sends us data containing - ... - - - The event subscribers, null of no subscribers - - - Raises the InventoryObjectOffered Event - A InventoryObjectOfferedEventArgs object containing - the data sent from the simulator - - - Thread sync lock object - - - Raised when the simulator sends us data containing - an inventory object sent by another avatar or primitive - - - The event subscribers, null of no subscribers - - - Raises the TaskItemReceived Event - A TaskItemReceivedEventArgs object containing - the data sent from the simulator - - - Thread sync lock object - - - Raised when the simulator sends us data containing - ... - - - The event subscribers, null of no subscribers - - - Raises the FindObjectByPath Event - A FindObjectByPathEventArgs object containing - the data sent from the simulator - - - Thread sync lock object - - - Raised when the simulator sends us data containing - ... - - - The event subscribers, null of no subscribers - - - Raises the TaskInventoryReply Event - A TaskInventoryReplyEventArgs object containing - the data sent from the simulator - - - Thread sync lock object - - - Raised when the simulator sends us data containing - ... - - - - Reply received when uploading an inventory asset - - Has upload been successful - Error message if upload failed - Inventory asset UUID - New asset UUID - - - The event subscribers, null of no subscribers - - - Raises the SaveAssetToInventory Event - A SaveAssetToInventoryEventArgs object containing - the data sent from the simulator - - - Thread sync lock object - - - Raised when the simulator sends us data containing - ... - - - - Delegate that is invoked when script upload is completed - - Has upload succeded (note, there still might be compile errors) - Upload status message - Is compilation successful - If compilation failed, list of error messages, null on compilation success - Script inventory UUID - Script's new asset UUID - - - The event subscribers, null of no subscribers - - - Raises the ScriptRunningReply Event - A ScriptRunningReplyEventArgs object containing - the data sent from the simulator - - - Thread sync lock object - - - Raised when the simulator sends us data containing - ... - - - Partial mapping of FolderTypes to folder names - - - - Get this agents Inventory data - - - - - Default constructor - - Reference to the GridClient object - - - - Fetch an inventory item from the dataserver - - The items - The item Owners - a integer representing the number of milliseconds to wait for results - An object on success, or null if no item was found - Items will also be sent to the event - - - - Request A single inventory item - - The items - The item Owners - - - - - Request inventory items - - Inventory items to request - Owners of the inventory items - - - - - Request inventory items via Capabilities - - Inventory items to request - Owners of the inventory items - - - - - FolderContentsWithReply - Get contents of a folder - - The of the folder to search - The of the folders owner - true to retrieve folders - true to retrieve items - sort order to return results in - a integer representing the number of milliseconds to wait for results - when false uses links and does not attempt to get the real object - keypair with a status message, and List - if the status message is retry you should check again in a bit is is currently loading - links using RequestFetchInventoryCap - - - - - Get contents of a folder - - The of the folder to search - The of the folders owner - true to retrieve folders - true to retrieve items - sort order to return results in - a integer representing the number of milliseconds to wait for results - when false uses links and does not attempt to get the real object - A list of inventory items matching search criteria within folder - - InventoryFolder.DescendentCount will only be accurate if both folders and items are - requested - - - - Request the contents of an inventory folder - - The folder to search - The folder owners - true to return s contained in folder - true to return s contained in folder - the sort order to return items in - - - - - Request the contents of an inventory folder using HTTP capabilities - - The folder to search - The folder owners - true to return s contained in folder - true to return s contained in folder - the sort order to return items in - - - - - Returns the UUID of the folder (category) that defaults to - containing 'type'. The folder is not necessarily only for that - type - - This will return the root folder if one does not exist - - The UUID of the desired folder if found, the UUID of the RootFolder - if not found, or UUID.Zero on failure - - - - Find an object in inventory using a specific path to search - - The folder to begin the search in - The object owners - A string path to search - milliseconds to wait for a reply - Found items or if - timeout occurs or item is not found - - - - Find inventory items by path - - The folder to begin the search in - The object owners - A string path to search, folders/objects separated by a '/' - Results are sent to the event - - - - Search inventory Store object for an item or folder - - The folder to begin the search in - An array which creates a path to search - Number of levels below baseFolder to conduct searches - if True, will stop searching after first match is found - A list of inventory items found - - - - Move an inventory item or folder to a new location - - The item or folder to move - The to move item or folder to - - - - Move an inventory item or folder to a new location and change its name - - The item or folder to move - The to move item or folder to - The name to change the item or folder to - - - - Move and rename a folder - - The source folders - The destination folders - The name to change the folder to - - - - Update folder properties - - of the folder to update - Sets folder's parent to - Folder name - Folder type - - - - Move a folder - - The source folders - The destination folders - - - - Move multiple folders, the keys in the Dictionary parameter, - to a new parents, the value of that folder's key. - - A Dictionary containing the - of the source as the key, and the - of the destination as the value - - - - Move an inventory item to a new folder - - The of the source item to move - The of the destination folder - - - - Move and rename an inventory item - - The of the source item to move - The of the destination folder - The name to change the folder to - - - - Move multiple inventory items to new locations - - A Dictionary containing the - of the source item as the key, and the - of the destination folder as the value - - - - Remove descendants of a folder - - The of the folder - - - - Remove a single item from inventory - - The of the inventory item to remove - - - - Remove a folder from inventory - - The of the folder to remove - - - - Remove multiple items or folders from inventory - - A List containing the s of items to remove - A List containing the s of the folders to remove - - - - Empty the Lost and Found folder - - - - - Empty the Trash folder - - - - - - - - - - - Proper use is to upload the inventory's asset first, then provide the Asset's TransactionID here. - - - - - - - - - - - - - Proper use is to upload the inventory's asset first, then provide the Asset's TransactionID here. - - - - - - - - Creates a new inventory folder - - ID of the folder to put this folder in - Name of the folder to create - The UUID of the newly created folder - - - - Creates a new inventory folder - - ID of the folder to put this folder in - Name of the folder to create - Sets this folder as the default folder - for new assets of the specified type. Use FolderType.None - to create a normal folder, otherwise it will likely create a - duplicate of an existing folder type - The UUID of the newly created folder - If you specify a preferred type of AsseType.Folder - it will create a new root folder which may likely cause all sorts - of strange problems - - - - Create an inventory item and upload asset data - - Asset data - Inventory item name - Inventory item description - Asset type - Inventory type - Put newly created inventory in this folder - Delegate that will receive feedback on success or failure - - - - Create an inventory item and upload asset data - - Asset data - Inventory item name - Inventory item description - Asset type - Inventory type - Put newly created inventory in this folder - Permission of the newly created item - (EveryoneMask, GroupMask, and NextOwnerMask of Permissions struct are supported) - Delegate that will receive feedback on success or failure - - - - Creates inventory link to another inventory item or folder - - Put newly created link in folder with this UUID - Inventory item or folder - Method to call upon creation of the link - - - - Creates inventory link to another inventory item - - Put newly created link in folder with this UUID - Original inventory item - Method to call upon creation of the link - - - - Creates inventory link to another inventory folder - - Put newly created link in folder with this UUID - Original inventory folder - Method to call upon creation of the link - - - - Creates inventory link to another inventory item or folder - - Put newly created link in folder with this UUID - Original item's UUID - Name - Description - Asset Type - Inventory Type - Transaction UUID - Method to call upon creation of the link - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Request a copy of an asset embedded within a notecard - - Usually UUID.Zero for copying an asset from a notecard - UUID of the notecard to request an asset from - Target folder for asset to go to in your inventory - UUID of the embedded asset - callback to run when item is copied to inventory - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Save changes to notecard embedded in object contents - - Encoded notecard asset data - Notecard UUID - Object's UUID - Called upon finish of the upload with status information - - - - Upload new gesture asset for an inventory gesture item - - Encoded gesture asset - Gesture inventory UUID - Callback whick will be called when upload is complete - - - - Update an existing script in an agents Inventory - - A byte[] array containing the encoded scripts contents - the itemID of the script - if true, sets the script content to run on the mono interpreter - - - - - Update an existing script in an task Inventory - - A byte[] array containing the encoded scripts contents - the itemID of the script - UUID of the prim containting the script - if true, sets the script content to run on the mono interpreter - if true, sets the script to running - - - - - Rez an object from inventory - - Simulator to place object in - Rotation of the object when rezzed - Vector of where to place object - InventoryItem object containing item details - - - - Rez an object from inventory - - Simulator to place object in - Rotation of the object when rezzed - Vector of where to place object - InventoryItem object containing item details - UUID of group to own the object - - - - Rez an object from inventory - - Simulator to place object in - Rotation of the object when rezzed - Vector of where to place object - InventoryItem object containing item details - UUID of group to own the object - User defined queryID to correlate replies - If set to true, the CreateSelected flag - will be set on the rezzed object - - - - Rez an object from inventory - - Simulator to place object in - TaskID object when rezzed - Rotation of the object when rezzed - Vector of where to place object - InventoryItem object containing item details - UUID of group to own the object - User defined queryID to correlate replies - If set to true, the CreateSelected flag - will be set on the rezzed object - - - - DeRez an object from the simulator to the agents Objects folder in the agents Inventory - - The simulator Local ID of the object - If objectLocalID is a child primitive in a linkset, the entire linkset will be derezzed - - - - DeRez an object from the simulator and return to inventory - - The simulator Local ID of the object - The type of destination from the enum - The destination inventory folders -or- - if DeRezzing object to a tasks Inventory, the Tasks - The transaction ID for this request which - can be used to correlate this request with other packets - If objectLocalID is a child primitive in a linkset, the entire linkset will be derezzed - - - - Rez an item from inventory to its previous simulator location - - - - - - - - - Give an inventory item to another avatar - - The of the item to give - The name of the item - The type of the item from the enum - The of the recipient - true to generate a beameffect during transfer - - - - Recurse inventory category and return folders and items. Does NOT contain parent folder being searched - - Inventory category to recursively search - Owner of folder - reference to list of categories - reference to list of items - - - - Give an inventory Folder with contents to another avatar - - The of the Folder to give - The name of the folder - The of the recipient - true to generate a beameffect during transfer - - - - Copy or move an from agent inventory to a task (primitive) inventory - - The target object - The item to copy or move from inventory - - For items with copy permissions a copy of the item is placed in the tasks inventory, - for no-copy items the object is moved to the tasks inventory - - - - Retrieve a listing of the items contained in a task (Primitive) - - The tasks - The tasks simulator local ID - milliseconds to wait for reply from simulator - A list containing the inventory items inside the task or null - if a timeout occurs - This request blocks until the response from the simulator arrives - or timeoutMS is exceeded - - - - Request the contents of a tasks (primitives) inventory from the - current simulator - - The LocalID of the object - - - - - Request the contents of a tasks (primitives) inventory - - The simulator Local ID of the object - A reference to the simulator object that contains the object - - - - - Move an item from a tasks (Primitive) inventory to the specified folder in the avatars inventory - - LocalID of the object in the simulator - UUID of the task item to move - The ID of the destination folder in this agents inventory - Simulator Object - Raises the event - - - - Remove an item from an objects (Prim) Inventory - - LocalID of the object in the simulator - UUID of the task item to remove - Simulator Object - You can confirm the removal by comparing the tasks inventory serial before and after the - request with the request combined with - the event - - - - Copy an InventoryScript item from the Agents Inventory into a primitives task inventory - - An unsigned integer representing a primitive being simulated - An which represents a script object from the agents inventory - true to set the scripts running state to enabled - A Unique Transaction ID - - The following example shows the basic steps necessary to copy a script from the agents inventory into a tasks inventory - and assumes the script exists in the agents inventory. - - uint primID = 95899503; // Fake prim ID - UUID scriptID = UUID.Parse("92a7fe8a-e949-dd39-a8d8-1681d8673232"); // Fake Script UUID in Inventory - - Client.Inventory.FolderContents(Client.Inventory.FindFolderForType(AssetType.LSLText), Client.Self.AgentID, - false, true, InventorySortOrder.ByName, 10000); - - Client.Inventory.RezScript(primID, (InventoryItem)Client.Inventory.Store[scriptID]); - - - - - - Request the running status of a script contained in a task (primitive) inventory - - The ID of the primitive containing the script - The ID of the script - The event can be used to obtain the results of the - request - - - - - Send a request to set the running state of a script contained in a task (primitive) inventory - - The ID of the primitive containing the script - The ID of the script - true to set the script running, false to stop a running script - To verify the change you can use the method combined - with the event - - - - Create a CRC from an InventoryItem - - The source InventoryItem - A uint representing the source InventoryItem as a CRC - - - - Reverses a cheesy XORing with a fixed UUID to convert a shadow_id to an asset_id - - Obfuscated shadow_id value - Deobfuscated asset_id value - - - - Does a cheesy XORing with a fixed UUID to convert an asset_id to a shadow_id - - asset_id value to obfuscate - Obfuscated shadow_id value - - - - Wrapper for creating a new object - - The type of item from the enum - The of the newly created object - An object with the type and id passed - - - - Parse the results of a RequestTaskInventory() response - - A string which contains the data from the task reply - A List containing the items contained within the tasks inventory - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - - - - UpdateCreateInventoryItem packets are received when a new inventory item - is created. This may occur when an object that's rezzed in world is - taken into inventory, when an item is created using the CreateInventoryItem - packet, or when an object is purchased - - The sender - The EventArgs object containing the packet data - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - - - Set to true to accept offer, false to decline it - - - The folder to accept the inventory into, if null default folder for will be used - - - - Callback when an inventory object is accepted and received from a - task inventory. This is the callback in which you actually get - the ItemID, as in ObjectOfferedCallback it is null when received - from a task. - - - - - - - User data - - - - - - - - - - - - - For inventory folder nodes specifies weather the folder needs to be - refreshed from the server - - - - - - - - De-serialization constructor for the InventoryNode Class - - - - - Serialization handler for the InventoryNode Class - - - - - De-serialization handler for the InventoryNode Class - - - - - Singleton logging class for the entire library - - - - - Callback used for client apps to receive log messages from - the library - - Data being logged - The severity of the log entry from - - - Triggered whenever a message is logged. If this is left - null, log messages will go to the console - - - log4net logging engine - - - - Default constructor - - - - - Send a log message to the logging engine - - The log message - The severity of the log entry - - - - Send a log message to the logging engine - - The log message - The severity of the log entry - Instance of the client - - - - Send a log message to the logging engine - - The log message - The severity of the log entry - Exception that was raised - - - - Send a log message to the logging engine - - The log message - The severity of the log entry - Instance of the client - Exception that was raised - - - - If the library is compiled with DEBUG defined, an event will be - fired if an OnLogMessage handler is registered and the - message will be sent to the logging engine - - The message to log at the DEBUG level to the - current logging engine - - - - If the library is compiled with DEBUG defined and - GridClient.Settings.DEBUG is true, an event will be - fired if an OnLogMessage handler is registered and the - message will be sent to the logging engine - - The message to log at the DEBUG level to the - current logging engine - Instance of the client - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Status of the last application run. - Used for error reporting to the grid login service for statistical purposes. - - - - Application exited normally - - - Application froze - - - Application detected error and exited abnormally - - - Other crash - - - Application froze during logout - - - Application crashed during logout - - - - Login Request Parameters - - - - The URL of the Login Server - - - The number of milliseconds to wait before a login is considered - failed due to timeout - - - The request method - login_to_simulator is currently the only supported method - - - The Agents First name - - - The Agents Last name - - - A md5 hashed password - plaintext password will be automatically hashed - - - The agents starting location home or last - Please use LoginLocation for custom region and Location - - - A string containing the client software channel information - Second Life Release - - - The client software version information - The official viewer uses: Second Life Release n.n.n.n - where n is replaced with the current version of the viewer - - - A string containing the platform information the agent is running on - - - A string containing version number for OS the agent is running on - - - A string hash of the network cards Mac Address - - - Unknown or deprecated - - - A string hash of the first disk drives ID used to identify this clients uniqueness - - - A string containing the viewers Software, this is not directly sent to the login server but - instead is used to generate the Version string - - - A string representing the software creator. This is not directly sent to the login server but - is used by the library to generate the Version information - - - If true, this agent agrees to the Terms of Service of the grid its connecting to - - - Unknown - - - Status of the last application run sent to the grid login server for statistical purposes - - - An array of string sent to the login server to enable various options - - - A randomly generated ID to distinguish between login attempts. This value is only used - internally in the library and is never sent over the wire - - - LoginLocation used to set the starting region and location (overrides Start) example: "Tentacles/128/64/109" - Leave empty to use the starting location - - - - Default constructor, initializes sane default values - - - - - Instantiates new LoginParams object and fills in the values - - Instance of GridClient to read settings from - Login first name - Login last name - Password - Login channel (application name) - Client version, should be application name + version number - - - - Instantiates new LoginParams object and fills in the values - - Instance of GridClient to read settings from - Login first name - Login last name - Password - Login channnel (application name) - Client version, should be application name + version number - URI of the login server - - - - The decoded data returned from the login server after a successful login - - - - true, false, indeterminate - - - Login message of the day - - - M or PG, also agent_region_access and agent_access_max - - - - Parse LLSD Login Reply Data - - An - containing the login response data - XML-RPC logins do not require this as XML-RPC.NET - automatically populates the struct properly using attributes - - - - Login Routines - - - NetworkManager is responsible for managing the network layer of - OpenMetaverse. It tracks all the server connections, serializes - outgoing traffic and deserializes incoming traffic, and provides - instances of delegates for network-related events. - - - - The event subscribers, null of no subscribers - - - Raises the LoginProgress Event - A LoginProgressEventArgs object containing - the data sent from the simulator - - - Thread sync lock object - - - Raised when the simulator sends us data containing - ... - - - - - - - - - - - - - Called when a reply is received from the login server, the - login sequence will block until this event returns - - - Seed CAPS URL returned from the login server - - - Current state of logging in - - - Upon login failure, contains a short string key for the - type of login error that occurred - - - The raw XML-RPC reply from the login server, exactly as it - was received (minus the HTTP header) - - - During login this contains a descriptive version of - LoginStatusCode. After a successful login this will contain the - message of the day, and after a failed login a descriptive error - message will be returned - - - Maximum number of groups an agent can belong to, -1 for unlimited - - - Server side baking service URL - - - Parsed login response data - - - A list of packets obtained during the login process which - networkmanager will log but not process - - - - Generate sane default values for a login request - - Account first name - Account last name - Account password - Client application name (channel) - Client application name + version - A populated struct containing - sane defaults - - - - Simplified login that takes the most common and required fields - - Account first name - Account last name - Account password - Client application name (channel) - Client application name + version - Whether the login was successful or not. On failure the - LoginErrorKey string will contain the error code and LoginMessage - will contain a description of the error - - - - Simplified login that takes the most common fields along with a - starting location URI, and can accept an MD5 string instead of a - plaintext password - - Account first name - Account last name - Account password or MD5 hash of the password - such as $1$1682a1e45e9f957dcdf0bb56eb43319c - Client application name (channel) - Starting location URI that can be built with - StartLocation() - Client application name + version - Whether the login was successful or not. On failure the - LoginErrorKey string will contain the error code and LoginMessage - will contain a description of the error - - - - Login that takes a struct of all the values that will be passed to - the login server - - The values that will be passed to the login - server, all fields must be set even if they are String.Empty - Whether the login was successful or not. On failure the - LoginErrorKey string will contain the error code and LoginMessage - will contain a description of the error - - - - Build a start location URI for passing to the Login function - - Name of the simulator to start in - X coordinate to start at - Y coordinate to start at - Z coordinate to start at - String with a URI that can be used to login to a specified - location - - - - LoginParams and the initial login XmlRpcRequest were made on a remote machine. - This method now initializes libomv with the results. - - - - - Handles response from XML-RPC login replies - - - - - Handles response from XML-RPC login replies with already parsed LoginResponseData - - - - - Handle response from LLSD login replies - - - - - - - - Get current OS - - Either "Win" or "Linux" - - - - Gets the current OS version number - - The platform version. - - - - Get clients default Mac Address - - A string containing the first found Mac Address - - - - MD5 hash of string - - String to hash - Hashed string - - - - Explains why a simulator or the grid disconnected from us - - - - The client requested the logout or simulator disconnect - - - The server notified us that it is disconnecting - - - Either a socket was closed or network traffic timed out - - - The last active simulator shut down - - - - Holds a simulator reference and a decoded packet, these structs are put in - the packet inbox for event handling - - - - Reference to the simulator that this packet came from - - - Packet that needs to be processed - - - - Holds a simulator reference and a serialized packet, these structs are put in - the packet outbox for sending - - - - Reference to the simulator this packet is destined for - - - Packet that needs to be sent - - - Sequence number of the wrapped packet - - - Number of times this packet has been resent - - - Environment.TickCount when this packet was last sent over the wire - - - Type of the packet - - - The event subscribers, null of no subscribers - - - Raises the PacketSent Event - A PacketSentEventArgs object containing - the data sent from the simulator - - - Thread sync lock object - - - Raised when the simulator sends us data containing - ... - - - The event subscribers, null of no subscribers - - - Raises the LoggedOut Event - A LoggedOutEventArgs object containing - the data sent from the simulator - - - Thread sync lock object - - - Raised when the simulator sends us data containing - ... - - - The event subscribers, null of no subscribers - - - Raises the SimConnecting Event - A SimConnectingEventArgs object containing - the data sent from the simulator - - - Thread sync lock object - - - Raised when the simulator sends us data containing - ... - - - The event subscribers, null of no subscribers - - - Raises the SimConnected Event - A SimConnectedEventArgs object containing - the data sent from the simulator - - - Thread sync lock object - - - Raised when the simulator sends us data containing - ... - - - The event subscribers, null of no subscribers - - - Raises the SimDisconnected Event - A SimDisconnectedEventArgs object containing - the data sent from the simulator - - - Thread sync lock object - - - Raised when the simulator sends us data containing - ... - - - The event subscribers, null of no subscribers - - - Raises the Disconnected Event - A DisconnectedEventArgs object containing - the data sent from the simulator - - - Thread sync lock object - - - Raised when the simulator sends us data containing - ... - - - The event subscribers, null of no subscribers - - - Raises the SimChanged Event - A SimChangedEventArgs object containing - the data sent from the simulator - - - Thread sync lock object - - - Raised when the simulator sends us data containing - ... - - - The event subscribers, null of no subscribers - - - Raises the EventQueueRunning Event - A EventQueueRunningEventArgs object containing - the data sent from the simulator - - - Thread sync lock object - - - Raised when the simulator sends us data containing - ... - - - Unique identifier associated with our connections to - simulators - - - The simulator that the logged in avatar is currently - occupying - - - Shows whether the network layer is logged in to the - grid or not - - - Number of packets in the incoming queue - - - Number of packets in the outgoing queue - - - All of the simulators we are currently connected to - - - Handlers for incoming capability events - - - Handlers for incoming packets - - - Incoming packets that are awaiting handling - - - Outgoing packets that are awaiting handling - - - - Default constructor - - Reference to the GridClient object - - - - Register an event handler for a packet. This is a low level event - interface and should only be used if you are doing something not - supported in the library - - Packet type to trigger events for - Callback to fire when a packet of this type - is received - - - - Register an event handler for a packet. This is a low level event - interface and should only be used if you are doing something not - supported in the library - - Packet type to trigger events for - Callback to fire when a packet of this type - is received - True if the callback should be ran - asynchronously. Only set this to false (synchronous for callbacks - that will always complete quickly) - If any callback for a packet type is marked as - asynchronous, all callbacks for that packet type will be fired - asynchronously - - - - Unregister an event handler for a packet. This is a low level event - interface and should only be used if you are doing something not - supported in the library - - Packet type this callback is registered with - Callback to stop firing events for - - - - Register a CAPS event handler. This is a low level event interface - and should only be used if you are doing something not supported in - the library - - Name of the CAPS event to register a handler for - Callback to fire when a CAPS event is received - - - - Unregister a CAPS event handler. This is a low level event interface - and should only be used if you are doing something not supported in - the library - - Name of the CAPS event this callback is - registered with - Callback to stop firing events for - - - - Send a packet to the simulator the avatar is currently occupying - - Packet to send - - - - Send a packet to a specified simulator - - Packet to send - Simulator to send the packet to - - - - Add a packet to the Inbox queue to process - - Incoming packet to process - - - - adds a debug message when you try to access a network item - while they are still null - - what - where - - - - Add a packet to the Inbox queue to process - - Incoming packet to process - - - - Connect to a simulator - - IP address to connect to - Port to connect to - Handle for this simulator, to identify its - location in the grid - Whether to set CurrentSim to this new - connection, use this if the avatar is moving in to this simulator - URL of the capabilities server to use for - this sim connection - A Simulator object on success, otherwise null - - - - Connect to a simulator - - IP address and port to connect to - Handle for this simulator, to identify its - location in the grid - Whether to set CurrentSim to this new - connection, use this if the avatar is moving in to this simulator - URL of the capabilities server to use for - this sim connection - A Simulator object on success, otherwise null - - - - Begins the non-blocking logout. Makes sure that the LoggedOut event is - called even if the server does not send a logout reply, and Shutdown() - is properly called. - - - - - Initiate a blocking logout request. This will return when the logout - handshake has completed or when Settings.LOGOUT_TIMEOUT - has expired and the network layer is manually shut down - - - - - Initiate the logout process. The Shutdown() function - needs to be manually called. - - - - - Close a connection to the given simulator - - - - - - - Shutdown will disconnect all the sims except for the current sim - first, and then kill the connection to CurrentSim. This should only - be called if the logout process times out on RequestLogout - - Type of shutdown - - - - Shutdown will disconnect all the sims except for the current sim - first, and then kill the connection to CurrentSim. This should only - be called if the logout process times out on RequestLogout - - Type of shutdown - Shutdown message - - - - Searches through the list of currently connected simulators to find - one attached to the given IPEndPoint - - IPEndPoint of the Simulator to search for - A Simulator reference on success, otherwise null - - - - Fire an event when an event queue connects for capabilities - - Simulator the event queue is attached to - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - - - - Sent to the client to indicate a teleport request has completed - - - - The of the agent - - - - - - The simulators handle the agent teleported to - - - A Uri which contains a list of Capabilities the simulator supports - - - Indicates the level of access required - to access the simulator, or the content rating, or the simulators - map status - - - The IP Address of the simulator - - - The UDP Port the simulator will listen for UDP traffic on - - - Status flags indicating the state of the Agent upon arrival, Flying, etc. - - - - Serialize the object - - An containing the objects data - - - - Deserialize the message - - An containing the data - - - - Sent to the viewer when a neighboring simulator is requesting the agent make a connection to it. - - - - - Serialize the object - - An containing the objects data - - - - Deserialize the message - - An containing the data - - - - Serialize the object - - An containing the objects data - - - - Deserialize the message - - An containing the data - - - - Serialize the object - - An containing the objects data - - - - Deserialize the message - - An containing the data - - - - A message sent to the client which indicates a teleport request has failed - and contains some information on why it failed - - - - - - - A string key of the reason the teleport failed e.g. CouldntTPCloser - Which could be used to look up a value in a dictionary or enum - - - The of the Agent - - - A string human readable message containing the reason - An example: Could not teleport closer to destination - - - - Serialize the object - - An containing the objects data - - - - Deserialize the message - - An containing the data - - - - Serialize the object - - An containing the objects data - - - - Deserialize the message - - An containing the data - - - - Contains a list of prim owner information for a specific parcel in a simulator - - - A Simulator will always return at least 1 entry - If agent does not have proper permission the OwnerID will be UUID.Zero - If agent does not have proper permission OR there are no primitives on parcel - the DataBlocksExtended map will not be sent from the simulator - - - - - Prim ownership information for a specified owner on a single parcel - - - - The of the prim owner, - UUID.Zero if agent has no permission to view prim owner information - - - The total number of prims - - - True if the OwnerID is a - - - True if the owner is online - This is no longer used by the LL Simulators - - - The date the most recent prim was rezzed - - - An Array of objects - - - - Serialize the object - - An containing the objects data - - - - Deserialize the message - - An containing the data - - - - The details of a single parcel in a region, also contains some regionwide globals - - - - Simulator-local ID of this parcel - - - Maximum corner of the axis-aligned bounding box for this - parcel - - - Minimum corner of the axis-aligned bounding box for this - parcel - - - Total parcel land area - - - - - - Key of authorized buyer - - - Bitmap describing land layout in 4x4m squares across the - entire region - - - - - - Date land was claimed - - - Appears to always be zero - - - Parcel Description - - - - - - - - - Total number of primitives owned by the parcel group on - this parcel - - - Whether the land is deeded to a group or not - - - - - - Maximum number of primitives this parcel supports - - - The Asset UUID of the Texture which when applied to a - primitive will display the media - - - A URL which points to any Quicktime supported media type - - - A byte, if 0x1 viewer should auto scale media to fit object - - - URL For Music Stream - - - Parcel Name - - - Autoreturn value in minutes for others' objects - - - - - - Total number of other primitives on this parcel - - - UUID of the owner of this parcel - - - Total number of primitives owned by the parcel owner on - this parcel - - - - - - How long is pass valid for - - - Price for a temporary pass - - - - - - Disallows people outside the parcel from being able to see in - - - - - - - - - - - - True if the region denies access to age unverified users - - - - - - This field is no longer used - - - The result of a request for parcel properties - - - Sale price of the parcel, only useful if ForSale is set - The SalePrice will remain the same after an ownership - transfer (sale), so it can be used to see the purchase price after - a sale if the new owner has not changed it - - - - Number of primitives your avatar is currently - selecting and sitting on in this parcel - - - - - - - - A number which increments by 1, starting at 0 for each ParcelProperties request. - Can be overriden by specifying the sequenceID with the ParcelPropertiesRequest being sent. - a Negative number indicates the action in has occurred. - - - - Maximum primitives across the entire simulator - - - Total primitives across the entire simulator - - - - - - Key of parcel snapshot - - - Parcel ownership status - - - Total number of primitives on this parcel - - - - - - - - - A description of the media - - - An Integer which represents the height of the media - - - An integer which represents the width of the media - - - A boolean, if true the viewer should loop the media - - - A string which contains the mime type of the media - - - true to obscure (hide) media url - - - true to obscure (hide) music url - - - true if avatars in this parcel should be invisible to people outside - - - true if avatars outside can hear any sounds avatars inside play - - - true if group members outside can hear any sounds avatars inside play - - - - Serialize the object - - An containing the objects data - - - - Deserialize the message - - An containing the data - - - A message sent from the viewer to the simulator to updated a specific parcels settings - - - The of the agent authorized to purchase this - parcel of land or a NULL if the sale is authorized to anyone - - - true to enable auto scaling of the parcel media - - - The category of this parcel used when search is enabled to restrict - search results - - - A string containing the description to set - - - The of the which allows for additional - powers and restrictions. - - - The which specifies how avatars which teleport - to this parcel are handled - - - The LocalID of the parcel to update settings on - - - A string containing the description of the media which can be played - to visitors - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - true if avatars in this parcel should be invisible to people outside - - - true if avatars outside can hear any sounds avatars inside play - - - true if group members outside can hear any sounds avatars inside play - - - - Deserialize the message - - An containing the data - - - - Serialize the object - - An containing the objects data - - - Base class used for the RemoteParcelRequest message - - - - A message sent from the viewer to the simulator to request information - on a remote parcel - - - - Local sim position of the parcel we are looking up - - - Region handle of the parcel we are looking up - - - Region of the parcel we are looking up - - - - Serialize the object - - An containing the objects data - - - - Deserialize the message - - An containing the data - - - - A message sent from the simulator to the viewer in response to a - which will contain parcel information - - - - The grid-wide unique parcel ID - - - - Serialize the object - - An containing the objects data - - - - Deserialize the message - - An containing the data - - - - A message containing a request for a remote parcel from a viewer, or a response - from the simulator to that request - - - - The request or response details block - - - - Serialize the object - - An containing the objects data - - - - Deserialize the message - - An containing the data - - - - Serialize the object - - An containing the objects data - - - - Deserialize the message - - An containing the data - - - - Serialize the object - - An containing the objects data - - - - Deserialize the message - - An containing the data - - - - A message sent from the simulator to an agent which contains - the groups the agent is in - - - - The Agent receiving the message - - - Group Details specific to the agent - - - true of the agent accepts group notices - - - The agents tier contribution to the group - - - The Groups - - - The of the groups insignia - - - The name of the group - - - The aggregate permissions the agent has in the group for all roles the agent - is assigned - - - An optional block containing additional agent specific information - - - true of the agent allows this group to be - listed in their profile - - - An array containing information - for each the agent is a member of - - - An array containing information - for each the agent is a member of - - - - Serialize the object - - An containing the objects data - - - - Deserialize the message - - An containing the data - - - - A message sent from the viewer to the simulator which - specifies the language and permissions for others to detect - the language specified - - - - A string containng the default language - to use for the agent - - - true of others are allowed to - know the language setting - - - - Serialize the object - - An containing the objects data - - - - Deserialize the message - - An containing the data - - - - An EventQueue message sent from the simulator to an agent when the agent - leaves a group - - - - An object containing the Agents UUID, and the Groups UUID - - - The ID of the Agent leaving the group - - - The GroupID the Agent is leaving - - - - An Array containing the AgentID and GroupID - - - - - Serialize the object - - An containing the objects data - - - - Deserialize the message - - An containing the data - - - Base class for Asset uploads/results via Capabilities - - - - The request state - - - - - Serialize the object - - An containing the objects data - - - - Deserialize the message - - An containing the data - - - - A message sent from the viewer to the simulator to request a temporary upload capability - which allows an asset to be uploaded - - - - The Capability URL sent by the simulator to upload the baked texture to - - - - A message sent from the simulator that will inform the agent the upload is complete, - and the UUID of the uploaded asset - - - - The uploaded texture asset ID - - - - A message sent from the viewer to the simulator to request a temporary - capability URI which is used to upload an agents baked appearance textures - - - - Object containing request or response - - - - Serialize the object - - An containing the objects data - - - - Deserialize the message - - An containing the data - - - - A message sent from the simulator which indicates the minimum version required for - using voice chat - - - - Major Version Required - - - Minor version required - - - The name of the region sending the version requrements - - - - Serialize the object - - An containing the objects data - - - - Deserialize the message - - An containing the data - - - - A message sent from the simulator to the viewer containing the - voice server URI - - - - The Parcel ID which the voice server URI applies - - - The name of the region - - - A uri containing the server/channel information - which the viewer can utilize to participate in voice conversations - - - - Serialize the object - - An containing the objects data - - - - Deserialize the message - - An containing the data - - - - - - - - - - - - - - - Serialize the object - - An containing the objects data - - - - Deserialize the message - - An containing the data - - - - A message sent by the viewer to the simulator to request a temporary - capability for a script contained with in a Tasks inventory to be updated - - - - Object containing request or response - - - - Serialize the object - - An containing the objects data - - - - Deserialize the message - - An containing the data - - - - A message sent from the simulator to the viewer to indicate - a Tasks scripts status. - - - - The Asset ID of the script - - - True of the script is compiled/ran using the mono interpreter, false indicates it - uses the older less efficient lsl2 interprter - - - The Task containing the scripts - - - true of the script is in a running state - - - - Serialize the object - - An containing the objects data - - - - Deserialize the message - - An containing the data - - - - A message containing the request/response used for updating a gesture - contained with an agents inventory - - - - Object containing request or response - - - - Serialize the object - - An containing the objects data - - - - Deserialize the message - - An containing the data - - - - A message request/response which is used to update a notecard contained within - a tasks inventory - - - - The of the Task containing the notecard asset to update - - - The notecard assets contained in the tasks inventory - - - - Serialize the object - - An containing the objects data - - - - Deserialize the message - - An containing the data - - - - A reusable class containing a message sent from the viewer to the simulator to request a temporary uploader capability - which is used to update an asset in an agents inventory - - - - - The Notecard AssetID to replace - - - - - Serialize the object - - An containing the objects data - - - - Deserialize the message - - An containing the data - - - - A message containing the request/response used for updating a notecard - contained with an agents inventory - - - - Object containing request or response - - - - Serialize the object - - An containing the objects data - - - - Deserialize the message - - An containing the data - - - - Serialize the object - - An containing the objects data - - - - Deserialize the message - - An containing the data - - - - A message sent from the simulator to the viewer which indicates - an error occurred while attempting to update a script in an agents or tasks - inventory - - - - true of the script was successfully compiled by the simulator - - - A string containing the error which occured while trying - to update the script - - - A new AssetID assigned to the script - - - - A message sent from the viewer to the simulator - requesting the update of an existing script contained - within a tasks inventory - - - - if true, set the script mode to running - - - The scripts InventoryItem ItemID to update - - - A lowercase string containing either "mono" or "lsl2" which - specifies the script is compiled and ran on the mono runtime, or the older - lsl runtime - - - The tasks which contains the script to update - - - - Serialize the object - - An containing the objects data - - - - Deserialize the message - - An containing the data - - - - A message containing either the request or response used in updating a script inside - a tasks inventory - - - - Object containing request or response - - - - Serialize the object - - An containing the objects data - - - - Deserialize the message - - An containing the data - - - - Response from the simulator to notify the viewer the upload is completed, and - the UUID of the script asset and its compiled status - - - - The uploaded texture asset ID - - - true of the script was compiled successfully - - - - A message sent from a viewer to the simulator requesting a temporary uploader capability - used to update a script contained in an agents inventory - - - - The existing asset if of the script in the agents inventory to replace - - - The language of the script - Defaults to lsl version 2, "mono" might be another possible option - - - - Serialize the object - - An containing the objects data - - - - Deserialize the message - - An containing the data - - - - A message containing either the request or response used in updating a script inside - an agents inventory - - - - Object containing request or response - - - - Serialize the object - - An containing the objects data - - - - Deserialize the message - - An containing the data - - - - Serialize the object - - An containing the objects data - - - - Deserialize the message - - An containing the data - - - Base class for Map Layers via Capabilities - - - - - - - Serialize the object - - An containing the objects data - - - - Deserialize the message - - An containing the data - - - - Sent by an agent to the capabilities server to request map layers - - - - - A message sent from the simulator to the viewer which contains an array of map images and their grid coordinates - - - - - An object containing map location details - - - - The Asset ID of the regions tile overlay - - - The grid location of the southern border of the map tile - - - The grid location of the western border of the map tile - - - The grid location of the eastern border of the map tile - - - The grid location of the northern border of the map tile - - - An array containing LayerData items - - - - Serialize the object - - An containing the objects data - - - - Deserialize the message - - An containing the data - - - Object containing request or response - - - - Serialize the object - - An containing the objects data - - - - Deserialize the message - - An containing the data - - - - New as of 1.23 RC1, no details yet. - - - - - Serialize the object - - An containing the objects data - - - - Deserialize the message - - An containing the data - - - - Serialize the object - - An containing the objects data - - - - Deserialize the message - - An containing the data - - - A string containing the method used - - - - A request sent from an agent to the Simulator to begin a new conference. - Contains a list of Agents which will be included in the conference - - - - An array containing the of the agents invited to this conference - - - The conferences Session ID - - - - Serialize the object - - An containing the objects data - - - - Deserialize the message - - An containing the data - - - - A moderation request sent from a conference moderator - Contains an agent and an optional action to take - - - - The Session ID - - - - - - A list containing Key/Value pairs, known valid values: - key: text value: true/false - allow/disallow specified agents ability to use text in session - key: voice value: true/false - allow/disallow specified agents ability to use voice in session - - "text" or "voice" - - - - - - - Serialize the object - - An containing the objects data - - - - Deserialize the message - - An containing the data - - - - A message sent from the agent to the simulator which tells the - simulator we've accepted a conference invitation - - - - The conference SessionID - - - - Serialize the object - - An containing the objects data - - - - Deserialize the message - - An containing the data - - - - Serialize the object - - An containing the objects data - - - - Deserialize the message - - An containing the data - - - - Serialize the object - - An containing the objects data - - - - Deserialize the message - - An containing the data - - - - Serialize the object - - An containing the objects data - - - - Deserialize the message - - An containing the data - - - Key of sender - - - Name of sender - - - Key of destination avatar - - - ID of originating estate - - - Key of originating region - - - Coordinates in originating region - - - Instant message type - - - Group IM session toggle - - - Key of IM session, for Group Messages, the groups UUID - - - Timestamp of the instant message - - - Instant message text - - - Whether this message is held for offline avatars - - - Context specific packed data - - - Is this invitation for voice group/conference chat - - - - Serialize the object - - An containing the objects data - - - - Deserialize the message - - An containing the data - - - - Sent from the simulator to the viewer. - - When an agent initially joins a session the AgentUpdatesBlock object will contain a list of session members including - a boolean indicating they can use voice chat in this session, a boolean indicating they are allowed to moderate - this session, and lastly a string which indicates another agent is entering the session with the Transition set to "ENTER" - - During the session lifetime updates on individuals are sent. During the update the booleans sent during the initial join are - excluded with the exception of the Transition field. This indicates a new user entering or exiting the session with - the string "ENTER" or "LEAVE" respectively. - - - - - Serialize the object - - An containing the objects data - - - - Deserialize the message - - An containing the data - - - - An EventQueue message sent when the agent is forcibly removed from a chatterbox session - - - - - A string containing the reason the agent was removed - - - - - The ChatterBoxSession's SessionID - - - - - Serialize the object - - An containing the objects data - - - - Deserialize the message - - An containing the data - - - - Serialize the object - - An containing the objects data - - - - Deserialize the message - - An containing the data - - - - Serialize the object - - An containing the objects data - - - - Deserialize the message - - An containing the data - - - - Serialize the object - - An containing the objects data - - - - Deserialize the message - - An containing the data - - - - Serialize the object - - An containing the objects data - - - - Deserialize the message - - An containing the data - - - - - - - - - Serialize the object - - An containing the objects data - - - - Deserialize the message - - An containing the data - - - - Serialize the object - - An containing the objects data - - - - Deserialize the message - - An containing the data - - - - Serialize the object - - An containing the objects data - - - - Deserialize the message - - An containing the data - - - - Event Queue message describing physics engine attributes of a list of objects - Sim sends these when object is selected - - - - Array with the list of physics properties - - - - Serializes the message - - Serialized OSD - - - - Deserializes the message - - Incoming data to deserialize - - - - Deserializes the message - - Incoming data to deserialize - - - - Serializes the message - - Serialized OSD - - - Object IDs for which to request cost information - - - - Deserializes the message - - Incoming data to deserialize - - - - Serializes the message - - Serialized OSD - - - - Deserializes the message - - Incoming data to deserialize - - - - Serializes the message - - Serialized OSD - - - - Detects which class handles deserialization of this message - - An containing the data - Object capable of decoding this message - - - - A message sent from the viewer to the simulator which - specifies that the user has changed current URL - of the specific media on a prim face - - - - - New URL - - - - - Prim UUID where navigation occured - - - - - Face index - - - - - Serialize the object - - An containing the objects data - - - - Deserialize the message - - An containing the data - - - Base class used for the ObjectMedia message - - - - Message used to retrive prim media data - - - - - Prim UUID - - - - - Requested operation, either GET or UPDATE - - - - - Serialize object - - Serialized object as OSDMap - - - - Deserialize the message - - An containing the data - - - - Message used to update prim media data - - - - - Prim UUID - - - - - Array of media entries indexed by face number - - - - - Media version string - - - - - Serialize object - - Serialized object as OSDMap - - - - Deserialize the message - - An containing the data - - - - Message used to update prim media data - - - - - Prim UUID - - - - - Array of media entries indexed by face number - - - - - Requested operation, either GET or UPDATE - - - - - Serialize object - - Serialized object as OSDMap - - - - Deserialize the message - - An containing the data - - - - Message for setting or getting per face MediaEntry - - - - The request or response details block - - - - Serialize the object - - An containing the objects data - - - - Deserialize the message - - An containing the data - - - Details about object resource usage - - - Object UUID - - - Object name - - - Indicates if object is group owned - - - Locatio of the object - - - Object owner - - - Resource usage, keys are resource names, values are resource usage for that specific resource - - - - Deserializes object from OSD - - An containing the data - - - - Makes an instance based on deserialized data - - serialized data - Instance containg deserialized data - - - Details about parcel resource usage - - - Parcel UUID - - - Parcel local ID - - - Parcel name - - - Indicates if parcel is group owned - - - Parcel owner - - - Array of containing per object resource usage - - - - Deserializes object from OSD - - An containing the data - - - - Makes an instance based on deserialized data - - serialized data - Instance containg deserialized data - - - Resource usage base class, both agent and parcel resource - usage contains summary information - - - Summary of available resources, keys are resource names, - values are resource usage for that specific resource - - - Summary resource usage, keys are resource names, - values are resource usage for that specific resource - - - - Serializes object - - serialized data - - - - Deserializes object from OSD - - An containing the data - - - Agent resource usage - - - Per attachment point object resource usage - - - - Deserializes object from OSD - - An containing the data - - - - Makes an instance based on deserialized data - - serialized data - Instance containg deserialized data - - - - Detects which class handles deserialization of this message - - An containing the data - Object capable of decoding this message - - - Request message for parcel resource usage - - - UUID of the parel to request resource usage info - - - - Serializes object - - serialized data - - - - Deserializes object from OSD - - An containing the data - - - Response message for parcel resource usage - - - URL where parcel resource usage details can be retrieved - - - URL where parcel resource usage summary can be retrieved - - - - Serializes object - - serialized data - - - - Deserializes object from OSD - - An containing the data - - - - Detects which class handles deserialization of this message - - An containing the data - Object capable of decoding this message - - - Parcel resource usage - - - Array of containing per percal resource usage - - - - Deserializes object from OSD - - An containing the data - - - - Reply to request for bunch if display names - - - - Current display name - - - Following UUIDs failed to return a valid display name - - - - Serializes the message - - OSD containting the messaage - - - - Message sent when requesting change of the display name - - - - Current display name - - - Desired new display name - - - - Serializes the message - - OSD containting the messaage - - - - Message recieved in response to request to change display name - - - - New display name - - - String message indicating the result of the operation - - - Numerical code of the result, 200 indicates success - - - - Serializes the message - - OSD containting the messaage - - - - Message recieved when someone nearby changes their display name - - - - Previous display name, empty string if default - - - New display name - - - - Serializes the message - - OSD containting the messaage - - - - Return a decoded capabilities message as a strongly typed object - - A string containing the name of the capabilities message key - An to decode - A strongly typed object containing the decoded information from the capabilities message, or null - if no existing Message object exists for the specified event - - - - A Name Value pair with additional settings, used in the protocol - primarily to transmit avatar names and active group in object packets - - - - Type of the value - - - Unknown - - - String value - - - - - - - - - - - - - - - Deprecated - - - String value, but designated as an asset - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Constructor that takes all the fields as parameters - - - - - - - - - - Constructor that takes a single line from a NameValue field - - - - - - - - - - No report - - - Unknown report type - - - Bug report - - - Complaint report - - - Customer service report - - - - Bitflag field for ObjectUpdateCompressed data blocks, describing - which options are present for each object - - - - Unknown - - - Whether the object has a TreeSpecies - - - Whether the object has floating text ala llSetText - - - Whether the object has an active particle system - - - Whether the object has sound attached to it - - - Whether the object is attached to a root object or not - - - Whether the object has texture animation settings - - - Whether the object has an angular velocity - - - Whether the object has a name value pairs string - - - Whether the object has a Media URL set - - - Whether the object has, you guessed it, new particles - - - - Specific Flags for MultipleObjectUpdate requests - - - - None - - - Change position of prims - - - Change rotation of prims - - - Change size of prims - - - Perform operation on link set - - - Scale prims uniformly, same as selecing ctrl+shift in the - viewer. Used in conjunction with Scale - - - - Special values in PayPriceReply. If the price is not one of these - literal value of the price should be use - - - - - Indicates that this pay option should be hidden - - - - - Indicates that this pay option should have the default value - - - - - Contains the variables sent in an object update packet for objects. - Used to track position and movement of prims and avatars - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Handles all network traffic related to prims and avatar positions and - movement. - - - - The event subscribers, null of no subscribers - - - Thread sync lock object - - - Raised when the simulator sends us data containing - A , Foliage or Attachment - - - - - The event subscribers, null of no subscribers - - - Raises the ObjectProperties Event - A ObjectPropertiesEventArgs object containing - the data sent from the simulator - - - Thread sync lock object - - - Raised when the simulator sends us data containing - additional information - - - - - The event subscribers, null of no subscribers - - - Raises the ObjectPropertiesUpdated Event - A ObjectPropertiesUpdatedEventArgs object containing - the data sent from the simulator - - - Thread sync lock object - - - Raised when the simulator sends us data containing - Primitive.ObjectProperties for an object we are currently tracking - - - The event subscribers, null of no subscribers - - - Raises the ObjectPropertiesFamily Event - A ObjectPropertiesFamilyEventArgs object containing - the data sent from the simulator - - - Thread sync lock object - - - Raised when the simulator sends us data containing - additional and details - - - - The event subscribers, null of no subscribers - - - Raises the AvatarUpdate Event - A AvatarUpdateEventArgs object containing - the data sent from the simulator - - - - Raises the ParticleUpdate Event - - A ParticleUpdateEventArgs object containing - the data sent from the simulator - - - Thread sync lock object - - - Raised when the simulator sends us data containing - updated information for an - - - The event subscribers, null of no subscribers - - - Thread sync lock object - - - Raised when the simulator sends us data containing - and movement changes - - - The event subscribers, null of no subscribers - - - Raises the ObjectDataBlockUpdate Event - A ObjectDataBlockUpdateEventArgs object containing - the data sent from the simulator - - - Thread sync lock object - - - Raised when the simulator sends us data containing - updates to an Objects DataBlock - - - The event subscribers, null of no subscribers - - - Raises the KillObject Event - A KillObjectEventArgs object containing - the data sent from the simulator - - - Thread sync lock object - - - Raised when the simulator informs us an - or is no longer within view - - - The event subscribers, null of no subscribers - - - Raises the KillObjects Event - A KillObjectsEventArgs object containing - the data sent from the simulator - - - Thread sync lock object - - - Raised when the simulator informs us when a group of - or is no longer within view - - - The event subscribers, null of no subscribers - - - Raises the AvatarSitChanged Event - A AvatarSitChangedEventArgs object containing - the data sent from the simulator - - - Thread sync lock object - - - Raised when the simulator sends us data containing - updated sit information for our - - - The event subscribers, null of no subscribers - - - Raises the PayPriceReply Event - A PayPriceReplyEventArgs object containing - the data sent from the simulator - - - Thread sync lock object - - - Raised when the simulator sends us data containing - purchase price information for a - - - - Callback for getting object media data via CAP - - Indicates if the operation was succesfull - Object media version string - Array indexed on prim face of media entry data - - - The event subscribers, null of no subscribers - - - Raises the PhysicsProperties Event - A PhysicsPropertiesEventArgs object containing - the data sent from the simulator - - - Thread sync lock object - - - Raised when the simulator sends us data containing - additional information - - - - - Reference to the GridClient object - - - Does periodic dead reckoning calculation to convert - velocity and acceleration to new positions for objects - - - - Construct a new instance of the ObjectManager class - - A reference to the instance - - - - Request information for a single object from a - you are currently connected to - - The the object is located - The Local ID of the object - - - - Request information for multiple objects contained in - the same simulator - - The the objects are located - An array containing the Local IDs of the objects - - - - Attempt to purchase an original object, a copy, or the contents of - an object - - The the object is located - The Local ID of the object - Whether the original, a copy, or the object - contents are on sale. This is used for verification, if the this - sale type is not valid for the object the purchase will fail - Price of the object. This is used for - verification, if it does not match the actual price the purchase - will fail - Group ID that will be associated with the new - purchase - Inventory folder UUID where the object or objects - purchased should be placed - - - BuyObject(Client.Network.CurrentSim, 500, SaleType.Copy, - 100, UUID.Zero, Client.Self.InventoryRootFolderUUID); - - - - - - Request prices that should be displayed in pay dialog. This will triggger the simulator - to send us back a PayPriceReply which can be handled by OnPayPriceReply event - - The the object is located - The ID of the object - The result is raised in the event - - - - Select a single object. This will cause the to send us - an which will raise the event - - The the object is located - The Local ID of the object - - - - - Select a single object. This will cause the to send us - an which will raise the event - - The the object is located - The Local ID of the object - if true, a call to is - made immediately following the request - - - - - Select multiple objects. This will cause the to send us - an which will raise the event - - The the objects are located - An array containing the Local IDs of the objects - Should objects be deselected immediately after selection - - - - - Select multiple objects. This will cause the to send us - an which will raise the event - - The the objects are located - An array containing the Local IDs of the objects - - - - - Update the properties of an object - - The the object is located - The Local ID of the object - true to turn the objects physical property on - true to turn the objects temporary property on - true to turn the objects phantom property on - true to turn the objects cast shadows property on - - - - Update the properties of an object - - The the object is located - The Local ID of the object - true to turn the objects physical property on - true to turn the objects temporary property on - true to turn the objects phantom property on - true to turn the objects cast shadows property on - Type of the represetnation prim will have in the physics engine - Density - normal value 1000 - Friction - normal value 0.6 - Restitution - standard value 0.5 - Gravity multiplier - standar value 1.0 - - - - Sets the sale properties of a single object - - The the object is located - The Local ID of the object - One of the options from the enum - The price of the object - - - - Sets the sale properties of multiple objects - - The the objects are located - An array containing the Local IDs of the objects - One of the options from the enum - The price of the object - - - - Deselect a single object - - The the object is located - The Local ID of the object - - - - Deselect multiple objects. - - The the objects are located - An array containing the Local IDs of the objects - - - - Perform a click action on an object - - The the object is located - The Local ID of the object - - - - Perform a click action (Grab) on a single object - - The the object is located - The Local ID of the object - The texture coordinates to touch - The surface coordinates to touch - The face of the position to touch - The region coordinates of the position to touch - The surface normal of the position to touch (A normal is a vector perpindicular to the surface) - The surface binormal of the position to touch (A binormal is a vector tangen to the surface - pointing along the U direction of the tangent space - - - - Create (rez) a new prim object in a simulator - - A reference to the object to place the object in - Data describing the prim object to rez - Group ID that this prim will be set to, or UUID.Zero if you - do not want the object to be associated with a specific group - An approximation of the position at which to rez the prim - Scale vector to size this prim - Rotation quaternion to rotate this prim - Due to the way client prim rezzing is done on the server, - the requested position for an object is only close to where the prim - actually ends up. If you desire exact placement you'll need to - follow up by moving the object after it has been created. This - function will not set textures, light and flexible data, or other - extended primitive properties - - - - Create (rez) a new prim object in a simulator - - A reference to the object to place the object in - Data describing the prim object to rez - Group ID that this prim will be set to, or UUID.Zero if you - do not want the object to be associated with a specific group - An approximation of the position at which to rez the prim - Scale vector to size this prim - Rotation quaternion to rotate this prim - Specify the - Due to the way client prim rezzing is done on the server, - the requested position for an object is only close to where the prim - actually ends up. If you desire exact placement you'll need to - follow up by moving the object after it has been created. This - function will not set textures, light and flexible data, or other - extended primitive properties - - - - Rez a Linden tree - - A reference to the object where the object resides - The size of the tree - The rotation of the tree - The position of the tree - The Type of tree - The of the group to set the tree to, - or UUID.Zero if no group is to be set - true to use the "new" Linden trees, false to use the old - - - - Rez grass and ground cover - - A reference to the object where the object resides - The size of the grass - The rotation of the grass - The position of the grass - The type of grass from the enum - The of the group to set the tree to, - or UUID.Zero if no group is to be set - - - - Set the textures to apply to the faces of an object - - A reference to the object where the object resides - The objects ID which is local to the simulator the object is in - The texture data to apply - - - - Set the textures to apply to the faces of an object - - A reference to the object where the object resides - The objects ID which is local to the simulator the object is in - The texture data to apply - A media URL (not used) - - - - Set the Light data on an object - - A reference to the object where the object resides - The objects ID which is local to the simulator the object is in - A object containing the data to set - - - - Set the flexible data on an object - - A reference to the object where the object resides - The objects ID which is local to the simulator the object is in - A object containing the data to set - - - - Set the sculptie texture and data on an object - - A reference to the object where the object resides - The objects ID which is local to the simulator the object is in - A object containing the data to set - - - - Unset additional primitive parameters on an object - - A reference to the object where the object resides - The objects ID which is local to the simulator the object is in - The extra parameters to set - - - - Link multiple prims into a linkset - - A reference to the object where the objects reside - An array which contains the IDs of the objects to link - The last object in the array will be the root object of the linkset TODO: Is this true? - - - - Delink/Unlink multiple prims from a linkset - - A reference to the object where the objects reside - An array which contains the IDs of the objects to delink - - - - Change the rotation of an object - - A reference to the object where the object resides - The objects ID which is local to the simulator the object is in - The new rotation of the object - - - - Set the name of an object - - A reference to the object where the object resides - The objects ID which is local to the simulator the object is in - A string containing the new name of the object - - - - Set the name of multiple objects - - A reference to the object where the objects reside - An array which contains the IDs of the objects to change the name of - An array which contains the new names of the objects - - - - Set the description of an object - - A reference to the object where the object resides - The objects ID which is local to the simulator the object is in - A string containing the new description of the object - - - - Set the descriptions of multiple objects - - A reference to the object where the objects reside - An array which contains the IDs of the objects to change the description of - An array which contains the new descriptions of the objects - - - - Attach an object to this avatar - - A reference to the object where the object resides - The objects ID which is local to the simulator the object is in - The point on the avatar the object will be attached - The rotation of the attached object - - - - Drop an attached object from this avatar - - A reference to the - object where the objects reside. This will always be the simulator the avatar is currently in - - The object's ID which is local to the simulator the object is in - - - - Detach an object from yourself - - A reference to the - object where the objects reside - - This will always be the simulator the avatar is currently in - - An array which contains the IDs of the objects to detach - - - - Change the position of an object, Will change position of entire linkset - - A reference to the object where the object resides - The objects ID which is local to the simulator the object is in - The new position of the object - - - - Change the position of an object - - A reference to the object where the object resides - The objects ID which is local to the simulator the object is in - The new position of the object - if true, will change position of (this) child prim only, not entire linkset - - - - Change the Scale (size) of an object - - A reference to the object where the object resides - The objects ID which is local to the simulator the object is in - The new scale of the object - If true, will change scale of this prim only, not entire linkset - True to resize prims uniformly - - - - Change the Rotation of an object that is either a child or a whole linkset - - A reference to the object where the object resides - The objects ID which is local to the simulator the object is in - The new scale of the object - If true, will change rotation of this prim only, not entire linkset - - - - Send a Multiple Object Update packet to change the size, scale or rotation of a primitive - - A reference to the object where the object resides - The objects ID which is local to the simulator the object is in - The new rotation, size, or position of the target object - The flags from the Enum - - - - Deed an object (prim) to a group, Object must be shared with group which - can be accomplished with SetPermissions() - - A reference to the object where the object resides - The objects ID which is local to the simulator the object is in - The of the group to deed the object to - - - - Deed multiple objects (prims) to a group, Objects must be shared with group which - can be accomplished with SetPermissions() - - A reference to the object where the object resides - An array which contains the IDs of the objects to deed - The of the group to deed the object to - - - - Set the permissions on multiple objects - - A reference to the object where the objects reside - An array which contains the IDs of the objects to set the permissions on - The new Who mask to set - Which permission to modify - The new state of permission - - - - Request additional properties for an object - - A reference to the object where the object resides - - - - - Request additional properties for an object - - A reference to the object where the object resides - Absolute UUID of the object - Whether to require server acknowledgement of this request - - - - Set the ownership of a list of objects to the specified group - - A reference to the object where the objects reside - An array which contains the IDs of the objects to set the group id on - The Groups ID - - - - Update current URL of the previously set prim media - - UUID of the prim - Set current URL to this - Prim face number - Simulator in which prim is located - - - - Set object media - - UUID of the prim - Array the length of prims number of faces. Null on face indexes where there is - no media, on faces which contain the media - Simulatior in which prim is located - - - - Retrieve information about object media - - UUID of the primitive - Simulator where prim is located - Call this callback when done - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - - - - A terse object update, used when a transformation matrix or - velocity/acceleration for an object changes but nothing else - (scale/position/rotation/acceleration/velocity) - - The sender - The EventArgs object containing the packet data - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - - - - - - - - - - - - Setup construction data for a basic primitive shape - - Primitive shape to construct - Construction data that can be plugged into a - - - - - - - - - - - - - - - - - - - - Set the Shape data of an object - - A reference to the object where the object resides - The objects ID which is local to the simulator the object is in - Data describing the prim shape - - - - Set the Material data of an object - - A reference to the object where the object resides - The objects ID which is local to the simulator the object is in - The new material of the object - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Provides data for the event - The event occurs when the simulator sends - an containing a Primitive, Foliage or Attachment data - Note 1: The event will not be raised when the object is an Avatar - Note 2: It is possible for the to be - raised twice for the same object if for example the primitive moved to a new simulator, then returned to the current simulator or - if an Avatar crosses the border into a new simulator and returns to the current simulator - - - The following code example uses the , , and - properties to display new Primitives and Attachments on the window. - - // Subscribe to the event that gives us prim and foliage information - Client.Objects.ObjectUpdate += Objects_ObjectUpdate; - - - private void Objects_ObjectUpdate(object sender, PrimEventArgs e) - { - Console.WriteLine("Primitive {0} {1} in {2} is an attachment {3}", e.Prim.ID, e.Prim.LocalID, e.Simulator.Name, e.IsAttachment); - } - - - - - - - - Get the simulator the originated from - - - Get the details - - - true if the did not exist in the dictionary before this update (always true if object tracking has been disabled) - - - true if the is attached to an - - - Get the simulator Time Dilation - - - - Construct a new instance of the PrimEventArgs class - - The simulator the object originated from - The Primitive - The simulator time dilation - The prim was not in the dictionary before this update - true if the primitive represents an attachment to an agent - - - Provides data for the event - The event occurs when the simulator sends - an containing Avatar data - Note 1: The event will not be raised when the object is an Avatar - Note 2: It is possible for the to be - raised twice for the same avatar if for example the avatar moved to a new simulator, then returned to the current simulator - - - The following code example uses the property to make a request for the top picks - using the method in the class to display the names - of our own agents picks listings on the window. - - // subscribe to the AvatarUpdate event to get our information - Client.Objects.AvatarUpdate += Objects_AvatarUpdate; - Client.Avatars.AvatarPicksReply += Avatars_AvatarPicksReply; - - private void Objects_AvatarUpdate(object sender, AvatarUpdateEventArgs e) - { - // we only want our own data - if (e.Avatar.LocalID == Client.Self.LocalID) - { - // Unsubscribe from the avatar update event to prevent a loop - // where we continually request the picks every time we get an update for ourselves - Client.Objects.AvatarUpdate -= Objects_AvatarUpdate; - // make the top picks request through AvatarManager - Client.Avatars.RequestAvatarPicks(e.Avatar.ID); - } - } - - private void Avatars_AvatarPicksReply(object sender, AvatarPicksReplyEventArgs e) - { - // we'll unsubscribe from the AvatarPicksReply event since we now have the data - // we were looking for - Client.Avatars.AvatarPicksReply -= Avatars_AvatarPicksReply; - // loop through the dictionary and extract the names of the top picks from our profile - foreach (var pickName in e.Picks.Values) - { - Console.WriteLine(pickName); - } - } - - - - - - - Get the simulator the object originated from - - - Get the data - - - Get the simulator time dilation - - - true if the did not exist in the dictionary before this update (always true if avatar tracking has been disabled) - - - - Construct a new instance of the AvatarUpdateEventArgs class - - The simulator the packet originated from - The data - The simulator time dilation - The avatar was not in the dictionary before this update - - - Get the simulator the object originated from - - - Get the data - - - Get source - - - - Construct a new instance of the ParticleUpdateEventArgs class - - The simulator the packet originated from - The ParticleSystem data - The Primitive source - - - Provides additional primitive data for the event - The event occurs when the simulator sends - an containing additional details for a Primitive, Foliage data or Attachment data - The event is also raised when a request is - made. - - - The following code example uses the , and - - properties to display new attachments and send a request for additional properties containing the name of the - attachment then display it on the window. - - // Subscribe to the event that provides additional primitive details - Client.Objects.ObjectProperties += Objects_ObjectProperties; - - // handle the properties data that arrives - private void Objects_ObjectProperties(object sender, ObjectPropertiesEventArgs e) - { - Console.WriteLine("Primitive Properties: {0} Name is {1}", e.Properties.ObjectID, e.Properties.Name); - } - - - - - Get the simulator the object is located - - - Get the primitive properties - - - - Construct a new instance of the ObjectPropertiesEventArgs class - - The simulator the object is located - The primitive Properties - - - Provides additional primitive data for the event - The event occurs when the simulator sends - an containing additional details for a Primitive or Foliage data that is currently - being tracked in the dictionary - The event is also raised when a request is - made and is enabled - - - - Get the primitive details - - - - Construct a new instance of the ObjectPropertiesUpdatedEvenrArgs class - - The simulator the object is located - The Primitive - The primitive Properties - - - Provides additional primitive data, permissions and sale info for the event - The event occurs when the simulator sends - an containing additional details for a Primitive, Foliage data or Attachment. This includes - Permissions, Sale info, and other basic details on an object - The event is also raised when a request is - made, the viewer equivalent is hovering the mouse cursor over an object - - - - Get the simulator the object is located - - - - - - - - - Provides primitive data containing updated location, velocity, rotation, textures for the event - The event occurs when the simulator sends updated location, velocity, rotation, etc - - - - Get the simulator the object is located - - - Get the primitive details - - - - - - - - - - - - - - Get the simulator the object is located - - - Get the primitive details - - - - - - - - - - - - - - - Provides notification when an Avatar, Object or Attachment is DeRezzed or moves out of the avatars view for the - event - - - Get the simulator the object is located - - - The LocalID of the object - - - Provides notification when an Avatar, Object or Attachment is DeRezzed or moves out of the avatars view for the - event - - - Get the simulator the object is located - - - The LocalID of the object - - - - Provides updates sit position data - - - - Get the simulator the object is located - - - - - - - - - - - - - - - - - Get the simulator the object is located - - - - - - - - - - - - - Indicates if the operation was successful - - - - - Media version string - - - - - Array of media entries indexed by face number - - - - - Set when simulator sends us infomation on primitive's physical properties - - - - Simulator where the message originated - - - Updated physical properties - - - - Constructor - - Simulator where the message originated - Updated physical properties - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - The ObservableDictionary class is used for storing key/value pairs. It has methods for firing - events to subscribers when items are added, removed, or changed. - - Key - Value - - - - A dictionary of callbacks to fire when specified action occurs - - - - - Register a callback to be fired when an action occurs - - The action - The callback to fire - - - - Unregister a callback - - The action - The callback to fire - - - - - - - - - - Internal dictionary that this class wraps around. Do not - modify or enumerate the contents of this dictionary without locking - - - - Gets the number of Key/Value pairs contained in the - - - - - Initializes a new instance of the Class - with the specified key/value, has the default initial capacity. - - - - // initialize a new ObservableDictionary named testDict with a string as the key and an int as the value. - public ObservableDictionary<string, int> testDict = new ObservableDictionary<string, int>(); - - - - - - Initializes a new instance of the Class - with the specified key/value, With its initial capacity specified. - - Initial size of dictionary - - - // initialize a new ObservableDictionary named testDict with a string as the key and an int as the value, - // initially allocated room for 10 entries. - public ObservableDictionary<string, int> testDict = new ObservableDictionary<string, int>(10); - - - - - - Try to get entry from the with specified key - - Key to use for lookup - Value returned - if specified key exists, if not found - - - // find your avatar using the Simulator.ObjectsAvatars ObservableDictionary: - Avatar av; - if (Client.Network.CurrentSim.ObjectsAvatars.TryGetValue(Client.Self.AgentID, out av)) - Console.WriteLine("Found Avatar {0}", av.Name); - - - - - - - Finds the specified match. - - The match. - Matched value - - - // use a delegate to find a prim in the ObjectsPrimitives ObservableDictionary - // with the ID 95683496 - uint findID = 95683496; - Primitive findPrim = sim.ObjectsPrimitives.Find( - delegate(Primitive prim) { return prim.ID == findID; }); - - - - - Find All items in an - return matching items. - a containing found items. - - Find All prims within 20 meters and store them in a List - - int radius = 20; - List<Primitive> prims = Client.Network.CurrentSim.ObjectsPrimitives.FindAll( - delegate(Primitive prim) { - Vector3 pos = prim.Position; - return ((prim.ParentID == 0) && (pos != Vector3.Zero) && (Vector3.Distance(pos, location) < radius)); - } - ); - - - - - Find All items in an - return matching keys. - a containing found keys. - - Find All keys which also exist in another dictionary - - List<UUID> matches = myDict.FindAll( - delegate(UUID id) { - return myOtherDict.ContainsKey(id); - } - ); - - - - - Check if Key exists in Dictionary - Key to check for - if found, otherwise - - - Check if Value exists in Dictionary - Value to check for - if found, otherwise - - - - Adds the specified key to the dictionary, dictionary locking is not performed, - - - The key - The value - - - - Removes the specified key, dictionary locking is not performed - - The key. - if successful, otherwise - - - - Indexer for the dictionary - - The key - The value - - - - Clear the contents of the dictionary - - - - - Enumerator for iterating dictionary entries - - - - - - Type of return to use when returning objects from a parcel - - - - - - - Return objects owned by parcel owner - - - Return objects set to group - - - Return objects not owned by parcel owner or set to group - - - Return a specific list of objects on parcel - - - Return objects that are marked for-sale - - - - Blacklist/Whitelist flags used in parcels Access List - - - - Agent is denied access - - - Agent is granted access - - - - The result of a request for parcel properties - - - - No matches were found for the request - - - Request matched a single parcel - - - Request matched multiple parcels - - - - Flags used in the ParcelAccessListRequest packet to specify whether - we want the access list (whitelist), ban list (blacklist), or both - - - - Request the access list - - - Request the ban list - - - Request both White and Black lists - - - - Sequence ID in ParcelPropertiesReply packets (sent when avatar - tries to cross a parcel border) - - - - Parcel is currently selected - - - Parcel restricted to a group the avatar is not a - member of - - - Avatar is banned from the parcel - - - Parcel is restricted to an access list that the - avatar is not on - - - Response to hovering over a parcel - - - - The tool to use when modifying terrain levels - - - - Level the terrain - - - Raise the terrain - - - Lower the terrain - - - Smooth the terrain - - - Add random noise to the terrain - - - Revert terrain to simulator default - - - - The tool size to use when changing terrain levels - - - - Small - - - Medium - - - Large - - - - Reasons agent is denied access to a parcel on the simulator - - - - Agent is not denied, access is granted - - - Agent is not a member of the group set for the parcel, or which owns the parcel - - - Agent is not on the parcels specific allow list - - - Agent is on the parcels ban list - - - Unknown - - - Agent is not age verified and parcel settings deny access to non age verified avatars - - - - Parcel overlay type. This is used primarily for highlighting and - coloring which is why it is a single integer instead of a set of - flags - - These values seem to be poorly thought out. The first three - bits represent a single value, not flags. For example Auction (0x05) is - not a combination of OwnedByOther (0x01) and ForSale(0x04). However, - the BorderWest and BorderSouth values are bit flags that get attached - to the value stored in the first three bits. Bits four, five, and six - are unused - - - Public land - - - Land is owned by another avatar - - - Land is owned by a group - - - Land is owned by the current avatar - - - Land is for sale - - - Land is being auctioned - - - Land is private - - - To the west of this area is a parcel border - - - To the south of this area is a parcel border - - - - Various parcel properties - - - - No flags set - - - Allow avatars to fly (a client-side only restriction) - - - Allow foreign scripts to run - - - This parcel is for sale - - - Allow avatars to create a landmark on this parcel - - - Allows all avatars to edit the terrain on this parcel - - - Avatars have health and can take damage on this parcel. - If set, avatars can be killed and sent home here - - - Foreign avatars can create objects here - - - All objects on this parcel can be purchased - - - Access is restricted to a group - - - Access is restricted to a whitelist - - - Ban blacklist is enabled - - - Unknown - - - List this parcel in the search directory - - - Allow personally owned parcels to be deeded to group - - - If Deeded, owner contributes required tier to group parcel is deeded to - - - Restrict sounds originating on this parcel to the - parcel boundaries - - - Objects on this parcel are sold when the land is - purchsaed - - - Allow this parcel to be published on the web - - - The information for this parcel is mature content - - - The media URL is an HTML page - - - The media URL is a raw HTML string - - - Restrict foreign object pushes - - - Ban all non identified/transacted avatars - - - Allow group-owned scripts to run - - - Allow object creation by group members or group - objects - - - Allow all objects to enter this parcel - - - Only allow group and owner objects to enter this parcel - - - Voice Enabled on this parcel - - - Use Estate Voice channel for Voice on this parcel - - - Deny Age Unverified Users - - - - Parcel ownership status - - - - Placeholder - - - Parcel is leased (owned) by an avatar or group - - - Parcel is in process of being leased (purchased) by an avatar or group - - - Parcel has been abandoned back to Governor Linden - - - - Category parcel is listed in under search - - - - No assigned category - - - Linden Infohub or public area - - - Adult themed area - - - Arts and Culture - - - Business - - - Educational - - - Gaming - - - Hangout or Club - - - Newcomer friendly - - - Parks and Nature - - - Residential - - - Shopping - - - Not Used? - - - Other - - - Not an actual category, only used for queries - - - - Type of teleport landing for a parcel - - - - Unset, simulator default - - - Specific landing point set for this parcel - - - No landing point set, direct teleports enabled for - this parcel - - - - Parcel Media Command used in ParcelMediaCommandMessage - - - - Stop the media stream and go back to the first frame - - - Pause the media stream (stop playing but stay on current frame) - - - Start the current media stream playing and stop when the end is reached - - - Start the current media stream playing, - loop to the beginning when the end is reached and continue to play - - - Specifies the texture to replace with video - If passing the key of a texture, it must be explicitly typecast as a key, - not just passed within double quotes. - - - Specifies the movie URL (254 characters max) - - - Specifies the time index at which to begin playing - - - Specifies a single agent to apply the media command to - - - Unloads the stream. While the stop command sets the texture to the first frame of the movie, - unload resets it to the real texture that the movie was replacing. - - - Turn on/off the auto align feature, similar to the auto align checkbox in the parcel media properties - (NOT to be confused with the "align" function in the textures view of the editor!) Takes TRUE or FALSE as parameter. - - - Allows a Web page or image to be placed on a prim (1.19.1 RC0 and later only). - Use "text/html" for HTML. - - - Resizes a Web page to fit on x, y pixels (1.19.1 RC0 and later only). - This might still not be working - - - Sets a description for the media being displayed (1.19.1 RC0 and later only). - - - - Some information about a parcel of land returned from a DirectoryManager search - - - - Global Key of record - - - Parcel Owners - - - Name field of parcel, limited to 128 characters - - - Description field of parcel, limited to 256 characters - - - Total Square meters of parcel - - - Total area billable as Tier, for group owned land this will be 10% less than ActualArea - - - True of parcel is in Mature simulator - - - Grid global X position of parcel - - - Grid global Y position of parcel - - - Grid global Z position of parcel (not used) - - - Name of simulator parcel is located in - - - Texture of parcels display picture - - - Float representing calculated traffic based on time spent on parcel by avatars - - - Sale price of parcel (not used) - - - Auction ID of parcel - - - - Parcel Media Information - - - - A byte, if 0x1 viewer should auto scale media to fit object - - - A boolean, if true the viewer should loop the media - - - The Asset UUID of the Texture which when applied to a - primitive will display the media - - - A URL which points to any Quicktime supported media type - - - A description of the media - - - An Integer which represents the height of the media - - - An integer which represents the width of the media - - - A string which contains the mime type of the media - - - - Parcel of land, a portion of virtual real estate in a simulator - - - - The total number of contiguous 4x4 meter blocks your agent owns within this parcel - - - The total number of contiguous 4x4 meter blocks contained in this parcel owned by a group or agent other than your own - - - Deprecated, Value appears to always be 0 - - - Simulator-local ID of this parcel - - - UUID of the owner of this parcel - - - Whether the land is deeded to a group or not - - - - - - Date land was claimed - - - Appears to always be zero - - - This field is no longer used - - - Minimum corner of the axis-aligned bounding box for this - parcel - - - Maximum corner of the axis-aligned bounding box for this - parcel - - - Bitmap describing land layout in 4x4m squares across the - entire region - - - Total parcel land area - - - - - - Maximum primitives across the entire simulator owned by the same agent or group that owns this parcel that can be used - - - Total primitives across the entire simulator calculated by combining the allowed prim counts for each parcel - owned by the agent or group that owns this parcel - - - Maximum number of primitives this parcel supports - - - Total number of primitives on this parcel - - - For group-owned parcels this indicates the total number of prims deeded to the group, - for parcels owned by an individual this inicates the number of prims owned by the individual - - - Total number of primitives owned by the parcel group on - this parcel, or for parcels owned by an individual with a group set the - total number of prims set to that group. - - - Total number of prims owned by other avatars that are not set to group, or not the parcel owner - - - A bonus multiplier which allows parcel prim counts to go over times this amount, this does not affect - the max prims per simulator. e.g: 117 prim parcel limit x 1.5 bonus = 175 allowed - - - Autoreturn value in minutes for others' objects - - - - - - Sale price of the parcel, only useful if ForSale is set - The SalePrice will remain the same after an ownership - transfer (sale), so it can be used to see the purchase price after - a sale if the new owner has not changed it - - - Parcel Name - - - Parcel Description - - - URL For Music Stream - - - - - - Price for a temporary pass - - - How long is pass valid for - - - - - - Key of authorized buyer - - - Key of parcel snapshot - - - The landing point location - - - The landing point LookAt - - - The type of landing enforced from the enum - - - - - - - - - - - - Access list of who is whitelisted on this - parcel - - - Access list of who is blacklisted on this - parcel - - - TRUE of region denies access to age unverified users - - - true to obscure (hide) media url - - - true to obscure (hide) music url - - - A struct containing media details - - - Parcel privacy see avatars outside/inside parcel - - - Parcel privacy play sounds attached to avatars outside/inside parcel - - - Parcel privacy play sounds for group members - - - - Displays a parcel object in string format - - string containing key=value pairs of a parcel object - - - - Defalt constructor - - Local ID of this parcel - - - - Update the simulator with any local changes to this Parcel object - - Simulator to send updates to - Whether we want the simulator to confirm - the update with a reply packet or not - - - - Set Autoreturn time - - Simulator to send the update to - - - - Parcel (subdivided simulator lots) subsystem - - - - - Parcel Accesslist - - - - Agents - - - - - - Flags for specific entry in white/black lists - - - - Owners of primitives on parcel - - - - Prim Owners - - - True of owner is group - - - Total count of prims owned by OwnerID - - - true of OwnerID is currently online and is not a group - - - The date of the most recent prim left by OwnerID - - - - Called once parcel resource usage information has been collected - - Indicates if operation was successfull - Parcel resource usage information - - - The event subscribers. null if no subcribers - - - Raises the ParcelDwellReply event - A ParcelDwellReplyEventArgs object containing the - data returned from the simulator - - - Thread sync lock object - - - Raised when the simulator responds to a request - - - The event subscribers. null if no subcribers - - - Raises the ParcelInfoReply event - A ParcelInfoReplyEventArgs object containing the - data returned from the simulator - - - Thread sync lock object - - - Raised when the simulator responds to a request - - - The event subscribers. null if no subcribers - - - Raises the ParcelProperties event - A ParcelPropertiesEventArgs object containing the - data returned from the simulator - - - Thread sync lock object - - - Raised when the simulator responds to a request - - - The event subscribers. null if no subcribers - - - Raises the ParcelAccessListReply event - A ParcelAccessListReplyEventArgs object containing the - data returned from the simulator - - - Thread sync lock object - - - Raised when the simulator responds to a request - - - The event subscribers. null if no subcribers - - - Raises the ParcelObjectOwnersReply event - A ParcelObjectOwnersReplyEventArgs object containing the - data returned from the simulator - - - Thread sync lock object - - - Raised when the simulator responds to a request - - - The event subscribers. null if no subcribers - - - Raises the SimParcelsDownloaded event - A SimParcelsDownloadedEventArgs object containing the - data returned from the simulator - - - Thread sync lock object - - - Raised when the simulator responds to a request - - - The event subscribers. null if no subcribers - - - Raises the ForceSelectObjectsReply event - A ForceSelectObjectsReplyEventArgs object containing the - data returned from the simulator - - - Thread sync lock object - - - Raised when the simulator responds to a request - - - The event subscribers. null if no subcribers - - - Raises the ParcelMediaUpdateReply event - A ParcelMediaUpdateReplyEventArgs object containing the - data returned from the simulator - - - Thread sync lock object - - - Raised when the simulator responds to a Parcel Update request - - - The event subscribers. null if no subcribers - - - Raises the ParcelMediaCommand event - A ParcelMediaCommandEventArgs object containing the - data returned from the simulator - - - Thread sync lock object - - - Raised when the parcel your agent is located sends a ParcelMediaCommand - - - - Default constructor - - A reference to the GridClient object - - - - Request basic information for a single parcel - - Simulator-local ID of the parcel - - - - Request properties of a single parcel - - Simulator containing the parcel - Simulator-local ID of the parcel - An arbitrary integer that will be returned - with the ParcelProperties reply, useful for distinguishing between - multiple simultaneous requests - - - - Request the access list for a single parcel - - Simulator containing the parcel - Simulator-local ID of the parcel - An arbitrary integer that will be returned - with the ParcelAccessList reply, useful for distinguishing between - multiple simultaneous requests - - - - - Request properties of parcels using a bounding box selection - - Simulator containing the parcel - Northern boundary of the parcel selection - Eastern boundary of the parcel selection - Southern boundary of the parcel selection - Western boundary of the parcel selection - An arbitrary integer that will be returned - with the ParcelProperties reply, useful for distinguishing between - different types of parcel property requests - A boolean that is returned with the - ParcelProperties reply, useful for snapping focus to a single - parcel - - - - Request all simulator parcel properties (used for populating the Simulator.Parcels - dictionary) - - Simulator to request parcels from (must be connected) - - - - Request all simulator parcel properties (used for populating the Simulator.Parcels - dictionary) - - Simulator to request parcels from (must be connected) - If TRUE, will force a full refresh - Number of milliseconds to pause in between each request - - - - Request the dwell value for a parcel - - Simulator containing the parcel - Simulator-local ID of the parcel - - - - Send a request to Purchase a parcel of land - - The Simulator the parcel is located in - The parcels region specific local ID - true if this parcel is being purchased by a group - The groups - true to remove tier contribution if purchase is successful - The parcels size - The purchase price of the parcel - - - - - Reclaim a parcel of land - - The simulator the parcel is in - The parcels region specific local ID - - - - Deed a parcel to a group - - The simulator the parcel is in - The parcels region specific local ID - The groups - - - - Request prim owners of a parcel of land. - - Simulator parcel is in - The parcels region specific local ID - - - - Return objects from a parcel - - Simulator parcel is in - The parcels region specific local ID - the type of objects to return, - A list containing object owners s to return - - - - Subdivide (split) a parcel - - - - - - - - - - Join two parcels of land creating a single parcel - - - - - - - - - - Get a parcels LocalID - - Simulator parcel is in - Vector3 position in simulator (Z not used) - 0 on failure, or parcel LocalID on success. - A call to Parcels.RequestAllSimParcels is required to populate map and - dictionary. - - - - Terraform (raise, lower, etc) an area or whole parcel of land - - Simulator land area is in. - LocalID of parcel, or -1 if using bounding box - From Enum, Raise, Lower, Level, Smooth, Etc. - Size of area to modify - true on successful request sent. - Settings.STORE_LAND_PATCHES must be true, - Parcel information must be downloaded using RequestAllSimParcels() - - - - Terraform (raise, lower, etc) an area or whole parcel of land - - Simulator land area is in. - west border of area to modify - south border of area to modify - east border of area to modify - north border of area to modify - From Enum, Raise, Lower, Level, Smooth, Etc. - Size of area to modify - true on successful request sent. - Settings.STORE_LAND_PATCHES must be true, - Parcel information must be downloaded using RequestAllSimParcels() - - - - Terraform (raise, lower, etc) an area or whole parcel of land - - Simulator land area is in. - LocalID of parcel, or -1 if using bounding box - west border of area to modify - south border of area to modify - east border of area to modify - north border of area to modify - From Enum, Raise, Lower, Level, Smooth, Etc. - Size of area to modify - How many meters + or - to lower, 1 = 1 meter - true on successful request sent. - Settings.STORE_LAND_PATCHES must be true, - Parcel information must be downloaded using RequestAllSimParcels() - - - - Terraform (raise, lower, etc) an area or whole parcel of land - - Simulator land area is in. - LocalID of parcel, or -1 if using bounding box - west border of area to modify - south border of area to modify - east border of area to modify - north border of area to modify - From Enum, Raise, Lower, Level, Smooth, Etc. - Size of area to modify - How many meters + or - to lower, 1 = 1 meter - Height at which the terraform operation is acting at - - - - Sends a request to the simulator to return a list of objects owned by specific owners - - Simulator local ID of parcel - Owners, Others, Etc - List containing keys of avatars objects to select; - if List is null will return Objects of type selectType - Response data is returned in the event - - - - Eject and optionally ban a user from a parcel - - target key of avatar to eject - true to also ban target - - - - Freeze or unfreeze an avatar over your land - - target key to freeze - true to freeze, false to unfreeze - - - - Abandon a parcel of land - - Simulator parcel is in - Simulator local ID of parcel - - - - Requests the UUID of the parcel in a remote region at a specified location - - Location of the parcel in the remote region - Remote region handle - Remote region UUID - If successful UUID of the remote parcel, UUID.Zero otherwise - - - - Retrieves information on resources used by the parcel - - UUID of the parcel - Should per object resource usage be requested - Callback invoked when the request is complete - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - Raises the event - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - Raises the event - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - Raises the event - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - Raises the event - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - Raises the event - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - Raises the event - - - Contains a parcels dwell data returned from the simulator in response to an - - - Get the global ID of the parcel - - - Get the simulator specific ID of the parcel - - - Get the calculated dwell - - - - Construct a new instance of the ParcelDwellReplyEventArgs class - - The global ID of the parcel - The simulator specific ID of the parcel - The calculated dwell for the parcel - - - Contains basic parcel information data returned from the - simulator in response to an request - - - Get the object containing basic parcel info - - - - Construct a new instance of the ParcelInfoReplyEventArgs class - - The object containing basic parcel info - - - Contains basic parcel information data returned from the simulator in response to an request - - - Get the simulator the parcel is located in - - - Get the object containing the details - If Result is NoData, this object will not contain valid data - - - Get the result of the request - - - Get the number of primitieves your agent is - currently selecting and or sitting on in this parcel - - - Get the user assigned ID used to correlate a request with - these results - - - TODO: - - - - Construct a new instance of the ParcelPropertiesEventArgs class - - The object containing the details - The object containing the details - The result of the request - The number of primitieves your agent is - currently selecting and or sitting on in this parcel - The user assigned ID used to correlate a request with - these results - TODO: - - - Contains blacklist and whitelist data returned from the simulator in response to an request - - - Get the simulator the parcel is located in - - - Get the user assigned ID used to correlate a request with - these results - - - Get the simulator specific ID of the parcel - - - TODO - - - Get the list containing the white/blacklisted agents for the parcel - - - - Construct a new instance of the ParcelAccessListReplyEventArgs class - - The simulator the parcel is located in - The user assigned ID used to correlate a request with - these results - The simulator specific ID of the parcel - TODO: - The list containing the white/blacklisted agents for the parcel - - - Contains blacklist and whitelist data returned from the - simulator in response to an request - - - Get the simulator the parcel is located in - - - Get the list containing prim ownership counts - - - - Construct a new instance of the ParcelObjectOwnersReplyEventArgs class - - The simulator the parcel is located in - The list containing prim ownership counts - - - Contains the data returned when all parcel data has been retrieved from a simulator - - - Get the simulator the parcel data was retrieved from - - - A dictionary containing the parcel data where the key correlates to the ParcelMap entry - - - Get the multidimensional array containing a x,y grid mapped - to each 64x64 parcel's LocalID. - - - - Construct a new instance of the SimParcelsDownloadedEventArgs class - - The simulator the parcel data was retrieved from - The dictionary containing the parcel data - The multidimensional array containing a x,y grid mapped - to each 64x64 parcel's LocalID. - - - Contains the data returned when a request - - - Get the simulator the parcel data was retrieved from - - - Get the list of primitive IDs - - - true if the list is clean and contains the information - only for a given request - - - - Construct a new instance of the ForceSelectObjectsReplyEventArgs class - - The simulator the parcel data was retrieved from - The list of primitive IDs - true if the list is clean and contains the information - only for a given request - - - Contains data when the media data for a parcel the avatar is on changes - - - Get the simulator the parcel media data was updated in - - - Get the updated media information - - - - Construct a new instance of the ParcelMediaUpdateReplyEventArgs class - - the simulator the parcel media data was updated in - The updated media information - - - Contains the media command for a parcel the agent is currently on - - - Get the simulator the parcel media command was issued in - - - - - - - - - Get the media command that was sent - - - - - - - Construct a new instance of the ParcelMediaCommandEventArgs class - - The simulator the parcel media command was issued in - - - The media command that was sent - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Permissions for control of object media - - - - - Style of cotrols that shold be displayed to the user - - - - - Class representing media data for a single face - - - - Is display of the alternative image enabled - - - Should media auto loop - - - Shoule media be auto played - - - Auto scale media to prim face - - - Should viewer automatically zoom in on the face when clicked - - - Should viewer interpret first click as interaction with the media - or when false should the first click be treated as zoom in commadn - - - Style of controls viewer should display when - viewer media on this face - - - Starting URL for the media - - - Currently navigated URL - - - Media height in pixes - - - Media width in pixels - - - Who can controls the media - - - Who can interact with the media - - - Is URL whitelist enabled - - - Array of URLs that are whitelisted - - - - Serialize to OSD - - OSDMap with the serialized data - - - - Deserialize from OSD data - - Serialized OSD data - Deserialized object - - - - Particle system specific enumerators, flags and methods. - - - - - Current version of the media data for the prim - - - - - Array of media entries indexed by face number - - - - - Complete structure for the particle system - - - - - Particle source pattern - - - - None - - - Drop particles from source position with no force - - - "Explode" particles in all directions - - - Particles shoot across a 2D area - - - Particles shoot across a 3D Cone - - - Inverse of AngleCone (shoot particles everywhere except the 3D cone defined - - - - Particle Data Flags - - - - None - - - Interpolate color and alpha from start to end - - - Interpolate scale from start to end - - - Bounce particles off particle sources Z height - - - velocity of particles is dampened toward the simulators wind - - - Particles follow the source - - - Particles point towards the direction of source's velocity - - - Target of the particles - - - Particles are sent in a straight line - - - Particles emit a glow - - - used for point/grab/touch - - - continuous ribbon particle - - - particle data contains glow - - - particle data contains blend functions - - - - Particle Flags Enum - - - - None - - - Acceleration and velocity for particles are - relative to the object rotation - - - Particles use new 'correct' angle parameters - - - Particle Flags - There appears to be more data packed in to this area - for many particle systems. It doesn't appear to be flag values - and serialization breaks unless there is a flag for every - possible bit so it is left as an unsigned integer - - - pattern of particles - - - A representing the maximimum age (in seconds) particle will be displayed - Maximum value is 30 seconds - - - A representing the number of seconds, - from when the particle source comes into view, - or the particle system's creation, that the object will emits particles; - after this time period no more particles are emitted - - - A in radians that specifies where particles will not be created - - - A in radians that specifies where particles will be created - - - A representing the number of seconds between burts. - - - A representing the number of meters - around the center of the source where particles will be created. - - - A representing in seconds, the minimum speed between bursts of new particles - being emitted - - - A representing in seconds the maximum speed of new particles being emitted. - - - A representing the maximum number of particles emitted per burst - - - A which represents the velocity (speed) from the source which particles are emitted - - - A which represents the Acceleration from the source which particles are emitted - - - The Key of the texture displayed on the particle - - - The Key of the specified target object or avatar particles will follow - - - Flags of particle from - - - Max Age particle system will emit particles for - - - The the particle has at the beginning of its lifecycle - - - The the particle has at the ending of its lifecycle - - - A that represents the starting X size of the particle - Minimum value is 0, maximum value is 4 - - - A that represents the starting Y size of the particle - Minimum value is 0, maximum value is 4 - - - A that represents the ending X size of the particle - Minimum value is 0, maximum value is 4 - - - A that represents the ending Y size of the particle - Minimum value is 0, maximum value is 4 - - - A that represents the start glow value - Minimum value is 0, maximum value is 1 - - - A that represents the end glow value - Minimum value is 0, maximum value is 1 - - - OpenGL blend function to use at particle source - - - OpenGL blend function to use at particle destination - - - - Can this particle system be packed in a legacy compatible way - - True if the particle system doesn't use new particle system features - - - - Decodes a byte[] array into a ParticleSystem Object - - ParticleSystem object - Start position for BitPacker - - - - Generate byte[] array from particle data - - Byte array - - - - - - - Parameters used to construct a visual representation of a primitive - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Attachment point to an avatar - - - - - - - - - - - - - - - - Calculdates hash code for prim construction data - - The has - - - - Information on the flexible properties of a primitive - - - - - - - - - - - - - - - - - - - - - - - Default constructor - - - - - - - - - - - - - - - - - - - - - - - - Information on the light properties of a primitive - - - - - - - - - - - - - - - - - - - - Default constructor - - - - - - - - - - - - - - - - - - - - - - - - Information on the light properties of a primitive as texture map - - - - - - - - - - - Default constructor - - - - - - - - - - - - - - - - - - - - - - - - Information on the sculpt properties of a sculpted primitive - - - - - Render inside out (inverts the normals). - - - - - Render an X axis mirror of the sculpty. - - - - - Default constructor - - - - - - - - - - - - Extended properties to describe an object - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Default constructor - - - - - Set the properties that are set in an ObjectPropertiesFamily packet - - that has - been partially filled by an ObjectPropertiesFamily packet - - - - Describes physics attributes of the prim - - - - Primitive's local ID - - - Density (1000 for normal density) - - - Friction - - - Gravity multiplier (1 for normal gravity) - - - Type of physics representation of this primitive in the simulator - - - Restitution - - - - Creates PhysicsProperties from OSD - - OSDMap with incoming data - Deserialized PhysicsProperties object - - - - Serializes PhysicsProperties to OSD - - OSDMap with serialized PhysicsProperties data - - - - - - - - - - - - - - - - - - - - - Foliage type for this primitive. Only applicable if this - primitive is foliage - - - Unknown - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Identifies the owner if audio or a particle system is - active - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Objects physics engine propertis - - - Extra data about primitive - - - Indicates if prim is attached to an avatar - - - Number of clients referencing this prim - - - Uses basic heuristics to estimate the primitive shape - - - - Default constructor - - - - - Packs PathTwist, PathTwistBegin, PathRadiusOffset, and PathSkew - parameters in to signed eight bit values - - Floating point parameter to pack - Signed eight bit value containing the packed parameter - - - - Unpacks PathTwist, PathTwistBegin, PathRadiusOffset, and PathSkew - parameters from signed eight bit integers to floating point values - - Signed eight bit value to unpack - Unpacked floating point value - - - - Texture animation mode - - - - Disable texture animation - - - Enable texture animation - - - Loop when animating textures - - - Animate in reverse direction - - - Animate forward then reverse - - - Slide texture smoothly instead of frame-stepping - - - Rotate texture instead of using frames - - - Scale texture instead of using frames - - - - A single textured face. Don't instantiate this class yourself, use the - methods in TextureEntry - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - In the future this will specify whether a webpage is - attached to this face - - - - - - - - - - Contains the definition for individual faces - - - - - - - - - - - - Represents all of the texturable faces for an object - - Grid objects have infinite faces, with each face - using the properties of the default face unless set otherwise. So if - you have a TextureEntry with a default texture uuid of X, and face 18 - has a texture UUID of Y, every face would be textured with X except for - face 18 that uses Y. In practice however, primitives utilize a maximum - of nine faces - - - - - - - - - - Constructor that takes a default texture UUID - - Texture UUID to use as the default texture - - - - Constructor that takes a TextureEntryFace for the - default face - - Face to use as the default face - - - - Constructor that creates the TextureEntry class from a byte array - - Byte array containing the TextureEntry field - Starting position of the TextureEntry field in - the byte array - Length of the TextureEntry field, in bytes - - - - This will either create a new face if a custom face for the given - index is not defined, or return the custom face for that index if - it already exists - - The index number of the face to create or - retrieve - A TextureEntryFace containing all the properties for that - face - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Controls the texture animation of a particular prim - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - The type of bump-mapping applied to a face - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - The level of shininess applied to a face - - - - - - - - - - - - - - - - - The texture mapping style used for a face - - - - - - - - - - - - - - - - - Flags in the TextureEntry block that describe which properties are - set - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Class for controlling various system settings. - - Some values are readonly because they affect things that - happen when the GridClient object is initialized, so changing them at - runtime won't do any good. Non-readonly values may affect things that - happen at login or dynamically - - - Main grid login server - - - Beta grid login server - - - The relative directory where external resources are kept - - - Login server to connect to - - - IP Address the client will bind to - - - Use XML-RPC Login or LLSD Login, default is XML-RPC Login - - - - Maximum number of HTTP connections to open to a particular endpoint. - - - An endpoint is defined as a commbination of network address and port. This is used for Caps. - This is a static variable which applies to all instances. - - - - - InventoryManager requests inventory information on login, - GridClient initializes an Inventory store for main inventory. - - - - - InventoryManager requests library information on login, - GridClient initializes an Inventory store for the library. - - - - Number of milliseconds before an asset transfer will time - out - - - Number of milliseconds before a teleport attempt will time - out - - - Number of milliseconds before NetworkManager.Logout() will - time out - - - Number of milliseconds before a CAPS call will time out - Setting this too low will cause web requests time out and - possibly retry repeatedly - - - Number of milliseconds for xml-rpc to timeout - - - Milliseconds before a packet is assumed lost and resent - - - Milliseconds without receiving a packet before the - connection to a simulator is assumed lost - - - Milliseconds to wait for a simulator info request through - the grid interface - - - Number of milliseconds between sending pings to each sim - - - Number of milliseconds between sending camera updates - - - Number of milliseconds between updating the current - positions of moving, non-accelerating and non-colliding objects - - - Millisecond interval between ticks, where all ACKs are - sent out and the age of unACKed packets is checked - - - Maximum size of packet that we want to send over the wire - - - The maximum value of a packet sequence number before it - rolls over back to one - - - The maximum size of the sequence number archive, used to - check for resent and/or duplicate packets - - - Maximum number of queued ACKs to be sent before SendAcks() - is forced - - - Network stats queue length (seconds) - - - - Primitives will be reused when falling in/out of interest list (and shared between clients) - prims returning to interest list do not need re-requested - Helps also in not re-requesting prim.Properties for code that checks for a Properties == null per client - - - - - Pool parcel data between clients (saves on requesting multiple times when all clients may need it) - - - - - How long to preserve cached data when no client is connected to a simulator - The reason for setting it to something like 2 minutes is in case a client - is running back and forth between region edges or a sim is comming and going - - - - Enable/disable storing terrain heightmaps in the - TerrainManager - - - Enable/disable sending periodic camera updates - - - Enable/disable automatically setting agent appearance at - login and after sim crossing - - - Enable/disable automatically setting the bandwidth throttle - after connecting to each simulator - The default throttle uses the equivalent of the maximum - bandwidth setting in the official client. If you do not set a - throttle your connection will by default be throttled well below - the minimum values and you may experience connection problems - - - Enable/disable the sending of pings to monitor lag and - packet loss - - - Should we connect to multiple sims? This will allow - viewing in to neighboring simulators and sim crossings - (Experimental) - - - If true, all object update packets will be decoded in to - native objects. If false, only updates for our own agent will be - decoded. Registering an event handler will force objects for that - type to always be decoded. If this is disabled the object tracking - will have missing or partial prim and avatar information - - - If true, when a cached object check is received from the - server the full object info will automatically be requested - - - Whether to establish connections to HTTP capabilities - servers for simulators - - - Whether to decode sim stats - - - The capabilities servers are currently designed to - periodically return a 502 error which signals for the client to - re-establish a connection. Set this to true to log those 502 errors - - - If true, and SEND_AGENT_UPDATES is true, - AgentUpdate packets will continuously be sent out to give the bot - smoother movement and autopiloting - - - If true, currently visible avatars will be stored - in dictionaries inside Simulator.ObjectAvatars. - If false, a new Avatar or Primitive object will be created - each time an object update packet is received - - - If true, currently visible avatars will be stored - in dictionaries inside Simulator.ObjectPrimitives. - If false, a new Avatar or Primitive object will be created - each time an object update packet is received - - - If true, position and velocity will periodically be - interpolated (extrapolated, technically) for objects and - avatars that are being tracked by the library. This is - necessary to increase the accuracy of speed and position - estimates for simulated objects - - - - If true, utilization statistics will be tracked. There is a minor penalty - in CPU time for enabling this option. - - - - If true, parcel details will be stored in the - Simulator.Parcels dictionary as they are received - - - - If true, an incoming parcel properties reply will automatically send - a request for the parcel access list - - - - - if true, an incoming parcel properties reply will automatically send - a request for the traffic count. - - - - - If true, images, and other assets downloaded from the server - will be cached in a local directory - - - - Path to store cached texture data - - - Maximum size cached files are allowed to take on disk (bytes) - - - Default color used for viewer particle effects - - - Cost of uploading an asset - Read-only since this value is dynamically fetched at login - - - Maximum number of times to resend a failed packet - - - Throttle outgoing packet rate - - - - Download textures using GetTexture capability when available - - - - The maximum number of concurrent texture downloads allowed - Increasing this number will not necessarily increase texture retrieval times due to - simulator throttles - - - - The Refresh timer inteval is used to set the delay between checks for stalled texture downloads - - This is a static variable which applies to all instances - - - - Textures taking longer than this value will be flagged as timed out and removed from the pipeline - - - - - Get or set the minimum log level to output to the console by default - - If the library is not compiled with DEBUG defined and this level is set to DEBUG - You will get no output on the console. This behavior can be overriden by creating - a logger configuration file for log4net - - - - Attach avatar names to log messages - - - Log packet retransmission info - - - Log disk cache misses and other info - - - Constructor - Reference to a GridClient object - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - - - - Simulator (region) properties - - - - No flags set - - - Agents can take damage and be killed - - - Landmarks can be created here - - - Home position can be set in this sim - - - Home position is reset when an agent teleports away - - - Sun does not move - - - Allows private parcels (ie. banlines) - - - Disable heightmap alterations (agents can still plant foliage) - - - Land cannot be released, sold, or purchased - - - All content is wiped nightly - - - Unknown: Related to the availability of an overview world map tile.(Think mainland images when zoomed out.) - - - Unknown: Related to region debug flags. Possibly to skip processing of agent interaction with world. - - - Region does not update agent prim interest lists. Internal debugging option. - - - No collision detection for non-agent objects - - - No scripts are ran - - - All physics processing is turned off - - - Region can be seen from other regions on world map. (Legacy world map option?) - - - Region can be seen from mainland on world map. (Legacy world map option?) - - - Agents not explicitly on the access list can visit the region. - - - Traffic calculations are not run across entire region, overrides parcel settings. - - - Flight is disabled (not currently enforced by the sim) - - - Allow direct (p2p) teleporting - - - Estate owner has temporarily disabled scripting - - - Restricts the usage of the LSL llPushObject function, applies to whole region. - - - Deny agents with no payment info on file - - - Deny agents with payment info on file - - - Deny agents who have made a monetary transaction - - - Parcels within the region may be joined or divided by anyone, not just estate owners/managers. - - - Abuse reports sent from within this region are sent to the estate owner defined email. - - - Region is Voice Enabled - - - Removes the ability from parcel owners to set their parcels to show in search. - - - Deny agents who have not been age verified from entering the region. - - - - Region protocol flags - - - - Nothing special - - - Region supports Server side Appearance - - - Viewer supports Server side Appearance - - - - Access level for a simulator - - - - Unknown or invalid access level - - - Trial accounts allowed - - - PG rating - - - Mature rating - - - Adult rating - - - Simulator is offline - - - Simulator does not exist - - - - - - - - - Simulator Statistics - - - - Total number of packets sent by this simulator to this agent - - - Total number of packets received by this simulator to this agent - - - Total number of bytes sent by this simulator to this agent - - - Total number of bytes received by this simulator to this agent - - - Time in seconds agent has been connected to simulator - - - Total number of packets that have been resent - - - Total number of resent packets recieved - - - Total number of pings sent to this simulator by this agent - - - Total number of ping replies sent to this agent by this simulator - - - - Incoming bytes per second - - It would be nice to have this claculated on the fly, but - this is far, far easier - - - - Outgoing bytes per second - - It would be nice to have this claculated on the fly, but - this is far, far easier - - - Time last ping was sent - - - ID of last Ping sent - - - - - - - - - Current time dilation of this simulator - - - Current Frames per second of simulator - - - Current Physics frames per second of simulator - - - - - - - - - - - - - - - - - - - - - - - - - - - Total number of objects Simulator is simulating - - - Total number of Active (Scripted) objects running - - - Number of agents currently in this simulator - - - Number of agents in neighbor simulators - - - Number of Active scripts running in this simulator - - - - - - - - - - - - Number of downloads pending - - - Number of uploads pending - - - - - - - - - Number of local uploads pending - - - Unacknowledged bytes in queue - - - A public reference to the client that this Simulator object - is attached to - - - A Unique Cache identifier for this simulator - - - The capabilities for this simulator - - - - - - The current version of software this simulator is running - - - - - - A 64x64 grid of parcel coloring values. The values stored - in this array are of the type - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - true if your agent has Estate Manager rights on this region - - - - - - - - - - - - Statistics information for this simulator and the - connection to the simulator, calculated by the simulator itself - and the library - - - The regions Unique ID - - - The physical data center the simulator is located - Known values are: - - Dallas - Chandler - SF - - - - - The CPU Class of the simulator - Most full mainland/estate sims appear to be 5, - Homesteads and Openspace appear to be 501 - - - The number of regions sharing the same CPU as this one - "Full Sims" appear to be 1, Homesteads appear to be 4 - - - The billing product name - Known values are: - - Mainland / Full Region (Sku: 023) - Estate / Full Region (Sku: 024) - Estate / Openspace (Sku: 027) - Estate / Homestead (Sku: 029) - Mainland / Homestead (Sku: 129) (Linden Owned) - Mainland / Linden Homes (Sku: 131) - - - - - The billing product SKU - Known values are: - - 023 Mainland / Full Region - 024 Estate / Full Region - 027 Estate / Openspace - 029 Estate / Homestead - 129 Mainland / Homestead (Linden Owned) - 131 Linden Homes / Full Region - - - - - - Flags indicating which protocols this region supports - - - - The current sequence number for packets sent to this - simulator. Must be Interlocked before modifying. Only - useful for applications manipulating sequence numbers - - - - A thread-safe dictionary containing avatars in a simulator - - - - - A thread-safe dictionary containing primitives in a simulator - - - - - Provides access to an internal thread-safe dictionary containing parcel - information found in this simulator - - - - - Provides access to an internal thread-safe multidimensional array containing a x,y grid mapped - to each 64x64 parcel's LocalID. - - - - - Checks simulator parcel map to make sure it has downloaded all data successfully - - true if map is full (contains no 0's) - - - - Is it safe to send agent updates to this sim - AgentMovementComplete message received - - - - The IP address and port of the server - - - Whether there is a working connection to the simulator or - not - - - Coarse locations of avatars in this simulator - - - AvatarPositions key representing TrackAgent target - - - Indicates if UDP connection to the sim is fully established - - - Used internally to track sim disconnections - - - Event that is triggered when the simulator successfully - establishes a connection - - - Whether this sim is currently connected or not. Hooked up - to the property Connected - - - Coarse locations of avatars in this simulator - - - AvatarPositions key representing TrackAgent target - - - Sequence numbers of packets we've received - (for duplicate checking) - - - Packets we sent out that need ACKs from the simulator - - - Sequence number for pause/resume - - - Indicates if UDP connection to the sim is fully established - - - - - - Reference to the GridClient object - IPEndPoint of the simulator - handle of the simulator - - - - Called when this Simulator object is being destroyed - - - - - Attempt to connect to this simulator - - Whether to move our agent in to this sim or not - True if the connection succeeded or connection status is - unknown, false if there was a failure - - - - Initiates connection to the simulator - - Should we block until ack for this packet is recieved - - - - Disconnect from this simulator - - - - - Instructs the simulator to stop sending update (and possibly other) packets - - - - - Instructs the simulator to resume sending update packets (unpause) - - - - - Retrieve the terrain height at a given coordinate - - Sim X coordinate, valid range is from 0 to 255 - Sim Y coordinate, valid range is from 0 to 255 - The terrain height at the given point if the - lookup was successful, otherwise 0.0f - True if the lookup was successful, otherwise false - - - - Sends a packet - - Packet to be sent - - - - - - - - - Returns Simulator Name as a String - - - - - - - - - - - - - - - - - - - Sends out pending acknowledgements - - Number of ACKs sent - - - - Resend unacknowledged packets - - - - - Simulator handle - - - - - Number of GridClients using this datapool - - - - - Time that the last client disconnected from the simulator - - - - - The cache of prims used and unused in this simulator - - - - - Shared parcel info only when POOL_PARCEL_DATA == true - - - - - - - - - The event subscribers, null of no subscribers - - - Raises the AttachedSound Event - A AttachedSoundEventArgs object containing - the data sent from the simulator - - - Thread sync lock object - - - Raised when the simulator sends us data containing - sound - - - The event subscribers, null of no subscribers - - - Raises the AttachedSoundGainChange Event - A AttachedSoundGainChangeEventArgs object containing - the data sent from the simulator - - - Thread sync lock object - - - Raised when the simulator sends us data containing - ... - - - The event subscribers, null of no subscribers - - - Raises the SoundTrigger Event - A SoundTriggerEventArgs object containing - the data sent from the simulator - - - Thread sync lock object - - - Raised when the simulator sends us data containing - ... - - - The event subscribers, null of no subscribers - - - Raises the PreloadSound Event - A PreloadSoundEventArgs object containing - the data sent from the simulator - - - Thread sync lock object - - - Raised when the simulator sends us data containing - ... - - - - Construct a new instance of the SoundManager class, used for playing and receiving - sound assets - - A reference to the current GridClient instance - - - - Plays a sound in the current region at full volume from avatar position - - UUID of the sound to be played - - - - Plays a sound in the current region at full volume - - UUID of the sound to be played. - position for the sound to be played at. Normally the avatar. - - - - Plays a sound in the current region - - UUID of the sound to be played. - position for the sound to be played at. Normally the avatar. - volume of the sound, from 0.0 to 1.0 - - - - Plays a sound in the specified sim - - UUID of the sound to be played. - UUID of the sound to be played. - position for the sound to be played at. Normally the avatar. - volume of the sound, from 0.0 to 1.0 - - - - Play a sound asset - - UUID of the sound to be played. - handle id for the sim to be played in. - position for the sound to be played at. Normally the avatar. - volume of the sound, from 0.0 to 1.0 - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - - - Process an incoming packet and raise the appropriate events - The sender - The EventArgs object containing the packet data - - - Provides data for the event - The event occurs when the simulator sends - the sound data which emits from an agents attachment - - The following code example shows the process to subscribe to the event - and a stub to handle the data passed from the simulator - - // Subscribe to the AttachedSound event - Client.Sound.AttachedSound += Sound_AttachedSound; - - // process the data raised in the event here - private void Sound_AttachedSound(object sender, AttachedSoundEventArgs e) - { - // ... Process AttachedSoundEventArgs here ... - } - - - - - Simulator where the event originated - - - Get the sound asset id - - - Get the ID of the owner - - - Get the ID of the Object - - - Get the volume level - - - Get the - - - - Construct a new instance of the SoundTriggerEventArgs class - - Simulator where the event originated - The sound asset id - The ID of the owner - The ID of the object - The volume level - The - - - Provides data for the event - The event occurs when an attached sound - changes its volume level - - - Simulator where the event originated - - - Get the ID of the Object - - - Get the volume level - - - - Construct a new instance of the AttachedSoundGainChangedEventArgs class - - Simulator where the event originated - The ID of the Object - The new volume level - - - Provides data for the event - The event occurs when the simulator forwards - a request made by yourself or another agent to play either an asset sound or a built in sound - - Requests to play sounds where the is not one of the built-in - will require sending a request to download the sound asset before it can be played - - - The following code example uses the , - and - properties to display some information on a sound request on the window. - - // subscribe to the event - Client.Sound.SoundTrigger += Sound_SoundTrigger; - - // play the pre-defined BELL_TING sound - Client.Sound.SendSoundTrigger(Sounds.BELL_TING); - - // handle the response data - private void Sound_SoundTrigger(object sender, SoundTriggerEventArgs e) - { - Console.WriteLine("{0} played the sound {1} at volume {2}", - e.OwnerID, e.SoundID, e.Gain); - } - - - - - Simulator where the event originated - - - Get the sound asset id - - - Get the ID of the owner - - - Get the ID of the Object - - - Get the ID of the objects parent - - - Get the volume level - - - Get the regionhandle - - - Get the source position - - - - Construct a new instance of the SoundTriggerEventArgs class - - Simulator where the event originated - The sound asset id - The ID of the owner - The ID of the object - The ID of the objects parent - The volume level - The regionhandle - The source position - - - Provides data for the event - The event occurs when the simulator sends - the appearance data for an avatar - - The following code example uses the and - properties to display the selected shape of an avatar on the window. - - // subscribe to the event - Client.Avatars.AvatarAppearance += Avatars_AvatarAppearance; - - // handle the data when the event is raised - void Avatars_AvatarAppearance(object sender, AvatarAppearanceEventArgs e) - { - Console.WriteLine("The Agent {0} is using a {1} shape.", e.AvatarID, (e.VisualParams[31] > 0) : "male" ? "female") - } - - - - - Simulator where the event originated - - - Get the sound asset id - - - Get the ID of the owner - - - Get the ID of the Object - - - - Construct a new instance of the PreloadSoundEventArgs class - - Simulator where the event originated - The sound asset id - The ID of the owner - The ID of the object - - - - pre-defined built in sounds - - - - - - - - - - - - - - - - - - - - - - - - - - - - coins - - - cash register bell - - - - - - - - - rubber - - - plastic - - - flesh - - - wood splintering? - - - glass break - - - metal clunk - - - whoosh - - - shake - - - summon - - - ding - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - A dictionary containing all pre-defined sounds - - A dictionary containing the pre-defined sounds, - where the key is the sounds ID, and the value is a string - containing a name to identify the purpose of the sound - - - X position of this patch - - - Y position of this patch - - - A 16x16 array of floats holding decompressed layer data - - - - Creates a LayerData packet for compressed land data given a full - simulator heightmap and an array of indices of patches to compress - - A 256 * 256 array of floating point values - specifying the height at each meter in the simulator - Array of indexes in the 16x16 grid of patches - for this simulator. For example if 1 and 17 are specified, patches - x=1,y=0 and x=1,y=1 are sent - - - - - Add a patch of terrain to a BitPacker - - BitPacker to write the patch to - Heightmap of the simulator, must be a 256 * - 256 float array - X offset of the patch to create, valid values are - from 0 to 15 - Y offset of the patch to create, valid values are - from 0 to 15 - - - The event subscribers. null if no subcribers - - - Raises the LandPatchReceived event - A LandPatchReceivedEventArgs object containing the - data returned from the simulator - - - Thread sync lock object - - - Raised when the simulator responds sends - - - - Default constructor - - - - - Simulator from that sent tha data - - - Sim coordinate of the patch - - - Sim coordinate of the patch - - - Size of tha patch - - - Heightmap for the patch - - - - The current status of a texture request as it moves through the pipeline or final result of a texture request. - - - - The initial state given to a request. Requests in this state - are waiting for an available slot in the pipeline - - - A request that has been added to the pipeline and the request packet - has been sent to the simulator - - - A request that has received one or more packets back from the simulator - - - A request that has received all packets back from the simulator - - - A request that has taken longer than - to download OR the initial packet containing the packet information was never received - - - The texture request was aborted by request of the agent - - - The simulator replied to the request that it was not able to find the requested texture - - - - A callback fired to indicate the status or final state of the requested texture. For progressive - downloads this will fire each time new asset data is returned from the simulator. - - The indicating either Progress for textures not fully downloaded, - or the final result of the request after it has been processed through the TexturePipeline - The object containing the Assets ID, raw data - and other information. For progressive rendering the will contain - the data from the beginning of the file. For failed, aborted and timed out requests it will contain - an empty byte array. - - - - Texture request download handler, allows a configurable number of download slots which manage multiple - concurrent texture downloads from the - - This class makes full use of the internal - system for full texture downloads. - - - - A request task containing information and status of a request as it is processed through the - - - - The current which identifies the current status of the request - - - The Unique Request ID, This is also the Asset ID of the texture being requested - - - The cancellation token for the request. - - - The ImageType of the request. - - - The callback to fire when the request is complete, will include - the and the - object containing the result data - - - If true, indicates the callback will be fired whenever new data is returned from the simulator. - This is used to progressively render textures as portions of the texture are received. - - - An object that maintains the data of an request thats in-process. - - - A dictionary containing all pending and in-process transfer requests where the Key is both the RequestID - and also the Asset Texture ID, and the value is an object containing the current state of the request and also - the asset data as it is being re-assembled - - - Holds the reference to the client object - - - Maximum concurrent texture requests allowed at a time - - - The primary thread which manages the requests. - - - The cancellation token for the TexturePipeline and all child tasks. - - - true if the TexturePipeline is currently running - - - A refresh timer used to increase the priority of stalled requests - - - Current number of pending and in-process transfers - - - - Default constructor, Instantiates a new copy of the TexturePipeline class - - Reference to the instantiated object - - - - Initialize callbacks required for the TexturePipeline to operate - - - - - Shutdown the TexturePipeline and cleanup any callbacks or transfers - - - - - Request a texture asset from the simulator using the system to - manage the requests and re-assemble the image from the packets received from the simulator - - The of the texture asset to download - The of the texture asset. - Use for most textures, or for baked layer texture assets - A float indicating the requested priority for the transfer. Higher priority values tell the simulator - to prioritize the request before lower valued requests. An image already being transferred using the can have - its priority changed by resending the request with the new priority value - Number of quality layers to discard. - This controls the end marker of the data sent - The packet number to begin the request at. A value of 0 begins the request - from the start of the asset texture - The callback to fire when the image is retrieved. The callback - will contain the result of the request and the texture asset data - If true, the callback will be fired for each chunk of the downloaded image. - The callback asset parameter will contain all previously received chunks of the texture asset starting - from the beginning of the request - - - - Sends the actual request packet to the simulator - - The image to download - Type of the image to download, either a baked - avatar texture or a normal texture - Priority level of the download. Default is - 1,013,000.0f - Number of quality layers to discard. - This controls the end marker of the data sent - Packet number to start the download at. - This controls the start marker of the data sent - Sending a priority of 0 and a discardlevel of -1 aborts - download - - - - Cancel a pending or in process texture request - - The texture assets unique ID - - - - Master Download Thread, Queues up downloads in the threadpool - - - - - The worker thread that sends the request and handles timeouts - - A object containing the request details - - - - Handle responses from the simulator that tell us a texture we have requested is unable to be located - or no longer exists. This will remove the request from the pipeline and free up a slot if one is in use - - The sender - The EventArgs object containing the packet data - - - - Handles the remaining Image data that did not fit in the initial ImageData packet - - The sender - The EventArgs object containing the packet data - - - - Handle the initial ImageDataPacket sent from the simulator - - The sender - The EventArgs object containing the packet data - - - - - - - - - Initialize the UDP packet handler in server mode - - Port to listening for incoming UDP packets on - - - - Initialize the UDP packet handler in client mode - - Remote UDP server to connect to - - - - - - - - - - - - - - - - - - Size of the byte array used to store raw packet data - - - Raw packet data buffer - - - Length of the data to transmit - - - EndPoint of the remote host - - - - Create an allocated UDP packet buffer for receiving a packet - - - - - Create an allocated UDP packet buffer for sending a packet - - EndPoint of the remote host - - - - Create an allocated UDP packet buffer for sending a packet - - EndPoint of the remote host - Size of the buffer to allocate for packet data - - - - Create an allocated UDP packet buffer for sending a packet - - - - - Create an allocated UDP packet buffer for sending a packet - - EndPoint of the remote host - The actual buffer to use for packet data (no allocation). - - - - This is used to login a specific user account(s). It may only be called after - Connector initialization has completed successfully - - Handle returned from successful Connector ‘create’ request - User's account name - User's account password - Values may be “AutoAnswerâ€� or “VerifyAnswerâ€� - "" - This is an integer that specifies how often - the daemon will send participant property events while in a channel. If this is not set - the default will be “on state changeâ€�, which means that the events will be sent when - the participant starts talking, stops talking, is muted, is unmuted. - The valid values are: - 0 – Never - 5 – 10 times per second - 10 – 5 times per second - 50 – 1 time per second - 100 – on participant state change (this is the default) - false - - - - - This is used to logout a user session. It should only be called with a valid AccountHandle. - - Handle returned from successful Connector ‘login’ request - - - - - This is used to get a list of audio devices that can be used for capture (input) of voice. - - - - - - This is used to get a list of audio devices that can be used for render (playback) of voice. - - - - - This command is used to select the render device. - - The name of the device as returned by the Aux.GetRenderDevices command. - - - - This command is used to select the capture device. - - The name of the device as returned by the Aux.GetCaptureDevices command. - - - - This command is used to start the audio capture process which will cause - AuxAudioProperty Events to be raised. These events can be used to display a - microphone VU meter for the currently selected capture device. This command - should not be issued if the user is on a call. - - (unused but required) - - - - - This command is used to stop the audio capture process. - - - - - - This command is used to set the mic volume while in the audio tuning process. - Once an acceptable mic level is attained, the application must issue a - connector set mic volume command to have that level be used while on voice - calls. - - the microphone volume (-100 to 100 inclusive) - - - - - This command is used to set the speaker volume while in the audio tuning - process. Once an acceptable speaker level is attained, the application must - issue a connector set speaker volume command to have that level be used while - on voice calls. - - the speaker volume (-100 to 100 inclusive) - - - - - This is used to initialize and stop the Connector as a whole. The Connector - Create call must be completed successfully before any other requests are made - (typically during application initialization). The shutdown should be called - when the application is shutting down to gracefully release resources - - A string value indicting the Application name - URL for the management server - LoggingSettings - - - - - - Shutdown Connector -- Should be called when the application is shutting down - to gracefully release resources - - Handle returned from successful Connector ‘create’ request - - - - Mute or unmute the microphone - - Handle returned from successful Connector ‘create’ request - true (mute) or false (unmute) - - - - Mute or unmute the speaker - - Handle returned from successful Connector ‘create’ request - true (mute) or false (unmute) - - - - Set microphone volume - - Handle returned from successful Connector ‘create’ request - The level of the audio, a number between -100 and 100 where - 0 represents ‘normal’ speaking volume - - - - Set local speaker volume - - Handle returned from successful Connector ‘create’ request - The level of the audio, a number between -100 and 100 where - 0 represents ‘normal’ speaking volume - - - - List of audio input devices - - - - - List of audio output devices - - - - - Start up the Voice service. - - - - - Handle miscellaneous request status - - - - ///If something goes wrong, we log it. - - - - Cleanup oject resources - - - - - Request voice cap when changing regions - - - - - Handle a change in session state - - - - - Close a voice session - - - - - - Locate a Session context from its handle - - Creates the session context if it does not exist. - - - - Handle completion of main voice cap request. - - - - - - - - Daemon has started so connect to it. - - - - - The daemon TCP connection is open. - - - - - Handle creation of the Connector. - - - - - Handle response to audio output device query - - - - - Handle response to audio input device query - - - - - Set audio test mode - - - - - Set voice channel for new parcel - - - - - - Request info from a parcel capability Uri. - - - - - - Receive parcel voice cap - - - - - - - - Tell Vivox where we are standing - - This has to be called when we move or turn. - - - - Start and stop updating out position. - - - - - Enable logging - - - The folder where any logs will be created - - - This will be prepended to beginning of each log file - - - The suffix or extension to be appended to each log file - - - - 0: NONE - No logging - 1: ERROR - Log errors only - 2: WARNING - Log errors and warnings - 3: INFO - Log errors, warnings and info - 4: DEBUG - Log errors, warnings, info and debug - - - - - Constructor for default logging settings - - - - Audio Properties Events are sent after audio capture is started. These events are used to display a microphone VU meter - - - - Event for most mundane request reposnses. - - - - Response to Connector.Create request - - - Response to Aux.GetCaptureDevices request - - - Response to Aux.GetRenderDevices request - - - Audio Properties Events are sent after audio capture is started. - These events are used to display a microphone VU meter - - - Response to Account.Login request - - - This event message is sent whenever the login state of the - particular Account has transitioned from one value to another - - - - Starts a thread that keeps the daemon running - - - - - - - Stops the daemon and the thread keeping it running - - - - - - - - - - - - - Create a Session - Sessions typically represent a connection to a media session with one or more - participants. This is used to generate an ‘outbound’ call to another user or - channel. The specifics depend on the media types involved. A session handle is - required to control the local user functions within the session (or remote - users if the current account has rights to do so). Currently creating a - session automatically connects to the audio media, there is no need to call - Session.Connect at this time, this is reserved for future use. - - Handle returned from successful Connector ‘create’ request - This is the URI of the terminating point of the session (ie who/what is being called) - This is the display name of the entity being called (user or channel) - Only needs to be supplied when the target URI is password protected - This indicates the format of the password as passed in. This can either be - “ClearTextâ€� or “SHA1UserNameâ€�. If this element does not exist, it is assumed to be “ClearTextâ€�. If it is - “SHA1UserNameâ€�, the password as passed in is the SHA1 hash of the password and username concatenated together, - then base64 encoded, with the final “=â€� character stripped off. - - - - - - - Used to accept a call - - SessionHandle such as received from SessionNewEvent - "default" - - - - - This command is used to start the audio render process, which will then play - the passed in file through the selected audio render device. This command - should not be issued if the user is on a call. - - The fully qualified path to the sound file. - True if the file is to be played continuously and false if it is should be played once. - - - - - This command is used to stop the audio render process. - - The fully qualified path to the sound file issued in the start render command. - - - - - This is used to ‘end’ an established session (i.e. hang-up or disconnect). - - Handle returned from successful Session ‘create’ request or a SessionNewEvent - - - - - Set the combined speaking and listening position in 3D space. - - Handle returned from successful Session ‘create’ request or a SessionNewEvent - Speaking position - Listening position - - - - - Set User Volume for a particular user. Does not affect how other users hear that user. - - Handle returned from successful Session ‘create’ request or a SessionNewEvent - - The level of the audio, a number between -100 and 100 where 0 represents ‘normal’ speaking volume - - - - Positional vector of the users position - - - Velocity vector of the position - - - At Orientation (X axis) of the position - - - Up Orientation (Y axis) of the position - - - Left Orientation (Z axis) of the position - - - - Extract the avatar UUID encoded in a SIP URI - - - - - - - Represents a single Voice Session to the Vivox service. - - - - - Close this session. - - - - - Look up an existing Participants in this session - - - - - - - - - - - - - - - - - - - - - Operation to apply when applying color to texture - - - - - Information needed to translate visual param value to RGBA color - - - - - Construct VisualColorParam - - Operation to apply when applying color to texture - Colors - - - - Represents alpha blending and bump infor for a visual parameter - such as sleive length - - - - Stregth of the alpha to apply - - - File containing the alpha channel - - - Skip blending if parameter value is 0 - - - Use miltiply insted of alpha blending - - - - Create new alhpa information for a visual param - - Stregth of the alpha to apply - File containing the alpha channel - Skip blending if parameter value is 0 - Use miltiply insted of alpha blending - - - - A single visual characteristic of an avatar mesh, such as eyebrow height - - - - Index of this visual param - - - Internal name - - - Group ID this parameter belongs to - - - Name of the wearable this parameter belongs to - - - Displayable label of this characteristic - - - Displayable label for the minimum value of this characteristic - - - Displayable label for the maximum value of this characteristic - - - Default value - - - Minimum value - - - Maximum value - - - Is this param used for creation of bump layer? - - - Alpha blending/bump info - - - Color information - - - Array of param IDs that are drivers for this parameter - - - - Set all the values through the constructor - - Index of this visual param - Internal name - - - Displayable label of this characteristic - Displayable label for the minimum value of this characteristic - Displayable label for the maximum value of this characteristic - Default value - Minimum value - Maximum value - Is this param used for creation of bump layer? - Array of param IDs that are drivers for this parameter - Alpha blending/bump info - Color information - - - - Holds the Params array of all the avatar appearance parameters - - - - A reference to the current instance - - - - Construct a new instance of the UserReport class - - A reference to the current instance - - - - - - Sends user report first by trying SendUserReport sim cap, falling back to legacy - - - - - - - - - - - - - - - Sends user report using legacy lludp packet - - - - - - - - - - - - - - - - - - - - Delegate to wrap another delegate and its arguments - - - - - - - An instance of DelegateWrapper which calls InvokeWrappedDelegate, - which in turn calls the DynamicInvoke method of the wrapped - delegate - - - - - Callback used to call EndInvoke on the asynchronously - invoked DelegateWrapper - - - - - Executes the specified delegate with the specified arguments - asynchronously on a thread pool thread - - - - - - - Invokes the wrapped delegate synchronously - - - - - - - Calls EndInvoke on the wrapper and Close on the resulting WaitHandle - to prevent resource leaks - - - - - diff --git a/LibreMetaverse/LibreMetaverse.csproj b/LibreMetaverse/LibreMetaverse.csproj index 698b811..8422941 100644 --- a/LibreMetaverse/LibreMetaverse.csproj +++ b/LibreMetaverse/LibreMetaverse.csproj @@ -1,160 +1,67 @@ - - - Local - 14.0.25123 - 2.0 - {27C70F3A-0000-0000-0000-000000000000} - Debug - LibreMetaverse - JScript - Grid - IE50 - false - Library - LibreMetaverse - true - true - netstandard2.0;netstandard2.1;net5.0 - AnyCPU;x64;x86 - - - True - 285212672 - False - TRACE;DEBUG - True - 4096 - False - ..\bin\ - False - False - False - 4 - False - 1591,1574,0419 - AnyCPU - - - True - 285212672 - False - TRACE;DEBUG - True - 4096 - False - ..\bin\ - False - False - False - 4 - False - 1591,1574,0419 - AnyCPU - - - True - 285212672 - False - TRACE;DEBUG - True - 4096 - False - ..\bin\ - False - False - False - 4 - False - 1591,1574,0419 - AnyCPU - - - True - 285212672 - False - TRACE - LibreMetaverse.XML - False - 4096 - True - ..\bin\ - False - False - False - 4 - False - 1591,1574,0419 - AnyCPU - - - True - 285212672 - False - TRACE - LibreMetaverse.XML - False - 4096 - True - ..\bin\ - False - False - False - 4 - False - 1591,1574,0419 - AnyCPU - - - True - 285212672 - False - TRACE - LibreMetaverse.XML - False - 4096 - True - ..\bin\ - False - False - False - 4 - False - 1591,1574,0419 - AnyCPU - - - - - - - - - - - - - - - - - - - - - True - - - - - - - - - 1.2.0 - Sjofn LLC, OpenMetaverse Developers - LibreMetaverse - Copyright © OpenMetaverse Developers 2008, 2017. Copyright © Sjofn LLC 2018-2021. All rights reserved. - LICENSE.txt - https://github.com/cinderblocks/libremetaverse - + + + LibreMetaverse + LibreMetaverse + LibreMetaverse allows your code to read and work with data send across a SecondLife, Halcyon, OpenSimulator, or related connection. + Library + LibreMetaverse + true + true + true + true + snupkg + 0419,1574,1591 + netstandard2.0;netstandard2.1;net5.0 + x64;x86;AnyCPU + ..\bin\ + + + TRACE;DEBUG + + + TRACE;DEBUG + + + TRACE;DEBUG + + + true + pdbonly + TRACE + True + + + true + pdbonly + TRACE + True + + + true + pdbonly + TRACE + True + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/LibreMetaverse/LibreMetaverse.nuspec b/LibreMetaverse/LibreMetaverse.nuspec deleted file mode 100644 index d4a4903..0000000 --- a/LibreMetaverse/LibreMetaverse.nuspec +++ /dev/null @@ -1,15 +0,0 @@ - - - - LibreMetaverse - $version$ - Cinder Biscuits - Cinder Biscuits - https://github.com/cinderblocks/libremetaverse/blob/master/LICENSE.txt - https://github.com/cinderblocks/libremetaverse - false - LibreMetaverse allows your code to read and work with data send across a SecondLife, Halcyon, OpenSimulator, or related connection. - Copyright 2017 - LMV OMV OpenMetaverse OpenSim OpenSimulator Halcyon OpenMetaverseFoundation VirtualWorld Radegast SecondLife - - \ No newline at end of file diff --git a/LibreMetaverse/LocationParser.cs b/LibreMetaverse/LocationParser.cs new file mode 100644 index 0000000..8592489 --- /dev/null +++ b/LibreMetaverse/LocationParser.cs @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2022, Sjofn, LLC + * 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 openmetaverse.co 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; + +namespace OpenMetaverse +{ + public class LocationParser + { + public string Sim { get; } + public int X { get; } + public int Y { get; } + public int Z { get; } + + public LocationParser(string location) + { + if (location == null ) { throw new ArgumentNullException("Location cannot be null."); } + if (location.Length == 0) { throw new ArgumentException("Location cannot be empty."); } + + string toParse; + if (location.StartsWith("secondlife://")) { toParse = location.Substring(13); } + else if (location.StartsWith("uri:")) { toParse = location.Substring(4); } + else { toParse = location; } + + string[] elements = toParse.Split('/'); + Sim = elements[0]; + int parsed; + X = (elements.Length > 1 && int.TryParse(elements[1], out parsed)) ? parsed : 128; + Y = (elements.Length > 2 && int.TryParse(elements[2], out parsed)) ? parsed : 128; + Z = (elements.Length > 3 && int.TryParse(elements[3], out parsed)) ? parsed : 0; + } + + public string GetRawLocation() + { + return $"{Sim}/{X}/{Y}/{Z}"; + } + + public string GetSlurl() + { + return $"secondlife://{Sim}/{X}/{Y}/{Z}/"; + } + + public string GetStartLocationUri() + { + return $"uri:{Sim}&{X}&{Y}&{Z}"; + } + } +} diff --git a/LibreMetaverse/Login.cs b/LibreMetaverse/Login.cs index 0e83bb4..bc7ca46 100644 --- a/LibreMetaverse/Login.cs +++ b/LibreMetaverse/Login.cs @@ -1,6 +1,6 @@ /* * Copyright (c) 2006-2016, openmetaverse.co - * Copyright (c) 2019-2020, Sjofn, LLC + * Copyright (c) 2019-2022, Sjofn, LLC * All rights reserved. * * - Redistribution and use in source and binary forms, with or without @@ -35,7 +35,6 @@ using System.Collections.Generic; using System.Linq; using System.Net; using System.Net.Http; -using System.Net.NetworkInformation; using System.Security.Cryptography; using System.Text; using System.Threading; @@ -90,6 +89,28 @@ namespace OpenMetaverse #region Structs + public class LoginCredential + { + public string FirstName { get; private set; } + public string LastName { get; private set; } + public string Password { get; private set; } + public string Token { get; private set; } + public string MfaHash { get; private set; } + + public LoginCredential(string first, string last, string passwd, string token, string mfaHash) + { + FirstName = first; + LastName = last; + Password = passwd; + Token = token; + MfaHash = mfaHash; + } + + public LoginCredential(string first, string last, string passwd) + : this(first, last, passwd, string.Empty, string.Empty) + { } + } + /// /// Login Request Parameters /// @@ -110,10 +131,16 @@ namespace OpenMetaverse /// A md5 hashed password /// plaintext password will be automatically hashed public string Password; + /// The user's entered Time based One Time Password (TOTP) token. + /// This should be the empty string for login attempts that are not responding to an MFA challenge. + public string Token; + /// The saved hash value and timestamp from a previously successfully answered MFA challenge. + /// This should be the empty string initially. + public string MfaHash; /// The agents starting location home or last - /// Please use LoginLocation for custom region and Location + /// Either "last", "home", or a string encoded URI + /// containing the simulator name and x/y/z coordinates e.g: uri:hooper&128&152&17 public string Start; - /// A string containing the client software channel information /// Second Life Release public string Channel; @@ -145,7 +172,7 @@ namespace OpenMetaverse public LastExecStatus LastExecEvent; /// An array of string sent to the login server to enable various options - public string[] Options; + public List Options; /// A randomly generated ID to distinguish between login attempts. This value is only used /// internally in the library and is never sent over the wire @@ -153,9 +180,13 @@ namespace OpenMetaverse /// LoginLocation used to set the starting region and location (overrides Start) example: "Tentacles/128/64/109" /// Leave empty to use the starting location - public string LoginLocation; - - + public string LoginLocation; + + /// + /// Is the client Multi-Factor Authentication enabled + /// + public bool MfaEnabled; + /// /// Default constructor, initializes sane default values /// @@ -202,7 +233,7 @@ namespace OpenMetaverse "search" }; - Options = options.ToArray(); + Options = options; // *TODO: include library and opensim options when we support them MethodName = "login_to_simulator"; Start = "last"; @@ -216,6 +247,44 @@ namespace OpenMetaverse LastExecEvent = LastExecStatus.Normal; } + /// + /// Instantiate LoginParams + /// + /// Use this constructor if Application supports multi-factor authentication + /// Instance of + /// Instance of + /// Login channel (application name) + /// Client version, as application name + version number + public LoginParams(GridClient client, LoginCredential credential, string channel, string version) + : this() + { + URI = client.Settings.LOGIN_SERVER; + Timeout = client.Settings.LOGIN_TIMEOUT; + MfaEnabled = client.Settings.MFA_ENABLED; + FirstName = credential.FirstName; + LastName = credential.LastName; + Password = credential.Password; + Token = credential.Token; + MfaHash = credential.MfaHash; + Channel = channel; + Version = version; + } + + /// + /// Instantiate LoginParams + /// + /// Use this constructor if Application supports multi-factor authentication + /// Instance of + /// Instance of + /// Login channel (application name) + /// Client version, as application name + version number + /// Address of login service + public LoginParams(GridClient client, LoginCredential credential, string channel, string version, string loginUri) + : this(client, credential, channel, version) + { + URI = loginUri; + } + /// /// Instantiates new LoginParams object and fills in the values /// @@ -225,7 +294,8 @@ namespace OpenMetaverse /// Password /// Login channel (application name) /// Client version, should be application name + version number - public LoginParams(GridClient client, string firstName, string lastName, string password, string channel, string version) + public LoginParams(GridClient client, string firstName, string lastName, string password, + string channel, string version) : this() { URI = client.Settings.LOGIN_SERVER; @@ -244,10 +314,11 @@ namespace OpenMetaverse /// Login first name /// Login last name /// Password - /// Login channnel (application name) + /// Login channel (application name) /// Client version, should be application name + version number /// URI of the login server - public LoginParams(GridClient client, string firstName, string lastName, string password, string channel, string version, string loginURI) + public LoginParams(GridClient client, string firstName, string lastName, string password, + string channel, string version, string loginURI) : this(client, firstName, lastName, password, channel, version) { URI = loginURI; @@ -261,6 +332,13 @@ namespace OpenMetaverse public int BuddyRightsHas; } + public struct HomeInfo + { + public ulong RegionHandle; + public Vector3 Position; + public Vector3 LookAt; + } + /// /// The decoded data returned from the login server after a successful login /// @@ -273,18 +351,21 @@ namespace OpenMetaverse public string Reason; /// Login message of the day public string Message; + public bool FirstLogin; public UUID AgentID; public UUID SessionID; public UUID SecureSessionID; + public string MfaHash; public string FirstName; public string LastName; public string StartLocation; - /// M or PG, also agent_region_access and agent_access_max + public string AccountType; public string AgentAccess; + public string AgentAccessMax; + public string AgentRegionAccess; + public string InitialOutfit; public Vector3 LookAt; - public ulong HomeRegion; - public Vector3 HomePosition; - public Vector3 HomeLookAt; + public HomeInfo Home; public int CircuitCode; public uint RegionX; public uint RegionY; @@ -294,6 +375,18 @@ namespace OpenMetaverse public BuddyListEntry[] BuddyList; public int SecondsSinceEpoch; public string UDPBlacklist; + public int MaxAgentGroups; + public string OpenIDUrl; + public string AgentAppearanceServiceURL; + public string MapServerUrl; + public string SnapshotConfigUrl; + public uint COFVersion; + public Hashtable AccountLevelBenefits; + public Hashtable PremiumPackages; + public ArrayList ClassifiedCategories; + public ArrayList EventCategories; + public ArrayList GlobalTextures; + public ArrayList UiConfig; #region Inventory @@ -302,6 +395,7 @@ namespace OpenMetaverse public InventoryFolder[] InventorySkeleton; public InventoryFolder[] LibrarySkeleton; public UUID LibraryOwner; + public Dictionary Gestures; #endregion @@ -314,19 +408,6 @@ namespace OpenMetaverse #endregion - // These aren't currently being utilized by the library - public string AgentAccessMax; - public string AgentRegionAccess; - public int AOTransition; - public string InventoryHost; - public int MaxAgentGroups; - public string OpenIDUrl; - public string AgentAppearanceServiceURL; - public uint COFVersion; - public string InitialOutfit; - public bool FirstLogin; - public Dictionary Gestures; - /// /// Parse LLSD Login Reply Data /// @@ -341,10 +422,12 @@ namespace OpenMetaverse AgentID = ParseUUID("agent_id", reply); SessionID = ParseUUID("session_id", reply); SecureSessionID = ParseUUID("secure_session_id", reply); - FirstName = ParseString("first_name", reply).Trim('"'); - LastName = ParseString("last_name", reply).Trim('"'); + FirstName = ParseString("first_name", reply).Trim('"').Trim(); // lol but necessary, unfortunately. + LastName = ParseString("last_name", reply).Trim('"').Trim(); StartLocation = ParseString("start_location", reply); AgentAccess = ParseString("agent_access", reply); + AgentAccessMax = ParseString("agent_access_max", reply); + AgentRegionAccess = ParseString("agent_region_access", reply); LookAt = ParseVector3("look_at", reply); Reason = ParseString("reason", reply); Message = ParseString("message", reply); @@ -354,40 +437,59 @@ namespace OpenMetaverse } catch (OSDException e) { - Logger.Log("Login server returned (some) invalid data: " + e.Message, Helpers.LogLevel.Warning); + Logger.Log("Login server returned (some) invalid data", Helpers.LogLevel.Warning, e); } // Home - OSD osdHome = OSDParser.DeserializeLLSDNotation(reply["home"].AsString()); - - if (osdHome.Type == OSDType.Map) + if (reply.ContainsKey("home_info")) { - var home = (OSDMap)osdHome; - - OSD homeRegion; - if (home.TryGetValue("region_handle", out homeRegion) && homeRegion.Type == OSDType.Array) + if (reply["home_info"].Type == OSDType.Map) { - OSDArray homeArray = (OSDArray)homeRegion; - HomeRegion = homeArray.Count == 2 - ? Utils.UIntsToLong((uint)homeArray[0].AsInteger(), (uint)homeArray[1].AsInteger()) - : 0; - } + var map = (OSDMap)reply["home_info"]; + Home.Position = ParseVector3("position", map); + Home.LookAt = ParseVector3("look_at", map); - HomePosition = ParseVector3("position", home); - HomeLookAt = ParseVector3("look_at", home); + var coords = (OSDArray)OSDParser.DeserializeLLSDNotation(map["region_handle"].ToString()); + if (coords.Type == OSDType.Array) + { + Home.RegionHandle = (coords.Count == 2) + ? Utils.UIntsToLong((uint)coords[0].AsInteger(), (uint)coords[1].AsInteger()) : 0; + } + } + } + else if (reply.ContainsKey("home")) + { + var osdHome = OSDParser.DeserializeLLSDNotation(reply["home"].AsString()); + + if (osdHome.Type == OSDType.Map) + { + var home = (OSDMap)osdHome; + + OSD homeRegion; + if (home.TryGetValue("region_handle", out homeRegion) && homeRegion.Type == OSDType.Array) + { + var homeArray = (OSDArray)homeRegion; + Home.RegionHandle = homeArray.Count == 2 + ? Utils.UIntsToLong((uint)homeArray[0].AsInteger(), (uint)homeArray[1].AsInteger()) + : 0; + } + + Home.Position = ParseVector3("position", home); + Home.LookAt = ParseVector3("look_at", home); + } } else { - HomeRegion = 0; - HomePosition = Vector3.Zero; - HomeLookAt = Vector3.Zero; + Home.RegionHandle = 0; + Home.Position = Vector3.Zero; + Home.LookAt = Vector3.Zero; } CircuitCode = (int)ParseUInt("circuit_code", reply); RegionX = ParseUInt("region_x", reply); RegionY = ParseUInt("region_y", reply); SimPort = (ushort)ParseUInt("sim_port", reply); - string simIP = ParseString("sim_ip", reply); + var simIP = ParseString("sim_ip", reply); IPAddress.TryParse(simIP, out SimIP); SeedCapability = ParseString("seed_capability", reply); @@ -395,14 +497,14 @@ namespace OpenMetaverse OSD buddyLLSD; if (reply.TryGetValue("buddy-list", out buddyLLSD) && buddyLLSD.Type == OSDType.Array) { - List buddys = new List(); - OSDArray buddyArray = (OSDArray)buddyLLSD; - foreach (OSD t in buddyArray) + var buddys = new List(); + var buddyArray = (OSDArray)buddyLLSD; + foreach (var t in buddyArray) { if (t.Type == OSDType.Map) { - BuddyListEntry bud = new BuddyListEntry(); - OSDMap buddy = (OSDMap)t; + var bud = new BuddyListEntry(); + var buddy = (OSDMap)t; bud.BuddyId = buddy["buddy_id"].AsString(); bud.BuddyRightsGiven = (int)ParseUInt("buddy_rights_given", buddy); @@ -422,6 +524,68 @@ namespace OpenMetaverse LibraryOwner = ParseMappedUUID("inventory-lib-owner", "agent_id", reply); LibraryRoot = ParseMappedUUID("inventory-lib-root", "folder_id", reply); LibrarySkeleton = ParseInventorySkeleton("inventory-skel-lib", reply); + + if (reply.ContainsKey("mfa_hash")) + { + MfaHash = ParseString("mfa_hash", reply); + } + + if (reply.ContainsKey("account_level_benefits")) + { + if (reply["account_level_benefits"].Type == OSDType.Map) + { + AccountLevelBenefits = ((OSDMap)reply["account_level_benefits"]).ToHashtable(); + } + } + + if (reply.ContainsKey("classified_categories")) + { + if (reply["classified_categories"].Type == OSDType.Array) + { + ClassifiedCategories = ((OSDArray)reply["classified_categories"]).ToArrayList(); + } + } + + if (reply.ContainsKey("event_categories")) + { + if (reply["event_categories"].Type == OSDType.Array) + { + EventCategories = ((OSDArray)reply["event_categories"]).ToArrayList(); + } + } + + if (reply.ContainsKey("global-textures")) + { + if (reply["global-textures"].Type == OSDType.Array) + { + GlobalTextures = ((OSDArray)reply["global-textures"]).ToArrayList(); + } + } + + if (reply.ContainsKey("premium_packages")) + { + if (reply["premium_packages"].Type == OSDType.Map) + { + PremiumPackages = ((OSDMap)reply["premium_packages"]).ToHashtable(); + } + } + + if (reply.ContainsKey("ui-config")) + { + if (reply["ui-config"].Type == OSDType.Array) + { + UiConfig = ((OSDArray)reply["ui-config"]).ToArrayList(); + } + } + + if (reply.ContainsKey("max-agent-groups")) + { + MaxAgentGroups = (int)ParseUInt("max-agent-groups", reply); + } + else + { + MaxAgentGroups = -1; + } } public void Parse(Hashtable reply) @@ -459,49 +623,78 @@ namespace OpenMetaverse { Logger.Log("Login server returned (some) invalid data: " + e.Message, Helpers.LogLevel.Warning); } - if (!Success) - return; - - // Home - HomeRegion = 0; - HomePosition = Vector3.Zero; - HomeLookAt = Vector3.Zero; - if (reply.ContainsKey("home")) + if (!Success) { return; } + + // HomeInfo + try { - try - { - OSD osdHome = OSDParser.DeserializeLLSDNotation(reply["home"].ToString()); - - if (osdHome.Type == OSDType.Map) - { - var home = (OSDMap)osdHome; - - OSD homeRegion; - if (home.TryGetValue("region_handle", out homeRegion) && homeRegion.Type == OSDType.Array) - { - OSDArray homeArray = (OSDArray)homeRegion; - if (homeArray.Count == 2) - HomeRegion = Utils.UIntsToLong((uint)homeArray[0].AsInteger(), - (uint)homeArray[1].AsInteger()); - else - HomeRegion = 0; - } - - HomePosition = ParseVector3("position", home); - HomeLookAt = ParseVector3("look_at", home); + if (reply.ContainsKey("home_info")) + { + if (reply?["home_info"] is Hashtable map) + { + Home.Position = ParseVector3("position", map); + Home.LookAt = ParseVector3("look_at", map); + + var coords = (OSDArray)OSDParser.DeserializeLLSDNotation(map["region_handle"].ToString()); + if (coords.Type == OSDType.Array) + { + Home.RegionHandle = (coords.Count == 2) + ? Utils.UIntsToLong((uint)coords[0].AsInteger(), (uint)coords[1].AsInteger()) : 0; + } } } - catch (Exception e) - { - Logger.Log("Unable to unpack home location: " + e.Message, Helpers.LogLevel.Warning); + + // Home + if (Home.RegionHandle == 0 && reply.ContainsKey("home")) + { + if (reply?["home"] is Hashtable map) + { + Home.Position = ParseVector3("position", map); + Home.LookAt = ParseVector3("look_at", map); + + var coords = (OSDArray)OSDParser.DeserializeLLSDNotation(map["region_handle"].ToString()); + if (coords.Type == OSDType.Array) + { + Home.RegionHandle = (coords.Count == 2) + ? Utils.UIntsToLong((uint)coords[0].AsInteger(), (uint)coords[1].AsInteger()) : 0; + } + } + else if (reply?["home"] is string osdString) + { + var osdHome = OSDParser.DeserializeLLSDNotation(reply["home"].ToString()); + + if (osdHome.Type == OSDType.Map) + { + var home = (OSDMap)osdHome; + + OSD homeRegion; + if (home.TryGetValue("region_handle", out homeRegion) && homeRegion.Type == OSDType.Array) + { + var coords = (OSDArray)homeRegion; + Home.RegionHandle = (coords.Count == 2) + ? Utils.UIntsToLong((uint)coords[0].AsInteger(), (uint)coords[1].AsInteger()) : 0; + + } + Home.Position = ParseVector3("position", home); + Home.LookAt = ParseVector3("look_at", home); + } + } + else + { + throw new Exception("Could not parse 'home' in Login Response"); + } } + } catch (Exception ex) + { + Logger.Log("Could not parse home info from login response. Setting nil", Helpers.LogLevel.Warning, ex); + Home = new HomeInfo(); } CircuitCode = (int)ParseUInt("circuit_code", reply); RegionX = ParseUInt("region_x", reply); RegionY = ParseUInt("region_y", reply); SimPort = (ushort)ParseUInt("sim_port", reply); - string simIP = ParseString("sim_ip", reply); + var simIP = ParseString("sim_ip", reply); IPAddress.TryParse(simIP, out SimIP); SeedCapability = ParseString("seed_capability", reply); @@ -513,14 +706,14 @@ namespace OpenMetaverse var buddyArray = (ArrayList)reply["buddy-list"]; foreach (var t in buddyArray) { - if (!(t is Hashtable)) continue; + if (!(t is Hashtable buddy)) continue; - var bud = new BuddyListEntry(); - var buddy = (Hashtable)t; - - bud.BuddyId = ParseString("buddy_id", buddy); - bud.BuddyRightsGiven = (int)ParseUInt("buddy_rights_given", buddy); - bud.BuddyRightsHas = (int)ParseUInt("buddy_rights_has", buddy); + var bud = new BuddyListEntry + { + BuddyId = ParseString("buddy_id", buddy), + BuddyRightsGiven = (int)ParseUInt("buddy_rights_given", buddy), + BuddyRightsHas = (int)ParseUInt("buddy_rights_has", buddy) + }; buddys.Add(bud); } @@ -536,11 +729,66 @@ namespace OpenMetaverse LibraryOwner = ParseMappedUUID("inventory-lib-owner", "agent_id", reply); LibraryRoot = ParseMappedUUID("inventory-lib-root", "folder_id", reply); LibrarySkeleton = ParseInventorySkeleton("inventory-skel-lib", reply); + + AccountType = ParseString("account_type", reply); + AgentAppearanceServiceURL = ParseString("agent_appearance_service", reply); + COFVersion = ParseUInt("cof_version", reply); + MapServerUrl = ParseString("map-server-url", reply); + OpenIDUrl = ParseString("openid_url", reply); + SnapshotConfigUrl = ParseString("snapshot_config_url", reply); + UDPBlacklist = ParseString("udp_blacklist", reply); - // UDP Blacklist - if (reply.ContainsKey("udp_blacklist")) + if (reply.ContainsKey("mfa_hash")) { - UDPBlacklist = ParseString("udp_blacklist", reply); + MfaHash = ParseString("mfa_hash", reply); + } + + if (reply.ContainsKey("account_level_benefits")) + { + if (reply?["account_level_benefits"] is Hashtable) + { + AccountLevelBenefits = (Hashtable)reply["account_level_benefits"]; + } + } + + if (reply.ContainsKey("classified_categories")) + { + if (reply?["classified_categories"] is ArrayList) + { + ClassifiedCategories = (ArrayList)reply["classified_categories"]; + } + } + + if (reply.ContainsKey("event_categories")) + { + if (reply?["event_categories"] is ArrayList) + { + EventCategories = (ArrayList)reply["event_categories"]; + } + } + + if (reply.ContainsKey("global-textures")) + { + if (reply?["global-textures"] is ArrayList) + { + GlobalTextures = (ArrayList)reply["global-textures"]; + } + } + + if (reply.ContainsKey("premium_packages")) + { + if (reply?["premium_packages"] is Hashtable) + { + PremiumPackages = (Hashtable)reply["premium_packages"]; + } + } + + if (reply.ContainsKey("ui-config")) + { + if (reply?["ui-config"] is ArrayList) + { + UiConfig = (ArrayList)reply["ui-config"]; + } } if (reply.ContainsKey("max-agent-groups")) @@ -552,21 +800,6 @@ namespace OpenMetaverse MaxAgentGroups = -1; } - if (reply.ContainsKey("openid_url")) - { - OpenIDUrl = ParseString("openid_url", reply); - } - - if (reply.ContainsKey("agent_appearance_service")) - { - AgentAppearanceServiceURL = ParseString("agent_appearance_service", reply); - } - - COFVersion = 0; - if (reply.ContainsKey("cof_version")) - { - COFVersion = ParseUInt("cof_version", reply); - } InitialOutfit = string.Empty; if (reply.ContainsKey("initial-outfit") && reply["initial-outfit"] is ArrayList) @@ -574,9 +807,8 @@ namespace OpenMetaverse var array = (ArrayList)reply["initial-outfit"]; foreach (var t in array) { - if (!(t is Hashtable)) continue; + if (!(t is Hashtable map)) continue; - var map = (Hashtable)t; InitialOutfit = ParseString("folder_name", map); } } @@ -614,9 +846,8 @@ namespace OpenMetaverse var array = (ArrayList)reply["login-flags"]; foreach (var t in array) { - if (!(t is Hashtable)) continue; + if (!(t is Hashtable map)) continue; - var map = (Hashtable)t; FirstLogin = ParseString("ever_logged_in", map) == "N"; } } @@ -660,12 +891,12 @@ namespace OpenMetaverse public static string ParseString(string key, OSDMap reply) { OSD osd; - return reply.TryGetValue(key, out osd) ? osd.AsString() : String.Empty; + return reply.TryGetValue(key, out osd) ? osd.AsString() : string.Empty; } public static string ParseString(string key, Hashtable reply) { - return reply.ContainsKey(key) ? $"{reply[key]}" : String.Empty; + return reply.ContainsKey(key) ? $"{reply[key]}" : string.Empty; } public static Vector3 ParseVector3(string key, OSDMap reply) @@ -678,7 +909,7 @@ namespace OpenMetaverse case OSDType.Array: return ((OSDArray)osd).AsVector3(); case OSDType.String: - OSDArray array = (OSDArray)OSDParser.DeserializeLLSDNotation(osd.AsString()); + var array = (OSDArray)OSDParser.DeserializeLLSDNotation(osd.AsString()); return array.AsVector3(); } @@ -696,16 +927,16 @@ namespace OpenMetaverse if (list.Count == 3) { float x, y, z; - Single.TryParse((string)list[0], out x); - Single.TryParse((string)list[1], out y); - Single.TryParse((string)list[2], out z); + float.TryParse((string)list[0], out x); + float.TryParse((string)list[1], out y); + float.TryParse((string)list[2], out z); return new Vector3(x, y, z); } } else if (value is string str) { - OSDArray array = (OSDArray)OSDParser.DeserializeLLSDNotation(str); + var array = (OSDArray)OSDParser.DeserializeLLSDNotation(str); return array.AsVector3(); } @@ -715,12 +946,12 @@ namespace OpenMetaverse public static UUID ParseMappedUUID(string key, string key2, OSDMap reply) { OSD folderOSD; - if (!reply.TryGetValue(key, out folderOSD) || folderOSD.Type != OSDType.Array) { return UUID.Zero; } + if (!reply.TryGetValue(key, out folderOSD) || folderOSD.Type != OSDType.Array) {return UUID.Zero;} - OSDArray array = (OSDArray)folderOSD; + var array = (OSDArray)folderOSD; if (array.Count == 1 && array[0].Type == OSDType.Map) { - OSDMap map = (OSDMap)array[0]; + var map = (OSDMap)array[0]; OSD folder; if (map.TryGetValue(key2, out folder)) return folder.AsUUID(); @@ -731,7 +962,7 @@ namespace OpenMetaverse public static UUID ParseMappedUUID(string key, string key2, Hashtable reply) { - if (!reply.ContainsKey(key) || !(reply[key] is ArrayList)) { return UUID.Zero; } + if (!reply.ContainsKey(key) || !(reply[key] is ArrayList)) {return UUID.Zero;} var array = (ArrayList)reply[key]; if (array.Count == 1 && array[0] is Hashtable) @@ -745,25 +976,25 @@ namespace OpenMetaverse public static InventoryFolder[] ParseInventoryFolders(string key, UUID owner, OSDMap reply) { - List folders = new List(); + var folders = new List(); OSD skeleton; - if (!reply.TryGetValue(key, out skeleton) || skeleton.Type != OSDType.Array) { return folders.ToArray(); } + if (!reply.TryGetValue(key, out skeleton) || skeleton.Type != OSDType.Array) {return folders.ToArray();} - OSDArray array = (OSDArray)skeleton; + var array = (OSDArray)skeleton; - folders.AddRange(from t in array - where t.Type == OSDType.Map - select (OSDMap)t - into map - select new InventoryFolder(map["folder_id"].AsUUID()) - { - PreferredType = (FolderType)map["type_default"].AsInteger(), - Version = map["version"].AsInteger(), - OwnerID = owner, - ParentUUID = map["parent_id"].AsUUID(), - Name = map["name"].AsString() - }); + folders.AddRange(from t in array + where t.Type == OSDType.Map + select (OSDMap)t + into map + select new InventoryFolder(map["folder_id"].AsUUID()) + { + PreferredType = (FolderType)map["type_default"].AsInteger(), + Version = map["version"].AsInteger(), + OwnerID = owner, + ParentUUID = map["parent_id"].AsUUID(), + Name = map["name"].AsString() + }); return folders.ToArray(); } @@ -773,19 +1004,19 @@ namespace OpenMetaverse var folders = new List(); OSD skeleton; - if (!reply.TryGetValue(key, out skeleton) || skeleton.Type != OSDType.Array) { return folders.ToArray(); } - OSDArray array = (OSDArray)skeleton; - folders.AddRange(from t in array - where t.Type == OSDType.Map - select (OSDMap)t - into map - select new InventoryFolder(map["folder_id"].AsUUID()) - { - Name = map["name"].AsString(), - ParentUUID = map["parent_id"].AsUUID(), - PreferredType = (FolderType)map["type_default"].AsInteger(), - Version = map["version"].AsInteger() - }); + if (!reply.TryGetValue(key, out skeleton) || skeleton.Type != OSDType.Array) {return folders.ToArray();} + var array = (OSDArray)skeleton; + folders.AddRange(from t in array + where t.Type == OSDType.Map + select (OSDMap)t + into map + select new InventoryFolder(map["folder_id"].AsUUID()) + { + Name = map["name"].AsString(), + ParentUUID = map["parent_id"].AsUUID(), + PreferredType = (FolderType)map["type_default"].AsInteger(), + Version = map["version"].AsInteger() + }); return folders.ToArray(); } @@ -796,14 +1027,13 @@ namespace OpenMetaverse var folders = new List(); - if (!reply.ContainsKey(key) || !(reply[key] is ArrayList)) { return folders.ToArray(); } + if (!reply.ContainsKey(key) || !(reply[key] is ArrayList)) {return folders.ToArray();} - ArrayList array = (ArrayList)reply[key]; - foreach (object t in array) + var array = (ArrayList)reply[key]; + foreach (var t in array) { - if (!(t is Hashtable)) continue; - Hashtable map = (Hashtable)t; - InventoryFolder folder = new InventoryFolder(ParseUUID("folder_id", map)) + if (!(t is Hashtable map)) continue; + var folder = new InventoryFolder(ParseUUID("folder_id", map)) { Name = ParseString("name", map), ParentUUID = ParseUUID("parent_id", map), @@ -902,9 +1132,9 @@ namespace OpenMetaverse #region Public Members /// Seed CAPS URL returned from the login server - public string LoginSeedCapability = String.Empty; + public string LoginSeedCapability = string.Empty; /// Current state of logging in - public LoginStatus LoginStatusCode => InternalStatusCode; + public LoginStatus LoginStatusCode { get; private set; } = LoginStatus.None; /// Upon login failure, contains a short string key for the /// type of login error that occurred @@ -934,11 +1164,10 @@ namespace OpenMetaverse { ServerCertificateCustomValidationCallback = delegate { return true; }, AllowAutoRedirect = true - }); - + }); + private LoginParams CurrentContext = null; private readonly AutoResetEvent LoginEvent = new AutoResetEvent(false); - private LoginStatus InternalStatusCode = LoginStatus.None; private readonly Dictionary CallbackOptions = new Dictionary(); /// A list of packets obtained during the login process which @@ -956,12 +1185,11 @@ namespace OpenMetaverse /// Account password /// Client application name (channel) /// Client application name + version - /// A populated struct containing - /// sane defaults + /// A populated object containing sane defaults public LoginParams DefaultLoginParams(string firstName, string lastName, string password, string channel, string version) { - return new LoginParams(Client, firstName, lastName, password, channel, version); + return new LoginParams(Client, new LoginCredential(firstName, lastName, password), channel, version); } /// @@ -999,7 +1227,7 @@ namespace OpenMetaverse public bool Login(string firstName, string lastName, string password, string channel, string start, string version) { - LoginParams loginParams = DefaultLoginParams(firstName, lastName, password, channel, version); + var loginParams = DefaultLoginParams(firstName, lastName, password, channel, version); loginParams.Start = start; return Login(loginParams); @@ -1023,18 +1251,18 @@ namespace OpenMetaverse if (CurrentContext != null) { CurrentContext = null; // Will force any pending callbacks to bail out early - InternalStatusCode = LoginStatus.Failed; + LoginStatusCode = LoginStatus.Failed; LoginMessage = "Timed out"; return false; } - return (InternalStatusCode == LoginStatus.Success); + return (LoginStatusCode == LoginStatus.Success); } public void BeginLogin(LoginParams loginParams) { // FIXME: Now that we're using CAPS we could cancel the current login and start a new one - if (CurrentContext != null) { throw new Exception("Login already in progress"); } + if (CurrentContext != null) {throw new Exception("Login already in progress");} LoginEvent.Reset(); CurrentContext = loginParams; @@ -1067,24 +1295,23 @@ namespace OpenMetaverse /// X coordinate to start at /// Y coordinate to start at /// Z coordinate to start at - /// String with a URI that can be used to login to a specified - /// location + /// String with a URI that can be used to login to a specified location public static string StartLocation(string sim, int x, int y, int z) { return $"uri:{sim}&{x}&{y}&{z}"; } public void AbortLogin() { - LoginParams loginParams = CurrentContext; + var loginParams = CurrentContext; CurrentContext = null; // Will force any pending callbacks to bail out early // FIXME: Now that we're using CAPS we could cancel the current login and start a new one if (loginParams == null) { - Logger.DebugLog("No Login was in progress: " + CurrentContext, Client); + Logger.DebugLog($"No Login was in progress: {CurrentContext}", Client); } else { - InternalStatusCode = LoginStatus.Failed; + LoginStatusCode = LoginStatus.Failed; LoginMessage = "Aborted"; } UpdateLoginStatus(LoginStatus.Failed, "Abort Requested"); @@ -1096,7 +1323,7 @@ namespace OpenMetaverse private void BeginLogin() { - LoginParams loginParams = CurrentContext; + var loginParams = CurrentContext; // Generate a random ID to identify this login attempt loginParams.LoginID = UUID.Random(); CurrentContext = loginParams; @@ -1104,12 +1331,12 @@ namespace OpenMetaverse #region Sanity Check loginParams if (loginParams.Options == null) - loginParams.Options = new List().ToArray(); + loginParams.Options = new List(); if (loginParams.Password == null) loginParams.Password = string.Empty; - // Convert the password to MD5 if it isn't already + // *HACK: Convert the password to MD5 if it isn't already if (loginParams.Password.Length != 35 && !loginParams.Password.StartsWith("$1$")) loginParams.Password = Utils.MD5(loginParams.Password); @@ -1133,43 +1360,38 @@ namespace OpenMetaverse if (string.IsNullOrEmpty(loginParams.Channel)) { - Logger.Log("Viewer channel not set. This is a TOS violation on some grids.", + Logger.Log("Viewer channel not set.", Helpers.LogLevel.Warning); loginParams.Channel = $"{Settings.USER_AGENT}"; } - if ((loginParams.Start != "home") && (loginParams.Start != "last")) - { - loginParams.Start = "home"; - Logger.Log("The Start option only accepts home or last! please use LoginLocation to set a custom login location!", Helpers.LogLevel.Warning); - } - - if (string.IsNullOrEmpty(loginParams.LoginLocation) == false) - { - string[] bits = loginParams.LoginLocation.Split('/'); - if (bits.Count() == 4) - { - if (int.TryParse(bits[1], out int X) == true) - { - if (int.TryParse(bits[2], out int Y) == true) - { - if (int.TryParse(bits[3], out int Z) == true) - { - Logger.Log("Setting login location to: " + loginParams.LoginLocation, Helpers.LogLevel.Info); - loginParams.Start = StartLocation(bits[0], X, Y, Z); - } - } - } - } + if (!string.IsNullOrEmpty(loginParams.LoginLocation)) + { + var startLoc = new LocationParser(loginParams.LoginLocation.Trim()); + loginParams.Start = startLoc.GetStartLocationUri(); + } + else + { + switch (loginParams.Start) + { + case "home": + case "last": + break; + default: + var startLoc = new LocationParser(loginParams.Start.Trim()); + loginParams.Start = startLoc.GetStartLocationUri(); + break; + } } if (loginParams.Author == null) + { loginParams.Author = string.Empty; - + } #endregion // TODO: Allow a user callback to be defined for handling the cert - ServicePointManager.ServerCertificateValidationCallback = + ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true; if (Client.Settings.USE_LLSD_LOGIN) @@ -1177,7 +1399,7 @@ namespace OpenMetaverse #region LLSD Based Login // Create the CAPS login structure - OSDMap loginLLSD = new OSDMap + var loginLLSD = new OSDMap { ["first"] = OSD.FromString(loginParams.FirstName), ["last"] = OSD.FromString(loginParams.LastName), @@ -1194,20 +1416,22 @@ namespace OpenMetaverse ["id0"] = OSD.FromString(loginParams.ID0), ["last_exec_event"] = OSD.FromInteger((int)loginParams.LastExecEvent) }; + if (loginParams.MfaEnabled) + { + loginLLSD["token"] = OSD.FromString(loginParams.Token); + loginLLSD["mfa_hash"] = OSD.FromString(loginParams.MfaHash); + } // Create the options LLSD array - OSDArray optionsOSD = new OSDArray(); - foreach (var t in loginParams.Options) - optionsOSD.Add(OSD.FromString(t)); - - foreach (var callbackOpts in CallbackOptions.Values) + var optionsOSD = new OSDArray(); + foreach (var option in loginParams.Options) { - if (callbackOpts == null) continue; - foreach (var t in callbackOpts) - { - if (!optionsOSD.Contains(t)) - optionsOSD.Add(t); - } + optionsOSD.Add(OSD.FromString(option)); + } + foreach (var t in from callbackOpts in CallbackOptions.Values where callbackOpts != null + from t in callbackOpts where !optionsOSD.Contains(t) select t) + { + optionsOSD.Add(t); } loginLLSD["options"] = optionsOSD; @@ -1238,7 +1462,7 @@ namespace OpenMetaverse #region XML-RPC Based Login Code // Create the Hashtable for XmlRpcCs - Hashtable loginXmlRpc = new Hashtable + var loginXmlRpc = new Hashtable { ["first"] = loginParams.FirstName, ["last"] = loginParams.LastName, @@ -1248,20 +1472,24 @@ namespace OpenMetaverse ["version"] = loginParams.Version, ["platform"] = loginParams.Platform, ["platform_version"] = loginParams.PlatformVersion, - ["mac"] = loginParams.MAC + ["mac"] = loginParams.MAC, + ["id0"] = loginParams.ID0, + ["last_exec_event"] = (int)loginParams.LastExecEvent }; - if (loginParams.AgreeToTos) - loginXmlRpc["agree_to_tos"] = "true"; - if (loginParams.ReadCritical) - loginXmlRpc["read_critical"] = "true"; - loginXmlRpc["id0"] = loginParams.ID0; - loginXmlRpc["last_exec_event"] = (int)loginParams.LastExecEvent; + if (loginParams.AgreeToTos) { loginXmlRpc["agree_to_tos"] = "true"; } + if (loginParams.ReadCritical) { loginXmlRpc["read_critical"] = "true"; } + if (loginParams.MfaEnabled) + { + loginXmlRpc["token"] = loginParams.Token; + loginXmlRpc["mfa_hash"] = loginParams.MfaHash; + } // Create the options array var options = new ArrayList(); - foreach (var t in loginParams.Options) - options.Add(t); - + foreach (var option in loginParams.Options) + { + options.Add(option); + } foreach (var callbackOpts in CallbackOptions.Values) { if (callbackOpts == null) continue; @@ -1286,8 +1514,8 @@ namespace OpenMetaverse var cts = new CancellationTokenSource(); cts.CancelAfter(cc.Timeout); var loginResponse = await HTTP_CLIENT.PostAsXmlRpcAsync(cc.URI, request, cts.Token); - cts.Dispose(); - + cts.Dispose(); + LoginReplyXmlRpcHandler(loginResponse, loginParams); } catch (Exception e) @@ -1308,10 +1536,10 @@ namespace OpenMetaverse private void UpdateLoginStatus(LoginStatus status, string message) { - InternalStatusCode = status; + LoginStatusCode = status; LoginMessage = message; - Logger.DebugLog($"Login status: {status.ToString()}: {message}", Client); + Logger.DebugLog($"Login status: {status}: {message}", Client); // If we reached a login resolution trigger the event if (status == LoginStatus.Success || status == LoginStatus.Failed) @@ -1344,9 +1572,9 @@ namespace OpenMetaverse /// private void LoginReplyXmlRpcHandler(XmlRpcResponse response, LoginParams context) { - LoginResponseData reply = new LoginResponseData(); + var reply = new LoginResponseData(); // Fetch the login response - if (!(response?.Value is Hashtable)) + if (!(response?.Value is Hashtable value)) { UpdateLoginStatus(LoginStatus.Failed, "Invalid or missing login response from the server"); Logger.Log("Invalid or missing login response from the server", Helpers.LogLevel.Warning); @@ -1355,10 +1583,11 @@ namespace OpenMetaverse try { - reply.Parse((Hashtable)response.Value); + reply.Parse(value); if (context.LoginID != CurrentContext.LoginID) { - Logger.Log("Login response does not match login request. Only one login can be attempted at a time", + Logger.Log("Login response does not match login request. " + + "Only one login can be attempted at a time", Helpers.LogLevel.Error); return; } @@ -1382,8 +1611,8 @@ namespace OpenMetaverse ushort simPort = 0; uint regionX = 0; uint regionY = 0; - string reason = reply.Reason; - string message = reply.Message; + var reason = reply.Reason; + var message = reply.Message; if (reply.Login == "true") { @@ -1425,23 +1654,9 @@ namespace OpenMetaverse //uint timestamp = (uint)reply.seconds_since_epoch; //DateTime time = Helpers.UnixTimeToDateTime(timestamp); // TODO: Do something with this? - - // Unhandled: - // reply.gestures - // reply.event_categories - // reply.classified_categories - // reply.event_notifications - // reply.ui_config - // reply.login_flags - // reply.global_textures - // reply.inventory_lib_root - // reply.inventory_lib_owner - // reply.inventory_skeleton - // reply.inventory_skel_lib - // reply.initial_outfit } - bool redirect = (reply.Login == "indeterminate"); + var redirect = (reply.Login == "indeterminate"); try { @@ -1460,10 +1675,10 @@ namespace OpenMetaverse var loginParams = CurrentContext; loginParams.URI = reply.NextUrl; loginParams.MethodName = reply.NextMethod; - loginParams.Options = reply.NextOptions; + loginParams.Options = reply.NextOptions.ToList(); // Sleep for some amount of time while the servers work - int seconds = reply.NextDuration; + var seconds = reply.NextDuration; Logger.Log($"Sleeping for {seconds} seconds during a login redirect", Helpers.LogLevel.Info); Thread.Sleep(seconds * 1000); @@ -1513,16 +1728,16 @@ namespace OpenMetaverse { if (result != null && result.Type == OSDType.Map) { - OSDMap map = (OSDMap)result; + var map = (OSDMap)result; OSD osd; - LoginResponseData data = new LoginResponseData(); + var data = new LoginResponseData(); data.Parse(map); if (map.TryGetValue("login", out osd)) { - bool loginSuccess = osd.AsBoolean(); - bool redirect = (osd.AsString() == "indeterminate"); + var loginSuccess = osd.AsBoolean(); + var redirect = (osd.AsString() == "indeterminate"); if (redirect) { @@ -1531,12 +1746,12 @@ namespace OpenMetaverse // Make the next login URL jump UpdateLoginStatus(LoginStatus.Redirecting, data.Message); - LoginParams loginParams = CurrentContext; + var loginParams = CurrentContext; loginParams.URI = LoginResponseData.ParseString("next_url", map); //CurrentContext.Params.MethodName = LoginResponseData.ParseString("next_method", map); // Sleep for some amount of time while the servers work - int seconds = (int)LoginResponseData.ParseUInt("next_duration", map); + var seconds = (int)LoginResponseData.ParseUInt("next_duration", map); Logger.Log("Sleeping for " + seconds + " seconds during a login redirect", Helpers.LogLevel.Info); Thread.Sleep(seconds * 1000); @@ -1594,7 +1809,7 @@ namespace OpenMetaverse // Login failed // Make sure a usable error key is set - LoginErrorKey = data.Reason != String.Empty ? data.Reason : "unknown"; + LoginErrorKey = data.Reason != string.Empty ? data.Reason : "unknown"; UpdateLoginStatus(LoginStatus.Failed, data.Message); } @@ -1602,14 +1817,14 @@ namespace OpenMetaverse else { // Got an LLSD map but no login value - UpdateLoginStatus(LoginStatus.Failed, "login parameter missing in the response"); + UpdateLoginStatus(LoginStatus.Failed, "Login parameter missing in the response"); } } else { // No LLSD response LoginErrorKey = "bad response"; - UpdateLoginStatus(LoginStatus.Failed, "Empty or unparseable login response"); + UpdateLoginStatus(LoginStatus.Failed, "Empty or corrupt login response"); } } else @@ -1656,14 +1871,14 @@ namespace OpenMetaverse try { - System.Net.NetworkInformation.NetworkInterface[] nics = + var nics = System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces(); if (nics.Length > 0) { - foreach (NetworkInterface t in nics) + foreach (var t in nics) { - string adapterMac = t.GetPhysicalAddress().ToString().ToUpper(); + var adapterMac = t.GetPhysicalAddress().ToString().ToUpper(); if (adapterMac.Length == 12 && adapterMac != "000000000000") { mac = adapterMac; @@ -1677,7 +1892,7 @@ namespace OpenMetaverse if (mac.Length < 12) mac = UUID.Random().ToString().Substring(24, 12); - return String.Format("{0}:{1}:{2}:{3}:{4}:{5}", + return string.Format("{0}:{1}:{2}:{3}:{4}:{5}", mac.Substring(0, 2), mac.Substring(2, 2), mac.Substring(4, 2), @@ -1694,8 +1909,8 @@ namespace OpenMetaverse private static string HashString(string str) { MD5 sec = new MD5CryptoServiceProvider(); - ASCIIEncoding enc = new ASCIIEncoding(); - byte[] buf = enc.GetBytes(str); + var enc = new ASCIIEncoding(); + var buf = enc.GetBytes(str); return GetHexString(sec.ComputeHash(buf)); } @@ -1747,4 +1962,4 @@ namespace OpenMetaverse } #endregion EventArgs -} \ No newline at end of file +} diff --git a/LibreMetaverse/Messages/LindenMessages.cs b/LibreMetaverse/Messages/LindenMessages.cs index c67074e..39d3013 100644 --- a/LibreMetaverse/Messages/LindenMessages.cs +++ b/LibreMetaverse/Messages/LindenMessages.cs @@ -1,6 +1,6 @@ /* * Copyright (c) 2006-2016, openmetaverse.co - * Copyright (c) 2021, Sjofn LLC + * Copyright (c) 2021-2022, Sjofn LLC * All rights reserved. * * - Redistribution and use in source and binary forms, with or without @@ -1402,9 +1402,7 @@ namespace OpenMetaverse.Messages.Linden { FolderDataInfo ret = new FolderDataInfo(); - if (!(data is OSDMap)) return ret; - - OSDMap map = (OSDMap)data; + if (!(data is OSDMap map)) return ret; ret.FolderID = map["FolderID"]; ret.ParentID = map["ParentID"]; @@ -1443,9 +1441,7 @@ namespace OpenMetaverse.Messages.Linden { ItemDataInfo ret = new ItemDataInfo(); - if (!(data is OSDMap)) return ret; - - OSDMap map = (OSDMap)data; + if (!(data is OSDMap map)) return ret; ret.ItemID = map["ItemID"]; ret.CallbackID = map["CallbackID"]; diff --git a/LibreMetaverse/NetworkManager.cs b/LibreMetaverse/NetworkManager.cs index cfb89be..9a30c45 100644 --- a/LibreMetaverse/NetworkManager.cs +++ b/LibreMetaverse/NetworkManager.cs @@ -25,12 +25,10 @@ */ using System; -using System.Collections.Concurrent; using System.Threading; using System.Collections.Generic; using System.Linq; using System.Net; -using System.Net.Http; using System.Threading.Channels; using System.Threading.Tasks; using OpenMetaverse.Packets; @@ -38,7 +36,7 @@ using OpenMetaverse.Interfaces; using OpenMetaverse.Messages.Linden; namespace OpenMetaverse -{ +{ /// /// NetworkManager is responsible for managing the network layer of /// OpenMetaverse. It tracks all the server connections, serializes @@ -316,7 +314,7 @@ namespace OpenMetaverse /// Shows whether the network layer is logged in to the /// grid or not - public bool Connected => connected; + public bool Connected { get; private set; } /// Number of packets in the incoming queue public int InboxCount => _packetInboxCount; @@ -346,7 +344,6 @@ namespace OpenMetaverse private GridClient Client; private Timer DisconnectTimer; - private bool connected; private long lastpacketwarning = 0; @@ -587,7 +584,7 @@ namespace OpenMetaverse { // Mark that we are connecting/connected to the grid // - connected = true; + Connected = true; // raise the SimConnecting event and allow any event // subscribers to cancel the connection @@ -746,7 +743,7 @@ namespace OpenMetaverse } // This will catch a Logout when the client is not logged in - if (CurrentSim == null || !connected) + if (CurrentSim == null || !Connected) { Logger.Log("Ignoring RequestLogout(), client is already logged out", Helpers.LogLevel.Warning, Client); return; @@ -865,7 +862,7 @@ namespace OpenMetaverse Interlocked.Exchange(ref _packetInboxCount, 0); Interlocked.Exchange(ref _packetOutboxCount, 0); - connected = false; + Connected = false; // Fire the disconnected callback if (m_Disconnected != null) @@ -923,7 +920,7 @@ namespace OpenMetaverse // FIXME: This is kind of ridiculous. Port the HTB code from Simian over ASAP! var stopwatch = new System.Diagnostics.Stopwatch(); - while (await reader.WaitToReadAsync() && connected) + while (await reader.WaitToReadAsync() && Connected) { while (reader.TryRead(out var outgoingPacket)) { @@ -956,7 +953,7 @@ namespace OpenMetaverse { var reader = _packetInbox.Reader; - while (await reader.WaitToReadAsync() && connected) + while (await reader.WaitToReadAsync() && Connected) { while (reader.TryRead(out var incomingPacket)) { @@ -1006,14 +1003,14 @@ namespace OpenMetaverse private void DisconnectTimer_Elapsed(object obj) { - if (!connected || CurrentSim == null) + if (!Connected || CurrentSim == null) { if (DisconnectTimer != null) { DisconnectTimer.Dispose(); DisconnectTimer = null; } - connected = false; + Connected = false; } else if (CurrentSim.DisconnectCandidate) { @@ -1027,7 +1024,7 @@ namespace OpenMetaverse DisconnectTimer = null; } - connected = false; + Connected = false; // Shutdown the network layer Shutdown(DisconnectType.NetworkTimeout); diff --git a/LibreMetaverse/ObjectManager.cs b/LibreMetaverse/ObjectManager.cs index ba1e284..d1285ee 100644 --- a/LibreMetaverse/ObjectManager.cs +++ b/LibreMetaverse/ObjectManager.cs @@ -3359,22 +3359,20 @@ namespace OpenMetaverse /// public class PrimEventArgs : EventArgs { - private readonly Simulator m_Simulator; - private readonly bool m_IsNew; - private readonly bool m_IsAttachment; - private readonly Primitive m_Prim; - private readonly ushort m_TimeDilation; - /// Get the simulator the originated from - public Simulator Simulator { get { return m_Simulator; } } + public Simulator Simulator { get; } + /// Get the details - public Primitive Prim { get { return m_Prim; } } + public Primitive Prim { get; } + /// true if the did not exist in the dictionary before this update (always true if object tracking has been disabled) - public bool IsNew { get { return m_IsNew; } } + public bool IsNew { get; } + /// true if the is attached to an - public bool IsAttachment { get { return m_IsAttachment; } } + public bool IsAttachment { get; } + /// Get the simulator Time Dilation - public ushort TimeDilation { get { return m_TimeDilation; } } + public ushort TimeDilation { get; } /// /// Construct a new instance of the PrimEventArgs class @@ -3386,11 +3384,11 @@ namespace OpenMetaverse /// true if the primitive represents an attachment to an agent public PrimEventArgs(Simulator simulator, Primitive prim, ushort timeDilation, bool isNew, bool isAttachment) { - this.m_Simulator = simulator; - this.m_IsNew = isNew; - this.m_IsAttachment = isAttachment; - this.m_Prim = prim; - this.m_TimeDilation = timeDilation; + this.Simulator = simulator; + this.IsNew = isNew; + this.IsAttachment = isAttachment; + this.Prim = prim; + this.TimeDilation = timeDilation; } } @@ -3440,19 +3438,17 @@ namespace OpenMetaverse /// public class AvatarUpdateEventArgs : EventArgs { - private readonly Simulator m_Simulator; - private readonly Avatar m_Avatar; - private readonly ushort m_TimeDilation; - private readonly bool m_IsNew; - /// Get the simulator the object originated from - public Simulator Simulator { get { return m_Simulator; } } + public Simulator Simulator { get; } + /// Get the data - public Avatar Avatar { get { return m_Avatar; } } + public Avatar Avatar { get; } + /// Get the simulator time dilation - public ushort TimeDilation { get { return m_TimeDilation; } } + public ushort TimeDilation { get; } + /// true if the did not exist in the dictionary before this update (always true if avatar tracking has been disabled) - public bool IsNew { get { return m_IsNew; } } + public bool IsNew { get; } /// /// Construct a new instance of the AvatarUpdateEventArgs class @@ -3463,24 +3459,22 @@ namespace OpenMetaverse /// The avatar was not in the dictionary before this update public AvatarUpdateEventArgs(Simulator simulator, Avatar avatar, ushort timeDilation, bool isNew) { - this.m_Simulator = simulator; - this.m_Avatar = avatar; - this.m_TimeDilation = timeDilation; - this.m_IsNew = isNew; + this.Simulator = simulator; + this.Avatar = avatar; + this.TimeDilation = timeDilation; + this.IsNew = isNew; } } public class ParticleUpdateEventArgs : EventArgs { - private readonly Simulator m_Simulator; - private readonly Primitive.ParticleSystem m_ParticleSystem; - private readonly Primitive m_Source; - /// Get the simulator the object originated from - public Simulator Simulator { get { return m_Simulator; } } + public Simulator Simulator { get; } + /// Get the data - public Primitive.ParticleSystem ParticleSystem { get { return m_ParticleSystem; } } + public Primitive.ParticleSystem ParticleSystem { get; } + /// Get source - public Primitive Source { get { return m_Source; } } + public Primitive Source { get; } /// /// Construct a new instance of the ParticleUpdateEventArgs class @@ -3489,9 +3483,9 @@ namespace OpenMetaverse /// The ParticleSystem data /// The Primitive source public ParticleUpdateEventArgs(Simulator simulator, Primitive.ParticleSystem particlesystem, Primitive source) { - this.m_Simulator = simulator; - this.m_ParticleSystem = particlesystem; - this.m_Source = source; + this.Simulator = simulator; + this.ParticleSystem = particlesystem; + this.Source = source; } } @@ -3548,11 +3542,8 @@ namespace OpenMetaverse /// public class ObjectPropertiesUpdatedEventArgs : ObjectPropertiesEventArgs { - - private readonly Primitive m_Prim; - /// Get the primitive details - public Primitive Prim { get { return m_Prim; } } + public Primitive Prim { get; } /// /// Construct a new instance of the ObjectPropertiesUpdatedEvenrArgs class @@ -3562,7 +3553,7 @@ namespace OpenMetaverse /// The primitive Properties public ObjectPropertiesUpdatedEventArgs(Simulator simulator, Primitive prim, Primitive.ObjectProperties props) : base(simulator, props) { - this.m_Prim = prim; + this.Prim = prim; } } @@ -3575,22 +3566,20 @@ namespace OpenMetaverse /// public class ObjectPropertiesFamilyEventArgs : EventArgs { - private readonly Simulator m_Simulator; - private readonly Primitive.ObjectProperties m_Properties; - private readonly ReportType m_Type; - /// Get the simulator the object is located - public Simulator Simulator { get { return m_Simulator; } } + public Simulator Simulator { get; } + /// - public Primitive.ObjectProperties Properties { get { return m_Properties; } } + public Primitive.ObjectProperties Properties { get; } + /// - public ReportType Type { get { return m_Type; } } + public ReportType Type { get; } public ObjectPropertiesFamilyEventArgs(Simulator simulator, Primitive.ObjectProperties props, ReportType type) { - this.m_Simulator = simulator; - this.m_Properties = props; - this.m_Type = type; + this.Simulator = simulator; + this.Properties = props; + this.Type = type; } } @@ -3599,26 +3588,24 @@ namespace OpenMetaverse /// public class TerseObjectUpdateEventArgs : EventArgs { - private readonly Simulator m_Simulator; - private readonly Primitive m_Prim; - private readonly ObjectMovementUpdate m_Update; - private readonly ushort m_TimeDilation; - /// Get the simulator the object is located - public Simulator Simulator { get { return m_Simulator; } } + public Simulator Simulator { get; } + /// Get the primitive details - public Primitive Prim { get { return m_Prim; } } + public Primitive Prim { get; } + /// - public ObjectMovementUpdate Update { get { return m_Update; } } + public ObjectMovementUpdate Update { get; } + /// - public ushort TimeDilation { get { return m_TimeDilation; } } + public ushort TimeDilation { get; } public TerseObjectUpdateEventArgs(Simulator simulator, Primitive prim, ObjectMovementUpdate update, ushort timeDilation) { - this.m_Simulator = simulator; - this.m_Prim = prim; - this.m_Update = update; - this.m_TimeDilation = timeDilation; + this.Simulator = simulator; + this.Prim = prim; + this.Update = update; + this.TimeDilation = timeDilation; } } @@ -3627,35 +3614,33 @@ namespace OpenMetaverse /// public class ObjectDataBlockUpdateEventArgs : EventArgs { - private readonly Simulator m_Simulator; - private readonly Primitive m_Prim; - private readonly Primitive.ConstructionData m_ConstructionData; - private readonly ObjectUpdatePacket.ObjectDataBlock m_Block; - private readonly ObjectMovementUpdate m_Update; - private readonly NameValue[] m_NameValues; - /// Get the simulator the object is located - public Simulator Simulator { get { return m_Simulator; } } + public Simulator Simulator { get; } + /// Get the primitive details - public Primitive Prim { get { return m_Prim; } } + public Primitive Prim { get; } + /// - public Primitive.ConstructionData ConstructionData { get { return m_ConstructionData; } } + public Primitive.ConstructionData ConstructionData { get; } + /// - public ObjectUpdatePacket.ObjectDataBlock Block { get { return m_Block; } } + public ObjectUpdatePacket.ObjectDataBlock Block { get; } + /// - public ObjectMovementUpdate Update { get { return m_Update; } } + public ObjectMovementUpdate Update { get; } + /// - public NameValue[] NameValues { get { return m_NameValues; } } + public NameValue[] NameValues { get; } public ObjectDataBlockUpdateEventArgs(Simulator simulator, Primitive prim, Primitive.ConstructionData constructionData, ObjectUpdatePacket.ObjectDataBlock block, ObjectMovementUpdate objectupdate, NameValue[] nameValues) { - this.m_Simulator = simulator; - this.m_Prim = prim; - this.m_ConstructionData = constructionData; - this.m_Block = block; - this.m_Update = objectupdate; - this.m_NameValues = nameValues; + this.Simulator = simulator; + this.Prim = prim; + this.ConstructionData = constructionData; + this.Block = block; + this.Update = objectupdate; + this.NameValues = nameValues; } } @@ -3663,18 +3648,16 @@ namespace OpenMetaverse /// event public class KillObjectEventArgs : EventArgs { - private readonly Simulator m_Simulator; - private readonly uint m_ObjectLocalID; - /// Get the simulator the object is located - public Simulator Simulator { get { return m_Simulator; } } + public Simulator Simulator { get; } + /// The LocalID of the object - public uint ObjectLocalID { get { return m_ObjectLocalID; } } + public uint ObjectLocalID { get; } public KillObjectEventArgs(Simulator simulator, uint objectID) { - this.m_Simulator = simulator; - this.m_ObjectLocalID = objectID; + this.Simulator = simulator; + this.ObjectLocalID = objectID; } } @@ -3682,18 +3665,16 @@ namespace OpenMetaverse /// event public class KillObjectsEventArgs : EventArgs { - private readonly Simulator m_Simulator; - private readonly uint[] m_ObjectLocalIDs; - /// Get the simulator the object is located - public Simulator Simulator { get { return m_Simulator; } } + public Simulator Simulator { get; } + /// The LocalID of the object - public uint[] ObjectLocalIDs { get { return m_ObjectLocalIDs; } } + public uint[] ObjectLocalIDs { get; } public KillObjectsEventArgs(Simulator simulator, uint[] objectIDs) { - this.m_Simulator = simulator; - this.m_ObjectLocalIDs = objectIDs; + this.Simulator = simulator; + this.ObjectLocalIDs = objectIDs; } } @@ -3702,26 +3683,24 @@ namespace OpenMetaverse /// public class AvatarSitChangedEventArgs : EventArgs { - private readonly Simulator m_Simulator; - private readonly Avatar m_Avatar; - private readonly uint m_SittingOn; - private readonly uint m_OldSeat; - /// Get the simulator the object is located - public Simulator Simulator { get { return m_Simulator; } } + public Simulator Simulator { get; } + /// - public Avatar Avatar { get { return m_Avatar; } } + public Avatar Avatar { get; } + /// - public uint SittingOn { get { return m_SittingOn; } } + public uint SittingOn { get; } + /// - public uint OldSeat { get { return m_OldSeat; } } + public uint OldSeat { get; } public AvatarSitChangedEventArgs(Simulator simulator, Avatar avatar, uint sittingOn, uint oldSeat) { - this.m_Simulator = simulator; - this.m_Avatar = avatar; - this.m_SittingOn = sittingOn; - this.m_OldSeat = oldSeat; + this.Simulator = simulator; + this.Avatar = avatar; + this.SittingOn = sittingOn; + this.OldSeat = oldSeat; } } @@ -3730,26 +3709,24 @@ namespace OpenMetaverse /// public class PayPriceReplyEventArgs : EventArgs { - private readonly Simulator m_Simulator; - private readonly UUID m_ObjectID; - private readonly int m_DefaultPrice; - private readonly int[] m_ButtonPrices; - /// Get the simulator the object is located - public Simulator Simulator { get { return m_Simulator; } } + public Simulator Simulator { get; } + /// - public UUID ObjectID { get { return m_ObjectID; } } + public UUID ObjectID { get; } + /// - public int DefaultPrice { get { return m_DefaultPrice; } } + public int DefaultPrice { get; } + /// - public int[] ButtonPrices { get { return m_ButtonPrices; } } + public int[] ButtonPrices { get; } public PayPriceReplyEventArgs(Simulator simulator, UUID objectID, int defaultPrice, int[] buttonPrices) { - this.m_Simulator = simulator; - this.m_ObjectID = objectID; - this.m_DefaultPrice = defaultPrice; - this.m_ButtonPrices = buttonPrices; + this.Simulator = simulator; + this.ObjectID = objectID; + this.DefaultPrice = defaultPrice; + this.ButtonPrices = buttonPrices; } } diff --git a/LibreMetaverse/PacketDecoder.cs b/LibreMetaverse/PacketDecoder.cs index 2933cf4..dd89763 100644 --- a/LibreMetaverse/PacketDecoder.cs +++ b/LibreMetaverse/PacketDecoder.cs @@ -26,7 +26,6 @@ using System; using System.Collections.Generic; -using System.Collections.ObjectModel; using System.Reflection; using System.Text; diff --git a/LibreMetaverse/ParcelManager.cs b/LibreMetaverse/ParcelManager.cs index 2b0b4e3..2bfc1e7 100644 --- a/LibreMetaverse/ParcelManager.cs +++ b/LibreMetaverse/ParcelManager.cs @@ -1,2416 +1,2377 @@ -/* - * Copyright (c) 2006-2016, openmetaverse.co - * Copyright (c) 2021, Sjofn LLC - * 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 openmetaverse.co 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 System.Threading; -using System.Reflection; -using System.Collections.Generic; -using System.Linq; -using OpenMetaverse.Http; -using OpenMetaverse.Packets; -using OpenMetaverse.Interfaces; -using OpenMetaverse.StructuredData; -using OpenMetaverse.Messages.Linden; - -namespace OpenMetaverse -{ - #region Enums - - /// - /// Type of return to use when returning objects from a parcel - /// - public enum ObjectReturnType : uint - { - /// - None = 0, - /// Return objects owned by parcel owner - Owner = 1 << 1, - /// Return objects set to group - Group = 1 << 2, - /// Return objects not owned by parcel owner or set to group - Other = 1 << 3, - /// Return a specific list of objects on parcel - List = 1 << 4, - /// Return objects that are marked for-sale - Sell = 1 << 5 - } - - /// - /// Blacklist/Whitelist flags used in parcels Access List - /// - public enum ParcelAccessFlags : uint - { - /// Agent is denied access - NoAccess = 0, - /// Agent is granted access - Access = 1 - } - - /// - /// The result of a request for parcel properties - /// - public enum ParcelResult : int - { - /// No matches were found for the request - NoData = -1, - /// Request matched a single parcel - Single = 0, - /// Request matched multiple parcels - Multiple = 1 - } - - /// - /// Flags used in the ParcelAccessListRequest packet to specify whether - /// we want the access list (whitelist), ban list (blacklist), or both - /// - [Flags] - public enum AccessList : uint - { - /// Request the access list - Access = 1 << 0, - /// Request the ban list - Ban = 1 << 1, - /// Request both White and Black lists - Both = Access | Ban - } - - /// - /// Sequence ID in ParcelPropertiesReply packets (sent when avatar - /// tries to cross a parcel border) - /// - public enum ParcelPropertiesStatus : int - { - /// Parcel is currently selected - ParcelSelected = -10000, - /// Parcel restricted to a group the avatar is not a - /// member of - CollisionNotInGroup = -20000, - /// Avatar is banned from the parcel - CollisionBanned = -30000, - /// Parcel is restricted to an access list that the - /// avatar is not on - CollisionNotOnAccessList = -40000, - /// Response to hovering over a parcel - HoveredOverParcel = -50000 - } - - /// - /// The tool to use when modifying terrain levels - /// - public enum TerraformAction : byte - { - /// Level the terrain - Level = 0, - /// Raise the terrain - Raise = 1, - /// Lower the terrain - Lower = 2, - /// Smooth the terrain - Smooth = 3, - /// Add random noise to the terrain - Noise = 4, - /// Revert terrain to simulator default - Revert = 5 - } - - /// - /// The tool size to use when changing terrain levels - /// - public enum TerraformBrushSize : byte - { - /// Small - Small = 1, - /// Medium - Medium = 2, - /// Large - Large = 4 - } - - /// - /// Reasons agent is denied access to a parcel on the simulator - /// - public enum AccessDeniedReason : byte - { - /// Agent is not denied, access is granted - NotDenied = 0, - /// Agent is not a member of the group set for the parcel, or which owns the parcel - NotInGroup = 1, - /// Agent is not on the parcels specific allow list - NotOnAllowList = 2, - /// Agent is on the parcels ban list - BannedFromParcel = 3, - /// Unknown - NoAccess = 4, - /// Agent is not age verified and parcel settings deny access to non age verified avatars - NotAgeVerified = 5 - } - - /// - /// Parcel overlay type. This is used primarily for highlighting and - /// coloring which is why it is a single integer instead of a set of - /// flags - /// - /// These values seem to be poorly thought out. The first three - /// bits represent a single value, not flags. For example Auction (0x05) is - /// not a combination of OwnedByOther (0x01) and ForSale(0x04). However, - /// the BorderWest and BorderSouth values are bit flags that get attached - /// to the value stored in the first three bits. Bits four, five, and six - /// are unused - [Flags] - public enum ParcelOverlayType : byte - { - /// Public land - Public = 0, - /// Land is owned by another avatar - OwnedByOther = 1, - /// Land is owned by a group - OwnedByGroup = 2, - /// Land is owned by the current avatar - OwnedBySelf = 3, - /// Land is for sale - ForSale = 4, - /// Land is being auctioned - Auction = 5, - /// Land is private - Private = 32, - /// To the west of this area is a parcel border - BorderWest = 64, - /// To the south of this area is a parcel border - BorderSouth = 128 - } - - /// - /// Various parcel properties - /// - [Flags] - public enum ParcelFlags : uint - { - /// No flags set - None = 0, - /// Allow avatars to fly (a client-side only restriction) - AllowFly = 1 << 0, - /// Allow foreign scripts to run - AllowOtherScripts = 1 << 1, - /// This parcel is for sale - ForSale = 1 << 2, - /// Allow avatars to create a landmark on this parcel - AllowLandmark = 1 << 3, - /// Allows all avatars to edit the terrain on this parcel - AllowTerraform = 1 << 4, - /// Avatars have health and can take damage on this parcel. - /// If set, avatars can be killed and sent home here - AllowDamage = 1 << 5, - /// Foreign avatars can create objects here - CreateObjects = 1 << 6, - /// All objects on this parcel can be purchased - ForSaleObjects = 1 << 7, - /// Access is restricted to a group - UseAccessGroup = 1 << 8, - /// Access is restricted to a whitelist - UseAccessList = 1 << 9, - /// Ban blacklist is enabled - UseBanList = 1 << 10, - /// Unknown - UsePassList = 1 << 11, - /// List this parcel in the search directory - ShowDirectory = 1 << 12, - /// Allow personally owned parcels to be deeded to group - AllowDeedToGroup = 1 << 13, - /// If Deeded, owner contributes required tier to group parcel is deeded to - ContributeWithDeed = 1 << 14, - /// Restrict sounds originating on this parcel to the - /// parcel boundaries - SoundLocal = 1 << 15, - /// Objects on this parcel are sold when the land is - /// purchsaed - SellParcelObjects = 1 << 16, - /// Allow this parcel to be published on the web - AllowPublish = 1 << 17, - /// The information for this parcel is mature content - MaturePublish = 1 << 18, - /// The media URL is an HTML page - UrlWebPage = 1 << 19, - /// The media URL is a raw HTML string - UrlRawHtml = 1 << 20, - /// Restrict foreign object pushes - RestrictPushObject = 1 << 21, - /// Ban all non identified/transacted avatars - DenyAnonymous = 1 << 22, - // Ban all identified avatars [OBSOLETE] - //[Obsolete] - // This was obsoleted in 1.19.0 but appears to be recycled and is used on linden homes parcels - LindenHome = 1 << 23, - // Ban all transacted avatars [OBSOLETE] - //[Obsolete] - //DenyTransacted = 1 << 24, - /// Allow group-owned scripts to run - AllowGroupScripts = 1 << 25, - /// Allow object creation by group members or group - /// objects - CreateGroupObjects = 1 << 26, - /// Allow all objects to enter this parcel - AllowAPrimitiveEntry = 1 << 27, - /// Only allow group and owner objects to enter this parcel - AllowGroupObjectEntry = 1 << 28, - /// Voice Enabled on this parcel - AllowVoiceChat = 1 << 29, - /// Use Estate Voice channel for Voice on this parcel - UseEstateVoiceChan = 1 << 30, - /// Deny Age Unverified Users - DenyAgeUnverified = 1U << 31 - } - - /// - /// Parcel ownership status - /// - public enum ParcelStatus : sbyte - { - /// Placeholder - None = -1, - /// Parcel is leased (owned) by an avatar or group - Leased = 0, - /// Parcel is in process of being leased (purchased) by an avatar or group - LeasePending = 1, - /// Parcel has been abandoned back to Governor Linden - Abandoned = 2 - } - - /// - /// Category parcel is listed in under search - /// - public enum ParcelCategory : sbyte - { - /// No assigned category - None = 0, - /// Linden Infohub or public area - Linden, - /// Adult themed area - Adult, - /// Arts and Culture - Arts, - /// Business - Business, - /// Educational - Educational, - /// Gaming - Gaming, - /// Hangout or Club - Hangout, - /// Newcomer friendly - Newcomer, - /// Parks and Nature - Park, - /// Residential - Residential, - /// Shopping - Shopping, - /// Not Used? - Stage, - /// Other - Other, - /// Not an actual category, only used for queries - Any = -1 - } - - /// - /// Type of teleport landing for a parcel - /// - public enum LandingType : byte - { - /// Unset, simulator default - None = 0, - /// Specific landing point set for this parcel - LandingPoint = 1, - /// No landing point set, direct teleports enabled for - /// this parcel - Direct = 2 - } - - /// - /// Parcel Media Command used in ParcelMediaCommandMessage - /// - public enum ParcelMediaCommand : uint - { - /// Stop the media stream and go back to the first frame - Stop = 0, - /// Pause the media stream (stop playing but stay on current frame) - Pause, - /// Start the current media stream playing and stop when the end is reached - Play, - /// Start the current media stream playing, - /// loop to the beginning when the end is reached and continue to play - Loop, - /// Specifies the texture to replace with video - /// If passing the key of a texture, it must be explicitly typecast as a key, - /// not just passed within double quotes. - Texture, - /// Specifies the movie URL (254 characters max) - URL, - /// Specifies the time index at which to begin playing - Time, - /// Specifies a single agent to apply the media command to - Agent, - /// Unloads the stream. While the stop command sets the texture to the first frame of the movie, - /// unload resets it to the real texture that the movie was replacing. - Unload, - /// Turn on/off the auto align feature, similar to the auto align checkbox in the parcel media properties - /// (NOT to be confused with the "align" function in the textures view of the editor!) Takes TRUE or FALSE as parameter. - AutoAlign, - /// Allows a Web page or image to be placed on a prim (1.19.1 RC0 and later only). - /// Use "text/html" for HTML. - Type, - /// Resizes a Web page to fit on x, y pixels (1.19.1 RC0 and later only). - /// This might still not be working - Size, - /// Sets a description for the media being displayed (1.19.1 RC0 and later only). - Desc - } - - #endregion Enums - - #region Structs - - /// - /// Some information about a parcel of land returned from a DirectoryManager search - /// - public struct ParcelInfo - { - /// Global Key of record - public UUID ID; - /// Parcel Owners - public UUID OwnerID; - /// Name field of parcel, limited to 128 characters - public string Name; - /// Description field of parcel, limited to 256 characters - public string Description; - /// Total Square meters of parcel - public int ActualArea; - /// Total area billable as Tier, for group owned land this will be 10% less than ActualArea - public int BillableArea; - /// True of parcel is in Mature simulator - public bool Mature; - /// Grid global X position of parcel - public float GlobalX; - /// Grid global Y position of parcel - public float GlobalY; - /// Grid global Z position of parcel (not used) - public float GlobalZ; - /// Name of simulator parcel is located in - public string SimName; - /// Texture of parcels display picture - public UUID SnapshotID; - /// Float representing calculated traffic based on time spent on parcel by avatars - public float Dwell; - /// Sale price of parcel (not used) - public int SalePrice; - /// Auction ID of parcel - public int AuctionID; - } - - /// - /// Parcel Media Information - /// - public struct ParcelMedia - { - /// A byte, if 0x1 viewer should auto scale media to fit object - public bool MediaAutoScale; - /// A boolean, if true the viewer should loop the media - public bool MediaLoop; - /// The Asset UUID of the Texture which when applied to a - /// primitive will display the media - public UUID MediaID; - /// A URL which points to any Quicktime supported media type - public string MediaURL; - /// A description of the media - public string MediaDesc; - /// An Integer which represents the height of the media - public int MediaHeight; - /// An integer which represents the width of the media - public int MediaWidth; - /// A string which contains the mime type of the media - public string MediaType; - } - - #endregion Structs - - #region Parcel Class - - /// - /// Parcel of land, a portion of virtual real estate in a simulator - /// - public class Parcel - { - /// The total number of contiguous 4x4 meter blocks your agent owns within this parcel - public int SelfCount; - /// The total number of contiguous 4x4 meter blocks contained in this parcel owned by a group or agent other than your own - public int OtherCount; - /// Deprecated, Value appears to always be 0 - public int PublicCount; - /// Simulator-local ID of this parcel - public int LocalID; - /// UUID of the owner of this parcel - public UUID OwnerID; - /// Whether the land is deeded to a group or not - public bool IsGroupOwned; - /// - public uint AuctionID; - /// Date land was claimed - public DateTime ClaimDate; - /// Appears to always be zero - public int ClaimPrice; - /// This field is no longer used - public int RentPrice; - /// Minimum corner of the axis-aligned bounding box for this - /// parcel - public Vector3 AABBMin; - /// Maximum corner of the axis-aligned bounding box for this - /// parcel - public Vector3 AABBMax; - /// Bitmap describing land layout in 4x4m squares across the - /// entire region - public byte[] Bitmap; - /// Total parcel land area - public int Area; - /// - public ParcelStatus Status; - /// Maximum primitives across the entire simulator owned by the same agent or group that owns this parcel that can be used - public int SimWideMaxPrims; - /// Total primitives across the entire simulator calculated by combining the allowed prim counts for each parcel - /// owned by the agent or group that owns this parcel - public int SimWideTotalPrims; - /// Maximum number of primitives this parcel supports - public int MaxPrims; - /// Total number of primitives on this parcel - public int TotalPrims; - /// For group-owned parcels this indicates the total number of prims deeded to the group, - /// for parcels owned by an individual this inicates the number of prims owned by the individual - public int OwnerPrims; - /// Total number of primitives owned by the parcel group on - /// this parcel, or for parcels owned by an individual with a group set the - /// total number of prims set to that group. - public int GroupPrims; - /// Total number of prims owned by other avatars that are not set to group, or not the parcel owner - public int OtherPrims; - /// A bonus multiplier which allows parcel prim counts to go over times this amount, this does not affect - /// the max prims per simulator. e.g: 117 prim parcel limit x 1.5 bonus = 175 allowed - public float ParcelPrimBonus; - /// Autoreturn value in minutes for others' objects - public int OtherCleanTime; - /// - public ParcelFlags Flags; - /// Sale price of the parcel, only useful if ForSale is set - /// The SalePrice will remain the same after an ownership - /// transfer (sale), so it can be used to see the purchase price after - /// a sale if the new owner has not changed it - public int SalePrice; - /// Parcel Name - public string Name; - /// Parcel Description - public string Desc; - /// URL For Music Stream - public string MusicURL; - /// - public UUID GroupID; - /// Price for a temporary pass - public int PassPrice; - /// How long is pass valid for - public float PassHours; - /// - public ParcelCategory Category; - /// Key of authorized buyer - public UUID AuthBuyerID; - /// Key of parcel snapshot - public UUID SnapshotID; - /// The landing point location - public Vector3 UserLocation; - /// The landing point LookAt - public Vector3 UserLookAt; - /// The type of landing enforced from the enum - public LandingType Landing; - /// - public float Dwell; - /// - public bool RegionDenyAnonymous; - /// - public bool RegionPushOverride; - /// Access list of who is whitelisted on this - /// parcel - public List AccessWhiteList; - /// Access list of who is blacklisted on this - /// parcel - public List AccessBlackList; - /// TRUE of region denies access to age unverified users - public bool RegionDenyAgeUnverified; - /// true to obscure (hide) media url - public bool ObscureMedia; - /// true to obscure (hide) music url - public bool ObscureMusic; - /// A struct containing media details - public ParcelMedia Media; - /// Parcel privacy see avatars outside/inside parcel - public bool SeeAVs; - /// Parcel privacy play sounds attached to avatars outside/inside parcel - public bool AnyAVSounds; - /// Parcel privacy play sounds for group members - public bool GroupAVSounds; - - /// - /// Displays a parcel object in string format - /// - /// string containing key=value pairs of a parcel object - public override string ToString() - { - Type parcelType = this.GetType(); - FieldInfo[] fields = parcelType.GetFields(); - return fields.Aggregate("", (current, field) => current + (field.Name + " = " + field.GetValue(this) + " ")); - } - /// - /// Defalt constructor - /// - /// Local ID of this parcel - public Parcel(int localID) - { - LocalID = localID; - ClaimDate = Utils.Epoch; - Bitmap = Utils.EmptyBytes; - Name = String.Empty; - Desc = String.Empty; - MusicURL = String.Empty; - AccessWhiteList = new List(0); - AccessBlackList = new List(0); - Media = new ParcelMedia(); - } - - /// - /// Update the simulator with any local changes to this Parcel object - /// - /// Simulator to send updates to - /// Whether we want the simulator to confirm - /// the update with a reply packet or not - public void Update(Simulator simulator, bool wantReply) - { - CapsClient request = simulator.Caps.CreateCapsClient("ParcelPropertiesUpdate"); - if (request != null) - { - ParcelPropertiesUpdateMessage req = new ParcelPropertiesUpdateMessage - { - AuthBuyerID = AuthBuyerID, - Category = Category, - Desc = Desc, - GroupID = GroupID, - Landing = Landing, - LocalID = LocalID, - MediaAutoScale = Media.MediaAutoScale, - MediaDesc = Media.MediaDesc, - MediaHeight = Media.MediaHeight, - MediaID = Media.MediaID, - MediaLoop = Media.MediaLoop, - MediaType = Media.MediaType, - MediaURL = Media.MediaURL, - MediaWidth = Media.MediaWidth, - MusicURL = MusicURL, - Name = Name, - ObscureMedia = ObscureMedia, - ObscureMusic = ObscureMusic, - ParcelFlags = Flags, - PassHours = PassHours, - PassPrice = (uint) PassPrice, - SalePrice = (uint) SalePrice, - SnapshotID = SnapshotID, - UserLocation = UserLocation, - UserLookAt = UserLookAt, - SeeAVs = SeeAVs, - AnyAVSounds = AnyAVSounds, - GroupAVSounds = GroupAVSounds - }; - - OSDMap body = req.Serialize(); - - request.PostRequestAsync(body, OSDFormat.Xml, simulator.Client.Settings.CAPS_TIMEOUT); - } - else - { - ParcelPropertiesUpdatePacket updatePacket = new ParcelPropertiesUpdatePacket - { - AgentData = - { - AgentID = simulator.Client.Self.AgentID, - SessionID = simulator.Client.Self.SessionID - }, - ParcelData = - { - LocalID = LocalID, - AuthBuyerID = AuthBuyerID, - Category = (byte) Category, - Desc = Utils.StringToBytes(Desc), - GroupID = GroupID, - LandingType = (byte) Landing, - MediaAutoScale = (Media.MediaAutoScale) ? (byte) 0x1 : (byte) 0x0, - MediaID = Media.MediaID, - MediaURL = Utils.StringToBytes(Media.MediaURL), - MusicURL = Utils.StringToBytes(MusicURL), - Name = Utils.StringToBytes(Name) - } - }; - - - - if (wantReply) updatePacket.ParcelData.Flags = 1; - updatePacket.ParcelData.ParcelFlags = (uint)Flags; - updatePacket.ParcelData.PassHours = PassHours; - updatePacket.ParcelData.PassPrice = PassPrice; - updatePacket.ParcelData.SalePrice = SalePrice; - updatePacket.ParcelData.SnapshotID = SnapshotID; - updatePacket.ParcelData.UserLocation = UserLocation; - updatePacket.ParcelData.UserLookAt = UserLookAt; - - simulator.SendPacket(updatePacket); - } - - UpdateOtherCleanTime(simulator); - - } - - /// - /// Set Autoreturn time - /// - /// Simulator to send the update to - public void UpdateOtherCleanTime(Simulator simulator) - { - ParcelSetOtherCleanTimePacket request = new ParcelSetOtherCleanTimePacket - { - AgentData = - { - AgentID = simulator.Client.Self.AgentID, - SessionID = simulator.Client.Self.SessionID - }, - ParcelData = - { - LocalID = LocalID, - OtherCleanTime = OtherCleanTime - } - }; - - simulator.SendPacket(request); - } - } - - #endregion Parcel Class - - /// - /// Parcel (subdivided simulator lots) subsystem - /// - public class ParcelManager - { - #region Structs - - /// - /// Parcel Accesslist - /// - public struct ParcelAccessEntry - { - /// Agents - public UUID AgentID; - /// - public DateTime Time; - /// Flags for specific entry in white/black lists - public AccessList Flags; - } - - /// - /// Owners of primitives on parcel - /// - public struct ParcelPrimOwners - { - /// Prim Owners - public UUID OwnerID; - /// True of owner is group - public bool IsGroupOwned; - /// Total count of prims owned by OwnerID - public int Count; - /// true of OwnerID is currently online and is not a group - public bool OnlineStatus; - /// The date of the most recent prim left by OwnerID - public DateTime NewestPrim; - } - - #endregion Structs - - #region Delegates - /// - /// Called once parcel resource usage information has been collected - /// - /// Indicates if operation was successfull - /// Parcel resource usage information - public delegate void LandResourcesCallback(bool success, LandResourcesInfo info); - - /// The event subscribers. null if no subcribers - private EventHandler m_DwellReply; - - /// Raises the ParcelDwellReply event - /// A ParcelDwellReplyEventArgs object containing the - /// data returned from the simulator - protected virtual void OnParcelDwellReply(ParcelDwellReplyEventArgs e) - { - EventHandler handler = m_DwellReply; - handler?.Invoke(this, e); - } - - /// Thread sync lock object - private readonly object m_DwellReplyLock = new object(); - - /// Raised when the simulator responds to a request - public event EventHandler ParcelDwellReply - { - add { lock (m_DwellReplyLock) { m_DwellReply += value; } } - remove { lock (m_DwellReplyLock) { m_DwellReply -= value; } } - } - - /// The event subscribers. null if no subcribers - private EventHandler m_ParcelInfo; - - /// Raises the ParcelInfoReply event - /// A ParcelInfoReplyEventArgs object containing the - /// data returned from the simulator - protected virtual void OnParcelInfoReply(ParcelInfoReplyEventArgs e) - { - EventHandler handler = m_ParcelInfo; - handler?.Invoke(this, e); - } - - /// Thread sync lock object - private readonly object m_ParcelInfoLock = new object(); - - /// Raised when the simulator responds to a request - public event EventHandler ParcelInfoReply - { - add { lock (m_ParcelInfoLock) { m_ParcelInfo += value; } } - remove { lock (m_ParcelInfoLock) { m_ParcelInfo -= value; } } - } - - /// The event subscribers. null if no subcribers - private EventHandler m_ParcelProperties; - - /// Raises the ParcelProperties event - /// A ParcelPropertiesEventArgs object containing the - /// data returned from the simulator - protected virtual void OnParcelProperties(ParcelPropertiesEventArgs e) - { - EventHandler handler = m_ParcelProperties; - handler?.Invoke(this, e); - } - - /// Thread sync lock object - private readonly object m_ParcelPropertiesLock = new object(); - - /// Raised when the simulator responds to a request - public event EventHandler ParcelProperties - { - add { lock (m_ParcelPropertiesLock) { m_ParcelProperties += value; } } - remove { lock (m_ParcelPropertiesLock) { m_ParcelProperties -= value; } } - } - - /// The event subscribers. null if no subcribers - private EventHandler m_ParcelACL; - - /// Raises the ParcelAccessListReply event - /// A ParcelAccessListReplyEventArgs object containing the - /// data returned from the simulator - protected virtual void OnParcelAccessListReply(ParcelAccessListReplyEventArgs e) - { - EventHandler handler = m_ParcelACL; - handler?.Invoke(this, e); - } - - /// Thread sync lock object - private readonly object m_ParcelACLLock = new object(); - - /// Raised when the simulator responds to a request - public event EventHandler ParcelAccessListReply - { - add { lock (m_ParcelACLLock) { m_ParcelACL += value; } } - remove { lock (m_ParcelACLLock) { m_ParcelACL -= value; } } - } - - /// The event subscribers. null if no subcribers - private EventHandler m_ParcelObjectOwnersReply; - - /// Raises the ParcelObjectOwnersReply event - /// A ParcelObjectOwnersReplyEventArgs object containing the - /// data returned from the simulator - protected virtual void OnParcelObjectOwnersReply(ParcelObjectOwnersReplyEventArgs e) - { - EventHandler handler = m_ParcelObjectOwnersReply; - handler?.Invoke(this, e); - } - - /// Thread sync lock object - private readonly object m_ParcelObjectOwnersLock = new object(); - - /// Raised when the simulator responds to a request - public event EventHandler ParcelObjectOwnersReply - { - add { lock (m_ParcelObjectOwnersLock) { m_ParcelObjectOwnersReply += value; } } - remove { lock (m_ParcelObjectOwnersLock) { m_ParcelObjectOwnersReply -= value; } } - } - - /// The event subscribers. null if no subcribers - private EventHandler m_SimParcelsDownloaded; - - /// Raises the SimParcelsDownloaded event - /// A SimParcelsDownloadedEventArgs object containing the - /// data returned from the simulator - protected virtual void OnSimParcelsDownloaded(SimParcelsDownloadedEventArgs e) - { - EventHandler handler = m_SimParcelsDownloaded; - handler?.Invoke(this, e); - } - - /// Thread sync lock object - private readonly object m_SimParcelsDownloadedLock = new object(); - - /// Raised when the simulator responds to a request - public event EventHandler SimParcelsDownloaded - { - add { lock (m_SimParcelsDownloadedLock) { m_SimParcelsDownloaded += value; } } - remove { lock (m_SimParcelsDownloadedLock) { m_SimParcelsDownloaded -= value; } } - } - - /// The event subscribers. null if no subcribers - private EventHandler m_ForceSelectObjects; - - /// Raises the ForceSelectObjectsReply event - /// A ForceSelectObjectsReplyEventArgs object containing the - /// data returned from the simulator - protected virtual void OnForceSelectObjectsReply(ForceSelectObjectsReplyEventArgs e) - { - EventHandler handler = m_ForceSelectObjects; - handler?.Invoke(this, e); - } - - /// Thread sync lock object - private readonly object m_ForceSelectObjectsLock = new object(); - - /// Raised when the simulator responds to a request - public event EventHandler ForceSelectObjectsReply - { - add { lock (m_ForceSelectObjectsLock) { m_ForceSelectObjects += value; } } - remove { lock (m_ForceSelectObjectsLock) { m_ForceSelectObjects -= value; } } - } - - /// The event subscribers. null if no subcribers - private EventHandler m_ParcelMediaUpdateReply; - - /// Raises the ParcelMediaUpdateReply event - /// A ParcelMediaUpdateReplyEventArgs object containing the - /// data returned from the simulator - protected virtual void OnParcelMediaUpdateReply(ParcelMediaUpdateReplyEventArgs e) - { - EventHandler handler = m_ParcelMediaUpdateReply; - handler?.Invoke(this, e); - } - - /// Thread sync lock object - private readonly object m_ParcelMediaUpdateReplyLock = new object(); - - /// Raised when the simulator responds to a Parcel Update request - public event EventHandler ParcelMediaUpdateReply - { - add { lock (m_ParcelMediaUpdateReplyLock) { m_ParcelMediaUpdateReply += value; } } - remove { lock (m_ParcelMediaUpdateReplyLock) { m_ParcelMediaUpdateReply -= value; } } - } - - /// The event subscribers. null if no subcribers - private EventHandler m_ParcelMediaCommand; - - /// Raises the ParcelMediaCommand event - /// A ParcelMediaCommandEventArgs object containing the - /// data returned from the simulator - protected virtual void OnParcelMediaCommand(ParcelMediaCommandEventArgs e) - { - EventHandler handler = m_ParcelMediaCommand; - handler?.Invoke(this, e); - } - - /// Thread sync lock object - private readonly object m_ParcelMediaCommandLock = new object(); - - /// Raised when the parcel your agent is located sends a ParcelMediaCommand - public event EventHandler ParcelMediaCommand - { - add { lock (m_ParcelMediaCommandLock) { m_ParcelMediaCommand += value; } } - remove { lock (m_ParcelMediaCommandLock) { m_ParcelMediaCommand -= value; } } - } - #endregion Delegates - - private GridClient Client; - private AutoResetEvent WaitForSimParcel; - - #region Public Methods - - /// - /// Default constructor - /// - /// A reference to the GridClient object - public ParcelManager(GridClient client) - { - Client = client; - - // Setup the callbacks - Client.Network.RegisterCallback(PacketType.ParcelInfoReply, ParcelInfoReplyHandler); - Client.Network.RegisterEventCallback("ParcelObjectOwnersReply", ParcelObjectOwnersReplyHandler); - // CAPS packet handler, to allow for Media Data not contained in the message template - Client.Network.RegisterEventCallback("ParcelProperties", ParcelPropertiesReplyHandler); - Client.Network.RegisterCallback(PacketType.ParcelDwellReply, ParcelDwellReplyHandler); - Client.Network.RegisterCallback(PacketType.ParcelAccessListReply, ParcelAccessListReplyHandler); - Client.Network.RegisterCallback(PacketType.ForceObjectSelect, SelectParcelObjectsReplyHandler); - Client.Network.RegisterCallback(PacketType.ParcelMediaUpdate, ParcelMediaUpdateHandler); - Client.Network.RegisterCallback(PacketType.ParcelOverlay, ParcelOverlayHandler); - Client.Network.RegisterCallback(PacketType.ParcelMediaCommandMessage, ParcelMediaCommandMessagePacketHandler); - } - - /// - /// Request basic information for a single parcel - /// - /// Simulator-local ID of the parcel - public void RequestParcelInfo(UUID parcelID) - { - ParcelInfoRequestPacket request = new ParcelInfoRequestPacket - { - AgentData = - { - AgentID = Client.Self.AgentID, - SessionID = Client.Self.SessionID - }, - Data = {ParcelID = parcelID} - }; - - Client.Network.SendPacket(request); - } - - /// - /// Request properties of a single parcel - /// - /// Simulator containing the parcel - /// Simulator-local ID of the parcel - /// An arbitrary integer that will be returned - /// with the ParcelProperties reply, useful for distinguishing between - /// multiple simultaneous requests - public void RequestParcelProperties(Simulator simulator, int localID, int sequenceID) - { - ParcelPropertiesRequestByIDPacket request = new ParcelPropertiesRequestByIDPacket - { - AgentData = - { - AgentID = Client.Self.AgentID, - SessionID = Client.Self.SessionID - }, - ParcelData = - { - LocalID = localID, - SequenceID = sequenceID - } - }; - - Client.Network.SendPacket(request, simulator); - } - - /// - /// Request the access list for a single parcel - /// - /// Simulator containing the parcel - /// Simulator-local ID of the parcel - /// An arbitrary integer that will be returned - /// with the ParcelAccessList reply, useful for distinguishing between - /// multiple simultaneous requests - /// - public void RequestParcelAccessList(Simulator simulator, int localID, AccessList flags, int sequenceID) - { - ParcelAccessListRequestPacket request = new ParcelAccessListRequestPacket - { - AgentData = - { - AgentID = Client.Self.AgentID, - SessionID = Client.Self.SessionID - }, - Data = - { - LocalID = localID, - Flags = (uint) flags, - SequenceID = sequenceID - } - }; - - Client.Network.SendPacket(request, simulator); - } - - /// - /// Request properties of parcels using a bounding box selection - /// - /// Simulator containing the parcel - /// Northern boundary of the parcel selection - /// Eastern boundary of the parcel selection - /// Southern boundary of the parcel selection - /// Western boundary of the parcel selection - /// An arbitrary integer that will be returned - /// with the ParcelProperties reply, useful for distinguishing between - /// different types of parcel property requests - /// A boolean that is returned with the - /// ParcelProperties reply, useful for snapping focus to a single - /// parcel - public void RequestParcelProperties(Simulator simulator, float north, float east, float south, float west, - int sequenceID, bool snapSelection) - { - ParcelPropertiesRequestPacket request = new ParcelPropertiesRequestPacket - { - AgentData = - { - AgentID = Client.Self.AgentID, - SessionID = Client.Self.SessionID - }, - ParcelData = - { - North = north, - East = east, - South = south, - West = west, - SequenceID = sequenceID, - SnapSelection = snapSelection - } - }; - - Client.Network.SendPacket(request, simulator); - } - - /// - /// Request all simulator parcel properties (used for populating the Simulator.Parcels - /// dictionary) - /// - /// Simulator to request parcels from (must be connected) - public void RequestAllSimParcels(Simulator simulator) - { - RequestAllSimParcels(simulator, false, 750); - } - - /// - /// Request all simulator parcel properties (used for populating the Simulator.Parcels - /// dictionary) - /// - /// Simulator to request parcels from (must be connected) - /// If TRUE, will force a full refresh - /// Number of milliseconds to pause in between each request - public void RequestAllSimParcels(Simulator simulator, bool refresh, int msDelay) - { - if (simulator.DownloadingParcelMap) - { - Logger.Log("Already downloading parcels in " + simulator.Name, Helpers.LogLevel.Info, Client); - return; - } - else - { - simulator.DownloadingParcelMap = true; - WaitForSimParcel = new AutoResetEvent(false); - } - - if (refresh) - { - for (int y = 0; y < 64; y++) - for (int x = 0; x < 64; x++) - simulator.ParcelMap[y, x] = 0; - } - - ThreadPool.QueueUserWorkItem((_) => - { - int count = 0, timeouts = 0, y, x; - - for (y = 0; y < 64; y++) - { - for (x = 0; x < 64; x++) - { - if (!Client.Network.Connected) - return; - - if (simulator.ParcelMap[y, x] == 0) - { - Client.Parcels.RequestParcelProperties(simulator, - (y + 1) * 4.0f, (x + 1) * 4.0f, - y * 4.0f, x * 4.0f, int.MaxValue, false); - - // Wait the given amount of time for a reply before sending the next request - if (!WaitForSimParcel.WaitOne(msDelay, false)) - ++timeouts; - - ++count; - } - } - } - - Logger.Log(String.Format( - "Full simulator parcel information retrieved. Sent {0} parcel requests. Current outgoing queue: {1}, Retry Count {2}", - count, Client.Network.OutboxCount, timeouts), Helpers.LogLevel.Info, Client); - - simulator.DownloadingParcelMap = false; - }); - } - - /// - /// Request the dwell value for a parcel - /// - /// Simulator containing the parcel - /// Simulator-local ID of the parcel - public void RequestDwell(Simulator simulator, int localID) - { - ParcelDwellRequestPacket request = new ParcelDwellRequestPacket - { - AgentData = - { - AgentID = Client.Self.AgentID, - SessionID = Client.Self.SessionID - }, - Data = - { - LocalID = localID, - ParcelID = UUID.Zero - } - }; - // Not used by clients - - Client.Network.SendPacket(request, simulator); - } - - /// - /// Send a request to Purchase a parcel of land - /// - /// The Simulator the parcel is located in - /// The parcels region specific local ID - /// true if this parcel is being purchased by a group - /// The groups - /// true to remove tier contribution if purchase is successful - /// The parcels size - /// The purchase price of the parcel - /// - public void Buy(Simulator simulator, int localID, bool forGroup, UUID groupID, - bool removeContribution, int parcelArea, int parcelPrice) - { - ParcelBuyPacket request = new ParcelBuyPacket - { - AgentData = - { - AgentID = Client.Self.AgentID, - SessionID = Client.Self.SessionID - }, - Data = - { - Final = true, - GroupID = groupID, - LocalID = localID, - IsGroupOwned = forGroup, - RemoveContribution = removeContribution - }, - ParcelData = - { - Area = parcelArea, - Price = parcelPrice - } - }; - - - - - Client.Network.SendPacket(request, simulator); - } - - /// - /// Reclaim a parcel of land - /// - /// The simulator the parcel is in - /// The parcels region specific local ID - public void Reclaim(Simulator simulator, int localID) - { - ParcelReclaimPacket request = new ParcelReclaimPacket - { - AgentData = - { - AgentID = Client.Self.AgentID, - SessionID = Client.Self.SessionID - }, - Data = {LocalID = localID} - }; - - - Client.Network.SendPacket(request, simulator); - } - - /// - /// Deed a parcel to a group - /// - /// The simulator the parcel is in - /// The parcels region specific local ID - /// The groups - public void DeedToGroup(Simulator simulator, int localID, UUID groupID) - { - ParcelDeedToGroupPacket request = new ParcelDeedToGroupPacket - { - AgentData = - { - AgentID = Client.Self.AgentID, - SessionID = Client.Self.SessionID - }, - Data = - { - LocalID = localID, - GroupID = groupID - } - }; - - - Client.Network.SendPacket(request, simulator); - } - - /// - /// Request prim owners of a parcel of land. - /// - /// Simulator parcel is in - /// The parcels region specific local ID - public void RequestObjectOwners(Simulator simulator, int localID) - { - ParcelObjectOwnersRequestPacket request = new ParcelObjectOwnersRequestPacket - { - AgentData = - { - AgentID = Client.Self.AgentID, - SessionID = Client.Self.SessionID - }, - ParcelData = {LocalID = localID} - }; - - - Client.Network.SendPacket(request, simulator); - } - - /// - /// Return objects from a parcel - /// - /// Simulator parcel is in - /// The parcels region specific local ID - /// the type of objects to return, - /// A list containing object owners s to return - public void ReturnObjects(Simulator simulator, int localID, ObjectReturnType type, List ownerIDs) - { - ParcelReturnObjectsPacket request = new ParcelReturnObjectsPacket - { - AgentData = - { - AgentID = Client.Self.AgentID, - SessionID = Client.Self.SessionID - }, - ParcelData = - { - LocalID = localID, - ReturnType = (uint) type - }, - TaskIDs = new ParcelReturnObjectsPacket.TaskIDsBlock[1] - }; - - - // A single null TaskID is (not) used for parcel object returns - request.TaskIDs[0] = new ParcelReturnObjectsPacket.TaskIDsBlock {TaskID = UUID.Zero}; - - // Convert the list of owner UUIDs to packet blocks if a list is given - if (ownerIDs != null) - { - request.OwnerIDs = new ParcelReturnObjectsPacket.OwnerIDsBlock[ownerIDs.Count]; - - for (int i = 0; i < ownerIDs.Count; i++) - { - request.OwnerIDs[i] = new ParcelReturnObjectsPacket.OwnerIDsBlock {OwnerID = ownerIDs[i]}; - } - } - else - { - request.OwnerIDs = new ParcelReturnObjectsPacket.OwnerIDsBlock[0]; - } - - Client.Network.SendPacket(request, simulator); - } - - /// - /// Subdivide (split) a parcel - /// - /// - /// - /// - /// - /// - public void ParcelSubdivide(Simulator simulator, float west, float south, float east, float north) - { - ParcelDividePacket divide = new ParcelDividePacket - { - AgentData = - { - AgentID = Client.Self.AgentID, - SessionID = Client.Self.SessionID - }, - ParcelData = - { - East = east, - North = north, - South = south, - West = west - } - }; - - Client.Network.SendPacket(divide, simulator); - } - - /// - /// Join two parcels of land creating a single parcel - /// - /// - /// - /// - /// - /// - public void ParcelJoin(Simulator simulator, float west, float south, float east, float north) - { - ParcelJoinPacket join = new ParcelJoinPacket(); - join.AgentData.AgentID = Client.Self.AgentID; - join.AgentData.SessionID = Client.Self.SessionID; - join.ParcelData.East = east; - join.ParcelData.North = north; - join.ParcelData.South = south; - join.ParcelData.West = west; - - Client.Network.SendPacket(join, simulator); - } - - /// - /// Get a parcels LocalID - /// - /// Simulator parcel is in - /// Vector3 position in simulator (Z not used) - /// 0 on failure, or parcel LocalID on success. - /// A call to Parcels.RequestAllSimParcels is required to populate map and - /// dictionary. - public int GetParcelLocalID(Simulator simulator, Vector3 position) - { - if (simulator.ParcelMap[(byte)position.Y / 4, (byte)position.X / 4] > 0) - { - return simulator.ParcelMap[(byte)position.Y / 4, (byte)position.X / 4]; - } - else - { - Logger.Log(String.Format("ParcelMap returned an default/invalid value for location {0}/{1} Did you use RequestAllSimParcels() to populate the dictionaries?", (byte)position.Y / 4, (byte)position.X / 4 ), Helpers.LogLevel.Warning); - return 0; - } - } - - /// - /// Terraform (raise, lower, etc) an area or whole parcel of land - /// - /// Simulator land area is in. - /// LocalID of parcel, or -1 if using bounding box - /// From Enum, Raise, Lower, Level, Smooth, Etc. - /// Size of area to modify - /// true on successful request sent. - /// Settings.STORE_LAND_PATCHES must be true, - /// Parcel information must be downloaded using RequestAllSimParcels() - public bool Terraform(Simulator simulator, int localID, TerraformAction action, TerraformBrushSize brushSize) - { - return Terraform(simulator, localID, 0f, 0f, 0f, 0f, action, brushSize, 1); - } - - /// - /// Terraform (raise, lower, etc) an area or whole parcel of land - /// - /// Simulator land area is in. - /// west border of area to modify - /// south border of area to modify - /// east border of area to modify - /// north border of area to modify - /// From Enum, Raise, Lower, Level, Smooth, Etc. - /// Size of area to modify - /// true on successful request sent. - /// Settings.STORE_LAND_PATCHES must be true, - /// Parcel information must be downloaded using RequestAllSimParcels() - public bool Terraform(Simulator simulator, float west, float south, float east, float north, - TerraformAction action, TerraformBrushSize brushSize) - { - return Terraform(simulator, -1, west, south, east, north, action, brushSize, 1); - } - - /// - /// Terraform (raise, lower, etc) an area or whole parcel of land - /// - /// Simulator land area is in. - /// LocalID of parcel, or -1 if using bounding box - /// west border of area to modify - /// south border of area to modify - /// east border of area to modify - /// north border of area to modify - /// From Enum, Raise, Lower, Level, Smooth, Etc. - /// Size of area to modify - /// How many meters + or - to lower, 1 = 1 meter - /// true on successful request sent. - /// Settings.STORE_LAND_PATCHES must be true, - /// Parcel information must be downloaded using RequestAllSimParcels() - public bool Terraform(Simulator simulator, int localID, float west, float south, float east, float north, - TerraformAction action, TerraformBrushSize brushSize, int seconds) - { - float height = 0f; - int x, y; - if (localID == -1) - { - x = (int)east - (int)west / 2; - y = (int)north - (int)south / 2; - } - else - { - Parcel p; - if (!simulator.Parcels.TryGetValue(localID, out p)) - { - Logger.Log(String.Format("Can't find parcel {0} in simulator {1}", localID, simulator), - Helpers.LogLevel.Warning, Client); - return false; - } - - x = (int)p.AABBMax.X - (int)p.AABBMin.X / 2; - y = (int)p.AABBMax.Y - (int)p.AABBMin.Y / 2; - } - - if (!simulator.TerrainHeightAtPoint(x, y, out height)) - { - Logger.Log("Land Patch not stored for location", Helpers.LogLevel.Warning, Client); - return false; - } - - Terraform(simulator, localID, west, south, east, north, action, brushSize, seconds, height); - return true; - } - - /// - /// Terraform (raise, lower, etc) an area or whole parcel of land - /// - /// Simulator land area is in. - /// LocalID of parcel, or -1 if using bounding box - /// west border of area to modify - /// south border of area to modify - /// east border of area to modify - /// north border of area to modify - /// From Enum, Raise, Lower, Level, Smooth, Etc. - /// Size of area to modify - /// How many meters + or - to lower, 1 = 1 meter - /// Height at which the terraform operation is acting at - public void Terraform(Simulator simulator, int localID, float west, float south, float east, float north, - TerraformAction action, TerraformBrushSize brushSize, int seconds, float height) - { - ModifyLandPacket land = new ModifyLandPacket - { - AgentData = - { - AgentID = Client.Self.AgentID, - SessionID = Client.Self.SessionID - }, - ModifyBlock = - { - Action = (byte) action, - BrushSize = (byte) brushSize, - Seconds = seconds, - Height = height - }, - ParcelData = new ModifyLandPacket.ParcelDataBlock[1] - }; - - - land.ParcelData[0] = new ModifyLandPacket.ParcelDataBlock - { - LocalID = localID, - West = west, - South = south, - East = east, - North = north - }; - - land.ModifyBlockExtended = new ModifyLandPacket.ModifyBlockExtendedBlock[1]; - land.ModifyBlockExtended[0] = new ModifyLandPacket.ModifyBlockExtendedBlock {BrushSize = (float) brushSize}; - - Client.Network.SendPacket(land, simulator); - } - - /// - /// Sends a request to the simulator to return a list of objects owned by specific owners - /// - /// Simulator local ID of parcel - /// Owners, Others, Etc - /// List containing keys of avatars objects to select; - /// if List is null will return Objects of type selectType - /// Response data is returned in the event - public void RequestSelectObjects(int localID, ObjectReturnType selectType, UUID ownerID) - { - ParcelSelectObjectsPacket select = new ParcelSelectObjectsPacket(); - select.AgentData.AgentID = Client.Self.AgentID; - select.AgentData.SessionID = Client.Self.SessionID; - - select.ParcelData.LocalID = localID; - select.ParcelData.ReturnType = (uint)selectType; - - select.ReturnIDs = new ParcelSelectObjectsPacket.ReturnIDsBlock[1]; - select.ReturnIDs[0] = new ParcelSelectObjectsPacket.ReturnIDsBlock {ReturnID = ownerID}; - - Client.Network.SendPacket(select); - } - - /// - /// Eject and optionally ban a user from a parcel - /// - /// target key of avatar to eject - /// true to also ban target - public void EjectUser(UUID targetID, bool ban) - { - EjectUserPacket eject = new EjectUserPacket - { - AgentData = - { - AgentID = Client.Self.AgentID, - SessionID = Client.Self.SessionID - }, - Data = {TargetID = targetID} - }; - eject.Data.Flags = ban ? (uint)1 : 0; - - Client.Network.SendPacket(eject); - } - - /// - /// Freeze or unfreeze an avatar over your land - /// - /// target key to freeze - /// true to freeze, false to unfreeze - public void FreezeUser(UUID targetID, bool freeze) - { - FreezeUserPacket frz = new FreezeUserPacket - { - AgentData = - { - AgentID = Client.Self.AgentID, - SessionID = Client.Self.SessionID - }, - Data = {TargetID = targetID} - }; - frz.Data.Flags = freeze ? (uint)0 : 1; - - Client.Network.SendPacket(frz); - } - - /// - /// Abandon a parcel of land - /// - /// Simulator parcel is in - /// Simulator local ID of parcel - public void ReleaseParcel(Simulator simulator, int localID) - { - ParcelReleasePacket abandon = new ParcelReleasePacket - { - AgentData = - { - AgentID = Client.Self.AgentID, - SessionID = Client.Self.SessionID - }, - Data = {LocalID = localID} - }; - - Client.Network.SendPacket(abandon, simulator); - } - - /// - /// Requests the UUID of the parcel in a remote region at a specified location - /// - /// Location of the parcel in the remote region - /// Remote region handle - /// Remote region UUID - /// If successful UUID of the remote parcel, UUID.Zero otherwise - public UUID RequestRemoteParcelID(Vector3 location, ulong regionHandle, UUID regionID) - { - if (Client.Network.CurrentSim == null || Client.Network.CurrentSim.Caps == null) - return UUID.Zero; - - CapsClient request = Client.Network.CurrentSim.Caps.CreateCapsClient("RemoteParcelRequest"); - - if (request != null) - { - RemoteParcelRequestRequest msg = new RemoteParcelRequestRequest - { - Location = location, - RegionHandle = regionHandle, - RegionID = regionID - }; - - try - { - OSDMap result = request.PostRequest(msg.Serialize(), OSDFormat.Xml, Client.Settings.CAPS_TIMEOUT) as OSDMap; - RemoteParcelRequestReply response = new RemoteParcelRequestReply(); - response.Deserialize(result); - return response.ParcelID; - } - catch (Exception) - { - Logger.Log("Failed to fetch remote parcel ID", Helpers.LogLevel.Debug, Client); - } - } - - return UUID.Zero; - - } - - /// - /// Retrieves information on resources used by the parcel - /// - /// UUID of the parcel - /// Should per object resource usage be requested - /// Callback invoked when the request is complete - public void GetParcelResouces(UUID parcelID, bool getDetails, LandResourcesCallback callback) - { - try - { - CapsClient request = Client.Network.CurrentSim.Caps.CreateCapsClient("LandResources"); - - request.OnComplete += delegate(CapsClient client, OSD result, Exception error) - { - try - { - if (result == null || error != null) - { - callback(false, null); - } - LandResourcesMessage response = new LandResourcesMessage(); - response.Deserialize((OSDMap)result); - - CapsClient summaryRequest = new CapsClient(response.ScriptResourceSummary, "ScriptResourceSummary"); - OSD summaryResponse = summaryRequest.GetRequest(Client.Settings.CAPS_TIMEOUT); - - LandResourcesInfo res = new LandResourcesInfo(); - res.Deserialize((OSDMap)summaryResponse); - - if (response.ScriptResourceDetails != null && getDetails) - { - CapsClient detailRequest = new CapsClient(response.ScriptResourceDetails, "ScriptResourceDetails"); - OSD detailResponse = detailRequest.GetRequest(Client.Settings.CAPS_TIMEOUT); - res.Deserialize((OSDMap)detailResponse); - } - callback(true, res); - } - catch (Exception ex) - { - Logger.Log("Failed fetching land resources", Helpers.LogLevel.Error, Client, ex); - callback(false, null); - } - }; - - LandResourcesRequest param = new LandResourcesRequest {ParcelID = parcelID}; - request.PostRequestAsync(param.Serialize(), OSDFormat.Xml, Client.Settings.CAPS_TIMEOUT); - - } - catch (Exception ex) - { - Logger.Log("Failed fetching land resources:", Helpers.LogLevel.Error, Client, ex); - callback(false, null); - } - } - - #endregion Public Methods - - #region Packet Handlers - - /// Process an incoming packet and raise the appropriate events - /// The sender - /// The EventArgs object containing the packet data - /// Raises the event - protected void ParcelDwellReplyHandler(object sender, PacketReceivedEventArgs e) - { - if (m_DwellReply != null || Client.Settings.ALWAYS_REQUEST_PARCEL_DWELL) - { - Packet packet = e.Packet; - Simulator simulator = e.Simulator; - - ParcelDwellReplyPacket dwell = (ParcelDwellReplyPacket)packet; - - lock (simulator.Parcels.Dictionary) - { - if (simulator.Parcels.Dictionary.ContainsKey(dwell.Data.LocalID)) - { - Parcel parcel = simulator.Parcels.Dictionary[dwell.Data.LocalID]; - parcel.Dwell = dwell.Data.Dwell; - simulator.Parcels.Dictionary[dwell.Data.LocalID] = parcel; - } - } - - if (m_DwellReply != null) - { - OnParcelDwellReply(new ParcelDwellReplyEventArgs(dwell.Data.ParcelID, dwell.Data.LocalID, dwell.Data.Dwell)); - } - } - } - - /// Process an incoming packet and raise the appropriate events - /// The sender - /// The EventArgs object containing the packet data - /// Raises the event - protected void ParcelInfoReplyHandler(object sender, PacketReceivedEventArgs e) - { - if (m_ParcelInfo == null) return; - - Packet packet = e.Packet; - ParcelInfoReplyPacket info = (ParcelInfoReplyPacket)packet; - - ParcelInfo parcelInfo = new ParcelInfo - { - ActualArea = info.Data.ActualArea, - AuctionID = info.Data.AuctionID, - BillableArea = info.Data.BillableArea, - Description = Utils.BytesToString(info.Data.Desc), - Dwell = info.Data.Dwell, - GlobalX = info.Data.GlobalX, - GlobalY = info.Data.GlobalY, - GlobalZ = info.Data.GlobalZ, - ID = info.Data.ParcelID, - Mature = ((info.Data.Flags & 1) != 0), - Name = Utils.BytesToString(info.Data.Name), - OwnerID = info.Data.OwnerID, - SalePrice = info.Data.SalePrice, - SimName = Utils.BytesToString(info.Data.SimName), - SnapshotID = info.Data.SnapshotID - }; - - - OnParcelInfoReply(new ParcelInfoReplyEventArgs(parcelInfo)); - } - - protected void ParcelPropertiesReplyHandler(string capsKey, IMessage message, Simulator simulator) - { - if (m_ParcelProperties == null && Client.Settings.PARCEL_TRACKING != true) return; - ParcelPropertiesMessage msg = (ParcelPropertiesMessage)message; - - Parcel parcel = new Parcel(msg.LocalID) - { - AABBMax = msg.AABBMax, - AABBMin = msg.AABBMin, - Area = msg.Area, - AuctionID = msg.AuctionID, - AuthBuyerID = msg.AuthBuyerID, - Bitmap = msg.Bitmap, - Category = msg.Category, - ClaimDate = msg.ClaimDate, - ClaimPrice = msg.ClaimPrice, - Desc = msg.Desc, - Flags = msg.ParcelFlags, - GroupID = msg.GroupID, - GroupPrims = msg.GroupPrims, - IsGroupOwned = msg.IsGroupOwned, - Landing = msg.LandingType, - MaxPrims = msg.MaxPrims, - Media = - { - MediaAutoScale = msg.MediaAutoScale, - MediaID = msg.MediaID, - MediaURL = msg.MediaURL - }, - MusicURL = msg.MusicURL, - Name = msg.Name, - OtherCleanTime = msg.OtherCleanTime, - OtherCount = msg.OtherCount, - OtherPrims = msg.OtherPrims, - OwnerID = msg.OwnerID, - OwnerPrims = msg.OwnerPrims, - ParcelPrimBonus = msg.ParcelPrimBonus, - PassHours = msg.PassHours, - PassPrice = msg.PassPrice, - PublicCount = msg.PublicCount, - RegionDenyAgeUnverified = msg.RegionDenyAgeUnverified, - RegionDenyAnonymous = msg.RegionDenyAnonymous, - RegionPushOverride = msg.RegionPushOverride, - RentPrice = msg.RentPrice, - SeeAVs = msg.SeeAVs, - AnyAVSounds = msg.AnyAVSounds, - GroupAVSounds = msg.GroupAVSounds - - }; - - ParcelResult result = msg.RequestResult; - parcel.SalePrice = msg.SalePrice; - int selectedPrims = msg.SelectedPrims; - parcel.SelfCount = msg.SelfCount; - int sequenceID = msg.SequenceID; - parcel.SimWideMaxPrims = msg.SimWideMaxPrims; - parcel.SimWideTotalPrims = msg.SimWideTotalPrims; - bool snapSelection = msg.SnapSelection; - parcel.SnapshotID = msg.SnapshotID; - parcel.Status = msg.Status; - parcel.TotalPrims = msg.TotalPrims; - parcel.UserLocation = msg.UserLocation; - parcel.UserLookAt = msg.UserLookAt; - parcel.Media.MediaDesc = msg.MediaDesc; - parcel.Media.MediaHeight = msg.MediaHeight; - parcel.Media.MediaWidth = msg.MediaWidth; - parcel.Media.MediaLoop = msg.MediaLoop; - parcel.Media.MediaType = msg.MediaType; - parcel.ObscureMedia = msg.ObscureMedia; - parcel.ObscureMusic = msg.ObscureMusic; - - if (Client.Settings.PARCEL_TRACKING) - { - lock (simulator.Parcels.Dictionary) - simulator.Parcels.Dictionary[parcel.LocalID] = parcel; - - bool set = false; - int y, x, index, bit; - for (y = 0; y < 64; y++) - { - for (x = 0; x < 64; x++) - { - index = (y * 64) + x; - bit = index % 8; - index >>= 3; - - if ((parcel.Bitmap[index] & (1 << bit)) != 0) - { - simulator.ParcelMap[y, x] = parcel.LocalID; - set = true; - } - } - } - - if (!set) - { - Logger.Log("Received a parcel with a bitmap that did not map to any locations", - Helpers.LogLevel.Warning); - } - } - - if (sequenceID.Equals(int.MaxValue)) - WaitForSimParcel?.Set(); - - // auto request acl, will be stored in parcel tracking dictionary if enabled - if (Client.Settings.ALWAYS_REQUEST_PARCEL_ACL) - Client.Parcels.RequestParcelAccessList(simulator, parcel.LocalID, - AccessList.Both, sequenceID); - - // auto request dwell, will be stored in parcel tracking dictionary if enables - if (Client.Settings.ALWAYS_REQUEST_PARCEL_DWELL) - Client.Parcels.RequestDwell(simulator, parcel.LocalID); - - // Fire the callback for parcel properties being received - if (m_ParcelProperties != null) - { - OnParcelProperties(new ParcelPropertiesEventArgs(simulator, parcel, result, selectedPrims, sequenceID, snapSelection)); - } - - // Check if all of the simulator parcels have been retrieved, if so fire another callback - if (simulator.IsParcelMapFull() && m_SimParcelsDownloaded != null) - { - OnSimParcelsDownloaded(new SimParcelsDownloadedEventArgs(simulator, simulator.Parcels, simulator.ParcelMap)); - } - } - - /// Process an incoming packet and raise the appropriate events - /// The sender - /// The EventArgs object containing the packet data - /// Raises the event - protected void ParcelAccessListReplyHandler(object sender, PacketReceivedEventArgs e) - { - if (m_ParcelACL != null || Client.Settings.ALWAYS_REQUEST_PARCEL_ACL) - { - Packet packet = e.Packet; - Simulator simulator = e.Simulator; - - ParcelAccessListReplyPacket reply = (ParcelAccessListReplyPacket)packet; - - List accessList = new List(reply.List.Length); - - foreach (ParcelAccessListReplyPacket.ListBlock t in reply.List) - { - ParcelAccessEntry pae = new ParcelAccessEntry - { - AgentID = t.ID, - Time = Utils.UnixTimeToDateTime((uint) t.Time), - Flags = (AccessList) t.Flags - }; - - accessList.Add(pae); - } - - lock (simulator.Parcels.Dictionary) - { - if (simulator.Parcels.Dictionary.ContainsKey(reply.Data.LocalID)) - { - Parcel parcel = simulator.Parcels.Dictionary[reply.Data.LocalID]; - if ((AccessList)reply.Data.Flags == AccessList.Ban) - parcel.AccessBlackList = accessList; - else - parcel.AccessWhiteList = accessList; - - simulator.Parcels.Dictionary[reply.Data.LocalID] = parcel; - } - } - - - if (m_ParcelACL != null) - { - OnParcelAccessListReply(new ParcelAccessListReplyEventArgs(simulator, reply.Data.SequenceID, reply.Data.LocalID, - reply.Data.Flags, accessList)); - } - } - } - - protected void ParcelObjectOwnersReplyHandler(string capsKey, IMessage message, Simulator simulator) - { - if (m_ParcelObjectOwnersReply != null) - { - List primOwners = new List(); - - ParcelObjectOwnersReplyMessage msg = (ParcelObjectOwnersReplyMessage)message; - - foreach (ParcelObjectOwnersReplyMessage.PrimOwner t in msg.PrimOwnersBlock) - { - ParcelPrimOwners primOwner = new ParcelPrimOwners - { - OwnerID = t.OwnerID, - Count = t.Count, - IsGroupOwned = t.IsGroupOwned, - OnlineStatus = t.OnlineStatus, - NewestPrim = t.TimeStamp - }; - - primOwners.Add(primOwner); - } - - OnParcelObjectOwnersReply(new ParcelObjectOwnersReplyEventArgs(simulator, primOwners)); - } - } - - /// Process an incoming packet and raise the appropriate events - /// The sender - /// The EventArgs object containing the packet data - /// Raises the event - protected void SelectParcelObjectsReplyHandler(object sender, PacketReceivedEventArgs e) - { - if (m_ForceSelectObjects == null) return; - - Packet packet = e.Packet; - Simulator simulator = e.Simulator; - - ForceObjectSelectPacket reply = (ForceObjectSelectPacket)packet; - List objectIDs = new List(reply.Data.Length); - objectIDs.AddRange(reply.Data.Select(t => t.LocalID)); - - OnForceSelectObjectsReply(new ForceSelectObjectsReplyEventArgs(simulator, objectIDs, reply._Header.ResetList)); - } - - /// Process an incoming packet and raise the appropriate events - /// The sender - /// The EventArgs object containing the packet data - /// Raises the event - protected void ParcelMediaUpdateHandler(object sender, PacketReceivedEventArgs e) - { - if (m_ParcelMediaUpdateReply == null) return; - - Packet packet = e.Packet; - Simulator simulator = e.Simulator; - - ParcelMediaUpdatePacket reply = (ParcelMediaUpdatePacket)packet; - ParcelMedia media = new ParcelMedia - { - MediaAutoScale = (reply.DataBlock.MediaAutoScale == (byte) 0x1), - MediaID = reply.DataBlock.MediaID, - MediaDesc = Utils.BytesToString(reply.DataBlockExtended.MediaDesc), - MediaHeight = reply.DataBlockExtended.MediaHeight, - MediaLoop = ((reply.DataBlockExtended.MediaLoop & 1) != 0), - MediaType = Utils.BytesToString(reply.DataBlockExtended.MediaType), - MediaWidth = reply.DataBlockExtended.MediaWidth, - MediaURL = Utils.BytesToString(reply.DataBlock.MediaURL) - }; - - - OnParcelMediaUpdateReply(new ParcelMediaUpdateReplyEventArgs(simulator, media)); - } - - /// Process an incoming packet and raise the appropriate events - /// The sender - /// The EventArgs object containing the packet data - protected void ParcelOverlayHandler(object sender, PacketReceivedEventArgs e) - { - const int OVERLAY_COUNT = 4; - Packet packet = e.Packet; - Simulator simulator = e.Simulator; - - ParcelOverlayPacket overlay = (ParcelOverlayPacket)packet; - - if (overlay.ParcelData.SequenceID >= 0 && overlay.ParcelData.SequenceID < OVERLAY_COUNT) - { - int length = overlay.ParcelData.Data.Length; - - Buffer.BlockCopy(overlay.ParcelData.Data, 0, simulator.ParcelOverlay, - overlay.ParcelData.SequenceID * length, length); - simulator.ParcelOverlaysReceived++; - - if (simulator.ParcelOverlaysReceived >= OVERLAY_COUNT) - { - // TODO: ParcelOverlaysReceived should become internal, and reset to zero every - // time it hits four. Also need a callback here - } - } - else - { - Logger.Log("Parcel overlay with sequence ID of " + overlay.ParcelData.SequenceID + - " received from " + simulator, Helpers.LogLevel.Warning, Client); - } - } - - /// Process an incoming packet and raise the appropriate events - /// The sender - /// The EventArgs object containing the packet data - /// Raises the event - protected void ParcelMediaCommandMessagePacketHandler(object sender, PacketReceivedEventArgs e) - { - if (m_ParcelMediaCommand == null) return; - - Packet packet = e.Packet; - Simulator simulator = e.Simulator; - - ParcelMediaCommandMessagePacket pmc = (ParcelMediaCommandMessagePacket)packet; - ParcelMediaCommandMessagePacket.CommandBlockBlock block = pmc.CommandBlock; - - OnParcelMediaCommand(new ParcelMediaCommandEventArgs(simulator, pmc.Header.Sequence, (ParcelFlags)block.Flags, - (ParcelMediaCommand)block.Command, block.Time)); - } - - #endregion Packet Handlers - } - #region EventArgs classes - - /// Contains a parcels dwell data returned from the simulator in response to an - public class ParcelDwellReplyEventArgs : EventArgs - { - private readonly UUID m_ParcelID; - private readonly int m_LocalID; - private readonly float m_Dwell; - - /// Get the global ID of the parcel - public UUID ParcelID => m_ParcelID; - - /// Get the simulator specific ID of the parcel - public int LocalID => m_LocalID; - - /// Get the calculated dwell - public float Dwell => m_Dwell; - - /// - /// Construct a new instance of the ParcelDwellReplyEventArgs class - /// - /// The global ID of the parcel - /// The simulator specific ID of the parcel - /// The calculated dwell for the parcel - public ParcelDwellReplyEventArgs(UUID parcelID, int localID, float dwell) - { - m_ParcelID = parcelID; - m_LocalID = localID; - m_Dwell = dwell; - } - } - - /// Contains basic parcel information data returned from the - /// simulator in response to an request - public class ParcelInfoReplyEventArgs : EventArgs - { - private readonly ParcelInfo m_Parcel; - - /// Get the object containing basic parcel info - public ParcelInfo Parcel => m_Parcel; - - /// - /// Construct a new instance of the ParcelInfoReplyEventArgs class - /// - /// The object containing basic parcel info - public ParcelInfoReplyEventArgs(ParcelInfo parcel) - { - m_Parcel = parcel; - } - } - - /// Contains basic parcel information data returned from the simulator in response to an request - public class ParcelPropertiesEventArgs : EventArgs - { - private readonly Simulator m_Simulator; - private Parcel m_Parcel; - private readonly ParcelResult m_Result; - private readonly int m_SelectedPrims; - private readonly int m_SequenceID; - private readonly bool m_SnapSelection; - - /// Get the simulator the parcel is located in - public Simulator Simulator => m_Simulator; - - /// Get the object containing the details - /// If Result is NoData, this object will not contain valid data - public Parcel Parcel => m_Parcel; - - /// Get the result of the request - public ParcelResult Result => m_Result; - - /// Get the number of primitieves your agent is - /// currently selecting and or sitting on in this parcel - public int SelectedPrims => m_SelectedPrims; - - /// Get the user assigned ID used to correlate a request with - /// these results - public int SequenceID => m_SequenceID; - - /// TODO: - public bool SnapSelection => m_SnapSelection; - - /// - /// Construct a new instance of the ParcelPropertiesEventArgs class - /// - /// The object containing the details - /// The object containing the details - /// The result of the request - /// The number of primitieves your agent is - /// currently selecting and or sitting on in this parcel - /// The user assigned ID used to correlate a request with - /// these results - /// TODO: - public ParcelPropertiesEventArgs(Simulator simulator, Parcel parcel, ParcelResult result, int selectedPrims, - int sequenceID, bool snapSelection) - { - m_Simulator = simulator; - m_Parcel = parcel; - m_Result = result; - m_SelectedPrims = selectedPrims; - m_SequenceID = sequenceID; - m_SnapSelection = snapSelection; - } - } - - /// Contains blacklist and whitelist data returned from the simulator in response to an request - public class ParcelAccessListReplyEventArgs : EventArgs - { - private readonly Simulator m_Simulator; - private readonly int m_SequenceID; - private readonly int m_LocalID; - private readonly uint m_Flags; - private readonly List m_AccessList; - - /// Get the simulator the parcel is located in - public Simulator Simulator => m_Simulator; - - /// Get the user assigned ID used to correlate a request with - /// these results - public int SequenceID => m_SequenceID; - - /// Get the simulator specific ID of the parcel - public int LocalID => m_LocalID; - - /// TODO - public uint Flags => m_Flags; - - /// Get the list containing the white/blacklisted agents for the parcel - public List AccessList => m_AccessList; - - /// - /// Construct a new instance of the ParcelAccessListReplyEventArgs class - /// - /// The simulator the parcel is located in - /// The user assigned ID used to correlate a request with - /// these results - /// The simulator specific ID of the parcel - /// TODO: - /// The list containing the white/blacklisted agents for the parcel - public ParcelAccessListReplyEventArgs(Simulator simulator, int sequenceID, int localID, uint flags, List accessEntries) - { - m_Simulator = simulator; - m_SequenceID = sequenceID; - m_LocalID = localID; - m_Flags = flags; - m_AccessList = accessEntries; - } - } - - /// Contains blacklist and whitelist data returned from the - /// simulator in response to an request - public class ParcelObjectOwnersReplyEventArgs : EventArgs - { - private readonly Simulator m_Simulator; - private readonly List m_Owners; - - /// Get the simulator the parcel is located in - public Simulator Simulator => m_Simulator; - - /// Get the list containing prim ownership counts - public List PrimOwners => m_Owners; - - /// - /// Construct a new instance of the ParcelObjectOwnersReplyEventArgs class - /// - /// The simulator the parcel is located in - /// The list containing prim ownership counts - public ParcelObjectOwnersReplyEventArgs(Simulator simulator, List primOwners) - { - m_Simulator = simulator; - m_Owners = primOwners; - } - } - - /// Contains the data returned when all parcel data has been retrieved from a simulator - public class SimParcelsDownloadedEventArgs : EventArgs - { - private readonly Simulator m_Simulator; - private readonly InternalDictionary m_Parcels; - private readonly int[,] m_ParcelMap; - - /// Get the simulator the parcel data was retrieved from - public Simulator Simulator => m_Simulator; - - /// A dictionary containing the parcel data where the key correlates to the ParcelMap entry - public InternalDictionary Parcels => m_Parcels; - - /// Get the multidimensional array containing a x,y grid mapped - /// to each 64x64 parcel's LocalID. - public int[,] ParcelMap => m_ParcelMap; - - /// - /// Construct a new instance of the SimParcelsDownloadedEventArgs class - /// - /// The simulator the parcel data was retrieved from - /// The dictionary containing the parcel data - /// The multidimensional array containing a x,y grid mapped - /// to each 64x64 parcel's LocalID. - public SimParcelsDownloadedEventArgs(Simulator simulator, InternalDictionary simParcels, int[,] parcelMap) - { - m_Simulator = simulator; - m_Parcels = simParcels; - m_ParcelMap = parcelMap; - } - } - - /// Contains the data returned when a request - public class ForceSelectObjectsReplyEventArgs : EventArgs - { - private readonly Simulator m_Simulator; - private readonly List m_ObjectIDs; - private readonly bool m_ResetList; - - /// Get the simulator the parcel data was retrieved from - public Simulator Simulator => m_Simulator; - - /// Get the list of primitive IDs - public List ObjectIDs => m_ObjectIDs; - - /// true if the list is clean and contains the information - /// only for a given request - public bool ResetList => m_ResetList; - - /// - /// Construct a new instance of the ForceSelectObjectsReplyEventArgs class - /// - /// The simulator the parcel data was retrieved from - /// The list of primitive IDs - /// true if the list is clean and contains the information - /// only for a given request - public ForceSelectObjectsReplyEventArgs(Simulator simulator, List objectIDs, bool resetList) - { - this.m_Simulator = simulator; - this.m_ObjectIDs = objectIDs; - this.m_ResetList = resetList; - } - } - - /// Contains data when the media data for a parcel the avatar is on changes - public class ParcelMediaUpdateReplyEventArgs : EventArgs - { - private readonly Simulator m_Simulator; - private readonly ParcelMedia m_ParcelMedia; - - /// Get the simulator the parcel media data was updated in - public Simulator Simulator => m_Simulator; - - /// Get the updated media information - public ParcelMedia Media => m_ParcelMedia; - - /// - /// Construct a new instance of the ParcelMediaUpdateReplyEventArgs class - /// - /// the simulator the parcel media data was updated in - /// The updated media information - public ParcelMediaUpdateReplyEventArgs(Simulator simulator, ParcelMedia media) - { - this.m_Simulator = simulator; - this.m_ParcelMedia = media; - } - } - - /// Contains the media command for a parcel the agent is currently on - public class ParcelMediaCommandEventArgs : EventArgs - { - private readonly Simulator m_Simulator; - private readonly uint m_Sequence; - private readonly ParcelFlags m_ParcelFlags; - private readonly ParcelMediaCommand m_MediaCommand; - private readonly float m_Time; - - /// Get the simulator the parcel media command was issued in - public Simulator Simulator => m_Simulator; - - /// - public uint Sequence => m_Sequence; - - /// - public ParcelFlags ParcelFlags => m_ParcelFlags; - - /// Get the media command that was sent - public ParcelMediaCommand MediaCommand => m_MediaCommand; - - /// - public float Time => m_Time; - - /// - /// Construct a new instance of the ParcelMediaCommandEventArgs class - /// - /// The simulator the parcel media command was issued in - /// - /// - /// The media command that was sent - /// - public ParcelMediaCommandEventArgs(Simulator simulator, uint sequence, ParcelFlags flags, ParcelMediaCommand command, float time) - { - m_Simulator = simulator; - m_Sequence = sequence; - m_ParcelFlags = flags; - m_MediaCommand = command; - m_Time = time; - } - } - #endregion -} +/* + * Copyright (c) 2006-2016, openmetaverse.co + * Copyright (c) 2021-2022, Sjofn LLC + * 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 openmetaverse.co 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 System.Threading; +using System.Reflection; +using System.Collections.Generic; +using System.Linq; +using OpenMetaverse.Http; +using OpenMetaverse.Packets; +using OpenMetaverse.Interfaces; +using OpenMetaverse.StructuredData; +using OpenMetaverse.Messages.Linden; + +namespace OpenMetaverse +{ + #region Enums + + /// + /// Type of return to use when returning objects from a parcel + /// + public enum ObjectReturnType : uint + { + /// + None = 0, + /// Return objects owned by parcel owner + Owner = 1 << 1, + /// Return objects set to group + Group = 1 << 2, + /// Return objects not owned by parcel owner or set to group + Other = 1 << 3, + /// Return a specific list of objects on parcel + List = 1 << 4, + /// Return objects that are marked for-sale + Sell = 1 << 5 + } + + /// + /// Blacklist/Whitelist flags used in parcels Access List + /// + public enum ParcelAccessFlags : uint + { + /// Agent is denied access + NoAccess = 0, + /// Agent is granted access + Access = 1 + } + + /// + /// The result of a request for parcel properties + /// + public enum ParcelResult : int + { + /// No matches were found for the request + NoData = -1, + /// Request matched a single parcel + Single = 0, + /// Request matched multiple parcels + Multiple = 1 + } + + /// + /// Flags used in the ParcelAccessListRequest packet to specify whether + /// we want the access list (whitelist), ban list (blacklist), or both + /// + [Flags] + public enum AccessList : uint + { + /// Request the access list + Access = 1 << 0, + /// Request the ban list + Ban = 1 << 1, + /// Request both White and Black lists + Both = Access | Ban + } + + /// + /// Sequence ID in ParcelPropertiesReply packets (sent when avatar + /// tries to cross a parcel border) + /// + public enum ParcelPropertiesStatus : int + { + /// Parcel is currently selected + ParcelSelected = -10000, + /// Parcel restricted to a group the avatar is not a + /// member of + CollisionNotInGroup = -20000, + /// Avatar is banned from the parcel + CollisionBanned = -30000, + /// Parcel is restricted to an access list that the + /// avatar is not on + CollisionNotOnAccessList = -40000, + /// Response to hovering over a parcel + HoveredOverParcel = -50000 + } + + /// + /// The tool to use when modifying terrain levels + /// + public enum TerraformAction : byte + { + /// Level the terrain + Level = 0, + /// Raise the terrain + Raise = 1, + /// Lower the terrain + Lower = 2, + /// Smooth the terrain + Smooth = 3, + /// Add random noise to the terrain + Noise = 4, + /// Revert terrain to simulator default + Revert = 5 + } + + /// + /// The tool size to use when changing terrain levels + /// + public enum TerraformBrushSize : byte + { + /// Small + Small = 1, + /// Medium + Medium = 2, + /// Large + Large = 4 + } + + /// + /// Reasons agent is denied access to a parcel on the simulator + /// + public enum AccessDeniedReason : byte + { + /// Agent is not denied, access is granted + NotDenied = 0, + /// Agent is not a member of the group set for the parcel, or which owns the parcel + NotInGroup = 1, + /// Agent is not on the parcels specific allow list + NotOnAllowList = 2, + /// Agent is on the parcels ban list + BannedFromParcel = 3, + /// Unknown + NoAccess = 4, + /// Agent is not age verified and parcel settings deny access to non age verified avatars + NotAgeVerified = 5 + } + + /// + /// Parcel overlay type. This is used primarily for highlighting and + /// coloring which is why it is a single integer instead of a set of + /// flags + /// + /// These values seem to be poorly thought out. The first three + /// bits represent a single value, not flags. For example Auction (0x05) is + /// not a combination of OwnedByOther (0x01) and ForSale(0x04). However, + /// the BorderWest and BorderSouth values are bit flags that get attached + /// to the value stored in the first three bits. Bits four, five, and six + /// are unused + [Flags] + public enum ParcelOverlayType : byte + { + /// Public land + Public = 0, + /// Land is owned by another avatar + OwnedByOther = 1, + /// Land is owned by a group + OwnedByGroup = 2, + /// Land is owned by the current avatar + OwnedBySelf = 3, + /// Land is for sale + ForSale = 4, + /// Land is being auctioned + Auction = 5, + /// Land is private + Private = 32, + /// To the west of this area is a parcel border + BorderWest = 64, + /// To the south of this area is a parcel border + BorderSouth = 128 + } + + /// + /// Various parcel properties + /// + [Flags] + public enum ParcelFlags : uint + { + /// No flags set + None = 0, + /// Allow avatars to fly (a client-side only restriction) + AllowFly = 1 << 0, + /// Allow foreign scripts to run + AllowOtherScripts = 1 << 1, + /// This parcel is for sale + ForSale = 1 << 2, + /// Allow avatars to create a landmark on this parcel + AllowLandmark = 1 << 3, + /// Allows all avatars to edit the terrain on this parcel + AllowTerraform = 1 << 4, + /// Avatars have health and can take damage on this parcel. + /// If set, avatars can be killed and sent home here + AllowDamage = 1 << 5, + /// Foreign avatars can create objects here + CreateObjects = 1 << 6, + /// All objects on this parcel can be purchased + ForSaleObjects = 1 << 7, + /// Access is restricted to a group + UseAccessGroup = 1 << 8, + /// Access is restricted to a whitelist + UseAccessList = 1 << 9, + /// Ban blacklist is enabled + UseBanList = 1 << 10, + /// Unknown + UsePassList = 1 << 11, + /// List this parcel in the search directory + ShowDirectory = 1 << 12, + /// Allow personally owned parcels to be deeded to group + AllowDeedToGroup = 1 << 13, + /// If Deeded, owner contributes required tier to group parcel is deeded to + ContributeWithDeed = 1 << 14, + /// Restrict sounds originating on this parcel to the + /// parcel boundaries + SoundLocal = 1 << 15, + /// Objects on this parcel are sold when the land is + /// purchsaed + SellParcelObjects = 1 << 16, + /// Allow this parcel to be published on the web + AllowPublish = 1 << 17, + /// The information for this parcel is mature content + MaturePublish = 1 << 18, + /// The media URL is an HTML page + UrlWebPage = 1 << 19, + /// The media URL is a raw HTML string + UrlRawHtml = 1 << 20, + /// Restrict foreign object pushes + RestrictPushObject = 1 << 21, + /// Ban all non identified/transacted avatars + DenyAnonymous = 1 << 22, + // Ban all identified avatars [OBSOLETE] + //[Obsolete] + // This was obsoleted in 1.19.0 but appears to be recycled and is used on linden homes parcels + LindenHome = 1 << 23, + // Ban all transacted avatars [OBSOLETE] + //[Obsolete] + //DenyTransacted = 1 << 24, + /// Allow group-owned scripts to run + AllowGroupScripts = 1 << 25, + /// Allow object creation by group members or group + /// objects + CreateGroupObjects = 1 << 26, + /// Allow all objects to enter this parcel + AllowAPrimitiveEntry = 1 << 27, + /// Only allow group and owner objects to enter this parcel + AllowGroupObjectEntry = 1 << 28, + /// Voice Enabled on this parcel + AllowVoiceChat = 1 << 29, + /// Use Estate Voice channel for Voice on this parcel + UseEstateVoiceChan = 1 << 30, + /// Deny Age Unverified Users + DenyAgeUnverified = 1U << 31 + } + + /// + /// Parcel ownership status + /// + public enum ParcelStatus : sbyte + { + /// Placeholder + None = -1, + /// Parcel is leased (owned) by an avatar or group + Leased = 0, + /// Parcel is in process of being leased (purchased) by an avatar or group + LeasePending = 1, + /// Parcel has been abandoned back to Governor Linden + Abandoned = 2 + } + + /// + /// Category parcel is listed in under search + /// + public enum ParcelCategory : sbyte + { + /// No assigned category + None = 0, + /// Linden Infohub or public area + Linden, + /// Adult themed area + Adult, + /// Arts and Culture + Arts, + /// Business + Business, + /// Educational + Educational, + /// Gaming + Gaming, + /// Hangout or Club + Hangout, + /// Newcomer friendly + Newcomer, + /// Parks and Nature + Park, + /// Residential + Residential, + /// Shopping + Shopping, + /// Not Used? + Stage, + /// Other + Other, + /// Not an actual category, only used for queries + Any = -1 + } + + /// + /// Type of teleport landing for a parcel + /// + public enum LandingType : byte + { + /// Unset, simulator default + None = 0, + /// Specific landing point set for this parcel + LandingPoint = 1, + /// No landing point set, direct teleports enabled for + /// this parcel + Direct = 2 + } + + /// + /// Parcel Media Command used in ParcelMediaCommandMessage + /// + public enum ParcelMediaCommand : uint + { + /// Stop the media stream and go back to the first frame + Stop = 0, + /// Pause the media stream (stop playing but stay on current frame) + Pause, + /// Start the current media stream playing and stop when the end is reached + Play, + /// Start the current media stream playing, + /// loop to the beginning when the end is reached and continue to play + Loop, + /// Specifies the texture to replace with video + /// If passing the key of a texture, it must be explicitly typecast as a key, + /// not just passed within double quotes. + Texture, + /// Specifies the movie URL (254 characters max) + URL, + /// Specifies the time index at which to begin playing + Time, + /// Specifies a single agent to apply the media command to + Agent, + /// Unloads the stream. While the stop command sets the texture to the first frame of the movie, + /// unload resets it to the real texture that the movie was replacing. + Unload, + /// Turn on/off the auto align feature, similar to the auto align checkbox in the parcel media properties + /// (NOT to be confused with the "align" function in the textures view of the editor!) Takes TRUE or FALSE as parameter. + AutoAlign, + /// Allows a Web page or image to be placed on a prim (1.19.1 RC0 and later only). + /// Use "text/html" for HTML. + Type, + /// Resizes a Web page to fit on x, y pixels (1.19.1 RC0 and later only). + /// This might still not be working + Size, + /// Sets a description for the media being displayed (1.19.1 RC0 and later only). + Desc + } + + #endregion Enums + + #region Structs + + /// + /// Some information about a parcel of land returned from a DirectoryManager search + /// + public struct ParcelInfo + { + /// Global Key of record + public UUID ID; + /// Parcel Owners + public UUID OwnerID; + /// Name field of parcel, limited to 128 characters + public string Name; + /// Description field of parcel, limited to 256 characters + public string Description; + /// Total Square meters of parcel + public int ActualArea; + /// Total area billable as Tier, for group owned land this will be 10% less than ActualArea + public int BillableArea; + /// True of parcel is in Mature simulator + public bool Mature; + /// Grid global X position of parcel + public float GlobalX; + /// Grid global Y position of parcel + public float GlobalY; + /// Grid global Z position of parcel (not used) + public float GlobalZ; + /// Name of simulator parcel is located in + public string SimName; + /// Texture of parcels display picture + public UUID SnapshotID; + /// Float representing calculated traffic based on time spent on parcel by avatars + public float Dwell; + /// Sale price of parcel (not used) + public int SalePrice; + /// Auction ID of parcel + public int AuctionID; + } + + /// + /// Parcel Media Information + /// + public struct ParcelMedia + { + /// A byte, if 0x1 viewer should auto scale media to fit object + public bool MediaAutoScale; + /// A boolean, if true the viewer should loop the media + public bool MediaLoop; + /// The Asset UUID of the Texture which when applied to a + /// primitive will display the media + public UUID MediaID; + /// A URL which points to any Quicktime supported media type + public string MediaURL; + /// A description of the media + public string MediaDesc; + /// An Integer which represents the height of the media + public int MediaHeight; + /// An integer which represents the width of the media + public int MediaWidth; + /// A string which contains the mime type of the media + public string MediaType; + } + + #endregion Structs + + #region Parcel Class + + /// + /// Parcel of land, a portion of virtual real estate in a simulator + /// + public class Parcel + { + /// The total number of contiguous 4x4 meter blocks your agent owns within this parcel + public int SelfCount; + /// The total number of contiguous 4x4 meter blocks contained in this parcel owned by a group or agent other than your own + public int OtherCount; + /// Deprecated, Value appears to always be 0 + public int PublicCount; + /// Simulator-local ID of this parcel + public int LocalID; + /// UUID of the owner of this parcel + public UUID OwnerID; + /// Whether the land is deeded to a group or not + public bool IsGroupOwned; + /// + public uint AuctionID; + /// Date land was claimed + public DateTime ClaimDate; + /// Appears to always be zero + public int ClaimPrice; + /// This field is no longer used + public int RentPrice; + /// Minimum corner of the axis-aligned bounding box for this + /// parcel + public Vector3 AABBMin; + /// Maximum corner of the axis-aligned bounding box for this + /// parcel + public Vector3 AABBMax; + /// Bitmap describing land layout in 4x4m squares across the + /// entire region + public byte[] Bitmap; + /// Total parcel land area + public int Area; + /// + public ParcelStatus Status; + /// Maximum primitives across the entire simulator owned by the same agent or group that owns this parcel that can be used + public int SimWideMaxPrims; + /// Total primitives across the entire simulator calculated by combining the allowed prim counts for each parcel + /// owned by the agent or group that owns this parcel + public int SimWideTotalPrims; + /// Maximum number of primitives this parcel supports + public int MaxPrims; + /// Total number of primitives on this parcel + public int TotalPrims; + /// For group-owned parcels this indicates the total number of prims deeded to the group, + /// for parcels owned by an individual this inicates the number of prims owned by the individual + public int OwnerPrims; + /// Total number of primitives owned by the parcel group on + /// this parcel, or for parcels owned by an individual with a group set the + /// total number of prims set to that group. + public int GroupPrims; + /// Total number of prims owned by other avatars that are not set to group, or not the parcel owner + public int OtherPrims; + /// A bonus multiplier which allows parcel prim counts to go over times this amount, this does not affect + /// the max prims per simulator. e.g: 117 prim parcel limit x 1.5 bonus = 175 allowed + public float ParcelPrimBonus; + /// Autoreturn value in minutes for others' objects + public int OtherCleanTime; + /// + public ParcelFlags Flags; + /// Sale price of the parcel, only useful if ForSale is set + /// The SalePrice will remain the same after an ownership + /// transfer (sale), so it can be used to see the purchase price after + /// a sale if the new owner has not changed it + public int SalePrice; + /// Parcel Name + public string Name; + /// Parcel Description + public string Desc; + /// URL For Music Stream + public string MusicURL; + /// + public UUID GroupID; + /// Price for a temporary pass + public int PassPrice; + /// How long is pass valid for + public float PassHours; + /// + public ParcelCategory Category; + /// Key of authorized buyer + public UUID AuthBuyerID; + /// Key of parcel snapshot + public UUID SnapshotID; + /// The landing point location + public Vector3 UserLocation; + /// The landing point LookAt + public Vector3 UserLookAt; + /// The type of landing enforced from the enum + public LandingType Landing; + /// + public float Dwell; + /// + public bool RegionDenyAnonymous; + /// + public bool RegionPushOverride; + /// Access list of who is whitelisted on this + /// parcel + public List AccessWhiteList; + /// Access list of who is blacklisted on this + /// parcel + public List AccessBlackList; + /// TRUE of region denies access to age unverified users + public bool RegionDenyAgeUnverified; + /// true to obscure (hide) media url + public bool ObscureMedia; + /// true to obscure (hide) music url + public bool ObscureMusic; + /// A struct containing media details + public ParcelMedia Media; + /// Parcel privacy see avatars outside/inside parcel + public bool SeeAVs; + /// Parcel privacy play sounds attached to avatars outside/inside parcel + public bool AnyAVSounds; + /// Parcel privacy play sounds for group members + public bool GroupAVSounds; + + /// + /// Displays a parcel object in string format + /// + /// string containing key=value pairs of a parcel object + public override string ToString() + { + Type parcelType = this.GetType(); + FieldInfo[] fields = parcelType.GetFields(); + return fields.Aggregate("", (current, field) => current + (field.Name + " = " + field.GetValue(this) + " ")); + } + /// + /// Defalt constructor + /// + /// Local ID of this parcel + public Parcel(int localID) + { + LocalID = localID; + ClaimDate = Utils.Epoch; + Bitmap = Utils.EmptyBytes; + Name = String.Empty; + Desc = String.Empty; + MusicURL = String.Empty; + AccessWhiteList = new List(0); + AccessBlackList = new List(0); + Media = new ParcelMedia(); + } + + /// + /// Update the simulator with any local changes to this Parcel object + /// + /// Simulator to send updates to + /// Whether we want the simulator to confirm + /// the update with a reply packet or not + public void Update(Simulator simulator, bool wantReply) + { + CapsClient request = simulator.Caps.CreateCapsClient("ParcelPropertiesUpdate"); + if (request != null) + { + ParcelPropertiesUpdateMessage req = new ParcelPropertiesUpdateMessage + { + AuthBuyerID = AuthBuyerID, + Category = Category, + Desc = Desc, + GroupID = GroupID, + Landing = Landing, + LocalID = LocalID, + MediaAutoScale = Media.MediaAutoScale, + MediaDesc = Media.MediaDesc, + MediaHeight = Media.MediaHeight, + MediaID = Media.MediaID, + MediaLoop = Media.MediaLoop, + MediaType = Media.MediaType, + MediaURL = Media.MediaURL, + MediaWidth = Media.MediaWidth, + MusicURL = MusicURL, + Name = Name, + ObscureMedia = ObscureMedia, + ObscureMusic = ObscureMusic, + ParcelFlags = Flags, + PassHours = PassHours, + PassPrice = (uint) PassPrice, + SalePrice = (uint) SalePrice, + SnapshotID = SnapshotID, + UserLocation = UserLocation, + UserLookAt = UserLookAt, + SeeAVs = SeeAVs, + AnyAVSounds = AnyAVSounds, + GroupAVSounds = GroupAVSounds + }; + + OSDMap body = req.Serialize(); + + request.PostRequestAsync(body, OSDFormat.Xml, simulator.Client.Settings.CAPS_TIMEOUT); + } + else + { + ParcelPropertiesUpdatePacket updatePacket = new ParcelPropertiesUpdatePacket + { + AgentData = + { + AgentID = simulator.Client.Self.AgentID, + SessionID = simulator.Client.Self.SessionID + }, + ParcelData = + { + LocalID = LocalID, + AuthBuyerID = AuthBuyerID, + Category = (byte) Category, + Desc = Utils.StringToBytes(Desc), + GroupID = GroupID, + LandingType = (byte) Landing, + MediaAutoScale = (Media.MediaAutoScale) ? (byte) 0x1 : (byte) 0x0, + MediaID = Media.MediaID, + MediaURL = Utils.StringToBytes(Media.MediaURL), + MusicURL = Utils.StringToBytes(MusicURL), + Name = Utils.StringToBytes(Name) + } + }; + + + + if (wantReply) updatePacket.ParcelData.Flags = 1; + updatePacket.ParcelData.ParcelFlags = (uint)Flags; + updatePacket.ParcelData.PassHours = PassHours; + updatePacket.ParcelData.PassPrice = PassPrice; + updatePacket.ParcelData.SalePrice = SalePrice; + updatePacket.ParcelData.SnapshotID = SnapshotID; + updatePacket.ParcelData.UserLocation = UserLocation; + updatePacket.ParcelData.UserLookAt = UserLookAt; + + simulator.SendPacket(updatePacket); + } + + UpdateOtherCleanTime(simulator); + + } + + /// + /// Set Autoreturn time + /// + /// Simulator to send the update to + public void UpdateOtherCleanTime(Simulator simulator) + { + ParcelSetOtherCleanTimePacket request = new ParcelSetOtherCleanTimePacket + { + AgentData = + { + AgentID = simulator.Client.Self.AgentID, + SessionID = simulator.Client.Self.SessionID + }, + ParcelData = + { + LocalID = LocalID, + OtherCleanTime = OtherCleanTime + } + }; + + simulator.SendPacket(request); + } + } + + #endregion Parcel Class + + /// + /// Parcel (subdivided simulator lots) subsystem + /// + public class ParcelManager + { + #region Structs + + /// + /// Parcel Accesslist + /// + public struct ParcelAccessEntry + { + /// Agents + public UUID AgentID; + /// + public DateTime Time; + /// Flags for specific entry in white/black lists + public AccessList Flags; + } + + /// + /// Owners of primitives on parcel + /// + public struct ParcelPrimOwners + { + /// Prim Owners + public UUID OwnerID; + /// True of owner is group + public bool IsGroupOwned; + /// Total count of prims owned by OwnerID + public int Count; + /// true of OwnerID is currently online and is not a group + public bool OnlineStatus; + /// The date of the most recent prim left by OwnerID + public DateTime NewestPrim; + } + + #endregion Structs + + #region Delegates + /// + /// Called once parcel resource usage information has been collected + /// + /// Indicates if operation was successfull + /// Parcel resource usage information + public delegate void LandResourcesCallback(bool success, LandResourcesInfo info); + + /// The event subscribers. null if no subcribers + private EventHandler m_DwellReply; + + /// Raises the ParcelDwellReply event + /// A ParcelDwellReplyEventArgs object containing the + /// data returned from the simulator + protected virtual void OnParcelDwellReply(ParcelDwellReplyEventArgs e) + { + EventHandler handler = m_DwellReply; + handler?.Invoke(this, e); + } + + /// Thread sync lock object + private readonly object m_DwellReplyLock = new object(); + + /// Raised when the simulator responds to a request + public event EventHandler ParcelDwellReply + { + add { lock (m_DwellReplyLock) { m_DwellReply += value; } } + remove { lock (m_DwellReplyLock) { m_DwellReply -= value; } } + } + + /// The event subscribers. null if no subcribers + private EventHandler m_ParcelInfo; + + /// Raises the ParcelInfoReply event + /// A ParcelInfoReplyEventArgs object containing the + /// data returned from the simulator + protected virtual void OnParcelInfoReply(ParcelInfoReplyEventArgs e) + { + EventHandler handler = m_ParcelInfo; + handler?.Invoke(this, e); + } + + /// Thread sync lock object + private readonly object m_ParcelInfoLock = new object(); + + /// Raised when the simulator responds to a request + public event EventHandler ParcelInfoReply + { + add { lock (m_ParcelInfoLock) { m_ParcelInfo += value; } } + remove { lock (m_ParcelInfoLock) { m_ParcelInfo -= value; } } + } + + /// The event subscribers. null if no subcribers + private EventHandler m_ParcelProperties; + + /// Raises the ParcelProperties event + /// A ParcelPropertiesEventArgs object containing the + /// data returned from the simulator + protected virtual void OnParcelProperties(ParcelPropertiesEventArgs e) + { + EventHandler handler = m_ParcelProperties; + handler?.Invoke(this, e); + } + + /// Thread sync lock object + private readonly object m_ParcelPropertiesLock = new object(); + + /// Raised when the simulator responds to a request + public event EventHandler ParcelProperties + { + add { lock (m_ParcelPropertiesLock) { m_ParcelProperties += value; } } + remove { lock (m_ParcelPropertiesLock) { m_ParcelProperties -= value; } } + } + + /// The event subscribers. null if no subcribers + private EventHandler m_ParcelACL; + + /// Raises the ParcelAccessListReply event + /// A ParcelAccessListReplyEventArgs object containing the + /// data returned from the simulator + protected virtual void OnParcelAccessListReply(ParcelAccessListReplyEventArgs e) + { + EventHandler handler = m_ParcelACL; + handler?.Invoke(this, e); + } + + /// Thread sync lock object + private readonly object m_ParcelACLLock = new object(); + + /// Raised when the simulator responds to a request + public event EventHandler ParcelAccessListReply + { + add { lock (m_ParcelACLLock) { m_ParcelACL += value; } } + remove { lock (m_ParcelACLLock) { m_ParcelACL -= value; } } + } + + /// The event subscribers. null if no subcribers + private EventHandler m_ParcelObjectOwnersReply; + + /// Raises the ParcelObjectOwnersReply event + /// A ParcelObjectOwnersReplyEventArgs object containing the + /// data returned from the simulator + protected virtual void OnParcelObjectOwnersReply(ParcelObjectOwnersReplyEventArgs e) + { + EventHandler handler = m_ParcelObjectOwnersReply; + handler?.Invoke(this, e); + } + + /// Thread sync lock object + private readonly object m_ParcelObjectOwnersLock = new object(); + + /// Raised when the simulator responds to a request + public event EventHandler ParcelObjectOwnersReply + { + add { lock (m_ParcelObjectOwnersLock) { m_ParcelObjectOwnersReply += value; } } + remove { lock (m_ParcelObjectOwnersLock) { m_ParcelObjectOwnersReply -= value; } } + } + + /// The event subscribers. null if no subcribers + private EventHandler m_SimParcelsDownloaded; + + /// Raises the SimParcelsDownloaded event + /// A SimParcelsDownloadedEventArgs object containing the + /// data returned from the simulator + protected virtual void OnSimParcelsDownloaded(SimParcelsDownloadedEventArgs e) + { + EventHandler handler = m_SimParcelsDownloaded; + handler?.Invoke(this, e); + } + + /// Thread sync lock object + private readonly object m_SimParcelsDownloadedLock = new object(); + + /// Raised when the simulator responds to a request + public event EventHandler SimParcelsDownloaded + { + add { lock (m_SimParcelsDownloadedLock) { m_SimParcelsDownloaded += value; } } + remove { lock (m_SimParcelsDownloadedLock) { m_SimParcelsDownloaded -= value; } } + } + + /// The event subscribers. null if no subcribers + private EventHandler m_ForceSelectObjects; + + /// Raises the ForceSelectObjectsReply event + /// A ForceSelectObjectsReplyEventArgs object containing the + /// data returned from the simulator + protected virtual void OnForceSelectObjectsReply(ForceSelectObjectsReplyEventArgs e) + { + EventHandler handler = m_ForceSelectObjects; + handler?.Invoke(this, e); + } + + /// Thread sync lock object + private readonly object m_ForceSelectObjectsLock = new object(); + + /// Raised when the simulator responds to a request + public event EventHandler ForceSelectObjectsReply + { + add { lock (m_ForceSelectObjectsLock) { m_ForceSelectObjects += value; } } + remove { lock (m_ForceSelectObjectsLock) { m_ForceSelectObjects -= value; } } + } + + /// The event subscribers. null if no subcribers + private EventHandler m_ParcelMediaUpdateReply; + + /// Raises the ParcelMediaUpdateReply event + /// A ParcelMediaUpdateReplyEventArgs object containing the + /// data returned from the simulator + protected virtual void OnParcelMediaUpdateReply(ParcelMediaUpdateReplyEventArgs e) + { + EventHandler handler = m_ParcelMediaUpdateReply; + handler?.Invoke(this, e); + } + + /// Thread sync lock object + private readonly object m_ParcelMediaUpdateReplyLock = new object(); + + /// Raised when the simulator responds to a Parcel Update request + public event EventHandler ParcelMediaUpdateReply + { + add { lock (m_ParcelMediaUpdateReplyLock) { m_ParcelMediaUpdateReply += value; } } + remove { lock (m_ParcelMediaUpdateReplyLock) { m_ParcelMediaUpdateReply -= value; } } + } + + /// The event subscribers. null if no subcribers + private EventHandler m_ParcelMediaCommand; + + /// Raises the ParcelMediaCommand event + /// A ParcelMediaCommandEventArgs object containing the + /// data returned from the simulator + protected virtual void OnParcelMediaCommand(ParcelMediaCommandEventArgs e) + { + EventHandler handler = m_ParcelMediaCommand; + handler?.Invoke(this, e); + } + + /// Thread sync lock object + private readonly object m_ParcelMediaCommandLock = new object(); + + /// Raised when the parcel your agent is located sends a ParcelMediaCommand + public event EventHandler ParcelMediaCommand + { + add { lock (m_ParcelMediaCommandLock) { m_ParcelMediaCommand += value; } } + remove { lock (m_ParcelMediaCommandLock) { m_ParcelMediaCommand -= value; } } + } + #endregion Delegates + + private GridClient Client; + private AutoResetEvent WaitForSimParcel; + + #region Public Methods + + /// + /// Default constructor + /// + /// A reference to the GridClient object + public ParcelManager(GridClient client) + { + Client = client; + + // Setup the callbacks + Client.Network.RegisterCallback(PacketType.ParcelInfoReply, ParcelInfoReplyHandler); + Client.Network.RegisterEventCallback("ParcelObjectOwnersReply", ParcelObjectOwnersReplyHandler); + // CAPS packet handler, to allow for Media Data not contained in the message template + Client.Network.RegisterEventCallback("ParcelProperties", ParcelPropertiesReplyHandler); + Client.Network.RegisterCallback(PacketType.ParcelDwellReply, ParcelDwellReplyHandler); + Client.Network.RegisterCallback(PacketType.ParcelAccessListReply, ParcelAccessListReplyHandler); + Client.Network.RegisterCallback(PacketType.ForceObjectSelect, SelectParcelObjectsReplyHandler); + Client.Network.RegisterCallback(PacketType.ParcelMediaUpdate, ParcelMediaUpdateHandler); + Client.Network.RegisterCallback(PacketType.ParcelOverlay, ParcelOverlayHandler); + Client.Network.RegisterCallback(PacketType.ParcelMediaCommandMessage, ParcelMediaCommandMessagePacketHandler); + } + + /// + /// Request basic information for a single parcel + /// + /// Simulator-local ID of the parcel + public void RequestParcelInfo(UUID parcelID) + { + ParcelInfoRequestPacket request = new ParcelInfoRequestPacket + { + AgentData = + { + AgentID = Client.Self.AgentID, + SessionID = Client.Self.SessionID + }, + Data = {ParcelID = parcelID} + }; + + Client.Network.SendPacket(request); + } + + /// + /// Request properties of a single parcel + /// + /// Simulator containing the parcel + /// Simulator-local ID of the parcel + /// An arbitrary integer that will be returned + /// with the ParcelProperties reply, useful for distinguishing between + /// multiple simultaneous requests + public void RequestParcelProperties(Simulator simulator, int localID, int sequenceID) + { + ParcelPropertiesRequestByIDPacket request = new ParcelPropertiesRequestByIDPacket + { + AgentData = + { + AgentID = Client.Self.AgentID, + SessionID = Client.Self.SessionID + }, + ParcelData = + { + LocalID = localID, + SequenceID = sequenceID + } + }; + + Client.Network.SendPacket(request, simulator); + } + + /// + /// Request the access list for a single parcel + /// + /// Simulator containing the parcel + /// Simulator-local ID of the parcel + /// An arbitrary integer that will be returned + /// with the ParcelAccessList reply, useful for distinguishing between + /// multiple simultaneous requests + /// + public void RequestParcelAccessList(Simulator simulator, int localID, AccessList flags, int sequenceID) + { + ParcelAccessListRequestPacket request = new ParcelAccessListRequestPacket + { + AgentData = + { + AgentID = Client.Self.AgentID, + SessionID = Client.Self.SessionID + }, + Data = + { + LocalID = localID, + Flags = (uint) flags, + SequenceID = sequenceID + } + }; + + Client.Network.SendPacket(request, simulator); + } + + /// + /// Request properties of parcels using a bounding box selection + /// + /// Simulator containing the parcel + /// Northern boundary of the parcel selection + /// Eastern boundary of the parcel selection + /// Southern boundary of the parcel selection + /// Western boundary of the parcel selection + /// An arbitrary integer that will be returned + /// with the ParcelProperties reply, useful for distinguishing between + /// different types of parcel property requests + /// A boolean that is returned with the + /// ParcelProperties reply, useful for snapping focus to a single + /// parcel + public void RequestParcelProperties(Simulator simulator, float north, float east, float south, float west, + int sequenceID, bool snapSelection) + { + ParcelPropertiesRequestPacket request = new ParcelPropertiesRequestPacket + { + AgentData = + { + AgentID = Client.Self.AgentID, + SessionID = Client.Self.SessionID + }, + ParcelData = + { + North = north, + East = east, + South = south, + West = west, + SequenceID = sequenceID, + SnapSelection = snapSelection + } + }; + + Client.Network.SendPacket(request, simulator); + } + + /// + /// Request all simulator parcel properties (used for populating the Simulator.Parcels + /// dictionary) + /// + /// Simulator to request parcels from (must be connected) + public void RequestAllSimParcels(Simulator simulator) + { + RequestAllSimParcels(simulator, false, 750); + } + + /// + /// Request all simulator parcel properties (used for populating the Simulator.Parcels + /// dictionary) + /// + /// Simulator to request parcels from (must be connected) + /// If TRUE, will force a full refresh + /// Number of milliseconds to pause in between each request + public void RequestAllSimParcels(Simulator simulator, bool refresh, int msDelay) + { + if (simulator.DownloadingParcelMap) + { + Logger.Log("Already downloading parcels in " + simulator.Name, Helpers.LogLevel.Info, Client); + return; + } + else + { + simulator.DownloadingParcelMap = true; + WaitForSimParcel = new AutoResetEvent(false); + } + + if (refresh) + { + for (int y = 0; y < 64; y++) + for (int x = 0; x < 64; x++) + simulator.ParcelMap[y, x] = 0; + } + + ThreadPool.QueueUserWorkItem((_) => + { + int count = 0, timeouts = 0, y, x; + + for (y = 0; y < 64; y++) + { + for (x = 0; x < 64; x++) + { + if (!Client.Network.Connected) + return; + + if (simulator.ParcelMap[y, x] == 0) + { + Client.Parcels.RequestParcelProperties(simulator, + (y + 1) * 4.0f, (x + 1) * 4.0f, + y * 4.0f, x * 4.0f, int.MaxValue, false); + + // Wait the given amount of time for a reply before sending the next request + if (!WaitForSimParcel.WaitOne(msDelay, false)) + ++timeouts; + + ++count; + } + } + } + + Logger.Log(String.Format( + "Full simulator parcel information retrieved. Sent {0} parcel requests. Current outgoing queue: {1}, Retry Count {2}", + count, Client.Network.OutboxCount, timeouts), Helpers.LogLevel.Info, Client); + + simulator.DownloadingParcelMap = false; + }); + } + + /// + /// Request the dwell value for a parcel + /// + /// Simulator containing the parcel + /// Simulator-local ID of the parcel + public void RequestDwell(Simulator simulator, int localID) + { + ParcelDwellRequestPacket request = new ParcelDwellRequestPacket + { + AgentData = + { + AgentID = Client.Self.AgentID, + SessionID = Client.Self.SessionID + }, + Data = + { + LocalID = localID, + ParcelID = UUID.Zero + } + }; + // Not used by clients + + Client.Network.SendPacket(request, simulator); + } + + /// + /// Send a request to Purchase a parcel of land + /// + /// The Simulator the parcel is located in + /// The parcels region specific local ID + /// true if this parcel is being purchased by a group + /// The groups + /// true to remove tier contribution if purchase is successful + /// The parcels size + /// The purchase price of the parcel + /// + public void Buy(Simulator simulator, int localID, bool forGroup, UUID groupID, + bool removeContribution, int parcelArea, int parcelPrice) + { + ParcelBuyPacket request = new ParcelBuyPacket + { + AgentData = + { + AgentID = Client.Self.AgentID, + SessionID = Client.Self.SessionID + }, + Data = + { + Final = true, + GroupID = groupID, + LocalID = localID, + IsGroupOwned = forGroup, + RemoveContribution = removeContribution + }, + ParcelData = + { + Area = parcelArea, + Price = parcelPrice + } + }; + + + + + Client.Network.SendPacket(request, simulator); + } + + /// + /// Reclaim a parcel of land + /// + /// The simulator the parcel is in + /// The parcels region specific local ID + public void Reclaim(Simulator simulator, int localID) + { + ParcelReclaimPacket request = new ParcelReclaimPacket + { + AgentData = + { + AgentID = Client.Self.AgentID, + SessionID = Client.Self.SessionID + }, + Data = {LocalID = localID} + }; + + + Client.Network.SendPacket(request, simulator); + } + + /// + /// Deed a parcel to a group + /// + /// The simulator the parcel is in + /// The parcels region specific local ID + /// The groups + public void DeedToGroup(Simulator simulator, int localID, UUID groupID) + { + ParcelDeedToGroupPacket request = new ParcelDeedToGroupPacket + { + AgentData = + { + AgentID = Client.Self.AgentID, + SessionID = Client.Self.SessionID + }, + Data = + { + LocalID = localID, + GroupID = groupID + } + }; + + + Client.Network.SendPacket(request, simulator); + } + + /// + /// Request prim owners of a parcel of land. + /// + /// Simulator parcel is in + /// The parcels region specific local ID + public void RequestObjectOwners(Simulator simulator, int localID) + { + ParcelObjectOwnersRequestPacket request = new ParcelObjectOwnersRequestPacket + { + AgentData = + { + AgentID = Client.Self.AgentID, + SessionID = Client.Self.SessionID + }, + ParcelData = {LocalID = localID} + }; + + + Client.Network.SendPacket(request, simulator); + } + + /// + /// Return objects from a parcel + /// + /// Simulator parcel is in + /// The parcels region specific local ID + /// the type of objects to return, + /// A list containing object owners s to return + public void ReturnObjects(Simulator simulator, int localID, ObjectReturnType type, List ownerIDs) + { + ParcelReturnObjectsPacket request = new ParcelReturnObjectsPacket + { + AgentData = + { + AgentID = Client.Self.AgentID, + SessionID = Client.Self.SessionID + }, + ParcelData = + { + LocalID = localID, + ReturnType = (uint) type + }, + TaskIDs = new ParcelReturnObjectsPacket.TaskIDsBlock[1] + }; + + + // A single null TaskID is (not) used for parcel object returns + request.TaskIDs[0] = new ParcelReturnObjectsPacket.TaskIDsBlock {TaskID = UUID.Zero}; + + // Convert the list of owner UUIDs to packet blocks if a list is given + if (ownerIDs != null) + { + request.OwnerIDs = new ParcelReturnObjectsPacket.OwnerIDsBlock[ownerIDs.Count]; + + for (int i = 0; i < ownerIDs.Count; i++) + { + request.OwnerIDs[i] = new ParcelReturnObjectsPacket.OwnerIDsBlock {OwnerID = ownerIDs[i]}; + } + } + else + { + request.OwnerIDs = new ParcelReturnObjectsPacket.OwnerIDsBlock[0]; + } + + Client.Network.SendPacket(request, simulator); + } + + /// + /// Subdivide (split) a parcel + /// + /// + /// + /// + /// + /// + public void ParcelSubdivide(Simulator simulator, float west, float south, float east, float north) + { + ParcelDividePacket divide = new ParcelDividePacket + { + AgentData = + { + AgentID = Client.Self.AgentID, + SessionID = Client.Self.SessionID + }, + ParcelData = + { + East = east, + North = north, + South = south, + West = west + } + }; + + Client.Network.SendPacket(divide, simulator); + } + + /// + /// Join two parcels of land creating a single parcel + /// + /// + /// + /// + /// + /// + public void ParcelJoin(Simulator simulator, float west, float south, float east, float north) + { + ParcelJoinPacket join = new ParcelJoinPacket(); + join.AgentData.AgentID = Client.Self.AgentID; + join.AgentData.SessionID = Client.Self.SessionID; + join.ParcelData.East = east; + join.ParcelData.North = north; + join.ParcelData.South = south; + join.ParcelData.West = west; + + Client.Network.SendPacket(join, simulator); + } + + /// + /// Get a parcels LocalID + /// + /// Simulator parcel is in + /// Vector3 position in simulator (Z not used) + /// 0 on failure, or parcel LocalID on success. + /// A call to Parcels.RequestAllSimParcels is required to populate map and + /// dictionary. + public int GetParcelLocalID(Simulator simulator, Vector3 position) + { + if (simulator.ParcelMap[(byte)position.Y / 4, (byte)position.X / 4] > 0) + { + return simulator.ParcelMap[(byte)position.Y / 4, (byte)position.X / 4]; + } + else + { + Logger.Log(String.Format("ParcelMap returned an default/invalid value for location {0}/{1} Did you use RequestAllSimParcels() to populate the dictionaries?", (byte)position.Y / 4, (byte)position.X / 4 ), Helpers.LogLevel.Warning); + return 0; + } + } + + /// + /// Terraform (raise, lower, etc) an area or whole parcel of land + /// + /// Simulator land area is in. + /// LocalID of parcel, or -1 if using bounding box + /// From Enum, Raise, Lower, Level, Smooth, Etc. + /// Size of area to modify + /// true on successful request sent. + /// Settings.STORE_LAND_PATCHES must be true, + /// Parcel information must be downloaded using RequestAllSimParcels() + public bool Terraform(Simulator simulator, int localID, TerraformAction action, TerraformBrushSize brushSize) + { + return Terraform(simulator, localID, 0f, 0f, 0f, 0f, action, brushSize, 1); + } + + /// + /// Terraform (raise, lower, etc) an area or whole parcel of land + /// + /// Simulator land area is in. + /// west border of area to modify + /// south border of area to modify + /// east border of area to modify + /// north border of area to modify + /// From Enum, Raise, Lower, Level, Smooth, Etc. + /// Size of area to modify + /// true on successful request sent. + /// Settings.STORE_LAND_PATCHES must be true, + /// Parcel information must be downloaded using RequestAllSimParcels() + public bool Terraform(Simulator simulator, float west, float south, float east, float north, + TerraformAction action, TerraformBrushSize brushSize) + { + return Terraform(simulator, -1, west, south, east, north, action, brushSize, 1); + } + + /// + /// Terraform (raise, lower, etc) an area or whole parcel of land + /// + /// Simulator land area is in. + /// LocalID of parcel, or -1 if using bounding box + /// west border of area to modify + /// south border of area to modify + /// east border of area to modify + /// north border of area to modify + /// From Enum, Raise, Lower, Level, Smooth, Etc. + /// Size of area to modify + /// How many meters + or - to lower, 1 = 1 meter + /// true on successful request sent. + /// Settings.STORE_LAND_PATCHES must be true, + /// Parcel information must be downloaded using RequestAllSimParcels() + public bool Terraform(Simulator simulator, int localID, float west, float south, float east, float north, + TerraformAction action, TerraformBrushSize brushSize, int seconds) + { + float height = 0f; + int x, y; + if (localID == -1) + { + x = (int)east - (int)west / 2; + y = (int)north - (int)south / 2; + } + else + { + Parcel p; + if (!simulator.Parcels.TryGetValue(localID, out p)) + { + Logger.Log(String.Format("Can't find parcel {0} in simulator {1}", localID, simulator), + Helpers.LogLevel.Warning, Client); + return false; + } + + x = (int)p.AABBMax.X - (int)p.AABBMin.X / 2; + y = (int)p.AABBMax.Y - (int)p.AABBMin.Y / 2; + } + + if (!simulator.TerrainHeightAtPoint(x, y, out height)) + { + Logger.Log("Land Patch not stored for location", Helpers.LogLevel.Warning, Client); + return false; + } + + Terraform(simulator, localID, west, south, east, north, action, brushSize, seconds, height); + return true; + } + + /// + /// Terraform (raise, lower, etc) an area or whole parcel of land + /// + /// Simulator land area is in. + /// LocalID of parcel, or -1 if using bounding box + /// west border of area to modify + /// south border of area to modify + /// east border of area to modify + /// north border of area to modify + /// From Enum, Raise, Lower, Level, Smooth, Etc. + /// Size of area to modify + /// How many meters + or - to lower, 1 = 1 meter + /// Height at which the terraform operation is acting at + public void Terraform(Simulator simulator, int localID, float west, float south, float east, float north, + TerraformAction action, TerraformBrushSize brushSize, int seconds, float height) + { + ModifyLandPacket land = new ModifyLandPacket + { + AgentData = + { + AgentID = Client.Self.AgentID, + SessionID = Client.Self.SessionID + }, + ModifyBlock = + { + Action = (byte) action, + BrushSize = (byte) brushSize, + Seconds = seconds, + Height = height + }, + ParcelData = new ModifyLandPacket.ParcelDataBlock[1] + }; + + + land.ParcelData[0] = new ModifyLandPacket.ParcelDataBlock + { + LocalID = localID, + West = west, + South = south, + East = east, + North = north + }; + + land.ModifyBlockExtended = new ModifyLandPacket.ModifyBlockExtendedBlock[1]; + land.ModifyBlockExtended[0] = new ModifyLandPacket.ModifyBlockExtendedBlock {BrushSize = (float) brushSize}; + + Client.Network.SendPacket(land, simulator); + } + + /// + /// Sends a request to the simulator to return a list of objects owned by specific owners + /// + /// Simulator local ID of parcel + /// Owners, Others, Etc + /// List containing keys of avatars objects to select; + /// if List is null will return Objects of type selectType + /// Response data is returned in the event + public void RequestSelectObjects(int localID, ObjectReturnType selectType, UUID ownerID) + { + ParcelSelectObjectsPacket select = new ParcelSelectObjectsPacket(); + select.AgentData.AgentID = Client.Self.AgentID; + select.AgentData.SessionID = Client.Self.SessionID; + + select.ParcelData.LocalID = localID; + select.ParcelData.ReturnType = (uint)selectType; + + select.ReturnIDs = new ParcelSelectObjectsPacket.ReturnIDsBlock[1]; + select.ReturnIDs[0] = new ParcelSelectObjectsPacket.ReturnIDsBlock {ReturnID = ownerID}; + + Client.Network.SendPacket(select); + } + + /// + /// Eject and optionally ban a user from a parcel + /// + /// target key of avatar to eject + /// true to also ban target + public void EjectUser(UUID targetID, bool ban) + { + EjectUserPacket eject = new EjectUserPacket + { + AgentData = + { + AgentID = Client.Self.AgentID, + SessionID = Client.Self.SessionID + }, + Data = {TargetID = targetID} + }; + eject.Data.Flags = ban ? (uint)1 : 0; + + Client.Network.SendPacket(eject); + } + + /// + /// Freeze or unfreeze an avatar over your land + /// + /// target key to freeze + /// true to freeze, false to unfreeze + public void FreezeUser(UUID targetID, bool freeze) + { + FreezeUserPacket frz = new FreezeUserPacket + { + AgentData = + { + AgentID = Client.Self.AgentID, + SessionID = Client.Self.SessionID + }, + Data = {TargetID = targetID} + }; + frz.Data.Flags = freeze ? (uint)0 : 1; + + Client.Network.SendPacket(frz); + } + + /// + /// Abandon a parcel of land + /// + /// Simulator parcel is in + /// Simulator local ID of parcel + public void ReleaseParcel(Simulator simulator, int localID) + { + ParcelReleasePacket abandon = new ParcelReleasePacket + { + AgentData = + { + AgentID = Client.Self.AgentID, + SessionID = Client.Self.SessionID + }, + Data = {LocalID = localID} + }; + + Client.Network.SendPacket(abandon, simulator); + } + + /// + /// Requests the UUID of the parcel in a remote region at a specified location + /// + /// Location of the parcel in the remote region + /// Remote region handle + /// Remote region UUID + /// If successful UUID of the remote parcel, UUID.Zero otherwise + public UUID RequestRemoteParcelID(Vector3 location, ulong regionHandle, UUID regionID) + { + if (Client.Network.CurrentSim == null || Client.Network.CurrentSim.Caps == null) + return UUID.Zero; + + CapsClient request = Client.Network.CurrentSim.Caps.CreateCapsClient("RemoteParcelRequest"); + + if (request != null) + { + RemoteParcelRequestRequest msg = new RemoteParcelRequestRequest + { + Location = location, + RegionHandle = regionHandle, + RegionID = regionID + }; + + try + { + OSDMap result = request.PostRequest(msg.Serialize(), OSDFormat.Xml, Client.Settings.CAPS_TIMEOUT) as OSDMap; + RemoteParcelRequestReply response = new RemoteParcelRequestReply(); + response.Deserialize(result); + return response.ParcelID; + } + catch (Exception) + { + Logger.Log("Failed to fetch remote parcel ID", Helpers.LogLevel.Debug, Client); + } + } + + return UUID.Zero; + + } + + /// + /// Retrieves information on resources used by the parcel + /// + /// UUID of the parcel + /// Should per object resource usage be requested + /// Callback invoked when the request is complete + public void GetParcelResouces(UUID parcelID, bool getDetails, LandResourcesCallback callback) + { + try + { + CapsClient request = Client.Network.CurrentSim.Caps.CreateCapsClient("LandResources"); + + request.OnComplete += delegate(CapsClient client, OSD result, Exception error) + { + try + { + if (result == null || error != null) + { + callback(false, null); + } + LandResourcesMessage response = new LandResourcesMessage(); + response.Deserialize((OSDMap)result); + + CapsClient summaryRequest = new CapsClient(response.ScriptResourceSummary, "ScriptResourceSummary"); + OSD summaryResponse = summaryRequest.GetRequest(Client.Settings.CAPS_TIMEOUT); + + LandResourcesInfo res = new LandResourcesInfo(); + res.Deserialize((OSDMap)summaryResponse); + + if (response.ScriptResourceDetails != null && getDetails) + { + CapsClient detailRequest = new CapsClient(response.ScriptResourceDetails, "ScriptResourceDetails"); + OSD detailResponse = detailRequest.GetRequest(Client.Settings.CAPS_TIMEOUT); + res.Deserialize((OSDMap)detailResponse); + } + callback(true, res); + } + catch (Exception ex) + { + Logger.Log("Failed fetching land resources", Helpers.LogLevel.Error, Client, ex); + callback(false, null); + } + }; + + LandResourcesRequest param = new LandResourcesRequest {ParcelID = parcelID}; + request.PostRequestAsync(param.Serialize(), OSDFormat.Xml, Client.Settings.CAPS_TIMEOUT); + + } + catch (Exception ex) + { + Logger.Log("Failed fetching land resources:", Helpers.LogLevel.Error, Client, ex); + callback(false, null); + } + } + + #endregion Public Methods + + #region Packet Handlers + + /// Process an incoming packet and raise the appropriate events + /// The sender + /// The EventArgs object containing the packet data + /// Raises the event + protected void ParcelDwellReplyHandler(object sender, PacketReceivedEventArgs e) + { + if (m_DwellReply != null || Client.Settings.ALWAYS_REQUEST_PARCEL_DWELL) + { + Packet packet = e.Packet; + Simulator simulator = e.Simulator; + + ParcelDwellReplyPacket dwell = (ParcelDwellReplyPacket)packet; + + lock (simulator.Parcels.Dictionary) + { + if (simulator.Parcels.Dictionary.ContainsKey(dwell.Data.LocalID)) + { + Parcel parcel = simulator.Parcels.Dictionary[dwell.Data.LocalID]; + parcel.Dwell = dwell.Data.Dwell; + simulator.Parcels.Dictionary[dwell.Data.LocalID] = parcel; + } + } + + if (m_DwellReply != null) + { + OnParcelDwellReply(new ParcelDwellReplyEventArgs(dwell.Data.ParcelID, dwell.Data.LocalID, dwell.Data.Dwell)); + } + } + } + + /// Process an incoming packet and raise the appropriate events + /// The sender + /// The EventArgs object containing the packet data + /// Raises the event + protected void ParcelInfoReplyHandler(object sender, PacketReceivedEventArgs e) + { + if (m_ParcelInfo == null) return; + + Packet packet = e.Packet; + ParcelInfoReplyPacket info = (ParcelInfoReplyPacket)packet; + + ParcelInfo parcelInfo = new ParcelInfo + { + ActualArea = info.Data.ActualArea, + AuctionID = info.Data.AuctionID, + BillableArea = info.Data.BillableArea, + Description = Utils.BytesToString(info.Data.Desc), + Dwell = info.Data.Dwell, + GlobalX = info.Data.GlobalX, + GlobalY = info.Data.GlobalY, + GlobalZ = info.Data.GlobalZ, + ID = info.Data.ParcelID, + Mature = ((info.Data.Flags & 1) != 0), + Name = Utils.BytesToString(info.Data.Name), + OwnerID = info.Data.OwnerID, + SalePrice = info.Data.SalePrice, + SimName = Utils.BytesToString(info.Data.SimName), + SnapshotID = info.Data.SnapshotID + }; + + + OnParcelInfoReply(new ParcelInfoReplyEventArgs(parcelInfo)); + } + + protected void ParcelPropertiesReplyHandler(string capsKey, IMessage message, Simulator simulator) + { + if (m_ParcelProperties == null && Client.Settings.PARCEL_TRACKING != true) return; + ParcelPropertiesMessage msg = (ParcelPropertiesMessage)message; + + Parcel parcel = new Parcel(msg.LocalID) + { + AABBMax = msg.AABBMax, + AABBMin = msg.AABBMin, + Area = msg.Area, + AuctionID = msg.AuctionID, + AuthBuyerID = msg.AuthBuyerID, + Bitmap = msg.Bitmap, + Category = msg.Category, + ClaimDate = msg.ClaimDate, + ClaimPrice = msg.ClaimPrice, + Desc = msg.Desc, + Flags = msg.ParcelFlags, + GroupID = msg.GroupID, + GroupPrims = msg.GroupPrims, + IsGroupOwned = msg.IsGroupOwned, + Landing = msg.LandingType, + MaxPrims = msg.MaxPrims, + Media = + { + MediaAutoScale = msg.MediaAutoScale, + MediaID = msg.MediaID, + MediaURL = msg.MediaURL + }, + MusicURL = msg.MusicURL, + Name = msg.Name, + OtherCleanTime = msg.OtherCleanTime, + OtherCount = msg.OtherCount, + OtherPrims = msg.OtherPrims, + OwnerID = msg.OwnerID, + OwnerPrims = msg.OwnerPrims, + ParcelPrimBonus = msg.ParcelPrimBonus, + PassHours = msg.PassHours, + PassPrice = msg.PassPrice, + PublicCount = msg.PublicCount, + RegionDenyAgeUnverified = msg.RegionDenyAgeUnverified, + RegionDenyAnonymous = msg.RegionDenyAnonymous, + RegionPushOverride = msg.RegionPushOverride, + RentPrice = msg.RentPrice, + SeeAVs = msg.SeeAVs, + AnyAVSounds = msg.AnyAVSounds, + GroupAVSounds = msg.GroupAVSounds + + }; + + ParcelResult result = msg.RequestResult; + parcel.SalePrice = msg.SalePrice; + int selectedPrims = msg.SelectedPrims; + parcel.SelfCount = msg.SelfCount; + int sequenceID = msg.SequenceID; + parcel.SimWideMaxPrims = msg.SimWideMaxPrims; + parcel.SimWideTotalPrims = msg.SimWideTotalPrims; + bool snapSelection = msg.SnapSelection; + parcel.SnapshotID = msg.SnapshotID; + parcel.Status = msg.Status; + parcel.TotalPrims = msg.TotalPrims; + parcel.UserLocation = msg.UserLocation; + parcel.UserLookAt = msg.UserLookAt; + parcel.Media.MediaDesc = msg.MediaDesc; + parcel.Media.MediaHeight = msg.MediaHeight; + parcel.Media.MediaWidth = msg.MediaWidth; + parcel.Media.MediaLoop = msg.MediaLoop; + parcel.Media.MediaType = msg.MediaType; + parcel.ObscureMedia = msg.ObscureMedia; + parcel.ObscureMusic = msg.ObscureMusic; + + if (Client.Settings.PARCEL_TRACKING) + { + lock (simulator.Parcels.Dictionary) + simulator.Parcels.Dictionary[parcel.LocalID] = parcel; + + bool set = false; + int y, x, index, bit; + for (y = 0; y < 64; y++) + { + for (x = 0; x < 64; x++) + { + index = (y * 64) + x; + bit = index % 8; + index >>= 3; + + if ((parcel.Bitmap[index] & (1 << bit)) != 0) + { + simulator.ParcelMap[y, x] = parcel.LocalID; + set = true; + } + } + } + + if (!set) + { + Logger.Log("Received a parcel with a bitmap that did not map to any locations", + Helpers.LogLevel.Warning); + } + } + + if (sequenceID.Equals(int.MaxValue)) + WaitForSimParcel?.Set(); + + // auto request acl, will be stored in parcel tracking dictionary if enabled + if (Client.Settings.ALWAYS_REQUEST_PARCEL_ACL) + Client.Parcels.RequestParcelAccessList(simulator, parcel.LocalID, + AccessList.Both, sequenceID); + + // auto request dwell, will be stored in parcel tracking dictionary if enables + if (Client.Settings.ALWAYS_REQUEST_PARCEL_DWELL) + Client.Parcels.RequestDwell(simulator, parcel.LocalID); + + // Fire the callback for parcel properties being received + if (m_ParcelProperties != null) + { + OnParcelProperties(new ParcelPropertiesEventArgs(simulator, parcel, result, selectedPrims, sequenceID, snapSelection)); + } + + // Check if all of the simulator parcels have been retrieved, if so fire another callback + if (simulator.IsParcelMapFull() && m_SimParcelsDownloaded != null) + { + OnSimParcelsDownloaded(new SimParcelsDownloadedEventArgs(simulator, simulator.Parcels, simulator.ParcelMap)); + } + } + + /// Process an incoming packet and raise the appropriate events + /// The sender + /// The EventArgs object containing the packet data + /// Raises the event + protected void ParcelAccessListReplyHandler(object sender, PacketReceivedEventArgs e) + { + if (m_ParcelACL != null || Client.Settings.ALWAYS_REQUEST_PARCEL_ACL) + { + Packet packet = e.Packet; + Simulator simulator = e.Simulator; + + ParcelAccessListReplyPacket reply = (ParcelAccessListReplyPacket)packet; + + List accessList = new List(reply.List.Length); + + foreach (ParcelAccessListReplyPacket.ListBlock t in reply.List) + { + ParcelAccessEntry pae = new ParcelAccessEntry + { + AgentID = t.ID, + Time = Utils.UnixTimeToDateTime((uint) t.Time), + Flags = (AccessList) t.Flags + }; + + accessList.Add(pae); + } + + lock (simulator.Parcels.Dictionary) + { + if (simulator.Parcels.Dictionary.ContainsKey(reply.Data.LocalID)) + { + Parcel parcel = simulator.Parcels.Dictionary[reply.Data.LocalID]; + if ((AccessList)reply.Data.Flags == AccessList.Ban) + parcel.AccessBlackList = accessList; + else + parcel.AccessWhiteList = accessList; + + simulator.Parcels.Dictionary[reply.Data.LocalID] = parcel; + } + } + + + if (m_ParcelACL != null) + { + OnParcelAccessListReply(new ParcelAccessListReplyEventArgs(simulator, reply.Data.SequenceID, reply.Data.LocalID, + reply.Data.Flags, accessList)); + } + } + } + + protected void ParcelObjectOwnersReplyHandler(string capsKey, IMessage message, Simulator simulator) + { + if (m_ParcelObjectOwnersReply != null) + { + List primOwners = new List(); + + ParcelObjectOwnersReplyMessage msg = (ParcelObjectOwnersReplyMessage)message; + + foreach (ParcelObjectOwnersReplyMessage.PrimOwner t in msg.PrimOwnersBlock) + { + ParcelPrimOwners primOwner = new ParcelPrimOwners + { + OwnerID = t.OwnerID, + Count = t.Count, + IsGroupOwned = t.IsGroupOwned, + OnlineStatus = t.OnlineStatus, + NewestPrim = t.TimeStamp + }; + + primOwners.Add(primOwner); + } + + OnParcelObjectOwnersReply(new ParcelObjectOwnersReplyEventArgs(simulator, primOwners)); + } + } + + /// Process an incoming packet and raise the appropriate events + /// The sender + /// The EventArgs object containing the packet data + /// Raises the event + protected void SelectParcelObjectsReplyHandler(object sender, PacketReceivedEventArgs e) + { + if (m_ForceSelectObjects == null) return; + + Packet packet = e.Packet; + Simulator simulator = e.Simulator; + + ForceObjectSelectPacket reply = (ForceObjectSelectPacket)packet; + List objectIDs = new List(reply.Data.Length); + objectIDs.AddRange(reply.Data.Select(t => t.LocalID)); + + OnForceSelectObjectsReply(new ForceSelectObjectsReplyEventArgs(simulator, objectIDs, reply._Header.ResetList)); + } + + /// Process an incoming packet and raise the appropriate events + /// The sender + /// The EventArgs object containing the packet data + /// Raises the event + protected void ParcelMediaUpdateHandler(object sender, PacketReceivedEventArgs e) + { + if (m_ParcelMediaUpdateReply == null) return; + + Packet packet = e.Packet; + Simulator simulator = e.Simulator; + + ParcelMediaUpdatePacket reply = (ParcelMediaUpdatePacket)packet; + ParcelMedia media = new ParcelMedia + { + MediaAutoScale = (reply.DataBlock.MediaAutoScale == (byte) 0x1), + MediaID = reply.DataBlock.MediaID, + MediaDesc = Utils.BytesToString(reply.DataBlockExtended.MediaDesc), + MediaHeight = reply.DataBlockExtended.MediaHeight, + MediaLoop = ((reply.DataBlockExtended.MediaLoop & 1) != 0), + MediaType = Utils.BytesToString(reply.DataBlockExtended.MediaType), + MediaWidth = reply.DataBlockExtended.MediaWidth, + MediaURL = Utils.BytesToString(reply.DataBlock.MediaURL) + }; + + + OnParcelMediaUpdateReply(new ParcelMediaUpdateReplyEventArgs(simulator, media)); + } + + /// Process an incoming packet and raise the appropriate events + /// The sender + /// The EventArgs object containing the packet data + protected void ParcelOverlayHandler(object sender, PacketReceivedEventArgs e) + { + const int OVERLAY_COUNT = 4; + Packet packet = e.Packet; + Simulator simulator = e.Simulator; + + ParcelOverlayPacket overlay = (ParcelOverlayPacket)packet; + + if (overlay.ParcelData.SequenceID >= 0 && overlay.ParcelData.SequenceID < OVERLAY_COUNT) + { + int length = overlay.ParcelData.Data.Length; + + Buffer.BlockCopy(overlay.ParcelData.Data, 0, simulator.ParcelOverlay, + overlay.ParcelData.SequenceID * length, length); + simulator.ParcelOverlaysReceived++; + + if (simulator.ParcelOverlaysReceived >= OVERLAY_COUNT) + { + // TODO: ParcelOverlaysReceived should become internal, and reset to zero every + // time it hits four. Also need a callback here + } + } + else + { + Logger.Log("Parcel overlay with sequence ID of " + overlay.ParcelData.SequenceID + + " received from " + simulator, Helpers.LogLevel.Warning, Client); + } + } + + /// Process an incoming packet and raise the appropriate events + /// The sender + /// The EventArgs object containing the packet data + /// Raises the event + protected void ParcelMediaCommandMessagePacketHandler(object sender, PacketReceivedEventArgs e) + { + if (m_ParcelMediaCommand == null) return; + + Packet packet = e.Packet; + Simulator simulator = e.Simulator; + + ParcelMediaCommandMessagePacket pmc = (ParcelMediaCommandMessagePacket)packet; + ParcelMediaCommandMessagePacket.CommandBlockBlock block = pmc.CommandBlock; + + OnParcelMediaCommand(new ParcelMediaCommandEventArgs(simulator, pmc.Header.Sequence, (ParcelFlags)block.Flags, + (ParcelMediaCommand)block.Command, block.Time)); + } + + #endregion Packet Handlers + } + #region EventArgs classes + + /// Contains a parcels dwell data returned from the simulator in response to an + public class ParcelDwellReplyEventArgs : EventArgs + { + /// Get the global ID of the parcel + public UUID ParcelID { get; } + + /// Get the simulator specific ID of the parcel + public int LocalID { get; } + + /// Get the calculated dwell + public float Dwell { get; } + + /// + /// Construct a new instance of the ParcelDwellReplyEventArgs class + /// + /// The global ID of the parcel + /// The simulator specific ID of the parcel + /// The calculated dwell for the parcel + public ParcelDwellReplyEventArgs(UUID parcelID, int localID, float dwell) + { + ParcelID = parcelID; + LocalID = localID; + Dwell = dwell; + } + } + + /// Contains basic parcel information data returned from the + /// simulator in response to an request + public class ParcelInfoReplyEventArgs : EventArgs + { + /// Get the object containing basic parcel info + public ParcelInfo Parcel { get; } + + /// + /// Construct a new instance of the ParcelInfoReplyEventArgs class + /// + /// The object containing basic parcel info + public ParcelInfoReplyEventArgs(ParcelInfo parcel) + { + Parcel = parcel; + } + } + + /// Contains basic parcel information data returned from the simulator in response to an request + public class ParcelPropertiesEventArgs : EventArgs + { + /// Get the simulator the parcel is located in + public Simulator Simulator { get; } + + /// Get the object containing the details + /// If Result is NoData, this object will not contain valid data + public Parcel Parcel { get; } + + /// Get the result of the request + public ParcelResult Result { get; } + + /// Get the number of primitieves your agent is + /// currently selecting and or sitting on in this parcel + public int SelectedPrims { get; } + + /// Get the user assigned ID used to correlate a request with + /// these results + public int SequenceID { get; } + + /// TODO: + public bool SnapSelection { get; } + + /// + /// Construct a new instance of the ParcelPropertiesEventArgs class + /// + /// The object containing the details + /// The object containing the details + /// The result of the request + /// The number of primitieves your agent is + /// currently selecting and or sitting on in this parcel + /// The user assigned ID used to correlate a request with + /// these results + /// TODO: + public ParcelPropertiesEventArgs(Simulator simulator, Parcel parcel, ParcelResult result, int selectedPrims, + int sequenceID, bool snapSelection) + { + Simulator = simulator; + Parcel = parcel; + Result = result; + SelectedPrims = selectedPrims; + SequenceID = sequenceID; + SnapSelection = snapSelection; + } + } + + /// Contains blacklist and whitelist data returned from the simulator in response to an request + public class ParcelAccessListReplyEventArgs : EventArgs + { + /// Get the simulator the parcel is located in + public Simulator Simulator { get; } + + /// Get the user assigned ID used to correlate a request with + /// these results + public int SequenceID { get; } + + /// Get the simulator specific ID of the parcel + public int LocalID { get; } + + /// TODO + public uint Flags { get; } + + /// Get the list containing the white/blacklisted agents for the parcel + public List AccessList { get; } + + /// + /// Construct a new instance of the ParcelAccessListReplyEventArgs class + /// + /// The simulator the parcel is located in + /// The user assigned ID used to correlate a request with + /// these results + /// The simulator specific ID of the parcel + /// TODO: + /// The list containing the white/blacklisted agents for the parcel + public ParcelAccessListReplyEventArgs(Simulator simulator, int sequenceID, int localID, uint flags, List accessEntries) + { + Simulator = simulator; + SequenceID = sequenceID; + LocalID = localID; + Flags = flags; + AccessList = accessEntries; + } + } + + /// Contains blacklist and whitelist data returned from the + /// simulator in response to an request + public class ParcelObjectOwnersReplyEventArgs : EventArgs + { + /// Get the simulator the parcel is located in + public Simulator Simulator { get; } + + /// Get the list containing prim ownership counts + public List PrimOwners { get; } + + /// + /// Construct a new instance of the ParcelObjectOwnersReplyEventArgs class + /// + /// The simulator the parcel is located in + /// The list containing prim ownership counts + public ParcelObjectOwnersReplyEventArgs(Simulator simulator, List primOwners) + { + Simulator = simulator; + PrimOwners = primOwners; + } + } + + /// Contains the data returned when all parcel data has been retrieved from a simulator + public class SimParcelsDownloadedEventArgs : EventArgs + { + /// Get the simulator the parcel data was retrieved from + public Simulator Simulator { get; } + + /// A dictionary containing the parcel data where the key correlates to the ParcelMap entry + public InternalDictionary Parcels { get; } + + /// Get the multidimensional array containing a x,y grid mapped + /// to each 64x64 parcel's LocalID. + public int[,] ParcelMap { get; } + + /// + /// Construct a new instance of the SimParcelsDownloadedEventArgs class + /// + /// The simulator the parcel data was retrieved from + /// The dictionary containing the parcel data + /// The multidimensional array containing a x,y grid mapped + /// to each 64x64 parcel's LocalID. + public SimParcelsDownloadedEventArgs(Simulator simulator, InternalDictionary simParcels, int[,] parcelMap) + { + Simulator = simulator; + Parcels = simParcels; + ParcelMap = parcelMap; + } + } + + /// Contains the data returned when a request + public class ForceSelectObjectsReplyEventArgs : EventArgs + { + /// Get the simulator the parcel data was retrieved from + public Simulator Simulator { get; } + + /// Get the list of primitive IDs + public List ObjectIDs { get; } + + /// true if the list is clean and contains the information + /// only for a given request + public bool ResetList { get; } + + /// + /// Construct a new instance of the ForceSelectObjectsReplyEventArgs class + /// + /// The simulator the parcel data was retrieved from + /// The list of primitive IDs + /// true if the list is clean and contains the information + /// only for a given request + public ForceSelectObjectsReplyEventArgs(Simulator simulator, List objectIDs, bool resetList) + { + this.Simulator = simulator; + this.ObjectIDs = objectIDs; + this.ResetList = resetList; + } + } + + /// Contains data when the media data for a parcel the avatar is on changes + public class ParcelMediaUpdateReplyEventArgs : EventArgs + { + /// Get the simulator the parcel media data was updated in + public Simulator Simulator { get; } + + /// Get the updated media information + public ParcelMedia Media { get; } + + /// + /// Construct a new instance of the ParcelMediaUpdateReplyEventArgs class + /// + /// the simulator the parcel media data was updated in + /// The updated media information + public ParcelMediaUpdateReplyEventArgs(Simulator simulator, ParcelMedia media) + { + this.Simulator = simulator; + this.Media = media; + } + } + + /// Contains the media command for a parcel the agent is currently on + public class ParcelMediaCommandEventArgs : EventArgs + { + /// Get the simulator the parcel media command was issued in + public Simulator Simulator { get; } + + /// + public uint Sequence { get; } + + /// + public ParcelFlags ParcelFlags { get; } + + /// Get the media command that was sent + public ParcelMediaCommand MediaCommand { get; } + + /// + public float Time { get; } + + /// + /// Construct a new instance of the ParcelMediaCommandEventArgs class + /// + /// The simulator the parcel media command was issued in + /// + /// + /// The media command that was sent + /// + public ParcelMediaCommandEventArgs(Simulator simulator, uint sequence, ParcelFlags flags, ParcelMediaCommand command, float time) + { + Simulator = simulator; + Sequence = sequence; + ParcelFlags = flags; + MediaCommand = command; + Time = time; + } + } + #endregion +} diff --git a/LibreMetaverse/Permissions.cs b/LibreMetaverse/Permissions.cs index ab2cf65..283da10 100644 --- a/LibreMetaverse/Permissions.cs +++ b/LibreMetaverse/Permissions.cs @@ -29,9 +29,6 @@ using OpenMetaverse.StructuredData; namespace OpenMetaverse { - /// - /// - /// [Flags] public enum PermissionMask : uint { @@ -47,9 +44,6 @@ namespace OpenMetaverse All = (1 << 13) | (1 << 14) | (1 << 15) | (1 << 19) } - /// - /// - /// [Flags] public enum PermissionWho : byte { @@ -67,10 +61,7 @@ namespace OpenMetaverse All = 0x1F } - /// - /// - /// - [Serializable()] + [Serializable] public struct Permissions { public PermissionMask BaseMask; diff --git a/LibreMetaverse/Primitives/ParticleSystem.cs b/LibreMetaverse/Primitives/ParticleSystem.cs index 44e9831..421135b 100644 --- a/LibreMetaverse/Primitives/ParticleSystem.cs +++ b/LibreMetaverse/Primitives/ParticleSystem.cs @@ -25,8 +25,6 @@ */ using System; -using System.Collections.Generic; -using System.ComponentModel; using OpenMetaverse.StructuredData; namespace OpenMetaverse @@ -46,6 +44,7 @@ namespace OpenMetaverse /// /// Particle source pattern /// + [Flags] public enum SourcePattern : byte { /// None diff --git a/LibreMetaverse/Primitives/Primitive.cs b/LibreMetaverse/Primitives/Primitive.cs index 2a93eac..6b1ef22 100644 --- a/LibreMetaverse/Primitives/Primitive.cs +++ b/LibreMetaverse/Primitives/Primitive.cs @@ -25,7 +25,6 @@ */ using System; -using System.Collections.Generic; using OpenMetaverse.StructuredData; namespace OpenMetaverse @@ -744,9 +743,8 @@ namespace OpenMetaverse { PhysicsProperties ret = new PhysicsProperties(); - if (osd is OSDMap) + if (osd is OSDMap map) { - OSDMap map = (OSDMap)osd; ret.LocalID = map["LocalID"]; ret.Density = map["Density"]; ret.Friction = map["Friction"]; @@ -1317,7 +1315,7 @@ namespace OpenMetaverse public override bool Equals(object obj) { - return (obj is Primitive) ? this == (Primitive)obj : false; + return (obj is Primitive primitive) && this == primitive; } public bool Equals(Primitive other) diff --git a/LibreMetaverse/Rendering/Rendering.cs b/LibreMetaverse/Rendering/Rendering.cs index 51562ee..e7f1e59 100644 --- a/LibreMetaverse/Rendering/Rendering.cs +++ b/LibreMetaverse/Rendering/Rendering.cs @@ -116,7 +116,7 @@ namespace OpenMetaverse.Rendering public override bool Equals(object obj) { - return (obj is Vertex) && this == (Vertex)obj; + return (obj is Vertex vertex) && this == vertex; } public bool Equals(Vertex other) @@ -289,23 +289,19 @@ namespace OpenMetaverse.Rendering break; } - if (!(facesOSD is OSDArray)) + if (!(facesOSD is OSDArray decodedMeshOsdArray)) { return false; } - OSDArray decodedMeshOsdArray = (OSDArray)facesOSD; - for (int faceNr = 0; faceNr < decodedMeshOsdArray.Count; faceNr++) { OSD subMeshOsd = decodedMeshOsdArray[faceNr]; // Decode each individual face - if (subMeshOsd is OSDMap) + if (subMeshOsd is OSDMap subMeshMap) { - OSDMap subMeshMap = (OSDMap)subMeshOsd; - - // As per http://wiki.secondlife.com/wiki/Mesh/Mesh_Asset_Format, some Mesh Level + // As per http://wiki.secondlife.com/wiki/Mesh/Mesh_Asset_Format, some Mesh Level // of Detail Blocks (maps) contain just a NoGeometry key to signal there is no // geometry for this submesh. if (subMeshMap.ContainsKey("NoGeometry") && ((OSDBoolean)subMeshMap["NoGeometry"])) diff --git a/LibreMetaverse/Settings.cs b/LibreMetaverse/Settings.cs index 4cef288..f13b703 100644 --- a/LibreMetaverse/Settings.cs +++ b/LibreMetaverse/Settings.cs @@ -1,6 +1,6 @@ /* * Copyright (c) 2006-2016, openmetaverse.co - * Copyright (c) 2021, Sjofn LLC. + * Copyright (c) 2021-2022, Sjofn LLC. * All rights reserved. * * - Redistribution and use in source and binary forms, with or without @@ -60,6 +60,9 @@ namespace OpenMetaverse /// Use XML-RPC Login or LLSD Login, default is XML-RPC Login public bool USE_LLSD_LOGIN = false; + /// Client is Multi-Factor Authentication enabled + public bool MFA_ENABLED = false; + /// /// Maximum number of HTTP connections to open to a particular endpoint. /// @@ -201,7 +204,7 @@ namespace OpenMetaverse /// Should we connect to multiple sims? This will allow /// viewing in to neighboring simulators and sim crossings /// (Experimental) - public bool MULTIPLE_SIMS = false; + public bool MULTIPLE_SIMS = true; /// If true, all object update packets will be decoded in to /// native objects. If false, only updates for our own agent will be @@ -297,7 +300,7 @@ namespace OpenMetaverse /// Cost of uploading an asset /// Read-only since this value is dynamically fetched at login - public int UPLOAD_COST => priceUpload; + public int UPLOAD_COST { get; private set; } = 0; /// Maximum number of times to resend a failed packet public int MAX_RESEND_COUNT = 3; @@ -339,12 +342,7 @@ namespace OpenMetaverse /// You will get no output on the console. This behavior can be overriden by creating /// a logger configuration file for log4net /// -#if DEBUG public static Helpers.LogLevel LOG_LEVEL = Helpers.LogLevel.Debug; -#else - public static Helpers.LogLevel LOG_LEVEL = Helpers.LogLevel.None; -#endif - /// Attach avatar names to log messages public bool LOG_NAMES = true; @@ -359,7 +357,6 @@ namespace OpenMetaverse #region Private Fields private GridClient Client; - private int priceUpload = 0; public static bool SORT_INVENTORY = false; /// Constructor @@ -380,7 +377,7 @@ namespace OpenMetaverse { EconomyDataPacket econ = (EconomyDataPacket)e.Packet; - priceUpload = econ.Info.PriceUpload; + UPLOAD_COST = econ.Info.PriceUpload; } #endregion diff --git a/LibreMetaverse/SoundManager.cs b/LibreMetaverse/SoundManager.cs index 48b2049..91d6ac0 100644 --- a/LibreMetaverse/SoundManager.cs +++ b/LibreMetaverse/SoundManager.cs @@ -343,18 +343,14 @@ namespace OpenMetaverse /// changes its volume level public class AttachedSoundGainChangeEventArgs : EventArgs { - private readonly Simulator m_Simulator; - private readonly UUID m_ObjectID; - private readonly float m_Gain; - /// Simulator where the event originated - public Simulator Simulator => m_Simulator; + public Simulator Simulator { get; } /// Get the ID of the Object - public UUID ObjectID => m_ObjectID; + public UUID ObjectID { get; } /// Get the volume level - public float Gain => m_Gain; + public float Gain { get; } /// /// Construct a new instance of the AttachedSoundGainChangedEventArgs class @@ -364,9 +360,9 @@ namespace OpenMetaverse /// The new volume level public AttachedSoundGainChangeEventArgs(Simulator sim, UUID objectID, float gain) { - m_Simulator = sim; - m_ObjectID = objectID; - m_Gain = gain; + Simulator = sim; + ObjectID = objectID; + Gain = gain; } } @@ -398,38 +394,29 @@ namespace OpenMetaverse /// public class SoundTriggerEventArgs : EventArgs { - private readonly Simulator m_Simulator; - private readonly UUID m_SoundID; - private readonly UUID m_OwnerID; - private readonly UUID m_ObjectID; - private readonly UUID m_ParentID; - private readonly float m_Gain; - private readonly ulong m_RegionHandle; - private readonly Vector3 m_Position; - /// Simulator where the event originated - public Simulator Simulator => m_Simulator; + public Simulator Simulator { get; } /// Get the sound asset id - public UUID SoundID => m_SoundID; + public UUID SoundID { get; } /// Get the ID of the owner - public UUID OwnerID => m_OwnerID; + public UUID OwnerID { get; } /// Get the ID of the Object - public UUID ObjectID => m_ObjectID; + public UUID ObjectID { get; } /// Get the ID of the objects parent - public UUID ParentID => m_ParentID; + public UUID ParentID { get; } /// Get the volume level - public float Gain => m_Gain; + public float Gain { get; } /// Get the regionhandle - public ulong RegionHandle => m_RegionHandle; + public ulong RegionHandle { get; } /// Get the source position - public Vector3 Position => m_Position; + public Vector3 Position { get; } /// /// Construct a new instance of the SoundTriggerEventArgs class @@ -444,14 +431,14 @@ namespace OpenMetaverse /// The source position public SoundTriggerEventArgs(Simulator sim, UUID soundID, UUID ownerID, UUID objectID, UUID parentID, float gain, ulong regionHandle, Vector3 position) { - m_Simulator = sim; - m_SoundID = soundID; - m_OwnerID = ownerID; - m_ObjectID = objectID; - m_ParentID = parentID; - m_Gain = gain; - m_RegionHandle = regionHandle; - m_Position = position; + Simulator = sim; + SoundID = soundID; + OwnerID = ownerID; + ObjectID = objectID; + ParentID = parentID; + Gain = gain; + RegionHandle = regionHandle; + Position = position; } } @@ -474,22 +461,17 @@ namespace OpenMetaverse /// public class PreloadSoundEventArgs : EventArgs { - private readonly Simulator m_Simulator; - private readonly UUID m_SoundID; - private readonly UUID m_OwnerID; - private readonly UUID m_ObjectID; - /// Simulator where the event originated - public Simulator Simulator => m_Simulator; + public Simulator Simulator { get; } /// Get the sound asset id - public UUID SoundID => m_SoundID; + public UUID SoundID { get; } /// Get the ID of the owner - public UUID OwnerID => m_OwnerID; + public UUID OwnerID { get; } /// Get the ID of the Object - public UUID ObjectID => m_ObjectID; + public UUID ObjectID { get; } /// /// Construct a new instance of the PreloadSoundEventArgs class @@ -500,10 +482,10 @@ namespace OpenMetaverse /// The ID of the object public PreloadSoundEventArgs(Simulator sim, UUID soundID, UUID ownerID, UUID objectID) { - m_Simulator = sim; - m_SoundID = soundID; - m_OwnerID = ownerID; - m_ObjectID = objectID; + Simulator = sim; + SoundID = soundID; + OwnerID = ownerID; + ObjectID = objectID; } } #endregion diff --git a/LibreMetaverse/Sounds.cs b/LibreMetaverse/Sounds.cs index 4117ed2..06f886e 100644 --- a/LibreMetaverse/Sounds.cs +++ b/LibreMetaverse/Sounds.cs @@ -24,7 +24,6 @@ * POSSIBILITY OF SUCH DAMAGE. */ -using System; using System.Reflection; using System.Collections.Generic; diff --git a/LibreMetaverse/TerrainManager.cs b/LibreMetaverse/TerrainManager.cs index 44e5042..8a112e9 100644 --- a/LibreMetaverse/TerrainManager.cs +++ b/LibreMetaverse/TerrainManager.cs @@ -1,226 +1,220 @@ -/* - * Copyright (c) 2006-2016, openmetaverse.co - * 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 openmetaverse.co 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 OpenMetaverse.Packets; - -namespace OpenMetaverse -{ - public class TerrainManager - { - #region EventHandling - /// The event subscribers. null if no subcribers - private EventHandler m_LandPatchReceivedEvent; - - /// Raises the LandPatchReceived event - /// A LandPatchReceivedEventArgs object containing the - /// data returned from the simulator - protected virtual void OnLandPatchReceived(LandPatchReceivedEventArgs e) - { - EventHandler handler = m_LandPatchReceivedEvent; - handler?.Invoke(this, e); - } - - /// Thread sync lock object - private readonly object m_LandPatchReceivedLock = new object(); - - /// Raised when the simulator responds sends - public event EventHandler LandPatchReceived - { - add { lock (m_LandPatchReceivedLock) { m_LandPatchReceivedEvent += value; } } - remove { lock (m_LandPatchReceivedLock) { m_LandPatchReceivedEvent -= value; } } - } - #endregion - - private readonly GridClient Client; - - /// - /// Default constructor - /// - /// - public TerrainManager(GridClient client) - { - Client = client; - Client.Network.RegisterCallback(PacketType.LayerData, LayerDataHandler); - } - - private void DecompressLand(Simulator simulator, BitPack bitpack, TerrainPatch.GroupHeader group) - { - int x; - int y; - int[] patches = new int[32 * 32]; - int count = 0; - - while (true) - { - TerrainPatch.Header header = TerrainCompressor.DecodePatchHeader(bitpack); - - if (header.QuantWBits == TerrainCompressor.END_OF_PATCHES) - break; - - x = header.X; - y = header.Y; - - if (x >= TerrainCompressor.PATCHES_PER_EDGE || y >= TerrainCompressor.PATCHES_PER_EDGE) - { - Logger.Log(String.Format( - "Invalid LayerData land packet, x={0}, y={1}, dc_offset={2}, range={3}, quant_wbits={4}, patchids={5}, count={6}", - x, y, header.DCOffset, header.Range, header.QuantWBits, header.PatchIDs, count), - Helpers.LogLevel.Warning, Client); - return; - } - - // Decode this patch - TerrainCompressor.DecodePatch(patches, bitpack, header, group.PatchSize); - - // Decompress this patch - float[] heightmap = TerrainCompressor.DecompressPatch(patches, header, group); - - count++; - - try { OnLandPatchReceived(new LandPatchReceivedEventArgs(simulator, x, y, group.PatchSize, heightmap)); } - catch (Exception e) { Logger.Log(e.Message, Helpers.LogLevel.Error, Client, e); } - - if (Client.Settings.STORE_LAND_PATCHES) - { - TerrainPatch patch = new TerrainPatch - { - Data = heightmap, - X = x, - Y = y - }; - simulator.Terrain[y * 16 + x] = patch; - } - } - } - - private void DecompressWind(Simulator simulator, BitPack bitpack, TerrainPatch.GroupHeader group) - { - int[] patches = new int[32 * 32]; - - // Ignore the simulator stride value - group.Stride = group.PatchSize; - - // Each wind packet contains the wind speeds and direction for the entire simulator - // stored as two float arrays. The first array is the X value of the wind speed at - // each 16x16m block, second is the Y value. - // wind_speed = distance(x,y to 0,0) - // wind_direction = vec2(x,y) - - // X values - TerrainPatch.Header header = TerrainCompressor.DecodePatchHeader(bitpack); - TerrainCompressor.DecodePatch(patches, bitpack, header, group.PatchSize); - float[] xvalues = TerrainCompressor.DecompressPatch(patches, header, group); - - // Y values - header = TerrainCompressor.DecodePatchHeader(bitpack); - TerrainCompressor.DecodePatch(patches, bitpack, header, group.PatchSize); - float[] yvalues = TerrainCompressor.DecompressPatch(patches, header, group); - - if (simulator.Client.Settings.STORE_LAND_PATCHES) - { - for (int i = 0; i < 256; i++) - simulator.WindSpeeds[i] = new Vector2(xvalues[i], yvalues[i]); - } - } - - private void DecompressCloud(Simulator simulator, BitPack bitpack, TerrainPatch.GroupHeader group) - { - // FIXME: - } - - private void LayerDataHandler(object sender, PacketReceivedEventArgs e) - { - LayerDataPacket layer = (LayerDataPacket)e.Packet; - BitPack bitpack = new BitPack(layer.LayerData.Data, 0); - TerrainPatch.GroupHeader header = new TerrainPatch.GroupHeader(); - TerrainPatch.LayerType type = (TerrainPatch.LayerType)layer.LayerID.Type; - - // Stride - header.Stride = bitpack.UnpackBits(16); - // Patch size - header.PatchSize = bitpack.UnpackBits(8); - // Layer type - header.Type = (TerrainPatch.LayerType)bitpack.UnpackBits(8); - - switch (type) - { - case TerrainPatch.LayerType.Land: - if (m_LandPatchReceivedEvent != null || Client.Settings.STORE_LAND_PATCHES) - DecompressLand(e.Simulator, bitpack, header); - break; - case TerrainPatch.LayerType.Water: - Logger.Log("Got a Water LayerData packet, implement me!", Helpers.LogLevel.Error, Client); - break; - case TerrainPatch.LayerType.Wind: - DecompressWind(e.Simulator, bitpack, header); - break; - case TerrainPatch.LayerType.Cloud: - DecompressCloud(e.Simulator, bitpack, header); - break; - default: - Logger.Log("Unrecognized LayerData type " + type, Helpers.LogLevel.Warning, Client); - break; - } - } - } - - #region EventArgs classes - // Provides data for LandPatchReceived - public class LandPatchReceivedEventArgs : EventArgs - { - private readonly Simulator m_Simulator; - private readonly int m_X; - private readonly int m_Y; - private readonly int m_PatchSize; - private readonly float[] m_HeightMap; - - /// Simulator from that sent tha data - public Simulator Simulator => m_Simulator; - - /// Sim coordinate of the patch - public int X => m_X; - - /// Sim coordinate of the patch - public int Y => m_Y; - - /// Size of tha patch - public int PatchSize => m_PatchSize; - - /// Heightmap for the patch - public float[] HeightMap => m_HeightMap; - - public LandPatchReceivedEventArgs(Simulator simulator, int x, int y, int patchSize, float[] heightMap) - { - m_Simulator = simulator; - m_X = x; - m_Y = y; - m_PatchSize = patchSize; - m_HeightMap = heightMap; - } - } - #endregion -} +/* + * Copyright (c) 2006-2016, openmetaverse.co + * 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 openmetaverse.co 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 OpenMetaverse.Packets; + +namespace OpenMetaverse +{ + public class TerrainManager + { + #region EventHandling + /// The event subscribers. null if no subcribers + private EventHandler m_LandPatchReceivedEvent; + + /// Raises the LandPatchReceived event + /// A LandPatchReceivedEventArgs object containing the + /// data returned from the simulator + protected virtual void OnLandPatchReceived(LandPatchReceivedEventArgs e) + { + EventHandler handler = m_LandPatchReceivedEvent; + handler?.Invoke(this, e); + } + + /// Thread sync lock object + private readonly object m_LandPatchReceivedLock = new object(); + + /// Raised when the simulator responds sends + public event EventHandler LandPatchReceived + { + add { lock (m_LandPatchReceivedLock) { m_LandPatchReceivedEvent += value; } } + remove { lock (m_LandPatchReceivedLock) { m_LandPatchReceivedEvent -= value; } } + } + #endregion + + private readonly GridClient Client; + + /// + /// Default constructor + /// + /// + public TerrainManager(GridClient client) + { + Client = client; + Client.Network.RegisterCallback(PacketType.LayerData, LayerDataHandler); + } + + private void DecompressLand(Simulator simulator, BitPack bitpack, TerrainPatch.GroupHeader group) + { + int x; + int y; + int[] patches = new int[32 * 32]; + int count = 0; + + while (true) + { + TerrainPatch.Header header = TerrainCompressor.DecodePatchHeader(bitpack); + + if (header.QuantWBits == TerrainCompressor.END_OF_PATCHES) + break; + + x = header.X; + y = header.Y; + + if (x >= TerrainCompressor.PATCHES_PER_EDGE || y >= TerrainCompressor.PATCHES_PER_EDGE) + { + Logger.Log(String.Format( + "Invalid LayerData land packet, x={0}, y={1}, dc_offset={2}, range={3}, quant_wbits={4}, patchids={5}, count={6}", + x, y, header.DCOffset, header.Range, header.QuantWBits, header.PatchIDs, count), + Helpers.LogLevel.Warning, Client); + return; + } + + // Decode this patch + TerrainCompressor.DecodePatch(patches, bitpack, header, group.PatchSize); + + // Decompress this patch + float[] heightmap = TerrainCompressor.DecompressPatch(patches, header, group); + + count++; + + try { OnLandPatchReceived(new LandPatchReceivedEventArgs(simulator, x, y, group.PatchSize, heightmap)); } + catch (Exception e) { Logger.Log(e.Message, Helpers.LogLevel.Error, Client, e); } + + if (Client.Settings.STORE_LAND_PATCHES) + { + TerrainPatch patch = new TerrainPatch + { + Data = heightmap, + X = x, + Y = y + }; + simulator.Terrain[y * 16 + x] = patch; + } + } + } + + private void DecompressWind(Simulator simulator, BitPack bitpack, TerrainPatch.GroupHeader group) + { + int[] patches = new int[32 * 32]; + + // Ignore the simulator stride value + group.Stride = group.PatchSize; + + // Each wind packet contains the wind speeds and direction for the entire simulator + // stored as two float arrays. The first array is the X value of the wind speed at + // each 16x16m block, second is the Y value. + // wind_speed = distance(x,y to 0,0) + // wind_direction = vec2(x,y) + + // X values + TerrainPatch.Header header = TerrainCompressor.DecodePatchHeader(bitpack); + TerrainCompressor.DecodePatch(patches, bitpack, header, group.PatchSize); + float[] xvalues = TerrainCompressor.DecompressPatch(patches, header, group); + + // Y values + header = TerrainCompressor.DecodePatchHeader(bitpack); + TerrainCompressor.DecodePatch(patches, bitpack, header, group.PatchSize); + float[] yvalues = TerrainCompressor.DecompressPatch(patches, header, group); + + if (simulator.Client.Settings.STORE_LAND_PATCHES) + { + for (int i = 0; i < 256; i++) + simulator.WindSpeeds[i] = new Vector2(xvalues[i], yvalues[i]); + } + } + + private void DecompressCloud(Simulator simulator, BitPack bitpack, TerrainPatch.GroupHeader group) + { + // FIXME: + } + + private void LayerDataHandler(object sender, PacketReceivedEventArgs e) + { + LayerDataPacket layer = (LayerDataPacket)e.Packet; + BitPack bitpack = new BitPack(layer.LayerData.Data, 0); + TerrainPatch.GroupHeader header = new TerrainPatch.GroupHeader(); + TerrainPatch.LayerType type = (TerrainPatch.LayerType)layer.LayerID.Type; + + // Stride + header.Stride = bitpack.UnpackBits(16); + // Patch size + header.PatchSize = bitpack.UnpackBits(8); + // Layer type + header.Type = (TerrainPatch.LayerType)bitpack.UnpackBits(8); + + switch (type) + { + case TerrainPatch.LayerType.Land: + if (m_LandPatchReceivedEvent != null || Client.Settings.STORE_LAND_PATCHES) + DecompressLand(e.Simulator, bitpack, header); + break; + case TerrainPatch.LayerType.Water: + Logger.Log("Got a Water LayerData packet, implement me!", Helpers.LogLevel.Error, Client); + break; + case TerrainPatch.LayerType.Wind: + DecompressWind(e.Simulator, bitpack, header); + break; + case TerrainPatch.LayerType.Cloud: + DecompressCloud(e.Simulator, bitpack, header); + break; + default: + Logger.Log("Unrecognized LayerData type " + type, Helpers.LogLevel.Warning, Client); + break; + } + } + } + + #region EventArgs classes + // Provides data for LandPatchReceived + public class LandPatchReceivedEventArgs : EventArgs + { + /// Simulator from that sent tha data + public Simulator Simulator { get; } + + /// Sim coordinate of the patch + public int X { get; } + + /// Sim coordinate of the patch + public int Y { get; } + + /// Size of tha patch + public int PatchSize { get; } + + /// Heightmap for the patch + public float[] HeightMap { get; } + + public LandPatchReceivedEventArgs(Simulator simulator, int x, int y, int patchSize, float[] heightMap) + { + Simulator = simulator; + X = x; + Y = y; + PatchSize = patchSize; + HeightMap = heightMap; + } + } + #endregion +} diff --git a/LibreMetaverse/UDPPacketBuffer.cs b/LibreMetaverse/UDPPacketBuffer.cs index 7574bf0..50659b6 100644 --- a/LibreMetaverse/UDPPacketBuffer.cs +++ b/LibreMetaverse/UDPPacketBuffer.cs @@ -1,5 +1,4 @@ -using System; -using System.Collections.Generic; +using System; using System.Net; namespace OpenMetaverse diff --git a/LibreMetaverse/UserReport.cs b/LibreMetaverse/UserReport.cs index d4363d2..80b41d1 100644 --- a/LibreMetaverse/UserReport.cs +++ b/LibreMetaverse/UserReport.cs @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, Sjofn LLC + * Copyright (c) 2021-2022, Sjofn LLC * All rights reserved. * * - Redistribution and use in source and binary forms, with or without @@ -26,6 +26,7 @@ using System; using System.Collections.Generic; +using System.Linq; using OpenMetaverse; using OpenMetaverse.Http; using OpenMetaverse.Packets; @@ -58,7 +59,7 @@ namespace LibreMetaverse /// /// Fetch a list of Abuse Report categories from the simulator /// - /// Returns Dictionary of Abuse Report categories from the server + /// Returns Dictionary of Abuse Report categories from the server public Dictionary FetchAbuseReportCategories() { return FetchAbuseReportCategories(null); @@ -68,7 +69,7 @@ namespace LibreMetaverse /// Fetch a list of Abuse Report categories from the simulator /// /// language to return categories in - /// Returns Dictionary of Abuse Report categories from the server + /// Returns Dictionary of Abuse Report categories from the server public Dictionary FetchAbuseReportCategories(string lang) { Dictionary reportCategories = null; @@ -92,15 +93,12 @@ namespace LibreMetaverse Helpers.LogLevel.Info); return; } - if (result != null && result is OSDMap respMap && respMap.ContainsKey("categories")) + if (result is OSDMap respMap && respMap.ContainsKey("categories")) { - reportCategories = new Dictionary(); var categories = respMap["categories"] as OSDArray; - foreach (OSDMap row in categories) - { - reportCategories.Add( - row["description_localized"].AsString(), row["category"].AsString()); - } + reportCategories = categories.Cast().ToDictionary( + row => row["description_localized"].AsString(), + row => row["category"].AsString()); } }; request.GetRequestAsync(Client.Settings.CAPS_TIMEOUT); @@ -143,7 +141,7 @@ namespace LibreMetaverse ["abuse-region-id"] = UUID.Zero, ["position"] = pos, ["summary"] = summary, - ["version-string"] = $"<3 LibreMetaverse", + ["version-string"] = "<3 LibreMetaverse", ["details"] = details }; @@ -213,7 +211,7 @@ namespace LibreMetaverse Summary = Utils.StringToBytes(summary), Details = Utils.StringToBytes(details), - VersionString = Utils.StringToBytes($"<3 LibreMetaverse") + VersionString = Utils.StringToBytes("<3 LibreMetaverse") } }; Client.Network.SendPacket(urp); diff --git a/LibreMetaverse/Voice/TCPPipe.cs b/LibreMetaverse/Voice/TCPPipe.cs deleted file mode 100644 index 59553a9..0000000 --- a/LibreMetaverse/Voice/TCPPipe.cs +++ /dev/null @@ -1,181 +0,0 @@ -/* - * Copyright (c) 2006-2016, openmetaverse.co - * 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 openmetaverse.co 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 System.Net; -using System.Net.Sockets; - -namespace OpenMetaverse.Voice -{ - public class TCPPipe - { - protected class SocketPacket - { - public System.Net.Sockets.Socket TCPSocket; - public byte[] DataBuffer = new byte[1]; - } - - public delegate void OnReceiveLineCallback(string line); - public delegate void OnDisconnectedCallback(SocketException se); - - public event OnReceiveLineCallback OnReceiveLine; - public event OnDisconnectedCallback OnDisconnected; - - protected Socket _TCPSocket; - protected IAsyncResult _Result; - protected AsyncCallback _Callback; - protected string _Buffer = String.Empty; - - public bool Connected - { - get { return _TCPSocket != null && _TCPSocket.Connected; } - } - - public SocketException Connect(string address, int port) - { - if (_TCPSocket != null && _TCPSocket.Connected) - Disconnect(); - - try - { - IPAddress ip; - if (!IPAddress.TryParse(address, out ip)) - { - IPAddress[] ips = Dns.GetHostAddresses(address); - ip = ips[0]; - } - _TCPSocket = new Socket(ip.AddressFamily, SocketType.Stream, ProtocolType.Tcp); - IPEndPoint ipEndPoint = new IPEndPoint(ip, port); - _TCPSocket.Connect(ipEndPoint); - if (_TCPSocket.Connected) - { - WaitForData(); - return null; - } - else - { - return new SocketException(10000); - } - } - catch (SocketException se) - { - return se; - } - } - - public void Disconnect() - { - _TCPSocket.Disconnect(true); - } - - public void SendData(byte[] data) - { - if (Connected) - _TCPSocket.Send(data); - else - throw new InvalidOperationException("socket is not connected"); - } - - public void SendLine(string message) - { - if (Connected) - { - byte[] byData = System.Text.Encoding.ASCII.GetBytes(message + "\n"); - _TCPSocket.Send(byData); - } - else - { - throw new InvalidOperationException("socket is not connected"); - } - } - - void WaitForData() - { - try - { - if (_Callback == null) _Callback = new AsyncCallback(OnDataReceived); - SocketPacket packet = new SocketPacket(); - packet.TCPSocket = _TCPSocket; - _Result = _TCPSocket.BeginReceive(packet.DataBuffer, 0, packet.DataBuffer.Length, SocketFlags.None, _Callback, packet); - } - catch (SocketException se) - { - Console.WriteLine(se.Message); - } - } - - static char[] splitNull = { '\0' }; - static string[] splitLines = { "\r", "\n", "\r\n" }; - - void ReceiveData(string data) - { - if (OnReceiveLine == null) return; - - //string[] splitNull = { "\0" }; - string[] line = data.Split(splitNull, StringSplitOptions.None); - _Buffer += line[0]; - //string[] splitLines = { "\r\n", "\r", "\n" }; - string[] lines = _Buffer.Split(splitLines, StringSplitOptions.None); - if (lines.Length > 1) - { - int i; - for (i = 0; i < lines.Length - 1; i++) - { - if (lines[i].Trim().Length > 0) OnReceiveLine(lines[i]); - } - _Buffer = lines[i]; - } - } - - void OnDataReceived(IAsyncResult asyn) - { - try - { - SocketPacket packet = (SocketPacket)asyn.AsyncState; - int end = packet.TCPSocket.EndReceive(asyn); - char[] chars = new char[end + 1]; - System.Text.Decoder d = System.Text.Encoding.UTF8.GetDecoder(); - d.GetChars(packet.DataBuffer, 0, end, chars, 0); - System.String data = new System.String(chars); - ReceiveData(data); - WaitForData(); - } - catch (ObjectDisposedException) - { - Console.WriteLine("WARNING: Socket closed unexpectedly"); - } - catch (SocketException se) - { - if (!_TCPSocket.Connected) - { - if (OnDisconnected != null) - OnDisconnected(se); - } - } - } - - } -} diff --git a/LibreMetaverse/Voice/VoiceAccount.cs b/LibreMetaverse/Voice/VoiceAccount.cs deleted file mode 100644 index 2a059c3..0000000 --- a/LibreMetaverse/Voice/VoiceAccount.cs +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (c) 2006-2016, openmetaverse.co - * 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 openmetaverse.co 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 System.Collections.Generic; -using System.Text; - -namespace OpenMetaverse.Voice -{ - public partial class VoiceGateway - { - /// - /// This is used to login a specific user account(s). It may only be called after - /// Connector initialization has completed successfully - /// - /// Handle returned from successful Connector ‘create’ request - /// User's account name - /// User's account password - /// Values may be “AutoAnswer” or “VerifyAnswer” - /// "" - /// This is an integer that specifies how often - /// the daemon will send participant property events while in a channel. If this is not set - /// the default will be “on state change”, which means that the events will be sent when - /// the participant starts talking, stops talking, is muted, is unmuted. - /// The valid values are: - /// 0 – Never - /// 5 – 10 times per second - /// 10 – 5 times per second - /// 50 – 1 time per second - /// 100 – on participant state change (this is the default) - /// false - /// - public int AccountLogin(string ConnectorHandle, string AccountName, string AccountPassword, string AudioSessionAnswerMode, string AccountURI, int ParticipantPropertyFrequency, bool EnableBuddiesAndPresence) - { - StringBuilder sb = new StringBuilder(); - sb.Append(VoiceGateway.MakeXML("ConnectorHandle", ConnectorHandle)); - sb.Append(VoiceGateway.MakeXML("AccountName", AccountName)); - sb.Append(VoiceGateway.MakeXML("AccountPassword", AccountPassword)); - sb.Append(VoiceGateway.MakeXML("AudioSessionAnswerMode", AudioSessionAnswerMode)); - sb.Append(VoiceGateway.MakeXML("AccountURI", AccountURI)); - sb.Append(VoiceGateway.MakeXML("ParticipantPropertyFrequency", ParticipantPropertyFrequency.ToString())); - sb.Append(VoiceGateway.MakeXML("EnableBuddiesAndPresence", EnableBuddiesAndPresence ? "true" : "false")); - sb.Append(VoiceGateway.MakeXML("BuddyManagementMode", "Application")); - return Request("Account.Login.1", sb.ToString()); - } - - /// - /// This is used to logout a user session. It should only be called with a valid AccountHandle. - /// - /// Handle returned from successful Connector ‘login’ request - /// - public int AccountLogout(string AccountHandle) - { - string RequestXML = VoiceGateway.MakeXML("AccountHandle", AccountHandle); - return Request("Account.Logout.1", RequestXML); - } - } -} diff --git a/LibreMetaverse/Voice/VoiceAux.cs b/LibreMetaverse/Voice/VoiceAux.cs deleted file mode 100644 index 1381854..0000000 --- a/LibreMetaverse/Voice/VoiceAux.cs +++ /dev/null @@ -1,123 +0,0 @@ -/* - * Copyright (c) 2006-2016, openmetaverse.co - * 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 openmetaverse.co 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 System.Collections.Generic; -using System.Text; - -namespace OpenMetaverse.Voice -{ - public partial class VoiceGateway - { - /// - /// This is used to get a list of audio devices that can be used for capture (input) of voice. - /// - /// - public int AuxGetCaptureDevices() - { - return Request("Aux.GetCaptureDevices.1"); - } - - /// - /// This is used to get a list of audio devices that can be used for render (playback) of voice. - /// - public int AuxGetRenderDevices() - { - return Request("Aux.GetRenderDevices.1"); - } - - /// - /// This command is used to select the render device. - /// - /// The name of the device as returned by the Aux.GetRenderDevices command. - public int AuxSetRenderDevice(string RenderDeviceSpecifier) - { - string RequestXML = VoiceGateway.MakeXML("RenderDeviceSpecifier", RenderDeviceSpecifier); - return Request("Aux.SetRenderDevice.1", RequestXML); - } - - /// - /// This command is used to select the capture device. - /// - /// The name of the device as returned by the Aux.GetCaptureDevices command. - public int AuxSetCaptureDevice(string CaptureDeviceSpecifier) - { - string RequestXML = VoiceGateway.MakeXML("CaptureDeviceSpecifier", CaptureDeviceSpecifier); - return Request("Aux.SetCaptureDevice.1", RequestXML); - } - - /// - /// This command is used to start the audio capture process which will cause - /// AuxAudioProperty Events to be raised. These events can be used to display a - /// microphone VU meter for the currently selected capture device. This command - /// should not be issued if the user is on a call. - /// - /// (unused but required) - /// - public int AuxCaptureAudioStart(int Duration) - { - string RequestXML = VoiceGateway.MakeXML("Duration", Duration.ToString()); - return Request("Aux.CaptureAudioStart.1", RequestXML); - } - - /// - /// This command is used to stop the audio capture process. - /// - /// - public int AuxCaptureAudioStop() - { - return Request("Aux.CaptureAudioStop.1"); - } - - /// - /// This command is used to set the mic volume while in the audio tuning process. - /// Once an acceptable mic level is attained, the application must issue a - /// connector set mic volume command to have that level be used while on voice - /// calls. - /// - /// the microphone volume (-100 to 100 inclusive) - /// - public int AuxSetMicLevel(int Level) - { - string RequestXML = VoiceGateway.MakeXML("Level", Level.ToString()); - return Request("Aux.SetMicLevel.1", RequestXML); - } - - /// - /// This command is used to set the speaker volume while in the audio tuning - /// process. Once an acceptable speaker level is attained, the application must - /// issue a connector set speaker volume command to have that level be used while - /// on voice calls. - /// - /// the speaker volume (-100 to 100 inclusive) - /// - public int AuxSetSpeakerLevel(int Level) - { - string RequestXML = VoiceGateway.MakeXML("Level", Level.ToString()); - return Request("Aux.SetSpeakerLevel.1", RequestXML); - } - } -} diff --git a/LibreMetaverse/Voice/VoiceConnector.cs b/LibreMetaverse/Voice/VoiceConnector.cs deleted file mode 100644 index d08d1f0..0000000 --- a/LibreMetaverse/Voice/VoiceConnector.cs +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Copyright (c) 2006-2016, openmetaverse.co - * 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 openmetaverse.co 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 System.Collections.Generic; -using System.Text; - -namespace OpenMetaverse.Voice -{ - public partial class VoiceGateway - { - /// - /// This is used to initialize and stop the Connector as a whole. The Connector - /// Create call must be completed successfully before any other requests are made - /// (typically during application initialization). The shutdown should be called - /// when the application is shutting down to gracefully release resources - /// - /// A string value indicting the Application name - /// URL for the management server - /// LoggingSettings - /// - /// - public int ConnectorCreate(string ClientName, string AccountManagementServer, ushort MinimumPort, - ushort MaximumPort, VoiceLoggingSettings Logging) - { - StringBuilder sb = new StringBuilder(); - sb.Append(VoiceGateway.MakeXML("ClientName", ClientName)); - sb.Append(VoiceGateway.MakeXML("AccountManagementServer", AccountManagementServer)); - sb.Append(VoiceGateway.MakeXML("MinimumPort", MinimumPort.ToString())); - sb.Append(VoiceGateway.MakeXML("MaximumPort", MaximumPort.ToString())); - sb.Append(VoiceGateway.MakeXML("Mode", "Normal")); - sb.Append(""); - sb.Append(VoiceGateway.MakeXML("Enabled", Logging.Enabled ? "true" : "false")); - sb.Append(VoiceGateway.MakeXML("Folder", Logging.Folder)); - sb.Append(VoiceGateway.MakeXML("FileNamePrefix", Logging.FileNamePrefix)); - sb.Append(VoiceGateway.MakeXML("FileNameSuffix", Logging.FileNameSuffix)); - sb.Append(VoiceGateway.MakeXML("LogLevel", Logging.LogLevel.ToString())); - sb.Append(""); - return Request("Connector.Create.1", sb.ToString()); - } - - /// - /// Shutdown Connector -- Should be called when the application is shutting down - /// to gracefully release resources - /// - /// Handle returned from successful Connector ‘create’ request - public int ConnectorInitiateShutdown(string ConnectorHandle) - { - string RequestXML = VoiceGateway.MakeXML("ConnectorHandle", ConnectorHandle); - return Request("Connector.InitiateShutdown.1", RequestXML); - } - - /// - /// Mute or unmute the microphone - /// - /// Handle returned from successful Connector ‘create’ request - /// true (mute) or false (unmute) - public int ConnectorMuteLocalMic(string ConnectorHandle, bool Mute) - { - StringBuilder sb = new StringBuilder(); - sb.Append(VoiceGateway.MakeXML("ConnectorHandle", ConnectorHandle)); - sb.Append(VoiceGateway.MakeXML("Value", Mute ? "true" : "false")); - return Request("Connector.MuteLocalMic.1", sb.ToString()); - } - - /// - /// Mute or unmute the speaker - /// - /// Handle returned from successful Connector ‘create’ request - /// true (mute) or false (unmute) - public int ConnectorMuteLocalSpeaker(string ConnectorHandle, bool Mute) - { - StringBuilder sb = new StringBuilder(); - sb.Append(VoiceGateway.MakeXML("ConnectorHandle", ConnectorHandle)); - sb.Append(VoiceGateway.MakeXML("Value", Mute ? "true" : "false")); - return Request("Connector.MuteLocalSpeaker.1", sb.ToString()); - } - - /// - /// Set microphone volume - /// - /// Handle returned from successful Connector ‘create’ request - /// The level of the audio, a number between -100 and 100 where - /// 0 represents ‘normal’ speaking volume - public int ConnectorSetLocalMicVolume(string ConnectorHandle, int Value) - { - StringBuilder sb = new StringBuilder(); - sb.Append(VoiceGateway.MakeXML("ConnectorHandle", ConnectorHandle)); - sb.Append(VoiceGateway.MakeXML("Value", Value.ToString())); - return Request("Connector.SetLocalMicVolume.1", sb.ToString()); - } - - /// - /// Set local speaker volume - /// - /// Handle returned from successful Connector ‘create’ request - /// The level of the audio, a number between -100 and 100 where - /// 0 represents ‘normal’ speaking volume - public int ConnectorSetLocalSpeakerVolume(string ConnectorHandle, int Value) - { - StringBuilder sb = new StringBuilder(); - sb.Append(VoiceGateway.MakeXML("ConnectorHandle", ConnectorHandle)); - sb.Append(VoiceGateway.MakeXML("Value", Value.ToString())); - return Request("Connector.SetLocalSpeakerVolume.1", sb.ToString()); - } - } -} diff --git a/LibreMetaverse/Voice/VoiceControl.cs b/LibreMetaverse/Voice/VoiceControl.cs deleted file mode 100644 index 47005ac..0000000 --- a/LibreMetaverse/Voice/VoiceControl.cs +++ /dev/null @@ -1,1019 +0,0 @@ -/* - * Copyright (c) 2006-2016, openmetaverse.co - * 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 openmetaverse.co 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. - */ -//#define DEBUG_VOICE - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.IO; -using System.Threading; - -using OpenMetaverse; -using OpenMetaverse.StructuredData; -using OpenMetaverse.Http; - -namespace OpenMetaverse.Voice -{ - public partial class VoiceGateway : IDisposable - { - // These states should be in increasing order of 'completeness' - // so that the (int) values can drive a progress bar. - public enum ConnectionState - { - None = 0, - Provisioned, - DaemonStarted, - DaemonConnected, - ConnectorConnected, - AccountLogin, - RegionCapAvailable, - SessionRunning - } - - internal string sipServer = ""; - private string acctServer = "https://www.bhr.vivox.com/api2/"; - private string connectionHandle; - private string accountHandle; - private string sessionHandle; - - // Parameters to Vivox daemon - private string slvoicePath = ""; - private string slvoiceArgs = "-ll 5"; - private string daemonNode = "127.0.0.1"; - private int daemonPort = 37331; - - private string voiceUser; - private string voicePassword; - private string spatialUri; - private string spatialCredentials; - - // Session management - private Dictionary sessions; - private VoiceSession spatialSession; - private Uri currentParcelCap; - private Uri nextParcelCap; - private string regionName; - - // Position update thread - private Thread posThread; - private CancellationTokenSource posTokenSource; - private ManualResetEvent posRestart; - public GridClient Client; - private VoicePosition position; - private Vector3d oldPosition; - private Vector3d oldAt; - - // Audio interfaces - private List inputDevices; - /// - /// List of audio input devices - /// - public List CaptureDevices { get { return inputDevices; } } - private List outputDevices; - /// - /// List of audio output devices - /// - public List PlaybackDevices { get { return outputDevices; } } - private string currentCaptureDevice; - private string currentPlaybackDevice; - private bool testing = false; - - public event EventHandler OnSessionCreate; - public event EventHandler OnSessionRemove; - public delegate void VoiceConnectionChangeCallback(ConnectionState state); - public event VoiceConnectionChangeCallback OnVoiceConnectionChange; - public delegate void VoiceMicTestCallback(float level); - public event VoiceMicTestCallback OnVoiceMicTest; - - public VoiceGateway(GridClient c) - { - Random rand = new Random(); - daemonPort = rand.Next(34000, 44000); - - Client = c; - - sessions = new Dictionary(); - position = new VoicePosition(); - position.UpOrientation = new Vector3d(0.0, 1.0, 0.0); - position.Velocity = new Vector3d(0.0, 0.0, 0.0); - oldPosition = new Vector3d(0, 0, 0); - oldAt = new Vector3d(1, 0, 0); - - slvoiceArgs = " -ll -1"; // Min logging - slvoiceArgs += " -i 127.0.0.1:" + daemonPort.ToString(); - // slvoiceArgs += " -lf " + control.instance.ClientDir; - } - - /// - /// Start up the Voice service. - /// - public void Start() - { - // Start the background thread - if (posThread != null && posThread.IsAlive) - { - posRestart.Set(); - posTokenSource.Cancel(); - } - - posTokenSource = new CancellationTokenSource(); - posThread = new Thread(new ThreadStart(PositionThreadBody)); - posThread.Name = "VoicePositionUpdate"; - posThread.IsBackground = true; - posRestart = new ManualResetEvent(false); - posThread.Start(); - - Client.Network.EventQueueRunning += new EventHandler(Network_EventQueueRunning); - - // Connection events - OnDaemonRunning += - new VoiceGateway.DaemonRunningCallback(connector_OnDaemonRunning); - OnDaemonCouldntRun += - new VoiceGateway.DaemonCouldntRunCallback(connector_OnDaemonCouldntRun); - OnConnectorCreateResponse += - new EventHandler(connector_OnConnectorCreateResponse); - OnDaemonConnected += - new DaemonConnectedCallback(connector_OnDaemonConnected); - OnDaemonCouldntConnect += - new DaemonCouldntConnectCallback(connector_OnDaemonCouldntConnect); - OnAuxAudioPropertiesEvent += - new EventHandler(connector_OnAuxAudioPropertiesEvent); - - // Session events - OnSessionStateChangeEvent += - new EventHandler(connector_OnSessionStateChangeEvent); - OnSessionAddedEvent += - new EventHandler(connector_OnSessionAddedEvent); - - // Session Participants events - OnSessionParticipantUpdatedEvent += - new EventHandler(connector_OnSessionParticipantUpdatedEvent); - OnSessionParticipantAddedEvent += - new EventHandler(connector_OnSessionParticipantAddedEvent); - - // Device events - OnAuxGetCaptureDevicesResponse += - new EventHandler(connector_OnAuxGetCaptureDevicesResponse); - OnAuxGetRenderDevicesResponse += - new EventHandler(connector_OnAuxGetRenderDevicesResponse); - - // Generic status response - OnVoiceResponse += new EventHandler(connector_OnVoiceResponse); - - // Account events - OnAccountLoginResponse += - new EventHandler(connector_OnAccountLoginResponse); - - Logger.Log("Voice initialized", Helpers.LogLevel.Info); - - // If voice provisioning capability is already available, - // proceed with voice startup. Otherwise the EventQueueRunning - // event will do it. - System.Uri vCap = - Client.Network.CurrentSim.Caps.CapabilityURI("ProvisionVoiceAccountRequest"); - if (vCap != null) - RequestVoiceProvision(vCap); - - } - - /// - /// Handle miscellaneous request status - /// - /// - /// - /// ///If something goes wrong, we log it. - void connector_OnVoiceResponse(object sender, VoiceGateway.VoiceResponseEventArgs e) - { - if (e.StatusCode == 0) - return; - - Logger.Log(e.Message + " on " + sender as string, Helpers.LogLevel.Error); - } - - public void Stop() - { - Client.Network.EventQueueRunning -= new EventHandler(Network_EventQueueRunning); - - // Connection events - OnDaemonRunning -= - new VoiceGateway.DaemonRunningCallback(connector_OnDaemonRunning); - OnDaemonCouldntRun -= - new VoiceGateway.DaemonCouldntRunCallback(connector_OnDaemonCouldntRun); - OnConnectorCreateResponse -= - new EventHandler(connector_OnConnectorCreateResponse); - OnDaemonConnected -= - new VoiceGateway.DaemonConnectedCallback(connector_OnDaemonConnected); - OnDaemonCouldntConnect -= - new VoiceGateway.DaemonCouldntConnectCallback(connector_OnDaemonCouldntConnect); - OnAuxAudioPropertiesEvent -= - new EventHandler(connector_OnAuxAudioPropertiesEvent); - - // Session events - OnSessionStateChangeEvent -= - new EventHandler(connector_OnSessionStateChangeEvent); - OnSessionAddedEvent -= - new EventHandler(connector_OnSessionAddedEvent); - - // Session Participants events - OnSessionParticipantUpdatedEvent -= - new EventHandler(connector_OnSessionParticipantUpdatedEvent); - OnSessionParticipantAddedEvent -= - new EventHandler(connector_OnSessionParticipantAddedEvent); - OnSessionParticipantRemovedEvent -= - new EventHandler(connector_OnSessionParticipantRemovedEvent); - - // Tuning events - OnAuxGetCaptureDevicesResponse -= - new EventHandler(connector_OnAuxGetCaptureDevicesResponse); - OnAuxGetRenderDevicesResponse -= - new EventHandler(connector_OnAuxGetRenderDevicesResponse); - - // Account events - OnAccountLoginResponse -= - new EventHandler(connector_OnAccountLoginResponse); - - // Stop the background thread - if (posThread != null) - { - if (posThread.IsAlive) - { - posRestart.Set(); - posTokenSource.Cancel(); - } - posThread = null; - } - - // Close all sessions - foreach (VoiceSession s in sessions.Values) - { - if (OnSessionRemove != null) - OnSessionRemove(s, EventArgs.Empty); - s.Close(); - } - - // Clear out lots of state so in case of restart we begin at the beginning. - currentParcelCap = null; - sessions.Clear(); - accountHandle = null; - voiceUser = null; - voicePassword = null; - - SessionTerminate(sessionHandle); - sessionHandle = null; - AccountLogout(accountHandle); - accountHandle = null; - ConnectorInitiateShutdown(connectionHandle); - connectionHandle = null; - StopDaemon(); - } - - /// - /// Cleanup oject resources - /// - public void Dispose() - { - Dispose(true); - GC.SuppressFinalize(this); - } - - protected virtual void Dispose(bool disposing) - { - if (disposing) - { - Stop(); - } - } - - internal string GetVoiceDaemonPath() - { - string myDir = - Path.GetDirectoryName( - (System.Reflection.Assembly.GetEntryAssembly() ?? typeof (VoiceGateway).Assembly).Location); - - if (Environment.OSVersion.Platform != PlatformID.MacOSX && - Environment.OSVersion.Platform != PlatformID.Unix) - { - string localDaemon = Path.Combine(myDir, Path.Combine("voice", "SLVoice.exe")); - - if (File.Exists(localDaemon)) - return localDaemon; - - string progFiles; - if (!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("ProgramFiles(x86)"))) - { - progFiles = Environment.GetEnvironmentVariable("ProgramFiles(x86)"); - } - else - { - progFiles = Environment.GetEnvironmentVariable("ProgramFiles"); - } - - if (System.IO.File.Exists(Path.Combine(progFiles, @"SecondLife" + Path.DirectorySeparatorChar + @"SLVoice.exe"))) - { - return Path.Combine(progFiles, @"SecondLife" + Path.DirectorySeparatorChar + @"SLVoice.exe"); - } - - return Path.Combine(myDir, @"SLVoice.exe"); - - } - else - { - string localDaemon = Path.Combine(myDir, Path.Combine("voice", "SLVoice")); - - if (File.Exists(localDaemon)) - return localDaemon; - - return Path.Combine(myDir,"SLVoice"); - } - } - - void RequestVoiceProvision(System.Uri cap) - { - CapsClient capClient = new Http.CapsClient(cap, "ReqVoiceProvision"); - capClient.OnComplete += cClient_OnComplete; - - // STEP 0 - Logger.Log("Requesting voice capability", Helpers.LogLevel.Info); - capClient.PostRequestAsync(new OSD(), OSDFormat.Xml, 10000); - } - - /// - /// Request voice cap when changing regions - /// - void Network_EventQueueRunning(object sender, EventQueueRunningEventArgs e) - { - // We only care about the sim we are in. - if (e.Simulator != Client.Network.CurrentSim) - return; - - // Did we provision voice login info? - if (string.IsNullOrEmpty(voiceUser)) - { - // The startup steps are - // 0. Get voice account info - // 1. Start Daemon - // 2. Create TCP connection - // 3. Create Connector - // 4. Account login - // 5. Create session - - // Get the voice provisioning data - System.Uri vCap = - Client.Network.CurrentSim.Caps.CapabilityURI("ProvisionVoiceAccountRequest"); - - // Do we have voice capability? - if (vCap == null) - { - Logger.Log("Null voice capability after event queue running", Helpers.LogLevel.Warning); - } - else - { - RequestVoiceProvision(vCap); - } - - return; - } - else - { - // Change voice session for this region. - ParcelChanged(); - } - } - - - #region Participants - - void connector_OnSessionParticipantUpdatedEvent(object sender, ParticipantUpdatedEventArgs e) - { - VoiceSession s = FindSession(e.SessionHandle, false); - if (s == null) return; - s.ParticipantUpdate(e.URI, e.IsMuted, e.IsSpeaking, e.Volume, e.Energy); - } - - public string SIPFromUUID(UUID id) - { - return "sip:" + - nameFromID(id) + - "@" + - sipServer; - } - - private static string nameFromID(UUID id) - { - string result = null; - - if (id == UUID.Zero) - return null; - - // Prepending this apparently prevents conflicts with reserved names inside the vivox and diamondware code. - result = "x"; - - // Base64 encode and replace the pieces of base64 that are less compatible - // with e-mail local-parts. - // See RFC-4648 "Base 64 Encoding with URL and Filename Safe Alphabet" - byte[] encbuff = id.GetBytes(); - result += Convert.ToBase64String(encbuff); - result = result.Replace('+', '-'); - result = result.Replace('/', '_'); - - return result; - } - - void connector_OnSessionParticipantAddedEvent(object sender, ParticipantAddedEventArgs e) - { - VoiceSession s = FindSession(e.SessionHandle, false); - if (s == null) - { - Logger.Log("Orphan participant", Helpers.LogLevel.Error); - return; - } - s.AddParticipant(e.URI); - } - - void connector_OnSessionParticipantRemovedEvent(object sender, ParticipantRemovedEventArgs e) - { - VoiceSession s = FindSession(e.SessionHandle, false); - if (s == null) return; - s.RemoveParticipant(e.URI); - } - #endregion - - #region Sessions - void connector_OnSessionAddedEvent(object sender, SessionAddedEventArgs e) - { - sessionHandle = e.SessionHandle; - - // Create our session context. - VoiceSession s = FindSession(sessionHandle, true); - s.RegionName = regionName; - - spatialSession = s; - - // Tell any user-facing code. - if (OnSessionCreate != null) - OnSessionCreate(s, null); - - Logger.Log("Added voice session in " + regionName, Helpers.LogLevel.Info); - } - - /// - /// Handle a change in session state - /// - void connector_OnSessionStateChangeEvent(object sender, SessionStateChangeEventArgs e) - { - VoiceSession s; - - switch (e.State) - { - case VoiceGateway.SessionState.Connected: - s = FindSession(e.SessionHandle, true); - sessionHandle = e.SessionHandle; - s.RegionName = regionName; - spatialSession = s; - - Logger.Log("Voice connected in " + regionName, Helpers.LogLevel.Info); - // Tell any user-facing code. - if (OnSessionCreate != null) - OnSessionCreate(s, null); - break; - - case VoiceGateway.SessionState.Disconnected: - s = FindSession(sessionHandle, false); - sessions.Remove(sessionHandle); - - if (s != null) - { - Logger.Log("Voice disconnected in " + s.RegionName, Helpers.LogLevel.Info); - - // Inform interested parties - if (OnSessionRemove != null) - OnSessionRemove(s, null); - - if (s == spatialSession) - spatialSession = null; - } - - // The previous session is now ended. Check for a new one and - // start it going. - if (nextParcelCap != null) - { - currentParcelCap = nextParcelCap; - nextParcelCap = null; - RequestParcelInfo(currentParcelCap); - } - break; - } - - - } - - /// - /// Close a voice session - /// - /// - internal void CloseSession(string sessionHandle) - { - if (!sessions.ContainsKey(sessionHandle)) - return; - - PosUpdating(false); - ReportConnectionState(ConnectionState.AccountLogin); - - // Clean up spatial pointers. - VoiceSession s = sessions[sessionHandle]; - if (s.IsSpatial) - { - spatialSession = null; - currentParcelCap = null; - } - - // Remove this session from the master session list - sessions.Remove(sessionHandle); - - // Let any user-facing code clean up. - if (OnSessionRemove != null) - OnSessionRemove(s, null); - - // Tell SLVoice to clean it up as well. - SessionTerminate(sessionHandle); - } - - /// - /// Locate a Session context from its handle - /// - /// Creates the session context if it does not exist. - VoiceSession FindSession(string sessionHandle, bool make) - { - if (sessions.ContainsKey(sessionHandle)) - return sessions[sessionHandle]; - - if (!make) return null; - - // Create a new session and add it to the sessions list. - VoiceSession s = new VoiceSession(this, sessionHandle); - - // Turn on position updating for spatial sessions - // (For now, only spatial sessions are supported) - if (s.IsSpatial) - PosUpdating(true); - - // Register the session by its handle - sessions.Add(sessionHandle, s); - return s; - } - - #endregion - - #region MinorResponses - - void connector_OnAuxAudioPropertiesEvent(object sender, AudioPropertiesEventArgs e) - { - if (OnVoiceMicTest != null) - OnVoiceMicTest(e.MicEnergy); - } - - #endregion - - private void ReportConnectionState(ConnectionState s) - { - if (OnVoiceConnectionChange == null) return; - - OnVoiceConnectionChange(s); - } - - /// - /// Handle completion of main voice cap request. - /// - /// - /// - /// - void cClient_OnComplete(OpenMetaverse.Http.CapsClient client, - OpenMetaverse.StructuredData.OSD result, - Exception error) - { - if (error != null) - { - Logger.Log("Voice cap error " + error.Message, Helpers.LogLevel.Error); - return; - } - - Logger.Log("Voice provisioned", Helpers.LogLevel.Info); - ReportConnectionState(ConnectionState.Provisioned); - - OpenMetaverse.StructuredData.OSDMap pMap = result as OpenMetaverse.StructuredData.OSDMap; - - // We can get back 4 interesting values: - // voice_sip_uri_hostname - // voice_account_server_name (actually a full URI) - // username - // password - if (pMap.ContainsKey("voice_sip_uri_hostname")) - sipServer = pMap["voice_sip_uri_hostname"].AsString(); - if (pMap.ContainsKey("voice_account_server_name")) - acctServer = pMap["voice_account_server_name"].AsString(); - voiceUser = pMap["username"].AsString(); - voicePassword = pMap["password"].AsString(); - - // Start the SLVoice daemon - slvoicePath = GetVoiceDaemonPath(); - - // Test if the executable exists - if (!System.IO.File.Exists(slvoicePath)) - { - Logger.Log("SLVoice is missing", Helpers.LogLevel.Error); - return; - } - - // STEP 1 - StartDaemon(slvoicePath, slvoiceArgs); - } - - #region Daemon - void connector_OnDaemonCouldntConnect() - { - Logger.Log("No voice daemon connect", Helpers.LogLevel.Error); - } - - void connector_OnDaemonCouldntRun() - { - Logger.Log("Daemon not started", Helpers.LogLevel.Error); - } - - /// - /// Daemon has started so connect to it. - /// - void connector_OnDaemonRunning() - { - OnDaemonRunning -= - new VoiceGateway.DaemonRunningCallback(connector_OnDaemonRunning); - - Logger.Log("Daemon started", Helpers.LogLevel.Info); - ReportConnectionState(ConnectionState.DaemonStarted); - - // STEP 2 - ConnectToDaemon(daemonNode, daemonPort); - - } - - /// - /// The daemon TCP connection is open. - /// - void connector_OnDaemonConnected() - { - Logger.Log("Daemon connected", Helpers.LogLevel.Info); - ReportConnectionState(ConnectionState.DaemonConnected); - - // The connector is what does the logging. - VoiceGateway.VoiceLoggingSettings vLog = - new VoiceGateway.VoiceLoggingSettings(); - -#if DEBUG_VOICE - vLog.Enabled = true; - vLog.FileNamePrefix = "OpenmetaverseVoice"; - vLog.FileNameSuffix = ".log"; - vLog.LogLevel = 4; -#endif - // STEP 3 - int reqId = ConnectorCreate( - "V2 SDK", // Magic value keeps SLVoice happy - acctServer, // Account manager server - 30000, 30099, // port range - vLog); - if (reqId < 0) - { - Logger.Log("No voice connector request", Helpers.LogLevel.Error); - } - } - - /// - /// Handle creation of the Connector. - /// - void connector_OnConnectorCreateResponse( - object sender, - VoiceGateway.VoiceConnectorEventArgs e) - { - Logger.Log("Voice daemon protocol started " + e.Message, Helpers.LogLevel.Info); - - connectionHandle = e.Handle; - - if (e.StatusCode != 0) - return; - - // STEP 4 - AccountLogin( - connectionHandle, - voiceUser, - voicePassword, - "VerifyAnswer", // This can also be "AutoAnswer" - "", // Default account management server URI - 10, // Throttle state changes - true); // Enable buddies and presence - } - #endregion - - void connector_OnAccountLoginResponse( - object sender, - VoiceGateway.VoiceAccountEventArgs e) - { - Logger.Log("Account Login " + e.Message, Helpers.LogLevel.Info); - accountHandle = e.AccountHandle; - ReportConnectionState(ConnectionState.AccountLogin); - ParcelChanged(); - } - - #region Audio devices - /// - /// Handle response to audio output device query - /// - void connector_OnAuxGetRenderDevicesResponse( - object sender, - VoiceGateway.VoiceDevicesEventArgs e) - { - outputDevices = e.Devices; - currentPlaybackDevice = e.CurrentDevice; - } - - /// - /// Handle response to audio input device query - /// - void connector_OnAuxGetCaptureDevicesResponse( - object sender, - VoiceGateway.VoiceDevicesEventArgs e) - { - inputDevices = e.Devices; - currentCaptureDevice = e.CurrentDevice; - } - - public string CurrentCaptureDevice - { - get { return currentCaptureDevice; } - set - { - currentCaptureDevice = value; - AuxSetCaptureDevice(value); - } - } - public string PlaybackDevice - { - get { return currentPlaybackDevice; } - set - { - currentPlaybackDevice = value; - AuxSetRenderDevice(value); - } - } - - public int MicLevel - { - set - { - ConnectorSetLocalMicVolume(connectionHandle, value); - } - } - public int SpkrLevel - { - set - { - ConnectorSetLocalSpeakerVolume(connectionHandle, value); - } - } - - public bool MicMute - { - set - { - ConnectorMuteLocalMic(connectionHandle, value); - } - } - - public bool SpkrMute - { - set - { - ConnectorMuteLocalSpeaker(connectionHandle, value); - } - } - - /// - /// Set audio test mode - /// - public bool TestMode - { - get { return testing; } - set - { - testing = value; - if (testing) - { - if (spatialSession != null) - { - spatialSession.Close(); - spatialSession = null; - } - AuxCaptureAudioStart(0); - } - else - { - AuxCaptureAudioStop(); - ParcelChanged(); - } - } - } - #endregion - - - - - /// - /// Set voice channel for new parcel - /// - /// - internal void ParcelChanged() - { - // Get the capability for this parcel. - Caps c = Client.Network.CurrentSim.Caps; - System.Uri pCap = c.CapabilityURI("ParcelVoiceInfoRequest"); - - if (pCap == null) - { - Logger.Log("Null voice capability", Helpers.LogLevel.Error); - return; - } - - // Parcel has changed. If we were already in a spatial session, we have to close it first. - if (spatialSession != null) - { - nextParcelCap = pCap; - CloseSession(spatialSession.Handle); - } - - // Not already in a session, so can start the new one. - RequestParcelInfo(pCap); - } - - private OpenMetaverse.Http.CapsClient parcelCap; - - /// - /// Request info from a parcel capability Uri. - /// - /// - - void RequestParcelInfo(Uri cap) - { - Logger.Log("Requesting region voice info", Helpers.LogLevel.Info); - - parcelCap = new CapsClient(cap, "RequestParcelInfo"); - parcelCap.OnComplete += - pCap_OnComplete; - - currentParcelCap = cap; - parcelCap.PostRequestAsync(new OSD(), OSDFormat.Xml, 10000); - } - - /// - /// Receive parcel voice cap - /// - /// - /// - /// - void pCap_OnComplete(OpenMetaverse.Http.CapsClient client, - OpenMetaverse.StructuredData.OSD result, - Exception error) - { - parcelCap.OnComplete -= - new OpenMetaverse.Http.CapsClient.CompleteCallback(pCap_OnComplete); - parcelCap = null; - - if (error != null) - { - Logger.Log("Region voice cap " + error.Message, Helpers.LogLevel.Error); - return; - } - - OpenMetaverse.StructuredData.OSDMap pMap = result as OpenMetaverse.StructuredData.OSDMap; - - regionName = pMap["region_name"].AsString(); - ReportConnectionState(ConnectionState.RegionCapAvailable); - - if (pMap.ContainsKey("voice_credentials")) - { - OpenMetaverse.StructuredData.OSDMap cred = - pMap["voice_credentials"] as OpenMetaverse.StructuredData.OSDMap; - - if (cred.ContainsKey("channel_uri")) - spatialUri = cred["channel_uri"].AsString(); - if (cred.ContainsKey("channel_credentials")) - spatialCredentials = cred["channel_credentials"].AsString(); - } - - if (string.IsNullOrEmpty(spatialUri)) - { - // "No voice chat allowed here"); - return; - } - - Logger.Log("Voice connecting for region " + regionName, Helpers.LogLevel.Info); - - // STEP 5 - int reqId = SessionCreate( - accountHandle, - spatialUri, // uri - "", // Channel name seems to be always null - spatialCredentials, // spatialCredentials, // session password - true, // Join Audio - false, // Join Text - ""); - if (reqId < 0) - { - Logger.Log("Voice Session ReqID " + reqId.ToString(), Helpers.LogLevel.Error); - } - } - - #region Location Update - /// - /// Tell Vivox where we are standing - /// - /// This has to be called when we move or turn. - internal void UpdatePosition(AgentManager self) - { - // Get position in Global coordinates - Vector3d OMVpos = new Vector3d(self.GlobalPosition); - - // Do not send trivial updates. - if (OMVpos.ApproxEquals(oldPosition, 1.0)) - return; - - oldPosition = OMVpos; - - // Convert to the coordinate space that Vivox uses - // OMV X is East, Y is North, Z is up - // VVX X is East, Y is up, Z is South - position.Position = new Vector3d(OMVpos.X, OMVpos.Z, -OMVpos.Y); - - // TODO Rotate these two vectors - - // Get azimuth from the facing Quaternion. - // By definition, facing.W = Cos( angle/2 ) - double angle = 2.0 * Math.Acos(self.Movement.BodyRotation.W); - - position.LeftOrientation = new Vector3d(-1.0, 0.0, 0.0); - position.AtOrientation = new Vector3d((float)Math.Acos(angle), 0.0, -(float)Math.Asin(angle)); - - SessionSet3DPosition( - sessionHandle, - position, - position); - } - - /// - /// Start and stop updating out position. - /// - /// - internal void PosUpdating(bool go) - { - if (go) - posRestart.Set(); - else - posRestart.Reset(); - } - - private void PositionThreadBody() - { - var token = posTokenSource.Token; - while (true) - { - posRestart.WaitOne(); - token.ThrowIfCancellationRequested(); - - Thread.Sleep(1500); - UpdatePosition(Client.Self); - } - } - #endregion - - } -} diff --git a/LibreMetaverse/Voice/VoiceDefinitions.cs b/LibreMetaverse/Voice/VoiceDefinitions.cs deleted file mode 100644 index 1bcce53..0000000 --- a/LibreMetaverse/Voice/VoiceDefinitions.cs +++ /dev/null @@ -1,706 +0,0 @@ -/* - * Copyright (c) 2006-2016, openmetaverse.co - * 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 openmetaverse.co 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 System.Collections.Generic; -using System.Xml; -using System.Xml.Serialization; - -namespace OpenMetaverse.Voice -{ - public partial class VoiceGateway - { - #region Enums - - public enum LoginState - { - LoggedOut = 0, - LoggedIn = 1, - Error = 4 - } - - public enum SessionState - { - Idle = 1, - Answering = 2, - InProgress = 3, - Connected = 4, - Disconnected = 5, - Hold = 6, - Refer = 7, - Ringing = 8 - } - - public enum ParticipantState - { - Idle = 1, - Pending = 2, - Incoming = 3, - Answering = 4, - InProgress = 5, - Ringing = 6, - Connected = 7, - Disconnecting = 8, - Disconnected = 9 - } - - public enum ParticipantType - { - User = 0, - Moderator = 1, - Focus = 2 - } - - public enum ResponseType - { - None = 0, - ConnectorCreate, - ConnectorInitiateShutdown, - MuteLocalMic, - MuteLocalSpeaker, - SetLocalMicVolume, - SetLocalSpeakerVolume, - GetCaptureDevices, - GetRenderDevices, - SetRenderDevice, - SetCaptureDevice, - CaptureAudioStart, - CaptureAudioStop, - SetMicLevel, - SetSpeakerLevel, - AccountLogin, - AccountLogout, - RenderAudioStart, - RenderAudioStop, - SessionCreate, - SessionConnect, - SessionTerminate, - SetParticipantVolumeForMe, - SetParticipantMuteForMe, - Set3DPosition - } - #endregion Enums - - #region Logging - - public class VoiceLoggingSettings - { - /// Enable logging - public bool Enabled; - /// The folder where any logs will be created - public string Folder; - /// This will be prepended to beginning of each log file - public string FileNamePrefix; - /// The suffix or extension to be appended to each log file - public string FileNameSuffix; - /// - /// 0: NONE - No logging - /// 1: ERROR - Log errors only - /// 2: WARNING - Log errors and warnings - /// 3: INFO - Log errors, warnings and info - /// 4: DEBUG - Log errors, warnings, info and debug - /// - public int LogLevel; - - /// - /// Constructor for default logging settings - /// - public VoiceLoggingSettings() - { - Enabled = false; - Folder = String.Empty; - FileNamePrefix = "Connector"; - FileNameSuffix = ".log"; - LogLevel = 0; - } - } - - #endregion Logging - - public class VoiceResponseEventArgs : EventArgs - { - public readonly ResponseType Type; - public readonly int ReturnCode; - public readonly int StatusCode; - public readonly string Message; - - // All Voice Response events carry these properties. - public VoiceResponseEventArgs(ResponseType type, int rcode, int scode, string text) - { - this.Type = type; - this.ReturnCode = rcode; - this.StatusCode = scode; - this.Message = text; - } - } - - #region Session Event Args - public class VoiceSessionEventArgs : VoiceResponseEventArgs - { - public readonly string SessionHandle; - - public VoiceSessionEventArgs(int rcode, int scode, string text, string shandle) : - base(ResponseType.SessionCreate, rcode, scode, text) - { - this.SessionHandle = shandle; - } - } - - public class NewSessionEventArgs : EventArgs - { - public readonly string AccountHandle; - public readonly string SessionHandle; - public readonly string URI; - public readonly string Name; - public readonly string AudioMedia; - - public NewSessionEventArgs(string AccountHandle, string SessionHandle, string URI, bool IsChannel, string Name, string AudioMedia) - { - this.AccountHandle = AccountHandle; - this.SessionHandle = SessionHandle; - this.URI = URI; - this.Name = Name; - this.AudioMedia = AudioMedia; - } - } - - public class SessionMediaEventArgs : EventArgs - { - public readonly string SessionHandle; - public readonly bool HasText; - public readonly bool HasAudio; - public readonly bool HasVideo; - public readonly bool Terminated; - - public SessionMediaEventArgs(string SessionHandle, bool HasText, bool HasAudio, bool HasVideo, bool Terminated) - { - this.SessionHandle = SessionHandle; - this.HasText = HasText; - this.HasAudio = HasAudio; - this.HasVideo = HasVideo; - this.Terminated = Terminated; - } - } - - public class SessionStateChangeEventArgs : EventArgs - { - public readonly string SessionHandle; - public readonly int StatusCode; - public readonly string StatusString; - public readonly SessionState State; - public readonly string URI; - public readonly bool IsChannel; - public readonly string ChannelName; - public SessionStateChangeEventArgs(string SessionHandle, int StatusCode, string StatusString, SessionState State, string URI, bool IsChannel, string ChannelName) - { - this.SessionHandle = SessionHandle; - this.StatusCode = StatusCode; - this.StatusString = StatusString; - this.State = State; - this.URI = URI; - this.IsChannel = IsChannel; - this.ChannelName = ChannelName; - } - } - - // Participants - public class ParticipantAddedEventArgs : EventArgs - { - public readonly string SessionHandle; - public readonly string SessionGroupHandle; - public readonly string URI; - public readonly string AccountName; - public readonly string DisplayName; - public readonly ParticipantType Type; - public readonly string Appllication; - public ParticipantAddedEventArgs( - string SessionGroupHandle, - string SessionHandle, - string ParticipantUri, - string AccountName, - string DisplayName, - ParticipantType type, - string Application) - { - this.SessionGroupHandle = SessionGroupHandle; - this.SessionHandle = SessionHandle; - this.URI = ParticipantUri; - this.AccountName = AccountName; - this.DisplayName = DisplayName; - this.Type = type; - this.Appllication = Application; - } - } - - public class ParticipantRemovedEventArgs : EventArgs - { - public readonly string SessionGroupHandle; - public readonly string SessionHandle; - public readonly string URI; - public readonly string AccountName; - public readonly string Reason; - - public ParticipantRemovedEventArgs( - string SessionGroupHandle, - string SessionHandle, - string ParticipantUri, - string AccountName, - string Reason) - { - this.SessionGroupHandle = SessionGroupHandle; - this.SessionHandle = SessionHandle; - this.URI = ParticipantUri; - this.AccountName = AccountName; - this.Reason = Reason; - } - } - - public class ParticipantStateChangeEventArgs : EventArgs - { - public readonly string SessionHandle; - public readonly int StatusCode; - public readonly string StatusString; - public readonly ParticipantState State; - public readonly string URI; - public readonly string AccountName; - public readonly string DisplayName; - public readonly ParticipantType Type; - - public ParticipantStateChangeEventArgs(string SessionHandle, int StatusCode, string StatusString, - ParticipantState State, string ParticipantURI, string AccountName, - string DisplayName, ParticipantType ParticipantType) - { - this.SessionHandle = SessionHandle; - this.StatusCode = StatusCode; - this.StatusString = StatusString; - this.State = State; - this.URI = ParticipantURI; - this.AccountName = AccountName; - this.DisplayName = DisplayName; - this.Type = ParticipantType; - } - } - - public class ParticipantPropertiesEventArgs : EventArgs - { - public readonly string SessionHandle; - public readonly string URI; - public readonly bool IsLocallyMuted; - public readonly bool IsModeratorMuted; - public readonly bool IsSpeaking; - public readonly int Volume; - public readonly float Energy; - - public ParticipantPropertiesEventArgs(string SessionHandle, string ParticipantURI, - bool IsLocallyMuted, bool IsModeratorMuted, bool IsSpeaking, int Volume, float Energy) - { - this.SessionHandle = SessionHandle; - this.URI = ParticipantURI; - this.IsLocallyMuted = IsLocallyMuted; - this.IsModeratorMuted = IsModeratorMuted; - this.IsSpeaking = IsSpeaking; - this.Volume = Volume; - this.Energy = Energy; - } - - } - - public class ParticipantUpdatedEventArgs : EventArgs - { - public readonly string SessionHandle; - public readonly string URI; - public readonly bool IsMuted; - public readonly bool IsSpeaking; - public readonly int Volume; - public readonly float Energy; - - public ParticipantUpdatedEventArgs(string sessionHandle, string URI, bool isMuted, bool isSpeaking, int volume, float energy) - { - this.SessionHandle = sessionHandle; - this.URI = URI; - this.IsMuted = isMuted; - this.IsSpeaking = isSpeaking; - this.Volume = volume; - this.Energy = energy; - } - } - - public class SessionAddedEventArgs : EventArgs - { - public readonly string SessionGroupHandle; - public readonly string SessionHandle; - public readonly string URI; - public readonly bool IsChannel; - public readonly bool IsIncoming; - - public SessionAddedEventArgs(string sessionGroupHandle, string sessionHandle, - string URI, bool isChannel, bool isIncoming) - { - this.SessionGroupHandle = sessionGroupHandle; - this.SessionHandle = sessionHandle; - this.URI = URI; - this.IsChannel = isChannel; - this.IsIncoming = isIncoming; - } - } - - public class SessionRemovedEventArgs : EventArgs - { - public readonly string SessionGroupHandle; - public readonly string SessionHandle; - public readonly string URI; - public SessionRemovedEventArgs( - string SessionGroupHandle, - string SessionHandle, - string Uri) - { - this.SessionGroupHandle = SessionGroupHandle; - this.SessionHandle = SessionHandle; - this.URI = Uri; - } - } - - public class SessionUpdatedEventArgs : EventArgs - { - public readonly string SessionGroupHandle; - public readonly string SessionHandle; - public readonly string URI; - public readonly bool IsMuted; - public readonly int Volume; - public readonly bool TransmitEnabled; - public readonly bool IsFocused; - public SessionUpdatedEventArgs(string SessionGroupHandle, - string SessionHandle, string URI, bool IsMuted, int Volume, - bool TransmitEnabled, bool IsFocused) - { - this.SessionGroupHandle = SessionGroupHandle; - this.SessionHandle = SessionHandle; - this.URI = URI; - this.IsMuted = IsMuted; - this.Volume = Volume; - this.TransmitEnabled = TransmitEnabled; - this.IsFocused = IsFocused; - } - - } - - public class SessionGroupAddedEventArgs : EventArgs - { - public readonly string AccountHandle; - public readonly string SessionGroupHandle; - public readonly string Type; - public SessionGroupAddedEventArgs(string acctHandle, string sessionGroupHandle, string type) - { - this.AccountHandle = acctHandle; - this.SessionGroupHandle = sessionGroupHandle; - this.Type = type; - } - } - #endregion Session Event Args - - #region Connector Delegates - public class VoiceConnectorEventArgs : VoiceResponseEventArgs - { - private readonly string m_Version; - private readonly string m_ConnectorHandle; - public string Version { get { return m_Version; } } - public string Handle { get { return m_ConnectorHandle; } } - - public VoiceConnectorEventArgs(int rcode, int scode, string text, string version, string handle) : - base(ResponseType.ConnectorCreate, rcode, scode, text) - { - m_Version = version; - m_ConnectorHandle = handle; - } - } - - #endregion Connector Delegates - - - #region Aux Event Args - public class VoiceDevicesEventArgs : VoiceResponseEventArgs - { - private readonly string m_CurrentDevice; - private readonly List m_Available; - public string CurrentDevice { get { return m_CurrentDevice; } } - public List Devices { get { return m_Available; } } - - public VoiceDevicesEventArgs(ResponseType type, int rcode, int scode, string text, string current, List avail) : - base(type, rcode, scode, text) - { - m_CurrentDevice = current; - m_Available = avail; - } - } - - - /// Audio Properties Events are sent after audio capture is started. These events are used to display a microphone VU meter - public class AudioPropertiesEventArgs : EventArgs - { - public readonly bool IsMicActive; - public readonly float MicEnergy; - public readonly int MicVolume; - public readonly int SpeakerVolume; - public AudioPropertiesEventArgs(bool MicIsActive, float MicEnergy, int MicVolume, int SpeakerVolume) - { - this.IsMicActive = MicIsActive; - this.MicEnergy = MicEnergy; - this.MicVolume = MicVolume; - this.SpeakerVolume = SpeakerVolume; - } - } - - #endregion Aux Event Args - - #region Account Event Args - public class VoiceAccountEventArgs : VoiceResponseEventArgs - { - private readonly string m_AccountHandle; - public string AccountHandle { get { return m_AccountHandle; } } - - public VoiceAccountEventArgs(int rcode, int scode, string text, string ahandle) : - base(ResponseType.AccountLogin, rcode, scode, text) - { - this.m_AccountHandle = ahandle; - } - } - - public class AccountLoginStateChangeEventArgs : EventArgs - { - public readonly string AccountHandle; - public readonly int StatusCode; - public readonly string StatusString; - public readonly LoginState State; - public AccountLoginStateChangeEventArgs(string AccountHandle, int StatusCode, string StatusString, LoginState State) - { - this.AccountHandle = AccountHandle; - this.StatusCode = StatusCode; - this.StatusString = StatusString; - this.State = State; - } - } - - #endregion Account Event Args - - /// - /// Event for most mundane request reposnses. - /// - public event EventHandler OnVoiceResponse; - - #region Session Events - public event EventHandler OnSessionCreateResponse; - public event EventHandler OnSessionNewEvent; - public event EventHandler OnSessionStateChangeEvent; - public event EventHandler OnSessionParticipantStateChangeEvent; - public event EventHandler OnSessionParticipantPropertiesEvent; - public event EventHandler OnSessionParticipantUpdatedEvent; - public event EventHandler OnSessionParticipantAddedEvent; - public event EventHandler OnSessionParticipantRemovedEvent; - public event EventHandler OnSessionGroupAddedEvent; - public event EventHandler OnSessionAddedEvent; - public event EventHandler OnSessionRemovedEvent; - public event EventHandler OnSessionUpdatedEvent; - public event EventHandler OnSessionMediaEvent; - #endregion Session Events - - #region Connector Events - - /// Response to Connector.Create request - public event EventHandler OnConnectorCreateResponse; - - #endregion Connector Events - - #region Aux Events - - /// Response to Aux.GetCaptureDevices request - public event EventHandler OnAuxGetCaptureDevicesResponse; - /// Response to Aux.GetRenderDevices request - public event EventHandler OnAuxGetRenderDevicesResponse; - - /// Audio Properties Events are sent after audio capture is started. - /// These events are used to display a microphone VU meter - public event EventHandler OnAuxAudioPropertiesEvent; - - #endregion Aux Events - - #region Account Events - - /// Response to Account.Login request - public event EventHandler OnAccountLoginResponse; - - /// This event message is sent whenever the login state of the - /// particular Account has transitioned from one value to another - public event EventHandler OnAccountLoginStateChangeEvent; - - #endregion Account Events - - #region XML Serialization Classes - - private XmlSerializer EventSerializer = new XmlSerializer(typeof(VoiceEvent)); - private XmlSerializer ResponseSerializer = new XmlSerializer(typeof(VoiceResponse)); - - [XmlRoot("Event")] - public class VoiceEvent - { - [XmlAttribute("type")] - public string Type; - public string AccountHandle; - public string Application; - public string StatusCode; - public string StatusString; - public string State; - public string SessionHandle; - public string SessionGroupHandle; - public string URI; - public string Uri; // Yes, they send it with both capitalizations - public string IsChannel; - public string IsIncoming; - public string Incoming; - public string IsMuted; - public string Name; - public string AudioMedia; - public string ChannelName; - public string ParticipantUri; - public string AccountName; - public string DisplayName; - public string ParticipantType; - public string IsLocallyMuted; - public string IsModeratorMuted; - public string IsSpeaking; - public string Volume; - public string Energy; - public string MicIsActive; - public string MicEnergy; - public string MicVolume; - public string SpeakerVolume; - public string HasText; - public string HasAudio; - public string HasVideo; - public string Terminated; - public string Reason; - public string TransmitEnabled; - public string IsFocused; - } - - [XmlRoot("Response")] - public class VoiceResponse - { - [XmlAttribute("requestId")] - public string RequestId; - [XmlAttribute("action")] - public string Action; - public string ReturnCode; - public VoiceResponseResults Results; - public VoiceInputXml InputXml; - } - - public class CaptureDevice - { - public string Device; - } - - public class RenderDevice - { - public string Device; - } - - public class VoiceResponseResults - { - public string VersionID; - public string StatusCode; - public string StatusString; - public string ConnectorHandle; - public string AccountHandle; - public string SessionHandle; - public List CaptureDevices; - public CaptureDevice CurrentCaptureDevice; - public List RenderDevices; - public RenderDevice CurrentRenderDevice; - } - - public class VoiceInputXml - { - public VoiceRequest Request; - } - - [XmlRoot("Request")] - public class VoiceRequest - { - [XmlAttribute("requestId")] - public string RequestId; - [XmlAttribute("action")] - public string Action; - public string RenderDeviceSpecifier; - public string CaptureDeviceSpecifier; - public string Duration; - public string Level; - public string ClientName; - public string AccountManagementServer; - public string MinimumPort; - public string MaximumPort; - public VoiceLoggingSettings Logging; - public string ConnectorHandle; - public string Value; - public string AccountName; - public string AccountPassword; - public string AudioSessionAnswerMode; - public string AccountURI; - public string ParticipantPropertyFrequency; - public string EnableBuddiesAndPresence; - public string URI; - public string Name; - public string Password; - public string JoinAudio; - public string JoinText; - public string PasswordHashAlgorithm; - public string SoundFilePath; - public string Loop; - public string SessionHandle; - public string OrientationType; - public VoicePosition SpeakerPosition; - public VoicePosition ListenerPosition; - public string ParticipantURI; - public string Volume; - } - - #endregion XML Serialization Classes - } - - public class VoicePosition - { - /// Positional vector of the users position - public Vector3d Position; - /// Velocity vector of the position - public Vector3d Velocity; - /// At Orientation (X axis) of the position - public Vector3d AtOrientation; - /// Up Orientation (Y axis) of the position - public Vector3d UpOrientation; - /// Left Orientation (Z axis) of the position - public Vector3d LeftOrientation; - } - -} diff --git a/LibreMetaverse/Voice/VoiceGateway.cs b/LibreMetaverse/Voice/VoiceGateway.cs deleted file mode 100644 index 202792b..0000000 --- a/LibreMetaverse/Voice/VoiceGateway.cs +++ /dev/null @@ -1,693 +0,0 @@ -/* - * Copyright (c) 2006-2016, openmetaverse.co - * 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 openmetaverse.co 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 System.Collections.Generic; -using System.IO; -using System.Net.Sockets; -using System.Diagnostics; -using System.Threading; -using System.Text; - -namespace OpenMetaverse.Voice -{ - public partial class VoiceGateway - { - public delegate void DaemonRunningCallback(); - public delegate void DaemonExitedCallback(); - public delegate void DaemonCouldntRunCallback(); - public delegate void DaemonConnectedCallback(); - public delegate void DaemonDisconnectedCallback(); - public delegate void DaemonCouldntConnectCallback(); - - public event DaemonRunningCallback OnDaemonRunning; - public event DaemonExitedCallback OnDaemonExited; - public event DaemonCouldntRunCallback OnDaemonCouldntRun; - public event DaemonConnectedCallback OnDaemonConnected; - public event DaemonDisconnectedCallback OnDaemonDisconnected; - public event DaemonCouldntConnectCallback OnDaemonCouldntConnect; - - public bool DaemonIsRunning { get { return daemonIsRunning; } } - public bool DaemonIsConnected { get { return daemonIsConnected; } } - public int RequestId { get { return requestId; } } - - protected Process daemonProcess; - protected ManualResetEvent daemonLoopSignal = new ManualResetEvent(false); - protected TCPPipe daemonPipe; - protected bool daemonIsRunning = false; - protected bool daemonIsConnected = false; - protected int requestId = 0; - - #region Daemon Management - - /// - /// Starts a thread that keeps the daemon running - /// - /// - /// - public void StartDaemon(string path, string args) - { - StopDaemon(); - daemonLoopSignal.Set(); - - Thread thread = new Thread(new ThreadStart(delegate() - { - while (daemonLoopSignal.WaitOne(500, false)) - { - daemonProcess = new Process(); - daemonProcess.StartInfo.FileName = path; - daemonProcess.StartInfo.WorkingDirectory = Path.GetDirectoryName(path); - daemonProcess.StartInfo.Arguments = args; - daemonProcess.StartInfo.UseShellExecute = false; - - if (Environment.OSVersion.Platform == PlatformID.Unix) - { - string ldPath = string.Empty; - try - { - ldPath = Environment.GetEnvironmentVariable("LD_LIBRARY_PATH"); - } - catch { } - string newLdPath = daemonProcess.StartInfo.WorkingDirectory; - if (!string.IsNullOrEmpty(ldPath)) - newLdPath += ":" + ldPath; - daemonProcess.StartInfo.EnvironmentVariables.Add("LD_LIBRARY_PATH", newLdPath); - } - - Logger.DebugLog("Voice folder: " + daemonProcess.StartInfo.WorkingDirectory); - Logger.DebugLog(path + " " + args); - bool ok = File.Exists(path); - - if (ok) - { - // Attempt to start the process - if (!daemonProcess.Start()) - ok = false; - } - - if (!ok) - { - daemonIsRunning = false; - daemonLoopSignal.Reset(); - - if (OnDaemonCouldntRun != null) - { - try { OnDaemonCouldntRun(); } - catch (Exception e) { Logger.Log(e.Message, Helpers.LogLevel.Error, null, e); } - } - - return; - } - else - { - Thread.Sleep(2000); - daemonIsRunning = true; - if (OnDaemonRunning != null) - { - try { OnDaemonRunning(); } - catch (Exception e) { Logger.Log(e.Message, Helpers.LogLevel.Error, null, e); } - } - - Logger.DebugLog("Started voice daemon, waiting for exit..."); - daemonProcess.WaitForExit(); - Logger.DebugLog("Voice daemon exited"); - daemonIsRunning = false; - - if (OnDaemonExited != null) - { - try { OnDaemonExited(); } - catch (Exception e) { Logger.Log(e.Message, Helpers.LogLevel.Error, null, e); } - } - } - } - })); - - thread.Name = "VoiceDaemonController"; - thread.IsBackground = true; - thread.Start(); - } - - /// - /// Stops the daemon and the thread keeping it running - /// - public void StopDaemon() - { - daemonLoopSignal.Reset(); - if (daemonProcess != null) - { - try - { - daemonProcess.Kill(); - } - catch (InvalidOperationException ex) - { - Logger.Log("Failed to stop the voice daemon", Helpers.LogLevel.Error, ex); - } - } - } - - /// - /// - /// - /// - /// - /// - public bool ConnectToDaemon(string address, int port) - { - daemonIsConnected = false; - - daemonPipe = new TCPPipe(); - daemonPipe.OnDisconnected += - delegate(SocketException e) - { - if (OnDaemonDisconnected != null) - { - try { OnDaemonDisconnected(); } - catch (Exception ex) { Logger.Log(ex.Message, Helpers.LogLevel.Error, null, ex); } - } - }; - daemonPipe.OnReceiveLine += new TCPPipe.OnReceiveLineCallback(daemonPipe_OnReceiveLine); - - SocketException se = daemonPipe.Connect(address, port); - if (se == null) - { - daemonIsConnected = true; - - if (OnDaemonConnected != null) - { - try { OnDaemonConnected(); } - catch (Exception e) { Logger.Log(e.Message, Helpers.LogLevel.Error, null, e); } - } - - return true; - } - else - { - daemonIsConnected = false; - - if (OnDaemonCouldntConnect != null) - { - try { OnDaemonCouldntConnect(); } - catch (Exception e) { Logger.Log(e.Message, Helpers.LogLevel.Error, null, e); } - } - - Logger.Log("Voice daemon connection failed: " + se.Message, Helpers.LogLevel.Error); - return false; - } - } - - #endregion Daemon Management - - public int Request(string action) - { - return Request(action, null); - } - - public int Request(string action, string requestXML) - { - int returnId = requestId; - if (daemonIsConnected) - { - StringBuilder sb = new StringBuilder(); - sb.Append(String.Format(""); - } - else - { - sb.Append(">"); - sb.Append(requestXML); - sb.Append(""); - } - sb.Append("\n\n\n"); - -#if DEBUG - Logger.Log("Request: " + sb, Helpers.LogLevel.Debug); -#endif - try - { - daemonPipe.SendData(Encoding.ASCII.GetBytes(sb.ToString())); - } - catch - { - returnId = -1; - } - - return returnId; - } - else - { - return -1; - } - } - - public static string MakeXML(string name, string text) - { - if (string.IsNullOrEmpty(text)) - return string.Format("<{0} />", name); - else - return string.Format("<{0}>{1}", name, text); - } - - private void daemonPipe_OnReceiveLine(string line) - { -#if DEBUG - Logger.Log(line, Helpers.LogLevel.Debug); -#endif - - if (line.Substring(0, 10) == "(); - - if (rsp.Results.CaptureDevices.Count == 0 || rsp.Results.CurrentCaptureDevice == null) - break; - - foreach (CaptureDevice device in rsp.Results.CaptureDevices) - inputDevices.Add(device.Device); - currentCaptureDevice = rsp.Results.CurrentCaptureDevice.Device; - - if (OnAuxGetCaptureDevicesResponse != null && rsp.Results.CaptureDevices.Count > 0) - { - OnAuxGetCaptureDevicesResponse( - rsp.InputXml.Request, - new VoiceDevicesEventArgs( - ResponseType.GetCaptureDevices, - int.Parse(rsp.ReturnCode), - int.Parse(rsp.Results.StatusCode), - rsp.Results.StatusString, - rsp.Results.CurrentCaptureDevice.Device, - inputDevices)); - } - break; - case "Aux.GetRenderDevices.1": - outputDevices = new List(); - - if (rsp.Results.RenderDevices.Count == 0 || rsp.Results.CurrentRenderDevice == null) - break; - - foreach (RenderDevice device in rsp.Results.RenderDevices) - outputDevices.Add(device.Device); - - - currentPlaybackDevice = rsp.Results.CurrentRenderDevice.Device; - - if (OnAuxGetRenderDevicesResponse != null) - { - OnAuxGetRenderDevicesResponse( - rsp.InputXml.Request, - new VoiceDevicesEventArgs( - ResponseType.GetCaptureDevices, - int.Parse(rsp.ReturnCode), - int.Parse(rsp.Results.StatusCode), - rsp.Results.StatusString, - rsp.Results.CurrentRenderDevice.Device, - outputDevices)); - } - break; - - case "Account.Login.1": - if (OnAccountLoginResponse != null) - { - OnAccountLoginResponse(rsp.InputXml.Request, - new VoiceAccountEventArgs( - int.Parse(rsp.ReturnCode), - int.Parse(rsp.Results.StatusCode), - rsp.Results.StatusString, - rsp.Results.AccountHandle)); - } - break; - - case "Session.Create.1": - if (OnSessionCreateResponse != null) - { - OnSessionCreateResponse( - rsp.InputXml.Request, - new VoiceSessionEventArgs( - int.Parse(rsp.ReturnCode), - int.Parse(rsp.Results.StatusCode), - rsp.Results.StatusString, - rsp.Results.SessionHandle)); - } - break; - - // All the remaining responses below this point just report status, - // so they all share the same Event. Most are useful only for - // detecting coding errors. - case "Connector.InitiateShutdown.1": - genericResponse = ResponseType.ConnectorInitiateShutdown; - break; - case "Aux.SetRenderDevice.1": - genericResponse = ResponseType.SetRenderDevice; - break; - case "Connector.MuteLocalMic.1": - genericResponse = ResponseType.MuteLocalMic; - break; - case "Connector.MuteLocalSpeaker.1": - genericResponse = ResponseType.MuteLocalSpeaker; - break; - case "Connector.SetLocalMicVolume.1": - genericResponse = ResponseType.SetLocalMicVolume; - break; - case "Connector.SetLocalSpeakerVolume.1": - genericResponse = ResponseType.SetLocalSpeakerVolume; - break; - case "Aux.SetCaptureDevice.1": - genericResponse = ResponseType.SetCaptureDevice; - break; - case "Session.RenderAudioStart.1": - genericResponse = ResponseType.RenderAudioStart; - break; - case "Session.RenderAudioStop.1": - genericResponse = ResponseType.RenderAudioStop; - break; - case "Aux.CaptureAudioStart.1": - genericResponse = ResponseType.CaptureAudioStart; - break; - case "Aux.CaptureAudioStop.1": - genericResponse = ResponseType.CaptureAudioStop; - break; - case "Aux.SetMicLevel.1": - genericResponse = ResponseType.SetMicLevel; - break; - case "Aux.SetSpeakerLevel.1": - genericResponse = ResponseType.SetSpeakerLevel; - break; - case "Account.Logout.1": - genericResponse = ResponseType.AccountLogout; - break; - case "Session.Connect.1": - genericResponse = ResponseType.SessionConnect; - break; - case "Session.Terminate.1": - genericResponse = ResponseType.SessionTerminate; - break; - case "Session.SetParticipantVolumeForMe.1": - genericResponse = ResponseType.SetParticipantVolumeForMe; - break; - case "Session.SetParticipantMuteForMe.1": - genericResponse = ResponseType.SetParticipantMuteForMe; - break; - case "Session.Set3DPosition.1": - genericResponse = ResponseType.Set3DPosition; - break; - default: - Logger.Log("Unimplemented response from the voice daemon: " + line, Helpers.LogLevel.Error); - break; - } - - // Send the Response Event for all the simple cases. - if (genericResponse != ResponseType.None && OnVoiceResponse != null) - { - OnVoiceResponse(rsp.InputXml.Request, - new VoiceResponseEventArgs( - genericResponse, - int.Parse(rsp.ReturnCode), - int.Parse(rsp.Results.StatusCode), - rsp.Results.StatusString)); - } - } - else if (line.Substring(0, 7) == "c1_m1000xrjiQgi95QhCzH_D6ZJ8c5A== - break; - - case "MediaStreamUpdatedEvent": - // TODO c1_m1000xrjiQgi95QhCzH_D6ZJ8c5A==_sg0 - // c1_m1000xrjiQgi95QhCzH_D6ZJ8c5A==0 - //01false - - break; - - default: - Logger.Log("Unimplemented event from the voice daemon: " + line, Helpers.LogLevel.Error); - break; - } - } - else - { - Logger.Log("Unrecognized data from the voice daemon: " + line, Helpers.LogLevel.Error); - } - } - } -} diff --git a/LibreMetaverse/Voice/VoiceParticipant.cs b/LibreMetaverse/Voice/VoiceParticipant.cs deleted file mode 100644 index 135d9a2..0000000 --- a/LibreMetaverse/Voice/VoiceParticipant.cs +++ /dev/null @@ -1,159 +0,0 @@ -/* - * Copyright (c) 2006-2016, openmetaverse.co - * 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 openmetaverse.co 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 System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Text.RegularExpressions; - -namespace OpenMetaverse.Voice -{ - public class VoiceParticipant - { - private string Sip; - private string AvatarName { get; set; } - private UUID id; - - private bool muted; - private int volume; - private VoiceSession session; - private float energy; - - public float Energy { get { return energy; } } - private bool speaking; - public bool IsSpeaking { get { return speaking; } } - public string URI { get { return Sip; } } - public UUID ID { get { return id; } } - - public VoiceParticipant(string puri, VoiceSession s) - { - id = IDFromName(puri); - Sip = puri; - session = s; - } - - /// - /// Extract the avatar UUID encoded in a SIP URI - /// - /// - /// - public static UUID IDFromName(string inName) - { - // The "name" may actually be a SIP URI such as: "sip:xFnPP04IpREWNkuw1cOXlhw==@bhr.vivox.com" - // If it is, convert to a bare name before doing the transform. - string name = nameFromsipURI(inName) ?? inName; - - // Doesn't look like a SIP URI, assume it's an actual name. - - // This will only work if the name is of the proper form. - // As an example, the account name for Monroe Linden (UUID 1673cfd3-8229-4445-8d92-ec3570e5e587) is: - // "xFnPP04IpREWNkuw1cOXlhw==" - - if ((name.Length == 25) && (name[0] == 'x') && (name[23] == '=') && (name[24] == '=')) - { - // The name appears to have the right form. - - // Reverse the transforms done by nameFromID - string temp = name.Replace('-', '+'); - temp = temp.Replace('_', '/'); - - byte[] binary = Convert.FromBase64String(temp.Substring(1)); - UUID u = UUID.Zero; - u.FromBytes(binary, 0); - return u; - } - - return UUID.Zero; - } - - private static string Encode64(string str) - { - byte[] encbuff = System.Text.Encoding.UTF8.GetBytes(str); - return Convert.ToBase64String(encbuff); - } - private static byte[] Decode64(string str) - { - return Convert.FromBase64String(str); - // return System.Text.Encoding.UTF8.GetString(decbuff); - } - - private static string nameFromsipURI(string uri) - { - Regex sip = new Regex("^sip:([^@]*)@.*$"); - Match m = sip.Match(uri); - if (m.Success) - { - GroupCollection g = m.Groups; - return g[1].Value; - } - - return null; - } - - public string Name - { - get { return AvatarName; } - set { AvatarName = value; } - } - - public bool IsMuted - { - get { return muted; } - set - { - muted = value; - StringBuilder sb = new StringBuilder(); - sb.Append(OpenMetaverse.Voice.VoiceGateway.MakeXML("SessionHandle", session.Handle)); - sb.Append(OpenMetaverse.Voice.VoiceGateway.MakeXML("ParticipantURI", Sip)); - sb.Append(OpenMetaverse.Voice.VoiceGateway.MakeXML("Mute", muted ? "1" : "0")); - session.Connector.Request("Session.SetParticipantMuteForMe.1", sb.ToString()); - } - } - - public int Volume - { - get { return volume; } - set - { - volume = value; - StringBuilder sb = new StringBuilder(); - sb.Append(OpenMetaverse.Voice.VoiceGateway.MakeXML("SessionHandle", session.Handle)); - sb.Append(OpenMetaverse.Voice.VoiceGateway.MakeXML("ParticipantURI", Sip)); - sb.Append(OpenMetaverse.Voice.VoiceGateway.MakeXML("Volume", volume.ToString())); - session.Connector.Request("Session.SetParticipantVolumeForMe.1", sb.ToString()); - } - } - - internal void SetProperties(bool speak, bool mute, float en) - { - speaking = speak; - muted = mute; - energy = en; - } - } -} - diff --git a/LibreMetaverse/Voice/VoiceSession.cs b/LibreMetaverse/Voice/VoiceSession.cs deleted file mode 100644 index aadc96e..0000000 --- a/LibreMetaverse/Voice/VoiceSession.cs +++ /dev/null @@ -1,337 +0,0 @@ -/* - * Copyright (c) 2006-2016, openmetaverse.co - * 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 openmetaverse.co 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 System.Collections.Generic; -using System.Text; -using OpenMetaverse; - -namespace OpenMetaverse.Voice -{ - /// - /// Represents a single Voice Session to the Vivox service. - /// - public class VoiceSession - { - private string m_Handle; - private static Dictionary knownParticipants; - public string RegionName; - private bool m_spatial; - public bool IsSpatial { get { return m_spatial; } } - private VoiceGateway connector; - - public VoiceGateway Connector { get { return connector; } } - public string Handle { get { return m_Handle; } } - - public event System.EventHandler OnParticipantAdded; - public event System.EventHandler OnParticipantUpdate; - public event System.EventHandler OnParticipantRemoved; - - public VoiceSession(VoiceGateway conn, string handle) - { - m_Handle = handle; - connector = conn; - - m_spatial = true; - knownParticipants = new Dictionary(); - } - - /// - /// Close this session. - /// - internal void Close() - { - - knownParticipants.Clear(); - } - - internal void ParticipantUpdate(string URI, - bool isMuted, - bool isSpeaking, - int volume, - float energy) - { - lock (knownParticipants) - { - // Locate in this session - VoiceParticipant p = FindParticipant(URI); - if (p == null) return; - - // Set properties - p.SetProperties(isSpeaking, isMuted, energy); - - // Inform interested parties. - if (OnParticipantUpdate != null) - OnParticipantUpdate(p, null); - } - } - - internal void AddParticipant(string URI) - { - lock (knownParticipants) - { - VoiceParticipant p = FindParticipant(URI); - - // We expect that to come back null. If it is not - // null, this is a duplicate - if (p != null) - { - return; - } - - // It was not found, so add it. - p = new VoiceParticipant(URI, this); - knownParticipants.Add(URI, p); - - /* TODO - // Fill in the name. - if (p.Name == null || p.Name.StartsWith("Loading...")) - p.Name = control.instance.getAvatarName(p.ID); - return p; - */ - - // Inform interested parties. - if (OnParticipantAdded != null) - OnParticipantAdded(p, null); - } - } - - internal void RemoveParticipant(string URI) - { - lock (knownParticipants) - { - VoiceParticipant p = FindParticipant(URI); - if (p == null) return; - - // Remove from list for this session. - knownParticipants.Remove(URI); - - // Inform interested parties. - if (OnParticipantRemoved != null) - OnParticipantRemoved(p, null); - } - } - - /// - /// Look up an existing Participants in this session - /// - /// - /// - private VoiceParticipant FindParticipant(string puri) - { - if (knownParticipants.ContainsKey(puri)) - return knownParticipants[puri]; - - return null; - } - - public void Set3DPosition(VoicePosition SpeakerPosition, VoicePosition ListenerPosition) - { - connector.SessionSet3DPosition(m_Handle, SpeakerPosition, ListenerPosition); - } - } - - public partial class VoiceGateway - { - /// - /// Create a Session - /// Sessions typically represent a connection to a media session with one or more - /// participants. This is used to generate an ‘outbound’ call to another user or - /// channel. The specifics depend on the media types involved. A session handle is - /// required to control the local user functions within the session (or remote - /// users if the current account has rights to do so). Currently creating a - /// session automatically connects to the audio media, there is no need to call - /// Session.Connect at this time, this is reserved for future use. - /// - /// Handle returned from successful Connector ‘create’ request - /// This is the URI of the terminating point of the session (ie who/what is being called) - /// This is the display name of the entity being called (user or channel) - /// Only needs to be supplied when the target URI is password protected - /// This indicates the format of the password as passed in. This can either be - /// “ClearText” or “SHA1UserName”. If this element does not exist, it is assumed to be “ClearText”. If it is - /// “SHA1UserName”, the password as passed in is the SHA1 hash of the password and username concatenated together, - /// then base64 encoded, with the final “=” character stripped off. - /// - /// - /// - public int SessionCreate(string AccountHandle, string URI, string Name, string Password, - bool JoinAudio, bool JoinText, string PasswordHashAlgorithm) - { - StringBuilder sb = new StringBuilder(); - sb.Append(VoiceGateway.MakeXML("AccountHandle", AccountHandle)); - sb.Append(VoiceGateway.MakeXML("URI", URI)); - sb.Append(VoiceGateway.MakeXML("Name", Name)); - if (!string.IsNullOrEmpty(Password)) - { - sb.Append(VoiceGateway.MakeXML("Password", Password)); - sb.Append(VoiceGateway.MakeXML("PasswordHashAlgorithm", PasswordHashAlgorithm)); - } - sb.Append(VoiceGateway.MakeXML("ConnectAudio", JoinAudio ? "true" : "false")); - sb.Append(VoiceGateway.MakeXML("ConnectText", JoinText ? "true" : "false")); - sb.Append(VoiceGateway.MakeXML("JoinAudio", JoinAudio ? "true" : "false")); - sb.Append(VoiceGateway.MakeXML("JoinText", JoinText ? "true" : "false")); - sb.Append(VoiceGateway.MakeXML("VoiceFontID", "0")); - - return Request("Session.Create.1", sb.ToString()); - } - - /// - /// Used to accept a call - /// - /// SessionHandle such as received from SessionNewEvent - /// "default" - /// - public int SessionConnect(string SessionHandle, string AudioMedia) - { - StringBuilder sb = new StringBuilder(); - sb.Append(VoiceGateway.MakeXML("SessionHandle", SessionHandle)); - sb.Append(VoiceGateway.MakeXML("AudioMedia", AudioMedia)); - return Request("Session.Connect.1", sb.ToString()); - } - - /// - /// This command is used to start the audio render process, which will then play - /// the passed in file through the selected audio render device. This command - /// should not be issued if the user is on a call. - /// - /// The fully qualified path to the sound file. - /// True if the file is to be played continuously and false if it is should be played once. - /// - public int SessionRenderAudioStart(string SoundFilePath, bool Loop) - { - StringBuilder sb = new StringBuilder(); - sb.Append(VoiceGateway.MakeXML("SoundFilePath", SoundFilePath)); - sb.Append(VoiceGateway.MakeXML("Loop", Loop ? "1" : "0")); - return Request("Session.RenderAudioStart.1", sb.ToString()); - } - - /// - /// This command is used to stop the audio render process. - /// - /// The fully qualified path to the sound file issued in the start render command. - /// - public int SessionRenderAudioStop(string SoundFilePath) - { - string RequestXML = VoiceGateway.MakeXML("SoundFilePath", SoundFilePath); - return Request("Session.RenderAudioStop.1", RequestXML); - } - - /// - /// This is used to ‘end’ an established session (i.e. hang-up or disconnect). - /// - /// Handle returned from successful Session ‘create’ request or a SessionNewEvent - /// - public int SessionTerminate(string SessionHandle) - { - string RequestXML = VoiceGateway.MakeXML("SessionHandle", SessionHandle); - return Request("Session.Terminate.1", RequestXML); - } - - /// - /// Set the combined speaking and listening position in 3D space. - /// - /// Handle returned from successful Session ‘create’ request or a SessionNewEvent - /// Speaking position - /// Listening position - /// - public int SessionSet3DPosition(string SessionHandle, VoicePosition SpeakerPosition, VoicePosition ListenerPosition) - { - StringBuilder sb = new StringBuilder(); - sb.Append(VoiceGateway.MakeXML("SessionHandle", SessionHandle)); - sb.Append(""); - sb.Append(""); - sb.Append(VoiceGateway.MakeXML("X", SpeakerPosition.Position.X.ToString())); - sb.Append(VoiceGateway.MakeXML("Y", SpeakerPosition.Position.Y.ToString())); - sb.Append(VoiceGateway.MakeXML("Z", SpeakerPosition.Position.Z.ToString())); - sb.Append(""); - sb.Append(""); - sb.Append(VoiceGateway.MakeXML("X", SpeakerPosition.Velocity.X.ToString())); - sb.Append(VoiceGateway.MakeXML("Y", SpeakerPosition.Velocity.Y.ToString())); - sb.Append(VoiceGateway.MakeXML("Z", SpeakerPosition.Velocity.Z.ToString())); - sb.Append(""); - sb.Append(""); - sb.Append(VoiceGateway.MakeXML("X", SpeakerPosition.AtOrientation.X.ToString())); - sb.Append(VoiceGateway.MakeXML("Y", SpeakerPosition.AtOrientation.Y.ToString())); - sb.Append(VoiceGateway.MakeXML("Z", SpeakerPosition.AtOrientation.Z.ToString())); - sb.Append(""); - sb.Append(""); - sb.Append(VoiceGateway.MakeXML("X", SpeakerPosition.UpOrientation.X.ToString())); - sb.Append(VoiceGateway.MakeXML("Y", SpeakerPosition.UpOrientation.Y.ToString())); - sb.Append(VoiceGateway.MakeXML("Z", SpeakerPosition.UpOrientation.Z.ToString())); - sb.Append(""); - sb.Append(""); - sb.Append(VoiceGateway.MakeXML("X", SpeakerPosition.LeftOrientation.X.ToString())); - sb.Append(VoiceGateway.MakeXML("Y", SpeakerPosition.LeftOrientation.Y.ToString())); - sb.Append(VoiceGateway.MakeXML("Z", SpeakerPosition.LeftOrientation.Z.ToString())); - sb.Append(""); - sb.Append(""); - sb.Append(""); - sb.Append(""); - sb.Append(VoiceGateway.MakeXML("X", ListenerPosition.Position.X.ToString())); - sb.Append(VoiceGateway.MakeXML("Y", ListenerPosition.Position.Y.ToString())); - sb.Append(VoiceGateway.MakeXML("Z", ListenerPosition.Position.Z.ToString())); - sb.Append(""); - sb.Append(""); - sb.Append(VoiceGateway.MakeXML("X", ListenerPosition.Velocity.X.ToString())); - sb.Append(VoiceGateway.MakeXML("Y", ListenerPosition.Velocity.Y.ToString())); - sb.Append(VoiceGateway.MakeXML("Z", ListenerPosition.Velocity.Z.ToString())); - sb.Append(""); - sb.Append(""); - sb.Append(VoiceGateway.MakeXML("X", ListenerPosition.AtOrientation.X.ToString())); - sb.Append(VoiceGateway.MakeXML("Y", ListenerPosition.AtOrientation.Y.ToString())); - sb.Append(VoiceGateway.MakeXML("Z", ListenerPosition.AtOrientation.Z.ToString())); - sb.Append(""); - sb.Append(""); - sb.Append(VoiceGateway.MakeXML("X", ListenerPosition.UpOrientation.X.ToString())); - sb.Append(VoiceGateway.MakeXML("Y", ListenerPosition.UpOrientation.Y.ToString())); - sb.Append(VoiceGateway.MakeXML("Z", ListenerPosition.UpOrientation.Z.ToString())); - sb.Append(""); - sb.Append(""); - sb.Append(VoiceGateway.MakeXML("X", ListenerPosition.LeftOrientation.X.ToString())); - sb.Append(VoiceGateway.MakeXML("Y", ListenerPosition.LeftOrientation.Y.ToString())); - sb.Append(VoiceGateway.MakeXML("Z", ListenerPosition.LeftOrientation.Z.ToString())); - sb.Append(""); - sb.Append(""); - return Request("Session.Set3DPosition.1", sb.ToString()); - } - - /// - /// Set User Volume for a particular user. Does not affect how other users hear that user. - /// - /// Handle returned from successful Session ‘create’ request or a SessionNewEvent - /// - /// The level of the audio, a number between -100 and 100 where 0 represents ‘normal’ speaking volume - /// - public int SessionSetParticipantVolumeForMe(string SessionHandle, string ParticipantURI, int Volume) - { - StringBuilder sb = new StringBuilder(); - sb.Append(VoiceGateway.MakeXML("SessionHandle", SessionHandle)); - sb.Append(VoiceGateway.MakeXML("ParticipantURI", ParticipantURI)); - sb.Append(VoiceGateway.MakeXML("Volume", Volume.ToString())); - return Request("Session.SetParticipantVolumeForMe.1", sb.ToString()); - } - } -} diff --git a/LibreMetaverse/WindowsLibraryLoader.cs b/LibreMetaverse/WindowsLibraryLoader.cs deleted file mode 100644 index a225cf0..0000000 --- a/LibreMetaverse/WindowsLibraryLoader.cs +++ /dev/null @@ -1,307 +0,0 @@ -/* - * Copyright (c) 2021, Sjofn LLC. - * 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 openmetaverse.co 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 System.Collections.Generic; -using System.Diagnostics; -using System.Globalization; -using System.IO; -using System.Reflection; -using System.Runtime.InteropServices; -using System.Text; - -namespace LibreMetaverse -{ - internal sealed class WindowsLibraryLoader - { - #region Fields - - private const string ProcessorArchitecture = "PROCESSOR_ARCHITECTURE"; - private const string DllFileExtension = ".dll"; - private const string DllDirectory = "dll"; - private readonly Dictionary _ProcessorArchitectureAddressWidthPlatforms = - new Dictionary(StringComparer.OrdinalIgnoreCase) - { - {"x86", 4}, - {"AMD64", 8}, - {"IA64", 8}, - {"ARM", 4} - }; - - private readonly Dictionary _ProcessorArchitecturePlatforms = - new Dictionary(StringComparer.OrdinalIgnoreCase) - { - {"x86", "x86"}, - {"AMD64", "x64"}, - {"IA64", "Itanium"}, - {"ARM", "WinCE"} - }; - - private readonly object _SyncLock = new object(); - private static readonly IDictionary LoadedLibraries = new Dictionary(); - - [DllImport("kernel32", EntryPoint = "LoadLibrary", CallingConvention = CallingConvention.Winapi, SetLastError = true, BestFitMapping = false, ThrowOnUnmappableChar = true)] - private static extern IntPtr Win32LoadLibrary(string dllPath); - - #endregion - - #region Properties - - public static bool IsCurrentPlatformSupported() - { - return RuntimeInformation.IsOSPlatform(OSPlatform.Windows); - } - - public static bool IsWindows() - { - return Environment.OSVersion.Platform == PlatformID.Win32NT || - Environment.OSVersion.Platform == PlatformID.Win32S || - Environment.OSVersion.Platform == PlatformID.Win32Windows || - Environment.OSVersion.Platform == PlatformID.WinCE; - } - - #endregion - - #region Methods - - #region Helpers - - private static string FixUpDllFileName(string fileName) - { - if (string.IsNullOrEmpty(fileName)) - return fileName; - - if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - return fileName; - - if (!fileName.EndsWith(DllFileExtension, StringComparison.OrdinalIgnoreCase)) - return $"{fileName}{DllFileExtension}"; - - return fileName; - } - - private ProcessArchitectureInfo GetProcessArchitecture() - { - // BUG: Will this always be reliable? - var processArchitecture = Environment.GetEnvironmentVariable(ProcessorArchitecture); - var processInfo = new ProcessArchitectureInfo(); - if (!string.IsNullOrEmpty(processArchitecture)) - { - // Sanity check - processInfo.Architecture = processArchitecture; - } - else - { - processInfo.AddWarning("Failed to detect processor architecture, falling back to x86."); - processInfo.Architecture = (IntPtr.Size == 8) ? "x64" : "x86"; - } - - var addressWidth = this._ProcessorArchitectureAddressWidthPlatforms[processInfo.Architecture]; - if (addressWidth != IntPtr.Size) - { - if (String.Equals(processInfo.Architecture, "AMD64", StringComparison.OrdinalIgnoreCase) && IntPtr.Size == 4) - { - // fall back to x86 if detected x64 but has an address width of 32 bits. - processInfo.Architecture = "x86"; - processInfo.AddWarning("Expected the detected processing architecture of {0} to have an address width of {1} Bytes but was {2} Bytes, falling back to x86.", processInfo.Architecture, addressWidth, IntPtr.Size); - } - else - { - // no fallback possible - processInfo.AddWarning("Expected the detected processing architecture of {0} to have an address width of {1} Bytes but was {2} Bytes.", processInfo.Architecture, addressWidth, IntPtr.Size); - - } - } - - return processInfo; - } - - private string GetPlatformName(string processorArchitecture) - { - if (String.IsNullOrEmpty(processorArchitecture)) - return null; - - string platformName; - if (this._ProcessorArchitecturePlatforms.TryGetValue(processorArchitecture, out platformName)) - { - return platformName; - } - - return null; - } - - public void LoadLibraries(IEnumerable dlls) - { - if (!IsWindows()) - return; - - foreach (var dll in dlls) - LoadLibrary(dll); - } - - private void LoadLibrary(string dllName) - { - if (!IsCurrentPlatformSupported()) - return; - - try - { - lock (this._SyncLock) - { - if (LoadedLibraries.ContainsKey(dllName)) - return; - - var processArch = GetProcessArchitecture(); - IntPtr dllHandle; - - // Try loading from executing assembly domain - var executingAssembly = GetType().GetTypeInfo().Assembly; - var baseDirectory = Path.GetDirectoryName(executingAssembly.Location); - dllHandle = LoadLibraryInternal(dllName, baseDirectory, processArch); - if (dllHandle != IntPtr.Zero) return; - - // Gets the pathname of the base directory that the assembly resolver uses to probe for assemblies. - // https://github.com/dotnet/corefx/issues/2221 - baseDirectory = AppContext.BaseDirectory; - dllHandle = LoadLibraryInternal(dllName, baseDirectory, processArch); - if (dllHandle != IntPtr.Zero) return; - - // Finally try the working directory - baseDirectory = Path.GetFullPath(Directory.GetCurrentDirectory()); - dllHandle = LoadLibraryInternal(dllName, baseDirectory, processArch); - if (dllHandle != IntPtr.Zero) return; - - var errorMessage = new StringBuilder(); - errorMessage.Append($"Failed to find dll \"{dllName}\", for processor architecture {processArch.Architecture}."); - if (processArch.HasWarnings) - { - // include process detection warnings - errorMessage.Append($"\r\nWarnings: \r\n{processArch.WarningText()}"); - } - - throw new Exception(errorMessage.ToString()); - } - } - catch (Exception e) - { - Debug.WriteLine(e.Message); - } - } - - private IntPtr LoadLibraryInternal(string dllName, string baseDirectory, ProcessArchitectureInfo processArchInfo) - { - var platformName = GetPlatformName(processArchInfo.Architecture); - var expectedDllDirectory = Path.Combine( - Path.Combine(baseDirectory, DllDirectory), platformName); - return this.LoadLibraryRaw(dllName, expectedDllDirectory); - } - - private IntPtr LoadLibraryRaw(string dllName, string baseDirectory) - { - var libraryHandle = IntPtr.Zero; - var fileName = FixUpDllFileName(Path.Combine(baseDirectory, dllName)); - - // Show where we're trying to load the file from - Debug.WriteLine($"Trying to load native library \"{fileName}\"..."); - - if (File.Exists(fileName)) - { - // Attempt to load dll - try - { - libraryHandle = Win32LoadLibrary(fileName); - if (libraryHandle != IntPtr.Zero) - { - // library has been loaded - Debug.WriteLine($"Successfully loaded native library \"{fileName}\"."); - LoadedLibraries.Add(dllName, libraryHandle); - } - else - { - Debug.WriteLine($"Failed to load native library \"{fileName}\".\r\nCheck windows event log."); - } - } - catch (Exception e) - { - var lastError = Marshal.GetLastWin32Error(); - Debug.WriteLine($"Failed to load native library \"{fileName}\".\r\nLast Error:{lastError}\r\nCheck inner exception and\\or windows event log.\r\nInner Exception: {e}"); - } - } - else - { - Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "The native library \"{0}\" does not exist.", fileName)); - } - - return libraryHandle; - } - - #endregion - - #endregion - - private class ProcessArchitectureInfo - { - #region Constructors - - public ProcessArchitectureInfo() - { - this.Warnings = new List(); - } - - #endregion - - #region Properties - - public string Architecture - { - get; set; - } - - private List Warnings - { - get; - } - - #endregion - - #region Methods - - public void AddWarning(string format, params object[] args) - { - Warnings.Add(String.Format(format, args)); - } - - public bool HasWarnings => Warnings.Count > 0; - - public string WarningText() - { - return string.Join("\r\n", Warnings.ToArray()); - } - - #endregion - } - } -} diff --git a/LibreMetaverse/_Packets_.cs b/LibreMetaverse/_Packets_.cs index 8b7b9fd..096c5f3 100644 --- a/LibreMetaverse/_Packets_.cs +++ b/LibreMetaverse/_Packets_.cs @@ -1,82006 +1,82004 @@ -/* - * Copyright (c) 2006-2016, openmetaverse.co - * 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 System.Text; -using OpenMetaverse; - -namespace OpenMetaverse -{ - /// - /// - /// - public enum PacketFrequency : byte - { - /// - Low, - /// - Medium, - /// - High - } -} - -namespace OpenMetaverse.Packets -{ - /// - /// Thrown when a packet could not be successfully deserialized - /// - [Serializable] - public class MalformedDataException : ApplicationException - { - /// - /// Default constructor - /// - public MalformedDataException() { } - - /// - /// Constructor that takes an additional error message - /// - /// An error message to attach to this exception - public MalformedDataException(string Message) - : base(Message) - { - this.Source = "Packet decoding"; - } - } - - /// - /// The header of a message template packet. Holds packet flags, sequence - /// number, packet ID, and any ACKs that will be appended at the end of - /// the packet - /// - public struct Header - { - public bool Reliable; - public bool Resent; - public bool Zerocoded; - public bool AppendedAcks; - public uint Sequence; - public ushort ID; - public PacketFrequency Frequency; - public uint[] AckList; - - public void ToBytes(byte[] bytes, ref int i) - { - byte flags = 0; - if (Reliable) flags |= Helpers.MSG_RELIABLE; - if (Resent) flags |= Helpers.MSG_RESENT; - if (Zerocoded) flags |= Helpers.MSG_ZEROCODED; - if (AppendedAcks) flags |= Helpers.MSG_APPENDED_ACKS; - - // Flags - bytes[i++] = flags; - - // Sequence number - Utils.UIntToBytesBig(Sequence, bytes, i); - i += 4; - - // Extra byte - bytes[i++] = 0; - - // Packet ID - switch (Frequency) - { - case PacketFrequency.High: - // 1 byte ID - bytes[i++] = (byte)ID; - break; - case PacketFrequency.Medium: - // 2 byte ID - bytes[i++] = 0xFF; - bytes[i++] = (byte)ID; - break; - case PacketFrequency.Low: - // 4 byte ID - bytes[i++] = 0xFF; - bytes[i++] = 0xFF; - Utils.UInt16ToBytesBig(ID, bytes, i); - i += 2; - break; - } - } - - public void FromBytes(byte[] bytes, ref int pos, ref int packetEnd) - { - this = BuildHeader(bytes, ref pos, ref packetEnd); - } - - /// - /// Convert the AckList to a byte array, used for packet serializing - /// - /// Reference to the target byte array - /// Beginning position to start writing to in the byte - /// array, will be updated with the ending position of the ACK list - public void AcksToBytes(byte[] bytes, ref int i) - { - foreach (uint ack in AckList) - { - Utils.UIntToBytesBig(ack, bytes, i); - i += 4; - } - if (AckList.Length > 0) { bytes[i++] = (byte)AckList.Length; } - } - - /// - /// - /// - /// - /// - /// - /// - public static Header BuildHeader(byte[] bytes, ref int pos, ref int packetEnd) - { - Header header; - byte flags = bytes[pos]; - - header.AppendedAcks = (flags & Helpers.MSG_APPENDED_ACKS) != 0; - header.Reliable = (flags & Helpers.MSG_RELIABLE) != 0; - header.Resent = (flags & Helpers.MSG_RESENT) != 0; - header.Zerocoded = (flags & Helpers.MSG_ZEROCODED) != 0; - header.Sequence = (uint)((bytes[pos + 1] << 24) + (bytes[pos + 2] << 16) + (bytes[pos + 3] << 8) + bytes[pos + 4]); - - // Set the frequency and packet ID number - if (bytes[pos + 6] == 0xFF) - { - if (bytes[pos + 7] == 0xFF) - { - header.Frequency = PacketFrequency.Low; - if (header.Zerocoded && bytes[pos + 8] == 0) - header.ID = bytes[pos + 10]; - else - header.ID = (ushort)((bytes[pos + 8] << 8) + bytes[pos + 9]); - - pos += 10; - } - else - { - header.Frequency = PacketFrequency.Medium; - header.ID = bytes[pos + 7]; - - pos += 8; - } - } - else - { - header.Frequency = PacketFrequency.High; - header.ID = bytes[pos + 6]; - - pos += 7; - } - - header.AckList = null; - CreateAckList(ref header, bytes, ref packetEnd); - - return header; - } - - /// - /// - /// - /// - /// - /// - static void CreateAckList(ref Header header, byte[] bytes, ref int packetEnd) - { - if (header.AppendedAcks) - { - int count = bytes[packetEnd--]; - header.AckList = new uint[count]; - - for (int i = 0; i < count; i++) - { - header.AckList[i] = (uint)( - (bytes[(packetEnd - i * 4) - 3] << 24) | - (bytes[(packetEnd - i * 4) - 2] << 16) | - (bytes[(packetEnd - i * 4) - 1] << 8) | - (bytes[(packetEnd - i * 4) ])); - } - - packetEnd -= (count * 4); - } - } - } - - /// - /// A block of data in a packet. Packets are composed of one or more blocks, - /// each block containing one or more fields - /// - public abstract class PacketBlock - { - /// Current length of the data in this packet - public abstract int Length { get; } - - /// - /// Create a block from a byte array - /// - /// Byte array containing the serialized block - /// Starting position of the block in the byte array. - /// This will point to the data after the end of the block when the - /// call returns - public abstract void FromBytes(byte[] bytes, ref int i); - - /// - /// Serialize this block into a byte array - /// - /// Byte array to serialize this block into - /// Starting position in the byte array to serialize to. - /// This will point to the position directly after the end of the - /// serialized block when the call returns - public abstract void ToBytes(byte[] bytes, ref int i); - } - - public enum PacketType - { - /// A generic value, not an actual packet type - Default, - TestMessage = 65537, - UseCircuitCode = 65539, - TelehubInfo = 65546, - EconomyDataRequest = 65560, - EconomyData = 65561, - AvatarPickerRequest = 65562, - AvatarPickerReply = 65564, - PlacesQuery = 65565, - PlacesReply = 65566, - DirFindQuery = 65567, - DirPlacesQuery = 65569, - DirPlacesReply = 65571, - DirPeopleReply = 65572, - DirEventsReply = 65573, - DirGroupsReply = 65574, - DirClassifiedQuery = 65575, - DirClassifiedReply = 65577, - AvatarClassifiedReply = 65578, - ClassifiedInfoRequest = 65579, - ClassifiedInfoReply = 65580, - ClassifiedInfoUpdate = 65581, - ClassifiedDelete = 65582, - ClassifiedGodDelete = 65583, - DirLandQuery = 65584, - DirLandReply = 65586, - DirPopularQuery = 65587, - DirPopularReply = 65589, - ParcelInfoRequest = 65590, - ParcelInfoReply = 65591, - ParcelObjectOwnersRequest = 65592, - ParcelObjectOwnersReply = 65593, - GroupNoticesListRequest = 65594, - GroupNoticesListReply = 65595, - GroupNoticeRequest = 65596, - TeleportRequest = 65598, - TeleportLocationRequest = 65599, - TeleportLocal = 65600, - TeleportLandmarkRequest = 65601, - TeleportProgress = 65602, - TeleportFinish = 65605, - StartLure = 65606, - TeleportLureRequest = 65607, - TeleportCancel = 65608, - TeleportStart = 65609, - TeleportFailed = 65610, - Undo = 65611, - Redo = 65612, - UndoLand = 65613, - AgentPause = 65614, - AgentResume = 65615, - ChatFromViewer = 65616, - AgentThrottle = 65617, - AgentFOV = 65618, - AgentHeightWidth = 65619, - AgentSetAppearance = 65620, - AgentQuitCopy = 65621, - ImageNotInDatabase = 65622, - RebakeAvatarTextures = 65623, - SetAlwaysRun = 65624, - ObjectDelete = 65625, - ObjectDuplicate = 65626, - ObjectDuplicateOnRay = 65627, - ObjectScale = 65628, - ObjectRotation = 65629, - ObjectFlagUpdate = 65630, - ObjectClickAction = 65631, - ObjectImage = 65632, - ObjectMaterial = 65633, - ObjectShape = 65634, - ObjectExtraParams = 65635, - ObjectOwner = 65636, - ObjectGroup = 65637, - ObjectBuy = 65638, - BuyObjectInventory = 65639, - DerezContainer = 65640, - ObjectPermissions = 65641, - ObjectSaleInfo = 65642, - ObjectName = 65643, - ObjectDescription = 65644, - ObjectCategory = 65645, - ObjectSelect = 65646, - ObjectDeselect = 65647, - ObjectAttach = 65648, - ObjectDetach = 65649, - ObjectDrop = 65650, - ObjectLink = 65651, - ObjectDelink = 65652, - ObjectGrab = 65653, - ObjectGrabUpdate = 65654, - ObjectDeGrab = 65655, - ObjectSpinStart = 65656, - ObjectSpinUpdate = 65657, - ObjectSpinStop = 65658, - ObjectExportSelected = 65659, - ModifyLand = 65660, - VelocityInterpolateOn = 65661, - VelocityInterpolateOff = 65662, - StateSave = 65663, - ReportAutosaveCrash = 65664, - SimWideDeletes = 65665, - TrackAgent = 65666, - ViewerStats = 65667, - ScriptAnswerYes = 65668, - UserReport = 65669, - AlertMessage = 65670, - AgentAlertMessage = 65671, - MeanCollisionAlert = 65672, - ViewerFrozenMessage = 65673, - HealthMessage = 65674, - ChatFromSimulator = 65675, - SimStats = 65676, - RequestRegionInfo = 65677, - RegionInfo = 65678, - GodUpdateRegionInfo = 65679, - RegionHandshake = 65684, - RegionHandshakeReply = 65685, - SimulatorViewerTimeMessage = 65686, - EnableSimulator = 65687, - DisableSimulator = 65688, - TransferRequest = 65689, - TransferInfo = 65690, - TransferAbort = 65691, - RequestXfer = 65692, - AbortXfer = 65693, - AvatarAppearance = 65694, - SetFollowCamProperties = 65695, - ClearFollowCamProperties = 65696, - RequestPayPrice = 65697, - PayPriceReply = 65698, - KickUser = 65699, - GodKickUser = 65701, - EjectUser = 65703, - FreezeUser = 65704, - AvatarPropertiesRequest = 65705, - AvatarPropertiesReply = 65707, - AvatarInterestsReply = 65708, - AvatarGroupsReply = 65709, - AvatarPropertiesUpdate = 65710, - AvatarInterestsUpdate = 65711, - AvatarNotesReply = 65712, - AvatarNotesUpdate = 65713, - AvatarPicksReply = 65714, - EventInfoRequest = 65715, - EventInfoReply = 65716, - EventNotificationAddRequest = 65717, - EventNotificationRemoveRequest = 65718, - EventGodDelete = 65719, - PickInfoReply = 65720, - PickInfoUpdate = 65721, - PickDelete = 65722, - PickGodDelete = 65723, - ScriptQuestion = 65724, - ScriptControlChange = 65725, - ScriptDialog = 65726, - ScriptDialogReply = 65727, - ForceScriptControlRelease = 65728, - RevokePermissions = 65729, - LoadURL = 65730, - ScriptTeleportRequest = 65731, - ParcelOverlay = 65732, - ParcelPropertiesRequestByID = 65733, - ParcelPropertiesUpdate = 65734, - ParcelReturnObjects = 65735, - ParcelSetOtherCleanTime = 65736, - ParcelDisableObjects = 65737, - ParcelSelectObjects = 65738, - EstateCovenantRequest = 65739, - EstateCovenantReply = 65740, - ForceObjectSelect = 65741, - ParcelBuyPass = 65742, - ParcelDeedToGroup = 65743, - ParcelReclaim = 65744, - ParcelClaim = 65745, - ParcelJoin = 65746, - ParcelDivide = 65747, - ParcelRelease = 65748, - ParcelBuy = 65749, - ParcelGodForceOwner = 65750, - ParcelAccessListRequest = 65751, - ParcelAccessListReply = 65752, - ParcelAccessListUpdate = 65753, - ParcelDwellRequest = 65754, - ParcelDwellReply = 65755, - ParcelGodMarkAsContent = 65763, - ViewerStartAuction = 65764, - UUIDNameRequest = 65771, - UUIDNameReply = 65772, - UUIDGroupNameRequest = 65773, - UUIDGroupNameReply = 65774, - ChildAgentDying = 65776, - ChildAgentUnknown = 65777, - GetScriptRunning = 65779, - ScriptRunningReply = 65780, - SetScriptRunning = 65781, - ScriptReset = 65782, - ScriptSensorRequest = 65783, - ScriptSensorReply = 65784, - CompleteAgentMovement = 65785, - AgentMovementComplete = 65786, - LogoutRequest = 65788, - LogoutReply = 65789, - ImprovedInstantMessage = 65790, - RetrieveInstantMessages = 65791, - FindAgent = 65792, - RequestGodlikePowers = 65793, - GrantGodlikePowers = 65794, - GodlikeMessage = 65795, - EstateOwnerMessage = 65796, - GenericMessage = 65797, - MuteListRequest = 65798, - UpdateMuteListEntry = 65799, - RemoveMuteListEntry = 65800, - CopyInventoryFromNotecard = 65801, - UpdateInventoryItem = 65802, - UpdateCreateInventoryItem = 65803, - MoveInventoryItem = 65804, - CopyInventoryItem = 65805, - RemoveInventoryItem = 65806, - ChangeInventoryItemFlags = 65807, - SaveAssetIntoInventory = 65808, - CreateInventoryFolder = 65809, - UpdateInventoryFolder = 65810, - MoveInventoryFolder = 65811, - RemoveInventoryFolder = 65812, - FetchInventoryDescendents = 65813, - InventoryDescendents = 65814, - FetchInventory = 65815, - FetchInventoryReply = 65816, - BulkUpdateInventory = 65817, - RemoveInventoryObjects = 65820, - PurgeInventoryDescendents = 65821, - UpdateTaskInventory = 65822, - RemoveTaskInventory = 65823, - MoveTaskInventory = 65824, - RequestTaskInventory = 65825, - ReplyTaskInventory = 65826, - DeRezObject = 65827, - DeRezAck = 65828, - RezObject = 65829, - RezObjectFromNotecard = 65830, - AcceptFriendship = 65833, - DeclineFriendship = 65834, - TerminateFriendship = 65836, - OfferCallingCard = 65837, - AcceptCallingCard = 65838, - DeclineCallingCard = 65839, - RezScript = 65840, - CreateInventoryItem = 65841, - CreateLandmarkForEvent = 65842, - RegionHandleRequest = 65845, - RegionIDAndHandleReply = 65846, - MoneyTransferRequest = 65847, - MoneyBalanceRequest = 65849, - MoneyBalanceReply = 65850, - RoutedMoneyBalanceReply = 65851, - ActivateGestures = 65852, - DeactivateGestures = 65853, - MuteListUpdate = 65854, - UseCachedMuteList = 65855, - GrantUserRights = 65856, - ChangeUserRights = 65857, - OnlineNotification = 65858, - OfflineNotification = 65859, - SetStartLocationRequest = 65860, - AssetUploadRequest = 65869, - AssetUploadComplete = 65870, - CreateGroupRequest = 65875, - CreateGroupReply = 65876, - UpdateGroupInfo = 65877, - GroupRoleChanges = 65878, - JoinGroupRequest = 65879, - JoinGroupReply = 65880, - EjectGroupMemberRequest = 65881, - EjectGroupMemberReply = 65882, - LeaveGroupRequest = 65883, - LeaveGroupReply = 65884, - InviteGroupRequest = 65885, - GroupProfileRequest = 65887, - GroupProfileReply = 65888, - GroupAccountSummaryRequest = 65889, - GroupAccountSummaryReply = 65890, - GroupAccountDetailsRequest = 65891, - GroupAccountDetailsReply = 65892, - GroupAccountTransactionsRequest = 65893, - GroupAccountTransactionsReply = 65894, - GroupActiveProposalsRequest = 65895, - GroupActiveProposalItemReply = 65896, - GroupVoteHistoryRequest = 65897, - GroupVoteHistoryItemReply = 65898, - StartGroupProposal = 65899, - GroupProposalBallot = 65900, - GroupMembersRequest = 65902, - GroupMembersReply = 65903, - ActivateGroup = 65904, - SetGroupContribution = 65905, - SetGroupAcceptNotices = 65906, - GroupRoleDataRequest = 65907, - GroupRoleDataReply = 65908, - GroupRoleMembersRequest = 65909, - GroupRoleMembersReply = 65910, - GroupTitlesRequest = 65911, - GroupTitlesReply = 65912, - GroupTitleUpdate = 65913, - GroupRoleUpdate = 65914, - LiveHelpGroupRequest = 65915, - LiveHelpGroupReply = 65916, - AgentWearablesRequest = 65917, - AgentWearablesUpdate = 65918, - AgentIsNowWearing = 65919, - AgentCachedTexture = 65920, - AgentCachedTextureResponse = 65921, - AgentDataUpdateRequest = 65922, - AgentDataUpdate = 65923, - GroupDataUpdate = 65924, - AgentGroupDataUpdate = 65925, - AgentDropGroup = 65926, - RezSingleAttachmentFromInv = 65931, - RezMultipleAttachmentsFromInv = 65932, - DetachAttachmentIntoInv = 65933, - CreateNewOutfitAttachments = 65934, - UserInfoRequest = 65935, - UserInfoReply = 65936, - UpdateUserInfo = 65937, - InitiateDownload = 65939, - MapLayerRequest = 65941, - MapLayerReply = 65942, - MapBlockRequest = 65943, - MapNameRequest = 65944, - MapBlockReply = 65945, - MapItemRequest = 65946, - MapItemReply = 65947, - SendPostcard = 65948, - ParcelMediaCommandMessage = 65955, - ParcelMediaUpdate = 65956, - LandStatRequest = 65957, - LandStatReply = 65958, - Error = 65959, - ObjectIncludeInSearch = 65960, - RezRestoreToWorld = 65961, - LinkInventoryItem = 65962, - RetrieveIMsExtended = 65963, - JoinGroupRequestExtended = 65964, - CreateGroupRequestExtended = 65965, - PacketAck = 131067, - OpenCircuit = 131068, - CloseCircuit = 131069, - ObjectAdd = 131073, - MultipleObjectUpdate = 131074, - RequestMultipleObjects = 131075, - ObjectPosition = 131076, - RequestObjectPropertiesFamily = 131077, - CoarseLocationUpdate = 131078, - CrossedRegion = 131079, - ConfirmEnableSimulator = 131080, - ObjectProperties = 131081, - ObjectPropertiesFamily = 131082, - ParcelPropertiesRequest = 131083, - AttachedSound = 131085, - AttachedSoundGainChange = 131086, - PreloadSound = 131087, - ViewerEffect = 131089, - StartPingCheck = 196609, - CompletePingCheck = 196610, - AgentUpdate = 196612, - AgentAnimation = 196613, - AgentRequestSit = 196614, - AgentSit = 196615, - RequestImage = 196616, - ImageData = 196617, - ImagePacket = 196618, - LayerData = 196619, - ObjectUpdate = 196620, - ObjectUpdateCompressed = 196621, - ObjectUpdateCached = 196622, - ImprovedTerseObjectUpdate = 196623, - KillObject = 196624, - TransferPacket = 196625, - SendXferPacket = 196626, - ConfirmXferPacket = 196627, - AvatarAnimation = 196628, - AvatarSitResponse = 196629, - CameraConstraint = 196630, - ParcelProperties = 196631, - ChildAgentUpdate = 196633, - ChildAgentAlive = 196634, - ChildAgentPositionUpdate = 196635, - SoundTrigger = 196637, - ObjectAnimation = 196638, - } - - public abstract partial class Packet - { - public const int MTU = 1200; - - public Header Header; - public bool HasVariableBlocks; - public PacketType Type; - public abstract int Length { get; } - public abstract void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer); - public abstract void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd); - public abstract byte[] ToBytes(); - public abstract byte[][] ToBytesMultiple(); - - public virtual byte[] ToBytes(Interfaces.IByteBufferPool pool, ref int size) - { - throw new NotImplementedException(); - } - - public virtual byte[][] ToBytesMultiple(Interfaces.IByteBufferPool pool, out int[] sizes) - { - throw new NotImplementedException(); - } - - public virtual bool UsesBufferPooling - { - get - { - return false; - } - } - - public static PacketType GetType(ushort id, PacketFrequency frequency) - { - switch (frequency) - { - case PacketFrequency.Low: - switch (id) - { - case 1: return PacketType.TestMessage; - case 3: return PacketType.UseCircuitCode; - case 10: return PacketType.TelehubInfo; - case 24: return PacketType.EconomyDataRequest; - case 25: return PacketType.EconomyData; - case 26: return PacketType.AvatarPickerRequest; - case 28: return PacketType.AvatarPickerReply; - case 29: return PacketType.PlacesQuery; - case 30: return PacketType.PlacesReply; - case 31: return PacketType.DirFindQuery; - case 33: return PacketType.DirPlacesQuery; - case 35: return PacketType.DirPlacesReply; - case 36: return PacketType.DirPeopleReply; - case 37: return PacketType.DirEventsReply; - case 38: return PacketType.DirGroupsReply; - case 39: return PacketType.DirClassifiedQuery; - case 41: return PacketType.DirClassifiedReply; - case 42: return PacketType.AvatarClassifiedReply; - case 43: return PacketType.ClassifiedInfoRequest; - case 44: return PacketType.ClassifiedInfoReply; - case 45: return PacketType.ClassifiedInfoUpdate; - case 46: return PacketType.ClassifiedDelete; - case 47: return PacketType.ClassifiedGodDelete; - case 48: return PacketType.DirLandQuery; - case 50: return PacketType.DirLandReply; - case 51: return PacketType.DirPopularQuery; - case 53: return PacketType.DirPopularReply; - case 54: return PacketType.ParcelInfoRequest; - case 55: return PacketType.ParcelInfoReply; - case 56: return PacketType.ParcelObjectOwnersRequest; - case 57: return PacketType.ParcelObjectOwnersReply; - case 58: return PacketType.GroupNoticesListRequest; - case 59: return PacketType.GroupNoticesListReply; - case 60: return PacketType.GroupNoticeRequest; - case 62: return PacketType.TeleportRequest; - case 63: return PacketType.TeleportLocationRequest; - case 64: return PacketType.TeleportLocal; - case 65: return PacketType.TeleportLandmarkRequest; - case 66: return PacketType.TeleportProgress; - case 69: return PacketType.TeleportFinish; - case 70: return PacketType.StartLure; - case 71: return PacketType.TeleportLureRequest; - case 72: return PacketType.TeleportCancel; - case 73: return PacketType.TeleportStart; - case 74: return PacketType.TeleportFailed; - case 75: return PacketType.Undo; - case 76: return PacketType.Redo; - case 77: return PacketType.UndoLand; - case 78: return PacketType.AgentPause; - case 79: return PacketType.AgentResume; - case 80: return PacketType.ChatFromViewer; - case 81: return PacketType.AgentThrottle; - case 82: return PacketType.AgentFOV; - case 83: return PacketType.AgentHeightWidth; - case 84: return PacketType.AgentSetAppearance; - case 85: return PacketType.AgentQuitCopy; - case 86: return PacketType.ImageNotInDatabase; - case 87: return PacketType.RebakeAvatarTextures; - case 88: return PacketType.SetAlwaysRun; - case 89: return PacketType.ObjectDelete; - case 90: return PacketType.ObjectDuplicate; - case 91: return PacketType.ObjectDuplicateOnRay; - case 92: return PacketType.ObjectScale; - case 93: return PacketType.ObjectRotation; - case 94: return PacketType.ObjectFlagUpdate; - case 95: return PacketType.ObjectClickAction; - case 96: return PacketType.ObjectImage; - case 97: return PacketType.ObjectMaterial; - case 98: return PacketType.ObjectShape; - case 99: return PacketType.ObjectExtraParams; - case 100: return PacketType.ObjectOwner; - case 101: return PacketType.ObjectGroup; - case 102: return PacketType.ObjectBuy; - case 103: return PacketType.BuyObjectInventory; - case 104: return PacketType.DerezContainer; - case 105: return PacketType.ObjectPermissions; - case 106: return PacketType.ObjectSaleInfo; - case 107: return PacketType.ObjectName; - case 108: return PacketType.ObjectDescription; - case 109: return PacketType.ObjectCategory; - case 110: return PacketType.ObjectSelect; - case 111: return PacketType.ObjectDeselect; - case 112: return PacketType.ObjectAttach; - case 113: return PacketType.ObjectDetach; - case 114: return PacketType.ObjectDrop; - case 115: return PacketType.ObjectLink; - case 116: return PacketType.ObjectDelink; - case 117: return PacketType.ObjectGrab; - case 118: return PacketType.ObjectGrabUpdate; - case 119: return PacketType.ObjectDeGrab; - case 120: return PacketType.ObjectSpinStart; - case 121: return PacketType.ObjectSpinUpdate; - case 122: return PacketType.ObjectSpinStop; - case 123: return PacketType.ObjectExportSelected; - case 124: return PacketType.ModifyLand; - case 125: return PacketType.VelocityInterpolateOn; - case 126: return PacketType.VelocityInterpolateOff; - case 127: return PacketType.StateSave; - case 128: return PacketType.ReportAutosaveCrash; - case 129: return PacketType.SimWideDeletes; - case 130: return PacketType.TrackAgent; - case 131: return PacketType.ViewerStats; - case 132: return PacketType.ScriptAnswerYes; - case 133: return PacketType.UserReport; - case 134: return PacketType.AlertMessage; - case 135: return PacketType.AgentAlertMessage; - case 136: return PacketType.MeanCollisionAlert; - case 137: return PacketType.ViewerFrozenMessage; - case 138: return PacketType.HealthMessage; - case 139: return PacketType.ChatFromSimulator; - case 140: return PacketType.SimStats; - case 141: return PacketType.RequestRegionInfo; - case 142: return PacketType.RegionInfo; - case 143: return PacketType.GodUpdateRegionInfo; - case 148: return PacketType.RegionHandshake; - case 149: return PacketType.RegionHandshakeReply; - case 150: return PacketType.SimulatorViewerTimeMessage; - case 151: return PacketType.EnableSimulator; - case 152: return PacketType.DisableSimulator; - case 153: return PacketType.TransferRequest; - case 154: return PacketType.TransferInfo; - case 155: return PacketType.TransferAbort; - case 156: return PacketType.RequestXfer; - case 157: return PacketType.AbortXfer; - case 158: return PacketType.AvatarAppearance; - case 159: return PacketType.SetFollowCamProperties; - case 160: return PacketType.ClearFollowCamProperties; - case 161: return PacketType.RequestPayPrice; - case 162: return PacketType.PayPriceReply; - case 163: return PacketType.KickUser; - case 165: return PacketType.GodKickUser; - case 167: return PacketType.EjectUser; - case 168: return PacketType.FreezeUser; - case 169: return PacketType.AvatarPropertiesRequest; - case 171: return PacketType.AvatarPropertiesReply; - case 172: return PacketType.AvatarInterestsReply; - case 173: return PacketType.AvatarGroupsReply; - case 174: return PacketType.AvatarPropertiesUpdate; - case 175: return PacketType.AvatarInterestsUpdate; - case 176: return PacketType.AvatarNotesReply; - case 177: return PacketType.AvatarNotesUpdate; - case 178: return PacketType.AvatarPicksReply; - case 179: return PacketType.EventInfoRequest; - case 180: return PacketType.EventInfoReply; - case 181: return PacketType.EventNotificationAddRequest; - case 182: return PacketType.EventNotificationRemoveRequest; - case 183: return PacketType.EventGodDelete; - case 184: return PacketType.PickInfoReply; - case 185: return PacketType.PickInfoUpdate; - case 186: return PacketType.PickDelete; - case 187: return PacketType.PickGodDelete; - case 188: return PacketType.ScriptQuestion; - case 189: return PacketType.ScriptControlChange; - case 190: return PacketType.ScriptDialog; - case 191: return PacketType.ScriptDialogReply; - case 192: return PacketType.ForceScriptControlRelease; - case 193: return PacketType.RevokePermissions; - case 194: return PacketType.LoadURL; - case 195: return PacketType.ScriptTeleportRequest; - case 196: return PacketType.ParcelOverlay; - case 197: return PacketType.ParcelPropertiesRequestByID; - case 198: return PacketType.ParcelPropertiesUpdate; - case 199: return PacketType.ParcelReturnObjects; - case 200: return PacketType.ParcelSetOtherCleanTime; - case 201: return PacketType.ParcelDisableObjects; - case 202: return PacketType.ParcelSelectObjects; - case 203: return PacketType.EstateCovenantRequest; - case 204: return PacketType.EstateCovenantReply; - case 205: return PacketType.ForceObjectSelect; - case 206: return PacketType.ParcelBuyPass; - case 207: return PacketType.ParcelDeedToGroup; - case 208: return PacketType.ParcelReclaim; - case 209: return PacketType.ParcelClaim; - case 210: return PacketType.ParcelJoin; - case 211: return PacketType.ParcelDivide; - case 212: return PacketType.ParcelRelease; - case 213: return PacketType.ParcelBuy; - case 214: return PacketType.ParcelGodForceOwner; - case 215: return PacketType.ParcelAccessListRequest; - case 216: return PacketType.ParcelAccessListReply; - case 217: return PacketType.ParcelAccessListUpdate; - case 218: return PacketType.ParcelDwellRequest; - case 219: return PacketType.ParcelDwellReply; - case 227: return PacketType.ParcelGodMarkAsContent; - case 228: return PacketType.ViewerStartAuction; - case 235: return PacketType.UUIDNameRequest; - case 236: return PacketType.UUIDNameReply; - case 237: return PacketType.UUIDGroupNameRequest; - case 238: return PacketType.UUIDGroupNameReply; - case 240: return PacketType.ChildAgentDying; - case 241: return PacketType.ChildAgentUnknown; - case 243: return PacketType.GetScriptRunning; - case 244: return PacketType.ScriptRunningReply; - case 245: return PacketType.SetScriptRunning; - case 246: return PacketType.ScriptReset; - case 247: return PacketType.ScriptSensorRequest; - case 248: return PacketType.ScriptSensorReply; - case 249: return PacketType.CompleteAgentMovement; - case 250: return PacketType.AgentMovementComplete; - case 252: return PacketType.LogoutRequest; - case 253: return PacketType.LogoutReply; - case 254: return PacketType.ImprovedInstantMessage; - case 255: return PacketType.RetrieveInstantMessages; - case 256: return PacketType.FindAgent; - case 257: return PacketType.RequestGodlikePowers; - case 258: return PacketType.GrantGodlikePowers; - case 259: return PacketType.GodlikeMessage; - case 260: return PacketType.EstateOwnerMessage; - case 261: return PacketType.GenericMessage; - case 262: return PacketType.MuteListRequest; - case 263: return PacketType.UpdateMuteListEntry; - case 264: return PacketType.RemoveMuteListEntry; - case 265: return PacketType.CopyInventoryFromNotecard; - case 266: return PacketType.UpdateInventoryItem; - case 267: return PacketType.UpdateCreateInventoryItem; - case 268: return PacketType.MoveInventoryItem; - case 269: return PacketType.CopyInventoryItem; - case 270: return PacketType.RemoveInventoryItem; - case 271: return PacketType.ChangeInventoryItemFlags; - case 272: return PacketType.SaveAssetIntoInventory; - case 273: return PacketType.CreateInventoryFolder; - case 274: return PacketType.UpdateInventoryFolder; - case 275: return PacketType.MoveInventoryFolder; - case 276: return PacketType.RemoveInventoryFolder; - case 277: return PacketType.FetchInventoryDescendents; - case 278: return PacketType.InventoryDescendents; - case 279: return PacketType.FetchInventory; - case 280: return PacketType.FetchInventoryReply; - case 281: return PacketType.BulkUpdateInventory; - case 284: return PacketType.RemoveInventoryObjects; - case 285: return PacketType.PurgeInventoryDescendents; - case 286: return PacketType.UpdateTaskInventory; - case 287: return PacketType.RemoveTaskInventory; - case 288: return PacketType.MoveTaskInventory; - case 289: return PacketType.RequestTaskInventory; - case 290: return PacketType.ReplyTaskInventory; - case 291: return PacketType.DeRezObject; - case 292: return PacketType.DeRezAck; - case 293: return PacketType.RezObject; - case 294: return PacketType.RezObjectFromNotecard; - case 297: return PacketType.AcceptFriendship; - case 298: return PacketType.DeclineFriendship; - case 300: return PacketType.TerminateFriendship; - case 301: return PacketType.OfferCallingCard; - case 302: return PacketType.AcceptCallingCard; - case 303: return PacketType.DeclineCallingCard; - case 304: return PacketType.RezScript; - case 305: return PacketType.CreateInventoryItem; - case 306: return PacketType.CreateLandmarkForEvent; - case 309: return PacketType.RegionHandleRequest; - case 310: return PacketType.RegionIDAndHandleReply; - case 311: return PacketType.MoneyTransferRequest; - case 313: return PacketType.MoneyBalanceRequest; - case 314: return PacketType.MoneyBalanceReply; - case 315: return PacketType.RoutedMoneyBalanceReply; - case 316: return PacketType.ActivateGestures; - case 317: return PacketType.DeactivateGestures; - case 318: return PacketType.MuteListUpdate; - case 319: return PacketType.UseCachedMuteList; - case 320: return PacketType.GrantUserRights; - case 321: return PacketType.ChangeUserRights; - case 322: return PacketType.OnlineNotification; - case 323: return PacketType.OfflineNotification; - case 324: return PacketType.SetStartLocationRequest; - case 333: return PacketType.AssetUploadRequest; - case 334: return PacketType.AssetUploadComplete; - case 339: return PacketType.CreateGroupRequest; - case 340: return PacketType.CreateGroupReply; - case 341: return PacketType.UpdateGroupInfo; - case 342: return PacketType.GroupRoleChanges; - case 343: return PacketType.JoinGroupRequest; - case 344: return PacketType.JoinGroupReply; - case 345: return PacketType.EjectGroupMemberRequest; - case 346: return PacketType.EjectGroupMemberReply; - case 347: return PacketType.LeaveGroupRequest; - case 348: return PacketType.LeaveGroupReply; - case 349: return PacketType.InviteGroupRequest; - case 351: return PacketType.GroupProfileRequest; - case 352: return PacketType.GroupProfileReply; - case 353: return PacketType.GroupAccountSummaryRequest; - case 354: return PacketType.GroupAccountSummaryReply; - case 355: return PacketType.GroupAccountDetailsRequest; - case 356: return PacketType.GroupAccountDetailsReply; - case 357: return PacketType.GroupAccountTransactionsRequest; - case 358: return PacketType.GroupAccountTransactionsReply; - case 359: return PacketType.GroupActiveProposalsRequest; - case 360: return PacketType.GroupActiveProposalItemReply; - case 361: return PacketType.GroupVoteHistoryRequest; - case 362: return PacketType.GroupVoteHistoryItemReply; - case 363: return PacketType.StartGroupProposal; - case 364: return PacketType.GroupProposalBallot; - case 366: return PacketType.GroupMembersRequest; - case 367: return PacketType.GroupMembersReply; - case 368: return PacketType.ActivateGroup; - case 369: return PacketType.SetGroupContribution; - case 370: return PacketType.SetGroupAcceptNotices; - case 371: return PacketType.GroupRoleDataRequest; - case 372: return PacketType.GroupRoleDataReply; - case 373: return PacketType.GroupRoleMembersRequest; - case 374: return PacketType.GroupRoleMembersReply; - case 375: return PacketType.GroupTitlesRequest; - case 376: return PacketType.GroupTitlesReply; - case 377: return PacketType.GroupTitleUpdate; - case 378: return PacketType.GroupRoleUpdate; - case 379: return PacketType.LiveHelpGroupRequest; - case 380: return PacketType.LiveHelpGroupReply; - case 381: return PacketType.AgentWearablesRequest; - case 382: return PacketType.AgentWearablesUpdate; - case 383: return PacketType.AgentIsNowWearing; - case 384: return PacketType.AgentCachedTexture; - case 385: return PacketType.AgentCachedTextureResponse; - case 386: return PacketType.AgentDataUpdateRequest; - case 387: return PacketType.AgentDataUpdate; - case 388: return PacketType.GroupDataUpdate; - case 389: return PacketType.AgentGroupDataUpdate; - case 390: return PacketType.AgentDropGroup; - case 395: return PacketType.RezSingleAttachmentFromInv; - case 396: return PacketType.RezMultipleAttachmentsFromInv; - case 397: return PacketType.DetachAttachmentIntoInv; - case 398: return PacketType.CreateNewOutfitAttachments; - case 399: return PacketType.UserInfoRequest; - case 400: return PacketType.UserInfoReply; - case 401: return PacketType.UpdateUserInfo; - case 403: return PacketType.InitiateDownload; - case 405: return PacketType.MapLayerRequest; - case 406: return PacketType.MapLayerReply; - case 407: return PacketType.MapBlockRequest; - case 408: return PacketType.MapNameRequest; - case 409: return PacketType.MapBlockReply; - case 410: return PacketType.MapItemRequest; - case 411: return PacketType.MapItemReply; - case 412: return PacketType.SendPostcard; - case 419: return PacketType.ParcelMediaCommandMessage; - case 420: return PacketType.ParcelMediaUpdate; - case 421: return PacketType.LandStatRequest; - case 422: return PacketType.LandStatReply; - case 423: return PacketType.Error; - case 424: return PacketType.ObjectIncludeInSearch; - case 425: return PacketType.RezRestoreToWorld; - case 426: return PacketType.LinkInventoryItem; - case 427: return PacketType.RetrieveIMsExtended; - case 428: return PacketType.JoinGroupRequestExtended; - case 429: return PacketType.CreateGroupRequestExtended; - case 65531: return PacketType.PacketAck; - case 65532: return PacketType.OpenCircuit; - case 65533: return PacketType.CloseCircuit; - } - break; - case PacketFrequency.Medium: - switch (id) - { - case 1: return PacketType.ObjectAdd; - case 2: return PacketType.MultipleObjectUpdate; - case 3: return PacketType.RequestMultipleObjects; - case 4: return PacketType.ObjectPosition; - case 5: return PacketType.RequestObjectPropertiesFamily; - case 6: return PacketType.CoarseLocationUpdate; - case 7: return PacketType.CrossedRegion; - case 8: return PacketType.ConfirmEnableSimulator; - case 9: return PacketType.ObjectProperties; - case 10: return PacketType.ObjectPropertiesFamily; - case 11: return PacketType.ParcelPropertiesRequest; - case 13: return PacketType.AttachedSound; - case 14: return PacketType.AttachedSoundGainChange; - case 15: return PacketType.PreloadSound; - case 17: return PacketType.ViewerEffect; - } - break; - case PacketFrequency.High: - switch (id) - { - case 1: return PacketType.StartPingCheck; - case 2: return PacketType.CompletePingCheck; - case 4: return PacketType.AgentUpdate; - case 5: return PacketType.AgentAnimation; - case 6: return PacketType.AgentRequestSit; - case 7: return PacketType.AgentSit; - case 8: return PacketType.RequestImage; - case 9: return PacketType.ImageData; - case 10: return PacketType.ImagePacket; - case 11: return PacketType.LayerData; - case 12: return PacketType.ObjectUpdate; - case 13: return PacketType.ObjectUpdateCompressed; - case 14: return PacketType.ObjectUpdateCached; - case 15: return PacketType.ImprovedTerseObjectUpdate; - case 16: return PacketType.KillObject; - case 17: return PacketType.TransferPacket; - case 18: return PacketType.SendXferPacket; - case 19: return PacketType.ConfirmXferPacket; - case 20: return PacketType.AvatarAnimation; - case 21: return PacketType.AvatarSitResponse; - case 22: return PacketType.CameraConstraint; - case 23: return PacketType.ParcelProperties; - case 25: return PacketType.ChildAgentUpdate; - case 26: return PacketType.ChildAgentAlive; - case 27: return PacketType.ChildAgentPositionUpdate; - case 29: return PacketType.SoundTrigger; - case 30: return PacketType.ObjectAnimation; - } - break; - } - - return PacketType.Default; - } - - public static Packet BuildPacket(PacketType type) - { - if(type == PacketType.StartPingCheck) return new StartPingCheckPacket(); - if(type == PacketType.CompletePingCheck) return new CompletePingCheckPacket(); - if(type == PacketType.AgentUpdate) return new AgentUpdatePacket(); - if(type == PacketType.AgentAnimation) return new AgentAnimationPacket(); - if(type == PacketType.AgentRequestSit) return new AgentRequestSitPacket(); - if(type == PacketType.AgentSit) return new AgentSitPacket(); - if(type == PacketType.RequestImage) return new RequestImagePacket(); - if(type == PacketType.ImageData) return new ImageDataPacket(); - if(type == PacketType.ImagePacket) return new ImagePacketPacket(); - if(type == PacketType.LayerData) return new LayerDataPacket(); - if(type == PacketType.ObjectUpdate) return new ObjectUpdatePacket(); - if(type == PacketType.ObjectUpdateCompressed) return new ObjectUpdateCompressedPacket(); - if(type == PacketType.ObjectUpdateCached) return new ObjectUpdateCachedPacket(); - if(type == PacketType.ImprovedTerseObjectUpdate) return new ImprovedTerseObjectUpdatePacket(); - if(type == PacketType.KillObject) return new KillObjectPacket(); - if(type == PacketType.TransferPacket) return new TransferPacketPacket(); - if(type == PacketType.SendXferPacket) return new SendXferPacketPacket(); - if(type == PacketType.ConfirmXferPacket) return new ConfirmXferPacketPacket(); - if(type == PacketType.AvatarAnimation) return new AvatarAnimationPacket(); - if(type == PacketType.AvatarSitResponse) return new AvatarSitResponsePacket(); - if(type == PacketType.CameraConstraint) return new CameraConstraintPacket(); - if(type == PacketType.ParcelProperties) return new ParcelPropertiesPacket(); - if(type == PacketType.ChildAgentUpdate) return new ChildAgentUpdatePacket(); - if(type == PacketType.ChildAgentAlive) return new ChildAgentAlivePacket(); - if(type == PacketType.ChildAgentPositionUpdate) return new ChildAgentPositionUpdatePacket(); - if(type == PacketType.SoundTrigger) return new SoundTriggerPacket(); - if(type == PacketType.ObjectAnimation) return new ObjectAnimationPacket(); - if(type == PacketType.ObjectAdd) return new ObjectAddPacket(); - if(type == PacketType.MultipleObjectUpdate) return new MultipleObjectUpdatePacket(); - if(type == PacketType.RequestMultipleObjects) return new RequestMultipleObjectsPacket(); - if(type == PacketType.ObjectPosition) return new ObjectPositionPacket(); - if(type == PacketType.RequestObjectPropertiesFamily) return new RequestObjectPropertiesFamilyPacket(); - if(type == PacketType.CoarseLocationUpdate) return new CoarseLocationUpdatePacket(); - if(type == PacketType.CrossedRegion) return new CrossedRegionPacket(); - if(type == PacketType.ConfirmEnableSimulator) return new ConfirmEnableSimulatorPacket(); - if(type == PacketType.ObjectProperties) return new ObjectPropertiesPacket(); - if(type == PacketType.ObjectPropertiesFamily) return new ObjectPropertiesFamilyPacket(); - if(type == PacketType.ParcelPropertiesRequest) return new ParcelPropertiesRequestPacket(); - if(type == PacketType.AttachedSound) return new AttachedSoundPacket(); - if(type == PacketType.AttachedSoundGainChange) return new AttachedSoundGainChangePacket(); - if(type == PacketType.PreloadSound) return new PreloadSoundPacket(); - if(type == PacketType.ViewerEffect) return new ViewerEffectPacket(); - if(type == PacketType.TestMessage) return new TestMessagePacket(); - if(type == PacketType.UseCircuitCode) return new UseCircuitCodePacket(); - if(type == PacketType.TelehubInfo) return new TelehubInfoPacket(); - if(type == PacketType.EconomyDataRequest) return new EconomyDataRequestPacket(); - if(type == PacketType.EconomyData) return new EconomyDataPacket(); - if(type == PacketType.AvatarPickerRequest) return new AvatarPickerRequestPacket(); - if(type == PacketType.AvatarPickerReply) return new AvatarPickerReplyPacket(); - if(type == PacketType.PlacesQuery) return new PlacesQueryPacket(); - if(type == PacketType.PlacesReply) return new PlacesReplyPacket(); - if(type == PacketType.DirFindQuery) return new DirFindQueryPacket(); - if(type == PacketType.DirPlacesQuery) return new DirPlacesQueryPacket(); - if(type == PacketType.DirPlacesReply) return new DirPlacesReplyPacket(); - if(type == PacketType.DirPeopleReply) return new DirPeopleReplyPacket(); - if(type == PacketType.DirEventsReply) return new DirEventsReplyPacket(); - if(type == PacketType.DirGroupsReply) return new DirGroupsReplyPacket(); - if(type == PacketType.DirClassifiedQuery) return new DirClassifiedQueryPacket(); - if(type == PacketType.DirClassifiedReply) return new DirClassifiedReplyPacket(); - if(type == PacketType.AvatarClassifiedReply) return new AvatarClassifiedReplyPacket(); - if(type == PacketType.ClassifiedInfoRequest) return new ClassifiedInfoRequestPacket(); - if(type == PacketType.ClassifiedInfoReply) return new ClassifiedInfoReplyPacket(); - if(type == PacketType.ClassifiedInfoUpdate) return new ClassifiedInfoUpdatePacket(); - if(type == PacketType.ClassifiedDelete) return new ClassifiedDeletePacket(); - if(type == PacketType.ClassifiedGodDelete) return new ClassifiedGodDeletePacket(); - if(type == PacketType.DirLandQuery) return new DirLandQueryPacket(); - if(type == PacketType.DirLandReply) return new DirLandReplyPacket(); - if(type == PacketType.DirPopularQuery) return new DirPopularQueryPacket(); - if(type == PacketType.DirPopularReply) return new DirPopularReplyPacket(); - if(type == PacketType.ParcelInfoRequest) return new ParcelInfoRequestPacket(); - if(type == PacketType.ParcelInfoReply) return new ParcelInfoReplyPacket(); - if(type == PacketType.ParcelObjectOwnersRequest) return new ParcelObjectOwnersRequestPacket(); - if(type == PacketType.ParcelObjectOwnersReply) return new ParcelObjectOwnersReplyPacket(); - if(type == PacketType.GroupNoticesListRequest) return new GroupNoticesListRequestPacket(); - if(type == PacketType.GroupNoticesListReply) return new GroupNoticesListReplyPacket(); - if(type == PacketType.GroupNoticeRequest) return new GroupNoticeRequestPacket(); - if(type == PacketType.TeleportRequest) return new TeleportRequestPacket(); - if(type == PacketType.TeleportLocationRequest) return new TeleportLocationRequestPacket(); - if(type == PacketType.TeleportLocal) return new TeleportLocalPacket(); - if(type == PacketType.TeleportLandmarkRequest) return new TeleportLandmarkRequestPacket(); - if(type == PacketType.TeleportProgress) return new TeleportProgressPacket(); - if(type == PacketType.TeleportFinish) return new TeleportFinishPacket(); - if(type == PacketType.StartLure) return new StartLurePacket(); - if(type == PacketType.TeleportLureRequest) return new TeleportLureRequestPacket(); - if(type == PacketType.TeleportCancel) return new TeleportCancelPacket(); - if(type == PacketType.TeleportStart) return new TeleportStartPacket(); - if(type == PacketType.TeleportFailed) return new TeleportFailedPacket(); - if(type == PacketType.Undo) return new UndoPacket(); - if(type == PacketType.Redo) return new RedoPacket(); - if(type == PacketType.UndoLand) return new UndoLandPacket(); - if(type == PacketType.AgentPause) return new AgentPausePacket(); - if(type == PacketType.AgentResume) return new AgentResumePacket(); - if(type == PacketType.ChatFromViewer) return new ChatFromViewerPacket(); - if(type == PacketType.AgentThrottle) return new AgentThrottlePacket(); - if(type == PacketType.AgentFOV) return new AgentFOVPacket(); - if(type == PacketType.AgentHeightWidth) return new AgentHeightWidthPacket(); - if(type == PacketType.AgentSetAppearance) return new AgentSetAppearancePacket(); - if(type == PacketType.AgentQuitCopy) return new AgentQuitCopyPacket(); - if(type == PacketType.ImageNotInDatabase) return new ImageNotInDatabasePacket(); - if(type == PacketType.RebakeAvatarTextures) return new RebakeAvatarTexturesPacket(); - if(type == PacketType.SetAlwaysRun) return new SetAlwaysRunPacket(); - if(type == PacketType.ObjectDelete) return new ObjectDeletePacket(); - if(type == PacketType.ObjectDuplicate) return new ObjectDuplicatePacket(); - if(type == PacketType.ObjectDuplicateOnRay) return new ObjectDuplicateOnRayPacket(); - if(type == PacketType.ObjectScale) return new ObjectScalePacket(); - if(type == PacketType.ObjectRotation) return new ObjectRotationPacket(); - if(type == PacketType.ObjectFlagUpdate) return new ObjectFlagUpdatePacket(); - if(type == PacketType.ObjectClickAction) return new ObjectClickActionPacket(); - if(type == PacketType.ObjectImage) return new ObjectImagePacket(); - if(type == PacketType.ObjectMaterial) return new ObjectMaterialPacket(); - if(type == PacketType.ObjectShape) return new ObjectShapePacket(); - if(type == PacketType.ObjectExtraParams) return new ObjectExtraParamsPacket(); - if(type == PacketType.ObjectOwner) return new ObjectOwnerPacket(); - if(type == PacketType.ObjectGroup) return new ObjectGroupPacket(); - if(type == PacketType.ObjectBuy) return new ObjectBuyPacket(); - if(type == PacketType.BuyObjectInventory) return new BuyObjectInventoryPacket(); - if(type == PacketType.DerezContainer) return new DerezContainerPacket(); - if(type == PacketType.ObjectPermissions) return new ObjectPermissionsPacket(); - if(type == PacketType.ObjectSaleInfo) return new ObjectSaleInfoPacket(); - if(type == PacketType.ObjectName) return new ObjectNamePacket(); - if(type == PacketType.ObjectDescription) return new ObjectDescriptionPacket(); - if(type == PacketType.ObjectCategory) return new ObjectCategoryPacket(); - if(type == PacketType.ObjectSelect) return new ObjectSelectPacket(); - if(type == PacketType.ObjectDeselect) return new ObjectDeselectPacket(); - if(type == PacketType.ObjectAttach) return new ObjectAttachPacket(); - if(type == PacketType.ObjectDetach) return new ObjectDetachPacket(); - if(type == PacketType.ObjectDrop) return new ObjectDropPacket(); - if(type == PacketType.ObjectLink) return new ObjectLinkPacket(); - if(type == PacketType.ObjectDelink) return new ObjectDelinkPacket(); - if(type == PacketType.ObjectGrab) return new ObjectGrabPacket(); - if(type == PacketType.ObjectGrabUpdate) return new ObjectGrabUpdatePacket(); - if(type == PacketType.ObjectDeGrab) return new ObjectDeGrabPacket(); - if(type == PacketType.ObjectSpinStart) return new ObjectSpinStartPacket(); - if(type == PacketType.ObjectSpinUpdate) return new ObjectSpinUpdatePacket(); - if(type == PacketType.ObjectSpinStop) return new ObjectSpinStopPacket(); - if(type == PacketType.ObjectExportSelected) return new ObjectExportSelectedPacket(); - if(type == PacketType.ModifyLand) return new ModifyLandPacket(); - if(type == PacketType.VelocityInterpolateOn) return new VelocityInterpolateOnPacket(); - if(type == PacketType.VelocityInterpolateOff) return new VelocityInterpolateOffPacket(); - if(type == PacketType.StateSave) return new StateSavePacket(); - if(type == PacketType.ReportAutosaveCrash) return new ReportAutosaveCrashPacket(); - if(type == PacketType.SimWideDeletes) return new SimWideDeletesPacket(); - if(type == PacketType.TrackAgent) return new TrackAgentPacket(); - if(type == PacketType.ViewerStats) return new ViewerStatsPacket(); - if(type == PacketType.ScriptAnswerYes) return new ScriptAnswerYesPacket(); - if(type == PacketType.UserReport) return new UserReportPacket(); - if(type == PacketType.AlertMessage) return new AlertMessagePacket(); - if(type == PacketType.AgentAlertMessage) return new AgentAlertMessagePacket(); - if(type == PacketType.MeanCollisionAlert) return new MeanCollisionAlertPacket(); - if(type == PacketType.ViewerFrozenMessage) return new ViewerFrozenMessagePacket(); - if(type == PacketType.HealthMessage) return new HealthMessagePacket(); - if(type == PacketType.ChatFromSimulator) return new ChatFromSimulatorPacket(); - if(type == PacketType.SimStats) return new SimStatsPacket(); - if(type == PacketType.RequestRegionInfo) return new RequestRegionInfoPacket(); - if(type == PacketType.RegionInfo) return new RegionInfoPacket(); - if(type == PacketType.GodUpdateRegionInfo) return new GodUpdateRegionInfoPacket(); - if(type == PacketType.RegionHandshake) return new RegionHandshakePacket(); - if(type == PacketType.RegionHandshakeReply) return new RegionHandshakeReplyPacket(); - if(type == PacketType.SimulatorViewerTimeMessage) return new SimulatorViewerTimeMessagePacket(); - if(type == PacketType.EnableSimulator) return new EnableSimulatorPacket(); - if(type == PacketType.DisableSimulator) return new DisableSimulatorPacket(); - if(type == PacketType.TransferRequest) return new TransferRequestPacket(); - if(type == PacketType.TransferInfo) return new TransferInfoPacket(); - if(type == PacketType.TransferAbort) return new TransferAbortPacket(); - if(type == PacketType.RequestXfer) return new RequestXferPacket(); - if(type == PacketType.AbortXfer) return new AbortXferPacket(); - if(type == PacketType.AvatarAppearance) return new AvatarAppearancePacket(); - if(type == PacketType.SetFollowCamProperties) return new SetFollowCamPropertiesPacket(); - if(type == PacketType.ClearFollowCamProperties) return new ClearFollowCamPropertiesPacket(); - if(type == PacketType.RequestPayPrice) return new RequestPayPricePacket(); - if(type == PacketType.PayPriceReply) return new PayPriceReplyPacket(); - if(type == PacketType.KickUser) return new KickUserPacket(); - if(type == PacketType.GodKickUser) return new GodKickUserPacket(); - if(type == PacketType.EjectUser) return new EjectUserPacket(); - if(type == PacketType.FreezeUser) return new FreezeUserPacket(); - if(type == PacketType.AvatarPropertiesRequest) return new AvatarPropertiesRequestPacket(); - if(type == PacketType.AvatarPropertiesReply) return new AvatarPropertiesReplyPacket(); - if(type == PacketType.AvatarInterestsReply) return new AvatarInterestsReplyPacket(); - if(type == PacketType.AvatarGroupsReply) return new AvatarGroupsReplyPacket(); - if(type == PacketType.AvatarPropertiesUpdate) return new AvatarPropertiesUpdatePacket(); - if(type == PacketType.AvatarInterestsUpdate) return new AvatarInterestsUpdatePacket(); - if(type == PacketType.AvatarNotesReply) return new AvatarNotesReplyPacket(); - if(type == PacketType.AvatarNotesUpdate) return new AvatarNotesUpdatePacket(); - if(type == PacketType.AvatarPicksReply) return new AvatarPicksReplyPacket(); - if(type == PacketType.EventInfoRequest) return new EventInfoRequestPacket(); - if(type == PacketType.EventInfoReply) return new EventInfoReplyPacket(); - if(type == PacketType.EventNotificationAddRequest) return new EventNotificationAddRequestPacket(); - if(type == PacketType.EventNotificationRemoveRequest) return new EventNotificationRemoveRequestPacket(); - if(type == PacketType.EventGodDelete) return new EventGodDeletePacket(); - if(type == PacketType.PickInfoReply) return new PickInfoReplyPacket(); - if(type == PacketType.PickInfoUpdate) return new PickInfoUpdatePacket(); - if(type == PacketType.PickDelete) return new PickDeletePacket(); - if(type == PacketType.PickGodDelete) return new PickGodDeletePacket(); - if(type == PacketType.ScriptQuestion) return new ScriptQuestionPacket(); - if(type == PacketType.ScriptControlChange) return new ScriptControlChangePacket(); - if(type == PacketType.ScriptDialog) return new ScriptDialogPacket(); - if(type == PacketType.ScriptDialogReply) return new ScriptDialogReplyPacket(); - if(type == PacketType.ForceScriptControlRelease) return new ForceScriptControlReleasePacket(); - if(type == PacketType.RevokePermissions) return new RevokePermissionsPacket(); - if(type == PacketType.LoadURL) return new LoadURLPacket(); - if(type == PacketType.ScriptTeleportRequest) return new ScriptTeleportRequestPacket(); - if(type == PacketType.ParcelOverlay) return new ParcelOverlayPacket(); - if(type == PacketType.ParcelPropertiesRequestByID) return new ParcelPropertiesRequestByIDPacket(); - if(type == PacketType.ParcelPropertiesUpdate) return new ParcelPropertiesUpdatePacket(); - if(type == PacketType.ParcelReturnObjects) return new ParcelReturnObjectsPacket(); - if(type == PacketType.ParcelSetOtherCleanTime) return new ParcelSetOtherCleanTimePacket(); - if(type == PacketType.ParcelDisableObjects) return new ParcelDisableObjectsPacket(); - if(type == PacketType.ParcelSelectObjects) return new ParcelSelectObjectsPacket(); - if(type == PacketType.EstateCovenantRequest) return new EstateCovenantRequestPacket(); - if(type == PacketType.EstateCovenantReply) return new EstateCovenantReplyPacket(); - if(type == PacketType.ForceObjectSelect) return new ForceObjectSelectPacket(); - if(type == PacketType.ParcelBuyPass) return new ParcelBuyPassPacket(); - if(type == PacketType.ParcelDeedToGroup) return new ParcelDeedToGroupPacket(); - if(type == PacketType.ParcelReclaim) return new ParcelReclaimPacket(); - if(type == PacketType.ParcelClaim) return new ParcelClaimPacket(); - if(type == PacketType.ParcelJoin) return new ParcelJoinPacket(); - if(type == PacketType.ParcelDivide) return new ParcelDividePacket(); - if(type == PacketType.ParcelRelease) return new ParcelReleasePacket(); - if(type == PacketType.ParcelBuy) return new ParcelBuyPacket(); - if(type == PacketType.ParcelGodForceOwner) return new ParcelGodForceOwnerPacket(); - if(type == PacketType.ParcelAccessListRequest) return new ParcelAccessListRequestPacket(); - if(type == PacketType.ParcelAccessListReply) return new ParcelAccessListReplyPacket(); - if(type == PacketType.ParcelAccessListUpdate) return new ParcelAccessListUpdatePacket(); - if(type == PacketType.ParcelDwellRequest) return new ParcelDwellRequestPacket(); - if(type == PacketType.ParcelDwellReply) return new ParcelDwellReplyPacket(); - if(type == PacketType.ParcelGodMarkAsContent) return new ParcelGodMarkAsContentPacket(); - if(type == PacketType.ViewerStartAuction) return new ViewerStartAuctionPacket(); - if(type == PacketType.UUIDNameRequest) return new UUIDNameRequestPacket(); - if(type == PacketType.UUIDNameReply) return new UUIDNameReplyPacket(); - if(type == PacketType.UUIDGroupNameRequest) return new UUIDGroupNameRequestPacket(); - if(type == PacketType.UUIDGroupNameReply) return new UUIDGroupNameReplyPacket(); - if(type == PacketType.ChildAgentDying) return new ChildAgentDyingPacket(); - if(type == PacketType.ChildAgentUnknown) return new ChildAgentUnknownPacket(); - if(type == PacketType.GetScriptRunning) return new GetScriptRunningPacket(); - if(type == PacketType.ScriptRunningReply) return new ScriptRunningReplyPacket(); - if(type == PacketType.SetScriptRunning) return new SetScriptRunningPacket(); - if(type == PacketType.ScriptReset) return new ScriptResetPacket(); - if(type == PacketType.ScriptSensorRequest) return new ScriptSensorRequestPacket(); - if(type == PacketType.ScriptSensorReply) return new ScriptSensorReplyPacket(); - if(type == PacketType.CompleteAgentMovement) return new CompleteAgentMovementPacket(); - if(type == PacketType.AgentMovementComplete) return new AgentMovementCompletePacket(); - if(type == PacketType.LogoutRequest) return new LogoutRequestPacket(); - if(type == PacketType.LogoutReply) return new LogoutReplyPacket(); - if(type == PacketType.ImprovedInstantMessage) return new ImprovedInstantMessagePacket(); - if(type == PacketType.RetrieveInstantMessages) return new RetrieveInstantMessagesPacket(); - if(type == PacketType.FindAgent) return new FindAgentPacket(); - if(type == PacketType.RequestGodlikePowers) return new RequestGodlikePowersPacket(); - if(type == PacketType.GrantGodlikePowers) return new GrantGodlikePowersPacket(); - if(type == PacketType.GodlikeMessage) return new GodlikeMessagePacket(); - if(type == PacketType.EstateOwnerMessage) return new EstateOwnerMessagePacket(); - if(type == PacketType.GenericMessage) return new GenericMessagePacket(); - if(type == PacketType.MuteListRequest) return new MuteListRequestPacket(); - if(type == PacketType.UpdateMuteListEntry) return new UpdateMuteListEntryPacket(); - if(type == PacketType.RemoveMuteListEntry) return new RemoveMuteListEntryPacket(); - if(type == PacketType.CopyInventoryFromNotecard) return new CopyInventoryFromNotecardPacket(); - if(type == PacketType.UpdateInventoryItem) return new UpdateInventoryItemPacket(); - if(type == PacketType.UpdateCreateInventoryItem) return new UpdateCreateInventoryItemPacket(); - if(type == PacketType.MoveInventoryItem) return new MoveInventoryItemPacket(); - if(type == PacketType.CopyInventoryItem) return new CopyInventoryItemPacket(); - if(type == PacketType.RemoveInventoryItem) return new RemoveInventoryItemPacket(); - if(type == PacketType.ChangeInventoryItemFlags) return new ChangeInventoryItemFlagsPacket(); - if(type == PacketType.SaveAssetIntoInventory) return new SaveAssetIntoInventoryPacket(); - if(type == PacketType.CreateInventoryFolder) return new CreateInventoryFolderPacket(); - if(type == PacketType.UpdateInventoryFolder) return new UpdateInventoryFolderPacket(); - if(type == PacketType.MoveInventoryFolder) return new MoveInventoryFolderPacket(); - if(type == PacketType.RemoveInventoryFolder) return new RemoveInventoryFolderPacket(); - if(type == PacketType.FetchInventoryDescendents) return new FetchInventoryDescendentsPacket(); - if(type == PacketType.InventoryDescendents) return new InventoryDescendentsPacket(); - if(type == PacketType.FetchInventory) return new FetchInventoryPacket(); - if(type == PacketType.FetchInventoryReply) return new FetchInventoryReplyPacket(); - if(type == PacketType.BulkUpdateInventory) return new BulkUpdateInventoryPacket(); - if(type == PacketType.RemoveInventoryObjects) return new RemoveInventoryObjectsPacket(); - if(type == PacketType.PurgeInventoryDescendents) return new PurgeInventoryDescendentsPacket(); - if(type == PacketType.UpdateTaskInventory) return new UpdateTaskInventoryPacket(); - if(type == PacketType.RemoveTaskInventory) return new RemoveTaskInventoryPacket(); - if(type == PacketType.MoveTaskInventory) return new MoveTaskInventoryPacket(); - if(type == PacketType.RequestTaskInventory) return new RequestTaskInventoryPacket(); - if(type == PacketType.ReplyTaskInventory) return new ReplyTaskInventoryPacket(); - if(type == PacketType.DeRezObject) return new DeRezObjectPacket(); - if(type == PacketType.DeRezAck) return new DeRezAckPacket(); - if(type == PacketType.RezObject) return new RezObjectPacket(); - if(type == PacketType.RezObjectFromNotecard) return new RezObjectFromNotecardPacket(); - if(type == PacketType.AcceptFriendship) return new AcceptFriendshipPacket(); - if(type == PacketType.DeclineFriendship) return new DeclineFriendshipPacket(); - if(type == PacketType.TerminateFriendship) return new TerminateFriendshipPacket(); - if(type == PacketType.OfferCallingCard) return new OfferCallingCardPacket(); - if(type == PacketType.AcceptCallingCard) return new AcceptCallingCardPacket(); - if(type == PacketType.DeclineCallingCard) return new DeclineCallingCardPacket(); - if(type == PacketType.RezScript) return new RezScriptPacket(); - if(type == PacketType.CreateInventoryItem) return new CreateInventoryItemPacket(); - if(type == PacketType.CreateLandmarkForEvent) return new CreateLandmarkForEventPacket(); - if(type == PacketType.RegionHandleRequest) return new RegionHandleRequestPacket(); - if(type == PacketType.RegionIDAndHandleReply) return new RegionIDAndHandleReplyPacket(); - if(type == PacketType.MoneyTransferRequest) return new MoneyTransferRequestPacket(); - if(type == PacketType.MoneyBalanceRequest) return new MoneyBalanceRequestPacket(); - if(type == PacketType.MoneyBalanceReply) return new MoneyBalanceReplyPacket(); - if(type == PacketType.RoutedMoneyBalanceReply) return new RoutedMoneyBalanceReplyPacket(); - if(type == PacketType.ActivateGestures) return new ActivateGesturesPacket(); - if(type == PacketType.DeactivateGestures) return new DeactivateGesturesPacket(); - if(type == PacketType.MuteListUpdate) return new MuteListUpdatePacket(); - if(type == PacketType.UseCachedMuteList) return new UseCachedMuteListPacket(); - if(type == PacketType.GrantUserRights) return new GrantUserRightsPacket(); - if(type == PacketType.ChangeUserRights) return new ChangeUserRightsPacket(); - if(type == PacketType.OnlineNotification) return new OnlineNotificationPacket(); - if(type == PacketType.OfflineNotification) return new OfflineNotificationPacket(); - if(type == PacketType.SetStartLocationRequest) return new SetStartLocationRequestPacket(); - if(type == PacketType.AssetUploadRequest) return new AssetUploadRequestPacket(); - if(type == PacketType.AssetUploadComplete) return new AssetUploadCompletePacket(); - if(type == PacketType.CreateGroupRequest) return new CreateGroupRequestPacket(); - if(type == PacketType.CreateGroupReply) return new CreateGroupReplyPacket(); - if(type == PacketType.UpdateGroupInfo) return new UpdateGroupInfoPacket(); - if(type == PacketType.GroupRoleChanges) return new GroupRoleChangesPacket(); - if(type == PacketType.JoinGroupRequest) return new JoinGroupRequestPacket(); - if(type == PacketType.JoinGroupReply) return new JoinGroupReplyPacket(); - if(type == PacketType.EjectGroupMemberRequest) return new EjectGroupMemberRequestPacket(); - if(type == PacketType.EjectGroupMemberReply) return new EjectGroupMemberReplyPacket(); - if(type == PacketType.LeaveGroupRequest) return new LeaveGroupRequestPacket(); - if(type == PacketType.LeaveGroupReply) return new LeaveGroupReplyPacket(); - if(type == PacketType.InviteGroupRequest) return new InviteGroupRequestPacket(); - if(type == PacketType.GroupProfileRequest) return new GroupProfileRequestPacket(); - if(type == PacketType.GroupProfileReply) return new GroupProfileReplyPacket(); - if(type == PacketType.GroupAccountSummaryRequest) return new GroupAccountSummaryRequestPacket(); - if(type == PacketType.GroupAccountSummaryReply) return new GroupAccountSummaryReplyPacket(); - if(type == PacketType.GroupAccountDetailsRequest) return new GroupAccountDetailsRequestPacket(); - if(type == PacketType.GroupAccountDetailsReply) return new GroupAccountDetailsReplyPacket(); - if(type == PacketType.GroupAccountTransactionsRequest) return new GroupAccountTransactionsRequestPacket(); - if(type == PacketType.GroupAccountTransactionsReply) return new GroupAccountTransactionsReplyPacket(); - if(type == PacketType.GroupActiveProposalsRequest) return new GroupActiveProposalsRequestPacket(); - if(type == PacketType.GroupActiveProposalItemReply) return new GroupActiveProposalItemReplyPacket(); - if(type == PacketType.GroupVoteHistoryRequest) return new GroupVoteHistoryRequestPacket(); - if(type == PacketType.GroupVoteHistoryItemReply) return new GroupVoteHistoryItemReplyPacket(); - if(type == PacketType.StartGroupProposal) return new StartGroupProposalPacket(); - if(type == PacketType.GroupProposalBallot) return new GroupProposalBallotPacket(); - if(type == PacketType.GroupMembersRequest) return new GroupMembersRequestPacket(); - if(type == PacketType.GroupMembersReply) return new GroupMembersReplyPacket(); - if(type == PacketType.ActivateGroup) return new ActivateGroupPacket(); - if(type == PacketType.SetGroupContribution) return new SetGroupContributionPacket(); - if(type == PacketType.SetGroupAcceptNotices) return new SetGroupAcceptNoticesPacket(); - if(type == PacketType.GroupRoleDataRequest) return new GroupRoleDataRequestPacket(); - if(type == PacketType.GroupRoleDataReply) return new GroupRoleDataReplyPacket(); - if(type == PacketType.GroupRoleMembersRequest) return new GroupRoleMembersRequestPacket(); - if(type == PacketType.GroupRoleMembersReply) return new GroupRoleMembersReplyPacket(); - if(type == PacketType.GroupTitlesRequest) return new GroupTitlesRequestPacket(); - if(type == PacketType.GroupTitlesReply) return new GroupTitlesReplyPacket(); - if(type == PacketType.GroupTitleUpdate) return new GroupTitleUpdatePacket(); - if(type == PacketType.GroupRoleUpdate) return new GroupRoleUpdatePacket(); - if(type == PacketType.LiveHelpGroupRequest) return new LiveHelpGroupRequestPacket(); - if(type == PacketType.LiveHelpGroupReply) return new LiveHelpGroupReplyPacket(); - if(type == PacketType.AgentWearablesRequest) return new AgentWearablesRequestPacket(); - if(type == PacketType.AgentWearablesUpdate) return new AgentWearablesUpdatePacket(); - if(type == PacketType.AgentIsNowWearing) return new AgentIsNowWearingPacket(); - if(type == PacketType.AgentCachedTexture) return new AgentCachedTexturePacket(); - if(type == PacketType.AgentCachedTextureResponse) return new AgentCachedTextureResponsePacket(); - if(type == PacketType.AgentDataUpdateRequest) return new AgentDataUpdateRequestPacket(); - if(type == PacketType.AgentDataUpdate) return new AgentDataUpdatePacket(); - if(type == PacketType.GroupDataUpdate) return new GroupDataUpdatePacket(); - if(type == PacketType.AgentGroupDataUpdate) return new AgentGroupDataUpdatePacket(); - if(type == PacketType.AgentDropGroup) return new AgentDropGroupPacket(); - if(type == PacketType.RezSingleAttachmentFromInv) return new RezSingleAttachmentFromInvPacket(); - if(type == PacketType.RezMultipleAttachmentsFromInv) return new RezMultipleAttachmentsFromInvPacket(); - if(type == PacketType.DetachAttachmentIntoInv) return new DetachAttachmentIntoInvPacket(); - if(type == PacketType.CreateNewOutfitAttachments) return new CreateNewOutfitAttachmentsPacket(); - if(type == PacketType.UserInfoRequest) return new UserInfoRequestPacket(); - if(type == PacketType.UserInfoReply) return new UserInfoReplyPacket(); - if(type == PacketType.UpdateUserInfo) return new UpdateUserInfoPacket(); - if(type == PacketType.InitiateDownload) return new InitiateDownloadPacket(); - if(type == PacketType.MapLayerRequest) return new MapLayerRequestPacket(); - if(type == PacketType.MapLayerReply) return new MapLayerReplyPacket(); - if(type == PacketType.MapBlockRequest) return new MapBlockRequestPacket(); - if(type == PacketType.MapNameRequest) return new MapNameRequestPacket(); - if(type == PacketType.MapBlockReply) return new MapBlockReplyPacket(); - if(type == PacketType.MapItemRequest) return new MapItemRequestPacket(); - if(type == PacketType.MapItemReply) return new MapItemReplyPacket(); - if(type == PacketType.SendPostcard) return new SendPostcardPacket(); - if(type == PacketType.ParcelMediaCommandMessage) return new ParcelMediaCommandMessagePacket(); - if(type == PacketType.ParcelMediaUpdate) return new ParcelMediaUpdatePacket(); - if(type == PacketType.LandStatRequest) return new LandStatRequestPacket(); - if(type == PacketType.LandStatReply) return new LandStatReplyPacket(); - if(type == PacketType.Error) return new ErrorPacket(); - if(type == PacketType.ObjectIncludeInSearch) return new ObjectIncludeInSearchPacket(); - if(type == PacketType.RezRestoreToWorld) return new RezRestoreToWorldPacket(); - if(type == PacketType.LinkInventoryItem) return new LinkInventoryItemPacket(); - if(type == PacketType.RetrieveIMsExtended) return new RetrieveIMsExtendedPacket(); - if(type == PacketType.JoinGroupRequestExtended) return new JoinGroupRequestExtendedPacket(); - if(type == PacketType.CreateGroupRequestExtended) return new CreateGroupRequestExtendedPacket(); - if(type == PacketType.PacketAck) return new PacketAckPacket(); - if(type == PacketType.OpenCircuit) return new OpenCircuitPacket(); - if(type == PacketType.CloseCircuit) return new CloseCircuitPacket(); - return null; - - } - - public static Packet BuildPacket(byte[] packetBuffer, ref int packetEnd, byte[] zeroBuffer) - { - byte[] bytes; - int i = 0; - Header header = Header.BuildHeader(packetBuffer, ref i, ref packetEnd); - if (header.Zerocoded) - { - packetEnd = Helpers.ZeroDecode(packetBuffer, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - else - { - bytes = packetBuffer; - } - Array.Clear(bytes, packetEnd + 1, bytes.Length - packetEnd - 1); - - switch (header.Frequency) - { - case PacketFrequency.Low: - switch (header.ID) - { - case 1: return new TestMessagePacket(header, bytes, ref i); - case 3: return new UseCircuitCodePacket(header, bytes, ref i); - case 10: return new TelehubInfoPacket(header, bytes, ref i); - case 24: return new EconomyDataRequestPacket(header, bytes, ref i); - case 25: return new EconomyDataPacket(header, bytes, ref i); - case 26: return new AvatarPickerRequestPacket(header, bytes, ref i); - case 28: return new AvatarPickerReplyPacket(header, bytes, ref i); - case 29: return new PlacesQueryPacket(header, bytes, ref i); - case 30: return new PlacesReplyPacket(header, bytes, ref i); - case 31: return new DirFindQueryPacket(header, bytes, ref i); - case 33: return new DirPlacesQueryPacket(header, bytes, ref i); - case 35: return new DirPlacesReplyPacket(header, bytes, ref i); - case 36: return new DirPeopleReplyPacket(header, bytes, ref i); - case 37: return new DirEventsReplyPacket(header, bytes, ref i); - case 38: return new DirGroupsReplyPacket(header, bytes, ref i); - case 39: return new DirClassifiedQueryPacket(header, bytes, ref i); - case 41: return new DirClassifiedReplyPacket(header, bytes, ref i); - case 42: return new AvatarClassifiedReplyPacket(header, bytes, ref i); - case 43: return new ClassifiedInfoRequestPacket(header, bytes, ref i); - case 44: return new ClassifiedInfoReplyPacket(header, bytes, ref i); - case 45: return new ClassifiedInfoUpdatePacket(header, bytes, ref i); - case 46: return new ClassifiedDeletePacket(header, bytes, ref i); - case 47: return new ClassifiedGodDeletePacket(header, bytes, ref i); - case 48: return new DirLandQueryPacket(header, bytes, ref i); - case 50: return new DirLandReplyPacket(header, bytes, ref i); - case 51: return new DirPopularQueryPacket(header, bytes, ref i); - case 53: return new DirPopularReplyPacket(header, bytes, ref i); - case 54: return new ParcelInfoRequestPacket(header, bytes, ref i); - case 55: return new ParcelInfoReplyPacket(header, bytes, ref i); - case 56: return new ParcelObjectOwnersRequestPacket(header, bytes, ref i); - case 57: return new ParcelObjectOwnersReplyPacket(header, bytes, ref i); - case 58: return new GroupNoticesListRequestPacket(header, bytes, ref i); - case 59: return new GroupNoticesListReplyPacket(header, bytes, ref i); - case 60: return new GroupNoticeRequestPacket(header, bytes, ref i); - case 62: return new TeleportRequestPacket(header, bytes, ref i); - case 63: return new TeleportLocationRequestPacket(header, bytes, ref i); - case 64: return new TeleportLocalPacket(header, bytes, ref i); - case 65: return new TeleportLandmarkRequestPacket(header, bytes, ref i); - case 66: return new TeleportProgressPacket(header, bytes, ref i); - case 69: return new TeleportFinishPacket(header, bytes, ref i); - case 70: return new StartLurePacket(header, bytes, ref i); - case 71: return new TeleportLureRequestPacket(header, bytes, ref i); - case 72: return new TeleportCancelPacket(header, bytes, ref i); - case 73: return new TeleportStartPacket(header, bytes, ref i); - case 74: return new TeleportFailedPacket(header, bytes, ref i); - case 75: return new UndoPacket(header, bytes, ref i); - case 76: return new RedoPacket(header, bytes, ref i); - case 77: return new UndoLandPacket(header, bytes, ref i); - case 78: return new AgentPausePacket(header, bytes, ref i); - case 79: return new AgentResumePacket(header, bytes, ref i); - case 80: return new ChatFromViewerPacket(header, bytes, ref i); - case 81: return new AgentThrottlePacket(header, bytes, ref i); - case 82: return new AgentFOVPacket(header, bytes, ref i); - case 83: return new AgentHeightWidthPacket(header, bytes, ref i); - case 84: return new AgentSetAppearancePacket(header, bytes, ref i); - case 85: return new AgentQuitCopyPacket(header, bytes, ref i); - case 86: return new ImageNotInDatabasePacket(header, bytes, ref i); - case 87: return new RebakeAvatarTexturesPacket(header, bytes, ref i); - case 88: return new SetAlwaysRunPacket(header, bytes, ref i); - case 89: return new ObjectDeletePacket(header, bytes, ref i); - case 90: return new ObjectDuplicatePacket(header, bytes, ref i); - case 91: return new ObjectDuplicateOnRayPacket(header, bytes, ref i); - case 92: return new ObjectScalePacket(header, bytes, ref i); - case 93: return new ObjectRotationPacket(header, bytes, ref i); - case 94: return new ObjectFlagUpdatePacket(header, bytes, ref i); - case 95: return new ObjectClickActionPacket(header, bytes, ref i); - case 96: return new ObjectImagePacket(header, bytes, ref i); - case 97: return new ObjectMaterialPacket(header, bytes, ref i); - case 98: return new ObjectShapePacket(header, bytes, ref i); - case 99: return new ObjectExtraParamsPacket(header, bytes, ref i); - case 100: return new ObjectOwnerPacket(header, bytes, ref i); - case 101: return new ObjectGroupPacket(header, bytes, ref i); - case 102: return new ObjectBuyPacket(header, bytes, ref i); - case 103: return new BuyObjectInventoryPacket(header, bytes, ref i); - case 104: return new DerezContainerPacket(header, bytes, ref i); - case 105: return new ObjectPermissionsPacket(header, bytes, ref i); - case 106: return new ObjectSaleInfoPacket(header, bytes, ref i); - case 107: return new ObjectNamePacket(header, bytes, ref i); - case 108: return new ObjectDescriptionPacket(header, bytes, ref i); - case 109: return new ObjectCategoryPacket(header, bytes, ref i); - case 110: return new ObjectSelectPacket(header, bytes, ref i); - case 111: return new ObjectDeselectPacket(header, bytes, ref i); - case 112: return new ObjectAttachPacket(header, bytes, ref i); - case 113: return new ObjectDetachPacket(header, bytes, ref i); - case 114: return new ObjectDropPacket(header, bytes, ref i); - case 115: return new ObjectLinkPacket(header, bytes, ref i); - case 116: return new ObjectDelinkPacket(header, bytes, ref i); - case 117: return new ObjectGrabPacket(header, bytes, ref i); - case 118: return new ObjectGrabUpdatePacket(header, bytes, ref i); - case 119: return new ObjectDeGrabPacket(header, bytes, ref i); - case 120: return new ObjectSpinStartPacket(header, bytes, ref i); - case 121: return new ObjectSpinUpdatePacket(header, bytes, ref i); - case 122: return new ObjectSpinStopPacket(header, bytes, ref i); - case 123: return new ObjectExportSelectedPacket(header, bytes, ref i); - case 124: return new ModifyLandPacket(header, bytes, ref i); - case 125: return new VelocityInterpolateOnPacket(header, bytes, ref i); - case 126: return new VelocityInterpolateOffPacket(header, bytes, ref i); - case 127: return new StateSavePacket(header, bytes, ref i); - case 128: return new ReportAutosaveCrashPacket(header, bytes, ref i); - case 129: return new SimWideDeletesPacket(header, bytes, ref i); - case 130: return new TrackAgentPacket(header, bytes, ref i); - case 131: return new ViewerStatsPacket(header, bytes, ref i); - case 132: return new ScriptAnswerYesPacket(header, bytes, ref i); - case 133: return new UserReportPacket(header, bytes, ref i); - case 134: return new AlertMessagePacket(header, bytes, ref i); - case 135: return new AgentAlertMessagePacket(header, bytes, ref i); - case 136: return new MeanCollisionAlertPacket(header, bytes, ref i); - case 137: return new ViewerFrozenMessagePacket(header, bytes, ref i); - case 138: return new HealthMessagePacket(header, bytes, ref i); - case 139: return new ChatFromSimulatorPacket(header, bytes, ref i); - case 140: return new SimStatsPacket(header, bytes, ref i); - case 141: return new RequestRegionInfoPacket(header, bytes, ref i); - case 142: return new RegionInfoPacket(header, bytes, ref i); - case 143: return new GodUpdateRegionInfoPacket(header, bytes, ref i); - case 148: return new RegionHandshakePacket(header, bytes, ref i); - case 149: return new RegionHandshakeReplyPacket(header, bytes, ref i); - case 150: return new SimulatorViewerTimeMessagePacket(header, bytes, ref i); - case 151: return new EnableSimulatorPacket(header, bytes, ref i); - case 152: return new DisableSimulatorPacket(header, bytes, ref i); - case 153: return new TransferRequestPacket(header, bytes, ref i); - case 154: return new TransferInfoPacket(header, bytes, ref i); - case 155: return new TransferAbortPacket(header, bytes, ref i); - case 156: return new RequestXferPacket(header, bytes, ref i); - case 157: return new AbortXferPacket(header, bytes, ref i); - case 158: return new AvatarAppearancePacket(header, bytes, ref i); - case 159: return new SetFollowCamPropertiesPacket(header, bytes, ref i); - case 160: return new ClearFollowCamPropertiesPacket(header, bytes, ref i); - case 161: return new RequestPayPricePacket(header, bytes, ref i); - case 162: return new PayPriceReplyPacket(header, bytes, ref i); - case 163: return new KickUserPacket(header, bytes, ref i); - case 165: return new GodKickUserPacket(header, bytes, ref i); - case 167: return new EjectUserPacket(header, bytes, ref i); - case 168: return new FreezeUserPacket(header, bytes, ref i); - case 169: return new AvatarPropertiesRequestPacket(header, bytes, ref i); - case 171: return new AvatarPropertiesReplyPacket(header, bytes, ref i); - case 172: return new AvatarInterestsReplyPacket(header, bytes, ref i); - case 173: return new AvatarGroupsReplyPacket(header, bytes, ref i); - case 174: return new AvatarPropertiesUpdatePacket(header, bytes, ref i); - case 175: return new AvatarInterestsUpdatePacket(header, bytes, ref i); - case 176: return new AvatarNotesReplyPacket(header, bytes, ref i); - case 177: return new AvatarNotesUpdatePacket(header, bytes, ref i); - case 178: return new AvatarPicksReplyPacket(header, bytes, ref i); - case 179: return new EventInfoRequestPacket(header, bytes, ref i); - case 180: return new EventInfoReplyPacket(header, bytes, ref i); - case 181: return new EventNotificationAddRequestPacket(header, bytes, ref i); - case 182: return new EventNotificationRemoveRequestPacket(header, bytes, ref i); - case 183: return new EventGodDeletePacket(header, bytes, ref i); - case 184: return new PickInfoReplyPacket(header, bytes, ref i); - case 185: return new PickInfoUpdatePacket(header, bytes, ref i); - case 186: return new PickDeletePacket(header, bytes, ref i); - case 187: return new PickGodDeletePacket(header, bytes, ref i); - case 188: return new ScriptQuestionPacket(header, bytes, ref i); - case 189: return new ScriptControlChangePacket(header, bytes, ref i); - case 190: return new ScriptDialogPacket(header, bytes, ref i); - case 191: return new ScriptDialogReplyPacket(header, bytes, ref i); - case 192: return new ForceScriptControlReleasePacket(header, bytes, ref i); - case 193: return new RevokePermissionsPacket(header, bytes, ref i); - case 194: return new LoadURLPacket(header, bytes, ref i); - case 195: return new ScriptTeleportRequestPacket(header, bytes, ref i); - case 196: return new ParcelOverlayPacket(header, bytes, ref i); - case 197: return new ParcelPropertiesRequestByIDPacket(header, bytes, ref i); - case 198: return new ParcelPropertiesUpdatePacket(header, bytes, ref i); - case 199: return new ParcelReturnObjectsPacket(header, bytes, ref i); - case 200: return new ParcelSetOtherCleanTimePacket(header, bytes, ref i); - case 201: return new ParcelDisableObjectsPacket(header, bytes, ref i); - case 202: return new ParcelSelectObjectsPacket(header, bytes, ref i); - case 203: return new EstateCovenantRequestPacket(header, bytes, ref i); - case 204: return new EstateCovenantReplyPacket(header, bytes, ref i); - case 205: return new ForceObjectSelectPacket(header, bytes, ref i); - case 206: return new ParcelBuyPassPacket(header, bytes, ref i); - case 207: return new ParcelDeedToGroupPacket(header, bytes, ref i); - case 208: return new ParcelReclaimPacket(header, bytes, ref i); - case 209: return new ParcelClaimPacket(header, bytes, ref i); - case 210: return new ParcelJoinPacket(header, bytes, ref i); - case 211: return new ParcelDividePacket(header, bytes, ref i); - case 212: return new ParcelReleasePacket(header, bytes, ref i); - case 213: return new ParcelBuyPacket(header, bytes, ref i); - case 214: return new ParcelGodForceOwnerPacket(header, bytes, ref i); - case 215: return new ParcelAccessListRequestPacket(header, bytes, ref i); - case 216: return new ParcelAccessListReplyPacket(header, bytes, ref i); - case 217: return new ParcelAccessListUpdatePacket(header, bytes, ref i); - case 218: return new ParcelDwellRequestPacket(header, bytes, ref i); - case 219: return new ParcelDwellReplyPacket(header, bytes, ref i); - case 227: return new ParcelGodMarkAsContentPacket(header, bytes, ref i); - case 228: return new ViewerStartAuctionPacket(header, bytes, ref i); - case 235: return new UUIDNameRequestPacket(header, bytes, ref i); - case 236: return new UUIDNameReplyPacket(header, bytes, ref i); - case 237: return new UUIDGroupNameRequestPacket(header, bytes, ref i); - case 238: return new UUIDGroupNameReplyPacket(header, bytes, ref i); - case 240: return new ChildAgentDyingPacket(header, bytes, ref i); - case 241: return new ChildAgentUnknownPacket(header, bytes, ref i); - case 243: return new GetScriptRunningPacket(header, bytes, ref i); - case 244: return new ScriptRunningReplyPacket(header, bytes, ref i); - case 245: return new SetScriptRunningPacket(header, bytes, ref i); - case 246: return new ScriptResetPacket(header, bytes, ref i); - case 247: return new ScriptSensorRequestPacket(header, bytes, ref i); - case 248: return new ScriptSensorReplyPacket(header, bytes, ref i); - case 249: return new CompleteAgentMovementPacket(header, bytes, ref i); - case 250: return new AgentMovementCompletePacket(header, bytes, ref i); - case 252: return new LogoutRequestPacket(header, bytes, ref i); - case 253: return new LogoutReplyPacket(header, bytes, ref i); - case 254: return new ImprovedInstantMessagePacket(header, bytes, ref i); - case 255: return new RetrieveInstantMessagesPacket(header, bytes, ref i); - case 256: return new FindAgentPacket(header, bytes, ref i); - case 257: return new RequestGodlikePowersPacket(header, bytes, ref i); - case 258: return new GrantGodlikePowersPacket(header, bytes, ref i); - case 259: return new GodlikeMessagePacket(header, bytes, ref i); - case 260: return new EstateOwnerMessagePacket(header, bytes, ref i); - case 261: return new GenericMessagePacket(header, bytes, ref i); - case 262: return new MuteListRequestPacket(header, bytes, ref i); - case 263: return new UpdateMuteListEntryPacket(header, bytes, ref i); - case 264: return new RemoveMuteListEntryPacket(header, bytes, ref i); - case 265: return new CopyInventoryFromNotecardPacket(header, bytes, ref i); - case 266: return new UpdateInventoryItemPacket(header, bytes, ref i); - case 267: return new UpdateCreateInventoryItemPacket(header, bytes, ref i); - case 268: return new MoveInventoryItemPacket(header, bytes, ref i); - case 269: return new CopyInventoryItemPacket(header, bytes, ref i); - case 270: return new RemoveInventoryItemPacket(header, bytes, ref i); - case 271: return new ChangeInventoryItemFlagsPacket(header, bytes, ref i); - case 272: return new SaveAssetIntoInventoryPacket(header, bytes, ref i); - case 273: return new CreateInventoryFolderPacket(header, bytes, ref i); - case 274: return new UpdateInventoryFolderPacket(header, bytes, ref i); - case 275: return new MoveInventoryFolderPacket(header, bytes, ref i); - case 276: return new RemoveInventoryFolderPacket(header, bytes, ref i); - case 277: return new FetchInventoryDescendentsPacket(header, bytes, ref i); - case 278: return new InventoryDescendentsPacket(header, bytes, ref i); - case 279: return new FetchInventoryPacket(header, bytes, ref i); - case 280: return new FetchInventoryReplyPacket(header, bytes, ref i); - case 281: return new BulkUpdateInventoryPacket(header, bytes, ref i); - case 284: return new RemoveInventoryObjectsPacket(header, bytes, ref i); - case 285: return new PurgeInventoryDescendentsPacket(header, bytes, ref i); - case 286: return new UpdateTaskInventoryPacket(header, bytes, ref i); - case 287: return new RemoveTaskInventoryPacket(header, bytes, ref i); - case 288: return new MoveTaskInventoryPacket(header, bytes, ref i); - case 289: return new RequestTaskInventoryPacket(header, bytes, ref i); - case 290: return new ReplyTaskInventoryPacket(header, bytes, ref i); - case 291: return new DeRezObjectPacket(header, bytes, ref i); - case 292: return new DeRezAckPacket(header, bytes, ref i); - case 293: return new RezObjectPacket(header, bytes, ref i); - case 294: return new RezObjectFromNotecardPacket(header, bytes, ref i); - case 297: return new AcceptFriendshipPacket(header, bytes, ref i); - case 298: return new DeclineFriendshipPacket(header, bytes, ref i); - case 300: return new TerminateFriendshipPacket(header, bytes, ref i); - case 301: return new OfferCallingCardPacket(header, bytes, ref i); - case 302: return new AcceptCallingCardPacket(header, bytes, ref i); - case 303: return new DeclineCallingCardPacket(header, bytes, ref i); - case 304: return new RezScriptPacket(header, bytes, ref i); - case 305: return new CreateInventoryItemPacket(header, bytes, ref i); - case 306: return new CreateLandmarkForEventPacket(header, bytes, ref i); - case 309: return new RegionHandleRequestPacket(header, bytes, ref i); - case 310: return new RegionIDAndHandleReplyPacket(header, bytes, ref i); - case 311: return new MoneyTransferRequestPacket(header, bytes, ref i); - case 313: return new MoneyBalanceRequestPacket(header, bytes, ref i); - case 314: return new MoneyBalanceReplyPacket(header, bytes, ref i); - case 315: return new RoutedMoneyBalanceReplyPacket(header, bytes, ref i); - case 316: return new ActivateGesturesPacket(header, bytes, ref i); - case 317: return new DeactivateGesturesPacket(header, bytes, ref i); - case 318: return new MuteListUpdatePacket(header, bytes, ref i); - case 319: return new UseCachedMuteListPacket(header, bytes, ref i); - case 320: return new GrantUserRightsPacket(header, bytes, ref i); - case 321: return new ChangeUserRightsPacket(header, bytes, ref i); - case 322: return new OnlineNotificationPacket(header, bytes, ref i); - case 323: return new OfflineNotificationPacket(header, bytes, ref i); - case 324: return new SetStartLocationRequestPacket(header, bytes, ref i); - case 333: return new AssetUploadRequestPacket(header, bytes, ref i); - case 334: return new AssetUploadCompletePacket(header, bytes, ref i); - case 339: return new CreateGroupRequestPacket(header, bytes, ref i); - case 340: return new CreateGroupReplyPacket(header, bytes, ref i); - case 341: return new UpdateGroupInfoPacket(header, bytes, ref i); - case 342: return new GroupRoleChangesPacket(header, bytes, ref i); - case 343: return new JoinGroupRequestPacket(header, bytes, ref i); - case 344: return new JoinGroupReplyPacket(header, bytes, ref i); - case 345: return new EjectGroupMemberRequestPacket(header, bytes, ref i); - case 346: return new EjectGroupMemberReplyPacket(header, bytes, ref i); - case 347: return new LeaveGroupRequestPacket(header, bytes, ref i); - case 348: return new LeaveGroupReplyPacket(header, bytes, ref i); - case 349: return new InviteGroupRequestPacket(header, bytes, ref i); - case 351: return new GroupProfileRequestPacket(header, bytes, ref i); - case 352: return new GroupProfileReplyPacket(header, bytes, ref i); - case 353: return new GroupAccountSummaryRequestPacket(header, bytes, ref i); - case 354: return new GroupAccountSummaryReplyPacket(header, bytes, ref i); - case 355: return new GroupAccountDetailsRequestPacket(header, bytes, ref i); - case 356: return new GroupAccountDetailsReplyPacket(header, bytes, ref i); - case 357: return new GroupAccountTransactionsRequestPacket(header, bytes, ref i); - case 358: return new GroupAccountTransactionsReplyPacket(header, bytes, ref i); - case 359: return new GroupActiveProposalsRequestPacket(header, bytes, ref i); - case 360: return new GroupActiveProposalItemReplyPacket(header, bytes, ref i); - case 361: return new GroupVoteHistoryRequestPacket(header, bytes, ref i); - case 362: return new GroupVoteHistoryItemReplyPacket(header, bytes, ref i); - case 363: return new StartGroupProposalPacket(header, bytes, ref i); - case 364: return new GroupProposalBallotPacket(header, bytes, ref i); - case 366: return new GroupMembersRequestPacket(header, bytes, ref i); - case 367: return new GroupMembersReplyPacket(header, bytes, ref i); - case 368: return new ActivateGroupPacket(header, bytes, ref i); - case 369: return new SetGroupContributionPacket(header, bytes, ref i); - case 370: return new SetGroupAcceptNoticesPacket(header, bytes, ref i); - case 371: return new GroupRoleDataRequestPacket(header, bytes, ref i); - case 372: return new GroupRoleDataReplyPacket(header, bytes, ref i); - case 373: return new GroupRoleMembersRequestPacket(header, bytes, ref i); - case 374: return new GroupRoleMembersReplyPacket(header, bytes, ref i); - case 375: return new GroupTitlesRequestPacket(header, bytes, ref i); - case 376: return new GroupTitlesReplyPacket(header, bytes, ref i); - case 377: return new GroupTitleUpdatePacket(header, bytes, ref i); - case 378: return new GroupRoleUpdatePacket(header, bytes, ref i); - case 379: return new LiveHelpGroupRequestPacket(header, bytes, ref i); - case 380: return new LiveHelpGroupReplyPacket(header, bytes, ref i); - case 381: return new AgentWearablesRequestPacket(header, bytes, ref i); - case 382: return new AgentWearablesUpdatePacket(header, bytes, ref i); - case 383: return new AgentIsNowWearingPacket(header, bytes, ref i); - case 384: return new AgentCachedTexturePacket(header, bytes, ref i); - case 385: return new AgentCachedTextureResponsePacket(header, bytes, ref i); - case 386: return new AgentDataUpdateRequestPacket(header, bytes, ref i); - case 387: return new AgentDataUpdatePacket(header, bytes, ref i); - case 388: return new GroupDataUpdatePacket(header, bytes, ref i); - case 389: return new AgentGroupDataUpdatePacket(header, bytes, ref i); - case 390: return new AgentDropGroupPacket(header, bytes, ref i); - case 395: return new RezSingleAttachmentFromInvPacket(header, bytes, ref i); - case 396: return new RezMultipleAttachmentsFromInvPacket(header, bytes, ref i); - case 397: return new DetachAttachmentIntoInvPacket(header, bytes, ref i); - case 398: return new CreateNewOutfitAttachmentsPacket(header, bytes, ref i); - case 399: return new UserInfoRequestPacket(header, bytes, ref i); - case 400: return new UserInfoReplyPacket(header, bytes, ref i); - case 401: return new UpdateUserInfoPacket(header, bytes, ref i); - case 403: return new InitiateDownloadPacket(header, bytes, ref i); - case 405: return new MapLayerRequestPacket(header, bytes, ref i); - case 406: return new MapLayerReplyPacket(header, bytes, ref i); - case 407: return new MapBlockRequestPacket(header, bytes, ref i); - case 408: return new MapNameRequestPacket(header, bytes, ref i); - case 409: return new MapBlockReplyPacket(header, bytes, ref i); - case 410: return new MapItemRequestPacket(header, bytes, ref i); - case 411: return new MapItemReplyPacket(header, bytes, ref i); - case 412: return new SendPostcardPacket(header, bytes, ref i); - case 419: return new ParcelMediaCommandMessagePacket(header, bytes, ref i); - case 420: return new ParcelMediaUpdatePacket(header, bytes, ref i); - case 421: return new LandStatRequestPacket(header, bytes, ref i); - case 422: return new LandStatReplyPacket(header, bytes, ref i); - case 423: return new ErrorPacket(header, bytes, ref i); - case 424: return new ObjectIncludeInSearchPacket(header, bytes, ref i); - case 425: return new RezRestoreToWorldPacket(header, bytes, ref i); - case 426: return new LinkInventoryItemPacket(header, bytes, ref i); - case 427: return new RetrieveIMsExtendedPacket(header, bytes, ref i); - case 428: return new JoinGroupRequestExtendedPacket(header, bytes, ref i); - case 429: return new CreateGroupRequestExtendedPacket(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); - - } - break; - case PacketFrequency.Medium: - switch (header.ID) - { - case 1: return new ObjectAddPacket(header, bytes, ref i); - case 2: return new MultipleObjectUpdatePacket(header, bytes, ref i); - case 3: return new RequestMultipleObjectsPacket(header, bytes, ref i); - case 4: return new ObjectPositionPacket(header, bytes, ref i); - case 5: return new RequestObjectPropertiesFamilyPacket(header, bytes, ref i); - case 6: return new CoarseLocationUpdatePacket(header, bytes, ref i); - case 7: return new CrossedRegionPacket(header, bytes, ref i); - case 8: return new ConfirmEnableSimulatorPacket(header, bytes, ref i); - case 9: return new ObjectPropertiesPacket(header, bytes, ref i); - case 10: return new ObjectPropertiesFamilyPacket(header, bytes, ref i); - case 11: return new ParcelPropertiesRequestPacket(header, bytes, ref i); - case 13: return new AttachedSoundPacket(header, bytes, ref i); - case 14: return new AttachedSoundGainChangePacket(header, bytes, ref i); - case 15: return new PreloadSoundPacket(header, bytes, ref i); - case 17: return new ViewerEffectPacket(header, bytes, ref i); - - } - break; - case PacketFrequency.High: - switch (header.ID) - { - case 1: return new StartPingCheckPacket(header, bytes, ref i); - case 2: return new CompletePingCheckPacket(header, bytes, ref i); - case 4: return new AgentUpdatePacket(header, bytes, ref i); - case 5: return new AgentAnimationPacket(header, bytes, ref i); - case 6: return new AgentRequestSitPacket(header, bytes, ref i); - case 7: return new AgentSitPacket(header, bytes, ref i); - case 8: return new RequestImagePacket(header, bytes, ref i); - case 9: return new ImageDataPacket(header, bytes, ref i); - case 10: return new ImagePacketPacket(header, bytes, ref i); - case 11: return new LayerDataPacket(header, bytes, ref i); - case 12: return new ObjectUpdatePacket(header, bytes, ref i); - case 13: return new ObjectUpdateCompressedPacket(header, bytes, ref i); - case 14: return new ObjectUpdateCachedPacket(header, bytes, ref i); - case 15: return new ImprovedTerseObjectUpdatePacket(header, bytes, ref i); - case 16: return new KillObjectPacket(header, bytes, ref i); - case 17: return new TransferPacketPacket(header, bytes, ref i); - case 18: return new SendXferPacketPacket(header, bytes, ref i); - case 19: return new ConfirmXferPacketPacket(header, bytes, ref i); - case 20: return new AvatarAnimationPacket(header, bytes, ref i); - case 21: return new AvatarSitResponsePacket(header, bytes, ref i); - case 22: return new CameraConstraintPacket(header, bytes, ref i); - case 23: return new ParcelPropertiesPacket(header, bytes, ref i); - case 25: return new ChildAgentUpdatePacket(header, bytes, ref i); - case 26: return new ChildAgentAlivePacket(header, bytes, ref i); - case 27: return new ChildAgentPositionUpdatePacket(header, bytes, ref i); - case 29: return new SoundTriggerPacket(header, bytes, ref i); - case 30: return new ObjectAnimationPacket(header, bytes, ref i); - - } - break; - } - - throw new MalformedDataException("Unknown packet ID " + header.Frequency + " " + header.ID); - } - } - /// - public sealed class TestMessagePacket : Packet - { - /// - public sealed class TestBlock1Block : PacketBlock - { - public uint Test1; - - public override int Length - { - get - { - return 4; - } - } - - public TestBlock1Block() { } - public TestBlock1Block(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - Test1 = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UIntToBytes(Test1, bytes, i); i += 4; - } - - } - - /// - public sealed class NeighborBlockBlock : PacketBlock - { - public uint Test0; - public uint Test1; - public uint Test2; - - public override int Length - { - get - { - return 12; - } - } - - public NeighborBlockBlock() { } - public NeighborBlockBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(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(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UIntToBytes(Test0, bytes, i); i += 4; - Utils.UIntToBytes(Test1, bytes, i); i += 4; - Utils.UIntToBytes(Test2, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 10; - length += TestBlock1.Length; - for (int j = 0; j < 4; j++) - length += NeighborBlock[j].Length; - return length; - } - } - public TestBlock1Block TestBlock1; - public NeighborBlockBlock[] NeighborBlock; - - public TestMessagePacket() - { - HasVariableBlocks = false; - Type = PacketType.TestMessage; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 1; - Header.Reliable = true; - Header.Zerocoded = true; - TestBlock1 = new TestBlock1Block(); - NeighborBlock = new NeighborBlockBlock[4]; - } - - public TestMessagePacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - TestBlock1.FromBytes(bytes, ref i); - if(NeighborBlock == null || NeighborBlock.Length != 4) { - NeighborBlock = new NeighborBlockBlock[4]; - for(int j = 0; j < 4; j++) - { NeighborBlock[j] = new NeighborBlockBlock(); } - } - for (int j = 0; j < 4; j++) - { NeighborBlock[j].FromBytes(bytes, ref i); } - } - - public TestMessagePacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - TestBlock1.FromBytes(bytes, ref i); - if(NeighborBlock == null || NeighborBlock.Length != 4) { - NeighborBlock = new NeighborBlockBlock[4]; - for(int j = 0; j < 4; j++) - { NeighborBlock[j] = new NeighborBlockBlock(); } - } - for (int j = 0; j < 4; j++) - { NeighborBlock[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += TestBlock1.Length; - for (int j = 0; j < 4; j++) { length += NeighborBlock[j].Length; } - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class UseCircuitCodePacket : Packet - { - /// - public sealed class CircuitCodeBlock : PacketBlock - { - public uint Code; - public UUID SessionID; - public UUID ID; - - public override int Length - { - get - { - return 36; - } - } - - public CircuitCodeBlock() { } - public CircuitCodeBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - Code = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - SessionID.FromBytes(bytes, i); i += 16; - ID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UIntToBytes(Code, bytes, i); i += 4; - SessionID.ToBytes(bytes, i); i += 16; - ID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 10; - length += CircuitCode.Length; - return length; - } - } - public CircuitCodeBlock CircuitCode; - - public UseCircuitCodePacket() - { - HasVariableBlocks = false; - Type = PacketType.UseCircuitCode; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 3; - Header.Reliable = true; - CircuitCode = new CircuitCodeBlock(); - } - - public UseCircuitCodePacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - CircuitCode.FromBytes(bytes, ref i); - } - - public UseCircuitCodePacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - CircuitCode.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += CircuitCode.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class TelehubInfoPacket : Packet - { - /// - public sealed class TelehubBlockBlock : PacketBlock - { - public UUID ObjectID; - public byte[] ObjectName; - public Vector3 TelehubPos; - public Quaternion TelehubRot; - - public override int Length - { - get - { - int length = 41; - if (ObjectName != null) { length += ObjectName.Length; } - return length; - } - } - - public TelehubBlockBlock() { } - public TelehubBlockBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - ObjectID.FromBytes(bytes, i); i += 16; - length = bytes[i++]; - ObjectName = new byte[length]; - Buffer.BlockCopy(bytes, i, ObjectName, 0, length); i += length; - TelehubPos.FromBytes(bytes, i); i += 12; - TelehubRot.FromBytes(bytes, i, true); i += 12; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - ObjectID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)ObjectName.Length; - Buffer.BlockCopy(ObjectName, 0, bytes, i, ObjectName.Length); i += ObjectName.Length; - TelehubPos.ToBytes(bytes, i); i += 12; - TelehubRot.ToBytes(bytes, i); i += 12; - } - - } - - /// - public sealed class SpawnPointBlockBlock : PacketBlock - { - public Vector3 SpawnPointPos; - - public override int Length - { - get - { - return 12; - } - } - - public SpawnPointBlockBlock() { } - public SpawnPointBlockBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - SpawnPointPos.FromBytes(bytes, i); i += 12; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - SpawnPointPos.ToBytes(bytes, i); i += 12; - } - - } - - public override int Length - { - get - { - int length = 11; - length += TelehubBlock.Length; - for (int j = 0; j < SpawnPointBlock.Length; j++) - length += SpawnPointBlock[j].Length; - return length; - } - } - public TelehubBlockBlock TelehubBlock; - public SpawnPointBlockBlock[] SpawnPointBlock; - - public TelehubInfoPacket() - { - HasVariableBlocks = true; - Type = PacketType.TelehubInfo; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 10; - Header.Reliable = true; - TelehubBlock = new TelehubBlockBlock(); - SpawnPointBlock = null; - } - - public TelehubInfoPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - TelehubBlock.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(SpawnPointBlock == null || SpawnPointBlock.Length != -1) { - SpawnPointBlock = new SpawnPointBlockBlock[count]; - for(int j = 0; j < count; j++) - { SpawnPointBlock[j] = new SpawnPointBlockBlock(); } - } - for (int j = 0; j < count; j++) - { SpawnPointBlock[j].FromBytes(bytes, ref i); } - } - - public TelehubInfoPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - TelehubBlock.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(SpawnPointBlock == null || SpawnPointBlock.Length != count) { - SpawnPointBlock = new SpawnPointBlockBlock[count]; - for(int j = 0; j < count; j++) - { SpawnPointBlock[j] = new SpawnPointBlockBlock(); } - } - for (int j = 0; j < count; j++) - { SpawnPointBlock[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += TelehubBlock.Length; - length++; - for (int j = 0; j < SpawnPointBlock.Length; j++) { length += SpawnPointBlock[j].Length; } - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += TelehubBlock.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - TelehubBlock.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int SpawnPointBlockStart = 0; - do - { - int variableLength = 0; - int SpawnPointBlockCount = 0; - - i = SpawnPointBlockStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < SpawnPointBlock.Length) { - int blockLength = SpawnPointBlock[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == SpawnPointBlockStart) { - variableLength += blockLength; - ++SpawnPointBlockCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)SpawnPointBlockCount; - for (i = SpawnPointBlockStart; i < SpawnPointBlockStart + SpawnPointBlockCount; i++) { SpawnPointBlock[i].ToBytes(packet, ref length); } - SpawnPointBlockStart += SpawnPointBlockCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - SpawnPointBlockStart < SpawnPointBlock.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class EconomyDataRequestPacket : Packet - { - public override int Length - { - get - { - int length = 10; - return length; - } - } - - public EconomyDataRequestPacket() - { - HasVariableBlocks = false; - Type = PacketType.EconomyDataRequest; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 24; - Header.Reliable = true; - } - - public EconomyDataRequestPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - } - - public EconomyDataRequestPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - } - - public override byte[] ToBytes() - { - int length = 10; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class EconomyDataPacket : Packet - { - /// - public sealed class InfoBlock : PacketBlock - { - public int ObjectCapacity; - public int ObjectCount; - public int PriceEnergyUnit; - public int PriceObjectClaim; - public int PricePublicObjectDecay; - public int PricePublicObjectDelete; - public int PriceParcelClaim; - public float PriceParcelClaimFactor; - public int PriceUpload; - public int PriceRentLight; - public int TeleportMinPrice; - public float TeleportPriceExponent; - public float EnergyEfficiency; - public float PriceObjectRent; - public float PriceObjectScaleFactor; - public int PriceParcelRent; - public int PriceGroupCreate; - - public override int Length - { - get - { - return 68; - } - } - - public InfoBlock() { } - public InfoBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - ObjectCapacity = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - ObjectCount = (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)); - PriceObjectClaim = (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)); - PricePublicObjectDelete = (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)); - PriceParcelClaimFactor = Utils.BytesToFloat(bytes, i); i += 4; - PriceUpload = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - PriceRentLight = (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)); - TeleportPriceExponent = Utils.BytesToFloat(bytes, i); i += 4; - EnergyEfficiency = Utils.BytesToFloat(bytes, i); i += 4; - PriceObjectRent = Utils.BytesToFloat(bytes, i); i += 4; - PriceObjectScaleFactor = Utils.BytesToFloat(bytes, i); i += 4; - PriceParcelRent = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - PriceGroupCreate = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.IntToBytes(ObjectCapacity, bytes, i); i += 4; - Utils.IntToBytes(ObjectCount, bytes, i); i += 4; - Utils.IntToBytes(PriceEnergyUnit, bytes, i); i += 4; - Utils.IntToBytes(PriceObjectClaim, bytes, i); i += 4; - Utils.IntToBytes(PricePublicObjectDecay, bytes, i); i += 4; - Utils.IntToBytes(PricePublicObjectDelete, bytes, i); i += 4; - Utils.IntToBytes(PriceParcelClaim, bytes, i); i += 4; - Utils.FloatToBytes(PriceParcelClaimFactor, bytes, i); i += 4; - Utils.IntToBytes(PriceUpload, bytes, i); i += 4; - Utils.IntToBytes(PriceRentLight, bytes, i); i += 4; - Utils.IntToBytes(TeleportMinPrice, bytes, i); i += 4; - Utils.FloatToBytes(TeleportPriceExponent, bytes, i); i += 4; - Utils.FloatToBytes(EnergyEfficiency, bytes, i); i += 4; - Utils.FloatToBytes(PriceObjectRent, bytes, i); i += 4; - Utils.FloatToBytes(PriceObjectScaleFactor, bytes, i); i += 4; - Utils.IntToBytes(PriceParcelRent, bytes, i); i += 4; - Utils.IntToBytes(PriceGroupCreate, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 10; - length += Info.Length; - return length; - } - } - public InfoBlock Info; - - public EconomyDataPacket() - { - HasVariableBlocks = false; - Type = PacketType.EconomyData; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 25; - Header.Reliable = true; - Header.Zerocoded = true; - Info = new InfoBlock(); - } - - public EconomyDataPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - Info.FromBytes(bytes, ref i); - } - - public EconomyDataPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - Info.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += Info.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class AvatarPickerRequestPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - public UUID QueryID; - - public override int Length - { - get - { - return 48; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - QueryID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - QueryID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class DataBlock : PacketBlock - { - public byte[] Name; - - public override int Length - { - get - { - int length = 1; - if (Name != null) { length += Name.Length; } - return length; - } - } - - public DataBlock() { } - public DataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - length = bytes[i++]; - Name = new byte[length]; - Buffer.BlockCopy(bytes, i, Name, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - bytes[i++] = (byte)Name.Length; - Buffer.BlockCopy(Name, 0, bytes, i, Name.Length); i += Name.Length; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += Data.Length; - return length; - } - } - public AgentDataBlock AgentData; - public DataBlock Data; - - public AvatarPickerRequestPacket() - { - HasVariableBlocks = false; - Type = PacketType.AvatarPickerRequest; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 26; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - Data = new DataBlock(); - } - - public AvatarPickerRequestPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - Data.FromBytes(bytes, ref i); - } - - public AvatarPickerRequestPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - Data.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += Data.Length; - if (Header.AckList != null && 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); - Data.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class AvatarPickerReplyPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID QueryID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - QueryID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - QueryID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class DataBlock : PacketBlock - { - public UUID AvatarID; - public byte[] FirstName; - public byte[] LastName; - - public override int Length - { - get - { - int length = 18; - if (FirstName != null) { length += FirstName.Length; } - if (LastName != null) { length += LastName.Length; } - return length; - } - } - - public DataBlock() { } - public DataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - AvatarID.FromBytes(bytes, i); i += 16; - length = bytes[i++]; - FirstName = new byte[length]; - Buffer.BlockCopy(bytes, i, FirstName, 0, length); i += length; - length = bytes[i++]; - LastName = new byte[length]; - Buffer.BlockCopy(bytes, i, LastName, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AvatarID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)FirstName.Length; - Buffer.BlockCopy(FirstName, 0, bytes, i, FirstName.Length); i += FirstName.Length; - bytes[i++] = (byte)LastName.Length; - Buffer.BlockCopy(LastName, 0, bytes, i, LastName.Length); i += LastName.Length; - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentData.Length; - for (int j = 0; j < Data.Length; j++) - length += Data[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public DataBlock[] Data; - - public AvatarPickerReplyPacket() - { - HasVariableBlocks = true; - Type = PacketType.AvatarPickerReply; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 28; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - Data = null; - } - - public AvatarPickerReplyPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(Data == null || Data.Length != -1) { - Data = new DataBlock[count]; - for(int j = 0; j < count; j++) - { Data[j] = new DataBlock(); } - } - for (int j = 0; j < count; j++) - { Data[j].FromBytes(bytes, ref i); } - } - - public AvatarPickerReplyPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(Data == null || Data.Length != count) { - Data = new DataBlock[count]; - for(int j = 0; j < count; j++) - { Data[j] = new DataBlock(); } - } - for (int j = 0; j < count; j++) - { Data[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length++; - for (int j = 0; j < Data.Length; j++) { length += Data[j].Length; } - if (Header.AckList != null && 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)Data.Length; - for (int j = 0; j < Data.Length; j++) { Data[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int DataStart = 0; - do - { - int variableLength = 0; - int DataCount = 0; - - i = DataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < Data.Length) { - int blockLength = Data[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == DataStart) { - variableLength += blockLength; - ++DataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)DataCount; - for (i = DataStart; i < DataStart + DataCount; i++) { Data[i].ToBytes(packet, ref length); } - DataStart += DataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - DataStart < Data.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class PlacesQueryPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - public UUID QueryID; - - public override int Length - { - get - { - return 48; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - QueryID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - QueryID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class TransactionDataBlock : PacketBlock - { - public UUID TransactionID; - - public override int Length - { - get - { - return 16; - } - } - - public TransactionDataBlock() { } - public TransactionDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - TransactionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - TransactionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class QueryDataBlock : PacketBlock - { - public byte[] QueryText; - public uint QueryFlags; - public sbyte Category; - public byte[] SimName; - - public override int Length - { - get - { - int length = 7; - if (QueryText != null) { length += QueryText.Length; } - if (SimName != null) { length += SimName.Length; } - return length; - } - } - - public QueryDataBlock() { } - public QueryDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - length = bytes[i++]; - QueryText = new byte[length]; - Buffer.BlockCopy(bytes, i, QueryText, 0, length); i += length; - QueryFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - Category = (sbyte)bytes[i++]; - length = bytes[i++]; - SimName = new byte[length]; - Buffer.BlockCopy(bytes, i, SimName, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - bytes[i++] = (byte)QueryText.Length; - Buffer.BlockCopy(QueryText, 0, bytes, i, QueryText.Length); i += QueryText.Length; - Utils.UIntToBytes(QueryFlags, bytes, i); i += 4; - bytes[i++] = (byte)Category; - bytes[i++] = (byte)SimName.Length; - Buffer.BlockCopy(SimName, 0, bytes, i, SimName.Length); i += SimName.Length; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += TransactionData.Length; - length += QueryData.Length; - return length; - } - } - public AgentDataBlock AgentData; - public TransactionDataBlock TransactionData; - public QueryDataBlock QueryData; - - public PlacesQueryPacket() - { - HasVariableBlocks = false; - Type = PacketType.PlacesQuery; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 29; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - TransactionData = new TransactionDataBlock(); - QueryData = new QueryDataBlock(); - } - - public PlacesQueryPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - TransactionData.FromBytes(bytes, ref i); - QueryData.FromBytes(bytes, ref i); - } - - public PlacesQueryPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - TransactionData.FromBytes(bytes, ref i); - QueryData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += TransactionData.Length; - length += QueryData.Length; - if (Header.AckList != null && 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); - QueryData.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class PlacesReplyPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID QueryID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - QueryID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - QueryID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class TransactionDataBlock : PacketBlock - { - public UUID TransactionID; - - public override int Length - { - get - { - return 16; - } - } - - public TransactionDataBlock() { } - public TransactionDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - TransactionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - TransactionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class QueryDataBlock : PacketBlock - { - public UUID OwnerID; - public byte[] Name; - public byte[] Desc; - public int ActualArea; - public int BillableArea; - public byte Flags; - public float GlobalX; - public float GlobalY; - public float GlobalZ; - public byte[] SimName; - public UUID SnapshotID; - public float Dwell; - public int Price; - - public override int Length - { - get - { - int length = 64; - if (Name != null) { length += Name.Length; } - if (Desc != null) { length += Desc.Length; } - if (SimName != null) { length += SimName.Length; } - return length; - } - } - - public QueryDataBlock() { } - public QueryDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - OwnerID.FromBytes(bytes, i); i += 16; - length = bytes[i++]; - Name = new byte[length]; - Buffer.BlockCopy(bytes, i, Name, 0, length); i += length; - length = bytes[i++]; - Desc = new byte[length]; - Buffer.BlockCopy(bytes, i, Desc, 0, length); i += length; - ActualArea = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - BillableArea = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - Flags = (byte)bytes[i++]; - GlobalX = Utils.BytesToFloat(bytes, i); i += 4; - GlobalY = Utils.BytesToFloat(bytes, i); i += 4; - GlobalZ = Utils.BytesToFloat(bytes, i); i += 4; - length = bytes[i++]; - SimName = new byte[length]; - Buffer.BlockCopy(bytes, i, SimName, 0, length); i += length; - SnapshotID.FromBytes(bytes, i); i += 16; - Dwell = Utils.BytesToFloat(bytes, i); i += 4; - Price = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - OwnerID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)Name.Length; - Buffer.BlockCopy(Name, 0, bytes, i, Name.Length); i += Name.Length; - bytes[i++] = (byte)Desc.Length; - Buffer.BlockCopy(Desc, 0, bytes, i, Desc.Length); i += Desc.Length; - Utils.IntToBytes(ActualArea, bytes, i); i += 4; - Utils.IntToBytes(BillableArea, bytes, i); i += 4; - bytes[i++] = Flags; - Utils.FloatToBytes(GlobalX, bytes, i); i += 4; - Utils.FloatToBytes(GlobalY, bytes, i); i += 4; - Utils.FloatToBytes(GlobalZ, bytes, i); i += 4; - bytes[i++] = (byte)SimName.Length; - Buffer.BlockCopy(SimName, 0, bytes, i, SimName.Length); i += SimName.Length; - SnapshotID.ToBytes(bytes, i); i += 16; - Utils.FloatToBytes(Dwell, bytes, i); i += 4; - Utils.IntToBytes(Price, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentData.Length; - length += TransactionData.Length; - for (int j = 0; j < QueryData.Length; j++) - length += QueryData[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public TransactionDataBlock TransactionData; - public QueryDataBlock[] QueryData; - - public PlacesReplyPacket() - { - HasVariableBlocks = true; - Type = PacketType.PlacesReply; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 30; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - TransactionData = new TransactionDataBlock(); - QueryData = null; - } - - public PlacesReplyPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - TransactionData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(QueryData == null || QueryData.Length != -1) { - QueryData = new QueryDataBlock[count]; - for(int j = 0; j < count; j++) - { QueryData[j] = new QueryDataBlock(); } - } - for (int j = 0; j < count; j++) - { QueryData[j].FromBytes(bytes, ref i); } - } - - public PlacesReplyPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - TransactionData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(QueryData == null || QueryData.Length != count) { - QueryData = new QueryDataBlock[count]; - for(int j = 0; j < count; j++) - { QueryData[j] = new QueryDataBlock(); } - } - for (int j = 0; j < count; j++) - { QueryData[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += TransactionData.Length; - length++; - for (int j = 0; j < QueryData.Length; j++) { length += QueryData[j].Length; } - if (Header.AckList != null && 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); - bytes[i++] = (byte)QueryData.Length; - for (int j = 0; j < QueryData.Length; j++) { QueryData[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - fixedLength += TransactionData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - TransactionData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int QueryDataStart = 0; - do - { - int variableLength = 0; - int QueryDataCount = 0; - - i = QueryDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < QueryData.Length) { - int blockLength = QueryData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == QueryDataStart) { - variableLength += blockLength; - ++QueryDataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)QueryDataCount; - for (i = QueryDataStart; i < QueryDataStart + QueryDataCount; i++) { QueryData[i].ToBytes(packet, ref length); } - QueryDataStart += QueryDataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - QueryDataStart < QueryData.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class DirFindQueryPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class QueryDataBlock : PacketBlock - { - public UUID QueryID; - public byte[] QueryText; - public uint QueryFlags; - public int QueryStart; - - public override int Length - { - get - { - int length = 25; - if (QueryText != null) { length += QueryText.Length; } - return length; - } - } - - public QueryDataBlock() { } - public QueryDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - QueryID.FromBytes(bytes, i); i += 16; - length = bytes[i++]; - QueryText = new byte[length]; - Buffer.BlockCopy(bytes, i, QueryText, 0, length); i += length; - 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)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - QueryID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)QueryText.Length; - Buffer.BlockCopy(QueryText, 0, bytes, i, QueryText.Length); i += QueryText.Length; - Utils.UIntToBytes(QueryFlags, bytes, i); i += 4; - Utils.IntToBytes(QueryStart, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += QueryData.Length; - return length; - } - } - public AgentDataBlock AgentData; - public QueryDataBlock QueryData; - - public DirFindQueryPacket() - { - HasVariableBlocks = false; - Type = PacketType.DirFindQuery; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 31; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - QueryData = new QueryDataBlock(); - } - - public DirFindQueryPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - QueryData.FromBytes(bytes, ref i); - } - - public DirFindQueryPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - QueryData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += QueryData.Length; - if (Header.AckList != null && 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); - QueryData.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class DirPlacesQueryPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class QueryDataBlock : PacketBlock - { - public UUID QueryID; - public byte[] QueryText; - public uint QueryFlags; - public sbyte Category; - public byte[] SimName; - public int QueryStart; - - public override int Length - { - get - { - int length = 27; - if (QueryText != null) { length += QueryText.Length; } - if (SimName != null) { length += SimName.Length; } - return length; - } - } - - public QueryDataBlock() { } - public QueryDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - QueryID.FromBytes(bytes, i); i += 16; - length = bytes[i++]; - QueryText = new byte[length]; - Buffer.BlockCopy(bytes, i, QueryText, 0, length); i += length; - QueryFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - Category = (sbyte)bytes[i++]; - length = bytes[i++]; - SimName = new byte[length]; - Buffer.BlockCopy(bytes, i, SimName, 0, length); i += length; - QueryStart = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - QueryID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)QueryText.Length; - Buffer.BlockCopy(QueryText, 0, bytes, i, QueryText.Length); i += QueryText.Length; - Utils.UIntToBytes(QueryFlags, bytes, i); i += 4; - bytes[i++] = (byte)Category; - bytes[i++] = (byte)SimName.Length; - Buffer.BlockCopy(SimName, 0, bytes, i, SimName.Length); i += SimName.Length; - Utils.IntToBytes(QueryStart, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += QueryData.Length; - return length; - } - } - public AgentDataBlock AgentData; - public QueryDataBlock QueryData; - - public DirPlacesQueryPacket() - { - HasVariableBlocks = false; - Type = PacketType.DirPlacesQuery; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 33; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - QueryData = new QueryDataBlock(); - } - - public DirPlacesQueryPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - QueryData.FromBytes(bytes, ref i); - } - - public DirPlacesQueryPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - QueryData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += QueryData.Length; - if (Header.AckList != null && 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); - QueryData.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class DirPlacesReplyPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - - public override int Length - { - get - { - return 16; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class QueryDataBlock : PacketBlock - { - public UUID QueryID; - - public override int Length - { - get - { - return 16; - } - } - - public QueryDataBlock() { } - public QueryDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - QueryID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - QueryID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class QueryRepliesBlock : PacketBlock - { - public UUID ParcelID; - public byte[] Name; - public bool ForSale; - public bool Auction; - public float Dwell; - - public override int Length - { - get - { - int length = 23; - if (Name != null) { length += Name.Length; } - return length; - } - } - - public QueryRepliesBlock() { } - public QueryRepliesBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - ParcelID.FromBytes(bytes, i); i += 16; - length = bytes[i++]; - Name = new byte[length]; - Buffer.BlockCopy(bytes, i, Name, 0, length); i += length; - ForSale = (bytes[i++] != 0) ? (bool)true : (bool)false; - Auction = (bytes[i++] != 0) ? (bool)true : (bool)false; - Dwell = Utils.BytesToFloat(bytes, i); i += 4; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - ParcelID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)Name.Length; - Buffer.BlockCopy(Name, 0, bytes, i, Name.Length); i += Name.Length; - bytes[i++] = (byte)((ForSale) ? 1 : 0); - bytes[i++] = (byte)((Auction) ? 1 : 0); - Utils.FloatToBytes(Dwell, bytes, i); i += 4; - } - - } - - /// - public sealed class StatusDataBlock : PacketBlock - { - public uint Status; - - public override int Length - { - get - { - return 4; - } - } - - public StatusDataBlock() { } - public StatusDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - Status = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UIntToBytes(Status, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 13; - length += AgentData.Length; - for (int j = 0; j < QueryData.Length; j++) - length += QueryData[j].Length; - for (int j = 0; j < QueryReplies.Length; j++) - length += QueryReplies[j].Length; - for (int j = 0; j < StatusData.Length; j++) - length += StatusData[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public QueryDataBlock[] QueryData; - public QueryRepliesBlock[] QueryReplies; - public StatusDataBlock[] StatusData; - - public DirPlacesReplyPacket() - { - HasVariableBlocks = true; - Type = PacketType.DirPlacesReply; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 35; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - QueryData = null; - QueryReplies = null; - StatusData = null; - } - - public DirPlacesReplyPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(QueryData == null || QueryData.Length != -1) { - QueryData = new QueryDataBlock[count]; - for(int j = 0; j < count; j++) - { QueryData[j] = new QueryDataBlock(); } - } - for (int j = 0; j < count; j++) - { QueryData[j].FromBytes(bytes, ref i); } - count = (int)bytes[i++]; - if(QueryReplies == null || QueryReplies.Length != -1) { - QueryReplies = new QueryRepliesBlock[count]; - for(int j = 0; j < count; j++) - { QueryReplies[j] = new QueryRepliesBlock(); } - } - for (int j = 0; j < count; j++) - { QueryReplies[j].FromBytes(bytes, ref i); } - count = (int)bytes[i++]; - if(StatusData == null || StatusData.Length != -1) { - StatusData = new StatusDataBlock[count]; - for(int j = 0; j < count; j++) - { StatusData[j] = new StatusDataBlock(); } - } - for (int j = 0; j < count; j++) - { StatusData[j].FromBytes(bytes, ref i); } - } - - public DirPlacesReplyPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(QueryData == null || QueryData.Length != count) { - QueryData = new QueryDataBlock[count]; - for(int j = 0; j < count; j++) - { QueryData[j] = new QueryDataBlock(); } - } - for (int j = 0; j < count; j++) - { QueryData[j].FromBytes(bytes, ref i); } - count = (int)bytes[i++]; - if(QueryReplies == null || QueryReplies.Length != count) { - QueryReplies = new QueryRepliesBlock[count]; - for(int j = 0; j < count; j++) - { QueryReplies[j] = new QueryRepliesBlock(); } - } - for (int j = 0; j < count; j++) - { QueryReplies[j].FromBytes(bytes, ref i); } - count = (int)bytes[i++]; - if(StatusData == null || StatusData.Length != count) { - StatusData = new StatusDataBlock[count]; - for(int j = 0; j < count; j++) - { StatusData[j] = new StatusDataBlock(); } - } - for (int j = 0; j < count; j++) - { StatusData[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length++; - for (int j = 0; j < QueryData.Length; j++) { length += QueryData[j].Length; } - length++; - for (int j = 0; j < QueryReplies.Length; j++) { length += QueryReplies[j].Length; } - length++; - for (int j = 0; j < StatusData.Length; j++) { length += StatusData[j].Length; } - if (Header.AckList != null && 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)QueryData.Length; - for (int j = 0; j < QueryData.Length; j++) { QueryData[j].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)StatusData.Length; - for (int j = 0; j < StatusData.Length; j++) { StatusData[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - fixedLength += 3; - - int QueryDataStart = 0; - int QueryRepliesStart = 0; - int StatusDataStart = 0; - do - { - int variableLength = 0; - int QueryDataCount = 0; - int QueryRepliesCount = 0; - int StatusDataCount = 0; - - i = QueryDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < QueryData.Length) { - int blockLength = QueryData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == QueryDataStart) { - variableLength += blockLength; - ++QueryDataCount; - } - else { break; } - ++i; - } - - i = QueryRepliesStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < QueryReplies.Length) { - int blockLength = QueryReplies[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == QueryRepliesStart) { - variableLength += blockLength; - ++QueryRepliesCount; - } - else { break; } - ++i; - } - - i = StatusDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < StatusData.Length) { - int blockLength = StatusData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == StatusDataStart) { - variableLength += blockLength; - ++StatusDataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)QueryDataCount; - for (i = QueryDataStart; i < QueryDataStart + QueryDataCount; i++) { QueryData[i].ToBytes(packet, ref length); } - QueryDataStart += QueryDataCount; - - packet[length++] = (byte)QueryRepliesCount; - for (i = QueryRepliesStart; i < QueryRepliesStart + QueryRepliesCount; i++) { QueryReplies[i].ToBytes(packet, ref length); } - QueryRepliesStart += QueryRepliesCount; - - packet[length++] = (byte)StatusDataCount; - for (i = StatusDataStart; i < StatusDataStart + StatusDataCount; i++) { StatusData[i].ToBytes(packet, ref length); } - StatusDataStart += StatusDataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - QueryDataStart < QueryData.Length || - QueryRepliesStart < QueryReplies.Length || - StatusDataStart < StatusData.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class DirPeopleReplyPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - - public override int Length - { - get - { - return 16; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class QueryDataBlock : PacketBlock - { - public UUID QueryID; - - public override int Length - { - get - { - return 16; - } - } - - public QueryDataBlock() { } - public QueryDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - QueryID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - QueryID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class QueryRepliesBlock : PacketBlock - { - public UUID AgentID; - public byte[] FirstName; - public byte[] LastName; - public byte[] Group; - public bool Online; - public int Reputation; - - public override int Length - { - get - { - int length = 24; - if (FirstName != null) { length += FirstName.Length; } - if (LastName != null) { length += LastName.Length; } - if (Group != null) { length += Group.Length; } - return length; - } - } - - public QueryRepliesBlock() { } - public QueryRepliesBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - AgentID.FromBytes(bytes, i); i += 16; - length = bytes[i++]; - FirstName = new byte[length]; - Buffer.BlockCopy(bytes, i, FirstName, 0, length); i += length; - length = bytes[i++]; - LastName = new byte[length]; - Buffer.BlockCopy(bytes, i, LastName, 0, length); i += length; - length = bytes[i++]; - Group = new byte[length]; - Buffer.BlockCopy(bytes, i, Group, 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)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)FirstName.Length; - Buffer.BlockCopy(FirstName, 0, bytes, i, FirstName.Length); i += FirstName.Length; - bytes[i++] = (byte)LastName.Length; - Buffer.BlockCopy(LastName, 0, bytes, i, LastName.Length); i += LastName.Length; - bytes[i++] = (byte)Group.Length; - Buffer.BlockCopy(Group, 0, bytes, i, Group.Length); i += Group.Length; - bytes[i++] = (byte)((Online) ? 1 : 0); - Utils.IntToBytes(Reputation, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentData.Length; - length += QueryData.Length; - for (int j = 0; j < QueryReplies.Length; j++) - length += QueryReplies[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public QueryDataBlock QueryData; - public QueryRepliesBlock[] QueryReplies; - - public DirPeopleReplyPacket() - { - HasVariableBlocks = true; - Type = PacketType.DirPeopleReply; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 36; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - QueryData = new QueryDataBlock(); - QueryReplies = null; - } - - public DirPeopleReplyPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - QueryData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(QueryReplies == null || QueryReplies.Length != -1) { - QueryReplies = new QueryRepliesBlock[count]; - for(int j = 0; j < count; j++) - { QueryReplies[j] = new QueryRepliesBlock(); } - } - for (int j = 0; j < count; j++) - { QueryReplies[j].FromBytes(bytes, ref i); } - } - - public DirPeopleReplyPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - QueryData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(QueryReplies == null || QueryReplies.Length != count) { - QueryReplies = new QueryRepliesBlock[count]; - for(int j = 0; j < count; j++) - { QueryReplies[j] = new QueryRepliesBlock(); } - } - for (int j = 0; j < count; j++) - { QueryReplies[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += QueryData.Length; - length++; - for (int j = 0; j < QueryReplies.Length; j++) { length += QueryReplies[j].Length; } - if (Header.AckList != null && 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); - QueryData.ToBytes(bytes, ref i); - bytes[i++] = (byte)QueryReplies.Length; - for (int j = 0; j < QueryReplies.Length; j++) { QueryReplies[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - fixedLength += QueryData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - QueryData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int QueryRepliesStart = 0; - do - { - int variableLength = 0; - int QueryRepliesCount = 0; - - i = QueryRepliesStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < QueryReplies.Length) { - int blockLength = QueryReplies[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == QueryRepliesStart) { - variableLength += blockLength; - ++QueryRepliesCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)QueryRepliesCount; - for (i = QueryRepliesStart; i < QueryRepliesStart + QueryRepliesCount; i++) { QueryReplies[i].ToBytes(packet, ref length); } - QueryRepliesStart += QueryRepliesCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - QueryRepliesStart < QueryReplies.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class DirEventsReplyPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - - public override int Length - { - get - { - return 16; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class QueryDataBlock : PacketBlock - { - public UUID QueryID; - - public override int Length - { - get - { - return 16; - } - } - - public QueryDataBlock() { } - public QueryDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - QueryID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - QueryID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class QueryRepliesBlock : PacketBlock - { - public UUID OwnerID; - public byte[] Name; - public uint EventID; - public byte[] Date; - public uint UnixTime; - public uint EventFlags; - - public override int Length - { - get - { - int length = 30; - if (Name != null) { length += Name.Length; } - if (Date != null) { length += Date.Length; } - return length; - } - } - - public QueryRepliesBlock() { } - public QueryRepliesBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - OwnerID.FromBytes(bytes, i); i += 16; - length = bytes[i++]; - Name = new byte[length]; - Buffer.BlockCopy(bytes, i, Name, 0, length); i += length; - EventID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - length = bytes[i++]; - Date = new byte[length]; - Buffer.BlockCopy(bytes, i, Date, 0, length); i += length; - UnixTime = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - EventFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - OwnerID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)Name.Length; - Buffer.BlockCopy(Name, 0, bytes, i, Name.Length); i += Name.Length; - Utils.UIntToBytes(EventID, bytes, i); i += 4; - bytes[i++] = (byte)Date.Length; - Buffer.BlockCopy(Date, 0, bytes, i, Date.Length); i += Date.Length; - Utils.UIntToBytes(UnixTime, bytes, i); i += 4; - Utils.UIntToBytes(EventFlags, bytes, i); i += 4; - } - - } - - /// - public sealed class StatusDataBlock : PacketBlock - { - public uint Status; - - public override int Length - { - get - { - return 4; - } - } - - public StatusDataBlock() { } - public StatusDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - Status = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UIntToBytes(Status, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 12; - length += AgentData.Length; - length += QueryData.Length; - for (int j = 0; j < QueryReplies.Length; j++) - length += QueryReplies[j].Length; - for (int j = 0; j < StatusData.Length; j++) - length += StatusData[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public QueryDataBlock QueryData; - public QueryRepliesBlock[] QueryReplies; - public StatusDataBlock[] StatusData; - - public DirEventsReplyPacket() - { - HasVariableBlocks = true; - Type = PacketType.DirEventsReply; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 37; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - QueryData = new QueryDataBlock(); - QueryReplies = null; - StatusData = null; - } - - public DirEventsReplyPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - QueryData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(QueryReplies == null || QueryReplies.Length != -1) { - QueryReplies = new QueryRepliesBlock[count]; - for(int j = 0; j < count; j++) - { QueryReplies[j] = new QueryRepliesBlock(); } - } - for (int j = 0; j < count; j++) - { QueryReplies[j].FromBytes(bytes, ref i); } - count = (int)bytes[i++]; - if(StatusData == null || StatusData.Length != -1) { - StatusData = new StatusDataBlock[count]; - for(int j = 0; j < count; j++) - { StatusData[j] = new StatusDataBlock(); } - } - for (int j = 0; j < count; j++) - { StatusData[j].FromBytes(bytes, ref i); } - } - - public DirEventsReplyPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - QueryData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(QueryReplies == null || QueryReplies.Length != count) { - QueryReplies = new QueryRepliesBlock[count]; - for(int j = 0; j < count; j++) - { QueryReplies[j] = new QueryRepliesBlock(); } - } - for (int j = 0; j < count; j++) - { QueryReplies[j].FromBytes(bytes, ref i); } - count = (int)bytes[i++]; - if(StatusData == null || StatusData.Length != count) { - StatusData = new StatusDataBlock[count]; - for(int j = 0; j < count; j++) - { StatusData[j] = new StatusDataBlock(); } - } - for (int j = 0; j < count; j++) - { StatusData[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += QueryData.Length; - length++; - for (int j = 0; j < QueryReplies.Length; j++) { length += QueryReplies[j].Length; } - length++; - for (int j = 0; j < StatusData.Length; j++) { length += StatusData[j].Length; } - if (Header.AckList != null && 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); - QueryData.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)StatusData.Length; - for (int j = 0; j < StatusData.Length; j++) { StatusData[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - fixedLength += QueryData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - QueryData.ToBytes(fixedBytes, ref i); - fixedLength += 2; - - int QueryRepliesStart = 0; - int StatusDataStart = 0; - do - { - int variableLength = 0; - int QueryRepliesCount = 0; - int StatusDataCount = 0; - - i = QueryRepliesStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < QueryReplies.Length) { - int blockLength = QueryReplies[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == QueryRepliesStart) { - variableLength += blockLength; - ++QueryRepliesCount; - } - else { break; } - ++i; - } - - i = StatusDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < StatusData.Length) { - int blockLength = StatusData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == StatusDataStart) { - variableLength += blockLength; - ++StatusDataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)QueryRepliesCount; - for (i = QueryRepliesStart; i < QueryRepliesStart + QueryRepliesCount; i++) { QueryReplies[i].ToBytes(packet, ref length); } - QueryRepliesStart += QueryRepliesCount; - - packet[length++] = (byte)StatusDataCount; - for (i = StatusDataStart; i < StatusDataStart + StatusDataCount; i++) { StatusData[i].ToBytes(packet, ref length); } - StatusDataStart += StatusDataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - QueryRepliesStart < QueryReplies.Length || - StatusDataStart < StatusData.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class DirGroupsReplyPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - - public override int Length - { - get - { - return 16; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class QueryDataBlock : PacketBlock - { - public UUID QueryID; - - public override int Length - { - get - { - return 16; - } - } - - public QueryDataBlock() { } - public QueryDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - QueryID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - QueryID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class QueryRepliesBlock : PacketBlock - { - public UUID GroupID; - public byte[] GroupName; - public int Members; - public float SearchOrder; - - public override int Length - { - get - { - int length = 25; - if (GroupName != null) { length += GroupName.Length; } - return length; - } - } - - public QueryRepliesBlock() { } - public QueryRepliesBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - GroupID.FromBytes(bytes, i); i += 16; - length = bytes[i++]; - GroupName = new byte[length]; - Buffer.BlockCopy(bytes, i, GroupName, 0, length); i += length; - Members = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - SearchOrder = Utils.BytesToFloat(bytes, i); i += 4; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - GroupID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)GroupName.Length; - Buffer.BlockCopy(GroupName, 0, bytes, i, GroupName.Length); i += GroupName.Length; - Utils.IntToBytes(Members, bytes, i); i += 4; - Utils.FloatToBytes(SearchOrder, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentData.Length; - length += QueryData.Length; - for (int j = 0; j < QueryReplies.Length; j++) - length += QueryReplies[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public QueryDataBlock QueryData; - public QueryRepliesBlock[] QueryReplies; - - public DirGroupsReplyPacket() - { - HasVariableBlocks = true; - Type = PacketType.DirGroupsReply; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 38; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - QueryData = new QueryDataBlock(); - QueryReplies = null; - } - - public DirGroupsReplyPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - QueryData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(QueryReplies == null || QueryReplies.Length != -1) { - QueryReplies = new QueryRepliesBlock[count]; - for(int j = 0; j < count; j++) - { QueryReplies[j] = new QueryRepliesBlock(); } - } - for (int j = 0; j < count; j++) - { QueryReplies[j].FromBytes(bytes, ref i); } - } - - public DirGroupsReplyPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - QueryData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(QueryReplies == null || QueryReplies.Length != count) { - QueryReplies = new QueryRepliesBlock[count]; - for(int j = 0; j < count; j++) - { QueryReplies[j] = new QueryRepliesBlock(); } - } - for (int j = 0; j < count; j++) - { QueryReplies[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += QueryData.Length; - length++; - for (int j = 0; j < QueryReplies.Length; j++) { length += QueryReplies[j].Length; } - if (Header.AckList != null && 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); - QueryData.ToBytes(bytes, ref i); - bytes[i++] = (byte)QueryReplies.Length; - for (int j = 0; j < QueryReplies.Length; j++) { QueryReplies[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - fixedLength += QueryData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - QueryData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int QueryRepliesStart = 0; - do - { - int variableLength = 0; - int QueryRepliesCount = 0; - - i = QueryRepliesStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < QueryReplies.Length) { - int blockLength = QueryReplies[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == QueryRepliesStart) { - variableLength += blockLength; - ++QueryRepliesCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)QueryRepliesCount; - for (i = QueryRepliesStart; i < QueryRepliesStart + QueryRepliesCount; i++) { QueryReplies[i].ToBytes(packet, ref length); } - QueryRepliesStart += QueryRepliesCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - QueryRepliesStart < QueryReplies.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class DirClassifiedQueryPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class QueryDataBlock : PacketBlock - { - public UUID QueryID; - public byte[] QueryText; - public uint QueryFlags; - public uint Category; - public int QueryStart; - - public override int Length - { - get - { - int length = 29; - if (QueryText != null) { length += QueryText.Length; } - return length; - } - } - - public QueryDataBlock() { } - public QueryDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - QueryID.FromBytes(bytes, i); i += 16; - length = bytes[i++]; - QueryText = new byte[length]; - Buffer.BlockCopy(bytes, i, QueryText, 0, length); i += length; - QueryFlags = (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)); - QueryStart = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - QueryID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)QueryText.Length; - Buffer.BlockCopy(QueryText, 0, bytes, i, QueryText.Length); i += QueryText.Length; - Utils.UIntToBytes(QueryFlags, bytes, i); i += 4; - Utils.UIntToBytes(Category, bytes, i); i += 4; - Utils.IntToBytes(QueryStart, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += QueryData.Length; - return length; - } - } - public AgentDataBlock AgentData; - public QueryDataBlock QueryData; - - public DirClassifiedQueryPacket() - { - HasVariableBlocks = false; - Type = PacketType.DirClassifiedQuery; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 39; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - QueryData = new QueryDataBlock(); - } - - public DirClassifiedQueryPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - QueryData.FromBytes(bytes, ref i); - } - - public DirClassifiedQueryPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - QueryData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += QueryData.Length; - if (Header.AckList != null && 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); - QueryData.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class DirClassifiedReplyPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - - public override int Length - { - get - { - return 16; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class QueryDataBlock : PacketBlock - { - public UUID QueryID; - - public override int Length - { - get - { - return 16; - } - } - - public QueryDataBlock() { } - public QueryDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - QueryID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - QueryID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class QueryRepliesBlock : PacketBlock - { - public UUID ClassifiedID; - public byte[] Name; - public byte ClassifiedFlags; - public uint CreationDate; - public uint ExpirationDate; - public int PriceForListing; - - public override int Length - { - get - { - int length = 30; - if (Name != null) { length += Name.Length; } - return length; - } - } - - public QueryRepliesBlock() { } - public QueryRepliesBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - ClassifiedID.FromBytes(bytes, i); i += 16; - length = bytes[i++]; - Name = new byte[length]; - Buffer.BlockCopy(bytes, i, Name, 0, length); i += length; - ClassifiedFlags = (byte)bytes[i++]; - CreationDate = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - ExpirationDate = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - PriceForListing = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - ClassifiedID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)Name.Length; - Buffer.BlockCopy(Name, 0, bytes, i, Name.Length); i += Name.Length; - bytes[i++] = ClassifiedFlags; - Utils.UIntToBytes(CreationDate, bytes, i); i += 4; - Utils.UIntToBytes(ExpirationDate, bytes, i); i += 4; - Utils.IntToBytes(PriceForListing, bytes, i); i += 4; - } - - } - - /// - public sealed class StatusDataBlock : PacketBlock - { - public uint Status; - - public override int Length - { - get - { - return 4; - } - } - - public StatusDataBlock() { } - public StatusDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - Status = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UIntToBytes(Status, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 12; - length += AgentData.Length; - length += QueryData.Length; - for (int j = 0; j < QueryReplies.Length; j++) - length += QueryReplies[j].Length; - for (int j = 0; j < StatusData.Length; j++) - length += StatusData[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public QueryDataBlock QueryData; - public QueryRepliesBlock[] QueryReplies; - public StatusDataBlock[] StatusData; - - public DirClassifiedReplyPacket() - { - HasVariableBlocks = true; - Type = PacketType.DirClassifiedReply; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 41; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - QueryData = new QueryDataBlock(); - QueryReplies = null; - StatusData = null; - } - - public DirClassifiedReplyPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - QueryData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(QueryReplies == null || QueryReplies.Length != -1) { - QueryReplies = new QueryRepliesBlock[count]; - for(int j = 0; j < count; j++) - { QueryReplies[j] = new QueryRepliesBlock(); } - } - for (int j = 0; j < count; j++) - { QueryReplies[j].FromBytes(bytes, ref i); } - count = (int)bytes[i++]; - if(StatusData == null || StatusData.Length != -1) { - StatusData = new StatusDataBlock[count]; - for(int j = 0; j < count; j++) - { StatusData[j] = new StatusDataBlock(); } - } - for (int j = 0; j < count; j++) - { StatusData[j].FromBytes(bytes, ref i); } - } - - public DirClassifiedReplyPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - QueryData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(QueryReplies == null || QueryReplies.Length != count) { - QueryReplies = new QueryRepliesBlock[count]; - for(int j = 0; j < count; j++) - { QueryReplies[j] = new QueryRepliesBlock(); } - } - for (int j = 0; j < count; j++) - { QueryReplies[j].FromBytes(bytes, ref i); } - count = (int)bytes[i++]; - if(StatusData == null || StatusData.Length != count) { - StatusData = new StatusDataBlock[count]; - for(int j = 0; j < count; j++) - { StatusData[j] = new StatusDataBlock(); } - } - for (int j = 0; j < count; j++) - { StatusData[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += QueryData.Length; - length++; - for (int j = 0; j < QueryReplies.Length; j++) { length += QueryReplies[j].Length; } - length++; - for (int j = 0; j < StatusData.Length; j++) { length += StatusData[j].Length; } - if (Header.AckList != null && 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); - QueryData.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)StatusData.Length; - for (int j = 0; j < StatusData.Length; j++) { StatusData[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - fixedLength += QueryData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - QueryData.ToBytes(fixedBytes, ref i); - fixedLength += 2; - - int QueryRepliesStart = 0; - int StatusDataStart = 0; - do - { - int variableLength = 0; - int QueryRepliesCount = 0; - int StatusDataCount = 0; - - i = QueryRepliesStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < QueryReplies.Length) { - int blockLength = QueryReplies[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == QueryRepliesStart) { - variableLength += blockLength; - ++QueryRepliesCount; - } - else { break; } - ++i; - } - - i = StatusDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < StatusData.Length) { - int blockLength = StatusData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == StatusDataStart) { - variableLength += blockLength; - ++StatusDataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)QueryRepliesCount; - for (i = QueryRepliesStart; i < QueryRepliesStart + QueryRepliesCount; i++) { QueryReplies[i].ToBytes(packet, ref length); } - QueryRepliesStart += QueryRepliesCount; - - packet[length++] = (byte)StatusDataCount; - for (i = StatusDataStart; i < StatusDataStart + StatusDataCount; i++) { StatusData[i].ToBytes(packet, ref length); } - StatusDataStart += StatusDataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - QueryRepliesStart < QueryReplies.Length || - StatusDataStart < StatusData.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class AvatarClassifiedReplyPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID TargetID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - TargetID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - TargetID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class DataBlock : PacketBlock - { - public UUID ClassifiedID; - public byte[] Name; - - public override int Length - { - get - { - int length = 17; - if (Name != null) { length += Name.Length; } - return length; - } - } - - public DataBlock() { } - public DataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - ClassifiedID.FromBytes(bytes, i); i += 16; - length = bytes[i++]; - Name = new byte[length]; - Buffer.BlockCopy(bytes, i, Name, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - ClassifiedID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)Name.Length; - Buffer.BlockCopy(Name, 0, bytes, i, Name.Length); i += Name.Length; - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentData.Length; - for (int j = 0; j < Data.Length; j++) - length += Data[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public DataBlock[] Data; - - public AvatarClassifiedReplyPacket() - { - HasVariableBlocks = true; - Type = PacketType.AvatarClassifiedReply; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 42; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - Data = null; - } - - public AvatarClassifiedReplyPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(Data == null || Data.Length != -1) { - Data = new DataBlock[count]; - for(int j = 0; j < count; j++) - { Data[j] = new DataBlock(); } - } - for (int j = 0; j < count; j++) - { Data[j].FromBytes(bytes, ref i); } - } - - public AvatarClassifiedReplyPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(Data == null || Data.Length != count) { - Data = new DataBlock[count]; - for(int j = 0; j < count; j++) - { Data[j] = new DataBlock(); } - } - for (int j = 0; j < count; j++) - { Data[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length++; - for (int j = 0; j < Data.Length; j++) { length += Data[j].Length; } - if (Header.AckList != null && 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)Data.Length; - for (int j = 0; j < Data.Length; j++) { Data[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int DataStart = 0; - do - { - int variableLength = 0; - int DataCount = 0; - - i = DataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < Data.Length) { - int blockLength = Data[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == DataStart) { - variableLength += blockLength; - ++DataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)DataCount; - for (i = DataStart; i < DataStart + DataCount; i++) { Data[i].ToBytes(packet, ref length); } - DataStart += DataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - DataStart < Data.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class ClassifiedInfoRequestPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class DataBlock : PacketBlock - { - public UUID ClassifiedID; - - public override int Length - { - get - { - return 16; - } - } - - public DataBlock() { } - public DataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - ClassifiedID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - ClassifiedID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += Data.Length; - return length; - } - } - public AgentDataBlock AgentData; - public DataBlock Data; - - public ClassifiedInfoRequestPacket() - { - HasVariableBlocks = false; - Type = PacketType.ClassifiedInfoRequest; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 43; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - Data = new DataBlock(); - } - - public ClassifiedInfoRequestPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - Data.FromBytes(bytes, ref i); - } - - public ClassifiedInfoRequestPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - Data.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += Data.Length; - if (Header.AckList != null && 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); - Data.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class ClassifiedInfoReplyPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - - public override int Length - { - get - { - return 16; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class DataBlock : PacketBlock - { - public UUID ClassifiedID; - public UUID CreatorID; - public uint CreationDate; - public uint ExpirationDate; - public uint Category; - public byte[] Name; - public byte[] Desc; - public UUID ParcelID; - public uint ParentEstate; - public UUID SnapshotID; - public byte[] SimName; - public Vector3d PosGlobal; - public byte[] ParcelName; - public byte ClassifiedFlags; - public int PriceForListing; - - public override int Length - { - get - { - int length = 114; - if (Name != null) { length += Name.Length; } - if (Desc != null) { length += Desc.Length; } - if (SimName != null) { length += SimName.Length; } - if (ParcelName != null) { length += ParcelName.Length; } - return length; - } - } - - public DataBlock() { } - public DataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - ClassifiedID.FromBytes(bytes, i); i += 16; - CreatorID.FromBytes(bytes, i); i += 16; - CreationDate = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - ExpirationDate = (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)); - length = bytes[i++]; - Name = new byte[length]; - Buffer.BlockCopy(bytes, i, Name, 0, length); i += length; - length = (bytes[i++] + (bytes[i++] << 8)); - Desc = new byte[length]; - Buffer.BlockCopy(bytes, i, Desc, 0, length); i += length; - ParcelID.FromBytes(bytes, i); i += 16; - ParentEstate = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - SnapshotID.FromBytes(bytes, i); i += 16; - length = bytes[i++]; - SimName = new byte[length]; - Buffer.BlockCopy(bytes, i, SimName, 0, length); i += length; - PosGlobal.FromBytes(bytes, i); i += 24; - length = bytes[i++]; - ParcelName = new byte[length]; - Buffer.BlockCopy(bytes, i, ParcelName, 0, length); i += length; - ClassifiedFlags = (byte)bytes[i++]; - PriceForListing = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - ClassifiedID.ToBytes(bytes, i); i += 16; - CreatorID.ToBytes(bytes, i); i += 16; - Utils.UIntToBytes(CreationDate, bytes, i); i += 4; - Utils.UIntToBytes(ExpirationDate, bytes, i); i += 4; - Utils.UIntToBytes(Category, bytes, i); i += 4; - bytes[i++] = (byte)Name.Length; - Buffer.BlockCopy(Name, 0, bytes, i, Name.Length); i += Name.Length; - bytes[i++] = (byte)(Desc.Length % 256); - bytes[i++] = (byte)((Desc.Length >> 8) % 256); - Buffer.BlockCopy(Desc, 0, bytes, i, Desc.Length); i += Desc.Length; - ParcelID.ToBytes(bytes, i); i += 16; - Utils.UIntToBytes(ParentEstate, bytes, i); i += 4; - SnapshotID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)SimName.Length; - Buffer.BlockCopy(SimName, 0, bytes, i, SimName.Length); i += SimName.Length; - PosGlobal.ToBytes(bytes, i); i += 24; - bytes[i++] = (byte)ParcelName.Length; - Buffer.BlockCopy(ParcelName, 0, bytes, i, ParcelName.Length); i += ParcelName.Length; - bytes[i++] = ClassifiedFlags; - Utils.IntToBytes(PriceForListing, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += Data.Length; - return length; - } - } - public AgentDataBlock AgentData; - public DataBlock Data; - - public ClassifiedInfoReplyPacket() - { - HasVariableBlocks = false; - Type = PacketType.ClassifiedInfoReply; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 44; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - Data = new DataBlock(); - } - - public ClassifiedInfoReplyPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - Data.FromBytes(bytes, ref i); - } - - public ClassifiedInfoReplyPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - Data.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += Data.Length; - if (Header.AckList != null && 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); - Data.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class ClassifiedInfoUpdatePacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class DataBlock : PacketBlock - { - public UUID ClassifiedID; - public uint Category; - public byte[] Name; - public byte[] Desc; - public UUID ParcelID; - public uint ParentEstate; - public UUID SnapshotID; - public Vector3d PosGlobal; - public byte ClassifiedFlags; - public int PriceForListing; - - public override int Length - { - get - { - int length = 88; - if (Name != null) { length += Name.Length; } - if (Desc != null) { length += Desc.Length; } - return length; - } - } - - public DataBlock() { } - public DataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - ClassifiedID.FromBytes(bytes, i); i += 16; - Category = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - length = bytes[i++]; - Name = new byte[length]; - Buffer.BlockCopy(bytes, i, Name, 0, length); i += length; - length = (bytes[i++] + (bytes[i++] << 8)); - Desc = new byte[length]; - Buffer.BlockCopy(bytes, i, Desc, 0, length); i += length; - ParcelID.FromBytes(bytes, i); i += 16; - ParentEstate = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - SnapshotID.FromBytes(bytes, i); i += 16; - PosGlobal.FromBytes(bytes, i); i += 24; - ClassifiedFlags = (byte)bytes[i++]; - PriceForListing = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - ClassifiedID.ToBytes(bytes, i); i += 16; - Utils.UIntToBytes(Category, bytes, i); i += 4; - bytes[i++] = (byte)Name.Length; - Buffer.BlockCopy(Name, 0, bytes, i, Name.Length); i += Name.Length; - bytes[i++] = (byte)(Desc.Length % 256); - bytes[i++] = (byte)((Desc.Length >> 8) % 256); - Buffer.BlockCopy(Desc, 0, bytes, i, Desc.Length); i += Desc.Length; - ParcelID.ToBytes(bytes, i); i += 16; - Utils.UIntToBytes(ParentEstate, bytes, i); i += 4; - SnapshotID.ToBytes(bytes, i); i += 16; - PosGlobal.ToBytes(bytes, i); i += 24; - bytes[i++] = ClassifiedFlags; - Utils.IntToBytes(PriceForListing, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += Data.Length; - return length; - } - } - public AgentDataBlock AgentData; - public DataBlock Data; - - public ClassifiedInfoUpdatePacket() - { - HasVariableBlocks = false; - Type = PacketType.ClassifiedInfoUpdate; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 45; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - Data = new DataBlock(); - } - - public ClassifiedInfoUpdatePacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - Data.FromBytes(bytes, ref i); - } - - public ClassifiedInfoUpdatePacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - Data.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += Data.Length; - if (Header.AckList != null && 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); - Data.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class ClassifiedDeletePacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class DataBlock : PacketBlock - { - public UUID ClassifiedID; - - public override int Length - { - get - { - return 16; - } - } - - public DataBlock() { } - public DataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - ClassifiedID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - ClassifiedID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += Data.Length; - return length; - } - } - public AgentDataBlock AgentData; - public DataBlock Data; - - public ClassifiedDeletePacket() - { - HasVariableBlocks = false; - Type = PacketType.ClassifiedDelete; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 46; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - Data = new DataBlock(); - } - - public ClassifiedDeletePacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - Data.FromBytes(bytes, ref i); - } - - public ClassifiedDeletePacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - Data.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += Data.Length; - if (Header.AckList != null && 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); - Data.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class ClassifiedGodDeletePacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class DataBlock : PacketBlock - { - public UUID ClassifiedID; - public UUID QueryID; - - public override int Length - { - get - { - return 32; - } - } - - public DataBlock() { } - public DataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - ClassifiedID.FromBytes(bytes, i); i += 16; - QueryID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - ClassifiedID.ToBytes(bytes, i); i += 16; - QueryID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += Data.Length; - return length; - } - } - public AgentDataBlock AgentData; - public DataBlock Data; - - public ClassifiedGodDeletePacket() - { - HasVariableBlocks = false; - Type = PacketType.ClassifiedGodDelete; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 47; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - Data = new DataBlock(); - } - - public ClassifiedGodDeletePacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - Data.FromBytes(bytes, ref i); - } - - public ClassifiedGodDeletePacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - Data.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += Data.Length; - if (Header.AckList != null && 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); - Data.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class DirLandQueryPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class QueryDataBlock : PacketBlock - { - public UUID QueryID; - public uint QueryFlags; - public uint SearchType; - public int Price; - public int Area; - public int QueryStart; - - public override int Length - { - get - { - return 36; - } - } - - public QueryDataBlock() { } - public QueryDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - QueryID.FromBytes(bytes, i); i += 16; - QueryFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - SearchType = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - Price = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - Area = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - QueryStart = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - QueryID.ToBytes(bytes, i); i += 16; - Utils.UIntToBytes(QueryFlags, bytes, i); i += 4; - Utils.UIntToBytes(SearchType, bytes, i); i += 4; - Utils.IntToBytes(Price, bytes, i); i += 4; - Utils.IntToBytes(Area, bytes, i); i += 4; - Utils.IntToBytes(QueryStart, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += QueryData.Length; - return length; - } - } - public AgentDataBlock AgentData; - public QueryDataBlock QueryData; - - public DirLandQueryPacket() - { - HasVariableBlocks = false; - Type = PacketType.DirLandQuery; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 48; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - QueryData = new QueryDataBlock(); - } - - public DirLandQueryPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - QueryData.FromBytes(bytes, ref i); - } - - public DirLandQueryPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - QueryData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += QueryData.Length; - if (Header.AckList != null && 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); - QueryData.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class DirLandReplyPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - - public override int Length - { - get - { - return 16; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class QueryDataBlock : PacketBlock - { - public UUID QueryID; - - public override int Length - { - get - { - return 16; - } - } - - public QueryDataBlock() { } - public QueryDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - QueryID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - QueryID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class QueryRepliesBlock : PacketBlock - { - public UUID ParcelID; - public byte[] Name; - public bool Auction; - public bool ForSale; - public int SalePrice; - public int ActualArea; - - public override int Length - { - get - { - int length = 27; - if (Name != null) { length += Name.Length; } - return length; - } - } - - public QueryRepliesBlock() { } - public QueryRepliesBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - ParcelID.FromBytes(bytes, i); i += 16; - length = bytes[i++]; - Name = new byte[length]; - Buffer.BlockCopy(bytes, i, Name, 0, length); i += length; - Auction = (bytes[i++] != 0) ? (bool)true : (bool)false; - ForSale = (bytes[i++] != 0) ? (bool)true : (bool)false; - SalePrice = (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)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - ParcelID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)Name.Length; - Buffer.BlockCopy(Name, 0, bytes, i, Name.Length); i += Name.Length; - bytes[i++] = (byte)((Auction) ? 1 : 0); - bytes[i++] = (byte)((ForSale) ? 1 : 0); - Utils.IntToBytes(SalePrice, bytes, i); i += 4; - Utils.IntToBytes(ActualArea, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentData.Length; - length += QueryData.Length; - for (int j = 0; j < QueryReplies.Length; j++) - length += QueryReplies[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public QueryDataBlock QueryData; - public QueryRepliesBlock[] QueryReplies; - - public DirLandReplyPacket() - { - HasVariableBlocks = true; - Type = PacketType.DirLandReply; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 50; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - QueryData = new QueryDataBlock(); - QueryReplies = null; - } - - public DirLandReplyPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - QueryData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(QueryReplies == null || QueryReplies.Length != -1) { - QueryReplies = new QueryRepliesBlock[count]; - for(int j = 0; j < count; j++) - { QueryReplies[j] = new QueryRepliesBlock(); } - } - for (int j = 0; j < count; j++) - { QueryReplies[j].FromBytes(bytes, ref i); } - } - - public DirLandReplyPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - QueryData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(QueryReplies == null || QueryReplies.Length != count) { - QueryReplies = new QueryRepliesBlock[count]; - for(int j = 0; j < count; j++) - { QueryReplies[j] = new QueryRepliesBlock(); } - } - for (int j = 0; j < count; j++) - { QueryReplies[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += QueryData.Length; - length++; - for (int j = 0; j < QueryReplies.Length; j++) { length += QueryReplies[j].Length; } - if (Header.AckList != null && 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); - QueryData.ToBytes(bytes, ref i); - bytes[i++] = (byte)QueryReplies.Length; - for (int j = 0; j < QueryReplies.Length; j++) { QueryReplies[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - fixedLength += QueryData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - QueryData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int QueryRepliesStart = 0; - do - { - int variableLength = 0; - int QueryRepliesCount = 0; - - i = QueryRepliesStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < QueryReplies.Length) { - int blockLength = QueryReplies[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == QueryRepliesStart) { - variableLength += blockLength; - ++QueryRepliesCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)QueryRepliesCount; - for (i = QueryRepliesStart; i < QueryRepliesStart + QueryRepliesCount; i++) { QueryReplies[i].ToBytes(packet, ref length); } - QueryRepliesStart += QueryRepliesCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - QueryRepliesStart < QueryReplies.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class DirPopularQueryPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class QueryDataBlock : PacketBlock - { - public UUID QueryID; - public uint QueryFlags; - - public override int Length - { - get - { - return 20; - } - } - - public QueryDataBlock() { } - public QueryDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - QueryID.FromBytes(bytes, i); i += 16; - QueryFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - QueryID.ToBytes(bytes, i); i += 16; - Utils.UIntToBytes(QueryFlags, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += QueryData.Length; - return length; - } - } - public AgentDataBlock AgentData; - public QueryDataBlock QueryData; - - public DirPopularQueryPacket() - { - HasVariableBlocks = false; - Type = PacketType.DirPopularQuery; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 51; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - QueryData = new QueryDataBlock(); - } - - public DirPopularQueryPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - QueryData.FromBytes(bytes, ref i); - } - - public DirPopularQueryPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - QueryData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += QueryData.Length; - if (Header.AckList != null && 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); - QueryData.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class DirPopularReplyPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - - public override int Length - { - get - { - return 16; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class QueryDataBlock : PacketBlock - { - public UUID QueryID; - - public override int Length - { - get - { - return 16; - } - } - - public QueryDataBlock() { } - public QueryDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - QueryID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - QueryID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class QueryRepliesBlock : PacketBlock - { - public UUID ParcelID; - public byte[] Name; - public float Dwell; - - public override int Length - { - get - { - int length = 21; - if (Name != null) { length += Name.Length; } - return length; - } - } - - public QueryRepliesBlock() { } - public QueryRepliesBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - ParcelID.FromBytes(bytes, i); i += 16; - length = bytes[i++]; - Name = new byte[length]; - Buffer.BlockCopy(bytes, i, Name, 0, length); i += length; - Dwell = Utils.BytesToFloat(bytes, i); i += 4; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - ParcelID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)Name.Length; - Buffer.BlockCopy(Name, 0, bytes, i, Name.Length); i += Name.Length; - Utils.FloatToBytes(Dwell, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentData.Length; - length += QueryData.Length; - for (int j = 0; j < QueryReplies.Length; j++) - length += QueryReplies[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public QueryDataBlock QueryData; - public QueryRepliesBlock[] QueryReplies; - - public DirPopularReplyPacket() - { - HasVariableBlocks = true; - Type = PacketType.DirPopularReply; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 53; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - QueryData = new QueryDataBlock(); - QueryReplies = null; - } - - public DirPopularReplyPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - QueryData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(QueryReplies == null || QueryReplies.Length != -1) { - QueryReplies = new QueryRepliesBlock[count]; - for(int j = 0; j < count; j++) - { QueryReplies[j] = new QueryRepliesBlock(); } - } - for (int j = 0; j < count; j++) - { QueryReplies[j].FromBytes(bytes, ref i); } - } - - public DirPopularReplyPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - QueryData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(QueryReplies == null || QueryReplies.Length != count) { - QueryReplies = new QueryRepliesBlock[count]; - for(int j = 0; j < count; j++) - { QueryReplies[j] = new QueryRepliesBlock(); } - } - for (int j = 0; j < count; j++) - { QueryReplies[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += QueryData.Length; - length++; - for (int j = 0; j < QueryReplies.Length; j++) { length += QueryReplies[j].Length; } - if (Header.AckList != null && 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); - QueryData.ToBytes(bytes, ref i); - bytes[i++] = (byte)QueryReplies.Length; - for (int j = 0; j < QueryReplies.Length; j++) { QueryReplies[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - fixedLength += QueryData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - QueryData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int QueryRepliesStart = 0; - do - { - int variableLength = 0; - int QueryRepliesCount = 0; - - i = QueryRepliesStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < QueryReplies.Length) { - int blockLength = QueryReplies[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == QueryRepliesStart) { - variableLength += blockLength; - ++QueryRepliesCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)QueryRepliesCount; - for (i = QueryRepliesStart; i < QueryRepliesStart + QueryRepliesCount; i++) { QueryReplies[i].ToBytes(packet, ref length); } - QueryRepliesStart += QueryRepliesCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - QueryRepliesStart < QueryReplies.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class ParcelInfoRequestPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class DataBlock : PacketBlock - { - public UUID ParcelID; - - public override int Length - { - get - { - return 16; - } - } - - public DataBlock() { } - public DataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - ParcelID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - ParcelID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += Data.Length; - return length; - } - } - public AgentDataBlock AgentData; - public DataBlock Data; - - public ParcelInfoRequestPacket() - { - HasVariableBlocks = false; - Type = PacketType.ParcelInfoRequest; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 54; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - Data = new DataBlock(); - } - - public ParcelInfoRequestPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - Data.FromBytes(bytes, ref i); - } - - public ParcelInfoRequestPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - Data.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += Data.Length; - if (Header.AckList != null && 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); - Data.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class ParcelInfoReplyPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - - public override int Length - { - get - { - return 16; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class DataBlock : PacketBlock - { - public UUID ParcelID; - public UUID OwnerID; - public byte[] Name; - public byte[] Desc; - public int ActualArea; - public int BillableArea; - public byte Flags; - public float GlobalX; - public float GlobalY; - public float GlobalZ; - public byte[] SimName; - public UUID SnapshotID; - public float Dwell; - public int SalePrice; - public int AuctionID; - - public override int Length - { - get - { - int length = 84; - if (Name != null) { length += Name.Length; } - if (Desc != null) { length += Desc.Length; } - if (SimName != null) { length += SimName.Length; } - return length; - } - } - - public DataBlock() { } - public DataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - ParcelID.FromBytes(bytes, i); i += 16; - OwnerID.FromBytes(bytes, i); i += 16; - length = bytes[i++]; - Name = new byte[length]; - Buffer.BlockCopy(bytes, i, Name, 0, length); i += length; - length = bytes[i++]; - Desc = new byte[length]; - Buffer.BlockCopy(bytes, i, Desc, 0, length); i += length; - ActualArea = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - BillableArea = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - Flags = (byte)bytes[i++]; - GlobalX = Utils.BytesToFloat(bytes, i); i += 4; - GlobalY = Utils.BytesToFloat(bytes, i); i += 4; - GlobalZ = Utils.BytesToFloat(bytes, i); i += 4; - length = bytes[i++]; - SimName = new byte[length]; - Buffer.BlockCopy(bytes, i, SimName, 0, length); i += length; - SnapshotID.FromBytes(bytes, i); i += 16; - Dwell = Utils.BytesToFloat(bytes, i); i += 4; - SalePrice = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - AuctionID = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - ParcelID.ToBytes(bytes, i); i += 16; - OwnerID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)Name.Length; - Buffer.BlockCopy(Name, 0, bytes, i, Name.Length); i += Name.Length; - bytes[i++] = (byte)Desc.Length; - Buffer.BlockCopy(Desc, 0, bytes, i, Desc.Length); i += Desc.Length; - Utils.IntToBytes(ActualArea, bytes, i); i += 4; - Utils.IntToBytes(BillableArea, bytes, i); i += 4; - bytes[i++] = Flags; - Utils.FloatToBytes(GlobalX, bytes, i); i += 4; - Utils.FloatToBytes(GlobalY, bytes, i); i += 4; - Utils.FloatToBytes(GlobalZ, bytes, i); i += 4; - bytes[i++] = (byte)SimName.Length; - Buffer.BlockCopy(SimName, 0, bytes, i, SimName.Length); i += SimName.Length; - SnapshotID.ToBytes(bytes, i); i += 16; - Utils.FloatToBytes(Dwell, bytes, i); i += 4; - Utils.IntToBytes(SalePrice, bytes, i); i += 4; - Utils.IntToBytes(AuctionID, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += Data.Length; - return length; - } - } - public AgentDataBlock AgentData; - public DataBlock Data; - - public ParcelInfoReplyPacket() - { - HasVariableBlocks = false; - Type = PacketType.ParcelInfoReply; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 55; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - Data = new DataBlock(); - } - - public ParcelInfoReplyPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - Data.FromBytes(bytes, ref i); - } - - public ParcelInfoReplyPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - Data.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += Data.Length; - if (Header.AckList != null && 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); - Data.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class ParcelObjectOwnersRequestPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class ParcelDataBlock : PacketBlock - { - public int LocalID; - - public override int Length - { - get - { - return 4; - } - } - - public ParcelDataBlock() { } - public ParcelDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - LocalID = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.IntToBytes(LocalID, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += ParcelData.Length; - return length; - } - } - public AgentDataBlock AgentData; - public ParcelDataBlock ParcelData; - - public ParcelObjectOwnersRequestPacket() - { - HasVariableBlocks = false; - Type = PacketType.ParcelObjectOwnersRequest; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 56; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - ParcelData = new ParcelDataBlock(); - } - - public ParcelObjectOwnersRequestPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - ParcelData.FromBytes(bytes, ref i); - } - - public ParcelObjectOwnersRequestPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - ParcelData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += ParcelData.Length; - if (Header.AckList != null && 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); - ParcelData.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class ParcelObjectOwnersReplyPacket : Packet - { - /// - public sealed class DataBlock : PacketBlock - { - public UUID OwnerID; - public bool IsGroupOwned; - public int Count; - public bool OnlineStatus; - - public override int Length - { - get - { - return 22; - } - } - - public DataBlock() { } - public DataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - OwnerID.FromBytes(bytes, i); i += 16; - IsGroupOwned = (bytes[i++] != 0) ? (bool)true : (bool)false; - Count = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - OnlineStatus = (bytes[i++] != 0) ? (bool)true : (bool)false; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - OwnerID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)((IsGroupOwned) ? 1 : 0); - Utils.IntToBytes(Count, bytes, i); i += 4; - bytes[i++] = (byte)((OnlineStatus) ? 1 : 0); - } - - } - - public override int Length - { - get - { - int length = 11; - for (int j = 0; j < Data.Length; j++) - length += Data[j].Length; - return length; - } - } - public DataBlock[] Data; - - public ParcelObjectOwnersReplyPacket() - { - HasVariableBlocks = true; - Type = PacketType.ParcelObjectOwnersReply; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 57; - Header.Reliable = true; - Header.Zerocoded = true; - Data = null; - } - - public ParcelObjectOwnersReplyPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - int count = (int)bytes[i++]; - if(Data == null || Data.Length != -1) { - Data = new DataBlock[count]; - for(int j = 0; j < count; j++) - { Data[j] = new DataBlock(); } - } - for (int j = 0; j < count; j++) - { Data[j].FromBytes(bytes, ref i); } - } - - public ParcelObjectOwnersReplyPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - int count = (int)bytes[i++]; - if(Data == null || Data.Length != count) { - Data = new DataBlock[count]; - for(int j = 0; j < count; j++) - { Data[j] = new DataBlock(); } - } - for (int j = 0; j < count; j++) - { Data[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length++; - for (int j = 0; j < Data.Length; j++) { length += Data[j].Length; } - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int DataStart = 0; - do - { - int variableLength = 0; - int DataCount = 0; - - i = DataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < Data.Length) { - int blockLength = Data[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == DataStart) { - variableLength += blockLength; - ++DataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)DataCount; - for (i = DataStart; i < DataStart + DataCount; i++) { Data[i].ToBytes(packet, ref length); } - DataStart += DataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - DataStart < Data.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class GroupNoticesListRequestPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class DataBlock : PacketBlock - { - public UUID GroupID; - - public override int Length - { - get - { - return 16; - } - } - - public DataBlock() { } - public DataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - GroupID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - GroupID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += Data.Length; - return length; - } - } - public AgentDataBlock AgentData; - public DataBlock Data; - - public GroupNoticesListRequestPacket() - { - HasVariableBlocks = false; - Type = PacketType.GroupNoticesListRequest; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 58; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - Data = new DataBlock(); - } - - public GroupNoticesListRequestPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - Data.FromBytes(bytes, ref i); - } - - public GroupNoticesListRequestPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - Data.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += Data.Length; - if (Header.AckList != null && 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); - Data.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class GroupNoticesListReplyPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID GroupID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - GroupID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - GroupID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class DataBlock : PacketBlock - { - public UUID NoticeID; - public uint Timestamp; - public byte[] FromName; - public byte[] Subject; - public bool HasAttachment; - public byte AssetType; - - public override int Length - { - get - { - int length = 26; - if (FromName != null) { length += FromName.Length; } - if (Subject != null) { length += Subject.Length; } - return length; - } - } - - public DataBlock() { } - public DataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - NoticeID.FromBytes(bytes, i); i += 16; - Timestamp = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - length = (bytes[i++] + (bytes[i++] << 8)); - FromName = new byte[length]; - Buffer.BlockCopy(bytes, i, FromName, 0, length); i += length; - length = (bytes[i++] + (bytes[i++] << 8)); - Subject = new byte[length]; - Buffer.BlockCopy(bytes, i, Subject, 0, length); i += length; - HasAttachment = (bytes[i++] != 0) ? (bool)true : (bool)false; - AssetType = (byte)bytes[i++]; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - NoticeID.ToBytes(bytes, i); i += 16; - Utils.UIntToBytes(Timestamp, bytes, i); i += 4; - bytes[i++] = (byte)(FromName.Length % 256); - bytes[i++] = (byte)((FromName.Length >> 8) % 256); - Buffer.BlockCopy(FromName, 0, bytes, i, FromName.Length); i += FromName.Length; - bytes[i++] = (byte)(Subject.Length % 256); - bytes[i++] = (byte)((Subject.Length >> 8) % 256); - Buffer.BlockCopy(Subject, 0, bytes, i, Subject.Length); i += Subject.Length; - bytes[i++] = (byte)((HasAttachment) ? 1 : 0); - bytes[i++] = AssetType; - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentData.Length; - for (int j = 0; j < Data.Length; j++) - length += Data[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public DataBlock[] Data; - - public GroupNoticesListReplyPacket() - { - HasVariableBlocks = true; - Type = PacketType.GroupNoticesListReply; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 59; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - Data = null; - } - - public GroupNoticesListReplyPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(Data == null || Data.Length != -1) { - Data = new DataBlock[count]; - for(int j = 0; j < count; j++) - { Data[j] = new DataBlock(); } - } - for (int j = 0; j < count; j++) - { Data[j].FromBytes(bytes, ref i); } - } - - public GroupNoticesListReplyPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(Data == null || Data.Length != count) { - Data = new DataBlock[count]; - for(int j = 0; j < count; j++) - { Data[j] = new DataBlock(); } - } - for (int j = 0; j < count; j++) - { Data[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length++; - for (int j = 0; j < Data.Length; j++) { length += Data[j].Length; } - if (Header.AckList != null && 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)Data.Length; - for (int j = 0; j < Data.Length; j++) { Data[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int DataStart = 0; - do - { - int variableLength = 0; - int DataCount = 0; - - i = DataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < Data.Length) { - int blockLength = Data[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == DataStart) { - variableLength += blockLength; - ++DataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)DataCount; - for (i = DataStart; i < DataStart + DataCount; i++) { Data[i].ToBytes(packet, ref length); } - DataStart += DataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - DataStart < Data.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class GroupNoticeRequestPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class DataBlock : PacketBlock - { - public UUID GroupNoticeID; - - public override int Length - { - get - { - return 16; - } - } - - public DataBlock() { } - public DataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - GroupNoticeID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - GroupNoticeID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += Data.Length; - return length; - } - } - public AgentDataBlock AgentData; - public DataBlock Data; - - public GroupNoticeRequestPacket() - { - HasVariableBlocks = false; - Type = PacketType.GroupNoticeRequest; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 60; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - Data = new DataBlock(); - } - - public GroupNoticeRequestPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - Data.FromBytes(bytes, ref i); - } - - public GroupNoticeRequestPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - Data.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += Data.Length; - if (Header.AckList != null && 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); - Data.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class TeleportRequestPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class InfoBlock : PacketBlock - { - public UUID RegionID; - public Vector3 Position; - public Vector3 LookAt; - - public override int Length - { - get - { - return 40; - } - } - - public InfoBlock() { } - public InfoBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - RegionID.FromBytes(bytes, i); i += 16; - Position.FromBytes(bytes, i); i += 12; - LookAt.FromBytes(bytes, i); i += 12; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - RegionID.ToBytes(bytes, i); i += 16; - Position.ToBytes(bytes, i); i += 12; - LookAt.ToBytes(bytes, i); i += 12; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += Info.Length; - return length; - } - } - public AgentDataBlock AgentData; - public InfoBlock Info; - - public TeleportRequestPacket() - { - HasVariableBlocks = false; - Type = PacketType.TeleportRequest; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 62; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - Info = new InfoBlock(); - } - - public TeleportRequestPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - Info.FromBytes(bytes, ref i); - } - - public TeleportRequestPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - Info.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += Info.Length; - if (Header.AckList != null && 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); - Info.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class TeleportLocationRequestPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class InfoBlock : PacketBlock - { - public ulong RegionHandle; - public Vector3 Position; - public Vector3 LookAt; - - public override int Length - { - get - { - return 32; - } - } - - public InfoBlock() { } - public InfoBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(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)); - Position.FromBytes(bytes, i); i += 12; - LookAt.FromBytes(bytes, i); i += 12; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UInt64ToBytes(RegionHandle, bytes, i); i += 8; - Position.ToBytes(bytes, i); i += 12; - LookAt.ToBytes(bytes, i); i += 12; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += Info.Length; - return length; - } - } - public AgentDataBlock AgentData; - public InfoBlock Info; - - public TeleportLocationRequestPacket() - { - HasVariableBlocks = false; - Type = PacketType.TeleportLocationRequest; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 63; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - Info = new InfoBlock(); - } - - public TeleportLocationRequestPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - Info.FromBytes(bytes, ref i); - } - - public TeleportLocationRequestPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - Info.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += Info.Length; - if (Header.AckList != null && 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); - Info.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class TeleportLocalPacket : Packet - { - /// - public sealed class InfoBlock : PacketBlock - { - public UUID AgentID; - public uint LocationID; - public Vector3 Position; - public Vector3 LookAt; - public uint TeleportFlags; - - public override int Length - { - get - { - return 48; - } - } - - public InfoBlock() { } - public InfoBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - LocationID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - Position.FromBytes(bytes, i); i += 12; - LookAt.FromBytes(bytes, i); i += 12; - TeleportFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - Utils.UIntToBytes(LocationID, bytes, i); i += 4; - Position.ToBytes(bytes, i); i += 12; - LookAt.ToBytes(bytes, i); i += 12; - Utils.UIntToBytes(TeleportFlags, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 10; - length += Info.Length; - return length; - } - } - public InfoBlock Info; - - public TeleportLocalPacket() - { - HasVariableBlocks = false; - Type = PacketType.TeleportLocal; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 64; - Header.Reliable = true; - Info = new InfoBlock(); - } - - public TeleportLocalPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - Info.FromBytes(bytes, ref i); - } - - public TeleportLocalPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - Info.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += Info.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class TeleportLandmarkRequestPacket : Packet - { - /// - public sealed class InfoBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - public UUID LandmarkID; - - public override int Length - { - get - { - return 48; - } - } - - public InfoBlock() { } - public InfoBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - LandmarkID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - LandmarkID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 10; - length += Info.Length; - return length; - } - } - public InfoBlock Info; - - public TeleportLandmarkRequestPacket() - { - HasVariableBlocks = false; - Type = PacketType.TeleportLandmarkRequest; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 65; - Header.Reliable = true; - Header.Zerocoded = true; - Info = new InfoBlock(); - } - - public TeleportLandmarkRequestPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - Info.FromBytes(bytes, ref i); - } - - public TeleportLandmarkRequestPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - Info.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += Info.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class TeleportProgressPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - - public override int Length - { - get - { - return 16; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class InfoBlock : PacketBlock - { - public uint TeleportFlags; - public byte[] Message; - - public override int Length - { - get - { - int length = 5; - if (Message != null) { length += Message.Length; } - return length; - } - } - - public InfoBlock() { } - public InfoBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - TeleportFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - length = bytes[i++]; - Message = new byte[length]; - Buffer.BlockCopy(bytes, i, Message, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UIntToBytes(TeleportFlags, bytes, i); i += 4; - bytes[i++] = (byte)Message.Length; - Buffer.BlockCopy(Message, 0, bytes, i, Message.Length); i += Message.Length; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += Info.Length; - return length; - } - } - public AgentDataBlock AgentData; - public InfoBlock Info; - - public TeleportProgressPacket() - { - HasVariableBlocks = false; - Type = PacketType.TeleportProgress; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 66; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - Info = new InfoBlock(); - } - - public TeleportProgressPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - Info.FromBytes(bytes, ref i); - } - - public TeleportProgressPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - Info.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += Info.Length; - if (Header.AckList != null && 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); - Info.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class TeleportFinishPacket : Packet - { - /// - public sealed class InfoBlock : PacketBlock - { - public UUID AgentID; - public uint LocationID; - public uint SimIP; - public ushort SimPort; - public ulong RegionHandle; - public byte[] SeedCapability; - public byte SimAccess; - public uint TeleportFlags; - - public override int Length - { - get - { - int length = 41; - if (SeedCapability != null) { length += SeedCapability.Length; } - return length; - } - } - - public InfoBlock() { } - public InfoBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - AgentID.FromBytes(bytes, i); i += 16; - LocationID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - SimIP = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - 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)); - length = (bytes[i++] + (bytes[i++] << 8)); - SeedCapability = new byte[length]; - Buffer.BlockCopy(bytes, i, SeedCapability, 0, length); i += length; - SimAccess = (byte)bytes[i++]; - TeleportFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - Utils.UIntToBytes(LocationID, bytes, i); i += 4; - Utils.UIntToBytes(SimIP, bytes, i); i += 4; - bytes[i++] = (byte)((SimPort >> 8) % 256); - bytes[i++] = (byte)(SimPort % 256); - Utils.UInt64ToBytes(RegionHandle, bytes, i); i += 8; - bytes[i++] = (byte)(SeedCapability.Length % 256); - bytes[i++] = (byte)((SeedCapability.Length >> 8) % 256); - Buffer.BlockCopy(SeedCapability, 0, bytes, i, SeedCapability.Length); i += SeedCapability.Length; - bytes[i++] = SimAccess; - Utils.UIntToBytes(TeleportFlags, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 10; - length += Info.Length; - return length; - } - } - public InfoBlock Info; - - public TeleportFinishPacket() - { - HasVariableBlocks = false; - Type = PacketType.TeleportFinish; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 69; - Header.Reliable = true; - Info = new InfoBlock(); - } - - public TeleportFinishPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - Info.FromBytes(bytes, ref i); - } - - public TeleportFinishPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - Info.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += Info.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class StartLurePacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class InfoBlock : PacketBlock - { - public byte LureType; - public byte[] Message; - - public override int Length - { - get - { - int length = 2; - if (Message != null) { length += Message.Length; } - return length; - } - } - - public InfoBlock() { } - public InfoBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - LureType = (byte)bytes[i++]; - length = bytes[i++]; - Message = new byte[length]; - Buffer.BlockCopy(bytes, i, Message, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - bytes[i++] = LureType; - bytes[i++] = (byte)Message.Length; - Buffer.BlockCopy(Message, 0, bytes, i, Message.Length); i += Message.Length; - } - - } - - /// - public sealed class TargetDataBlock : PacketBlock - { - public UUID TargetID; - - public override int Length - { - get - { - return 16; - } - } - - public TargetDataBlock() { } - public TargetDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - TargetID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - TargetID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentData.Length; - length += Info.Length; - for (int j = 0; j < TargetData.Length; j++) - length += TargetData[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public InfoBlock Info; - public TargetDataBlock[] TargetData; - - public StartLurePacket() - { - HasVariableBlocks = true; - Type = PacketType.StartLure; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 70; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - Info = new InfoBlock(); - TargetData = null; - } - - public StartLurePacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - Info.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(TargetData == null || TargetData.Length != -1) { - TargetData = new TargetDataBlock[count]; - for(int j = 0; j < count; j++) - { TargetData[j] = new TargetDataBlock(); } - } - for (int j = 0; j < count; j++) - { TargetData[j].FromBytes(bytes, ref i); } - } - - public StartLurePacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - Info.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(TargetData == null || TargetData.Length != count) { - TargetData = new TargetDataBlock[count]; - for(int j = 0; j < count; j++) - { TargetData[j] = new TargetDataBlock(); } - } - for (int j = 0; j < count; j++) - { TargetData[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += Info.Length; - length++; - for (int j = 0; j < TargetData.Length; j++) { length += TargetData[j].Length; } - if (Header.AckList != null && 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); - Info.ToBytes(bytes, ref i); - bytes[i++] = (byte)TargetData.Length; - for (int j = 0; j < TargetData.Length; j++) { TargetData[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - fixedLength += Info.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - Info.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int TargetDataStart = 0; - do - { - int variableLength = 0; - int TargetDataCount = 0; - - i = TargetDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < TargetData.Length) { - int blockLength = TargetData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == TargetDataStart) { - variableLength += blockLength; - ++TargetDataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)TargetDataCount; - for (i = TargetDataStart; i < TargetDataStart + TargetDataCount; i++) { TargetData[i].ToBytes(packet, ref length); } - TargetDataStart += TargetDataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - TargetDataStart < TargetData.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class TeleportLureRequestPacket : Packet - { - /// - public sealed class InfoBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - public UUID LureID; - public uint TeleportFlags; - - public override int Length - { - get - { - return 52; - } - } - - public InfoBlock() { } - public InfoBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - LureID.FromBytes(bytes, i); i += 16; - TeleportFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - LureID.ToBytes(bytes, i); i += 16; - Utils.UIntToBytes(TeleportFlags, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 10; - length += Info.Length; - return length; - } - } - public InfoBlock Info; - - public TeleportLureRequestPacket() - { - HasVariableBlocks = false; - Type = PacketType.TeleportLureRequest; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 71; - Header.Reliable = true; - Info = new InfoBlock(); - } - - public TeleportLureRequestPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - Info.FromBytes(bytes, ref i); - } - - public TeleportLureRequestPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - Info.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += Info.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class TeleportCancelPacket : Packet - { - /// - public sealed class InfoBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public InfoBlock() { } - public InfoBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 10; - length += Info.Length; - return length; - } - } - public InfoBlock Info; - - public TeleportCancelPacket() - { - HasVariableBlocks = false; - Type = PacketType.TeleportCancel; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 72; - Header.Reliable = true; - Info = new InfoBlock(); - } - - public TeleportCancelPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - Info.FromBytes(bytes, ref i); - } - - public TeleportCancelPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - Info.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += Info.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class TeleportStartPacket : Packet - { - /// - public sealed class InfoBlock : PacketBlock - { - public uint TeleportFlags; - - public override int Length - { - get - { - return 4; - } - } - - public InfoBlock() { } - public InfoBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - TeleportFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UIntToBytes(TeleportFlags, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 10; - length += Info.Length; - return length; - } - } - public InfoBlock Info; - - public TeleportStartPacket() - { - HasVariableBlocks = false; - Type = PacketType.TeleportStart; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 73; - Header.Reliable = true; - Info = new InfoBlock(); - } - - public TeleportStartPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - Info.FromBytes(bytes, ref i); - } - - public TeleportStartPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - Info.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += Info.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class TeleportFailedPacket : Packet - { - /// - public sealed class InfoBlock : PacketBlock - { - public UUID AgentID; - public byte[] Reason; - - public override int Length - { - get - { - int length = 17; - if (Reason != null) { length += Reason.Length; } - return length; - } - } - - public InfoBlock() { } - public InfoBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - AgentID.FromBytes(bytes, i); i += 16; - length = bytes[i++]; - Reason = new byte[length]; - Buffer.BlockCopy(bytes, i, Reason, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)Reason.Length; - Buffer.BlockCopy(Reason, 0, bytes, i, Reason.Length); i += Reason.Length; - } - - } - - /// - public sealed class AlertInfoBlock : PacketBlock - { - public byte[] Message; - public byte[] ExtraParams; - - public override int Length - { - get - { - int length = 2; - if (Message != null) { length += Message.Length; } - if (ExtraParams != null) { length += ExtraParams.Length; } - return length; - } - } - - public AlertInfoBlock() { } - public AlertInfoBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - length = bytes[i++]; - Message = new byte[length]; - Buffer.BlockCopy(bytes, i, Message, 0, length); i += length; - length = bytes[i++]; - ExtraParams = new byte[length]; - Buffer.BlockCopy(bytes, i, ExtraParams, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - bytes[i++] = (byte)Message.Length; - Buffer.BlockCopy(Message, 0, bytes, i, Message.Length); i += Message.Length; - bytes[i++] = (byte)ExtraParams.Length; - Buffer.BlockCopy(ExtraParams, 0, bytes, i, ExtraParams.Length); i += ExtraParams.Length; - } - - } - - public override int Length - { - get - { - int length = 11; - length += Info.Length; - for (int j = 0; j < AlertInfo.Length; j++) - length += AlertInfo[j].Length; - return length; - } - } - public InfoBlock Info; - public AlertInfoBlock[] AlertInfo; - - public TeleportFailedPacket() - { - HasVariableBlocks = true; - Type = PacketType.TeleportFailed; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 74; - Header.Reliable = true; - Info = new InfoBlock(); - AlertInfo = null; - } - - public TeleportFailedPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - Info.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(AlertInfo == null || AlertInfo.Length != -1) { - AlertInfo = new AlertInfoBlock[count]; - for(int j = 0; j < count; j++) - { AlertInfo[j] = new AlertInfoBlock(); } - } - for (int j = 0; j < count; j++) - { AlertInfo[j].FromBytes(bytes, ref i); } - } - - public TeleportFailedPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - Info.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(AlertInfo == null || AlertInfo.Length != count) { - AlertInfo = new AlertInfoBlock[count]; - for(int j = 0; j < count; j++) - { AlertInfo[j] = new AlertInfoBlock(); } - } - for (int j = 0; j < count; j++) - { AlertInfo[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += Info.Length; - length++; - for (int j = 0; j < AlertInfo.Length; j++) { length += AlertInfo[j].Length; } - if (Header.AckList != null && 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); - bytes[i++] = (byte)AlertInfo.Length; - for (int j = 0; j < AlertInfo.Length; j++) { AlertInfo[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += Info.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - Info.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int AlertInfoStart = 0; - do - { - int variableLength = 0; - int AlertInfoCount = 0; - - i = AlertInfoStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < AlertInfo.Length) { - int blockLength = AlertInfo[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == AlertInfoStart) { - variableLength += blockLength; - ++AlertInfoCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)AlertInfoCount; - for (i = AlertInfoStart; i < AlertInfoStart + AlertInfoCount; i++) { AlertInfo[i].ToBytes(packet, ref length); } - AlertInfoStart += AlertInfoCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - AlertInfoStart < AlertInfo.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class UndoPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - public UUID GroupID; - - public override int Length - { - get - { - return 48; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - GroupID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - GroupID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class ObjectDataBlock : PacketBlock - { - public UUID ObjectID; - - public override int Length - { - get - { - return 16; - } - } - - public ObjectDataBlock() { } - public ObjectDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - ObjectID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - ObjectID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentData.Length; - for (int j = 0; j < ObjectData.Length; j++) - length += ObjectData[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public ObjectDataBlock[] ObjectData; - - public UndoPacket() - { - HasVariableBlocks = true; - Type = PacketType.Undo; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 75; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - ObjectData = null; - } - - public UndoPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ObjectData == null || ObjectData.Length != -1) { - ObjectData = new ObjectDataBlock[count]; - for(int j = 0; j < count; j++) - { ObjectData[j] = new ObjectDataBlock(); } - } - for (int j = 0; j < count; j++) - { ObjectData[j].FromBytes(bytes, ref i); } - } - - public UndoPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ObjectData == null || ObjectData.Length != count) { - ObjectData = new ObjectDataBlock[count]; - for(int j = 0; j < count; j++) - { ObjectData[j] = new ObjectDataBlock(); } - } - for (int j = 0; j < count; j++) - { ObjectData[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length++; - for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } - if (Header.AckList != null && 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)ObjectData.Length; - for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int ObjectDataStart = 0; - do - { - int variableLength = 0; - int ObjectDataCount = 0; - - i = ObjectDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < ObjectData.Length) { - int blockLength = ObjectData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ObjectDataStart) { - variableLength += blockLength; - ++ObjectDataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)ObjectDataCount; - for (i = ObjectDataStart; i < ObjectDataStart + ObjectDataCount; i++) { ObjectData[i].ToBytes(packet, ref length); } - ObjectDataStart += ObjectDataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - ObjectDataStart < ObjectData.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class RedoPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - public UUID GroupID; - - public override int Length - { - get - { - return 48; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - GroupID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - GroupID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class ObjectDataBlock : PacketBlock - { - public UUID ObjectID; - - public override int Length - { - get - { - return 16; - } - } - - public ObjectDataBlock() { } - public ObjectDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - ObjectID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - ObjectID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentData.Length; - for (int j = 0; j < ObjectData.Length; j++) - length += ObjectData[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public ObjectDataBlock[] ObjectData; - - public RedoPacket() - { - HasVariableBlocks = true; - Type = PacketType.Redo; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 76; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - ObjectData = null; - } - - public RedoPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ObjectData == null || ObjectData.Length != -1) { - ObjectData = new ObjectDataBlock[count]; - for(int j = 0; j < count; j++) - { ObjectData[j] = new ObjectDataBlock(); } - } - for (int j = 0; j < count; j++) - { ObjectData[j].FromBytes(bytes, ref i); } - } - - public RedoPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ObjectData == null || ObjectData.Length != count) { - ObjectData = new ObjectDataBlock[count]; - for(int j = 0; j < count; j++) - { ObjectData[j] = new ObjectDataBlock(); } - } - for (int j = 0; j < count; j++) - { ObjectData[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length++; - for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } - if (Header.AckList != null && 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)ObjectData.Length; - for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int ObjectDataStart = 0; - do - { - int variableLength = 0; - int ObjectDataCount = 0; - - i = ObjectDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < ObjectData.Length) { - int blockLength = ObjectData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ObjectDataStart) { - variableLength += blockLength; - ++ObjectDataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)ObjectDataCount; - for (i = ObjectDataStart; i < ObjectDataStart + ObjectDataCount; i++) { ObjectData[i].ToBytes(packet, ref length); } - ObjectDataStart += ObjectDataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - ObjectDataStart < ObjectData.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class UndoLandPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - return length; - } - } - public AgentDataBlock AgentData; - - public UndoLandPacket() - { - HasVariableBlocks = false; - Type = PacketType.UndoLand; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 77; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - } - - public UndoLandPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - } - - public UndoLandPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class AgentPausePacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - public uint SerialNum; - - public override int Length - { - get - { - return 36; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - SerialNum = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - Utils.UIntToBytes(SerialNum, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - return length; - } - } - public AgentDataBlock AgentData; - - public AgentPausePacket() - { - HasVariableBlocks = false; - Type = PacketType.AgentPause; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 78; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - } - - public AgentPausePacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - } - - public AgentPausePacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class AgentResumePacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - public uint SerialNum; - - public override int Length - { - get - { - return 36; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - SerialNum = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - Utils.UIntToBytes(SerialNum, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - return length; - } - } - public AgentDataBlock AgentData; - - public AgentResumePacket() - { - HasVariableBlocks = false; - Type = PacketType.AgentResume; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 79; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - } - - public AgentResumePacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - } - - public AgentResumePacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class ChatFromViewerPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class ChatDataBlock : PacketBlock - { - public byte[] Message; - public byte Type; - public int Channel; - - public override int Length - { - get - { - int length = 7; - if (Message != null) { length += Message.Length; } - return length; - } - } - - public ChatDataBlock() { } - public ChatDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - length = (bytes[i++] + (bytes[i++] << 8)); - Message = new byte[length]; - Buffer.BlockCopy(bytes, i, Message, 0, length); i += length; - Type = (byte)bytes[i++]; - Channel = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - bytes[i++] = (byte)(Message.Length % 256); - bytes[i++] = (byte)((Message.Length >> 8) % 256); - Buffer.BlockCopy(Message, 0, bytes, i, Message.Length); i += Message.Length; - bytes[i++] = Type; - Utils.IntToBytes(Channel, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += ChatData.Length; - return length; - } - } - public AgentDataBlock AgentData; - public ChatDataBlock ChatData; - - public ChatFromViewerPacket() - { - HasVariableBlocks = false; - Type = PacketType.ChatFromViewer; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 80; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - ChatData = new ChatDataBlock(); - } - - public ChatFromViewerPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - ChatData.FromBytes(bytes, ref i); - } - - public ChatFromViewerPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - ChatData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += ChatData.Length; - if (Header.AckList != null && 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); - ChatData.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class AgentThrottlePacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - public uint CircuitCode; - - public override int Length - { - get - { - return 36; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - CircuitCode = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - Utils.UIntToBytes(CircuitCode, bytes, i); i += 4; - } - - } - - /// - public sealed class ThrottleBlock : PacketBlock - { - public uint GenCounter; - public byte[] Throttles; - - public override int Length - { - get - { - int length = 5; - if (Throttles != null) { length += Throttles.Length; } - return length; - } - } - - public ThrottleBlock() { } - public ThrottleBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - GenCounter = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - length = bytes[i++]; - Throttles = new byte[length]; - Buffer.BlockCopy(bytes, i, Throttles, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UIntToBytes(GenCounter, bytes, i); i += 4; - bytes[i++] = (byte)Throttles.Length; - Buffer.BlockCopy(Throttles, 0, bytes, i, Throttles.Length); i += Throttles.Length; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += Throttle.Length; - return length; - } - } - public AgentDataBlock AgentData; - public ThrottleBlock Throttle; - - public AgentThrottlePacket() - { - HasVariableBlocks = false; - Type = PacketType.AgentThrottle; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 81; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - Throttle = new ThrottleBlock(); - } - - public AgentThrottlePacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - Throttle.FromBytes(bytes, ref i); - } - - public AgentThrottlePacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - Throttle.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += Throttle.Length; - if (Header.AckList != null && 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); - Throttle.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class AgentFOVPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - public uint CircuitCode; - - public override int Length - { - get - { - return 36; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - CircuitCode = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - Utils.UIntToBytes(CircuitCode, bytes, i); i += 4; - } - - } - - /// - public sealed class FOVBlockBlock : PacketBlock - { - public uint GenCounter; - public float VerticalAngle; - - public override int Length - { - get - { - return 8; - } - } - - public FOVBlockBlock() { } - public FOVBlockBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - GenCounter = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - VerticalAngle = Utils.BytesToFloat(bytes, i); i += 4; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UIntToBytes(GenCounter, bytes, i); i += 4; - Utils.FloatToBytes(VerticalAngle, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += FOVBlock.Length; - return length; - } - } - public AgentDataBlock AgentData; - public FOVBlockBlock FOVBlock; - - public AgentFOVPacket() - { - HasVariableBlocks = false; - Type = PacketType.AgentFOV; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 82; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - FOVBlock = new FOVBlockBlock(); - } - - public AgentFOVPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - FOVBlock.FromBytes(bytes, ref i); - } - - public AgentFOVPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - FOVBlock.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += FOVBlock.Length; - if (Header.AckList != null && 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); - FOVBlock.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class AgentHeightWidthPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - public uint CircuitCode; - - public override int Length - { - get - { - return 36; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - CircuitCode = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - Utils.UIntToBytes(CircuitCode, bytes, i); i += 4; - } - - } - - /// - public sealed class HeightWidthBlockBlock : PacketBlock - { - public uint GenCounter; - public ushort Height; - public ushort Width; - - public override int Length - { - get - { - return 8; - } - } - - public HeightWidthBlockBlock() { } - public HeightWidthBlockBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(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(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UIntToBytes(GenCounter, bytes, i); i += 4; - bytes[i++] = (byte)(Height % 256); - bytes[i++] = (byte)((Height >> 8) % 256); - bytes[i++] = (byte)(Width % 256); - bytes[i++] = (byte)((Width >> 8) % 256); - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += HeightWidthBlock.Length; - return length; - } - } - public AgentDataBlock AgentData; - public HeightWidthBlockBlock HeightWidthBlock; - - public AgentHeightWidthPacket() - { - HasVariableBlocks = false; - Type = PacketType.AgentHeightWidth; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 83; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - HeightWidthBlock = new HeightWidthBlockBlock(); - } - - public AgentHeightWidthPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - HeightWidthBlock.FromBytes(bytes, ref i); - } - - public AgentHeightWidthPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - HeightWidthBlock.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += HeightWidthBlock.Length; - if (Header.AckList != null && 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); - HeightWidthBlock.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class AgentSetAppearancePacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - public uint SerialNum; - public Vector3 Size; - - public override int Length - { - get - { - return 48; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - SerialNum = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - Size.FromBytes(bytes, i); i += 12; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - Utils.UIntToBytes(SerialNum, bytes, i); i += 4; - Size.ToBytes(bytes, i); i += 12; - } - - } - - /// - public sealed class WearableDataBlock : PacketBlock - { - public UUID CacheID; - public byte TextureIndex; - - public override int Length - { - get - { - return 17; - } - } - - public WearableDataBlock() { } - public WearableDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - CacheID.FromBytes(bytes, i); i += 16; - TextureIndex = (byte)bytes[i++]; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - CacheID.ToBytes(bytes, i); i += 16; - bytes[i++] = TextureIndex; - } - - } - - /// - public sealed class ObjectDataBlock : PacketBlock - { - public byte[] TextureEntry; - - public override int Length - { - get - { - int length = 2; - if (TextureEntry != null) { length += TextureEntry.Length; } - return length; - } - } - - public ObjectDataBlock() { } - public ObjectDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - length = (bytes[i++] + (bytes[i++] << 8)); - TextureEntry = new byte[length]; - Buffer.BlockCopy(bytes, i, TextureEntry, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - bytes[i++] = (byte)(TextureEntry.Length % 256); - bytes[i++] = (byte)((TextureEntry.Length >> 8) % 256); - Buffer.BlockCopy(TextureEntry, 0, bytes, i, TextureEntry.Length); i += TextureEntry.Length; - } - - } - - /// - public sealed class VisualParamBlock : PacketBlock - { - public byte ParamValue; - - public override int Length - { - get - { - return 1; - } - } - - public VisualParamBlock() { } - public VisualParamBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - ParamValue = (byte)bytes[i++]; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - bytes[i++] = ParamValue; - } - - } - - public override int Length - { - get - { - int length = 12; - length += AgentData.Length; - for (int j = 0; j < WearableData.Length; j++) - length += WearableData[j].Length; - length += ObjectData.Length; - for (int j = 0; j < VisualParam.Length; j++) - length += VisualParam[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public WearableDataBlock[] WearableData; - public ObjectDataBlock ObjectData; - public VisualParamBlock[] VisualParam; - - public AgentSetAppearancePacket() - { - HasVariableBlocks = true; - Type = PacketType.AgentSetAppearance; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 84; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - WearableData = null; - ObjectData = new ObjectDataBlock(); - VisualParam = null; - } - - public AgentSetAppearancePacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(WearableData == null || WearableData.Length != -1) { - WearableData = new WearableDataBlock[count]; - for(int j = 0; j < count; j++) - { WearableData[j] = new WearableDataBlock(); } - } - for (int j = 0; j < count; j++) - { WearableData[j].FromBytes(bytes, ref i); } - ObjectData.FromBytes(bytes, ref i); - count = (int)bytes[i++]; - if(VisualParam == null || VisualParam.Length != -1) { - VisualParam = new VisualParamBlock[count]; - for(int j = 0; j < count; j++) - { VisualParam[j] = new VisualParamBlock(); } - } - for (int j = 0; j < count; j++) - { VisualParam[j].FromBytes(bytes, ref i); } - } - - public AgentSetAppearancePacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(WearableData == null || WearableData.Length != count) { - WearableData = new WearableDataBlock[count]; - for(int j = 0; j < count; j++) - { WearableData[j] = new WearableDataBlock(); } - } - for (int j = 0; j < count; j++) - { WearableData[j].FromBytes(bytes, ref i); } - ObjectData.FromBytes(bytes, ref i); - count = (int)bytes[i++]; - if(VisualParam == null || VisualParam.Length != count) { - VisualParam = new VisualParamBlock[count]; - for(int j = 0; j < count; j++) - { VisualParam[j] = new VisualParamBlock(); } - } - for (int j = 0; j < count; j++) - { VisualParam[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += ObjectData.Length; - length++; - for (int j = 0; j < WearableData.Length; j++) { length += WearableData[j].Length; } - length++; - for (int j = 0; j < VisualParam.Length; j++) { length += VisualParam[j].Length; } - if (Header.AckList != null && 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)WearableData.Length; - for (int j = 0; j < WearableData.Length; j++) { WearableData[j].ToBytes(bytes, ref i); } - ObjectData.ToBytes(bytes, ref i); - bytes[i++] = (byte)VisualParam.Length; - for (int j = 0; j < VisualParam.Length; j++) { VisualParam[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class AgentQuitCopyPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class FuseBlockBlock : PacketBlock - { - public uint ViewerCircuitCode; - - public override int Length - { - get - { - return 4; - } - } - - public FuseBlockBlock() { } - public FuseBlockBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - ViewerCircuitCode = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UIntToBytes(ViewerCircuitCode, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += FuseBlock.Length; - return length; - } - } - public AgentDataBlock AgentData; - public FuseBlockBlock FuseBlock; - - public AgentQuitCopyPacket() - { - HasVariableBlocks = false; - Type = PacketType.AgentQuitCopy; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 85; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - FuseBlock = new FuseBlockBlock(); - } - - public AgentQuitCopyPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - FuseBlock.FromBytes(bytes, ref i); - } - - public AgentQuitCopyPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - FuseBlock.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += FuseBlock.Length; - if (Header.AckList != null && 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); - FuseBlock.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class ImageNotInDatabasePacket : Packet - { - /// - public sealed class ImageIDBlock : PacketBlock - { - public UUID ID; - - public override int Length - { - get - { - return 16; - } - } - - public ImageIDBlock() { } - public ImageIDBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - ID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - ID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 10; - length += ImageID.Length; - return length; - } - } - public ImageIDBlock ImageID; - - public ImageNotInDatabasePacket() - { - HasVariableBlocks = false; - Type = PacketType.ImageNotInDatabase; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 86; - Header.Reliable = true; - ImageID = new ImageIDBlock(); - } - - public ImageNotInDatabasePacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - ImageID.FromBytes(bytes, ref i); - } - - public ImageNotInDatabasePacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - ImageID.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += ImageID.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class RebakeAvatarTexturesPacket : Packet - { - /// - public sealed class TextureDataBlock : PacketBlock - { - public UUID TextureID; - - public override int Length - { - get - { - return 16; - } - } - - public TextureDataBlock() { } - public TextureDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - TextureID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - TextureID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 10; - length += TextureData.Length; - return length; - } - } - public TextureDataBlock TextureData; - - public RebakeAvatarTexturesPacket() - { - HasVariableBlocks = false; - Type = PacketType.RebakeAvatarTextures; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 87; - Header.Reliable = true; - TextureData = new TextureDataBlock(); - } - - public RebakeAvatarTexturesPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - TextureData.FromBytes(bytes, ref i); - } - - public RebakeAvatarTexturesPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - TextureData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += TextureData.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class SetAlwaysRunPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - public bool AlwaysRun; - - public override int Length - { - get - { - return 33; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - AlwaysRun = (bytes[i++] != 0) ? (bool)true : (bool)false; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)((AlwaysRun) ? 1 : 0); - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - return length; - } - } - public AgentDataBlock AgentData; - - public SetAlwaysRunPacket() - { - HasVariableBlocks = false; - Type = PacketType.SetAlwaysRun; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 88; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - } - - public SetAlwaysRunPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - } - - public SetAlwaysRunPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class ObjectDeletePacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - public bool Force; - - public override int Length - { - get - { - return 33; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - Force = (bytes[i++] != 0) ? (bool)true : (bool)false; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)((Force) ? 1 : 0); - } - - } - - /// - public sealed class ObjectDataBlock : PacketBlock - { - public uint ObjectLocalID; - - public override int Length - { - get - { - return 4; - } - } - - public ObjectDataBlock() { } - public ObjectDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - ObjectLocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UIntToBytes(ObjectLocalID, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentData.Length; - for (int j = 0; j < ObjectData.Length; j++) - length += ObjectData[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public ObjectDataBlock[] ObjectData; - - public ObjectDeletePacket() - { - HasVariableBlocks = true; - Type = PacketType.ObjectDelete; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 89; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - ObjectData = null; - } - - public ObjectDeletePacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ObjectData == null || ObjectData.Length != -1) { - ObjectData = new ObjectDataBlock[count]; - for(int j = 0; j < count; j++) - { ObjectData[j] = new ObjectDataBlock(); } - } - for (int j = 0; j < count; j++) - { ObjectData[j].FromBytes(bytes, ref i); } - } - - public ObjectDeletePacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ObjectData == null || ObjectData.Length != count) { - ObjectData = new ObjectDataBlock[count]; - for(int j = 0; j < count; j++) - { ObjectData[j] = new ObjectDataBlock(); } - } - for (int j = 0; j < count; j++) - { ObjectData[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length++; - for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } - if (Header.AckList != null && 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)ObjectData.Length; - for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int ObjectDataStart = 0; - do - { - int variableLength = 0; - int ObjectDataCount = 0; - - i = ObjectDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < ObjectData.Length) { - int blockLength = ObjectData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ObjectDataStart) { - variableLength += blockLength; - ++ObjectDataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)ObjectDataCount; - for (i = ObjectDataStart; i < ObjectDataStart + ObjectDataCount; i++) { ObjectData[i].ToBytes(packet, ref length); } - ObjectDataStart += ObjectDataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - ObjectDataStart < ObjectData.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class ObjectDuplicatePacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - public UUID GroupID; - - public override int Length - { - get - { - return 48; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - GroupID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - GroupID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class SharedDataBlock : PacketBlock - { - public Vector3 Offset; - public uint DuplicateFlags; - - public override int Length - { - get - { - return 16; - } - } - - public SharedDataBlock() { } - public SharedDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - Offset.FromBytes(bytes, i); i += 12; - DuplicateFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Offset.ToBytes(bytes, i); i += 12; - Utils.UIntToBytes(DuplicateFlags, bytes, i); i += 4; - } - - } - - /// - public sealed class ObjectDataBlock : PacketBlock - { - public uint ObjectLocalID; - - public override int Length - { - get - { - return 4; - } - } - - public ObjectDataBlock() { } - public ObjectDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - ObjectLocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UIntToBytes(ObjectLocalID, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentData.Length; - length += SharedData.Length; - for (int j = 0; j < ObjectData.Length; j++) - length += ObjectData[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public SharedDataBlock SharedData; - public ObjectDataBlock[] ObjectData; - - public ObjectDuplicatePacket() - { - HasVariableBlocks = true; - Type = PacketType.ObjectDuplicate; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 90; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - SharedData = new SharedDataBlock(); - ObjectData = null; - } - - public ObjectDuplicatePacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - SharedData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ObjectData == null || ObjectData.Length != -1) { - ObjectData = new ObjectDataBlock[count]; - for(int j = 0; j < count; j++) - { ObjectData[j] = new ObjectDataBlock(); } - } - for (int j = 0; j < count; j++) - { ObjectData[j].FromBytes(bytes, ref i); } - } - - public ObjectDuplicatePacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - SharedData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ObjectData == null || ObjectData.Length != count) { - ObjectData = new ObjectDataBlock[count]; - for(int j = 0; j < count; j++) - { ObjectData[j] = new ObjectDataBlock(); } - } - for (int j = 0; j < count; j++) - { ObjectData[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += SharedData.Length; - length++; - for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } - if (Header.AckList != null && 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); - SharedData.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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - fixedLength += SharedData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - SharedData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int ObjectDataStart = 0; - do - { - int variableLength = 0; - int ObjectDataCount = 0; - - i = ObjectDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < ObjectData.Length) { - int blockLength = ObjectData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ObjectDataStart) { - variableLength += blockLength; - ++ObjectDataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)ObjectDataCount; - for (i = ObjectDataStart; i < ObjectDataStart + ObjectDataCount; i++) { ObjectData[i].ToBytes(packet, ref length); } - ObjectDataStart += ObjectDataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - ObjectDataStart < ObjectData.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class ObjectDuplicateOnRayPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - public UUID GroupID; - public Vector3 RayStart; - public Vector3 RayEnd; - public bool BypassRaycast; - public bool RayEndIsIntersection; - public bool CopyCenters; - public bool CopyRotates; - public UUID RayTargetID; - public uint DuplicateFlags; - - public override int Length - { - get - { - return 96; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - GroupID.FromBytes(bytes, i); i += 16; - RayStart.FromBytes(bytes, i); i += 12; - RayEnd.FromBytes(bytes, i); i += 12; - BypassRaycast = (bytes[i++] != 0) ? (bool)true : (bool)false; - RayEndIsIntersection = (bytes[i++] != 0) ? (bool)true : (bool)false; - CopyCenters = (bytes[i++] != 0) ? (bool)true : (bool)false; - CopyRotates = (bytes[i++] != 0) ? (bool)true : (bool)false; - RayTargetID.FromBytes(bytes, i); i += 16; - DuplicateFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - GroupID.ToBytes(bytes, i); i += 16; - RayStart.ToBytes(bytes, i); i += 12; - RayEnd.ToBytes(bytes, i); i += 12; - bytes[i++] = (byte)((BypassRaycast) ? 1 : 0); - bytes[i++] = (byte)((RayEndIsIntersection) ? 1 : 0); - bytes[i++] = (byte)((CopyCenters) ? 1 : 0); - bytes[i++] = (byte)((CopyRotates) ? 1 : 0); - RayTargetID.ToBytes(bytes, i); i += 16; - Utils.UIntToBytes(DuplicateFlags, bytes, i); i += 4; - } - - } - - /// - public sealed class ObjectDataBlock : PacketBlock - { - public uint ObjectLocalID; - - public override int Length - { - get - { - return 4; - } - } - - public ObjectDataBlock() { } - public ObjectDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - ObjectLocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UIntToBytes(ObjectLocalID, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentData.Length; - for (int j = 0; j < ObjectData.Length; j++) - length += ObjectData[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public ObjectDataBlock[] ObjectData; - - public ObjectDuplicateOnRayPacket() - { - HasVariableBlocks = true; - Type = PacketType.ObjectDuplicateOnRay; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 91; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - ObjectData = null; - } - - public ObjectDuplicateOnRayPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ObjectData == null || ObjectData.Length != -1) { - ObjectData = new ObjectDataBlock[count]; - for(int j = 0; j < count; j++) - { ObjectData[j] = new ObjectDataBlock(); } - } - for (int j = 0; j < count; j++) - { ObjectData[j].FromBytes(bytes, ref i); } - } - - public ObjectDuplicateOnRayPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ObjectData == null || ObjectData.Length != count) { - ObjectData = new ObjectDataBlock[count]; - for(int j = 0; j < count; j++) - { ObjectData[j] = new ObjectDataBlock(); } - } - for (int j = 0; j < count; j++) - { ObjectData[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length++; - for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } - if (Header.AckList != null && 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)ObjectData.Length; - for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int ObjectDataStart = 0; - do - { - int variableLength = 0; - int ObjectDataCount = 0; - - i = ObjectDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < ObjectData.Length) { - int blockLength = ObjectData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ObjectDataStart) { - variableLength += blockLength; - ++ObjectDataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)ObjectDataCount; - for (i = ObjectDataStart; i < ObjectDataStart + ObjectDataCount; i++) { ObjectData[i].ToBytes(packet, ref length); } - ObjectDataStart += ObjectDataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - ObjectDataStart < ObjectData.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class ObjectScalePacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class ObjectDataBlock : PacketBlock - { - public uint ObjectLocalID; - public Vector3 Scale; - - public override int Length - { - get - { - return 16; - } - } - - public ObjectDataBlock() { } - public ObjectDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - ObjectLocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - Scale.FromBytes(bytes, i); i += 12; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UIntToBytes(ObjectLocalID, bytes, i); i += 4; - Scale.ToBytes(bytes, i); i += 12; - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentData.Length; - for (int j = 0; j < ObjectData.Length; j++) - length += ObjectData[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public ObjectDataBlock[] ObjectData; - - public ObjectScalePacket() - { - HasVariableBlocks = true; - Type = PacketType.ObjectScale; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 92; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - ObjectData = null; - } - - public ObjectScalePacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ObjectData == null || ObjectData.Length != -1) { - ObjectData = new ObjectDataBlock[count]; - for(int j = 0; j < count; j++) - { ObjectData[j] = new ObjectDataBlock(); } - } - for (int j = 0; j < count; j++) - { ObjectData[j].FromBytes(bytes, ref i); } - } - - public ObjectScalePacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ObjectData == null || ObjectData.Length != count) { - ObjectData = new ObjectDataBlock[count]; - for(int j = 0; j < count; j++) - { ObjectData[j] = new ObjectDataBlock(); } - } - for (int j = 0; j < count; j++) - { ObjectData[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length++; - for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } - if (Header.AckList != null && 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)ObjectData.Length; - for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int ObjectDataStart = 0; - do - { - int variableLength = 0; - int ObjectDataCount = 0; - - i = ObjectDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < ObjectData.Length) { - int blockLength = ObjectData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ObjectDataStart) { - variableLength += blockLength; - ++ObjectDataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)ObjectDataCount; - for (i = ObjectDataStart; i < ObjectDataStart + ObjectDataCount; i++) { ObjectData[i].ToBytes(packet, ref length); } - ObjectDataStart += ObjectDataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - ObjectDataStart < ObjectData.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class ObjectRotationPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class ObjectDataBlock : PacketBlock - { - public uint ObjectLocalID; - public Quaternion Rotation; - - public override int Length - { - get - { - return 16; - } - } - - public ObjectDataBlock() { } - public ObjectDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - ObjectLocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - Rotation.FromBytes(bytes, i, true); i += 12; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UIntToBytes(ObjectLocalID, bytes, i); i += 4; - Rotation.ToBytes(bytes, i); i += 12; - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentData.Length; - for (int j = 0; j < ObjectData.Length; j++) - length += ObjectData[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public ObjectDataBlock[] ObjectData; - - public ObjectRotationPacket() - { - HasVariableBlocks = true; - Type = PacketType.ObjectRotation; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 93; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - ObjectData = null; - } - - public ObjectRotationPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ObjectData == null || ObjectData.Length != -1) { - ObjectData = new ObjectDataBlock[count]; - for(int j = 0; j < count; j++) - { ObjectData[j] = new ObjectDataBlock(); } - } - for (int j = 0; j < count; j++) - { ObjectData[j].FromBytes(bytes, ref i); } - } - - public ObjectRotationPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ObjectData == null || ObjectData.Length != count) { - ObjectData = new ObjectDataBlock[count]; - for(int j = 0; j < count; j++) - { ObjectData[j] = new ObjectDataBlock(); } - } - for (int j = 0; j < count; j++) - { ObjectData[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length++; - for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } - if (Header.AckList != null && 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)ObjectData.Length; - for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int ObjectDataStart = 0; - do - { - int variableLength = 0; - int ObjectDataCount = 0; - - i = ObjectDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < ObjectData.Length) { - int blockLength = ObjectData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ObjectDataStart) { - variableLength += blockLength; - ++ObjectDataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)ObjectDataCount; - for (i = ObjectDataStart; i < ObjectDataStart + ObjectDataCount; i++) { ObjectData[i].ToBytes(packet, ref length); } - ObjectDataStart += ObjectDataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - ObjectDataStart < ObjectData.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class ObjectFlagUpdatePacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - public uint ObjectLocalID; - public bool UsePhysics; - public bool IsTemporary; - public bool IsPhantom; - public bool CastsShadows; - - public override int Length - { - get - { - return 40; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - ObjectLocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - UsePhysics = (bytes[i++] != 0) ? (bool)true : (bool)false; - IsTemporary = (bytes[i++] != 0) ? (bool)true : (bool)false; - IsPhantom = (bytes[i++] != 0) ? (bool)true : (bool)false; - CastsShadows = (bytes[i++] != 0) ? (bool)true : (bool)false; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - Utils.UIntToBytes(ObjectLocalID, bytes, i); i += 4; - bytes[i++] = (byte)((UsePhysics) ? 1 : 0); - bytes[i++] = (byte)((IsTemporary) ? 1 : 0); - bytes[i++] = (byte)((IsPhantom) ? 1 : 0); - bytes[i++] = (byte)((CastsShadows) ? 1 : 0); - } - - } - - /// - public sealed class ExtraPhysicsBlock : PacketBlock - { - public byte PhysicsShapeType; - public float Density; - public float Friction; - public float Restitution; - public float GravityMultiplier; - - public override int Length - { - get - { - return 17; - } - } - - public ExtraPhysicsBlock() { } - public ExtraPhysicsBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - PhysicsShapeType = (byte)bytes[i++]; - Density = Utils.BytesToFloat(bytes, i); i += 4; - Friction = Utils.BytesToFloat(bytes, i); i += 4; - Restitution = Utils.BytesToFloat(bytes, i); i += 4; - GravityMultiplier = Utils.BytesToFloat(bytes, i); i += 4; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - bytes[i++] = PhysicsShapeType; - Utils.FloatToBytes(Density, bytes, i); i += 4; - Utils.FloatToBytes(Friction, bytes, i); i += 4; - Utils.FloatToBytes(Restitution, bytes, i); i += 4; - Utils.FloatToBytes(GravityMultiplier, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentData.Length; - for (int j = 0; j < ExtraPhysics.Length; j++) - length += ExtraPhysics[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public ExtraPhysicsBlock[] ExtraPhysics; - - public ObjectFlagUpdatePacket() - { - HasVariableBlocks = true; - Type = PacketType.ObjectFlagUpdate; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 94; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - ExtraPhysics = null; - } - - public ObjectFlagUpdatePacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ExtraPhysics == null || ExtraPhysics.Length != -1) { - ExtraPhysics = new ExtraPhysicsBlock[count]; - for(int j = 0; j < count; j++) - { ExtraPhysics[j] = new ExtraPhysicsBlock(); } - } - for (int j = 0; j < count; j++) - { ExtraPhysics[j].FromBytes(bytes, ref i); } - } - - public ObjectFlagUpdatePacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ExtraPhysics == null || ExtraPhysics.Length != count) { - ExtraPhysics = new ExtraPhysicsBlock[count]; - for(int j = 0; j < count; j++) - { ExtraPhysics[j] = new ExtraPhysicsBlock(); } - } - for (int j = 0; j < count; j++) - { ExtraPhysics[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length++; - for (int j = 0; j < ExtraPhysics.Length; j++) { length += ExtraPhysics[j].Length; } - if (Header.AckList != null && 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)ExtraPhysics.Length; - for (int j = 0; j < ExtraPhysics.Length; j++) { ExtraPhysics[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int ExtraPhysicsStart = 0; - do - { - int variableLength = 0; - int ExtraPhysicsCount = 0; - - i = ExtraPhysicsStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < ExtraPhysics.Length) { - int blockLength = ExtraPhysics[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ExtraPhysicsStart) { - variableLength += blockLength; - ++ExtraPhysicsCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)ExtraPhysicsCount; - for (i = ExtraPhysicsStart; i < ExtraPhysicsStart + ExtraPhysicsCount; i++) { ExtraPhysics[i].ToBytes(packet, ref length); } - ExtraPhysicsStart += ExtraPhysicsCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - ExtraPhysicsStart < ExtraPhysics.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class ObjectClickActionPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class ObjectDataBlock : PacketBlock - { - public uint ObjectLocalID; - public byte ClickAction; - - public override int Length - { - get - { - return 5; - } - } - - public ObjectDataBlock() { } - public ObjectDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - ObjectLocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - ClickAction = (byte)bytes[i++]; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UIntToBytes(ObjectLocalID, bytes, i); i += 4; - bytes[i++] = ClickAction; - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentData.Length; - for (int j = 0; j < ObjectData.Length; j++) - length += ObjectData[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public ObjectDataBlock[] ObjectData; - - public ObjectClickActionPacket() - { - HasVariableBlocks = true; - Type = PacketType.ObjectClickAction; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 95; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - ObjectData = null; - } - - public ObjectClickActionPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ObjectData == null || ObjectData.Length != -1) { - ObjectData = new ObjectDataBlock[count]; - for(int j = 0; j < count; j++) - { ObjectData[j] = new ObjectDataBlock(); } - } - for (int j = 0; j < count; j++) - { ObjectData[j].FromBytes(bytes, ref i); } - } - - public ObjectClickActionPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ObjectData == null || ObjectData.Length != count) { - ObjectData = new ObjectDataBlock[count]; - for(int j = 0; j < count; j++) - { ObjectData[j] = new ObjectDataBlock(); } - } - for (int j = 0; j < count; j++) - { ObjectData[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length++; - for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } - if (Header.AckList != null && 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)ObjectData.Length; - for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int ObjectDataStart = 0; - do - { - int variableLength = 0; - int ObjectDataCount = 0; - - i = ObjectDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < ObjectData.Length) { - int blockLength = ObjectData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ObjectDataStart) { - variableLength += blockLength; - ++ObjectDataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)ObjectDataCount; - for (i = ObjectDataStart; i < ObjectDataStart + ObjectDataCount; i++) { ObjectData[i].ToBytes(packet, ref length); } - ObjectDataStart += ObjectDataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - ObjectDataStart < ObjectData.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class ObjectImagePacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class ObjectDataBlock : PacketBlock - { - public uint ObjectLocalID; - public byte[] MediaURL; - public byte[] TextureEntry; - - public override int Length - { - get - { - int length = 7; - if (MediaURL != null) { length += MediaURL.Length; } - if (TextureEntry != null) { length += TextureEntry.Length; } - return length; - } - } - - public ObjectDataBlock() { } - public ObjectDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - ObjectLocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - length = bytes[i++]; - MediaURL = new byte[length]; - Buffer.BlockCopy(bytes, i, MediaURL, 0, length); i += length; - length = (bytes[i++] + (bytes[i++] << 8)); - TextureEntry = new byte[length]; - Buffer.BlockCopy(bytes, i, TextureEntry, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UIntToBytes(ObjectLocalID, bytes, i); i += 4; - bytes[i++] = (byte)MediaURL.Length; - Buffer.BlockCopy(MediaURL, 0, bytes, i, MediaURL.Length); i += MediaURL.Length; - bytes[i++] = (byte)(TextureEntry.Length % 256); - bytes[i++] = (byte)((TextureEntry.Length >> 8) % 256); - Buffer.BlockCopy(TextureEntry, 0, bytes, i, TextureEntry.Length); i += TextureEntry.Length; - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentData.Length; - for (int j = 0; j < ObjectData.Length; j++) - length += ObjectData[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public ObjectDataBlock[] ObjectData; - - public ObjectImagePacket() - { - HasVariableBlocks = true; - Type = PacketType.ObjectImage; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 96; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - ObjectData = null; - } - - public ObjectImagePacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ObjectData == null || ObjectData.Length != -1) { - ObjectData = new ObjectDataBlock[count]; - for(int j = 0; j < count; j++) - { ObjectData[j] = new ObjectDataBlock(); } - } - for (int j = 0; j < count; j++) - { ObjectData[j].FromBytes(bytes, ref i); } - } - - public ObjectImagePacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ObjectData == null || ObjectData.Length != count) { - ObjectData = new ObjectDataBlock[count]; - for(int j = 0; j < count; j++) - { ObjectData[j] = new ObjectDataBlock(); } - } - for (int j = 0; j < count; j++) - { ObjectData[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length++; - for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } - if (Header.AckList != null && 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)ObjectData.Length; - for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int ObjectDataStart = 0; - do - { - int variableLength = 0; - int ObjectDataCount = 0; - - i = ObjectDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < ObjectData.Length) { - int blockLength = ObjectData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ObjectDataStart) { - variableLength += blockLength; - ++ObjectDataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)ObjectDataCount; - for (i = ObjectDataStart; i < ObjectDataStart + ObjectDataCount; i++) { ObjectData[i].ToBytes(packet, ref length); } - ObjectDataStart += ObjectDataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - ObjectDataStart < ObjectData.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class ObjectMaterialPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class ObjectDataBlock : PacketBlock - { - public uint ObjectLocalID; - public byte Material; - - public override int Length - { - get - { - return 5; - } - } - - public ObjectDataBlock() { } - public ObjectDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - ObjectLocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - Material = (byte)bytes[i++]; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UIntToBytes(ObjectLocalID, bytes, i); i += 4; - bytes[i++] = Material; - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentData.Length; - for (int j = 0; j < ObjectData.Length; j++) - length += ObjectData[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public ObjectDataBlock[] ObjectData; - - public ObjectMaterialPacket() - { - HasVariableBlocks = true; - Type = PacketType.ObjectMaterial; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 97; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - ObjectData = null; - } - - public ObjectMaterialPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ObjectData == null || ObjectData.Length != -1) { - ObjectData = new ObjectDataBlock[count]; - for(int j = 0; j < count; j++) - { ObjectData[j] = new ObjectDataBlock(); } - } - for (int j = 0; j < count; j++) - { ObjectData[j].FromBytes(bytes, ref i); } - } - - public ObjectMaterialPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ObjectData == null || ObjectData.Length != count) { - ObjectData = new ObjectDataBlock[count]; - for(int j = 0; j < count; j++) - { ObjectData[j] = new ObjectDataBlock(); } - } - for (int j = 0; j < count; j++) - { ObjectData[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length++; - for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } - if (Header.AckList != null && 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)ObjectData.Length; - for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int ObjectDataStart = 0; - do - { - int variableLength = 0; - int ObjectDataCount = 0; - - i = ObjectDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < ObjectData.Length) { - int blockLength = ObjectData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ObjectDataStart) { - variableLength += blockLength; - ++ObjectDataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)ObjectDataCount; - for (i = ObjectDataStart; i < ObjectDataStart + ObjectDataCount; i++) { ObjectData[i].ToBytes(packet, ref length); } - ObjectDataStart += ObjectDataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - ObjectDataStart < ObjectData.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class ObjectShapePacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class ObjectDataBlock : PacketBlock - { - public uint ObjectLocalID; - public byte PathCurve; - public byte ProfileCurve; - public ushort PathBegin; - public ushort PathEnd; - public byte PathScaleX; - public byte PathScaleY; - public byte PathShearX; - public byte PathShearY; - public sbyte PathTwist; - public sbyte PathTwistBegin; - public sbyte PathRadiusOffset; - public sbyte PathTaperX; - public sbyte PathTaperY; - public byte PathRevolutions; - public sbyte PathSkew; - public ushort ProfileBegin; - public ushort ProfileEnd; - public ushort ProfileHollow; - - public override int Length - { - get - { - return 27; - } - } - - public ObjectDataBlock() { } - public ObjectDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - ObjectLocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - PathCurve = (byte)bytes[i++]; - ProfileCurve = (byte)bytes[i++]; - PathBegin = (ushort)(bytes[i++] + (bytes[i++] << 8)); - PathEnd = (ushort)(bytes[i++] + (bytes[i++] << 8)); - PathScaleX = (byte)bytes[i++]; - PathScaleY = (byte)bytes[i++]; - PathShearX = (byte)bytes[i++]; - PathShearY = (byte)bytes[i++]; - PathTwist = (sbyte)bytes[i++]; - PathTwistBegin = (sbyte)bytes[i++]; - PathRadiusOffset = (sbyte)bytes[i++]; - PathTaperX = (sbyte)bytes[i++]; - PathTaperY = (sbyte)bytes[i++]; - PathRevolutions = (byte)bytes[i++]; - PathSkew = (sbyte)bytes[i++]; - ProfileBegin = (ushort)(bytes[i++] + (bytes[i++] << 8)); - ProfileEnd = (ushort)(bytes[i++] + (bytes[i++] << 8)); - ProfileHollow = (ushort)(bytes[i++] + (bytes[i++] << 8)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UIntToBytes(ObjectLocalID, bytes, i); i += 4; - bytes[i++] = PathCurve; - bytes[i++] = ProfileCurve; - bytes[i++] = (byte)(PathBegin % 256); - bytes[i++] = (byte)((PathBegin >> 8) % 256); - bytes[i++] = (byte)(PathEnd % 256); - bytes[i++] = (byte)((PathEnd >> 8) % 256); - bytes[i++] = PathScaleX; - bytes[i++] = PathScaleY; - bytes[i++] = PathShearX; - bytes[i++] = PathShearY; - bytes[i++] = (byte)PathTwist; - bytes[i++] = (byte)PathTwistBegin; - bytes[i++] = (byte)PathRadiusOffset; - bytes[i++] = (byte)PathTaperX; - bytes[i++] = (byte)PathTaperY; - bytes[i++] = PathRevolutions; - bytes[i++] = (byte)PathSkew; - bytes[i++] = (byte)(ProfileBegin % 256); - bytes[i++] = (byte)((ProfileBegin >> 8) % 256); - bytes[i++] = (byte)(ProfileEnd % 256); - bytes[i++] = (byte)((ProfileEnd >> 8) % 256); - bytes[i++] = (byte)(ProfileHollow % 256); - bytes[i++] = (byte)((ProfileHollow >> 8) % 256); - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentData.Length; - for (int j = 0; j < ObjectData.Length; j++) - length += ObjectData[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public ObjectDataBlock[] ObjectData; - - public ObjectShapePacket() - { - HasVariableBlocks = true; - Type = PacketType.ObjectShape; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 98; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - ObjectData = null; - } - - public ObjectShapePacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ObjectData == null || ObjectData.Length != -1) { - ObjectData = new ObjectDataBlock[count]; - for(int j = 0; j < count; j++) - { ObjectData[j] = new ObjectDataBlock(); } - } - for (int j = 0; j < count; j++) - { ObjectData[j].FromBytes(bytes, ref i); } - } - - public ObjectShapePacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ObjectData == null || ObjectData.Length != count) { - ObjectData = new ObjectDataBlock[count]; - for(int j = 0; j < count; j++) - { ObjectData[j] = new ObjectDataBlock(); } - } - for (int j = 0; j < count; j++) - { ObjectData[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length++; - for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } - if (Header.AckList != null && 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)ObjectData.Length; - for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int ObjectDataStart = 0; - do - { - int variableLength = 0; - int ObjectDataCount = 0; - - i = ObjectDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < ObjectData.Length) { - int blockLength = ObjectData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ObjectDataStart) { - variableLength += blockLength; - ++ObjectDataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)ObjectDataCount; - for (i = ObjectDataStart; i < ObjectDataStart + ObjectDataCount; i++) { ObjectData[i].ToBytes(packet, ref length); } - ObjectDataStart += ObjectDataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - ObjectDataStart < ObjectData.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class ObjectExtraParamsPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class ObjectDataBlock : PacketBlock - { - public uint ObjectLocalID; - public ushort ParamType; - public bool ParamInUse; - public uint ParamSize; - public byte[] ParamData; - - public override int Length - { - get - { - int length = 12; - if (ParamData != null) { length += ParamData.Length; } - return length; - } - } - - public ObjectDataBlock() { } - public ObjectDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - ObjectLocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - ParamType = (ushort)(bytes[i++] + (bytes[i++] << 8)); - ParamInUse = (bytes[i++] != 0) ? (bool)true : (bool)false; - ParamSize = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - length = bytes[i++]; - ParamData = new byte[length]; - Buffer.BlockCopy(bytes, i, ParamData, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UIntToBytes(ObjectLocalID, bytes, i); i += 4; - bytes[i++] = (byte)(ParamType % 256); - bytes[i++] = (byte)((ParamType >> 8) % 256); - bytes[i++] = (byte)((ParamInUse) ? 1 : 0); - Utils.UIntToBytes(ParamSize, bytes, i); i += 4; - bytes[i++] = (byte)ParamData.Length; - Buffer.BlockCopy(ParamData, 0, bytes, i, ParamData.Length); i += ParamData.Length; - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentData.Length; - for (int j = 0; j < ObjectData.Length; j++) - length += ObjectData[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public ObjectDataBlock[] ObjectData; - - public ObjectExtraParamsPacket() - { - HasVariableBlocks = true; - Type = PacketType.ObjectExtraParams; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 99; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - ObjectData = null; - } - - public ObjectExtraParamsPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ObjectData == null || ObjectData.Length != -1) { - ObjectData = new ObjectDataBlock[count]; - for(int j = 0; j < count; j++) - { ObjectData[j] = new ObjectDataBlock(); } - } - for (int j = 0; j < count; j++) - { ObjectData[j].FromBytes(bytes, ref i); } - } - - public ObjectExtraParamsPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ObjectData == null || ObjectData.Length != count) { - ObjectData = new ObjectDataBlock[count]; - for(int j = 0; j < count; j++) - { ObjectData[j] = new ObjectDataBlock(); } - } - for (int j = 0; j < count; j++) - { ObjectData[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length++; - for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } - if (Header.AckList != null && 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)ObjectData.Length; - for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int ObjectDataStart = 0; - do - { - int variableLength = 0; - int ObjectDataCount = 0; - - i = ObjectDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < ObjectData.Length) { - int blockLength = ObjectData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ObjectDataStart) { - variableLength += blockLength; - ++ObjectDataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)ObjectDataCount; - for (i = ObjectDataStart; i < ObjectDataStart + ObjectDataCount; i++) { ObjectData[i].ToBytes(packet, ref length); } - ObjectDataStart += ObjectDataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - ObjectDataStart < ObjectData.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class ObjectOwnerPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class HeaderDataBlock : PacketBlock - { - public bool Override; - public UUID OwnerID; - public UUID GroupID; - - public override int Length - { - get - { - return 33; - } - } - - public HeaderDataBlock() { } - public HeaderDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - Override = (bytes[i++] != 0) ? (bool)true : (bool)false; - OwnerID.FromBytes(bytes, i); i += 16; - GroupID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - bytes[i++] = (byte)((Override) ? 1 : 0); - OwnerID.ToBytes(bytes, i); i += 16; - GroupID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class ObjectDataBlock : PacketBlock - { - public uint ObjectLocalID; - - public override int Length - { - get - { - return 4; - } - } - - public ObjectDataBlock() { } - public ObjectDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - ObjectLocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UIntToBytes(ObjectLocalID, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentData.Length; - length += HeaderData.Length; - for (int j = 0; j < ObjectData.Length; j++) - length += ObjectData[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public HeaderDataBlock HeaderData; - public ObjectDataBlock[] ObjectData; - - public ObjectOwnerPacket() - { - HasVariableBlocks = true; - Type = PacketType.ObjectOwner; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 100; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - HeaderData = new HeaderDataBlock(); - ObjectData = null; - } - - public ObjectOwnerPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - HeaderData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ObjectData == null || ObjectData.Length != -1) { - ObjectData = new ObjectDataBlock[count]; - for(int j = 0; j < count; j++) - { ObjectData[j] = new ObjectDataBlock(); } - } - for (int j = 0; j < count; j++) - { ObjectData[j].FromBytes(bytes, ref i); } - } - - public ObjectOwnerPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - HeaderData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ObjectData == null || ObjectData.Length != count) { - ObjectData = new ObjectDataBlock[count]; - for(int j = 0; j < count; j++) - { ObjectData[j] = new ObjectDataBlock(); } - } - for (int j = 0; j < count; j++) - { ObjectData[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += HeaderData.Length; - length++; - for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } - if (Header.AckList != null && 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); - HeaderData.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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - fixedLength += HeaderData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - HeaderData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int ObjectDataStart = 0; - do - { - int variableLength = 0; - int ObjectDataCount = 0; - - i = ObjectDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < ObjectData.Length) { - int blockLength = ObjectData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ObjectDataStart) { - variableLength += blockLength; - ++ObjectDataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)ObjectDataCount; - for (i = ObjectDataStart; i < ObjectDataStart + ObjectDataCount; i++) { ObjectData[i].ToBytes(packet, ref length); } - ObjectDataStart += ObjectDataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - ObjectDataStart < ObjectData.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class ObjectGroupPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - public UUID GroupID; - - public override int Length - { - get - { - return 48; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - GroupID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - GroupID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class ObjectDataBlock : PacketBlock - { - public uint ObjectLocalID; - - public override int Length - { - get - { - return 4; - } - } - - public ObjectDataBlock() { } - public ObjectDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - ObjectLocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UIntToBytes(ObjectLocalID, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentData.Length; - for (int j = 0; j < ObjectData.Length; j++) - length += ObjectData[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public ObjectDataBlock[] ObjectData; - - public ObjectGroupPacket() - { - HasVariableBlocks = true; - Type = PacketType.ObjectGroup; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 101; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - ObjectData = null; - } - - public ObjectGroupPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ObjectData == null || ObjectData.Length != -1) { - ObjectData = new ObjectDataBlock[count]; - for(int j = 0; j < count; j++) - { ObjectData[j] = new ObjectDataBlock(); } - } - for (int j = 0; j < count; j++) - { ObjectData[j].FromBytes(bytes, ref i); } - } - - public ObjectGroupPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ObjectData == null || ObjectData.Length != count) { - ObjectData = new ObjectDataBlock[count]; - for(int j = 0; j < count; j++) - { ObjectData[j] = new ObjectDataBlock(); } - } - for (int j = 0; j < count; j++) - { ObjectData[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length++; - for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } - if (Header.AckList != null && 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)ObjectData.Length; - for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int ObjectDataStart = 0; - do - { - int variableLength = 0; - int ObjectDataCount = 0; - - i = ObjectDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < ObjectData.Length) { - int blockLength = ObjectData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ObjectDataStart) { - variableLength += blockLength; - ++ObjectDataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)ObjectDataCount; - for (i = ObjectDataStart; i < ObjectDataStart + ObjectDataCount; i++) { ObjectData[i].ToBytes(packet, ref length); } - ObjectDataStart += ObjectDataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - ObjectDataStart < ObjectData.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class ObjectBuyPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - public UUID GroupID; - public UUID CategoryID; - - public override int Length - { - get - { - return 64; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - GroupID.FromBytes(bytes, i); i += 16; - CategoryID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - GroupID.ToBytes(bytes, i); i += 16; - CategoryID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class ObjectDataBlock : PacketBlock - { - public uint ObjectLocalID; - public byte SaleType; - public int SalePrice; - - public override int Length - { - get - { - return 9; - } - } - - public ObjectDataBlock() { } - public ObjectDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - ObjectLocalID = (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(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UIntToBytes(ObjectLocalID, bytes, i); i += 4; - bytes[i++] = SaleType; - Utils.IntToBytes(SalePrice, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentData.Length; - for (int j = 0; j < ObjectData.Length; j++) - length += ObjectData[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public ObjectDataBlock[] ObjectData; - - public ObjectBuyPacket() - { - HasVariableBlocks = true; - Type = PacketType.ObjectBuy; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 102; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - ObjectData = null; - } - - public ObjectBuyPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ObjectData == null || ObjectData.Length != -1) { - ObjectData = new ObjectDataBlock[count]; - for(int j = 0; j < count; j++) - { ObjectData[j] = new ObjectDataBlock(); } - } - for (int j = 0; j < count; j++) - { ObjectData[j].FromBytes(bytes, ref i); } - } - - public ObjectBuyPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ObjectData == null || ObjectData.Length != count) { - ObjectData = new ObjectDataBlock[count]; - for(int j = 0; j < count; j++) - { ObjectData[j] = new ObjectDataBlock(); } - } - for (int j = 0; j < count; j++) - { ObjectData[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length++; - for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } - if (Header.AckList != null && 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)ObjectData.Length; - for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int ObjectDataStart = 0; - do - { - int variableLength = 0; - int ObjectDataCount = 0; - - i = ObjectDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < ObjectData.Length) { - int blockLength = ObjectData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ObjectDataStart) { - variableLength += blockLength; - ++ObjectDataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)ObjectDataCount; - for (i = ObjectDataStart; i < ObjectDataStart + ObjectDataCount; i++) { ObjectData[i].ToBytes(packet, ref length); } - ObjectDataStart += ObjectDataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - ObjectDataStart < ObjectData.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class BuyObjectInventoryPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class DataBlock : PacketBlock - { - public UUID ObjectID; - public UUID ItemID; - public UUID FolderID; - - public override int Length - { - get - { - return 48; - } - } - - public DataBlock() { } - public DataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - ObjectID.FromBytes(bytes, i); i += 16; - ItemID.FromBytes(bytes, i); i += 16; - FolderID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - ObjectID.ToBytes(bytes, i); i += 16; - ItemID.ToBytes(bytes, i); i += 16; - FolderID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += Data.Length; - return length; - } - } - public AgentDataBlock AgentData; - public DataBlock Data; - - public BuyObjectInventoryPacket() - { - HasVariableBlocks = false; - Type = PacketType.BuyObjectInventory; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 103; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - Data = new DataBlock(); - } - - public BuyObjectInventoryPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - Data.FromBytes(bytes, ref i); - } - - public BuyObjectInventoryPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - Data.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += Data.Length; - if (Header.AckList != null && 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); - Data.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class DerezContainerPacket : Packet - { - /// - public sealed class DataBlock : PacketBlock - { - public UUID ObjectID; - public bool Delete; - - public override int Length - { - get - { - return 17; - } - } - - public DataBlock() { } - public DataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - ObjectID.FromBytes(bytes, i); i += 16; - Delete = (bytes[i++] != 0) ? (bool)true : (bool)false; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - ObjectID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)((Delete) ? 1 : 0); - } - - } - - public override int Length - { - get - { - int length = 10; - length += Data.Length; - return length; - } - } - public DataBlock Data; - - public DerezContainerPacket() - { - HasVariableBlocks = false; - Type = PacketType.DerezContainer; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 104; - Header.Reliable = true; - Header.Zerocoded = true; - Data = new DataBlock(); - } - - public DerezContainerPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - Data.FromBytes(bytes, ref i); - } - - public DerezContainerPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - Data.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += Data.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class ObjectPermissionsPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class HeaderDataBlock : PacketBlock - { - public bool Override; - - public override int Length - { - get - { - return 1; - } - } - - public HeaderDataBlock() { } - public HeaderDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - Override = (bytes[i++] != 0) ? (bool)true : (bool)false; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - bytes[i++] = (byte)((Override) ? 1 : 0); - } - - } - - /// - public sealed class ObjectDataBlock : PacketBlock - { - public uint ObjectLocalID; - public byte Field; - public byte Set; - public uint Mask; - - public override int Length - { - get - { - return 10; - } - } - - public ObjectDataBlock() { } - public ObjectDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - ObjectLocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - Field = (byte)bytes[i++]; - Set = (byte)bytes[i++]; - Mask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UIntToBytes(ObjectLocalID, bytes, i); i += 4; - bytes[i++] = Field; - bytes[i++] = Set; - Utils.UIntToBytes(Mask, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentData.Length; - length += HeaderData.Length; - for (int j = 0; j < ObjectData.Length; j++) - length += ObjectData[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public HeaderDataBlock HeaderData; - public ObjectDataBlock[] ObjectData; - - public ObjectPermissionsPacket() - { - HasVariableBlocks = true; - Type = PacketType.ObjectPermissions; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 105; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - HeaderData = new HeaderDataBlock(); - ObjectData = null; - } - - public ObjectPermissionsPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - HeaderData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ObjectData == null || ObjectData.Length != -1) { - ObjectData = new ObjectDataBlock[count]; - for(int j = 0; j < count; j++) - { ObjectData[j] = new ObjectDataBlock(); } - } - for (int j = 0; j < count; j++) - { ObjectData[j].FromBytes(bytes, ref i); } - } - - public ObjectPermissionsPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - HeaderData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ObjectData == null || ObjectData.Length != count) { - ObjectData = new ObjectDataBlock[count]; - for(int j = 0; j < count; j++) - { ObjectData[j] = new ObjectDataBlock(); } - } - for (int j = 0; j < count; j++) - { ObjectData[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += HeaderData.Length; - length++; - for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } - if (Header.AckList != null && 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); - HeaderData.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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - fixedLength += HeaderData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - HeaderData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int ObjectDataStart = 0; - do - { - int variableLength = 0; - int ObjectDataCount = 0; - - i = ObjectDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < ObjectData.Length) { - int blockLength = ObjectData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ObjectDataStart) { - variableLength += blockLength; - ++ObjectDataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)ObjectDataCount; - for (i = ObjectDataStart; i < ObjectDataStart + ObjectDataCount; i++) { ObjectData[i].ToBytes(packet, ref length); } - ObjectDataStart += ObjectDataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - ObjectDataStart < ObjectData.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class ObjectSaleInfoPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class ObjectDataBlock : PacketBlock - { - public uint LocalID; - public byte SaleType; - public int SalePrice; - - public override int Length - { - get - { - return 9; - } - } - - public ObjectDataBlock() { } - public ObjectDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(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(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UIntToBytes(LocalID, bytes, i); i += 4; - bytes[i++] = SaleType; - Utils.IntToBytes(SalePrice, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentData.Length; - for (int j = 0; j < ObjectData.Length; j++) - length += ObjectData[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public ObjectDataBlock[] ObjectData; - - public ObjectSaleInfoPacket() - { - HasVariableBlocks = true; - Type = PacketType.ObjectSaleInfo; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 106; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - ObjectData = null; - } - - public ObjectSaleInfoPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ObjectData == null || ObjectData.Length != -1) { - ObjectData = new ObjectDataBlock[count]; - for(int j = 0; j < count; j++) - { ObjectData[j] = new ObjectDataBlock(); } - } - for (int j = 0; j < count; j++) - { ObjectData[j].FromBytes(bytes, ref i); } - } - - public ObjectSaleInfoPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ObjectData == null || ObjectData.Length != count) { - ObjectData = new ObjectDataBlock[count]; - for(int j = 0; j < count; j++) - { ObjectData[j] = new ObjectDataBlock(); } - } - for (int j = 0; j < count; j++) - { ObjectData[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length++; - for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } - if (Header.AckList != null && 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)ObjectData.Length; - for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int ObjectDataStart = 0; - do - { - int variableLength = 0; - int ObjectDataCount = 0; - - i = ObjectDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < ObjectData.Length) { - int blockLength = ObjectData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ObjectDataStart) { - variableLength += blockLength; - ++ObjectDataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)ObjectDataCount; - for (i = ObjectDataStart; i < ObjectDataStart + ObjectDataCount; i++) { ObjectData[i].ToBytes(packet, ref length); } - ObjectDataStart += ObjectDataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - ObjectDataStart < ObjectData.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class ObjectNamePacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class ObjectDataBlock : PacketBlock - { - public uint LocalID; - public byte[] Name; - - public override int Length - { - get - { - int length = 5; - if (Name != null) { length += Name.Length; } - return length; - } - } - - public ObjectDataBlock() { } - public ObjectDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - LocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - length = bytes[i++]; - Name = new byte[length]; - Buffer.BlockCopy(bytes, i, Name, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UIntToBytes(LocalID, bytes, i); i += 4; - bytes[i++] = (byte)Name.Length; - Buffer.BlockCopy(Name, 0, bytes, i, Name.Length); i += Name.Length; - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentData.Length; - for (int j = 0; j < ObjectData.Length; j++) - length += ObjectData[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public ObjectDataBlock[] ObjectData; - - public ObjectNamePacket() - { - HasVariableBlocks = true; - Type = PacketType.ObjectName; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 107; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - ObjectData = null; - } - - public ObjectNamePacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ObjectData == null || ObjectData.Length != -1) { - ObjectData = new ObjectDataBlock[count]; - for(int j = 0; j < count; j++) - { ObjectData[j] = new ObjectDataBlock(); } - } - for (int j = 0; j < count; j++) - { ObjectData[j].FromBytes(bytes, ref i); } - } - - public ObjectNamePacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ObjectData == null || ObjectData.Length != count) { - ObjectData = new ObjectDataBlock[count]; - for(int j = 0; j < count; j++) - { ObjectData[j] = new ObjectDataBlock(); } - } - for (int j = 0; j < count; j++) - { ObjectData[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length++; - for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } - if (Header.AckList != null && 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)ObjectData.Length; - for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int ObjectDataStart = 0; - do - { - int variableLength = 0; - int ObjectDataCount = 0; - - i = ObjectDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < ObjectData.Length) { - int blockLength = ObjectData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ObjectDataStart) { - variableLength += blockLength; - ++ObjectDataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)ObjectDataCount; - for (i = ObjectDataStart; i < ObjectDataStart + ObjectDataCount; i++) { ObjectData[i].ToBytes(packet, ref length); } - ObjectDataStart += ObjectDataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - ObjectDataStart < ObjectData.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class ObjectDescriptionPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class ObjectDataBlock : PacketBlock - { - public uint LocalID; - public byte[] Description; - - public override int Length - { - get - { - int length = 5; - if (Description != null) { length += Description.Length; } - return length; - } - } - - public ObjectDataBlock() { } - public ObjectDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - LocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - length = bytes[i++]; - Description = new byte[length]; - Buffer.BlockCopy(bytes, i, Description, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UIntToBytes(LocalID, bytes, i); i += 4; - bytes[i++] = (byte)Description.Length; - Buffer.BlockCopy(Description, 0, bytes, i, Description.Length); i += Description.Length; - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentData.Length; - for (int j = 0; j < ObjectData.Length; j++) - length += ObjectData[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public ObjectDataBlock[] ObjectData; - - public ObjectDescriptionPacket() - { - HasVariableBlocks = true; - Type = PacketType.ObjectDescription; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 108; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - ObjectData = null; - } - - public ObjectDescriptionPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ObjectData == null || ObjectData.Length != -1) { - ObjectData = new ObjectDataBlock[count]; - for(int j = 0; j < count; j++) - { ObjectData[j] = new ObjectDataBlock(); } - } - for (int j = 0; j < count; j++) - { ObjectData[j].FromBytes(bytes, ref i); } - } - - public ObjectDescriptionPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ObjectData == null || ObjectData.Length != count) { - ObjectData = new ObjectDataBlock[count]; - for(int j = 0; j < count; j++) - { ObjectData[j] = new ObjectDataBlock(); } - } - for (int j = 0; j < count; j++) - { ObjectData[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length++; - for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } - if (Header.AckList != null && 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)ObjectData.Length; - for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int ObjectDataStart = 0; - do - { - int variableLength = 0; - int ObjectDataCount = 0; - - i = ObjectDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < ObjectData.Length) { - int blockLength = ObjectData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ObjectDataStart) { - variableLength += blockLength; - ++ObjectDataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)ObjectDataCount; - for (i = ObjectDataStart; i < ObjectDataStart + ObjectDataCount; i++) { ObjectData[i].ToBytes(packet, ref length); } - ObjectDataStart += ObjectDataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - ObjectDataStart < ObjectData.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class ObjectCategoryPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class ObjectDataBlock : PacketBlock - { - public uint LocalID; - public uint Category; - - public override int Length - { - get - { - return 8; - } - } - - public ObjectDataBlock() { } - public ObjectDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(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(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UIntToBytes(LocalID, bytes, i); i += 4; - Utils.UIntToBytes(Category, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentData.Length; - for (int j = 0; j < ObjectData.Length; j++) - length += ObjectData[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public ObjectDataBlock[] ObjectData; - - public ObjectCategoryPacket() - { - HasVariableBlocks = true; - Type = PacketType.ObjectCategory; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 109; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - ObjectData = null; - } - - public ObjectCategoryPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ObjectData == null || ObjectData.Length != -1) { - ObjectData = new ObjectDataBlock[count]; - for(int j = 0; j < count; j++) - { ObjectData[j] = new ObjectDataBlock(); } - } - for (int j = 0; j < count; j++) - { ObjectData[j].FromBytes(bytes, ref i); } - } - - public ObjectCategoryPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ObjectData == null || ObjectData.Length != count) { - ObjectData = new ObjectDataBlock[count]; - for(int j = 0; j < count; j++) - { ObjectData[j] = new ObjectDataBlock(); } - } - for (int j = 0; j < count; j++) - { ObjectData[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length++; - for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } - if (Header.AckList != null && 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)ObjectData.Length; - for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int ObjectDataStart = 0; - do - { - int variableLength = 0; - int ObjectDataCount = 0; - - i = ObjectDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < ObjectData.Length) { - int blockLength = ObjectData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ObjectDataStart) { - variableLength += blockLength; - ++ObjectDataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)ObjectDataCount; - for (i = ObjectDataStart; i < ObjectDataStart + ObjectDataCount; i++) { ObjectData[i].ToBytes(packet, ref length); } - ObjectDataStart += ObjectDataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - ObjectDataStart < ObjectData.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class ObjectSelectPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class ObjectDataBlock : PacketBlock - { - public uint ObjectLocalID; - - public override int Length - { - get - { - return 4; - } - } - - public ObjectDataBlock() { } - public ObjectDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - ObjectLocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UIntToBytes(ObjectLocalID, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentData.Length; - for (int j = 0; j < ObjectData.Length; j++) - length += ObjectData[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public ObjectDataBlock[] ObjectData; - - public ObjectSelectPacket() - { - HasVariableBlocks = true; - Type = PacketType.ObjectSelect; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 110; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - ObjectData = null; - } - - public ObjectSelectPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ObjectData == null || ObjectData.Length != -1) { - ObjectData = new ObjectDataBlock[count]; - for(int j = 0; j < count; j++) - { ObjectData[j] = new ObjectDataBlock(); } - } - for (int j = 0; j < count; j++) - { ObjectData[j].FromBytes(bytes, ref i); } - } - - public ObjectSelectPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ObjectData == null || ObjectData.Length != count) { - ObjectData = new ObjectDataBlock[count]; - for(int j = 0; j < count; j++) - { ObjectData[j] = new ObjectDataBlock(); } - } - for (int j = 0; j < count; j++) - { ObjectData[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length++; - for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } - if (Header.AckList != null && 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)ObjectData.Length; - for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int ObjectDataStart = 0; - do - { - int variableLength = 0; - int ObjectDataCount = 0; - - i = ObjectDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < ObjectData.Length) { - int blockLength = ObjectData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ObjectDataStart) { - variableLength += blockLength; - ++ObjectDataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)ObjectDataCount; - for (i = ObjectDataStart; i < ObjectDataStart + ObjectDataCount; i++) { ObjectData[i].ToBytes(packet, ref length); } - ObjectDataStart += ObjectDataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - ObjectDataStart < ObjectData.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class ObjectDeselectPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class ObjectDataBlock : PacketBlock - { - public uint ObjectLocalID; - - public override int Length - { - get - { - return 4; - } - } - - public ObjectDataBlock() { } - public ObjectDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - ObjectLocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UIntToBytes(ObjectLocalID, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentData.Length; - for (int j = 0; j < ObjectData.Length; j++) - length += ObjectData[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public ObjectDataBlock[] ObjectData; - - public ObjectDeselectPacket() - { - HasVariableBlocks = true; - Type = PacketType.ObjectDeselect; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 111; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - ObjectData = null; - } - - public ObjectDeselectPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ObjectData == null || ObjectData.Length != -1) { - ObjectData = new ObjectDataBlock[count]; - for(int j = 0; j < count; j++) - { ObjectData[j] = new ObjectDataBlock(); } - } - for (int j = 0; j < count; j++) - { ObjectData[j].FromBytes(bytes, ref i); } - } - - public ObjectDeselectPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ObjectData == null || ObjectData.Length != count) { - ObjectData = new ObjectDataBlock[count]; - for(int j = 0; j < count; j++) - { ObjectData[j] = new ObjectDataBlock(); } - } - for (int j = 0; j < count; j++) - { ObjectData[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length++; - for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } - if (Header.AckList != null && 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)ObjectData.Length; - for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int ObjectDataStart = 0; - do - { - int variableLength = 0; - int ObjectDataCount = 0; - - i = ObjectDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < ObjectData.Length) { - int blockLength = ObjectData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ObjectDataStart) { - variableLength += blockLength; - ++ObjectDataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)ObjectDataCount; - for (i = ObjectDataStart; i < ObjectDataStart + ObjectDataCount; i++) { ObjectData[i].ToBytes(packet, ref length); } - ObjectDataStart += ObjectDataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - ObjectDataStart < ObjectData.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class ObjectAttachPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - public byte AttachmentPoint; - - public override int Length - { - get - { - return 33; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - AttachmentPoint = (byte)bytes[i++]; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - bytes[i++] = AttachmentPoint; - } - - } - - /// - public sealed class ObjectDataBlock : PacketBlock - { - public uint ObjectLocalID; - public Quaternion Rotation; - - public override int Length - { - get - { - return 16; - } - } - - public ObjectDataBlock() { } - public ObjectDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - ObjectLocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - Rotation.FromBytes(bytes, i, true); i += 12; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UIntToBytes(ObjectLocalID, bytes, i); i += 4; - Rotation.ToBytes(bytes, i); i += 12; - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentData.Length; - for (int j = 0; j < ObjectData.Length; j++) - length += ObjectData[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public ObjectDataBlock[] ObjectData; - - public ObjectAttachPacket() - { - HasVariableBlocks = true; - Type = PacketType.ObjectAttach; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 112; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - ObjectData = null; - } - - public ObjectAttachPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ObjectData == null || ObjectData.Length != -1) { - ObjectData = new ObjectDataBlock[count]; - for(int j = 0; j < count; j++) - { ObjectData[j] = new ObjectDataBlock(); } - } - for (int j = 0; j < count; j++) - { ObjectData[j].FromBytes(bytes, ref i); } - } - - public ObjectAttachPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ObjectData == null || ObjectData.Length != count) { - ObjectData = new ObjectDataBlock[count]; - for(int j = 0; j < count; j++) - { ObjectData[j] = new ObjectDataBlock(); } - } - for (int j = 0; j < count; j++) - { ObjectData[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length++; - for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } - if (Header.AckList != null && 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)ObjectData.Length; - for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int ObjectDataStart = 0; - do - { - int variableLength = 0; - int ObjectDataCount = 0; - - i = ObjectDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < ObjectData.Length) { - int blockLength = ObjectData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ObjectDataStart) { - variableLength += blockLength; - ++ObjectDataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)ObjectDataCount; - for (i = ObjectDataStart; i < ObjectDataStart + ObjectDataCount; i++) { ObjectData[i].ToBytes(packet, ref length); } - ObjectDataStart += ObjectDataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - ObjectDataStart < ObjectData.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class ObjectDetachPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class ObjectDataBlock : PacketBlock - { - public uint ObjectLocalID; - - public override int Length - { - get - { - return 4; - } - } - - public ObjectDataBlock() { } - public ObjectDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - ObjectLocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UIntToBytes(ObjectLocalID, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentData.Length; - for (int j = 0; j < ObjectData.Length; j++) - length += ObjectData[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public ObjectDataBlock[] ObjectData; - - public ObjectDetachPacket() - { - HasVariableBlocks = true; - Type = PacketType.ObjectDetach; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 113; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - ObjectData = null; - } - - public ObjectDetachPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ObjectData == null || ObjectData.Length != -1) { - ObjectData = new ObjectDataBlock[count]; - for(int j = 0; j < count; j++) - { ObjectData[j] = new ObjectDataBlock(); } - } - for (int j = 0; j < count; j++) - { ObjectData[j].FromBytes(bytes, ref i); } - } - - public ObjectDetachPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ObjectData == null || ObjectData.Length != count) { - ObjectData = new ObjectDataBlock[count]; - for(int j = 0; j < count; j++) - { ObjectData[j] = new ObjectDataBlock(); } - } - for (int j = 0; j < count; j++) - { ObjectData[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length++; - for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } - if (Header.AckList != null && 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)ObjectData.Length; - for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int ObjectDataStart = 0; - do - { - int variableLength = 0; - int ObjectDataCount = 0; - - i = ObjectDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < ObjectData.Length) { - int blockLength = ObjectData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ObjectDataStart) { - variableLength += blockLength; - ++ObjectDataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)ObjectDataCount; - for (i = ObjectDataStart; i < ObjectDataStart + ObjectDataCount; i++) { ObjectData[i].ToBytes(packet, ref length); } - ObjectDataStart += ObjectDataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - ObjectDataStart < ObjectData.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class ObjectDropPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class ObjectDataBlock : PacketBlock - { - public uint ObjectLocalID; - - public override int Length - { - get - { - return 4; - } - } - - public ObjectDataBlock() { } - public ObjectDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - ObjectLocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UIntToBytes(ObjectLocalID, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentData.Length; - for (int j = 0; j < ObjectData.Length; j++) - length += ObjectData[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public ObjectDataBlock[] ObjectData; - - public ObjectDropPacket() - { - HasVariableBlocks = true; - Type = PacketType.ObjectDrop; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 114; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - ObjectData = null; - } - - public ObjectDropPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ObjectData == null || ObjectData.Length != -1) { - ObjectData = new ObjectDataBlock[count]; - for(int j = 0; j < count; j++) - { ObjectData[j] = new ObjectDataBlock(); } - } - for (int j = 0; j < count; j++) - { ObjectData[j].FromBytes(bytes, ref i); } - } - - public ObjectDropPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ObjectData == null || ObjectData.Length != count) { - ObjectData = new ObjectDataBlock[count]; - for(int j = 0; j < count; j++) - { ObjectData[j] = new ObjectDataBlock(); } - } - for (int j = 0; j < count; j++) - { ObjectData[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length++; - for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } - if (Header.AckList != null && 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)ObjectData.Length; - for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int ObjectDataStart = 0; - do - { - int variableLength = 0; - int ObjectDataCount = 0; - - i = ObjectDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < ObjectData.Length) { - int blockLength = ObjectData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ObjectDataStart) { - variableLength += blockLength; - ++ObjectDataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)ObjectDataCount; - for (i = ObjectDataStart; i < ObjectDataStart + ObjectDataCount; i++) { ObjectData[i].ToBytes(packet, ref length); } - ObjectDataStart += ObjectDataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - ObjectDataStart < ObjectData.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class ObjectLinkPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class ObjectDataBlock : PacketBlock - { - public uint ObjectLocalID; - - public override int Length - { - get - { - return 4; - } - } - - public ObjectDataBlock() { } - public ObjectDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - ObjectLocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UIntToBytes(ObjectLocalID, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentData.Length; - for (int j = 0; j < ObjectData.Length; j++) - length += ObjectData[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public ObjectDataBlock[] ObjectData; - - public ObjectLinkPacket() - { - HasVariableBlocks = true; - Type = PacketType.ObjectLink; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 115; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - ObjectData = null; - } - - public ObjectLinkPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ObjectData == null || ObjectData.Length != -1) { - ObjectData = new ObjectDataBlock[count]; - for(int j = 0; j < count; j++) - { ObjectData[j] = new ObjectDataBlock(); } - } - for (int j = 0; j < count; j++) - { ObjectData[j].FromBytes(bytes, ref i); } - } - - public ObjectLinkPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ObjectData == null || ObjectData.Length != count) { - ObjectData = new ObjectDataBlock[count]; - for(int j = 0; j < count; j++) - { ObjectData[j] = new ObjectDataBlock(); } - } - for (int j = 0; j < count; j++) - { ObjectData[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length++; - for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } - if (Header.AckList != null && 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)ObjectData.Length; - for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int ObjectDataStart = 0; - do - { - int variableLength = 0; - int ObjectDataCount = 0; - - i = ObjectDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < ObjectData.Length) { - int blockLength = ObjectData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ObjectDataStart) { - variableLength += blockLength; - ++ObjectDataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)ObjectDataCount; - for (i = ObjectDataStart; i < ObjectDataStart + ObjectDataCount; i++) { ObjectData[i].ToBytes(packet, ref length); } - ObjectDataStart += ObjectDataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - ObjectDataStart < ObjectData.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class ObjectDelinkPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class ObjectDataBlock : PacketBlock - { - public uint ObjectLocalID; - - public override int Length - { - get - { - return 4; - } - } - - public ObjectDataBlock() { } - public ObjectDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - ObjectLocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UIntToBytes(ObjectLocalID, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentData.Length; - for (int j = 0; j < ObjectData.Length; j++) - length += ObjectData[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public ObjectDataBlock[] ObjectData; - - public ObjectDelinkPacket() - { - HasVariableBlocks = true; - Type = PacketType.ObjectDelink; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 116; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - ObjectData = null; - } - - public ObjectDelinkPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ObjectData == null || ObjectData.Length != -1) { - ObjectData = new ObjectDataBlock[count]; - for(int j = 0; j < count; j++) - { ObjectData[j] = new ObjectDataBlock(); } - } - for (int j = 0; j < count; j++) - { ObjectData[j].FromBytes(bytes, ref i); } - } - - public ObjectDelinkPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ObjectData == null || ObjectData.Length != count) { - ObjectData = new ObjectDataBlock[count]; - for(int j = 0; j < count; j++) - { ObjectData[j] = new ObjectDataBlock(); } - } - for (int j = 0; j < count; j++) - { ObjectData[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length++; - for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } - if (Header.AckList != null && 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)ObjectData.Length; - for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int ObjectDataStart = 0; - do - { - int variableLength = 0; - int ObjectDataCount = 0; - - i = ObjectDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < ObjectData.Length) { - int blockLength = ObjectData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ObjectDataStart) { - variableLength += blockLength; - ++ObjectDataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)ObjectDataCount; - for (i = ObjectDataStart; i < ObjectDataStart + ObjectDataCount; i++) { ObjectData[i].ToBytes(packet, ref length); } - ObjectDataStart += ObjectDataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - ObjectDataStart < ObjectData.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class ObjectGrabPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class ObjectDataBlock : PacketBlock - { - public uint LocalID; - public Vector3 GrabOffset; - - public override int Length - { - get - { - return 16; - } - } - - public ObjectDataBlock() { } - public ObjectDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - LocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - GrabOffset.FromBytes(bytes, i); i += 12; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UIntToBytes(LocalID, bytes, i); i += 4; - GrabOffset.ToBytes(bytes, i); i += 12; - } - - } - - /// - public sealed class SurfaceInfoBlock : PacketBlock - { - public Vector3 UVCoord; - public Vector3 STCoord; - public int FaceIndex; - public Vector3 Position; - public Vector3 Normal; - public Vector3 Binormal; - - public override int Length - { - get - { - return 64; - } - } - - public SurfaceInfoBlock() { } - public SurfaceInfoBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - UVCoord.FromBytes(bytes, i); i += 12; - STCoord.FromBytes(bytes, i); i += 12; - FaceIndex = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - Position.FromBytes(bytes, i); i += 12; - Normal.FromBytes(bytes, i); i += 12; - Binormal.FromBytes(bytes, i); i += 12; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - UVCoord.ToBytes(bytes, i); i += 12; - STCoord.ToBytes(bytes, i); i += 12; - Utils.IntToBytes(FaceIndex, bytes, i); i += 4; - Position.ToBytes(bytes, i); i += 12; - Normal.ToBytes(bytes, i); i += 12; - Binormal.ToBytes(bytes, i); i += 12; - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentData.Length; - length += ObjectData.Length; - for (int j = 0; j < SurfaceInfo.Length; j++) - length += SurfaceInfo[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public ObjectDataBlock ObjectData; - public SurfaceInfoBlock[] SurfaceInfo; - - public ObjectGrabPacket() - { - HasVariableBlocks = true; - Type = PacketType.ObjectGrab; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 117; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - ObjectData = new ObjectDataBlock(); - SurfaceInfo = null; - } - - public ObjectGrabPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - ObjectData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(SurfaceInfo == null || SurfaceInfo.Length != -1) { - SurfaceInfo = new SurfaceInfoBlock[count]; - for(int j = 0; j < count; j++) - { SurfaceInfo[j] = new SurfaceInfoBlock(); } - } - for (int j = 0; j < count; j++) - { SurfaceInfo[j].FromBytes(bytes, ref i); } - } - - public ObjectGrabPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - ObjectData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(SurfaceInfo == null || SurfaceInfo.Length != count) { - SurfaceInfo = new SurfaceInfoBlock[count]; - for(int j = 0; j < count; j++) - { SurfaceInfo[j] = new SurfaceInfoBlock(); } - } - for (int j = 0; j < count; j++) - { SurfaceInfo[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += ObjectData.Length; - length++; - for (int j = 0; j < SurfaceInfo.Length; j++) { length += SurfaceInfo[j].Length; } - if (Header.AckList != null && 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); - ObjectData.ToBytes(bytes, ref i); - bytes[i++] = (byte)SurfaceInfo.Length; - for (int j = 0; j < SurfaceInfo.Length; j++) { SurfaceInfo[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - fixedLength += ObjectData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - ObjectData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int SurfaceInfoStart = 0; - do - { - int variableLength = 0; - int SurfaceInfoCount = 0; - - i = SurfaceInfoStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < SurfaceInfo.Length) { - int blockLength = SurfaceInfo[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == SurfaceInfoStart) { - variableLength += blockLength; - ++SurfaceInfoCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)SurfaceInfoCount; - for (i = SurfaceInfoStart; i < SurfaceInfoStart + SurfaceInfoCount; i++) { SurfaceInfo[i].ToBytes(packet, ref length); } - SurfaceInfoStart += SurfaceInfoCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - SurfaceInfoStart < SurfaceInfo.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class ObjectGrabUpdatePacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class ObjectDataBlock : PacketBlock - { - public UUID ObjectID; - public Vector3 GrabOffsetInitial; - public Vector3 GrabPosition; - public uint TimeSinceLast; - - public override int Length - { - get - { - return 44; - } - } - - public ObjectDataBlock() { } - public ObjectDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - ObjectID.FromBytes(bytes, i); i += 16; - GrabOffsetInitial.FromBytes(bytes, i); i += 12; - GrabPosition.FromBytes(bytes, i); i += 12; - TimeSinceLast = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - ObjectID.ToBytes(bytes, i); i += 16; - GrabOffsetInitial.ToBytes(bytes, i); i += 12; - GrabPosition.ToBytes(bytes, i); i += 12; - Utils.UIntToBytes(TimeSinceLast, bytes, i); i += 4; - } - - } - - /// - public sealed class SurfaceInfoBlock : PacketBlock - { - public Vector3 UVCoord; - public Vector3 STCoord; - public int FaceIndex; - public Vector3 Position; - public Vector3 Normal; - public Vector3 Binormal; - - public override int Length - { - get - { - return 64; - } - } - - public SurfaceInfoBlock() { } - public SurfaceInfoBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - UVCoord.FromBytes(bytes, i); i += 12; - STCoord.FromBytes(bytes, i); i += 12; - FaceIndex = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - Position.FromBytes(bytes, i); i += 12; - Normal.FromBytes(bytes, i); i += 12; - Binormal.FromBytes(bytes, i); i += 12; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - UVCoord.ToBytes(bytes, i); i += 12; - STCoord.ToBytes(bytes, i); i += 12; - Utils.IntToBytes(FaceIndex, bytes, i); i += 4; - Position.ToBytes(bytes, i); i += 12; - Normal.ToBytes(bytes, i); i += 12; - Binormal.ToBytes(bytes, i); i += 12; - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentData.Length; - length += ObjectData.Length; - for (int j = 0; j < SurfaceInfo.Length; j++) - length += SurfaceInfo[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public ObjectDataBlock ObjectData; - public SurfaceInfoBlock[] SurfaceInfo; - - public ObjectGrabUpdatePacket() - { - HasVariableBlocks = true; - Type = PacketType.ObjectGrabUpdate; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 118; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - ObjectData = new ObjectDataBlock(); - SurfaceInfo = null; - } - - public ObjectGrabUpdatePacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - ObjectData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(SurfaceInfo == null || SurfaceInfo.Length != -1) { - SurfaceInfo = new SurfaceInfoBlock[count]; - for(int j = 0; j < count; j++) - { SurfaceInfo[j] = new SurfaceInfoBlock(); } - } - for (int j = 0; j < count; j++) - { SurfaceInfo[j].FromBytes(bytes, ref i); } - } - - public ObjectGrabUpdatePacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - ObjectData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(SurfaceInfo == null || SurfaceInfo.Length != count) { - SurfaceInfo = new SurfaceInfoBlock[count]; - for(int j = 0; j < count; j++) - { SurfaceInfo[j] = new SurfaceInfoBlock(); } - } - for (int j = 0; j < count; j++) - { SurfaceInfo[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += ObjectData.Length; - length++; - for (int j = 0; j < SurfaceInfo.Length; j++) { length += SurfaceInfo[j].Length; } - if (Header.AckList != null && 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); - ObjectData.ToBytes(bytes, ref i); - bytes[i++] = (byte)SurfaceInfo.Length; - for (int j = 0; j < SurfaceInfo.Length; j++) { SurfaceInfo[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - fixedLength += ObjectData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - ObjectData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int SurfaceInfoStart = 0; - do - { - int variableLength = 0; - int SurfaceInfoCount = 0; - - i = SurfaceInfoStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < SurfaceInfo.Length) { - int blockLength = SurfaceInfo[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == SurfaceInfoStart) { - variableLength += blockLength; - ++SurfaceInfoCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)SurfaceInfoCount; - for (i = SurfaceInfoStart; i < SurfaceInfoStart + SurfaceInfoCount; i++) { SurfaceInfo[i].ToBytes(packet, ref length); } - SurfaceInfoStart += SurfaceInfoCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - SurfaceInfoStart < SurfaceInfo.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class ObjectDeGrabPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class ObjectDataBlock : PacketBlock - { - public uint LocalID; - - public override int Length - { - get - { - return 4; - } - } - - public ObjectDataBlock() { } - public ObjectDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - LocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UIntToBytes(LocalID, bytes, i); i += 4; - } - - } - - /// - public sealed class SurfaceInfoBlock : PacketBlock - { - public Vector3 UVCoord; - public Vector3 STCoord; - public int FaceIndex; - public Vector3 Position; - public Vector3 Normal; - public Vector3 Binormal; - - public override int Length - { - get - { - return 64; - } - } - - public SurfaceInfoBlock() { } - public SurfaceInfoBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - UVCoord.FromBytes(bytes, i); i += 12; - STCoord.FromBytes(bytes, i); i += 12; - FaceIndex = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - Position.FromBytes(bytes, i); i += 12; - Normal.FromBytes(bytes, i); i += 12; - Binormal.FromBytes(bytes, i); i += 12; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - UVCoord.ToBytes(bytes, i); i += 12; - STCoord.ToBytes(bytes, i); i += 12; - Utils.IntToBytes(FaceIndex, bytes, i); i += 4; - Position.ToBytes(bytes, i); i += 12; - Normal.ToBytes(bytes, i); i += 12; - Binormal.ToBytes(bytes, i); i += 12; - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentData.Length; - length += ObjectData.Length; - for (int j = 0; j < SurfaceInfo.Length; j++) - length += SurfaceInfo[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public ObjectDataBlock ObjectData; - public SurfaceInfoBlock[] SurfaceInfo; - - public ObjectDeGrabPacket() - { - HasVariableBlocks = true; - Type = PacketType.ObjectDeGrab; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 119; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - ObjectData = new ObjectDataBlock(); - SurfaceInfo = null; - } - - public ObjectDeGrabPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - ObjectData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(SurfaceInfo == null || SurfaceInfo.Length != -1) { - SurfaceInfo = new SurfaceInfoBlock[count]; - for(int j = 0; j < count; j++) - { SurfaceInfo[j] = new SurfaceInfoBlock(); } - } - for (int j = 0; j < count; j++) - { SurfaceInfo[j].FromBytes(bytes, ref i); } - } - - public ObjectDeGrabPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - ObjectData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(SurfaceInfo == null || SurfaceInfo.Length != count) { - SurfaceInfo = new SurfaceInfoBlock[count]; - for(int j = 0; j < count; j++) - { SurfaceInfo[j] = new SurfaceInfoBlock(); } - } - for (int j = 0; j < count; j++) - { SurfaceInfo[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += ObjectData.Length; - length++; - for (int j = 0; j < SurfaceInfo.Length; j++) { length += SurfaceInfo[j].Length; } - if (Header.AckList != null && 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); - ObjectData.ToBytes(bytes, ref i); - bytes[i++] = (byte)SurfaceInfo.Length; - for (int j = 0; j < SurfaceInfo.Length; j++) { SurfaceInfo[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - fixedLength += ObjectData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - ObjectData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int SurfaceInfoStart = 0; - do - { - int variableLength = 0; - int SurfaceInfoCount = 0; - - i = SurfaceInfoStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < SurfaceInfo.Length) { - int blockLength = SurfaceInfo[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == SurfaceInfoStart) { - variableLength += blockLength; - ++SurfaceInfoCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)SurfaceInfoCount; - for (i = SurfaceInfoStart; i < SurfaceInfoStart + SurfaceInfoCount; i++) { SurfaceInfo[i].ToBytes(packet, ref length); } - SurfaceInfoStart += SurfaceInfoCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - SurfaceInfoStart < SurfaceInfo.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class ObjectSpinStartPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class ObjectDataBlock : PacketBlock - { - public UUID ObjectID; - - public override int Length - { - get - { - return 16; - } - } - - public ObjectDataBlock() { } - public ObjectDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - ObjectID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - ObjectID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += ObjectData.Length; - return length; - } - } - public AgentDataBlock AgentData; - public ObjectDataBlock ObjectData; - - public ObjectSpinStartPacket() - { - HasVariableBlocks = false; - Type = PacketType.ObjectSpinStart; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 120; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - ObjectData = new ObjectDataBlock(); - } - - public ObjectSpinStartPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - ObjectData.FromBytes(bytes, ref i); - } - - public ObjectSpinStartPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - ObjectData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += ObjectData.Length; - if (Header.AckList != null && 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); - ObjectData.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class ObjectSpinUpdatePacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class ObjectDataBlock : PacketBlock - { - public UUID ObjectID; - public Quaternion Rotation; - - public override int Length - { - get - { - return 28; - } - } - - public ObjectDataBlock() { } - public ObjectDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - ObjectID.FromBytes(bytes, i); i += 16; - Rotation.FromBytes(bytes, i, true); i += 12; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - ObjectID.ToBytes(bytes, i); i += 16; - Rotation.ToBytes(bytes, i); i += 12; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += ObjectData.Length; - return length; - } - } - public AgentDataBlock AgentData; - public ObjectDataBlock ObjectData; - - public ObjectSpinUpdatePacket() - { - HasVariableBlocks = false; - Type = PacketType.ObjectSpinUpdate; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 121; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - ObjectData = new ObjectDataBlock(); - } - - public ObjectSpinUpdatePacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - ObjectData.FromBytes(bytes, ref i); - } - - public ObjectSpinUpdatePacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - ObjectData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += ObjectData.Length; - if (Header.AckList != null && 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); - ObjectData.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class ObjectSpinStopPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class ObjectDataBlock : PacketBlock - { - public UUID ObjectID; - - public override int Length - { - get - { - return 16; - } - } - - public ObjectDataBlock() { } - public ObjectDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - ObjectID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - ObjectID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += ObjectData.Length; - return length; - } - } - public AgentDataBlock AgentData; - public ObjectDataBlock ObjectData; - - public ObjectSpinStopPacket() - { - HasVariableBlocks = false; - Type = PacketType.ObjectSpinStop; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 122; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - ObjectData = new ObjectDataBlock(); - } - - public ObjectSpinStopPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - ObjectData.FromBytes(bytes, ref i); - } - - public ObjectSpinStopPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - ObjectData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += ObjectData.Length; - if (Header.AckList != null && 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); - ObjectData.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class ObjectExportSelectedPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID RequestID; - public short VolumeDetail; - - public override int Length - { - get - { - return 34; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - RequestID.FromBytes(bytes, i); i += 16; - VolumeDetail = (short)(bytes[i++] + (bytes[i++] << 8)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - RequestID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)(VolumeDetail % 256); - bytes[i++] = (byte)((VolumeDetail >> 8) % 256); - } - - } - - /// - public sealed class ObjectDataBlock : PacketBlock - { - public UUID ObjectID; - - public override int Length - { - get - { - return 16; - } - } - - public ObjectDataBlock() { } - public ObjectDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - ObjectID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - ObjectID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentData.Length; - for (int j = 0; j < ObjectData.Length; j++) - length += ObjectData[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public ObjectDataBlock[] ObjectData; - - public ObjectExportSelectedPacket() - { - HasVariableBlocks = true; - Type = PacketType.ObjectExportSelected; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 123; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - ObjectData = null; - } - - public ObjectExportSelectedPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ObjectData == null || ObjectData.Length != -1) { - ObjectData = new ObjectDataBlock[count]; - for(int j = 0; j < count; j++) - { ObjectData[j] = new ObjectDataBlock(); } - } - for (int j = 0; j < count; j++) - { ObjectData[j].FromBytes(bytes, ref i); } - } - - public ObjectExportSelectedPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ObjectData == null || ObjectData.Length != count) { - ObjectData = new ObjectDataBlock[count]; - for(int j = 0; j < count; j++) - { ObjectData[j] = new ObjectDataBlock(); } - } - for (int j = 0; j < count; j++) - { ObjectData[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length++; - for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } - if (Header.AckList != null && 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)ObjectData.Length; - for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int ObjectDataStart = 0; - do - { - int variableLength = 0; - int ObjectDataCount = 0; - - i = ObjectDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < ObjectData.Length) { - int blockLength = ObjectData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ObjectDataStart) { - variableLength += blockLength; - ++ObjectDataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)ObjectDataCount; - for (i = ObjectDataStart; i < ObjectDataStart + ObjectDataCount; i++) { ObjectData[i].ToBytes(packet, ref length); } - ObjectDataStart += ObjectDataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - ObjectDataStart < ObjectData.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class ModifyLandPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class ModifyBlockBlock : PacketBlock - { - public byte Action; - public byte BrushSize; - public float Seconds; - public float Height; - - public override int Length - { - get - { - return 10; - } - } - - public ModifyBlockBlock() { } - public ModifyBlockBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - Action = (byte)bytes[i++]; - BrushSize = (byte)bytes[i++]; - Seconds = Utils.BytesToFloat(bytes, i); i += 4; - Height = Utils.BytesToFloat(bytes, i); i += 4; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - bytes[i++] = Action; - bytes[i++] = BrushSize; - Utils.FloatToBytes(Seconds, bytes, i); i += 4; - Utils.FloatToBytes(Height, bytes, i); i += 4; - } - - } - - /// - public sealed class ParcelDataBlock : PacketBlock - { - public int LocalID; - public float West; - public float South; - public float East; - public float North; - - public override int Length - { - get - { - return 20; - } - } - - public ParcelDataBlock() { } - public ParcelDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - LocalID = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - West = Utils.BytesToFloat(bytes, i); i += 4; - South = Utils.BytesToFloat(bytes, i); i += 4; - East = Utils.BytesToFloat(bytes, i); i += 4; - North = Utils.BytesToFloat(bytes, i); i += 4; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.IntToBytes(LocalID, bytes, i); i += 4; - Utils.FloatToBytes(West, bytes, i); i += 4; - Utils.FloatToBytes(South, bytes, i); i += 4; - Utils.FloatToBytes(East, bytes, i); i += 4; - Utils.FloatToBytes(North, bytes, i); i += 4; - } - - } - - /// - public sealed class ModifyBlockExtendedBlock : PacketBlock - { - public float BrushSize; - - public override int Length - { - get - { - return 4; - } - } - - public ModifyBlockExtendedBlock() { } - public ModifyBlockExtendedBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - BrushSize = Utils.BytesToFloat(bytes, i); i += 4; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.FloatToBytes(BrushSize, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 12; - length += AgentData.Length; - length += ModifyBlock.Length; - for (int j = 0; j < ParcelData.Length; j++) - length += ParcelData[j].Length; - for (int j = 0; j < ModifyBlockExtended.Length; j++) - length += ModifyBlockExtended[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public ModifyBlockBlock ModifyBlock; - public ParcelDataBlock[] ParcelData; - public ModifyBlockExtendedBlock[] ModifyBlockExtended; - - public ModifyLandPacket() - { - HasVariableBlocks = true; - Type = PacketType.ModifyLand; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 124; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - ModifyBlock = new ModifyBlockBlock(); - ParcelData = null; - ModifyBlockExtended = null; - } - - public ModifyLandPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - ModifyBlock.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ParcelData == null || ParcelData.Length != -1) { - ParcelData = new ParcelDataBlock[count]; - for(int j = 0; j < count; j++) - { ParcelData[j] = new ParcelDataBlock(); } - } - for (int j = 0; j < count; j++) - { ParcelData[j].FromBytes(bytes, ref i); } - count = (int)bytes[i++]; - if(ModifyBlockExtended == null || ModifyBlockExtended.Length != -1) { - ModifyBlockExtended = new ModifyBlockExtendedBlock[count]; - for(int j = 0; j < count; j++) - { ModifyBlockExtended[j] = new ModifyBlockExtendedBlock(); } - } - for (int j = 0; j < count; j++) - { ModifyBlockExtended[j].FromBytes(bytes, ref i); } - } - - public ModifyLandPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - ModifyBlock.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ParcelData == null || ParcelData.Length != count) { - ParcelData = new ParcelDataBlock[count]; - for(int j = 0; j < count; j++) - { ParcelData[j] = new ParcelDataBlock(); } - } - for (int j = 0; j < count; j++) - { ParcelData[j].FromBytes(bytes, ref i); } - count = (int)bytes[i++]; - if(ModifyBlockExtended == null || ModifyBlockExtended.Length != count) { - ModifyBlockExtended = new ModifyBlockExtendedBlock[count]; - for(int j = 0; j < count; j++) - { ModifyBlockExtended[j] = new ModifyBlockExtendedBlock(); } - } - for (int j = 0; j < count; j++) - { ModifyBlockExtended[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += ModifyBlock.Length; - length++; - for (int j = 0; j < ParcelData.Length; j++) { length += ParcelData[j].Length; } - length++; - for (int j = 0; j < ModifyBlockExtended.Length; j++) { length += ModifyBlockExtended[j].Length; } - if (Header.AckList != null && 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); - ModifyBlock.ToBytes(bytes, ref i); - bytes[i++] = (byte)ParcelData.Length; - for (int j = 0; j < ParcelData.Length; j++) { ParcelData[j].ToBytes(bytes, ref i); } - bytes[i++] = (byte)ModifyBlockExtended.Length; - for (int j = 0; j < ModifyBlockExtended.Length; j++) { ModifyBlockExtended[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - fixedLength += ModifyBlock.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - ModifyBlock.ToBytes(fixedBytes, ref i); - fixedLength += 2; - - int ParcelDataStart = 0; - int ModifyBlockExtendedStart = 0; - do - { - int variableLength = 0; - int ParcelDataCount = 0; - int ModifyBlockExtendedCount = 0; - - i = ParcelDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < ParcelData.Length) { - int blockLength = ParcelData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ParcelDataStart) { - variableLength += blockLength; - ++ParcelDataCount; - } - else { break; } - ++i; - } - - i = ModifyBlockExtendedStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < ModifyBlockExtended.Length) { - int blockLength = ModifyBlockExtended[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ModifyBlockExtendedStart) { - variableLength += blockLength; - ++ModifyBlockExtendedCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)ParcelDataCount; - for (i = ParcelDataStart; i < ParcelDataStart + ParcelDataCount; i++) { ParcelData[i].ToBytes(packet, ref length); } - ParcelDataStart += ParcelDataCount; - - packet[length++] = (byte)ModifyBlockExtendedCount; - for (i = ModifyBlockExtendedStart; i < ModifyBlockExtendedStart + ModifyBlockExtendedCount; i++) { ModifyBlockExtended[i].ToBytes(packet, ref length); } - ModifyBlockExtendedStart += ModifyBlockExtendedCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - ParcelDataStart < ParcelData.Length || - ModifyBlockExtendedStart < ModifyBlockExtended.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class VelocityInterpolateOnPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - return length; - } - } - public AgentDataBlock AgentData; - - public VelocityInterpolateOnPacket() - { - HasVariableBlocks = false; - Type = PacketType.VelocityInterpolateOn; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 125; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - } - - public VelocityInterpolateOnPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - } - - public VelocityInterpolateOnPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class VelocityInterpolateOffPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - return length; - } - } - public AgentDataBlock AgentData; - - public VelocityInterpolateOffPacket() - { - HasVariableBlocks = false; - Type = PacketType.VelocityInterpolateOff; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 126; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - } - - public VelocityInterpolateOffPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - } - - public VelocityInterpolateOffPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class StateSavePacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class DataBlockBlock : PacketBlock - { - public byte[] Filename; - - public override int Length - { - get - { - int length = 1; - if (Filename != null) { length += Filename.Length; } - return length; - } - } - - public DataBlockBlock() { } - public DataBlockBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - length = bytes[i++]; - Filename = new byte[length]; - Buffer.BlockCopy(bytes, i, Filename, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - bytes[i++] = (byte)Filename.Length; - Buffer.BlockCopy(Filename, 0, bytes, i, Filename.Length); i += Filename.Length; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += DataBlock.Length; - return length; - } - } - public AgentDataBlock AgentData; - public DataBlockBlock DataBlock; - - public StateSavePacket() - { - HasVariableBlocks = false; - Type = PacketType.StateSave; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 127; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - DataBlock = new DataBlockBlock(); - } - - public StateSavePacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - DataBlock.FromBytes(bytes, ref i); - } - - public StateSavePacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - DataBlock.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += DataBlock.Length; - if (Header.AckList != null && 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); - DataBlock.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class ReportAutosaveCrashPacket : Packet - { - /// - public sealed class AutosaveDataBlock : PacketBlock - { - public int PID; - public int Status; - - public override int Length - { - get - { - return 8; - } - } - - public AutosaveDataBlock() { } - public AutosaveDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(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(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.IntToBytes(PID, bytes, i); i += 4; - Utils.IntToBytes(Status, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AutosaveData.Length; - return length; - } - } - public AutosaveDataBlock AutosaveData; - - public ReportAutosaveCrashPacket() - { - HasVariableBlocks = false; - Type = PacketType.ReportAutosaveCrash; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 128; - Header.Reliable = true; - AutosaveData = new AutosaveDataBlock(); - } - - public ReportAutosaveCrashPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AutosaveData.FromBytes(bytes, ref i); - } - - public ReportAutosaveCrashPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AutosaveData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AutosaveData.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class SimWideDeletesPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class DataBlockBlock : PacketBlock - { - public UUID TargetID; - public uint Flags; - - public override int Length - { - get - { - return 20; - } - } - - public DataBlockBlock() { } - public DataBlockBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - TargetID.FromBytes(bytes, i); i += 16; - Flags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - TargetID.ToBytes(bytes, i); i += 16; - Utils.UIntToBytes(Flags, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += DataBlock.Length; - return length; - } - } - public AgentDataBlock AgentData; - public DataBlockBlock DataBlock; - - public SimWideDeletesPacket() - { - HasVariableBlocks = false; - Type = PacketType.SimWideDeletes; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 129; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - DataBlock = new DataBlockBlock(); - } - - public SimWideDeletesPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - DataBlock.FromBytes(bytes, ref i); - } - - public SimWideDeletesPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - DataBlock.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += DataBlock.Length; - if (Header.AckList != null && 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); - DataBlock.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class TrackAgentPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class TargetDataBlock : PacketBlock - { - public UUID PreyID; - - public override int Length - { - get - { - return 16; - } - } - - public TargetDataBlock() { } - public TargetDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - PreyID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - PreyID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += TargetData.Length; - return length; - } - } - public AgentDataBlock AgentData; - public TargetDataBlock TargetData; - - public TrackAgentPacket() - { - HasVariableBlocks = false; - Type = PacketType.TrackAgent; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 130; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - TargetData = new TargetDataBlock(); - } - - public TrackAgentPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - TargetData.FromBytes(bytes, ref i); - } - - public TrackAgentPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - TargetData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += TargetData.Length; - if (Header.AckList != null && 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); - TargetData.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class ViewerStatsPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - public uint IP; - public uint StartTime; - public float RunTime; - public float SimFPS; - public float FPS; - public byte AgentsInView; - public float Ping; - public double MetersTraveled; - public int RegionsVisited; - public uint SysRAM; - public byte[] SysOS; - public byte[] SysCPU; - public byte[] SysGPU; - - public override int Length - { - get - { - int length = 76; - if (SysOS != null) { length += SysOS.Length; } - if (SysCPU != null) { length += SysCPU.Length; } - if (SysGPU != null) { length += SysGPU.Length; } - return length; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - IP = (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)); - RunTime = Utils.BytesToFloat(bytes, i); i += 4; - SimFPS = Utils.BytesToFloat(bytes, i); i += 4; - FPS = Utils.BytesToFloat(bytes, i); i += 4; - AgentsInView = (byte)bytes[i++]; - Ping = Utils.BytesToFloat(bytes, i); i += 4; - MetersTraveled = Utils.BytesToDouble(bytes, i); i += 8; - RegionsVisited = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - SysRAM = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - length = bytes[i++]; - SysOS = new byte[length]; - Buffer.BlockCopy(bytes, i, SysOS, 0, length); i += length; - length = bytes[i++]; - SysCPU = new byte[length]; - Buffer.BlockCopy(bytes, i, SysCPU, 0, length); i += length; - length = bytes[i++]; - SysGPU = new byte[length]; - Buffer.BlockCopy(bytes, i, SysGPU, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - Utils.UIntToBytes(IP, bytes, i); i += 4; - Utils.UIntToBytes(StartTime, bytes, i); i += 4; - Utils.FloatToBytes(RunTime, bytes, i); i += 4; - Utils.FloatToBytes(SimFPS, bytes, i); i += 4; - Utils.FloatToBytes(FPS, bytes, i); i += 4; - bytes[i++] = AgentsInView; - Utils.FloatToBytes(Ping, bytes, i); i += 4; - Utils.DoubleToBytes(MetersTraveled, bytes, i); i += 8; - Utils.IntToBytes(RegionsVisited, bytes, i); i += 4; - Utils.UIntToBytes(SysRAM, bytes, i); i += 4; - bytes[i++] = (byte)SysOS.Length; - Buffer.BlockCopy(SysOS, 0, bytes, i, SysOS.Length); i += SysOS.Length; - bytes[i++] = (byte)SysCPU.Length; - Buffer.BlockCopy(SysCPU, 0, bytes, i, SysCPU.Length); i += SysCPU.Length; - bytes[i++] = (byte)SysGPU.Length; - Buffer.BlockCopy(SysGPU, 0, bytes, i, SysGPU.Length); i += SysGPU.Length; - } - - } - - /// - public sealed class DownloadTotalsBlock : PacketBlock - { - public uint World; - public uint Objects; - public uint Textures; - - public override int Length - { - get - { - return 12; - } - } - - public DownloadTotalsBlock() { } - public DownloadTotalsBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - World = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - 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)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UIntToBytes(World, bytes, i); i += 4; - Utils.UIntToBytes(Objects, bytes, i); i += 4; - Utils.UIntToBytes(Textures, bytes, i); i += 4; - } - - } - - /// - public sealed class NetStatsBlock : PacketBlock - { - public uint Bytes; - public uint Packets; - public uint Compressed; - public uint Savings; - - public override int Length - { - get - { - return 16; - } - } - - public NetStatsBlock() { } - public NetStatsBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - Bytes = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - Packets = (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)); - Savings = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UIntToBytes(Bytes, bytes, i); i += 4; - Utils.UIntToBytes(Packets, bytes, i); i += 4; - Utils.UIntToBytes(Compressed, bytes, i); i += 4; - Utils.UIntToBytes(Savings, bytes, i); i += 4; - } - - } - - /// - public sealed class FailStatsBlock : PacketBlock - { - public uint SendPacket; - public uint Dropped; - public uint Resent; - public uint FailedResends; - public uint OffCircuit; - public uint Invalid; - - public override int Length - { - get - { - return 24; - } - } - - public FailStatsBlock() { } - public FailStatsBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - 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)); - Resent = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - FailedResends = (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)); - Invalid = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UIntToBytes(SendPacket, bytes, i); i += 4; - Utils.UIntToBytes(Dropped, bytes, i); i += 4; - Utils.UIntToBytes(Resent, bytes, i); i += 4; - Utils.UIntToBytes(FailedResends, bytes, i); i += 4; - Utils.UIntToBytes(OffCircuit, bytes, i); i += 4; - Utils.UIntToBytes(Invalid, bytes, i); i += 4; - } - - } - - /// - public sealed class MiscStatsBlock : PacketBlock - { - public uint Type; - public double Value; - - public override int Length - { - get - { - return 12; - } - } - - public MiscStatsBlock() { } - public MiscStatsBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - Type = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - Value = Utils.BytesToDouble(bytes, i); i += 8; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UIntToBytes(Type, bytes, i); i += 4; - Utils.DoubleToBytes(Value, bytes, i); i += 8; - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentData.Length; - length += DownloadTotals.Length; - for (int j = 0; j < 2; j++) - length += NetStats[j].Length; - length += FailStats.Length; - for (int j = 0; j < MiscStats.Length; j++) - length += MiscStats[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public DownloadTotalsBlock DownloadTotals; - public NetStatsBlock[] NetStats; - public FailStatsBlock FailStats; - public MiscStatsBlock[] MiscStats; - - public ViewerStatsPacket() - { - HasVariableBlocks = true; - Type = PacketType.ViewerStats; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 131; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - DownloadTotals = new DownloadTotalsBlock(); - NetStats = new NetStatsBlock[2]; - FailStats = new FailStatsBlock(); - MiscStats = null; - } - - public ViewerStatsPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - DownloadTotals.FromBytes(bytes, ref i); - if(NetStats == null || NetStats.Length != 2) { - NetStats = new NetStatsBlock[2]; - for(int j = 0; j < 2; j++) - { NetStats[j] = new NetStatsBlock(); } - } - for (int j = 0; j < 2; j++) - { NetStats[j].FromBytes(bytes, ref i); } - FailStats.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(MiscStats == null || MiscStats.Length != -1) { - MiscStats = new MiscStatsBlock[count]; - for(int j = 0; j < count; j++) - { MiscStats[j] = new MiscStatsBlock(); } - } - for (int j = 0; j < count; j++) - { MiscStats[j].FromBytes(bytes, ref i); } - } - - public ViewerStatsPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - DownloadTotals.FromBytes(bytes, ref i); - if(NetStats == null || NetStats.Length != 2) { - NetStats = new NetStatsBlock[2]; - for(int j = 0; j < 2; j++) - { NetStats[j] = new NetStatsBlock(); } - } - for (int j = 0; j < 2; j++) - { NetStats[j].FromBytes(bytes, ref i); } - FailStats.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(MiscStats == null || MiscStats.Length != count) { - MiscStats = new MiscStatsBlock[count]; - for(int j = 0; j < count; j++) - { MiscStats[j] = new MiscStatsBlock(); } - } - for (int j = 0; j < count; j++) - { MiscStats[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += DownloadTotals.Length; - length += FailStats.Length; - for (int j = 0; j < 2; j++) { length += NetStats[j].Length; } - length++; - for (int j = 0; j < MiscStats.Length; j++) { length += MiscStats[j].Length; } - if (Header.AckList != null && 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); - DownloadTotals.ToBytes(bytes, ref i); - for (int j = 0; j < 2; j++) { NetStats[j].ToBytes(bytes, ref i); } - FailStats.ToBytes(bytes, ref i); - bytes[i++] = (byte)MiscStats.Length; - for (int j = 0; j < MiscStats.Length; j++) { MiscStats[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - fixedLength += DownloadTotals.Length; - for (int j = 0; j < 2; j++) { fixedLength += NetStats[j].Length; } - fixedLength += FailStats.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - DownloadTotals.ToBytes(fixedBytes, ref i); - for (int j = 0; j < 2; j++) { NetStats[j].ToBytes(fixedBytes, ref i); } - FailStats.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int MiscStatsStart = 0; - do - { - int variableLength = 0; - int MiscStatsCount = 0; - - i = MiscStatsStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < MiscStats.Length) { - int blockLength = MiscStats[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == MiscStatsStart) { - variableLength += blockLength; - ++MiscStatsCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)MiscStatsCount; - for (i = MiscStatsStart; i < MiscStatsStart + MiscStatsCount; i++) { MiscStats[i].ToBytes(packet, ref length); } - MiscStatsStart += MiscStatsCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - MiscStatsStart < MiscStats.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class ScriptAnswerYesPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class DataBlock : PacketBlock - { - public UUID TaskID; - public UUID ItemID; - public int Questions; - - public override int Length - { - get - { - return 36; - } - } - - public DataBlock() { } - public DataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - TaskID.FromBytes(bytes, i); i += 16; - ItemID.FromBytes(bytes, i); i += 16; - Questions = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - TaskID.ToBytes(bytes, i); i += 16; - ItemID.ToBytes(bytes, i); i += 16; - Utils.IntToBytes(Questions, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += Data.Length; - return length; - } - } - public AgentDataBlock AgentData; - public DataBlock Data; - - public ScriptAnswerYesPacket() - { - HasVariableBlocks = false; - Type = PacketType.ScriptAnswerYes; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 132; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - Data = new DataBlock(); - } - - public ScriptAnswerYesPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - Data.FromBytes(bytes, ref i); - } - - public ScriptAnswerYesPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - Data.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += Data.Length; - if (Header.AckList != null && 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); - Data.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class UserReportPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class ReportDataBlock : PacketBlock - { - public byte ReportType; - public byte Category; - public Vector3 Position; - public byte CheckFlags; - public UUID ScreenshotID; - public UUID ObjectID; - public UUID AbuserID; - public byte[] AbuseRegionName; - public UUID AbuseRegionID; - public byte[] Summary; - public byte[] Details; - public byte[] VersionString; - - public override int Length - { - get - { - int length = 84; - if (AbuseRegionName != null) { length += AbuseRegionName.Length; } - if (Summary != null) { length += Summary.Length; } - if (Details != null) { length += Details.Length; } - if (VersionString != null) { length += VersionString.Length; } - return length; - } - } - - public ReportDataBlock() { } - public ReportDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - ReportType = (byte)bytes[i++]; - Category = (byte)bytes[i++]; - Position.FromBytes(bytes, i); i += 12; - CheckFlags = (byte)bytes[i++]; - ScreenshotID.FromBytes(bytes, i); i += 16; - ObjectID.FromBytes(bytes, i); i += 16; - AbuserID.FromBytes(bytes, i); i += 16; - length = bytes[i++]; - AbuseRegionName = new byte[length]; - Buffer.BlockCopy(bytes, i, AbuseRegionName, 0, length); i += length; - AbuseRegionID.FromBytes(bytes, i); i += 16; - length = bytes[i++]; - Summary = new byte[length]; - Buffer.BlockCopy(bytes, i, Summary, 0, length); i += length; - length = (bytes[i++] + (bytes[i++] << 8)); - Details = new byte[length]; - Buffer.BlockCopy(bytes, i, Details, 0, length); i += length; - length = bytes[i++]; - VersionString = new byte[length]; - Buffer.BlockCopy(bytes, i, VersionString, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - bytes[i++] = ReportType; - bytes[i++] = Category; - Position.ToBytes(bytes, i); i += 12; - bytes[i++] = CheckFlags; - ScreenshotID.ToBytes(bytes, i); i += 16; - ObjectID.ToBytes(bytes, i); i += 16; - AbuserID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)AbuseRegionName.Length; - Buffer.BlockCopy(AbuseRegionName, 0, bytes, i, AbuseRegionName.Length); i += AbuseRegionName.Length; - AbuseRegionID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)Summary.Length; - Buffer.BlockCopy(Summary, 0, bytes, i, Summary.Length); i += Summary.Length; - bytes[i++] = (byte)(Details.Length % 256); - bytes[i++] = (byte)((Details.Length >> 8) % 256); - Buffer.BlockCopy(Details, 0, bytes, i, Details.Length); i += Details.Length; - bytes[i++] = (byte)VersionString.Length; - Buffer.BlockCopy(VersionString, 0, bytes, i, VersionString.Length); i += VersionString.Length; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += ReportData.Length; - return length; - } - } - public AgentDataBlock AgentData; - public ReportDataBlock ReportData; - - public UserReportPacket() - { - HasVariableBlocks = false; - Type = PacketType.UserReport; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 133; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - ReportData = new ReportDataBlock(); - } - - public UserReportPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - ReportData.FromBytes(bytes, ref i); - } - - public UserReportPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - ReportData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += ReportData.Length; - if (Header.AckList != null && 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); - ReportData.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class AlertMessagePacket : Packet - { - /// - public sealed class AlertDataBlock : PacketBlock - { - public byte[] Message; - - public override int Length - { - get - { - int length = 1; - if (Message != null) { length += Message.Length; } - return length; - } - } - - public AlertDataBlock() { } - public AlertDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - length = bytes[i++]; - Message = new byte[length]; - Buffer.BlockCopy(bytes, i, Message, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - bytes[i++] = (byte)Message.Length; - Buffer.BlockCopy(Message, 0, bytes, i, Message.Length); i += Message.Length; - } - - } - - /// - public sealed class AlertInfoBlock : PacketBlock - { - public byte[] Message; - public byte[] ExtraParams; - - public override int Length - { - get - { - int length = 2; - if (Message != null) { length += Message.Length; } - if (ExtraParams != null) { length += ExtraParams.Length; } - return length; - } - } - - public AlertInfoBlock() { } - public AlertInfoBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - length = bytes[i++]; - Message = new byte[length]; - Buffer.BlockCopy(bytes, i, Message, 0, length); i += length; - length = bytes[i++]; - ExtraParams = new byte[length]; - Buffer.BlockCopy(bytes, i, ExtraParams, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - bytes[i++] = (byte)Message.Length; - Buffer.BlockCopy(Message, 0, bytes, i, Message.Length); i += Message.Length; - bytes[i++] = (byte)ExtraParams.Length; - Buffer.BlockCopy(ExtraParams, 0, bytes, i, ExtraParams.Length); i += ExtraParams.Length; - } - - } - - /// - public sealed class AgentInfoBlock : PacketBlock - { - public UUID AgentID; - - public override int Length - { - get - { - return 16; - } - } - - public AgentInfoBlock() { } - public AgentInfoBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 12; - length += AlertData.Length; - for (int j = 0; j < AlertInfo.Length; j++) - length += AlertInfo[j].Length; - for (int j = 0; j < AgentInfo.Length; j++) - length += AgentInfo[j].Length; - return length; - } - } - public AlertDataBlock AlertData; - public AlertInfoBlock[] AlertInfo; - public AgentInfoBlock[] AgentInfo; - - public AlertMessagePacket() - { - HasVariableBlocks = true; - Type = PacketType.AlertMessage; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 134; - Header.Reliable = true; - AlertData = new AlertDataBlock(); - AlertInfo = null; - AgentInfo = null; - } - - public AlertMessagePacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AlertData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(AlertInfo == null || AlertInfo.Length != -1) { - AlertInfo = new AlertInfoBlock[count]; - for(int j = 0; j < count; j++) - { AlertInfo[j] = new AlertInfoBlock(); } - } - for (int j = 0; j < count; j++) - { AlertInfo[j].FromBytes(bytes, ref i); } - count = (int)bytes[i++]; - if(AgentInfo == null || AgentInfo.Length != -1) { - AgentInfo = new AgentInfoBlock[count]; - for(int j = 0; j < count; j++) - { AgentInfo[j] = new AgentInfoBlock(); } - } - for (int j = 0; j < count; j++) - { AgentInfo[j].FromBytes(bytes, ref i); } - } - - public AlertMessagePacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AlertData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(AlertInfo == null || AlertInfo.Length != count) { - AlertInfo = new AlertInfoBlock[count]; - for(int j = 0; j < count; j++) - { AlertInfo[j] = new AlertInfoBlock(); } - } - for (int j = 0; j < count; j++) - { AlertInfo[j].FromBytes(bytes, ref i); } - count = (int)bytes[i++]; - if(AgentInfo == null || AgentInfo.Length != count) { - AgentInfo = new AgentInfoBlock[count]; - for(int j = 0; j < count; j++) - { AgentInfo[j] = new AgentInfoBlock(); } - } - for (int j = 0; j < count; j++) - { AgentInfo[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AlertData.Length; - length++; - for (int j = 0; j < AlertInfo.Length; j++) { length += AlertInfo[j].Length; } - length++; - for (int j = 0; j < AgentInfo.Length; j++) { length += AgentInfo[j].Length; } - if (Header.AckList != null && 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); - bytes[i++] = (byte)AlertInfo.Length; - for (int j = 0; j < AlertInfo.Length; j++) { AlertInfo[j].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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AlertData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AlertData.ToBytes(fixedBytes, ref i); - fixedLength += 2; - - int AlertInfoStart = 0; - int AgentInfoStart = 0; - do - { - int variableLength = 0; - int AlertInfoCount = 0; - int AgentInfoCount = 0; - - i = AlertInfoStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < AlertInfo.Length) { - int blockLength = AlertInfo[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == AlertInfoStart) { - variableLength += blockLength; - ++AlertInfoCount; - } - else { break; } - ++i; - } - - i = AgentInfoStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < AgentInfo.Length) { - int blockLength = AgentInfo[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == AgentInfoStart) { - variableLength += blockLength; - ++AgentInfoCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)AlertInfoCount; - for (i = AlertInfoStart; i < AlertInfoStart + AlertInfoCount; i++) { AlertInfo[i].ToBytes(packet, ref length); } - AlertInfoStart += AlertInfoCount; - - packet[length++] = (byte)AgentInfoCount; - for (i = AgentInfoStart; i < AgentInfoStart + AgentInfoCount; i++) { AgentInfo[i].ToBytes(packet, ref length); } - AgentInfoStart += AgentInfoCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - AlertInfoStart < AlertInfo.Length || - AgentInfoStart < AgentInfo.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class AgentAlertMessagePacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - - public override int Length - { - get - { - return 16; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class AlertDataBlock : PacketBlock - { - public bool Modal; - public byte[] Message; - - public override int Length - { - get - { - int length = 2; - if (Message != null) { length += Message.Length; } - return length; - } - } - - public AlertDataBlock() { } - public AlertDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - Modal = (bytes[i++] != 0) ? (bool)true : (bool)false; - length = bytes[i++]; - Message = new byte[length]; - Buffer.BlockCopy(bytes, i, Message, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - bytes[i++] = (byte)((Modal) ? 1 : 0); - bytes[i++] = (byte)Message.Length; - Buffer.BlockCopy(Message, 0, bytes, i, Message.Length); i += Message.Length; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += AlertData.Length; - return length; - } - } - public AgentDataBlock AgentData; - public AlertDataBlock AlertData; - - public AgentAlertMessagePacket() - { - HasVariableBlocks = false; - Type = PacketType.AgentAlertMessage; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 135; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - AlertData = new AlertDataBlock(); - } - - public AgentAlertMessagePacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - AlertData.FromBytes(bytes, ref i); - } - - public AgentAlertMessagePacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - AlertData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += AlertData.Length; - if (Header.AckList != null && 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); - AlertData.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class MeanCollisionAlertPacket : Packet - { - /// - public sealed class MeanCollisionBlock : PacketBlock - { - public UUID Victim; - public UUID Perp; - public uint Time; - public float Mag; - public byte Type; - - public override int Length - { - get - { - return 41; - } - } - - public MeanCollisionBlock() { } - public MeanCollisionBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - Victim.FromBytes(bytes, i); i += 16; - Perp.FromBytes(bytes, i); i += 16; - Time = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - Mag = Utils.BytesToFloat(bytes, i); i += 4; - Type = (byte)bytes[i++]; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Victim.ToBytes(bytes, i); i += 16; - Perp.ToBytes(bytes, i); i += 16; - Utils.UIntToBytes(Time, bytes, i); i += 4; - Utils.FloatToBytes(Mag, bytes, i); i += 4; - bytes[i++] = Type; - } - - } - - public override int Length - { - get - { - int length = 11; - for (int j = 0; j < MeanCollision.Length; j++) - length += MeanCollision[j].Length; - return length; - } - } - public MeanCollisionBlock[] MeanCollision; - - public MeanCollisionAlertPacket() - { - HasVariableBlocks = true; - Type = PacketType.MeanCollisionAlert; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 136; - Header.Reliable = true; - Header.Zerocoded = true; - MeanCollision = null; - } - - public MeanCollisionAlertPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - int count = (int)bytes[i++]; - if(MeanCollision == null || MeanCollision.Length != -1) { - MeanCollision = new MeanCollisionBlock[count]; - for(int j = 0; j < count; j++) - { MeanCollision[j] = new MeanCollisionBlock(); } - } - for (int j = 0; j < count; j++) - { MeanCollision[j].FromBytes(bytes, ref i); } - } - - public MeanCollisionAlertPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - int count = (int)bytes[i++]; - if(MeanCollision == null || MeanCollision.Length != count) { - MeanCollision = new MeanCollisionBlock[count]; - for(int j = 0; j < count; j++) - { MeanCollision[j] = new MeanCollisionBlock(); } - } - for (int j = 0; j < count; j++) - { MeanCollision[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length++; - for (int j = 0; j < MeanCollision.Length; j++) { length += MeanCollision[j].Length; } - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int MeanCollisionStart = 0; - do - { - int variableLength = 0; - int MeanCollisionCount = 0; - - i = MeanCollisionStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < MeanCollision.Length) { - int blockLength = MeanCollision[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == MeanCollisionStart) { - variableLength += blockLength; - ++MeanCollisionCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)MeanCollisionCount; - for (i = MeanCollisionStart; i < MeanCollisionStart + MeanCollisionCount; i++) { MeanCollision[i].ToBytes(packet, ref length); } - MeanCollisionStart += MeanCollisionCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - MeanCollisionStart < MeanCollision.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class ViewerFrozenMessagePacket : Packet - { - /// - public sealed class FrozenDataBlock : PacketBlock - { - public bool Data; - - public override int Length - { - get - { - return 1; - } - } - - public FrozenDataBlock() { } - public FrozenDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - Data = (bytes[i++] != 0) ? (bool)true : (bool)false; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - bytes[i++] = (byte)((Data) ? 1 : 0); - } - - } - - public override int Length - { - get - { - int length = 10; - length += FrozenData.Length; - return length; - } - } - public FrozenDataBlock FrozenData; - - public ViewerFrozenMessagePacket() - { - HasVariableBlocks = false; - Type = PacketType.ViewerFrozenMessage; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 137; - Header.Reliable = true; - FrozenData = new FrozenDataBlock(); - } - - public ViewerFrozenMessagePacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - FrozenData.FromBytes(bytes, ref i); - } - - public ViewerFrozenMessagePacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - FrozenData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += FrozenData.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class HealthMessagePacket : Packet - { - /// - public sealed class HealthDataBlock : PacketBlock - { - public float Health; - - public override int Length - { - get - { - return 4; - } - } - - public HealthDataBlock() { } - public HealthDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - Health = Utils.BytesToFloat(bytes, i); i += 4; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.FloatToBytes(Health, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 10; - length += HealthData.Length; - return length; - } - } - public HealthDataBlock HealthData; - - public HealthMessagePacket() - { - HasVariableBlocks = false; - Type = PacketType.HealthMessage; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 138; - Header.Reliable = true; - Header.Zerocoded = true; - HealthData = new HealthDataBlock(); - } - - public HealthMessagePacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - HealthData.FromBytes(bytes, ref i); - } - - public HealthMessagePacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - HealthData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += HealthData.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class ChatFromSimulatorPacket : Packet - { - /// - public sealed class ChatDataBlock : PacketBlock - { - public byte[] FromName; - public UUID SourceID; - public UUID OwnerID; - public byte SourceType; - public byte ChatType; - public byte Audible; - public Vector3 Position; - public byte[] Message; - - public override int Length - { - get - { - int length = 50; - if (FromName != null) { length += FromName.Length; } - if (Message != null) { length += Message.Length; } - return length; - } - } - - public ChatDataBlock() { } - public ChatDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - length = bytes[i++]; - FromName = new byte[length]; - Buffer.BlockCopy(bytes, i, FromName, 0, length); i += length; - SourceID.FromBytes(bytes, i); i += 16; - OwnerID.FromBytes(bytes, i); i += 16; - SourceType = (byte)bytes[i++]; - ChatType = (byte)bytes[i++]; - Audible = (byte)bytes[i++]; - Position.FromBytes(bytes, i); i += 12; - length = (bytes[i++] + (bytes[i++] << 8)); - Message = new byte[length]; - Buffer.BlockCopy(bytes, i, Message, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - bytes[i++] = (byte)FromName.Length; - Buffer.BlockCopy(FromName, 0, bytes, i, FromName.Length); i += FromName.Length; - SourceID.ToBytes(bytes, i); i += 16; - OwnerID.ToBytes(bytes, i); i += 16; - bytes[i++] = SourceType; - bytes[i++] = ChatType; - bytes[i++] = Audible; - Position.ToBytes(bytes, i); i += 12; - bytes[i++] = (byte)(Message.Length % 256); - bytes[i++] = (byte)((Message.Length >> 8) % 256); - Buffer.BlockCopy(Message, 0, bytes, i, Message.Length); i += Message.Length; - } - - } - - public override int Length - { - get - { - int length = 10; - length += ChatData.Length; - return length; - } - } - public ChatDataBlock ChatData; - - public ChatFromSimulatorPacket() - { - HasVariableBlocks = false; - Type = PacketType.ChatFromSimulator; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 139; - Header.Reliable = true; - ChatData = new ChatDataBlock(); - } - - public ChatFromSimulatorPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - ChatData.FromBytes(bytes, ref i); - } - - public ChatFromSimulatorPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - ChatData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += ChatData.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class SimStatsPacket : Packet - { - /// - public sealed class RegionBlock : PacketBlock - { - public uint RegionX; - public uint RegionY; - public uint RegionFlags; - public uint ObjectCapacity; - - public override int Length - { - get - { - return 16; - } - } - - public RegionBlock() { } - public RegionBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(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(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UIntToBytes(RegionX, bytes, i); i += 4; - Utils.UIntToBytes(RegionY, bytes, i); i += 4; - Utils.UIntToBytes(RegionFlags, bytes, i); i += 4; - Utils.UIntToBytes(ObjectCapacity, bytes, i); i += 4; - } - - } - - /// - public sealed class StatBlock : PacketBlock - { - public uint StatID; - public float StatValue; - - public override int Length - { - get - { - return 8; - } - } - - public StatBlock() { } - public StatBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - StatID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - StatValue = Utils.BytesToFloat(bytes, i); i += 4; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UIntToBytes(StatID, bytes, i); i += 4; - Utils.FloatToBytes(StatValue, bytes, i); i += 4; - } - - } - - /// - public sealed class PidStatBlock : PacketBlock - { - public int PID; - - public override int Length - { - get - { - return 4; - } - } - - public PidStatBlock() { } - public PidStatBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - PID = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.IntToBytes(PID, bytes, i); i += 4; - } - - } - - /// - public sealed class RegionInfoBlock : PacketBlock - { - public ulong RegionFlagsExtended; - - public override int Length - { - get - { - return 8; - } - } - - public RegionInfoBlock() { } - public RegionInfoBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - RegionFlagsExtended = (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(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UInt64ToBytes(RegionFlagsExtended, bytes, i); i += 8; - } - - } - - public override int Length - { - get - { - int length = 12; - length += Region.Length; - for (int j = 0; j < Stat.Length; j++) - length += Stat[j].Length; - length += PidStat.Length; - for (int j = 0; j < RegionInfo.Length; j++) - length += RegionInfo[j].Length; - return length; - } - } - public RegionBlock Region; - public StatBlock[] Stat; - public PidStatBlock PidStat; - public RegionInfoBlock[] RegionInfo; - - public SimStatsPacket() - { - HasVariableBlocks = true; - Type = PacketType.SimStats; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 140; - Header.Reliable = true; - Region = new RegionBlock(); - Stat = null; - PidStat = new PidStatBlock(); - RegionInfo = null; - } - - public SimStatsPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - Region.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(Stat == null || Stat.Length != -1) { - Stat = new StatBlock[count]; - for(int j = 0; j < count; j++) - { Stat[j] = new StatBlock(); } - } - for (int j = 0; j < count; j++) - { Stat[j].FromBytes(bytes, ref i); } - PidStat.FromBytes(bytes, ref i); - count = (int)bytes[i++]; - if(RegionInfo == null || RegionInfo.Length != -1) { - RegionInfo = new RegionInfoBlock[count]; - for(int j = 0; j < count; j++) - { RegionInfo[j] = new RegionInfoBlock(); } - } - for (int j = 0; j < count; j++) - { RegionInfo[j].FromBytes(bytes, ref i); } - } - - public SimStatsPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - Region.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(Stat == null || Stat.Length != count) { - Stat = new StatBlock[count]; - for(int j = 0; j < count; j++) - { Stat[j] = new StatBlock(); } - } - for (int j = 0; j < count; j++) - { Stat[j].FromBytes(bytes, ref i); } - PidStat.FromBytes(bytes, ref i); - count = (int)bytes[i++]; - if(RegionInfo == null || RegionInfo.Length != count) { - RegionInfo = new RegionInfoBlock[count]; - for(int j = 0; j < count; j++) - { RegionInfo[j] = new RegionInfoBlock(); } - } - for (int j = 0; j < count; j++) - { RegionInfo[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += Region.Length; - length += PidStat.Length; - length++; - for (int j = 0; j < Stat.Length; j++) { length += Stat[j].Length; } - length++; - for (int j = 0; j < RegionInfo.Length; j++) { length += RegionInfo[j].Length; } - if (Header.AckList != null && Header.AckList.Length > 0) { length += Header.AckList.Length * 4 + 1; } - byte[] bytes = new byte[length]; - int i = 0; - Header.ToBytes(bytes, ref i); - Region.ToBytes(bytes, ref i); - bytes[i++] = (byte)Stat.Length; - for (int j = 0; j < Stat.Length; j++) { Stat[j].ToBytes(bytes, ref i); } - PidStat.ToBytes(bytes, ref i); - bytes[i++] = (byte)RegionInfo.Length; - for (int j = 0; j < RegionInfo.Length; j++) { RegionInfo[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class RequestRegionInfoPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - return length; - } - } - public AgentDataBlock AgentData; - - public RequestRegionInfoPacket() - { - HasVariableBlocks = false; - Type = PacketType.RequestRegionInfo; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 141; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - } - - public RequestRegionInfoPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - } - - public RequestRegionInfoPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class RegionInfoPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class RegionInfoBlock : PacketBlock - { - public byte[] SimName; - public uint EstateID; - public uint ParentEstateID; - public uint RegionFlags; - public byte SimAccess; - public byte MaxAgents; - public float BillableFactor; - public float ObjectBonusFactor; - public float WaterHeight; - public float TerrainRaiseLimit; - public float TerrainLowerLimit; - public int PricePerMeter; - public int RedirectGridX; - public int RedirectGridY; - public bool UseEstateSun; - public float SunHour; - - public override int Length - { - get - { - int length = 52; - if (SimName != null) { length += SimName.Length; } - return length; - } - } - - public RegionInfoBlock() { } - public RegionInfoBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - length = bytes[i++]; - SimName = new byte[length]; - Buffer.BlockCopy(bytes, i, SimName, 0, length); i += length; - EstateID = (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)); - RegionFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - SimAccess = (byte)bytes[i++]; - MaxAgents = (byte)bytes[i++]; - BillableFactor = Utils.BytesToFloat(bytes, i); i += 4; - ObjectBonusFactor = Utils.BytesToFloat(bytes, i); i += 4; - WaterHeight = Utils.BytesToFloat(bytes, i); i += 4; - TerrainRaiseLimit = Utils.BytesToFloat(bytes, i); i += 4; - TerrainLowerLimit = Utils.BytesToFloat(bytes, i); i += 4; - PricePerMeter = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - 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)); - UseEstateSun = (bytes[i++] != 0) ? (bool)true : (bool)false; - SunHour = Utils.BytesToFloat(bytes, i); i += 4; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - bytes[i++] = (byte)SimName.Length; - Buffer.BlockCopy(SimName, 0, bytes, i, SimName.Length); i += SimName.Length; - Utils.UIntToBytes(EstateID, bytes, i); i += 4; - Utils.UIntToBytes(ParentEstateID, bytes, i); i += 4; - Utils.UIntToBytes(RegionFlags, bytes, i); i += 4; - bytes[i++] = SimAccess; - bytes[i++] = MaxAgents; - Utils.FloatToBytes(BillableFactor, bytes, i); i += 4; - Utils.FloatToBytes(ObjectBonusFactor, bytes, i); i += 4; - Utils.FloatToBytes(WaterHeight, bytes, i); i += 4; - Utils.FloatToBytes(TerrainRaiseLimit, bytes, i); i += 4; - Utils.FloatToBytes(TerrainLowerLimit, bytes, i); i += 4; - Utils.IntToBytes(PricePerMeter, bytes, i); i += 4; - Utils.IntToBytes(RedirectGridX, bytes, i); i += 4; - Utils.IntToBytes(RedirectGridY, bytes, i); i += 4; - bytes[i++] = (byte)((UseEstateSun) ? 1 : 0); - Utils.FloatToBytes(SunHour, bytes, i); i += 4; - } - - } - - /// - public sealed class RegionInfo2Block : PacketBlock - { - public byte[] ProductSKU; - public byte[] ProductName; - public uint MaxAgents32; - public uint HardMaxAgents; - public uint HardMaxObjects; - - public override int Length - { - get - { - int length = 14; - if (ProductSKU != null) { length += ProductSKU.Length; } - if (ProductName != null) { length += ProductName.Length; } - return length; - } - } - - public RegionInfo2Block() { } - public RegionInfo2Block(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - length = bytes[i++]; - ProductSKU = new byte[length]; - Buffer.BlockCopy(bytes, i, ProductSKU, 0, length); i += length; - length = bytes[i++]; - ProductName = new byte[length]; - Buffer.BlockCopy(bytes, i, ProductName, 0, length); i += length; - MaxAgents32 = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - HardMaxAgents = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - HardMaxObjects = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - bytes[i++] = (byte)ProductSKU.Length; - Buffer.BlockCopy(ProductSKU, 0, bytes, i, ProductSKU.Length); i += ProductSKU.Length; - bytes[i++] = (byte)ProductName.Length; - Buffer.BlockCopy(ProductName, 0, bytes, i, ProductName.Length); i += ProductName.Length; - Utils.UIntToBytes(MaxAgents32, bytes, i); i += 4; - Utils.UIntToBytes(HardMaxAgents, bytes, i); i += 4; - Utils.UIntToBytes(HardMaxObjects, bytes, i); i += 4; - } - - } - - /// - public sealed class RegionInfo3Block : PacketBlock - { - public ulong RegionFlagsExtended; - - public override int Length - { - get - { - return 8; - } - } - - public RegionInfo3Block() { } - public RegionInfo3Block(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - RegionFlagsExtended = (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(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UInt64ToBytes(RegionFlagsExtended, bytes, i); i += 8; - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentData.Length; - length += RegionInfo.Length; - length += RegionInfo2.Length; - for (int j = 0; j < RegionInfo3.Length; j++) - length += RegionInfo3[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public RegionInfoBlock RegionInfo; - public RegionInfo2Block RegionInfo2; - public RegionInfo3Block[] RegionInfo3; - - public RegionInfoPacket() - { - HasVariableBlocks = true; - Type = PacketType.RegionInfo; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 142; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - RegionInfo = new RegionInfoBlock(); - RegionInfo2 = new RegionInfo2Block(); - RegionInfo3 = null; - } - - public RegionInfoPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - RegionInfo.FromBytes(bytes, ref i); - RegionInfo2.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(RegionInfo3 == null || RegionInfo3.Length != -1) { - RegionInfo3 = new RegionInfo3Block[count]; - for(int j = 0; j < count; j++) - { RegionInfo3[j] = new RegionInfo3Block(); } - } - for (int j = 0; j < count; j++) - { RegionInfo3[j].FromBytes(bytes, ref i); } - } - - public RegionInfoPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - RegionInfo.FromBytes(bytes, ref i); - RegionInfo2.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(RegionInfo3 == null || RegionInfo3.Length != count) { - RegionInfo3 = new RegionInfo3Block[count]; - for(int j = 0; j < count; j++) - { RegionInfo3[j] = new RegionInfo3Block(); } - } - for (int j = 0; j < count; j++) - { RegionInfo3[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += RegionInfo.Length; - length += RegionInfo2.Length; - length++; - for (int j = 0; j < RegionInfo3.Length; j++) { length += RegionInfo3[j].Length; } - if (Header.AckList != null && 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); - RegionInfo.ToBytes(bytes, ref i); - RegionInfo2.ToBytes(bytes, ref i); - bytes[i++] = (byte)RegionInfo3.Length; - for (int j = 0; j < RegionInfo3.Length; j++) { RegionInfo3[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - fixedLength += RegionInfo.Length; - fixedLength += RegionInfo2.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - RegionInfo.ToBytes(fixedBytes, ref i); - RegionInfo2.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int RegionInfo3Start = 0; - do - { - int variableLength = 0; - int RegionInfo3Count = 0; - - i = RegionInfo3Start; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < RegionInfo3.Length) { - int blockLength = RegionInfo3[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == RegionInfo3Start) { - variableLength += blockLength; - ++RegionInfo3Count; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)RegionInfo3Count; - for (i = RegionInfo3Start; i < RegionInfo3Start + RegionInfo3Count; i++) { RegionInfo3[i].ToBytes(packet, ref length); } - RegionInfo3Start += RegionInfo3Count; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - RegionInfo3Start < RegionInfo3.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class GodUpdateRegionInfoPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class RegionInfoBlock : PacketBlock - { - public byte[] SimName; - public uint EstateID; - public uint ParentEstateID; - public uint RegionFlags; - public float BillableFactor; - public int PricePerMeter; - public int RedirectGridX; - public int RedirectGridY; - - public override int Length - { - get - { - int length = 29; - if (SimName != null) { length += SimName.Length; } - return length; - } - } - - public RegionInfoBlock() { } - public RegionInfoBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - length = bytes[i++]; - SimName = new byte[length]; - Buffer.BlockCopy(bytes, i, SimName, 0, length); i += length; - EstateID = (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)); - RegionFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - BillableFactor = Utils.BytesToFloat(bytes, i); i += 4; - PricePerMeter = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - 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)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - bytes[i++] = (byte)SimName.Length; - Buffer.BlockCopy(SimName, 0, bytes, i, SimName.Length); i += SimName.Length; - Utils.UIntToBytes(EstateID, bytes, i); i += 4; - Utils.UIntToBytes(ParentEstateID, bytes, i); i += 4; - Utils.UIntToBytes(RegionFlags, bytes, i); i += 4; - Utils.FloatToBytes(BillableFactor, bytes, i); i += 4; - Utils.IntToBytes(PricePerMeter, bytes, i); i += 4; - Utils.IntToBytes(RedirectGridX, bytes, i); i += 4; - Utils.IntToBytes(RedirectGridY, bytes, i); i += 4; - } - - } - - /// - public sealed class RegionInfo2Block : PacketBlock - { - public ulong RegionFlagsExtended; - - public override int Length - { - get - { - return 8; - } - } - - public RegionInfo2Block() { } - public RegionInfo2Block(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - RegionFlagsExtended = (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(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UInt64ToBytes(RegionFlagsExtended, bytes, i); i += 8; - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentData.Length; - length += RegionInfo.Length; - for (int j = 0; j < RegionInfo2.Length; j++) - length += RegionInfo2[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public RegionInfoBlock RegionInfo; - public RegionInfo2Block[] RegionInfo2; - - public GodUpdateRegionInfoPacket() - { - HasVariableBlocks = true; - Type = PacketType.GodUpdateRegionInfo; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 143; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - RegionInfo = new RegionInfoBlock(); - RegionInfo2 = null; - } - - public GodUpdateRegionInfoPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - RegionInfo.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(RegionInfo2 == null || RegionInfo2.Length != -1) { - RegionInfo2 = new RegionInfo2Block[count]; - for(int j = 0; j < count; j++) - { RegionInfo2[j] = new RegionInfo2Block(); } - } - for (int j = 0; j < count; j++) - { RegionInfo2[j].FromBytes(bytes, ref i); } - } - - public GodUpdateRegionInfoPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - RegionInfo.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(RegionInfo2 == null || RegionInfo2.Length != count) { - RegionInfo2 = new RegionInfo2Block[count]; - for(int j = 0; j < count; j++) - { RegionInfo2[j] = new RegionInfo2Block(); } - } - for (int j = 0; j < count; j++) - { RegionInfo2[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += RegionInfo.Length; - length++; - for (int j = 0; j < RegionInfo2.Length; j++) { length += RegionInfo2[j].Length; } - if (Header.AckList != null && 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); - RegionInfo.ToBytes(bytes, ref i); - bytes[i++] = (byte)RegionInfo2.Length; - for (int j = 0; j < RegionInfo2.Length; j++) { RegionInfo2[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - fixedLength += RegionInfo.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - RegionInfo.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int RegionInfo2Start = 0; - do - { - int variableLength = 0; - int RegionInfo2Count = 0; - - i = RegionInfo2Start; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < RegionInfo2.Length) { - int blockLength = RegionInfo2[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == RegionInfo2Start) { - variableLength += blockLength; - ++RegionInfo2Count; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)RegionInfo2Count; - for (i = RegionInfo2Start; i < RegionInfo2Start + RegionInfo2Count; i++) { RegionInfo2[i].ToBytes(packet, ref length); } - RegionInfo2Start += RegionInfo2Count; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - RegionInfo2Start < RegionInfo2.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class RegionHandshakePacket : Packet - { - /// - public sealed class RegionInfoBlock : PacketBlock - { - public uint RegionFlags; - public byte SimAccess; - public byte[] SimName; - public UUID SimOwner; - public bool IsEstateManager; - public float WaterHeight; - public float BillableFactor; - public UUID CacheID; - public UUID TerrainBase0; - public UUID TerrainBase1; - public UUID TerrainBase2; - public UUID TerrainBase3; - public UUID TerrainDetail0; - public UUID TerrainDetail1; - public UUID TerrainDetail2; - public UUID TerrainDetail3; - public float TerrainStartHeight00; - public float TerrainStartHeight01; - public float TerrainStartHeight10; - public float TerrainStartHeight11; - public float TerrainHeightRange00; - public float TerrainHeightRange01; - public float TerrainHeightRange10; - public float TerrainHeightRange11; - - public override int Length - { - get - { - int length = 207; - if (SimName != null) { length += SimName.Length; } - return length; - } - } - - public RegionInfoBlock() { } - public RegionInfoBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - RegionFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - SimAccess = (byte)bytes[i++]; - length = bytes[i++]; - SimName = new byte[length]; - Buffer.BlockCopy(bytes, i, SimName, 0, length); i += length; - SimOwner.FromBytes(bytes, i); i += 16; - IsEstateManager = (bytes[i++] != 0) ? (bool)true : (bool)false; - WaterHeight = Utils.BytesToFloat(bytes, i); i += 4; - BillableFactor = Utils.BytesToFloat(bytes, i); i += 4; - CacheID.FromBytes(bytes, i); i += 16; - TerrainBase0.FromBytes(bytes, i); i += 16; - TerrainBase1.FromBytes(bytes, i); i += 16; - TerrainBase2.FromBytes(bytes, i); i += 16; - TerrainBase3.FromBytes(bytes, i); i += 16; - TerrainDetail0.FromBytes(bytes, i); i += 16; - TerrainDetail1.FromBytes(bytes, i); i += 16; - TerrainDetail2.FromBytes(bytes, i); i += 16; - TerrainDetail3.FromBytes(bytes, i); i += 16; - TerrainStartHeight00 = Utils.BytesToFloat(bytes, i); i += 4; - TerrainStartHeight01 = Utils.BytesToFloat(bytes, i); i += 4; - TerrainStartHeight10 = Utils.BytesToFloat(bytes, i); i += 4; - TerrainStartHeight11 = Utils.BytesToFloat(bytes, i); i += 4; - TerrainHeightRange00 = Utils.BytesToFloat(bytes, i); i += 4; - TerrainHeightRange01 = Utils.BytesToFloat(bytes, i); i += 4; - TerrainHeightRange10 = Utils.BytesToFloat(bytes, i); i += 4; - TerrainHeightRange11 = Utils.BytesToFloat(bytes, i); i += 4; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UIntToBytes(RegionFlags, bytes, i); i += 4; - bytes[i++] = SimAccess; - bytes[i++] = (byte)SimName.Length; - Buffer.BlockCopy(SimName, 0, bytes, i, SimName.Length); i += SimName.Length; - SimOwner.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)((IsEstateManager) ? 1 : 0); - Utils.FloatToBytes(WaterHeight, bytes, i); i += 4; - Utils.FloatToBytes(BillableFactor, bytes, i); i += 4; - CacheID.ToBytes(bytes, i); i += 16; - TerrainBase0.ToBytes(bytes, i); i += 16; - TerrainBase1.ToBytes(bytes, i); i += 16; - TerrainBase2.ToBytes(bytes, i); i += 16; - TerrainBase3.ToBytes(bytes, i); i += 16; - TerrainDetail0.ToBytes(bytes, i); i += 16; - TerrainDetail1.ToBytes(bytes, i); i += 16; - TerrainDetail2.ToBytes(bytes, i); i += 16; - TerrainDetail3.ToBytes(bytes, i); i += 16; - Utils.FloatToBytes(TerrainStartHeight00, bytes, i); i += 4; - Utils.FloatToBytes(TerrainStartHeight01, bytes, i); i += 4; - Utils.FloatToBytes(TerrainStartHeight10, bytes, i); i += 4; - Utils.FloatToBytes(TerrainStartHeight11, bytes, i); i += 4; - Utils.FloatToBytes(TerrainHeightRange00, bytes, i); i += 4; - Utils.FloatToBytes(TerrainHeightRange01, bytes, i); i += 4; - Utils.FloatToBytes(TerrainHeightRange10, bytes, i); i += 4; - Utils.FloatToBytes(TerrainHeightRange11, bytes, i); i += 4; - } - - } - - /// - public sealed class RegionInfo2Block : PacketBlock - { - public UUID RegionID; - - public override int Length - { - get - { - return 16; - } - } - - public RegionInfo2Block() { } - public RegionInfo2Block(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - RegionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - RegionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class RegionInfo3Block : PacketBlock - { - public int CPUClassID; - public int CPURatio; - public byte[] ColoName; - public byte[] ProductSKU; - public byte[] ProductName; - - public override int Length - { - get - { - int length = 11; - if (ColoName != null) { length += ColoName.Length; } - if (ProductSKU != null) { length += ProductSKU.Length; } - if (ProductName != null) { length += ProductName.Length; } - return length; - } - } - - public RegionInfo3Block() { } - public RegionInfo3Block(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - CPUClassID = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - CPURatio = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - length = bytes[i++]; - ColoName = new byte[length]; - Buffer.BlockCopy(bytes, i, ColoName, 0, length); i += length; - length = bytes[i++]; - ProductSKU = new byte[length]; - Buffer.BlockCopy(bytes, i, ProductSKU, 0, length); i += length; - length = bytes[i++]; - ProductName = new byte[length]; - Buffer.BlockCopy(bytes, i, ProductName, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.IntToBytes(CPUClassID, bytes, i); i += 4; - Utils.IntToBytes(CPURatio, bytes, i); i += 4; - bytes[i++] = (byte)ColoName.Length; - Buffer.BlockCopy(ColoName, 0, bytes, i, ColoName.Length); i += ColoName.Length; - bytes[i++] = (byte)ProductSKU.Length; - Buffer.BlockCopy(ProductSKU, 0, bytes, i, ProductSKU.Length); i += ProductSKU.Length; - bytes[i++] = (byte)ProductName.Length; - Buffer.BlockCopy(ProductName, 0, bytes, i, ProductName.Length); i += ProductName.Length; - } - - } - - /// - public sealed class RegionInfo4Block : PacketBlock - { - public ulong RegionFlagsExtended; - public ulong RegionProtocols; - - public override int Length - { - get - { - return 16; - } - } - - public RegionInfo4Block() { } - public RegionInfo4Block(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - RegionFlagsExtended = (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)); - RegionProtocols = (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(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UInt64ToBytes(RegionFlagsExtended, bytes, i); i += 8; - Utils.UInt64ToBytes(RegionProtocols, bytes, i); i += 8; - } - - } - - public override int Length - { - get - { - int length = 11; - length += RegionInfo.Length; - length += RegionInfo2.Length; - length += RegionInfo3.Length; - for (int j = 0; j < RegionInfo4.Length; j++) - length += RegionInfo4[j].Length; - return length; - } - } - public RegionInfoBlock RegionInfo; - public RegionInfo2Block RegionInfo2; - public RegionInfo3Block RegionInfo3; - public RegionInfo4Block[] RegionInfo4; - - public RegionHandshakePacket() - { - HasVariableBlocks = true; - Type = PacketType.RegionHandshake; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 148; - Header.Reliable = true; - Header.Zerocoded = true; - RegionInfo = new RegionInfoBlock(); - RegionInfo2 = new RegionInfo2Block(); - RegionInfo3 = new RegionInfo3Block(); - RegionInfo4 = null; - } - - public RegionHandshakePacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - RegionInfo.FromBytes(bytes, ref i); - RegionInfo2.FromBytes(bytes, ref i); - RegionInfo3.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(RegionInfo4 == null || RegionInfo4.Length != -1) { - RegionInfo4 = new RegionInfo4Block[count]; - for(int j = 0; j < count; j++) - { RegionInfo4[j] = new RegionInfo4Block(); } - } - for (int j = 0; j < count; j++) - { RegionInfo4[j].FromBytes(bytes, ref i); } - } - - public RegionHandshakePacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - RegionInfo.FromBytes(bytes, ref i); - RegionInfo2.FromBytes(bytes, ref i); - RegionInfo3.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(RegionInfo4 == null || RegionInfo4.Length != count) { - RegionInfo4 = new RegionInfo4Block[count]; - for(int j = 0; j < count; j++) - { RegionInfo4[j] = new RegionInfo4Block(); } - } - for (int j = 0; j < count; j++) - { RegionInfo4[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += RegionInfo.Length; - length += RegionInfo2.Length; - length += RegionInfo3.Length; - length++; - for (int j = 0; j < RegionInfo4.Length; j++) { length += RegionInfo4[j].Length; } - if (Header.AckList != null && 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); - RegionInfo2.ToBytes(bytes, ref i); - RegionInfo3.ToBytes(bytes, ref i); - bytes[i++] = (byte)RegionInfo4.Length; - for (int j = 0; j < RegionInfo4.Length; j++) { RegionInfo4[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += RegionInfo.Length; - fixedLength += RegionInfo2.Length; - fixedLength += RegionInfo3.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - RegionInfo.ToBytes(fixedBytes, ref i); - RegionInfo2.ToBytes(fixedBytes, ref i); - RegionInfo3.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int RegionInfo4Start = 0; - do - { - int variableLength = 0; - int RegionInfo4Count = 0; - - i = RegionInfo4Start; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < RegionInfo4.Length) { - int blockLength = RegionInfo4[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == RegionInfo4Start) { - variableLength += blockLength; - ++RegionInfo4Count; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)RegionInfo4Count; - for (i = RegionInfo4Start; i < RegionInfo4Start + RegionInfo4Count; i++) { RegionInfo4[i].ToBytes(packet, ref length); } - RegionInfo4Start += RegionInfo4Count; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - RegionInfo4Start < RegionInfo4.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class RegionHandshakeReplyPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class RegionInfoBlock : PacketBlock - { - public uint Flags; - - public override int Length - { - get - { - return 4; - } - } - - public RegionInfoBlock() { } - public RegionInfoBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - Flags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UIntToBytes(Flags, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += RegionInfo.Length; - return length; - } - } - public AgentDataBlock AgentData; - public RegionInfoBlock RegionInfo; - - public RegionHandshakeReplyPacket() - { - HasVariableBlocks = false; - Type = PacketType.RegionHandshakeReply; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 149; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - RegionInfo = new RegionInfoBlock(); - } - - public RegionHandshakeReplyPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - RegionInfo.FromBytes(bytes, ref i); - } - - public RegionHandshakeReplyPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - RegionInfo.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += RegionInfo.Length; - if (Header.AckList != null && 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); - RegionInfo.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class SimulatorViewerTimeMessagePacket : Packet - { - /// - public sealed class TimeInfoBlock : PacketBlock - { - public ulong UsecSinceStart; - public uint SecPerDay; - public uint SecPerYear; - public Vector3 SunDirection; - public float SunPhase; - public Vector3 SunAngVelocity; - - public override int Length - { - get - { - return 44; - } - } - - public TimeInfoBlock() { } - public TimeInfoBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - 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)); - SecPerDay = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - SecPerYear = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - SunDirection.FromBytes(bytes, i); i += 12; - SunPhase = Utils.BytesToFloat(bytes, i); i += 4; - SunAngVelocity.FromBytes(bytes, i); i += 12; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UInt64ToBytes(UsecSinceStart, bytes, i); i += 8; - Utils.UIntToBytes(SecPerDay, bytes, i); i += 4; - Utils.UIntToBytes(SecPerYear, bytes, i); i += 4; - SunDirection.ToBytes(bytes, i); i += 12; - Utils.FloatToBytes(SunPhase, bytes, i); i += 4; - SunAngVelocity.ToBytes(bytes, i); i += 12; - } - - } - - public override int Length - { - get - { - int length = 10; - length += TimeInfo.Length; - return length; - } - } - public TimeInfoBlock TimeInfo; - - public SimulatorViewerTimeMessagePacket() - { - HasVariableBlocks = false; - Type = PacketType.SimulatorViewerTimeMessage; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 150; - Header.Reliable = true; - TimeInfo = new TimeInfoBlock(); - } - - public SimulatorViewerTimeMessagePacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - TimeInfo.FromBytes(bytes, ref i); - } - - public SimulatorViewerTimeMessagePacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - TimeInfo.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += TimeInfo.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class EnableSimulatorPacket : Packet - { - /// - public sealed class SimulatorInfoBlock : PacketBlock - { - public ulong Handle; - public uint IP; - public ushort Port; - - public override int Length - { - get - { - return 14; - } - } - - public SimulatorInfoBlock() { } - public SimulatorInfoBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - 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)); - 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(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UInt64ToBytes(Handle, bytes, i); i += 8; - Utils.UIntToBytes(IP, bytes, i); i += 4; - bytes[i++] = (byte)((Port >> 8) % 256); - bytes[i++] = (byte)(Port % 256); - } - - } - - public override int Length - { - get - { - int length = 10; - length += SimulatorInfo.Length; - return length; - } - } - public SimulatorInfoBlock SimulatorInfo; - - public EnableSimulatorPacket() - { - HasVariableBlocks = false; - Type = PacketType.EnableSimulator; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 151; - Header.Reliable = true; - SimulatorInfo = new SimulatorInfoBlock(); - } - - public EnableSimulatorPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - SimulatorInfo.FromBytes(bytes, ref i); - } - - public EnableSimulatorPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - SimulatorInfo.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += SimulatorInfo.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class DisableSimulatorPacket : Packet - { - public override int Length - { - get - { - int length = 10; - return length; - } - } - - public DisableSimulatorPacket() - { - HasVariableBlocks = false; - Type = PacketType.DisableSimulator; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 152; - Header.Reliable = true; - } - - public DisableSimulatorPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - } - - public DisableSimulatorPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - } - - public override byte[] ToBytes() - { - int length = 10; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class TransferRequestPacket : Packet - { - /// - public sealed class TransferInfoBlock : PacketBlock - { - public UUID TransferID; - public int ChannelType; - public int SourceType; - public float Priority; - public byte[] Params; - - public override int Length - { - get - { - int length = 30; - if (Params != null) { length += Params.Length; } - return length; - } - } - - public TransferInfoBlock() { } - public TransferInfoBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - TransferID.FromBytes(bytes, i); i += 16; - 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)); - Priority = Utils.BytesToFloat(bytes, i); i += 4; - length = (bytes[i++] + (bytes[i++] << 8)); - Params = new byte[length]; - Buffer.BlockCopy(bytes, i, Params, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - TransferID.ToBytes(bytes, i); i += 16; - Utils.IntToBytes(ChannelType, bytes, i); i += 4; - Utils.IntToBytes(SourceType, bytes, i); i += 4; - Utils.FloatToBytes(Priority, bytes, i); i += 4; - bytes[i++] = (byte)(Params.Length % 256); - bytes[i++] = (byte)((Params.Length >> 8) % 256); - Buffer.BlockCopy(Params, 0, bytes, i, Params.Length); i += Params.Length; - } - - } - - public override int Length - { - get - { - int length = 10; - length += TransferInfo.Length; - return length; - } - } - public TransferInfoBlock TransferInfo; - - public TransferRequestPacket() - { - HasVariableBlocks = false; - Type = PacketType.TransferRequest; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 153; - Header.Reliable = true; - Header.Zerocoded = true; - TransferInfo = new TransferInfoBlock(); - } - - public TransferRequestPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - TransferInfo.FromBytes(bytes, ref i); - } - - public TransferRequestPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - TransferInfo.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += TransferInfo.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class TransferInfoPacket : Packet - { - /// - public sealed class TransferInfoBlock : PacketBlock - { - public UUID TransferID; - public int ChannelType; - public int TargetType; - public int Status; - public int Size; - public byte[] Params; - - public override int Length - { - get - { - int length = 34; - if (Params != null) { length += Params.Length; } - return length; - } - } - - public TransferInfoBlock() { } - public TransferInfoBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - TransferID.FromBytes(bytes, i); i += 16; - 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)); - Size = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - length = (bytes[i++] + (bytes[i++] << 8)); - Params = new byte[length]; - Buffer.BlockCopy(bytes, i, Params, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - TransferID.ToBytes(bytes, i); i += 16; - Utils.IntToBytes(ChannelType, bytes, i); i += 4; - Utils.IntToBytes(TargetType, bytes, i); i += 4; - Utils.IntToBytes(Status, bytes, i); i += 4; - Utils.IntToBytes(Size, bytes, i); i += 4; - bytes[i++] = (byte)(Params.Length % 256); - bytes[i++] = (byte)((Params.Length >> 8) % 256); - Buffer.BlockCopy(Params, 0, bytes, i, Params.Length); i += Params.Length; - } - - } - - public override int Length - { - get - { - int length = 10; - length += TransferInfo.Length; - return length; - } - } - public TransferInfoBlock TransferInfo; - - public TransferInfoPacket() - { - HasVariableBlocks = false; - Type = PacketType.TransferInfo; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 154; - Header.Reliable = true; - Header.Zerocoded = true; - TransferInfo = new TransferInfoBlock(); - } - - public TransferInfoPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - TransferInfo.FromBytes(bytes, ref i); - } - - public TransferInfoPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - TransferInfo.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += TransferInfo.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class TransferAbortPacket : Packet - { - /// - public sealed class TransferInfoBlock : PacketBlock - { - public UUID TransferID; - public int ChannelType; - - public override int Length - { - get - { - return 20; - } - } - - public TransferInfoBlock() { } - public TransferInfoBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - TransferID.FromBytes(bytes, i); i += 16; - ChannelType = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - TransferID.ToBytes(bytes, i); i += 16; - Utils.IntToBytes(ChannelType, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 10; - length += TransferInfo.Length; - return length; - } - } - public TransferInfoBlock TransferInfo; - - public TransferAbortPacket() - { - HasVariableBlocks = false; - Type = PacketType.TransferAbort; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 155; - Header.Reliable = true; - Header.Zerocoded = true; - TransferInfo = new TransferInfoBlock(); - } - - public TransferAbortPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - TransferInfo.FromBytes(bytes, ref i); - } - - public TransferAbortPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - TransferInfo.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += TransferInfo.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class RequestXferPacket : Packet - { - /// - public sealed class XferIDBlock : PacketBlock - { - public ulong ID; - public byte[] Filename; - public byte FilePath; - public bool DeleteOnCompletion; - public bool UseBigPackets; - public UUID VFileID; - public short VFileType; - - public override int Length - { - get - { - int length = 30; - if (Filename != null) { length += Filename.Length; } - return length; - } - } - - public XferIDBlock() { } - public XferIDBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(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)); - length = bytes[i++]; - Filename = new byte[length]; - Buffer.BlockCopy(bytes, i, Filename, 0, length); i += length; - FilePath = (byte)bytes[i++]; - DeleteOnCompletion = (bytes[i++] != 0) ? (bool)true : (bool)false; - UseBigPackets = (bytes[i++] != 0) ? (bool)true : (bool)false; - VFileID.FromBytes(bytes, i); i += 16; - VFileType = (short)(bytes[i++] + (bytes[i++] << 8)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UInt64ToBytes(ID, bytes, i); i += 8; - bytes[i++] = (byte)Filename.Length; - Buffer.BlockCopy(Filename, 0, bytes, i, Filename.Length); i += Filename.Length; - bytes[i++] = FilePath; - bytes[i++] = (byte)((DeleteOnCompletion) ? 1 : 0); - bytes[i++] = (byte)((UseBigPackets) ? 1 : 0); - VFileID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)(VFileType % 256); - bytes[i++] = (byte)((VFileType >> 8) % 256); - } - - } - - public override int Length - { - get - { - int length = 10; - length += XferID.Length; - return length; - } - } - public XferIDBlock XferID; - - public RequestXferPacket() - { - HasVariableBlocks = false; - Type = PacketType.RequestXfer; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 156; - Header.Reliable = true; - Header.Zerocoded = true; - XferID = new XferIDBlock(); - } - - public RequestXferPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - XferID.FromBytes(bytes, ref i); - } - - public RequestXferPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - XferID.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += XferID.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class AbortXferPacket : Packet - { - /// - public sealed class XferIDBlock : PacketBlock - { - public ulong ID; - public int Result; - - public override int Length - { - get - { - return 12; - } - } - - public XferIDBlock() { } - public XferIDBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(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(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UInt64ToBytes(ID, bytes, i); i += 8; - Utils.IntToBytes(Result, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 10; - length += XferID.Length; - return length; - } - } - public XferIDBlock XferID; - - public AbortXferPacket() - { - HasVariableBlocks = false; - Type = PacketType.AbortXfer; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 157; - Header.Reliable = true; - XferID = new XferIDBlock(); - } - - public AbortXferPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - XferID.FromBytes(bytes, ref i); - } - - public AbortXferPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - XferID.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += XferID.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class AvatarAppearancePacket : Packet - { - /// - public sealed class SenderBlock : PacketBlock - { - public UUID ID; - public bool IsTrial; - - public override int Length - { - get - { - return 17; - } - } - - public SenderBlock() { } - public SenderBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - ID.FromBytes(bytes, i); i += 16; - IsTrial = (bytes[i++] != 0) ? (bool)true : (bool)false; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - ID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)((IsTrial) ? 1 : 0); - } - - } - - /// - public sealed class ObjectDataBlock : PacketBlock - { - public byte[] TextureEntry; - - public override int Length - { - get - { - int length = 2; - if (TextureEntry != null) { length += TextureEntry.Length; } - return length; - } - } - - public ObjectDataBlock() { } - public ObjectDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - length = (bytes[i++] + (bytes[i++] << 8)); - TextureEntry = new byte[length]; - Buffer.BlockCopy(bytes, i, TextureEntry, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - bytes[i++] = (byte)(TextureEntry.Length % 256); - bytes[i++] = (byte)((TextureEntry.Length >> 8) % 256); - Buffer.BlockCopy(TextureEntry, 0, bytes, i, TextureEntry.Length); i += TextureEntry.Length; - } - - } - - /// - public sealed class VisualParamBlock : PacketBlock - { - public byte ParamValue; - - public override int Length - { - get - { - return 1; - } - } - - public VisualParamBlock() { } - public VisualParamBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - ParamValue = (byte)bytes[i++]; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - bytes[i++] = ParamValue; - } - - } - - /// - public sealed class AppearanceDataBlock : PacketBlock - { - public byte AppearanceVersion; - public int CofVersion; - public uint Flags; - - public override int Length - { - get - { - return 9; - } - } - - public AppearanceDataBlock() { } - public AppearanceDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AppearanceVersion = (byte)bytes[i++]; - CofVersion = (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(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - bytes[i++] = AppearanceVersion; - Utils.IntToBytes(CofVersion, bytes, i); i += 4; - Utils.UIntToBytes(Flags, bytes, i); i += 4; - } - - } - - /// - public sealed class AppearanceHoverBlock : PacketBlock - { - public Vector3 HoverHeight; - - public override int Length - { - get - { - return 12; - } - } - - public AppearanceHoverBlock() { } - public AppearanceHoverBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - HoverHeight.FromBytes(bytes, i); i += 12; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - HoverHeight.ToBytes(bytes, i); i += 12; - } - - } - - public override int Length - { - get - { - int length = 13; - length += Sender.Length; - length += ObjectData.Length; - for (int j = 0; j < VisualParam.Length; j++) - length += VisualParam[j].Length; - for (int j = 0; j < AppearanceData.Length; j++) - length += AppearanceData[j].Length; - for (int j = 0; j < AppearanceHover.Length; j++) - length += AppearanceHover[j].Length; - return length; - } - } - public SenderBlock Sender; - public ObjectDataBlock ObjectData; - public VisualParamBlock[] VisualParam; - public AppearanceDataBlock[] AppearanceData; - public AppearanceHoverBlock[] AppearanceHover; - - public AvatarAppearancePacket() - { - HasVariableBlocks = true; - Type = PacketType.AvatarAppearance; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 158; - Header.Reliable = true; - Header.Zerocoded = true; - Sender = new SenderBlock(); - ObjectData = new ObjectDataBlock(); - VisualParam = null; - AppearanceData = null; - AppearanceHover = null; - } - - public AvatarAppearancePacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - Sender.FromBytes(bytes, ref i); - ObjectData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(VisualParam == null || VisualParam.Length != -1) { - VisualParam = new VisualParamBlock[count]; - for(int j = 0; j < count; j++) - { VisualParam[j] = new VisualParamBlock(); } - } - for (int j = 0; j < count; j++) - { VisualParam[j].FromBytes(bytes, ref i); } - count = (int)bytes[i++]; - if(AppearanceData == null || AppearanceData.Length != -1) { - AppearanceData = new AppearanceDataBlock[count]; - for(int j = 0; j < count; j++) - { AppearanceData[j] = new AppearanceDataBlock(); } - } - for (int j = 0; j < count; j++) - { AppearanceData[j].FromBytes(bytes, ref i); } - count = (int)bytes[i++]; - if(AppearanceHover == null || AppearanceHover.Length != -1) { - AppearanceHover = new AppearanceHoverBlock[count]; - for(int j = 0; j < count; j++) - { AppearanceHover[j] = new AppearanceHoverBlock(); } - } - for (int j = 0; j < count; j++) - { AppearanceHover[j].FromBytes(bytes, ref i); } - } - - public AvatarAppearancePacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - Sender.FromBytes(bytes, ref i); - ObjectData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(VisualParam == null || VisualParam.Length != count) { - VisualParam = new VisualParamBlock[count]; - for(int j = 0; j < count; j++) - { VisualParam[j] = new VisualParamBlock(); } - } - for (int j = 0; j < count; j++) - { VisualParam[j].FromBytes(bytes, ref i); } - count = (int)bytes[i++]; - if(AppearanceData == null || AppearanceData.Length != count) { - AppearanceData = new AppearanceDataBlock[count]; - for(int j = 0; j < count; j++) - { AppearanceData[j] = new AppearanceDataBlock(); } - } - for (int j = 0; j < count; j++) - { AppearanceData[j].FromBytes(bytes, ref i); } - count = (int)bytes[i++]; - if(AppearanceHover == null || AppearanceHover.Length != count) { - AppearanceHover = new AppearanceHoverBlock[count]; - for(int j = 0; j < count; j++) - { AppearanceHover[j] = new AppearanceHoverBlock(); } - } - for (int j = 0; j < count; j++) - { AppearanceHover[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += Sender.Length; - length += ObjectData.Length; - length++; - for (int j = 0; j < VisualParam.Length; j++) { length += VisualParam[j].Length; } - length++; - for (int j = 0; j < AppearanceData.Length; j++) { length += AppearanceData[j].Length; } - length++; - for (int j = 0; j < AppearanceHover.Length; j++) { length += AppearanceHover[j].Length; } - if (Header.AckList != null && 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); - ObjectData.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)AppearanceData.Length; - for (int j = 0; j < AppearanceData.Length; j++) { AppearanceData[j].ToBytes(bytes, ref i); } - bytes[i++] = (byte)AppearanceHover.Length; - for (int j = 0; j < AppearanceHover.Length; j++) { AppearanceHover[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += Sender.Length; - fixedLength += ObjectData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - Sender.ToBytes(fixedBytes, ref i); - ObjectData.ToBytes(fixedBytes, ref i); - fixedLength += 3; - - int VisualParamStart = 0; - int AppearanceDataStart = 0; - int AppearanceHoverStart = 0; - do - { - int variableLength = 0; - int VisualParamCount = 0; - int AppearanceDataCount = 0; - int AppearanceHoverCount = 0; - - i = VisualParamStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < VisualParam.Length) { - int blockLength = VisualParam[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == VisualParamStart) { - variableLength += blockLength; - ++VisualParamCount; - } - else { break; } - ++i; - } - - i = AppearanceDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < AppearanceData.Length) { - int blockLength = AppearanceData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == AppearanceDataStart) { - variableLength += blockLength; - ++AppearanceDataCount; - } - else { break; } - ++i; - } - - i = AppearanceHoverStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < AppearanceHover.Length) { - int blockLength = AppearanceHover[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == AppearanceHoverStart) { - variableLength += blockLength; - ++AppearanceHoverCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)VisualParamCount; - for (i = VisualParamStart; i < VisualParamStart + VisualParamCount; i++) { VisualParam[i].ToBytes(packet, ref length); } - VisualParamStart += VisualParamCount; - - packet[length++] = (byte)AppearanceDataCount; - for (i = AppearanceDataStart; i < AppearanceDataStart + AppearanceDataCount; i++) { AppearanceData[i].ToBytes(packet, ref length); } - AppearanceDataStart += AppearanceDataCount; - - packet[length++] = (byte)AppearanceHoverCount; - for (i = AppearanceHoverStart; i < AppearanceHoverStart + AppearanceHoverCount; i++) { AppearanceHover[i].ToBytes(packet, ref length); } - AppearanceHoverStart += AppearanceHoverCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - VisualParamStart < VisualParam.Length || - AppearanceDataStart < AppearanceData.Length || - AppearanceHoverStart < AppearanceHover.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class SetFollowCamPropertiesPacket : Packet - { - /// - public sealed class ObjectDataBlock : PacketBlock - { - public UUID ObjectID; - - public override int Length - { - get - { - return 16; - } - } - - public ObjectDataBlock() { } - public ObjectDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - ObjectID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - ObjectID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class CameraPropertyBlock : PacketBlock - { - public int Type; - public float Value; - - public override int Length - { - get - { - return 8; - } - } - - public CameraPropertyBlock() { } - public CameraPropertyBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - Type = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - Value = Utils.BytesToFloat(bytes, i); i += 4; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.IntToBytes(Type, bytes, i); i += 4; - Utils.FloatToBytes(Value, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 11; - length += ObjectData.Length; - for (int j = 0; j < CameraProperty.Length; j++) - length += CameraProperty[j].Length; - return length; - } - } - public ObjectDataBlock ObjectData; - public CameraPropertyBlock[] CameraProperty; - - public SetFollowCamPropertiesPacket() - { - HasVariableBlocks = true; - Type = PacketType.SetFollowCamProperties; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 159; - Header.Reliable = true; - ObjectData = new ObjectDataBlock(); - CameraProperty = null; - } - - public SetFollowCamPropertiesPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - ObjectData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(CameraProperty == null || CameraProperty.Length != -1) { - CameraProperty = new CameraPropertyBlock[count]; - for(int j = 0; j < count; j++) - { CameraProperty[j] = new CameraPropertyBlock(); } - } - for (int j = 0; j < count; j++) - { CameraProperty[j].FromBytes(bytes, ref i); } - } - - public SetFollowCamPropertiesPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - ObjectData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(CameraProperty == null || CameraProperty.Length != count) { - CameraProperty = new CameraPropertyBlock[count]; - for(int j = 0; j < count; j++) - { CameraProperty[j] = new CameraPropertyBlock(); } - } - for (int j = 0; j < count; j++) - { CameraProperty[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += ObjectData.Length; - length++; - for (int j = 0; j < CameraProperty.Length; j++) { length += CameraProperty[j].Length; } - if (Header.AckList != null && 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)CameraProperty.Length; - for (int j = 0; j < CameraProperty.Length; j++) { CameraProperty[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += ObjectData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - ObjectData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int CameraPropertyStart = 0; - do - { - int variableLength = 0; - int CameraPropertyCount = 0; - - i = CameraPropertyStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < CameraProperty.Length) { - int blockLength = CameraProperty[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == CameraPropertyStart) { - variableLength += blockLength; - ++CameraPropertyCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)CameraPropertyCount; - for (i = CameraPropertyStart; i < CameraPropertyStart + CameraPropertyCount; i++) { CameraProperty[i].ToBytes(packet, ref length); } - CameraPropertyStart += CameraPropertyCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - CameraPropertyStart < CameraProperty.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class ClearFollowCamPropertiesPacket : Packet - { - /// - public sealed class ObjectDataBlock : PacketBlock - { - public UUID ObjectID; - - public override int Length - { - get - { - return 16; - } - } - - public ObjectDataBlock() { } - public ObjectDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - ObjectID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - ObjectID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 10; - length += ObjectData.Length; - return length; - } - } - public ObjectDataBlock ObjectData; - - public ClearFollowCamPropertiesPacket() - { - HasVariableBlocks = false; - Type = PacketType.ClearFollowCamProperties; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 160; - Header.Reliable = true; - ObjectData = new ObjectDataBlock(); - } - - public ClearFollowCamPropertiesPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - ObjectData.FromBytes(bytes, ref i); - } - - public ClearFollowCamPropertiesPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - ObjectData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += ObjectData.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class RequestPayPricePacket : Packet - { - /// - public sealed class ObjectDataBlock : PacketBlock - { - public UUID ObjectID; - - public override int Length - { - get - { - return 16; - } - } - - public ObjectDataBlock() { } - public ObjectDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - ObjectID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - ObjectID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 10; - length += ObjectData.Length; - return length; - } - } - public ObjectDataBlock ObjectData; - - public RequestPayPricePacket() - { - HasVariableBlocks = false; - Type = PacketType.RequestPayPrice; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 161; - Header.Reliable = true; - ObjectData = new ObjectDataBlock(); - } - - public RequestPayPricePacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - ObjectData.FromBytes(bytes, ref i); - } - - public RequestPayPricePacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - ObjectData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += ObjectData.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class PayPriceReplyPacket : Packet - { - /// - public sealed class ObjectDataBlock : PacketBlock - { - public UUID ObjectID; - public int DefaultPayPrice; - - public override int Length - { - get - { - return 20; - } - } - - public ObjectDataBlock() { } - public ObjectDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - ObjectID.FromBytes(bytes, i); i += 16; - DefaultPayPrice = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - ObjectID.ToBytes(bytes, i); i += 16; - Utils.IntToBytes(DefaultPayPrice, bytes, i); i += 4; - } - - } - - /// - public sealed class ButtonDataBlock : PacketBlock - { - public int PayButton; - - public override int Length - { - get - { - return 4; - } - } - - public ButtonDataBlock() { } - public ButtonDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - PayButton = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.IntToBytes(PayButton, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 11; - length += ObjectData.Length; - for (int j = 0; j < ButtonData.Length; j++) - length += ButtonData[j].Length; - return length; - } - } - public ObjectDataBlock ObjectData; - public ButtonDataBlock[] ButtonData; - - public PayPriceReplyPacket() - { - HasVariableBlocks = true; - Type = PacketType.PayPriceReply; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 162; - Header.Reliable = true; - ObjectData = new ObjectDataBlock(); - ButtonData = null; - } - - public PayPriceReplyPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - ObjectData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ButtonData == null || ButtonData.Length != -1) { - ButtonData = new ButtonDataBlock[count]; - for(int j = 0; j < count; j++) - { ButtonData[j] = new ButtonDataBlock(); } - } - for (int j = 0; j < count; j++) - { ButtonData[j].FromBytes(bytes, ref i); } - } - - public PayPriceReplyPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - ObjectData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ButtonData == null || ButtonData.Length != count) { - ButtonData = new ButtonDataBlock[count]; - for(int j = 0; j < count; j++) - { ButtonData[j] = new ButtonDataBlock(); } - } - for (int j = 0; j < count; j++) - { ButtonData[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += ObjectData.Length; - length++; - for (int j = 0; j < ButtonData.Length; j++) { length += ButtonData[j].Length; } - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += ObjectData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - ObjectData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int ButtonDataStart = 0; - do - { - int variableLength = 0; - int ButtonDataCount = 0; - - i = ButtonDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < ButtonData.Length) { - int blockLength = ButtonData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ButtonDataStart) { - variableLength += blockLength; - ++ButtonDataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)ButtonDataCount; - for (i = ButtonDataStart; i < ButtonDataStart + ButtonDataCount; i++) { ButtonData[i].ToBytes(packet, ref length); } - ButtonDataStart += ButtonDataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - ButtonDataStart < ButtonData.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class KickUserPacket : Packet - { - /// - public sealed class TargetBlockBlock : PacketBlock - { - public uint TargetIP; - public ushort TargetPort; - - public override int Length - { - get - { - return 6; - } - } - - public TargetBlockBlock() { } - public TargetBlockBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(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(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UIntToBytes(TargetIP, bytes, i); i += 4; - bytes[i++] = (byte)((TargetPort >> 8) % 256); - bytes[i++] = (byte)(TargetPort % 256); - } - - } - - /// - public sealed class UserInfoBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - public byte[] Reason; - - public override int Length - { - get - { - int length = 34; - if (Reason != null) { length += Reason.Length; } - return length; - } - } - - public UserInfoBlock() { } - public UserInfoBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - length = (bytes[i++] + (bytes[i++] << 8)); - Reason = new byte[length]; - Buffer.BlockCopy(bytes, i, Reason, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)(Reason.Length % 256); - bytes[i++] = (byte)((Reason.Length >> 8) % 256); - Buffer.BlockCopy(Reason, 0, bytes, i, Reason.Length); i += Reason.Length; - } - - } - - public override int Length - { - get - { - int length = 10; - length += TargetBlock.Length; - length += UserInfo.Length; - return length; - } - } - public TargetBlockBlock TargetBlock; - public UserInfoBlock UserInfo; - - public KickUserPacket() - { - HasVariableBlocks = false; - Type = PacketType.KickUser; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 163; - Header.Reliable = true; - TargetBlock = new TargetBlockBlock(); - UserInfo = new UserInfoBlock(); - } - - public KickUserPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - TargetBlock.FromBytes(bytes, ref i); - UserInfo.FromBytes(bytes, ref i); - } - - public KickUserPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - TargetBlock.FromBytes(bytes, ref i); - UserInfo.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += TargetBlock.Length; - length += UserInfo.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class GodKickUserPacket : Packet - { - /// - public sealed class UserInfoBlock : PacketBlock - { - public UUID GodID; - public UUID GodSessionID; - public UUID AgentID; - public uint KickFlags; - public byte[] Reason; - - public override int Length - { - get - { - int length = 54; - if (Reason != null) { length += Reason.Length; } - return length; - } - } - - public UserInfoBlock() { } - public UserInfoBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - GodID.FromBytes(bytes, i); i += 16; - GodSessionID.FromBytes(bytes, i); i += 16; - AgentID.FromBytes(bytes, i); i += 16; - KickFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - length = (bytes[i++] + (bytes[i++] << 8)); - Reason = new byte[length]; - Buffer.BlockCopy(bytes, i, Reason, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - GodID.ToBytes(bytes, i); i += 16; - GodSessionID.ToBytes(bytes, i); i += 16; - AgentID.ToBytes(bytes, i); i += 16; - Utils.UIntToBytes(KickFlags, bytes, i); i += 4; - bytes[i++] = (byte)(Reason.Length % 256); - bytes[i++] = (byte)((Reason.Length >> 8) % 256); - Buffer.BlockCopy(Reason, 0, bytes, i, Reason.Length); i += Reason.Length; - } - - } - - public override int Length - { - get - { - int length = 10; - length += UserInfo.Length; - return length; - } - } - public UserInfoBlock UserInfo; - - public GodKickUserPacket() - { - HasVariableBlocks = false; - Type = PacketType.GodKickUser; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 165; - Header.Reliable = true; - UserInfo = new UserInfoBlock(); - } - - public GodKickUserPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - UserInfo.FromBytes(bytes, ref i); - } - - public GodKickUserPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - UserInfo.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += UserInfo.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class EjectUserPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class DataBlock : PacketBlock - { - public UUID TargetID; - public uint Flags; - - public override int Length - { - get - { - return 20; - } - } - - public DataBlock() { } - public DataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - TargetID.FromBytes(bytes, i); i += 16; - Flags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - TargetID.ToBytes(bytes, i); i += 16; - Utils.UIntToBytes(Flags, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += Data.Length; - return length; - } - } - public AgentDataBlock AgentData; - public DataBlock Data; - - public EjectUserPacket() - { - HasVariableBlocks = false; - Type = PacketType.EjectUser; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 167; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - Data = new DataBlock(); - } - - public EjectUserPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - Data.FromBytes(bytes, ref i); - } - - public EjectUserPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - Data.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += Data.Length; - if (Header.AckList != null && 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); - Data.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class FreezeUserPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class DataBlock : PacketBlock - { - public UUID TargetID; - public uint Flags; - - public override int Length - { - get - { - return 20; - } - } - - public DataBlock() { } - public DataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - TargetID.FromBytes(bytes, i); i += 16; - Flags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - TargetID.ToBytes(bytes, i); i += 16; - Utils.UIntToBytes(Flags, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += Data.Length; - return length; - } - } - public AgentDataBlock AgentData; - public DataBlock Data; - - public FreezeUserPacket() - { - HasVariableBlocks = false; - Type = PacketType.FreezeUser; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 168; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - Data = new DataBlock(); - } - - public FreezeUserPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - Data.FromBytes(bytes, ref i); - } - - public FreezeUserPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - Data.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += Data.Length; - if (Header.AckList != null && 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); - Data.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class AvatarPropertiesRequestPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - public UUID AvatarID; - - public override int Length - { - get - { - return 48; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - AvatarID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - AvatarID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - return length; - } - } - public AgentDataBlock AgentData; - - public AvatarPropertiesRequestPacket() - { - HasVariableBlocks = false; - Type = PacketType.AvatarPropertiesRequest; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 169; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - } - - public AvatarPropertiesRequestPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - } - - public AvatarPropertiesRequestPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class AvatarPropertiesReplyPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID AvatarID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - AvatarID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - AvatarID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class PropertiesDataBlock : PacketBlock - { - public UUID ImageID; - public UUID FLImageID; - public UUID PartnerID; - public byte[] AboutText; - public byte[] FLAboutText; - public byte[] BornOn; - public byte[] ProfileURL; - public byte[] CharterMember; - public uint Flags; - - public override int Length - { - get - { - int length = 58; - if (AboutText != null) { length += AboutText.Length; } - if (FLAboutText != null) { length += FLAboutText.Length; } - if (BornOn != null) { length += BornOn.Length; } - if (ProfileURL != null) { length += ProfileURL.Length; } - if (CharterMember != null) { length += CharterMember.Length; } - return length; - } - } - - public PropertiesDataBlock() { } - public PropertiesDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - ImageID.FromBytes(bytes, i); i += 16; - FLImageID.FromBytes(bytes, i); i += 16; - PartnerID.FromBytes(bytes, i); i += 16; - length = (bytes[i++] + (bytes[i++] << 8)); - AboutText = new byte[length]; - Buffer.BlockCopy(bytes, i, AboutText, 0, length); i += length; - length = bytes[i++]; - FLAboutText = new byte[length]; - Buffer.BlockCopy(bytes, i, FLAboutText, 0, length); i += length; - length = bytes[i++]; - BornOn = new byte[length]; - Buffer.BlockCopy(bytes, i, BornOn, 0, length); i += length; - length = bytes[i++]; - ProfileURL = new byte[length]; - Buffer.BlockCopy(bytes, i, ProfileURL, 0, length); i += length; - length = bytes[i++]; - CharterMember = new byte[length]; - Buffer.BlockCopy(bytes, i, CharterMember, 0, length); i += length; - Flags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - ImageID.ToBytes(bytes, i); i += 16; - FLImageID.ToBytes(bytes, i); i += 16; - PartnerID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)(AboutText.Length % 256); - bytes[i++] = (byte)((AboutText.Length >> 8) % 256); - Buffer.BlockCopy(AboutText, 0, bytes, i, AboutText.Length); i += AboutText.Length; - bytes[i++] = (byte)FLAboutText.Length; - Buffer.BlockCopy(FLAboutText, 0, bytes, i, FLAboutText.Length); i += FLAboutText.Length; - bytes[i++] = (byte)BornOn.Length; - Buffer.BlockCopy(BornOn, 0, bytes, i, BornOn.Length); i += BornOn.Length; - bytes[i++] = (byte)ProfileURL.Length; - Buffer.BlockCopy(ProfileURL, 0, bytes, i, ProfileURL.Length); i += ProfileURL.Length; - bytes[i++] = (byte)CharterMember.Length; - Buffer.BlockCopy(CharterMember, 0, bytes, i, CharterMember.Length); i += CharterMember.Length; - Utils.UIntToBytes(Flags, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += PropertiesData.Length; - return length; - } - } - public AgentDataBlock AgentData; - public PropertiesDataBlock PropertiesData; - - public AvatarPropertiesReplyPacket() - { - HasVariableBlocks = false; - Type = PacketType.AvatarPropertiesReply; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 171; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - PropertiesData = new PropertiesDataBlock(); - } - - public AvatarPropertiesReplyPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - PropertiesData.FromBytes(bytes, ref i); - } - - public AvatarPropertiesReplyPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - PropertiesData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += PropertiesData.Length; - if (Header.AckList != null && 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); - PropertiesData.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class AvatarInterestsReplyPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID AvatarID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - AvatarID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - AvatarID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class PropertiesDataBlock : PacketBlock - { - public uint WantToMask; - public byte[] WantToText; - public uint SkillsMask; - public byte[] SkillsText; - public byte[] LanguagesText; - - public override int Length - { - get - { - int length = 11; - if (WantToText != null) { length += WantToText.Length; } - if (SkillsText != null) { length += SkillsText.Length; } - if (LanguagesText != null) { length += LanguagesText.Length; } - return length; - } - } - - public PropertiesDataBlock() { } - public PropertiesDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - WantToMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - length = bytes[i++]; - WantToText = new byte[length]; - Buffer.BlockCopy(bytes, i, WantToText, 0, length); i += length; - SkillsMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - length = bytes[i++]; - SkillsText = new byte[length]; - Buffer.BlockCopy(bytes, i, SkillsText, 0, length); i += length; - length = bytes[i++]; - LanguagesText = new byte[length]; - Buffer.BlockCopy(bytes, i, LanguagesText, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UIntToBytes(WantToMask, bytes, i); i += 4; - bytes[i++] = (byte)WantToText.Length; - Buffer.BlockCopy(WantToText, 0, bytes, i, WantToText.Length); i += WantToText.Length; - Utils.UIntToBytes(SkillsMask, bytes, i); i += 4; - bytes[i++] = (byte)SkillsText.Length; - Buffer.BlockCopy(SkillsText, 0, bytes, i, SkillsText.Length); i += SkillsText.Length; - bytes[i++] = (byte)LanguagesText.Length; - Buffer.BlockCopy(LanguagesText, 0, bytes, i, LanguagesText.Length); i += LanguagesText.Length; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += PropertiesData.Length; - return length; - } - } - public AgentDataBlock AgentData; - public PropertiesDataBlock PropertiesData; - - public AvatarInterestsReplyPacket() - { - HasVariableBlocks = false; - Type = PacketType.AvatarInterestsReply; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 172; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - PropertiesData = new PropertiesDataBlock(); - } - - public AvatarInterestsReplyPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - PropertiesData.FromBytes(bytes, ref i); - } - - public AvatarInterestsReplyPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - PropertiesData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += PropertiesData.Length; - if (Header.AckList != null && 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); - PropertiesData.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class AvatarGroupsReplyPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID AvatarID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - AvatarID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - AvatarID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class GroupDataBlock : PacketBlock - { - public ulong GroupPowers; - public bool AcceptNotices; - public byte[] GroupTitle; - public UUID GroupID; - public byte[] GroupName; - public UUID GroupInsigniaID; - - public override int Length - { - get - { - int length = 43; - if (GroupTitle != null) { length += GroupTitle.Length; } - if (GroupName != null) { length += GroupName.Length; } - return length; - } - } - - public GroupDataBlock() { } - public GroupDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(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)); - AcceptNotices = (bytes[i++] != 0) ? (bool)true : (bool)false; - length = bytes[i++]; - GroupTitle = new byte[length]; - Buffer.BlockCopy(bytes, i, GroupTitle, 0, length); i += length; - GroupID.FromBytes(bytes, i); i += 16; - length = bytes[i++]; - GroupName = new byte[length]; - Buffer.BlockCopy(bytes, i, GroupName, 0, length); i += length; - GroupInsigniaID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UInt64ToBytes(GroupPowers, bytes, i); i += 8; - bytes[i++] = (byte)((AcceptNotices) ? 1 : 0); - bytes[i++] = (byte)GroupTitle.Length; - Buffer.BlockCopy(GroupTitle, 0, bytes, i, GroupTitle.Length); i += GroupTitle.Length; - GroupID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)GroupName.Length; - Buffer.BlockCopy(GroupName, 0, bytes, i, GroupName.Length); i += GroupName.Length; - GroupInsigniaID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class NewGroupDataBlock : PacketBlock - { - public bool ListInProfile; - - public override int Length - { - get - { - return 1; - } - } - - public NewGroupDataBlock() { } - public NewGroupDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - ListInProfile = (bytes[i++] != 0) ? (bool)true : (bool)false; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - bytes[i++] = (byte)((ListInProfile) ? 1 : 0); - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentData.Length; - for (int j = 0; j < GroupData.Length; j++) - length += GroupData[j].Length; - length += NewGroupData.Length; - return length; - } - } - public AgentDataBlock AgentData; - public GroupDataBlock[] GroupData; - public NewGroupDataBlock NewGroupData; - - public AvatarGroupsReplyPacket() - { - HasVariableBlocks = true; - Type = PacketType.AvatarGroupsReply; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 173; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - GroupData = null; - NewGroupData = new NewGroupDataBlock(); - } - - public AvatarGroupsReplyPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(GroupData == null || GroupData.Length != -1) { - GroupData = new GroupDataBlock[count]; - for(int j = 0; j < count; j++) - { GroupData[j] = new GroupDataBlock(); } - } - for (int j = 0; j < count; j++) - { GroupData[j].FromBytes(bytes, ref i); } - NewGroupData.FromBytes(bytes, ref i); - } - - public AvatarGroupsReplyPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(GroupData == null || GroupData.Length != count) { - GroupData = new GroupDataBlock[count]; - for(int j = 0; j < count; j++) - { GroupData[j] = new GroupDataBlock(); } - } - for (int j = 0; j < count; j++) - { GroupData[j].FromBytes(bytes, ref i); } - NewGroupData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += NewGroupData.Length; - length++; - for (int j = 0; j < GroupData.Length; j++) { length += GroupData[j].Length; } - if (Header.AckList != null && 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); } - NewGroupData.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class AvatarPropertiesUpdatePacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class PropertiesDataBlock : PacketBlock - { - public UUID ImageID; - public UUID FLImageID; - public byte[] AboutText; - public byte[] FLAboutText; - public bool AllowPublish; - public bool MaturePublish; - public byte[] ProfileURL; - - public override int Length - { - get - { - int length = 38; - if (AboutText != null) { length += AboutText.Length; } - if (FLAboutText != null) { length += FLAboutText.Length; } - if (ProfileURL != null) { length += ProfileURL.Length; } - return length; - } - } - - public PropertiesDataBlock() { } - public PropertiesDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - ImageID.FromBytes(bytes, i); i += 16; - FLImageID.FromBytes(bytes, i); i += 16; - length = (bytes[i++] + (bytes[i++] << 8)); - AboutText = new byte[length]; - Buffer.BlockCopy(bytes, i, AboutText, 0, length); i += length; - length = bytes[i++]; - FLAboutText = new byte[length]; - Buffer.BlockCopy(bytes, i, FLAboutText, 0, length); i += length; - AllowPublish = (bytes[i++] != 0) ? (bool)true : (bool)false; - MaturePublish = (bytes[i++] != 0) ? (bool)true : (bool)false; - length = bytes[i++]; - ProfileURL = new byte[length]; - Buffer.BlockCopy(bytes, i, ProfileURL, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - ImageID.ToBytes(bytes, i); i += 16; - FLImageID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)(AboutText.Length % 256); - bytes[i++] = (byte)((AboutText.Length >> 8) % 256); - Buffer.BlockCopy(AboutText, 0, bytes, i, AboutText.Length); i += AboutText.Length; - bytes[i++] = (byte)FLAboutText.Length; - Buffer.BlockCopy(FLAboutText, 0, bytes, i, FLAboutText.Length); i += FLAboutText.Length; - bytes[i++] = (byte)((AllowPublish) ? 1 : 0); - bytes[i++] = (byte)((MaturePublish) ? 1 : 0); - bytes[i++] = (byte)ProfileURL.Length; - Buffer.BlockCopy(ProfileURL, 0, bytes, i, ProfileURL.Length); i += ProfileURL.Length; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += PropertiesData.Length; - return length; - } - } - public AgentDataBlock AgentData; - public PropertiesDataBlock PropertiesData; - - public AvatarPropertiesUpdatePacket() - { - HasVariableBlocks = false; - Type = PacketType.AvatarPropertiesUpdate; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 174; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - PropertiesData = new PropertiesDataBlock(); - } - - public AvatarPropertiesUpdatePacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - PropertiesData.FromBytes(bytes, ref i); - } - - public AvatarPropertiesUpdatePacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - PropertiesData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += PropertiesData.Length; - if (Header.AckList != null && 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); - PropertiesData.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class AvatarInterestsUpdatePacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class PropertiesDataBlock : PacketBlock - { - public uint WantToMask; - public byte[] WantToText; - public uint SkillsMask; - public byte[] SkillsText; - public byte[] LanguagesText; - - public override int Length - { - get - { - int length = 11; - if (WantToText != null) { length += WantToText.Length; } - if (SkillsText != null) { length += SkillsText.Length; } - if (LanguagesText != null) { length += LanguagesText.Length; } - return length; - } - } - - public PropertiesDataBlock() { } - public PropertiesDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - WantToMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - length = bytes[i++]; - WantToText = new byte[length]; - Buffer.BlockCopy(bytes, i, WantToText, 0, length); i += length; - SkillsMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - length = bytes[i++]; - SkillsText = new byte[length]; - Buffer.BlockCopy(bytes, i, SkillsText, 0, length); i += length; - length = bytes[i++]; - LanguagesText = new byte[length]; - Buffer.BlockCopy(bytes, i, LanguagesText, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UIntToBytes(WantToMask, bytes, i); i += 4; - bytes[i++] = (byte)WantToText.Length; - Buffer.BlockCopy(WantToText, 0, bytes, i, WantToText.Length); i += WantToText.Length; - Utils.UIntToBytes(SkillsMask, bytes, i); i += 4; - bytes[i++] = (byte)SkillsText.Length; - Buffer.BlockCopy(SkillsText, 0, bytes, i, SkillsText.Length); i += SkillsText.Length; - bytes[i++] = (byte)LanguagesText.Length; - Buffer.BlockCopy(LanguagesText, 0, bytes, i, LanguagesText.Length); i += LanguagesText.Length; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += PropertiesData.Length; - return length; - } - } - public AgentDataBlock AgentData; - public PropertiesDataBlock PropertiesData; - - public AvatarInterestsUpdatePacket() - { - HasVariableBlocks = false; - Type = PacketType.AvatarInterestsUpdate; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 175; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - PropertiesData = new PropertiesDataBlock(); - } - - public AvatarInterestsUpdatePacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - PropertiesData.FromBytes(bytes, ref i); - } - - public AvatarInterestsUpdatePacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - PropertiesData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += PropertiesData.Length; - if (Header.AckList != null && 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); - PropertiesData.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class AvatarNotesReplyPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - - public override int Length - { - get - { - return 16; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class DataBlock : PacketBlock - { - public UUID TargetID; - public byte[] Notes; - - public override int Length - { - get - { - int length = 18; - if (Notes != null) { length += Notes.Length; } - return length; - } - } - - public DataBlock() { } - public DataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - TargetID.FromBytes(bytes, i); i += 16; - length = (bytes[i++] + (bytes[i++] << 8)); - Notes = new byte[length]; - Buffer.BlockCopy(bytes, i, Notes, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - TargetID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)(Notes.Length % 256); - bytes[i++] = (byte)((Notes.Length >> 8) % 256); - Buffer.BlockCopy(Notes, 0, bytes, i, Notes.Length); i += Notes.Length; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += Data.Length; - return length; - } - } - public AgentDataBlock AgentData; - public DataBlock Data; - - public AvatarNotesReplyPacket() - { - HasVariableBlocks = false; - Type = PacketType.AvatarNotesReply; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 176; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - Data = new DataBlock(); - } - - public AvatarNotesReplyPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - Data.FromBytes(bytes, ref i); - } - - public AvatarNotesReplyPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - Data.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += Data.Length; - if (Header.AckList != null && 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); - Data.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class AvatarNotesUpdatePacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class DataBlock : PacketBlock - { - public UUID TargetID; - public byte[] Notes; - - public override int Length - { - get - { - int length = 18; - if (Notes != null) { length += Notes.Length; } - return length; - } - } - - public DataBlock() { } - public DataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - TargetID.FromBytes(bytes, i); i += 16; - length = (bytes[i++] + (bytes[i++] << 8)); - Notes = new byte[length]; - Buffer.BlockCopy(bytes, i, Notes, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - TargetID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)(Notes.Length % 256); - bytes[i++] = (byte)((Notes.Length >> 8) % 256); - Buffer.BlockCopy(Notes, 0, bytes, i, Notes.Length); i += Notes.Length; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += Data.Length; - return length; - } - } - public AgentDataBlock AgentData; - public DataBlock Data; - - public AvatarNotesUpdatePacket() - { - HasVariableBlocks = false; - Type = PacketType.AvatarNotesUpdate; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 177; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - Data = new DataBlock(); - } - - public AvatarNotesUpdatePacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - Data.FromBytes(bytes, ref i); - } - - public AvatarNotesUpdatePacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - Data.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += Data.Length; - if (Header.AckList != null && 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); - Data.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class AvatarPicksReplyPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID TargetID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - TargetID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - TargetID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class DataBlock : PacketBlock - { - public UUID PickID; - public byte[] PickName; - - public override int Length - { - get - { - int length = 17; - if (PickName != null) { length += PickName.Length; } - return length; - } - } - - public DataBlock() { } - public DataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - PickID.FromBytes(bytes, i); i += 16; - length = bytes[i++]; - PickName = new byte[length]; - Buffer.BlockCopy(bytes, i, PickName, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - PickID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)PickName.Length; - Buffer.BlockCopy(PickName, 0, bytes, i, PickName.Length); i += PickName.Length; - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentData.Length; - for (int j = 0; j < Data.Length; j++) - length += Data[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public DataBlock[] Data; - - public AvatarPicksReplyPacket() - { - HasVariableBlocks = true; - Type = PacketType.AvatarPicksReply; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 178; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - Data = null; - } - - public AvatarPicksReplyPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(Data == null || Data.Length != -1) { - Data = new DataBlock[count]; - for(int j = 0; j < count; j++) - { Data[j] = new DataBlock(); } - } - for (int j = 0; j < count; j++) - { Data[j].FromBytes(bytes, ref i); } - } - - public AvatarPicksReplyPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(Data == null || Data.Length != count) { - Data = new DataBlock[count]; - for(int j = 0; j < count; j++) - { Data[j] = new DataBlock(); } - } - for (int j = 0; j < count; j++) - { Data[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length++; - for (int j = 0; j < Data.Length; j++) { length += Data[j].Length; } - if (Header.AckList != null && 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)Data.Length; - for (int j = 0; j < Data.Length; j++) { Data[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int DataStart = 0; - do - { - int variableLength = 0; - int DataCount = 0; - - i = DataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < Data.Length) { - int blockLength = Data[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == DataStart) { - variableLength += blockLength; - ++DataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)DataCount; - for (i = DataStart; i < DataStart + DataCount; i++) { Data[i].ToBytes(packet, ref length); } - DataStart += DataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - DataStart < Data.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class EventInfoRequestPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class EventDataBlock : PacketBlock - { - public uint EventID; - - public override int Length - { - get - { - return 4; - } - } - - public EventDataBlock() { } - public EventDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - EventID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UIntToBytes(EventID, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += EventData.Length; - return length; - } - } - public AgentDataBlock AgentData; - public EventDataBlock EventData; - - public EventInfoRequestPacket() - { - HasVariableBlocks = false; - Type = PacketType.EventInfoRequest; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 179; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - EventData = new EventDataBlock(); - } - - public EventInfoRequestPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - EventData.FromBytes(bytes, ref i); - } - - public EventInfoRequestPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - EventData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += EventData.Length; - if (Header.AckList != null && 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); - EventData.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class EventInfoReplyPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - - public override int Length - { - get - { - return 16; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class EventDataBlock : PacketBlock - { - public uint EventID; - public byte[] Creator; - public byte[] Name; - public byte[] Category; - public byte[] Desc; - public byte[] Date; - public uint DateUTC; - public uint Duration; - public uint Cover; - public uint Amount; - public byte[] SimName; - public Vector3d GlobalPos; - public uint EventFlags; - - public override int Length - { - get - { - int length = 55; - if (Creator != null) { length += Creator.Length; } - if (Name != null) { length += Name.Length; } - if (Category != null) { length += Category.Length; } - if (Desc != null) { length += Desc.Length; } - if (Date != null) { length += Date.Length; } - if (SimName != null) { length += SimName.Length; } - return length; - } - } - - public EventDataBlock() { } - public EventDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - EventID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - length = bytes[i++]; - Creator = new byte[length]; - Buffer.BlockCopy(bytes, i, Creator, 0, length); i += length; - length = bytes[i++]; - Name = new byte[length]; - Buffer.BlockCopy(bytes, i, Name, 0, length); i += length; - length = bytes[i++]; - Category = new byte[length]; - Buffer.BlockCopy(bytes, i, Category, 0, length); i += length; - length = (bytes[i++] + (bytes[i++] << 8)); - Desc = new byte[length]; - Buffer.BlockCopy(bytes, i, Desc, 0, length); i += length; - length = bytes[i++]; - Date = new byte[length]; - Buffer.BlockCopy(bytes, i, Date, 0, length); i += length; - DateUTC = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - Duration = (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)); - Amount = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - length = bytes[i++]; - SimName = new byte[length]; - Buffer.BlockCopy(bytes, i, SimName, 0, length); i += length; - GlobalPos.FromBytes(bytes, i); i += 24; - EventFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UIntToBytes(EventID, bytes, i); i += 4; - bytes[i++] = (byte)Creator.Length; - Buffer.BlockCopy(Creator, 0, bytes, i, Creator.Length); i += Creator.Length; - bytes[i++] = (byte)Name.Length; - Buffer.BlockCopy(Name, 0, bytes, i, Name.Length); i += Name.Length; - bytes[i++] = (byte)Category.Length; - Buffer.BlockCopy(Category, 0, bytes, i, Category.Length); i += Category.Length; - bytes[i++] = (byte)(Desc.Length % 256); - bytes[i++] = (byte)((Desc.Length >> 8) % 256); - Buffer.BlockCopy(Desc, 0, bytes, i, Desc.Length); i += Desc.Length; - bytes[i++] = (byte)Date.Length; - Buffer.BlockCopy(Date, 0, bytes, i, Date.Length); i += Date.Length; - Utils.UIntToBytes(DateUTC, bytes, i); i += 4; - Utils.UIntToBytes(Duration, bytes, i); i += 4; - Utils.UIntToBytes(Cover, bytes, i); i += 4; - Utils.UIntToBytes(Amount, bytes, i); i += 4; - bytes[i++] = (byte)SimName.Length; - Buffer.BlockCopy(SimName, 0, bytes, i, SimName.Length); i += SimName.Length; - GlobalPos.ToBytes(bytes, i); i += 24; - Utils.UIntToBytes(EventFlags, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += EventData.Length; - return length; - } - } - public AgentDataBlock AgentData; - public EventDataBlock EventData; - - public EventInfoReplyPacket() - { - HasVariableBlocks = false; - Type = PacketType.EventInfoReply; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 180; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - EventData = new EventDataBlock(); - } - - public EventInfoReplyPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - EventData.FromBytes(bytes, ref i); - } - - public EventInfoReplyPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - EventData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += EventData.Length; - if (Header.AckList != null && 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); - EventData.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class EventNotificationAddRequestPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class EventDataBlock : PacketBlock - { - public uint EventID; - - public override int Length - { - get - { - return 4; - } - } - - public EventDataBlock() { } - public EventDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - EventID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UIntToBytes(EventID, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += EventData.Length; - return length; - } - } - public AgentDataBlock AgentData; - public EventDataBlock EventData; - - public EventNotificationAddRequestPacket() - { - HasVariableBlocks = false; - Type = PacketType.EventNotificationAddRequest; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 181; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - EventData = new EventDataBlock(); - } - - public EventNotificationAddRequestPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - EventData.FromBytes(bytes, ref i); - } - - public EventNotificationAddRequestPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - EventData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += EventData.Length; - if (Header.AckList != null && 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); - EventData.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class EventNotificationRemoveRequestPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class EventDataBlock : PacketBlock - { - public uint EventID; - - public override int Length - { - get - { - return 4; - } - } - - public EventDataBlock() { } - public EventDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - EventID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UIntToBytes(EventID, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += EventData.Length; - return length; - } - } - public AgentDataBlock AgentData; - public EventDataBlock EventData; - - public EventNotificationRemoveRequestPacket() - { - HasVariableBlocks = false; - Type = PacketType.EventNotificationRemoveRequest; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 182; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - EventData = new EventDataBlock(); - } - - public EventNotificationRemoveRequestPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - EventData.FromBytes(bytes, ref i); - } - - public EventNotificationRemoveRequestPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - EventData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += EventData.Length; - if (Header.AckList != null && 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); - EventData.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class EventGodDeletePacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class EventDataBlock : PacketBlock - { - public uint EventID; - - public override int Length - { - get - { - return 4; - } - } - - public EventDataBlock() { } - public EventDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - EventID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UIntToBytes(EventID, bytes, i); i += 4; - } - - } - - /// - public sealed class QueryDataBlock : PacketBlock - { - public UUID QueryID; - public byte[] QueryText; - public uint QueryFlags; - public int QueryStart; - - public override int Length - { - get - { - int length = 25; - if (QueryText != null) { length += QueryText.Length; } - return length; - } - } - - public QueryDataBlock() { } - public QueryDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - QueryID.FromBytes(bytes, i); i += 16; - length = bytes[i++]; - QueryText = new byte[length]; - Buffer.BlockCopy(bytes, i, QueryText, 0, length); i += length; - 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)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - QueryID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)QueryText.Length; - Buffer.BlockCopy(QueryText, 0, bytes, i, QueryText.Length); i += QueryText.Length; - Utils.UIntToBytes(QueryFlags, bytes, i); i += 4; - Utils.IntToBytes(QueryStart, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += EventData.Length; - length += QueryData.Length; - return length; - } - } - public AgentDataBlock AgentData; - public EventDataBlock EventData; - public QueryDataBlock QueryData; - - public EventGodDeletePacket() - { - HasVariableBlocks = false; - Type = PacketType.EventGodDelete; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 183; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - EventData = new EventDataBlock(); - QueryData = new QueryDataBlock(); - } - - public EventGodDeletePacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - EventData.FromBytes(bytes, ref i); - QueryData.FromBytes(bytes, ref i); - } - - public EventGodDeletePacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - EventData.FromBytes(bytes, ref i); - QueryData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += EventData.Length; - length += QueryData.Length; - if (Header.AckList != null && 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); - EventData.ToBytes(bytes, ref i); - QueryData.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class PickInfoReplyPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - - public override int Length - { - get - { - return 16; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class DataBlock : PacketBlock - { - public UUID PickID; - public UUID CreatorID; - public bool TopPick; - public UUID ParcelID; - public byte[] Name; - public byte[] Desc; - public UUID SnapshotID; - public byte[] User; - public byte[] OriginalName; - public byte[] SimName; - public Vector3d PosGlobal; - public int SortOrder; - public bool Enabled; - - public override int Length - { - get - { - int length = 100; - if (Name != null) { length += Name.Length; } - if (Desc != null) { length += Desc.Length; } - if (User != null) { length += User.Length; } - if (OriginalName != null) { length += OriginalName.Length; } - if (SimName != null) { length += SimName.Length; } - return length; - } - } - - public DataBlock() { } - public DataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - PickID.FromBytes(bytes, i); i += 16; - CreatorID.FromBytes(bytes, i); i += 16; - TopPick = (bytes[i++] != 0) ? (bool)true : (bool)false; - ParcelID.FromBytes(bytes, i); i += 16; - length = bytes[i++]; - Name = new byte[length]; - Buffer.BlockCopy(bytes, i, Name, 0, length); i += length; - length = (bytes[i++] + (bytes[i++] << 8)); - Desc = new byte[length]; - Buffer.BlockCopy(bytes, i, Desc, 0, length); i += length; - SnapshotID.FromBytes(bytes, i); i += 16; - length = bytes[i++]; - User = new byte[length]; - Buffer.BlockCopy(bytes, i, User, 0, length); i += length; - length = bytes[i++]; - OriginalName = new byte[length]; - Buffer.BlockCopy(bytes, i, OriginalName, 0, length); i += length; - length = bytes[i++]; - SimName = new byte[length]; - Buffer.BlockCopy(bytes, i, SimName, 0, length); i += length; - PosGlobal.FromBytes(bytes, i); i += 24; - SortOrder = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - Enabled = (bytes[i++] != 0) ? (bool)true : (bool)false; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - PickID.ToBytes(bytes, i); i += 16; - CreatorID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)((TopPick) ? 1 : 0); - ParcelID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)Name.Length; - Buffer.BlockCopy(Name, 0, bytes, i, Name.Length); i += Name.Length; - bytes[i++] = (byte)(Desc.Length % 256); - bytes[i++] = (byte)((Desc.Length >> 8) % 256); - Buffer.BlockCopy(Desc, 0, bytes, i, Desc.Length); i += Desc.Length; - SnapshotID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)User.Length; - Buffer.BlockCopy(User, 0, bytes, i, User.Length); i += User.Length; - bytes[i++] = (byte)OriginalName.Length; - Buffer.BlockCopy(OriginalName, 0, bytes, i, OriginalName.Length); i += OriginalName.Length; - bytes[i++] = (byte)SimName.Length; - Buffer.BlockCopy(SimName, 0, bytes, i, SimName.Length); i += SimName.Length; - PosGlobal.ToBytes(bytes, i); i += 24; - Utils.IntToBytes(SortOrder, bytes, i); i += 4; - bytes[i++] = (byte)((Enabled) ? 1 : 0); - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += Data.Length; - return length; - } - } - public AgentDataBlock AgentData; - public DataBlock Data; - - public PickInfoReplyPacket() - { - HasVariableBlocks = false; - Type = PacketType.PickInfoReply; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 184; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - Data = new DataBlock(); - } - - public PickInfoReplyPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - Data.FromBytes(bytes, ref i); - } - - public PickInfoReplyPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - Data.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += Data.Length; - if (Header.AckList != null && 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); - Data.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class PickInfoUpdatePacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class DataBlock : PacketBlock - { - public UUID PickID; - public UUID CreatorID; - public bool TopPick; - public UUID ParcelID; - public byte[] Name; - public byte[] Desc; - public UUID SnapshotID; - public Vector3d PosGlobal; - public int SortOrder; - public bool Enabled; - - public override int Length - { - get - { - int length = 97; - if (Name != null) { length += Name.Length; } - if (Desc != null) { length += Desc.Length; } - return length; - } - } - - public DataBlock() { } - public DataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - PickID.FromBytes(bytes, i); i += 16; - CreatorID.FromBytes(bytes, i); i += 16; - TopPick = (bytes[i++] != 0) ? (bool)true : (bool)false; - ParcelID.FromBytes(bytes, i); i += 16; - length = bytes[i++]; - Name = new byte[length]; - Buffer.BlockCopy(bytes, i, Name, 0, length); i += length; - length = (bytes[i++] + (bytes[i++] << 8)); - Desc = new byte[length]; - Buffer.BlockCopy(bytes, i, Desc, 0, length); i += length; - SnapshotID.FromBytes(bytes, i); i += 16; - PosGlobal.FromBytes(bytes, i); i += 24; - SortOrder = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - Enabled = (bytes[i++] != 0) ? (bool)true : (bool)false; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - PickID.ToBytes(bytes, i); i += 16; - CreatorID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)((TopPick) ? 1 : 0); - ParcelID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)Name.Length; - Buffer.BlockCopy(Name, 0, bytes, i, Name.Length); i += Name.Length; - bytes[i++] = (byte)(Desc.Length % 256); - bytes[i++] = (byte)((Desc.Length >> 8) % 256); - Buffer.BlockCopy(Desc, 0, bytes, i, Desc.Length); i += Desc.Length; - SnapshotID.ToBytes(bytes, i); i += 16; - PosGlobal.ToBytes(bytes, i); i += 24; - Utils.IntToBytes(SortOrder, bytes, i); i += 4; - bytes[i++] = (byte)((Enabled) ? 1 : 0); - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += Data.Length; - return length; - } - } - public AgentDataBlock AgentData; - public DataBlock Data; - - public PickInfoUpdatePacket() - { - HasVariableBlocks = false; - Type = PacketType.PickInfoUpdate; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 185; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - Data = new DataBlock(); - } - - public PickInfoUpdatePacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - Data.FromBytes(bytes, ref i); - } - - public PickInfoUpdatePacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - Data.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += Data.Length; - if (Header.AckList != null && 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); - Data.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class PickDeletePacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class DataBlock : PacketBlock - { - public UUID PickID; - - public override int Length - { - get - { - return 16; - } - } - - public DataBlock() { } - public DataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - PickID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - PickID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += Data.Length; - return length; - } - } - public AgentDataBlock AgentData; - public DataBlock Data; - - public PickDeletePacket() - { - HasVariableBlocks = false; - Type = PacketType.PickDelete; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 186; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - Data = new DataBlock(); - } - - public PickDeletePacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - Data.FromBytes(bytes, ref i); - } - - public PickDeletePacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - Data.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += Data.Length; - if (Header.AckList != null && 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); - Data.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class PickGodDeletePacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class DataBlock : PacketBlock - { - public UUID PickID; - public UUID QueryID; - - public override int Length - { - get - { - return 32; - } - } - - public DataBlock() { } - public DataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - PickID.FromBytes(bytes, i); i += 16; - QueryID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - PickID.ToBytes(bytes, i); i += 16; - QueryID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += Data.Length; - return length; - } - } - public AgentDataBlock AgentData; - public DataBlock Data; - - public PickGodDeletePacket() - { - HasVariableBlocks = false; - Type = PacketType.PickGodDelete; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 187; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - Data = new DataBlock(); - } - - public PickGodDeletePacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - Data.FromBytes(bytes, ref i); - } - - public PickGodDeletePacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - Data.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += Data.Length; - if (Header.AckList != null && 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); - Data.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class ScriptQuestionPacket : Packet - { - /// - public sealed class DataBlock : PacketBlock - { - public UUID TaskID; - public UUID ItemID; - public byte[] ObjectName; - public byte[] ObjectOwner; - public int Questions; - - public override int Length - { - get - { - int length = 38; - if (ObjectName != null) { length += ObjectName.Length; } - if (ObjectOwner != null) { length += ObjectOwner.Length; } - return length; - } - } - - public DataBlock() { } - public DataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - TaskID.FromBytes(bytes, i); i += 16; - ItemID.FromBytes(bytes, i); i += 16; - length = bytes[i++]; - ObjectName = new byte[length]; - Buffer.BlockCopy(bytes, i, ObjectName, 0, length); i += length; - length = bytes[i++]; - ObjectOwner = new byte[length]; - Buffer.BlockCopy(bytes, i, ObjectOwner, 0, length); i += length; - Questions = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - TaskID.ToBytes(bytes, i); i += 16; - ItemID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)ObjectName.Length; - Buffer.BlockCopy(ObjectName, 0, bytes, i, ObjectName.Length); i += ObjectName.Length; - bytes[i++] = (byte)ObjectOwner.Length; - Buffer.BlockCopy(ObjectOwner, 0, bytes, i, ObjectOwner.Length); i += ObjectOwner.Length; - Utils.IntToBytes(Questions, bytes, i); i += 4; - } - - } - - /// - public sealed class ExperienceBlock : PacketBlock - { - public UUID ExperienceID; - - public override int Length - { - get - { - return 16; - } - } - - public ExperienceBlock() { } - public ExperienceBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - ExperienceID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - ExperienceID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 10; - length += Data.Length; - length += Experience.Length; - return length; - } - } - public DataBlock Data; - public ExperienceBlock Experience; - - public ScriptQuestionPacket() - { - HasVariableBlocks = false; - Type = PacketType.ScriptQuestion; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 188; - Header.Reliable = true; - Data = new DataBlock(); - Experience = new ExperienceBlock(); - } - - public ScriptQuestionPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - Data.FromBytes(bytes, ref i); - Experience.FromBytes(bytes, ref i); - } - - public ScriptQuestionPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - Data.FromBytes(bytes, ref i); - Experience.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += Data.Length; - length += Experience.Length; - if (Header.AckList != null && 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); - Experience.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class ScriptControlChangePacket : Packet - { - /// - public sealed class DataBlock : PacketBlock - { - public bool TakeControls; - public uint Controls; - public bool PassToAgent; - - public override int Length - { - get - { - return 6; - } - } - - public DataBlock() { } - public DataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - TakeControls = (bytes[i++] != 0) ? (bool)true : (bool)false; - Controls = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - PassToAgent = (bytes[i++] != 0) ? (bool)true : (bool)false; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - bytes[i++] = (byte)((TakeControls) ? 1 : 0); - Utils.UIntToBytes(Controls, bytes, i); i += 4; - bytes[i++] = (byte)((PassToAgent) ? 1 : 0); - } - - } - - public override int Length - { - get - { - int length = 11; - for (int j = 0; j < Data.Length; j++) - length += Data[j].Length; - return length; - } - } - public DataBlock[] Data; - - public ScriptControlChangePacket() - { - HasVariableBlocks = true; - Type = PacketType.ScriptControlChange; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 189; - Header.Reliable = true; - Data = null; - } - - public ScriptControlChangePacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - int count = (int)bytes[i++]; - if(Data == null || Data.Length != -1) { - Data = new DataBlock[count]; - for(int j = 0; j < count; j++) - { Data[j] = new DataBlock(); } - } - for (int j = 0; j < count; j++) - { Data[j].FromBytes(bytes, ref i); } - } - - public ScriptControlChangePacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - int count = (int)bytes[i++]; - if(Data == null || Data.Length != count) { - Data = new DataBlock[count]; - for(int j = 0; j < count; j++) - { Data[j] = new DataBlock(); } - } - for (int j = 0; j < count; j++) - { Data[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length++; - for (int j = 0; j < Data.Length; j++) { length += Data[j].Length; } - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int DataStart = 0; - do - { - int variableLength = 0; - int DataCount = 0; - - i = DataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < Data.Length) { - int blockLength = Data[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == DataStart) { - variableLength += blockLength; - ++DataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)DataCount; - for (i = DataStart; i < DataStart + DataCount; i++) { Data[i].ToBytes(packet, ref length); } - DataStart += DataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - DataStart < Data.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class ScriptDialogPacket : Packet - { - /// - public sealed class DataBlock : PacketBlock - { - public UUID ObjectID; - public byte[] FirstName; - public byte[] LastName; - public byte[] ObjectName; - public byte[] Message; - public int ChatChannel; - public UUID ImageID; - - public override int Length - { - get - { - int length = 41; - if (FirstName != null) { length += FirstName.Length; } - if (LastName != null) { length += LastName.Length; } - if (ObjectName != null) { length += ObjectName.Length; } - if (Message != null) { length += Message.Length; } - return length; - } - } - - public DataBlock() { } - public DataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - ObjectID.FromBytes(bytes, i); i += 16; - length = bytes[i++]; - FirstName = new byte[length]; - Buffer.BlockCopy(bytes, i, FirstName, 0, length); i += length; - length = bytes[i++]; - LastName = new byte[length]; - Buffer.BlockCopy(bytes, i, LastName, 0, length); i += length; - length = bytes[i++]; - ObjectName = new byte[length]; - Buffer.BlockCopy(bytes, i, ObjectName, 0, length); i += length; - length = (bytes[i++] + (bytes[i++] << 8)); - Message = new byte[length]; - Buffer.BlockCopy(bytes, i, Message, 0, length); i += length; - ChatChannel = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - ImageID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - ObjectID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)FirstName.Length; - Buffer.BlockCopy(FirstName, 0, bytes, i, FirstName.Length); i += FirstName.Length; - bytes[i++] = (byte)LastName.Length; - Buffer.BlockCopy(LastName, 0, bytes, i, LastName.Length); i += LastName.Length; - bytes[i++] = (byte)ObjectName.Length; - Buffer.BlockCopy(ObjectName, 0, bytes, i, ObjectName.Length); i += ObjectName.Length; - bytes[i++] = (byte)(Message.Length % 256); - bytes[i++] = (byte)((Message.Length >> 8) % 256); - Buffer.BlockCopy(Message, 0, bytes, i, Message.Length); i += Message.Length; - Utils.IntToBytes(ChatChannel, bytes, i); i += 4; - ImageID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class ButtonsBlock : PacketBlock - { - public byte[] ButtonLabel; - - public override int Length - { - get - { - int length = 1; - if (ButtonLabel != null) { length += ButtonLabel.Length; } - return length; - } - } - - public ButtonsBlock() { } - public ButtonsBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - length = bytes[i++]; - ButtonLabel = new byte[length]; - Buffer.BlockCopy(bytes, i, ButtonLabel, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - bytes[i++] = (byte)ButtonLabel.Length; - Buffer.BlockCopy(ButtonLabel, 0, bytes, i, ButtonLabel.Length); i += ButtonLabel.Length; - } - - } - - /// - public sealed class OwnerDataBlock : PacketBlock - { - public UUID OwnerID; - - public override int Length - { - get - { - return 16; - } - } - - public OwnerDataBlock() { } - public OwnerDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - OwnerID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - OwnerID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 12; - length += Data.Length; - for (int j = 0; j < Buttons.Length; j++) - length += Buttons[j].Length; - for (int j = 0; j < OwnerData.Length; j++) - length += OwnerData[j].Length; - return length; - } - } - public DataBlock Data; - public ButtonsBlock[] Buttons; - public OwnerDataBlock[] OwnerData; - - public ScriptDialogPacket() - { - HasVariableBlocks = true; - Type = PacketType.ScriptDialog; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 190; - Header.Reliable = true; - Header.Zerocoded = true; - Data = new DataBlock(); - Buttons = null; - OwnerData = null; - } - - public ScriptDialogPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - Data.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(Buttons == null || Buttons.Length != -1) { - Buttons = new ButtonsBlock[count]; - for(int j = 0; j < count; j++) - { Buttons[j] = new ButtonsBlock(); } - } - for (int j = 0; j < count; j++) - { Buttons[j].FromBytes(bytes, ref i); } - count = (int)bytes[i++]; - if(OwnerData == null || OwnerData.Length != -1) { - OwnerData = new OwnerDataBlock[count]; - for(int j = 0; j < count; j++) - { OwnerData[j] = new OwnerDataBlock(); } - } - for (int j = 0; j < count; j++) - { OwnerData[j].FromBytes(bytes, ref i); } - } - - public ScriptDialogPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - Data.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(Buttons == null || Buttons.Length != count) { - Buttons = new ButtonsBlock[count]; - for(int j = 0; j < count; j++) - { Buttons[j] = new ButtonsBlock(); } - } - for (int j = 0; j < count; j++) - { Buttons[j].FromBytes(bytes, ref i); } - count = (int)bytes[i++]; - if(OwnerData == null || OwnerData.Length != count) { - OwnerData = new OwnerDataBlock[count]; - for(int j = 0; j < count; j++) - { OwnerData[j] = new OwnerDataBlock(); } - } - for (int j = 0; j < count; j++) - { OwnerData[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += Data.Length; - length++; - for (int j = 0; j < Buttons.Length; j++) { length += Buttons[j].Length; } - length++; - for (int j = 0; j < OwnerData.Length; j++) { length += OwnerData[j].Length; } - if (Header.AckList != null && 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); } - bytes[i++] = (byte)OwnerData.Length; - for (int j = 0; j < OwnerData.Length; j++) { OwnerData[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += Data.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - Data.ToBytes(fixedBytes, ref i); - fixedLength += 2; - - int ButtonsStart = 0; - int OwnerDataStart = 0; - do - { - int variableLength = 0; - int ButtonsCount = 0; - int OwnerDataCount = 0; - - i = ButtonsStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < Buttons.Length) { - int blockLength = Buttons[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ButtonsStart) { - variableLength += blockLength; - ++ButtonsCount; - } - else { break; } - ++i; - } - - i = OwnerDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < OwnerData.Length) { - int blockLength = OwnerData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == OwnerDataStart) { - variableLength += blockLength; - ++OwnerDataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)ButtonsCount; - for (i = ButtonsStart; i < ButtonsStart + ButtonsCount; i++) { Buttons[i].ToBytes(packet, ref length); } - ButtonsStart += ButtonsCount; - - packet[length++] = (byte)OwnerDataCount; - for (i = OwnerDataStart; i < OwnerDataStart + OwnerDataCount; i++) { OwnerData[i].ToBytes(packet, ref length); } - OwnerDataStart += OwnerDataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - ButtonsStart < Buttons.Length || - OwnerDataStart < OwnerData.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class ScriptDialogReplyPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class DataBlock : PacketBlock - { - public UUID ObjectID; - public int ChatChannel; - public int ButtonIndex; - public byte[] ButtonLabel; - - public override int Length - { - get - { - int length = 25; - if (ButtonLabel != null) { length += ButtonLabel.Length; } - return length; - } - } - - public DataBlock() { } - public DataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - ObjectID.FromBytes(bytes, i); i += 16; - ChatChannel = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - ButtonIndex = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - length = bytes[i++]; - ButtonLabel = new byte[length]; - Buffer.BlockCopy(bytes, i, ButtonLabel, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - ObjectID.ToBytes(bytes, i); i += 16; - Utils.IntToBytes(ChatChannel, bytes, i); i += 4; - Utils.IntToBytes(ButtonIndex, bytes, i); i += 4; - bytes[i++] = (byte)ButtonLabel.Length; - Buffer.BlockCopy(ButtonLabel, 0, bytes, i, ButtonLabel.Length); i += ButtonLabel.Length; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += Data.Length; - return length; - } - } - public AgentDataBlock AgentData; - public DataBlock Data; - - public ScriptDialogReplyPacket() - { - HasVariableBlocks = false; - Type = PacketType.ScriptDialogReply; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 191; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - Data = new DataBlock(); - } - - public ScriptDialogReplyPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - Data.FromBytes(bytes, ref i); - } - - public ScriptDialogReplyPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - Data.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += Data.Length; - if (Header.AckList != null && 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); - Data.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class ForceScriptControlReleasePacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - return length; - } - } - public AgentDataBlock AgentData; - - public ForceScriptControlReleasePacket() - { - HasVariableBlocks = false; - Type = PacketType.ForceScriptControlRelease; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 192; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - } - - public ForceScriptControlReleasePacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - } - - public ForceScriptControlReleasePacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class RevokePermissionsPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class DataBlock : PacketBlock - { - public UUID ObjectID; - public uint ObjectPermissions; - - public override int Length - { - get - { - return 20; - } - } - - public DataBlock() { } - public DataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - ObjectID.FromBytes(bytes, i); i += 16; - ObjectPermissions = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - ObjectID.ToBytes(bytes, i); i += 16; - Utils.UIntToBytes(ObjectPermissions, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += Data.Length; - return length; - } - } - public AgentDataBlock AgentData; - public DataBlock Data; - - public RevokePermissionsPacket() - { - HasVariableBlocks = false; - Type = PacketType.RevokePermissions; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 193; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - Data = new DataBlock(); - } - - public RevokePermissionsPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - Data.FromBytes(bytes, ref i); - } - - public RevokePermissionsPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - Data.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += Data.Length; - if (Header.AckList != null && 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); - Data.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class LoadURLPacket : Packet - { - /// - public sealed class DataBlock : PacketBlock - { - public byte[] ObjectName; - public UUID ObjectID; - public UUID OwnerID; - public bool OwnerIsGroup; - public byte[] Message; - public byte[] URL; - - public override int Length - { - get - { - int length = 36; - if (ObjectName != null) { length += ObjectName.Length; } - if (Message != null) { length += Message.Length; } - if (URL != null) { length += URL.Length; } - return length; - } - } - - public DataBlock() { } - public DataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - length = bytes[i++]; - ObjectName = new byte[length]; - Buffer.BlockCopy(bytes, i, ObjectName, 0, length); i += length; - ObjectID.FromBytes(bytes, i); i += 16; - OwnerID.FromBytes(bytes, i); i += 16; - OwnerIsGroup = (bytes[i++] != 0) ? (bool)true : (bool)false; - length = bytes[i++]; - Message = new byte[length]; - Buffer.BlockCopy(bytes, i, Message, 0, length); i += length; - length = bytes[i++]; - URL = new byte[length]; - Buffer.BlockCopy(bytes, i, URL, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - bytes[i++] = (byte)ObjectName.Length; - Buffer.BlockCopy(ObjectName, 0, bytes, i, ObjectName.Length); i += ObjectName.Length; - ObjectID.ToBytes(bytes, i); i += 16; - OwnerID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)((OwnerIsGroup) ? 1 : 0); - bytes[i++] = (byte)Message.Length; - Buffer.BlockCopy(Message, 0, bytes, i, Message.Length); i += Message.Length; - bytes[i++] = (byte)URL.Length; - Buffer.BlockCopy(URL, 0, bytes, i, URL.Length); i += URL.Length; - } - - } - - public override int Length - { - get - { - int length = 10; - length += Data.Length; - return length; - } - } - public DataBlock Data; - - public LoadURLPacket() - { - HasVariableBlocks = false; - Type = PacketType.LoadURL; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 194; - Header.Reliable = true; - Data = new DataBlock(); - } - - public LoadURLPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - Data.FromBytes(bytes, ref i); - } - - public LoadURLPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - Data.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += Data.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class ScriptTeleportRequestPacket : Packet - { - /// - public sealed class DataBlock : PacketBlock - { - public byte[] ObjectName; - public byte[] SimName; - public Vector3 SimPosition; - public Vector3 LookAt; - - public override int Length - { - get - { - int length = 26; - if (ObjectName != null) { length += ObjectName.Length; } - if (SimName != null) { length += SimName.Length; } - return length; - } - } - - public DataBlock() { } - public DataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - length = bytes[i++]; - ObjectName = new byte[length]; - Buffer.BlockCopy(bytes, i, ObjectName, 0, length); i += length; - length = bytes[i++]; - SimName = new byte[length]; - Buffer.BlockCopy(bytes, i, SimName, 0, length); i += length; - SimPosition.FromBytes(bytes, i); i += 12; - LookAt.FromBytes(bytes, i); i += 12; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - bytes[i++] = (byte)ObjectName.Length; - Buffer.BlockCopy(ObjectName, 0, bytes, i, ObjectName.Length); i += ObjectName.Length; - bytes[i++] = (byte)SimName.Length; - Buffer.BlockCopy(SimName, 0, bytes, i, SimName.Length); i += SimName.Length; - SimPosition.ToBytes(bytes, i); i += 12; - LookAt.ToBytes(bytes, i); i += 12; - } - - } - - public override int Length - { - get - { - int length = 10; - length += Data.Length; - return length; - } - } - public DataBlock Data; - - public ScriptTeleportRequestPacket() - { - HasVariableBlocks = false; - Type = PacketType.ScriptTeleportRequest; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 195; - Header.Reliable = true; - Data = new DataBlock(); - } - - public ScriptTeleportRequestPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - Data.FromBytes(bytes, ref i); - } - - public ScriptTeleportRequestPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - Data.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += Data.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class ParcelOverlayPacket : Packet - { - /// - public sealed class ParcelDataBlock : PacketBlock - { - public int SequenceID; - public byte[] Data; - - public override int Length - { - get - { - int length = 6; - if (Data != null) { length += Data.Length; } - return length; - } - } - - public ParcelDataBlock() { } - public ParcelDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - SequenceID = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - length = (bytes[i++] + (bytes[i++] << 8)); - Data = new byte[length]; - Buffer.BlockCopy(bytes, i, Data, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.IntToBytes(SequenceID, bytes, i); i += 4; - bytes[i++] = (byte)(Data.Length % 256); - bytes[i++] = (byte)((Data.Length >> 8) % 256); - Buffer.BlockCopy(Data, 0, bytes, i, Data.Length); i += Data.Length; - } - - } - - public override int Length - { - get - { - int length = 10; - length += ParcelData.Length; - return length; - } - } - public ParcelDataBlock ParcelData; - - public ParcelOverlayPacket() - { - HasVariableBlocks = false; - Type = PacketType.ParcelOverlay; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 196; - Header.Reliable = true; - Header.Zerocoded = true; - ParcelData = new ParcelDataBlock(); - } - - public ParcelOverlayPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - ParcelData.FromBytes(bytes, ref i); - } - - public ParcelOverlayPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - ParcelData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += ParcelData.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class ParcelPropertiesRequestByIDPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class ParcelDataBlock : PacketBlock - { - public int SequenceID; - public int LocalID; - - public override int Length - { - get - { - return 8; - } - } - - public ParcelDataBlock() { } - public ParcelDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - SequenceID = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - LocalID = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.IntToBytes(SequenceID, bytes, i); i += 4; - Utils.IntToBytes(LocalID, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += ParcelData.Length; - return length; - } - } - public AgentDataBlock AgentData; - public ParcelDataBlock ParcelData; - - public ParcelPropertiesRequestByIDPacket() - { - HasVariableBlocks = false; - Type = PacketType.ParcelPropertiesRequestByID; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 197; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - ParcelData = new ParcelDataBlock(); - } - - public ParcelPropertiesRequestByIDPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - ParcelData.FromBytes(bytes, ref i); - } - - public ParcelPropertiesRequestByIDPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - ParcelData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += ParcelData.Length; - if (Header.AckList != null && 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); - ParcelData.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class ParcelPropertiesUpdatePacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class ParcelDataBlock : PacketBlock - { - public int LocalID; - public uint Flags; - public uint ParcelFlags; - public int SalePrice; - public byte[] Name; - public byte[] Desc; - public byte[] MusicURL; - public byte[] MediaURL; - public UUID MediaID; - public byte MediaAutoScale; - public UUID GroupID; - public int PassPrice; - public float PassHours; - public byte Category; - public UUID AuthBuyerID; - public UUID SnapshotID; - public Vector3 UserLocation; - public Vector3 UserLookAt; - public byte LandingType; - - public override int Length - { - get - { - int length = 119; - if (Name != null) { length += Name.Length; } - if (Desc != null) { length += Desc.Length; } - if (MusicURL != null) { length += MusicURL.Length; } - if (MediaURL != null) { length += MediaURL.Length; } - return length; - } - } - - public ParcelDataBlock() { } - public ParcelDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - LocalID = (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)); - ParcelFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - SalePrice = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - length = bytes[i++]; - Name = new byte[length]; - Buffer.BlockCopy(bytes, i, Name, 0, length); i += length; - length = bytes[i++]; - Desc = new byte[length]; - Buffer.BlockCopy(bytes, i, Desc, 0, length); i += length; - length = bytes[i++]; - MusicURL = new byte[length]; - Buffer.BlockCopy(bytes, i, MusicURL, 0, length); i += length; - length = bytes[i++]; - MediaURL = new byte[length]; - Buffer.BlockCopy(bytes, i, MediaURL, 0, length); i += length; - MediaID.FromBytes(bytes, i); i += 16; - MediaAutoScale = (byte)bytes[i++]; - GroupID.FromBytes(bytes, i); i += 16; - PassPrice = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - PassHours = Utils.BytesToFloat(bytes, i); i += 4; - Category = (byte)bytes[i++]; - AuthBuyerID.FromBytes(bytes, i); i += 16; - SnapshotID.FromBytes(bytes, i); i += 16; - UserLocation.FromBytes(bytes, i); i += 12; - UserLookAt.FromBytes(bytes, i); i += 12; - LandingType = (byte)bytes[i++]; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.IntToBytes(LocalID, bytes, i); i += 4; - Utils.UIntToBytes(Flags, bytes, i); i += 4; - Utils.UIntToBytes(ParcelFlags, bytes, i); i += 4; - Utils.IntToBytes(SalePrice, bytes, i); i += 4; - bytes[i++] = (byte)Name.Length; - Buffer.BlockCopy(Name, 0, bytes, i, Name.Length); i += Name.Length; - bytes[i++] = (byte)Desc.Length; - Buffer.BlockCopy(Desc, 0, bytes, i, Desc.Length); i += Desc.Length; - bytes[i++] = (byte)MusicURL.Length; - Buffer.BlockCopy(MusicURL, 0, bytes, i, MusicURL.Length); i += MusicURL.Length; - bytes[i++] = (byte)MediaURL.Length; - Buffer.BlockCopy(MediaURL, 0, bytes, i, MediaURL.Length); i += MediaURL.Length; - MediaID.ToBytes(bytes, i); i += 16; - bytes[i++] = MediaAutoScale; - GroupID.ToBytes(bytes, i); i += 16; - Utils.IntToBytes(PassPrice, bytes, i); i += 4; - Utils.FloatToBytes(PassHours, bytes, i); i += 4; - bytes[i++] = Category; - AuthBuyerID.ToBytes(bytes, i); i += 16; - SnapshotID.ToBytes(bytes, i); i += 16; - UserLocation.ToBytes(bytes, i); i += 12; - UserLookAt.ToBytes(bytes, i); i += 12; - bytes[i++] = LandingType; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += ParcelData.Length; - return length; - } - } - public AgentDataBlock AgentData; - public ParcelDataBlock ParcelData; - - public ParcelPropertiesUpdatePacket() - { - HasVariableBlocks = false; - Type = PacketType.ParcelPropertiesUpdate; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 198; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - ParcelData = new ParcelDataBlock(); - } - - public ParcelPropertiesUpdatePacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - ParcelData.FromBytes(bytes, ref i); - } - - public ParcelPropertiesUpdatePacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - ParcelData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += ParcelData.Length; - if (Header.AckList != null && 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); - ParcelData.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class ParcelReturnObjectsPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class ParcelDataBlock : PacketBlock - { - public int LocalID; - public uint ReturnType; - - public override int Length - { - get - { - return 8; - } - } - - public ParcelDataBlock() { } - public ParcelDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(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(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.IntToBytes(LocalID, bytes, i); i += 4; - Utils.UIntToBytes(ReturnType, bytes, i); i += 4; - } - - } - - /// - public sealed class TaskIDsBlock : PacketBlock - { - public UUID TaskID; - - public override int Length - { - get - { - return 16; - } - } - - public TaskIDsBlock() { } - public TaskIDsBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - TaskID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - TaskID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class OwnerIDsBlock : PacketBlock - { - public UUID OwnerID; - - public override int Length - { - get - { - return 16; - } - } - - public OwnerIDsBlock() { } - public OwnerIDsBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - OwnerID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - OwnerID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 12; - length += AgentData.Length; - length += ParcelData.Length; - for (int j = 0; j < TaskIDs.Length; j++) - length += TaskIDs[j].Length; - for (int j = 0; j < OwnerIDs.Length; j++) - length += OwnerIDs[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public ParcelDataBlock ParcelData; - public TaskIDsBlock[] TaskIDs; - public OwnerIDsBlock[] OwnerIDs; - - public ParcelReturnObjectsPacket() - { - HasVariableBlocks = true; - Type = PacketType.ParcelReturnObjects; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 199; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - ParcelData = new ParcelDataBlock(); - TaskIDs = null; - OwnerIDs = null; - } - - public ParcelReturnObjectsPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - ParcelData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(TaskIDs == null || TaskIDs.Length != -1) { - TaskIDs = new TaskIDsBlock[count]; - for(int j = 0; j < count; j++) - { TaskIDs[j] = new TaskIDsBlock(); } - } - for (int j = 0; j < count; j++) - { TaskIDs[j].FromBytes(bytes, ref i); } - count = (int)bytes[i++]; - if(OwnerIDs == null || OwnerIDs.Length != -1) { - OwnerIDs = new OwnerIDsBlock[count]; - for(int j = 0; j < count; j++) - { OwnerIDs[j] = new OwnerIDsBlock(); } - } - for (int j = 0; j < count; j++) - { OwnerIDs[j].FromBytes(bytes, ref i); } - } - - public ParcelReturnObjectsPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - ParcelData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(TaskIDs == null || TaskIDs.Length != count) { - TaskIDs = new TaskIDsBlock[count]; - for(int j = 0; j < count; j++) - { TaskIDs[j] = new TaskIDsBlock(); } - } - for (int j = 0; j < count; j++) - { TaskIDs[j].FromBytes(bytes, ref i); } - count = (int)bytes[i++]; - if(OwnerIDs == null || OwnerIDs.Length != count) { - OwnerIDs = new OwnerIDsBlock[count]; - for(int j = 0; j < count; j++) - { OwnerIDs[j] = new OwnerIDsBlock(); } - } - for (int j = 0; j < count; j++) - { OwnerIDs[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += ParcelData.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 != null && 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); - ParcelData.ToBytes(bytes, ref i); - bytes[i++] = (byte)TaskIDs.Length; - for (int j = 0; j < TaskIDs.Length; j++) { TaskIDs[j].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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - fixedLength += ParcelData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - ParcelData.ToBytes(fixedBytes, ref i); - fixedLength += 2; - - int TaskIDsStart = 0; - int OwnerIDsStart = 0; - do - { - int variableLength = 0; - int TaskIDsCount = 0; - int OwnerIDsCount = 0; - - i = TaskIDsStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < TaskIDs.Length) { - int blockLength = TaskIDs[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == TaskIDsStart) { - variableLength += blockLength; - ++TaskIDsCount; - } - else { break; } - ++i; - } - - i = OwnerIDsStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < OwnerIDs.Length) { - int blockLength = OwnerIDs[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == OwnerIDsStart) { - variableLength += blockLength; - ++OwnerIDsCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)TaskIDsCount; - for (i = TaskIDsStart; i < TaskIDsStart + TaskIDsCount; i++) { TaskIDs[i].ToBytes(packet, ref length); } - TaskIDsStart += TaskIDsCount; - - packet[length++] = (byte)OwnerIDsCount; - for (i = OwnerIDsStart; i < OwnerIDsStart + OwnerIDsCount; i++) { OwnerIDs[i].ToBytes(packet, ref length); } - OwnerIDsStart += OwnerIDsCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - TaskIDsStart < TaskIDs.Length || - OwnerIDsStart < OwnerIDs.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class ParcelSetOtherCleanTimePacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class ParcelDataBlock : PacketBlock - { - public int LocalID; - public int OtherCleanTime; - - public override int Length - { - get - { - return 8; - } - } - - public ParcelDataBlock() { } - public ParcelDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(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(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.IntToBytes(LocalID, bytes, i); i += 4; - Utils.IntToBytes(OtherCleanTime, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += ParcelData.Length; - return length; - } - } - public AgentDataBlock AgentData; - public ParcelDataBlock ParcelData; - - public ParcelSetOtherCleanTimePacket() - { - HasVariableBlocks = false; - Type = PacketType.ParcelSetOtherCleanTime; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 200; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - ParcelData = new ParcelDataBlock(); - } - - public ParcelSetOtherCleanTimePacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - ParcelData.FromBytes(bytes, ref i); - } - - public ParcelSetOtherCleanTimePacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - ParcelData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += ParcelData.Length; - if (Header.AckList != null && 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); - ParcelData.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class ParcelDisableObjectsPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class ParcelDataBlock : PacketBlock - { - public int LocalID; - public uint ReturnType; - - public override int Length - { - get - { - return 8; - } - } - - public ParcelDataBlock() { } - public ParcelDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(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(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.IntToBytes(LocalID, bytes, i); i += 4; - Utils.UIntToBytes(ReturnType, bytes, i); i += 4; - } - - } - - /// - public sealed class TaskIDsBlock : PacketBlock - { - public UUID TaskID; - - public override int Length - { - get - { - return 16; - } - } - - public TaskIDsBlock() { } - public TaskIDsBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - TaskID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - TaskID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class OwnerIDsBlock : PacketBlock - { - public UUID OwnerID; - - public override int Length - { - get - { - return 16; - } - } - - public OwnerIDsBlock() { } - public OwnerIDsBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - OwnerID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - OwnerID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 12; - length += AgentData.Length; - length += ParcelData.Length; - for (int j = 0; j < TaskIDs.Length; j++) - length += TaskIDs[j].Length; - for (int j = 0; j < OwnerIDs.Length; j++) - length += OwnerIDs[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public ParcelDataBlock ParcelData; - public TaskIDsBlock[] TaskIDs; - public OwnerIDsBlock[] OwnerIDs; - - public ParcelDisableObjectsPacket() - { - HasVariableBlocks = true; - Type = PacketType.ParcelDisableObjects; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 201; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - ParcelData = new ParcelDataBlock(); - TaskIDs = null; - OwnerIDs = null; - } - - public ParcelDisableObjectsPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - ParcelData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(TaskIDs == null || TaskIDs.Length != -1) { - TaskIDs = new TaskIDsBlock[count]; - for(int j = 0; j < count; j++) - { TaskIDs[j] = new TaskIDsBlock(); } - } - for (int j = 0; j < count; j++) - { TaskIDs[j].FromBytes(bytes, ref i); } - count = (int)bytes[i++]; - if(OwnerIDs == null || OwnerIDs.Length != -1) { - OwnerIDs = new OwnerIDsBlock[count]; - for(int j = 0; j < count; j++) - { OwnerIDs[j] = new OwnerIDsBlock(); } - } - for (int j = 0; j < count; j++) - { OwnerIDs[j].FromBytes(bytes, ref i); } - } - - public ParcelDisableObjectsPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - ParcelData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(TaskIDs == null || TaskIDs.Length != count) { - TaskIDs = new TaskIDsBlock[count]; - for(int j = 0; j < count; j++) - { TaskIDs[j] = new TaskIDsBlock(); } - } - for (int j = 0; j < count; j++) - { TaskIDs[j].FromBytes(bytes, ref i); } - count = (int)bytes[i++]; - if(OwnerIDs == null || OwnerIDs.Length != count) { - OwnerIDs = new OwnerIDsBlock[count]; - for(int j = 0; j < count; j++) - { OwnerIDs[j] = new OwnerIDsBlock(); } - } - for (int j = 0; j < count; j++) - { OwnerIDs[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += ParcelData.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 != null && 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); - ParcelData.ToBytes(bytes, ref i); - bytes[i++] = (byte)TaskIDs.Length; - for (int j = 0; j < TaskIDs.Length; j++) { TaskIDs[j].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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - fixedLength += ParcelData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - ParcelData.ToBytes(fixedBytes, ref i); - fixedLength += 2; - - int TaskIDsStart = 0; - int OwnerIDsStart = 0; - do - { - int variableLength = 0; - int TaskIDsCount = 0; - int OwnerIDsCount = 0; - - i = TaskIDsStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < TaskIDs.Length) { - int blockLength = TaskIDs[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == TaskIDsStart) { - variableLength += blockLength; - ++TaskIDsCount; - } - else { break; } - ++i; - } - - i = OwnerIDsStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < OwnerIDs.Length) { - int blockLength = OwnerIDs[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == OwnerIDsStart) { - variableLength += blockLength; - ++OwnerIDsCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)TaskIDsCount; - for (i = TaskIDsStart; i < TaskIDsStart + TaskIDsCount; i++) { TaskIDs[i].ToBytes(packet, ref length); } - TaskIDsStart += TaskIDsCount; - - packet[length++] = (byte)OwnerIDsCount; - for (i = OwnerIDsStart; i < OwnerIDsStart + OwnerIDsCount; i++) { OwnerIDs[i].ToBytes(packet, ref length); } - OwnerIDsStart += OwnerIDsCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - TaskIDsStart < TaskIDs.Length || - OwnerIDsStart < OwnerIDs.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class ParcelSelectObjectsPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class ParcelDataBlock : PacketBlock - { - public int LocalID; - public uint ReturnType; - - public override int Length - { - get - { - return 8; - } - } - - public ParcelDataBlock() { } - public ParcelDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(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(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.IntToBytes(LocalID, bytes, i); i += 4; - Utils.UIntToBytes(ReturnType, bytes, i); i += 4; - } - - } - - /// - public sealed class ReturnIDsBlock : PacketBlock - { - public UUID ReturnID; - - public override int Length - { - get - { - return 16; - } - } - - public ReturnIDsBlock() { } - public ReturnIDsBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - ReturnID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - ReturnID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentData.Length; - length += ParcelData.Length; - for (int j = 0; j < ReturnIDs.Length; j++) - length += ReturnIDs[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public ParcelDataBlock ParcelData; - public ReturnIDsBlock[] ReturnIDs; - - public ParcelSelectObjectsPacket() - { - HasVariableBlocks = true; - Type = PacketType.ParcelSelectObjects; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 202; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - ParcelData = new ParcelDataBlock(); - ReturnIDs = null; - } - - public ParcelSelectObjectsPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - ParcelData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ReturnIDs == null || ReturnIDs.Length != -1) { - ReturnIDs = new ReturnIDsBlock[count]; - for(int j = 0; j < count; j++) - { ReturnIDs[j] = new ReturnIDsBlock(); } - } - for (int j = 0; j < count; j++) - { ReturnIDs[j].FromBytes(bytes, ref i); } - } - - public ParcelSelectObjectsPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - ParcelData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ReturnIDs == null || ReturnIDs.Length != count) { - ReturnIDs = new ReturnIDsBlock[count]; - for(int j = 0; j < count; j++) - { ReturnIDs[j] = new ReturnIDsBlock(); } - } - for (int j = 0; j < count; j++) - { ReturnIDs[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += ParcelData.Length; - length++; - for (int j = 0; j < ReturnIDs.Length; j++) { length += ReturnIDs[j].Length; } - if (Header.AckList != null && 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); - ParcelData.ToBytes(bytes, ref i); - bytes[i++] = (byte)ReturnIDs.Length; - for (int j = 0; j < ReturnIDs.Length; j++) { ReturnIDs[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - fixedLength += ParcelData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - ParcelData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int ReturnIDsStart = 0; - do - { - int variableLength = 0; - int ReturnIDsCount = 0; - - i = ReturnIDsStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < ReturnIDs.Length) { - int blockLength = ReturnIDs[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ReturnIDsStart) { - variableLength += blockLength; - ++ReturnIDsCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)ReturnIDsCount; - for (i = ReturnIDsStart; i < ReturnIDsStart + ReturnIDsCount; i++) { ReturnIDs[i].ToBytes(packet, ref length); } - ReturnIDsStart += ReturnIDsCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - ReturnIDsStart < ReturnIDs.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class EstateCovenantRequestPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - return length; - } - } - public AgentDataBlock AgentData; - - public EstateCovenantRequestPacket() - { - HasVariableBlocks = false; - Type = PacketType.EstateCovenantRequest; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 203; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - } - - public EstateCovenantRequestPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - } - - public EstateCovenantRequestPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class EstateCovenantReplyPacket : Packet - { - /// - public sealed class DataBlock : PacketBlock - { - public UUID CovenantID; - public uint CovenantTimestamp; - public byte[] EstateName; - public UUID EstateOwnerID; - - public override int Length - { - get - { - int length = 37; - if (EstateName != null) { length += EstateName.Length; } - return length; - } - } - - public DataBlock() { } - public DataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - CovenantID.FromBytes(bytes, i); i += 16; - CovenantTimestamp = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - length = bytes[i++]; - EstateName = new byte[length]; - Buffer.BlockCopy(bytes, i, EstateName, 0, length); i += length; - EstateOwnerID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - CovenantID.ToBytes(bytes, i); i += 16; - Utils.UIntToBytes(CovenantTimestamp, bytes, i); i += 4; - bytes[i++] = (byte)EstateName.Length; - Buffer.BlockCopy(EstateName, 0, bytes, i, EstateName.Length); i += EstateName.Length; - EstateOwnerID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 10; - length += Data.Length; - return length; - } - } - public DataBlock Data; - - public EstateCovenantReplyPacket() - { - HasVariableBlocks = false; - Type = PacketType.EstateCovenantReply; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 204; - Header.Reliable = true; - Data = new DataBlock(); - } - - public EstateCovenantReplyPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - Data.FromBytes(bytes, ref i); - } - - public EstateCovenantReplyPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - Data.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += Data.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class ForceObjectSelectPacket : Packet - { - /// - public sealed class HeaderBlock : PacketBlock - { - public bool ResetList; - - public override int Length - { - get - { - return 1; - } - } - - public HeaderBlock() { } - public HeaderBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - ResetList = (bytes[i++] != 0) ? (bool)true : (bool)false; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - bytes[i++] = (byte)((ResetList) ? 1 : 0); - } - - } - - /// - public sealed class DataBlock : PacketBlock - { - public uint LocalID; - - public override int Length - { - get - { - return 4; - } - } - - public DataBlock() { } - public DataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - LocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UIntToBytes(LocalID, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 11; - length += _Header.Length; - for (int j = 0; j < Data.Length; j++) - length += Data[j].Length; - return length; - } - } - public HeaderBlock _Header; - public DataBlock[] Data; - - public ForceObjectSelectPacket() - { - HasVariableBlocks = true; - Type = PacketType.ForceObjectSelect; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 205; - Header.Reliable = true; - _Header = new HeaderBlock(); - Data = null; - } - - public ForceObjectSelectPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - _Header.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(Data == null || Data.Length != -1) { - Data = new DataBlock[count]; - for(int j = 0; j < count; j++) - { Data[j] = new DataBlock(); } - } - for (int j = 0; j < count; j++) - { Data[j].FromBytes(bytes, ref i); } - } - - public ForceObjectSelectPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - _Header.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(Data == null || Data.Length != count) { - Data = new DataBlock[count]; - for(int j = 0; j < count; j++) - { Data[j] = new DataBlock(); } - } - for (int j = 0; j < count; j++) - { Data[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += _Header.Length; - length++; - for (int j = 0; j < Data.Length; j++) { length += Data[j].Length; } - if (Header.AckList != null && Header.AckList.Length > 0) { length += Header.AckList.Length * 4 + 1; } - byte[] bytes = new byte[length]; - int i = 0; - Header.ToBytes(bytes, ref i); - _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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += _Header.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - _Header.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int DataStart = 0; - do - { - int variableLength = 0; - int DataCount = 0; - - i = DataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < Data.Length) { - int blockLength = Data[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == DataStart) { - variableLength += blockLength; - ++DataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)DataCount; - for (i = DataStart; i < DataStart + DataCount; i++) { Data[i].ToBytes(packet, ref length); } - DataStart += DataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - DataStart < Data.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class ParcelBuyPassPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class ParcelDataBlock : PacketBlock - { - public int LocalID; - - public override int Length - { - get - { - return 4; - } - } - - public ParcelDataBlock() { } - public ParcelDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - LocalID = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.IntToBytes(LocalID, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += ParcelData.Length; - return length; - } - } - public AgentDataBlock AgentData; - public ParcelDataBlock ParcelData; - - public ParcelBuyPassPacket() - { - HasVariableBlocks = false; - Type = PacketType.ParcelBuyPass; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 206; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - ParcelData = new ParcelDataBlock(); - } - - public ParcelBuyPassPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - ParcelData.FromBytes(bytes, ref i); - } - - public ParcelBuyPassPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - ParcelData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += ParcelData.Length; - if (Header.AckList != null && 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); - ParcelData.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class ParcelDeedToGroupPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class DataBlock : PacketBlock - { - public UUID GroupID; - public int LocalID; - - public override int Length - { - get - { - return 20; - } - } - - public DataBlock() { } - public DataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - GroupID.FromBytes(bytes, i); i += 16; - LocalID = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - GroupID.ToBytes(bytes, i); i += 16; - Utils.IntToBytes(LocalID, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += Data.Length; - return length; - } - } - public AgentDataBlock AgentData; - public DataBlock Data; - - public ParcelDeedToGroupPacket() - { - HasVariableBlocks = false; - Type = PacketType.ParcelDeedToGroup; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 207; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - Data = new DataBlock(); - } - - public ParcelDeedToGroupPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - Data.FromBytes(bytes, ref i); - } - - public ParcelDeedToGroupPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - Data.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += Data.Length; - if (Header.AckList != null && 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); - Data.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class ParcelReclaimPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class DataBlock : PacketBlock - { - public int LocalID; - - public override int Length - { - get - { - return 4; - } - } - - public DataBlock() { } - public DataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - LocalID = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.IntToBytes(LocalID, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += Data.Length; - return length; - } - } - public AgentDataBlock AgentData; - public DataBlock Data; - - public ParcelReclaimPacket() - { - HasVariableBlocks = false; - Type = PacketType.ParcelReclaim; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 208; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - Data = new DataBlock(); - } - - public ParcelReclaimPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - Data.FromBytes(bytes, ref i); - } - - public ParcelReclaimPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - Data.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += Data.Length; - if (Header.AckList != null && 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); - Data.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class ParcelClaimPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class DataBlock : PacketBlock - { - public UUID GroupID; - public bool IsGroupOwned; - public bool Final; - - public override int Length - { - get - { - return 18; - } - } - - public DataBlock() { } - public DataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - GroupID.FromBytes(bytes, i); i += 16; - IsGroupOwned = (bytes[i++] != 0) ? (bool)true : (bool)false; - Final = (bytes[i++] != 0) ? (bool)true : (bool)false; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - GroupID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)((IsGroupOwned) ? 1 : 0); - bytes[i++] = (byte)((Final) ? 1 : 0); - } - - } - - /// - public sealed class ParcelDataBlock : PacketBlock - { - public float West; - public float South; - public float East; - public float North; - - public override int Length - { - get - { - return 16; - } - } - - public ParcelDataBlock() { } - public ParcelDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - West = Utils.BytesToFloat(bytes, i); i += 4; - South = Utils.BytesToFloat(bytes, i); i += 4; - East = Utils.BytesToFloat(bytes, i); i += 4; - North = Utils.BytesToFloat(bytes, i); i += 4; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.FloatToBytes(West, bytes, i); i += 4; - Utils.FloatToBytes(South, bytes, i); i += 4; - Utils.FloatToBytes(East, bytes, i); i += 4; - Utils.FloatToBytes(North, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentData.Length; - length += Data.Length; - for (int j = 0; j < ParcelData.Length; j++) - length += ParcelData[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public DataBlock Data; - public ParcelDataBlock[] ParcelData; - - public ParcelClaimPacket() - { - HasVariableBlocks = true; - Type = PacketType.ParcelClaim; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 209; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - Data = new DataBlock(); - ParcelData = null; - } - - public ParcelClaimPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - Data.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ParcelData == null || ParcelData.Length != -1) { - ParcelData = new ParcelDataBlock[count]; - for(int j = 0; j < count; j++) - { ParcelData[j] = new ParcelDataBlock(); } - } - for (int j = 0; j < count; j++) - { ParcelData[j].FromBytes(bytes, ref i); } - } - - public ParcelClaimPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - Data.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ParcelData == null || ParcelData.Length != count) { - ParcelData = new ParcelDataBlock[count]; - for(int j = 0; j < count; j++) - { ParcelData[j] = new ParcelDataBlock(); } - } - for (int j = 0; j < count; j++) - { ParcelData[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += Data.Length; - length++; - for (int j = 0; j < ParcelData.Length; j++) { length += ParcelData[j].Length; } - if (Header.AckList != null && 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); - Data.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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - fixedLength += Data.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - Data.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int ParcelDataStart = 0; - do - { - int variableLength = 0; - int ParcelDataCount = 0; - - i = ParcelDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < ParcelData.Length) { - int blockLength = ParcelData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ParcelDataStart) { - variableLength += blockLength; - ++ParcelDataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)ParcelDataCount; - for (i = ParcelDataStart; i < ParcelDataStart + ParcelDataCount; i++) { ParcelData[i].ToBytes(packet, ref length); } - ParcelDataStart += ParcelDataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - ParcelDataStart < ParcelData.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class ParcelJoinPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class ParcelDataBlock : PacketBlock - { - public float West; - public float South; - public float East; - public float North; - - public override int Length - { - get - { - return 16; - } - } - - public ParcelDataBlock() { } - public ParcelDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - West = Utils.BytesToFloat(bytes, i); i += 4; - South = Utils.BytesToFloat(bytes, i); i += 4; - East = Utils.BytesToFloat(bytes, i); i += 4; - North = Utils.BytesToFloat(bytes, i); i += 4; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.FloatToBytes(West, bytes, i); i += 4; - Utils.FloatToBytes(South, bytes, i); i += 4; - Utils.FloatToBytes(East, bytes, i); i += 4; - Utils.FloatToBytes(North, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += ParcelData.Length; - return length; - } - } - public AgentDataBlock AgentData; - public ParcelDataBlock ParcelData; - - public ParcelJoinPacket() - { - HasVariableBlocks = false; - Type = PacketType.ParcelJoin; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 210; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - ParcelData = new ParcelDataBlock(); - } - - public ParcelJoinPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - ParcelData.FromBytes(bytes, ref i); - } - - public ParcelJoinPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - ParcelData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += ParcelData.Length; - if (Header.AckList != null && 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); - ParcelData.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class ParcelDividePacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class ParcelDataBlock : PacketBlock - { - public float West; - public float South; - public float East; - public float North; - - public override int Length - { - get - { - return 16; - } - } - - public ParcelDataBlock() { } - public ParcelDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - West = Utils.BytesToFloat(bytes, i); i += 4; - South = Utils.BytesToFloat(bytes, i); i += 4; - East = Utils.BytesToFloat(bytes, i); i += 4; - North = Utils.BytesToFloat(bytes, i); i += 4; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.FloatToBytes(West, bytes, i); i += 4; - Utils.FloatToBytes(South, bytes, i); i += 4; - Utils.FloatToBytes(East, bytes, i); i += 4; - Utils.FloatToBytes(North, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += ParcelData.Length; - return length; - } - } - public AgentDataBlock AgentData; - public ParcelDataBlock ParcelData; - - public ParcelDividePacket() - { - HasVariableBlocks = false; - Type = PacketType.ParcelDivide; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 211; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - ParcelData = new ParcelDataBlock(); - } - - public ParcelDividePacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - ParcelData.FromBytes(bytes, ref i); - } - - public ParcelDividePacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - ParcelData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += ParcelData.Length; - if (Header.AckList != null && 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); - ParcelData.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class ParcelReleasePacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class DataBlock : PacketBlock - { - public int LocalID; - - public override int Length - { - get - { - return 4; - } - } - - public DataBlock() { } - public DataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - LocalID = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.IntToBytes(LocalID, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += Data.Length; - return length; - } - } - public AgentDataBlock AgentData; - public DataBlock Data; - - public ParcelReleasePacket() - { - HasVariableBlocks = false; - Type = PacketType.ParcelRelease; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 212; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - Data = new DataBlock(); - } - - public ParcelReleasePacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - Data.FromBytes(bytes, ref i); - } - - public ParcelReleasePacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - Data.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += Data.Length; - if (Header.AckList != null && 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); - Data.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class ParcelBuyPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class DataBlock : PacketBlock - { - public UUID GroupID; - public bool IsGroupOwned; - public bool RemoveContribution; - public int LocalID; - public bool Final; - - public override int Length - { - get - { - return 23; - } - } - - public DataBlock() { } - public DataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - GroupID.FromBytes(bytes, i); i += 16; - IsGroupOwned = (bytes[i++] != 0) ? (bool)true : (bool)false; - RemoveContribution = (bytes[i++] != 0) ? (bool)true : (bool)false; - LocalID = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - Final = (bytes[i++] != 0) ? (bool)true : (bool)false; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - GroupID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)((IsGroupOwned) ? 1 : 0); - bytes[i++] = (byte)((RemoveContribution) ? 1 : 0); - Utils.IntToBytes(LocalID, bytes, i); i += 4; - bytes[i++] = (byte)((Final) ? 1 : 0); - } - - } - - /// - public sealed class ParcelDataBlock : PacketBlock - { - public int Price; - public int Area; - - public override int Length - { - get - { - return 8; - } - } - - public ParcelDataBlock() { } - public ParcelDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - Price = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - Area = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.IntToBytes(Price, bytes, i); i += 4; - Utils.IntToBytes(Area, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += Data.Length; - length += ParcelData.Length; - return length; - } - } - public AgentDataBlock AgentData; - public DataBlock Data; - public ParcelDataBlock ParcelData; - - public ParcelBuyPacket() - { - HasVariableBlocks = false; - Type = PacketType.ParcelBuy; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 213; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - Data = new DataBlock(); - ParcelData = new ParcelDataBlock(); - } - - public ParcelBuyPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - Data.FromBytes(bytes, ref i); - ParcelData.FromBytes(bytes, ref i); - } - - public ParcelBuyPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - Data.FromBytes(bytes, ref i); - ParcelData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += Data.Length; - length += ParcelData.Length; - if (Header.AckList != null && 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); - Data.ToBytes(bytes, ref i); - ParcelData.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class ParcelGodForceOwnerPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class DataBlock : PacketBlock - { - public UUID OwnerID; - public int LocalID; - - public override int Length - { - get - { - return 20; - } - } - - public DataBlock() { } - public DataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - OwnerID.FromBytes(bytes, i); i += 16; - LocalID = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - OwnerID.ToBytes(bytes, i); i += 16; - Utils.IntToBytes(LocalID, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += Data.Length; - return length; - } - } - public AgentDataBlock AgentData; - public DataBlock Data; - - public ParcelGodForceOwnerPacket() - { - HasVariableBlocks = false; - Type = PacketType.ParcelGodForceOwner; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 214; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - Data = new DataBlock(); - } - - public ParcelGodForceOwnerPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - Data.FromBytes(bytes, ref i); - } - - public ParcelGodForceOwnerPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - Data.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += Data.Length; - if (Header.AckList != null && 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); - Data.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class ParcelAccessListRequestPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class DataBlock : PacketBlock - { - public int SequenceID; - public uint Flags; - public int LocalID; - - public override int Length - { - get - { - return 12; - } - } - - public DataBlock() { } - public DataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - 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)); - LocalID = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.IntToBytes(SequenceID, bytes, i); i += 4; - Utils.UIntToBytes(Flags, bytes, i); i += 4; - Utils.IntToBytes(LocalID, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += Data.Length; - return length; - } - } - public AgentDataBlock AgentData; - public DataBlock Data; - - public ParcelAccessListRequestPacket() - { - HasVariableBlocks = false; - Type = PacketType.ParcelAccessListRequest; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 215; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - Data = new DataBlock(); - } - - public ParcelAccessListRequestPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - Data.FromBytes(bytes, ref i); - } - - public ParcelAccessListRequestPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - Data.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += Data.Length; - if (Header.AckList != null && 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); - Data.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class ParcelAccessListReplyPacket : Packet - { - /// - public sealed class DataBlock : PacketBlock - { - public UUID AgentID; - public int SequenceID; - public uint Flags; - public int LocalID; - - public override int Length - { - get - { - return 28; - } - } - - public DataBlock() { } - public DataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - 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)); - LocalID = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - Utils.IntToBytes(SequenceID, bytes, i); i += 4; - Utils.UIntToBytes(Flags, bytes, i); i += 4; - Utils.IntToBytes(LocalID, bytes, i); i += 4; - } - - } - - /// - public sealed class ListBlock : PacketBlock - { - public UUID ID; - public int Time; - public uint Flags; - - public override int Length - { - get - { - return 24; - } - } - - public ListBlock() { } - public ListBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - ID.FromBytes(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(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - ID.ToBytes(bytes, i); i += 16; - Utils.IntToBytes(Time, bytes, i); i += 4; - Utils.UIntToBytes(Flags, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 11; - length += Data.Length; - for (int j = 0; j < List.Length; j++) - length += List[j].Length; - return length; - } - } - public DataBlock Data; - public ListBlock[] List; - - public ParcelAccessListReplyPacket() - { - HasVariableBlocks = true; - Type = PacketType.ParcelAccessListReply; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 216; - Header.Reliable = true; - Header.Zerocoded = true; - Data = new DataBlock(); - List = null; - } - - public ParcelAccessListReplyPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - Data.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(List == null || List.Length != -1) { - List = new ListBlock[count]; - for(int j = 0; j < count; j++) - { List[j] = new ListBlock(); } - } - for (int j = 0; j < count; j++) - { List[j].FromBytes(bytes, ref i); } - } - - public ParcelAccessListReplyPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - Data.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(List == null || List.Length != count) { - List = new ListBlock[count]; - for(int j = 0; j < count; j++) - { List[j] = new ListBlock(); } - } - for (int j = 0; j < count; j++) - { List[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += Data.Length; - length++; - for (int j = 0; j < List.Length; j++) { length += List[j].Length; } - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += Data.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - Data.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int ListStart = 0; - do - { - int variableLength = 0; - int ListCount = 0; - - i = ListStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < List.Length) { - int blockLength = List[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ListStart) { - variableLength += blockLength; - ++ListCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)ListCount; - for (i = ListStart; i < ListStart + ListCount; i++) { List[i].ToBytes(packet, ref length); } - ListStart += ListCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - ListStart < List.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class ParcelAccessListUpdatePacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class DataBlock : PacketBlock - { - public uint Flags; - public int LocalID; - public UUID TransactionID; - public int SequenceID; - public int Sections; - - public override int Length - { - get - { - return 32; - } - } - - public DataBlock() { } - public DataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - Flags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - LocalID = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - TransactionID.FromBytes(bytes, i); i += 16; - SequenceID = (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)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UIntToBytes(Flags, bytes, i); i += 4; - Utils.IntToBytes(LocalID, bytes, i); i += 4; - TransactionID.ToBytes(bytes, i); i += 16; - Utils.IntToBytes(SequenceID, bytes, i); i += 4; - Utils.IntToBytes(Sections, bytes, i); i += 4; - } - - } - - /// - public sealed class ListBlock : PacketBlock - { - public UUID ID; - public int Time; - public uint Flags; - - public override int Length - { - get - { - return 24; - } - } - - public ListBlock() { } - public ListBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - ID.FromBytes(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(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - ID.ToBytes(bytes, i); i += 16; - Utils.IntToBytes(Time, bytes, i); i += 4; - Utils.UIntToBytes(Flags, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentData.Length; - length += Data.Length; - for (int j = 0; j < List.Length; j++) - length += List[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public DataBlock Data; - public ListBlock[] List; - - public ParcelAccessListUpdatePacket() - { - HasVariableBlocks = true; - Type = PacketType.ParcelAccessListUpdate; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 217; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - Data = new DataBlock(); - List = null; - } - - public ParcelAccessListUpdatePacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - Data.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(List == null || List.Length != -1) { - List = new ListBlock[count]; - for(int j = 0; j < count; j++) - { List[j] = new ListBlock(); } - } - for (int j = 0; j < count; j++) - { List[j].FromBytes(bytes, ref i); } - } - - public ParcelAccessListUpdatePacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - Data.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(List == null || List.Length != count) { - List = new ListBlock[count]; - for(int j = 0; j < count; j++) - { List[j] = new ListBlock(); } - } - for (int j = 0; j < count; j++) - { List[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += Data.Length; - length++; - for (int j = 0; j < List.Length; j++) { length += List[j].Length; } - if (Header.AckList != null && 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); - 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - fixedLength += Data.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - Data.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int ListStart = 0; - do - { - int variableLength = 0; - int ListCount = 0; - - i = ListStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < List.Length) { - int blockLength = List[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ListStart) { - variableLength += blockLength; - ++ListCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)ListCount; - for (i = ListStart; i < ListStart + ListCount; i++) { List[i].ToBytes(packet, ref length); } - ListStart += ListCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - ListStart < List.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class ParcelDwellRequestPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class DataBlock : PacketBlock - { - public int LocalID; - public UUID ParcelID; - - public override int Length - { - get - { - return 20; - } - } - - public DataBlock() { } - public DataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - LocalID = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - ParcelID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.IntToBytes(LocalID, bytes, i); i += 4; - ParcelID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += Data.Length; - return length; - } - } - public AgentDataBlock AgentData; - public DataBlock Data; - - public ParcelDwellRequestPacket() - { - HasVariableBlocks = false; - Type = PacketType.ParcelDwellRequest; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 218; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - Data = new DataBlock(); - } - - public ParcelDwellRequestPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - Data.FromBytes(bytes, ref i); - } - - public ParcelDwellRequestPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - Data.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += Data.Length; - if (Header.AckList != null && 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); - Data.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class ParcelDwellReplyPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - - public override int Length - { - get - { - return 16; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class DataBlock : PacketBlock - { - public int LocalID; - public UUID ParcelID; - public float Dwell; - - public override int Length - { - get - { - return 24; - } - } - - public DataBlock() { } - public DataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - LocalID = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - ParcelID.FromBytes(bytes, i); i += 16; - Dwell = Utils.BytesToFloat(bytes, i); i += 4; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.IntToBytes(LocalID, bytes, i); i += 4; - ParcelID.ToBytes(bytes, i); i += 16; - Utils.FloatToBytes(Dwell, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += Data.Length; - return length; - } - } - public AgentDataBlock AgentData; - public DataBlock Data; - - public ParcelDwellReplyPacket() - { - HasVariableBlocks = false; - Type = PacketType.ParcelDwellReply; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 219; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - Data = new DataBlock(); - } - - public ParcelDwellReplyPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - Data.FromBytes(bytes, ref i); - } - - public ParcelDwellReplyPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - Data.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += Data.Length; - if (Header.AckList != null && 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); - Data.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class ParcelGodMarkAsContentPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class ParcelDataBlock : PacketBlock - { - public int LocalID; - - public override int Length - { - get - { - return 4; - } - } - - public ParcelDataBlock() { } - public ParcelDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - LocalID = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.IntToBytes(LocalID, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += ParcelData.Length; - return length; - } - } - public AgentDataBlock AgentData; - public ParcelDataBlock ParcelData; - - public ParcelGodMarkAsContentPacket() - { - HasVariableBlocks = false; - Type = PacketType.ParcelGodMarkAsContent; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 227; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - ParcelData = new ParcelDataBlock(); - } - - public ParcelGodMarkAsContentPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - ParcelData.FromBytes(bytes, ref i); - } - - public ParcelGodMarkAsContentPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - ParcelData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += ParcelData.Length; - if (Header.AckList != null && 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); - ParcelData.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class ViewerStartAuctionPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class ParcelDataBlock : PacketBlock - { - public int LocalID; - public UUID SnapshotID; - - public override int Length - { - get - { - return 20; - } - } - - public ParcelDataBlock() { } - public ParcelDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - LocalID = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - SnapshotID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.IntToBytes(LocalID, bytes, i); i += 4; - SnapshotID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += ParcelData.Length; - return length; - } - } - public AgentDataBlock AgentData; - public ParcelDataBlock ParcelData; - - public ViewerStartAuctionPacket() - { - HasVariableBlocks = false; - Type = PacketType.ViewerStartAuction; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 228; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - ParcelData = new ParcelDataBlock(); - } - - public ViewerStartAuctionPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - ParcelData.FromBytes(bytes, ref i); - } - - public ViewerStartAuctionPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - ParcelData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += ParcelData.Length; - if (Header.AckList != null && 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); - ParcelData.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class UUIDNameRequestPacket : Packet - { - /// - public sealed class UUIDNameBlockBlock : PacketBlock - { - public UUID ID; - - public override int Length - { - get - { - return 16; - } - } - - public UUIDNameBlockBlock() { } - public UUIDNameBlockBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - ID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - ID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 11; - for (int j = 0; j < UUIDNameBlock.Length; j++) - length += UUIDNameBlock[j].Length; - return length; - } - } - public UUIDNameBlockBlock[] UUIDNameBlock; - - public UUIDNameRequestPacket() - { - HasVariableBlocks = true; - Type = PacketType.UUIDNameRequest; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 235; - Header.Reliable = true; - UUIDNameBlock = null; - } - - public UUIDNameRequestPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - int count = (int)bytes[i++]; - if(UUIDNameBlock == null || UUIDNameBlock.Length != -1) { - UUIDNameBlock = new UUIDNameBlockBlock[count]; - for(int j = 0; j < count; j++) - { UUIDNameBlock[j] = new UUIDNameBlockBlock(); } - } - for (int j = 0; j < count; j++) - { UUIDNameBlock[j].FromBytes(bytes, ref i); } - } - - public UUIDNameRequestPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - int count = (int)bytes[i++]; - if(UUIDNameBlock == null || UUIDNameBlock.Length != count) { - UUIDNameBlock = new UUIDNameBlockBlock[count]; - for(int j = 0; j < count; j++) - { UUIDNameBlock[j] = new UUIDNameBlockBlock(); } - } - for (int j = 0; j < count; j++) - { UUIDNameBlock[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length++; - for (int j = 0; j < UUIDNameBlock.Length; j++) { length += UUIDNameBlock[j].Length; } - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int UUIDNameBlockStart = 0; - do - { - int variableLength = 0; - int UUIDNameBlockCount = 0; - - i = UUIDNameBlockStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < UUIDNameBlock.Length) { - int blockLength = UUIDNameBlock[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == UUIDNameBlockStart) { - variableLength += blockLength; - ++UUIDNameBlockCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)UUIDNameBlockCount; - for (i = UUIDNameBlockStart; i < UUIDNameBlockStart + UUIDNameBlockCount; i++) { UUIDNameBlock[i].ToBytes(packet, ref length); } - UUIDNameBlockStart += UUIDNameBlockCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - UUIDNameBlockStart < UUIDNameBlock.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class UUIDNameReplyPacket : Packet - { - /// - public sealed class UUIDNameBlockBlock : PacketBlock - { - public UUID ID; - public byte[] FirstName; - public byte[] LastName; - - public override int Length - { - get - { - int length = 18; - if (FirstName != null) { length += FirstName.Length; } - if (LastName != null) { length += LastName.Length; } - return length; - } - } - - public UUIDNameBlockBlock() { } - public UUIDNameBlockBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - ID.FromBytes(bytes, i); i += 16; - length = bytes[i++]; - FirstName = new byte[length]; - Buffer.BlockCopy(bytes, i, FirstName, 0, length); i += length; - length = bytes[i++]; - LastName = new byte[length]; - Buffer.BlockCopy(bytes, i, LastName, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - ID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)FirstName.Length; - Buffer.BlockCopy(FirstName, 0, bytes, i, FirstName.Length); i += FirstName.Length; - bytes[i++] = (byte)LastName.Length; - Buffer.BlockCopy(LastName, 0, bytes, i, LastName.Length); i += LastName.Length; - } - - } - - public override int Length - { - get - { - int length = 11; - for (int j = 0; j < UUIDNameBlock.Length; j++) - length += UUIDNameBlock[j].Length; - return length; - } - } - public UUIDNameBlockBlock[] UUIDNameBlock; - - public UUIDNameReplyPacket() - { - HasVariableBlocks = true; - Type = PacketType.UUIDNameReply; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 236; - Header.Reliable = true; - UUIDNameBlock = null; - } - - public UUIDNameReplyPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - int count = (int)bytes[i++]; - if(UUIDNameBlock == null || UUIDNameBlock.Length != -1) { - UUIDNameBlock = new UUIDNameBlockBlock[count]; - for(int j = 0; j < count; j++) - { UUIDNameBlock[j] = new UUIDNameBlockBlock(); } - } - for (int j = 0; j < count; j++) - { UUIDNameBlock[j].FromBytes(bytes, ref i); } - } - - public UUIDNameReplyPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - int count = (int)bytes[i++]; - if(UUIDNameBlock == null || UUIDNameBlock.Length != count) { - UUIDNameBlock = new UUIDNameBlockBlock[count]; - for(int j = 0; j < count; j++) - { UUIDNameBlock[j] = new UUIDNameBlockBlock(); } - } - for (int j = 0; j < count; j++) - { UUIDNameBlock[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length++; - for (int j = 0; j < UUIDNameBlock.Length; j++) { length += UUIDNameBlock[j].Length; } - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int UUIDNameBlockStart = 0; - do - { - int variableLength = 0; - int UUIDNameBlockCount = 0; - - i = UUIDNameBlockStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < UUIDNameBlock.Length) { - int blockLength = UUIDNameBlock[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == UUIDNameBlockStart) { - variableLength += blockLength; - ++UUIDNameBlockCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)UUIDNameBlockCount; - for (i = UUIDNameBlockStart; i < UUIDNameBlockStart + UUIDNameBlockCount; i++) { UUIDNameBlock[i].ToBytes(packet, ref length); } - UUIDNameBlockStart += UUIDNameBlockCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - UUIDNameBlockStart < UUIDNameBlock.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class UUIDGroupNameRequestPacket : Packet - { - /// - public sealed class UUIDNameBlockBlock : PacketBlock - { - public UUID ID; - - public override int Length - { - get - { - return 16; - } - } - - public UUIDNameBlockBlock() { } - public UUIDNameBlockBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - ID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - ID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 11; - for (int j = 0; j < UUIDNameBlock.Length; j++) - length += UUIDNameBlock[j].Length; - return length; - } - } - public UUIDNameBlockBlock[] UUIDNameBlock; - - public UUIDGroupNameRequestPacket() - { - HasVariableBlocks = true; - Type = PacketType.UUIDGroupNameRequest; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 237; - Header.Reliable = true; - UUIDNameBlock = null; - } - - public UUIDGroupNameRequestPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - int count = (int)bytes[i++]; - if(UUIDNameBlock == null || UUIDNameBlock.Length != -1) { - UUIDNameBlock = new UUIDNameBlockBlock[count]; - for(int j = 0; j < count; j++) - { UUIDNameBlock[j] = new UUIDNameBlockBlock(); } - } - for (int j = 0; j < count; j++) - { UUIDNameBlock[j].FromBytes(bytes, ref i); } - } - - public UUIDGroupNameRequestPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - int count = (int)bytes[i++]; - if(UUIDNameBlock == null || UUIDNameBlock.Length != count) { - UUIDNameBlock = new UUIDNameBlockBlock[count]; - for(int j = 0; j < count; j++) - { UUIDNameBlock[j] = new UUIDNameBlockBlock(); } - } - for (int j = 0; j < count; j++) - { UUIDNameBlock[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length++; - for (int j = 0; j < UUIDNameBlock.Length; j++) { length += UUIDNameBlock[j].Length; } - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int UUIDNameBlockStart = 0; - do - { - int variableLength = 0; - int UUIDNameBlockCount = 0; - - i = UUIDNameBlockStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < UUIDNameBlock.Length) { - int blockLength = UUIDNameBlock[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == UUIDNameBlockStart) { - variableLength += blockLength; - ++UUIDNameBlockCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)UUIDNameBlockCount; - for (i = UUIDNameBlockStart; i < UUIDNameBlockStart + UUIDNameBlockCount; i++) { UUIDNameBlock[i].ToBytes(packet, ref length); } - UUIDNameBlockStart += UUIDNameBlockCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - UUIDNameBlockStart < UUIDNameBlock.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class UUIDGroupNameReplyPacket : Packet - { - /// - public sealed class UUIDNameBlockBlock : PacketBlock - { - public UUID ID; - public byte[] GroupName; - - public override int Length - { - get - { - int length = 17; - if (GroupName != null) { length += GroupName.Length; } - return length; - } - } - - public UUIDNameBlockBlock() { } - public UUIDNameBlockBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - ID.FromBytes(bytes, i); i += 16; - length = bytes[i++]; - GroupName = new byte[length]; - Buffer.BlockCopy(bytes, i, GroupName, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - ID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)GroupName.Length; - Buffer.BlockCopy(GroupName, 0, bytes, i, GroupName.Length); i += GroupName.Length; - } - - } - - public override int Length - { - get - { - int length = 11; - for (int j = 0; j < UUIDNameBlock.Length; j++) - length += UUIDNameBlock[j].Length; - return length; - } - } - public UUIDNameBlockBlock[] UUIDNameBlock; - - public UUIDGroupNameReplyPacket() - { - HasVariableBlocks = true; - Type = PacketType.UUIDGroupNameReply; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 238; - Header.Reliable = true; - UUIDNameBlock = null; - } - - public UUIDGroupNameReplyPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - int count = (int)bytes[i++]; - if(UUIDNameBlock == null || UUIDNameBlock.Length != -1) { - UUIDNameBlock = new UUIDNameBlockBlock[count]; - for(int j = 0; j < count; j++) - { UUIDNameBlock[j] = new UUIDNameBlockBlock(); } - } - for (int j = 0; j < count; j++) - { UUIDNameBlock[j].FromBytes(bytes, ref i); } - } - - public UUIDGroupNameReplyPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - int count = (int)bytes[i++]; - if(UUIDNameBlock == null || UUIDNameBlock.Length != count) { - UUIDNameBlock = new UUIDNameBlockBlock[count]; - for(int j = 0; j < count; j++) - { UUIDNameBlock[j] = new UUIDNameBlockBlock(); } - } - for (int j = 0; j < count; j++) - { UUIDNameBlock[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length++; - for (int j = 0; j < UUIDNameBlock.Length; j++) { length += UUIDNameBlock[j].Length; } - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int UUIDNameBlockStart = 0; - do - { - int variableLength = 0; - int UUIDNameBlockCount = 0; - - i = UUIDNameBlockStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < UUIDNameBlock.Length) { - int blockLength = UUIDNameBlock[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == UUIDNameBlockStart) { - variableLength += blockLength; - ++UUIDNameBlockCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)UUIDNameBlockCount; - for (i = UUIDNameBlockStart; i < UUIDNameBlockStart + UUIDNameBlockCount; i++) { UUIDNameBlock[i].ToBytes(packet, ref length); } - UUIDNameBlockStart += UUIDNameBlockCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - UUIDNameBlockStart < UUIDNameBlock.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class ChildAgentDyingPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - return length; - } - } - public AgentDataBlock AgentData; - - public ChildAgentDyingPacket() - { - HasVariableBlocks = false; - Type = PacketType.ChildAgentDying; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 240; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - } - - public ChildAgentDyingPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - } - - public ChildAgentDyingPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class ChildAgentUnknownPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - return length; - } - } - public AgentDataBlock AgentData; - - public ChildAgentUnknownPacket() - { - HasVariableBlocks = false; - Type = PacketType.ChildAgentUnknown; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 241; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - } - - public ChildAgentUnknownPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - } - - public ChildAgentUnknownPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class GetScriptRunningPacket : Packet - { - /// - public sealed class ScriptBlock : PacketBlock - { - public UUID ObjectID; - public UUID ItemID; - - public override int Length - { - get - { - return 32; - } - } - - public ScriptBlock() { } - public ScriptBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - ObjectID.FromBytes(bytes, i); i += 16; - ItemID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - ObjectID.ToBytes(bytes, i); i += 16; - ItemID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 10; - length += Script.Length; - return length; - } - } - public ScriptBlock Script; - - public GetScriptRunningPacket() - { - HasVariableBlocks = false; - Type = PacketType.GetScriptRunning; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 243; - Header.Reliable = true; - Script = new ScriptBlock(); - } - - public GetScriptRunningPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - Script.FromBytes(bytes, ref i); - } - - public GetScriptRunningPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - Script.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += Script.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class ScriptRunningReplyPacket : Packet - { - /// - public sealed class ScriptBlock : PacketBlock - { - public UUID ObjectID; - public UUID ItemID; - public bool Running; - - public override int Length - { - get - { - return 33; - } - } - - public ScriptBlock() { } - public ScriptBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - ObjectID.FromBytes(bytes, i); i += 16; - ItemID.FromBytes(bytes, i); i += 16; - Running = (bytes[i++] != 0) ? (bool)true : (bool)false; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - ObjectID.ToBytes(bytes, i); i += 16; - ItemID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)((Running) ? 1 : 0); - } - - } - - public override int Length - { - get - { - int length = 10; - length += Script.Length; - return length; - } - } - public ScriptBlock Script; - - public ScriptRunningReplyPacket() - { - HasVariableBlocks = false; - Type = PacketType.ScriptRunningReply; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 244; - Header.Reliable = true; - Script = new ScriptBlock(); - } - - public ScriptRunningReplyPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - Script.FromBytes(bytes, ref i); - } - - public ScriptRunningReplyPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - Script.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += Script.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class SetScriptRunningPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class ScriptBlock : PacketBlock - { - public UUID ObjectID; - public UUID ItemID; - public bool Running; - - public override int Length - { - get - { - return 33; - } - } - - public ScriptBlock() { } - public ScriptBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - ObjectID.FromBytes(bytes, i); i += 16; - ItemID.FromBytes(bytes, i); i += 16; - Running = (bytes[i++] != 0) ? (bool)true : (bool)false; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - ObjectID.ToBytes(bytes, i); i += 16; - ItemID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)((Running) ? 1 : 0); - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += Script.Length; - return length; - } - } - public AgentDataBlock AgentData; - public ScriptBlock Script; - - public SetScriptRunningPacket() - { - HasVariableBlocks = false; - Type = PacketType.SetScriptRunning; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 245; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - Script = new ScriptBlock(); - } - - public SetScriptRunningPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - Script.FromBytes(bytes, ref i); - } - - public SetScriptRunningPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - Script.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += Script.Length; - if (Header.AckList != null && 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); - Script.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class ScriptResetPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class ScriptBlock : PacketBlock - { - public UUID ObjectID; - public UUID ItemID; - - public override int Length - { - get - { - return 32; - } - } - - public ScriptBlock() { } - public ScriptBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - ObjectID.FromBytes(bytes, i); i += 16; - ItemID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - ObjectID.ToBytes(bytes, i); i += 16; - ItemID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += Script.Length; - return length; - } - } - public AgentDataBlock AgentData; - public ScriptBlock Script; - - public ScriptResetPacket() - { - HasVariableBlocks = false; - Type = PacketType.ScriptReset; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 246; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - Script = new ScriptBlock(); - } - - public ScriptResetPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - Script.FromBytes(bytes, ref i); - } - - public ScriptResetPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - Script.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += Script.Length; - if (Header.AckList != null && 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); - Script.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class ScriptSensorRequestPacket : Packet - { - /// - public sealed class RequesterBlock : PacketBlock - { - public UUID SourceID; - public UUID RequestID; - public UUID SearchID; - public Vector3 SearchPos; - public Quaternion SearchDir; - public byte[] SearchName; - public int Type; - public float Range; - public float Arc; - public ulong RegionHandle; - public byte SearchRegions; - - public override int Length - { - get - { - int length = 94; - if (SearchName != null) { length += SearchName.Length; } - return length; - } - } - - public RequesterBlock() { } - public RequesterBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - SourceID.FromBytes(bytes, i); i += 16; - RequestID.FromBytes(bytes, i); i += 16; - SearchID.FromBytes(bytes, i); i += 16; - SearchPos.FromBytes(bytes, i); i += 12; - SearchDir.FromBytes(bytes, i, true); i += 12; - length = bytes[i++]; - SearchName = new byte[length]; - Buffer.BlockCopy(bytes, i, SearchName, 0, length); i += length; - Type = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - Range = Utils.BytesToFloat(bytes, i); i += 4; - Arc = Utils.BytesToFloat(bytes, i); i += 4; - 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)); - SearchRegions = (byte)bytes[i++]; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - SourceID.ToBytes(bytes, i); i += 16; - RequestID.ToBytes(bytes, i); i += 16; - SearchID.ToBytes(bytes, i); i += 16; - SearchPos.ToBytes(bytes, i); i += 12; - SearchDir.ToBytes(bytes, i); i += 12; - bytes[i++] = (byte)SearchName.Length; - Buffer.BlockCopy(SearchName, 0, bytes, i, SearchName.Length); i += SearchName.Length; - Utils.IntToBytes(Type, bytes, i); i += 4; - Utils.FloatToBytes(Range, bytes, i); i += 4; - Utils.FloatToBytes(Arc, bytes, i); i += 4; - Utils.UInt64ToBytes(RegionHandle, bytes, i); i += 8; - bytes[i++] = SearchRegions; - } - - } - - public override int Length - { - get - { - int length = 10; - length += Requester.Length; - return length; - } - } - public RequesterBlock Requester; - - public ScriptSensorRequestPacket() - { - HasVariableBlocks = false; - Type = PacketType.ScriptSensorRequest; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 247; - Header.Reliable = true; - Header.Zerocoded = true; - Requester = new RequesterBlock(); - } - - public ScriptSensorRequestPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - Requester.FromBytes(bytes, ref i); - } - - public ScriptSensorRequestPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - Requester.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += Requester.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class ScriptSensorReplyPacket : Packet - { - /// - public sealed class RequesterBlock : PacketBlock - { - public UUID SourceID; - - public override int Length - { - get - { - return 16; - } - } - - public RequesterBlock() { } - public RequesterBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - SourceID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - SourceID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class SensedDataBlock : PacketBlock - { - public UUID ObjectID; - public UUID OwnerID; - public UUID GroupID; - public Vector3 Position; - public Vector3 Velocity; - public Quaternion Rotation; - public byte[] Name; - public int Type; - public float Range; - - public override int Length - { - get - { - int length = 93; - if (Name != null) { length += Name.Length; } - return length; - } - } - - public SensedDataBlock() { } - public SensedDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - ObjectID.FromBytes(bytes, i); i += 16; - OwnerID.FromBytes(bytes, i); i += 16; - GroupID.FromBytes(bytes, i); i += 16; - Position.FromBytes(bytes, i); i += 12; - Velocity.FromBytes(bytes, i); i += 12; - Rotation.FromBytes(bytes, i, true); i += 12; - length = bytes[i++]; - Name = new byte[length]; - Buffer.BlockCopy(bytes, i, Name, 0, length); i += length; - Type = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - Range = Utils.BytesToFloat(bytes, i); i += 4; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - ObjectID.ToBytes(bytes, i); i += 16; - OwnerID.ToBytes(bytes, i); i += 16; - GroupID.ToBytes(bytes, i); i += 16; - Position.ToBytes(bytes, i); i += 12; - Velocity.ToBytes(bytes, i); i += 12; - Rotation.ToBytes(bytes, i); i += 12; - bytes[i++] = (byte)Name.Length; - Buffer.BlockCopy(Name, 0, bytes, i, Name.Length); i += Name.Length; - Utils.IntToBytes(Type, bytes, i); i += 4; - Utils.FloatToBytes(Range, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 11; - length += Requester.Length; - for (int j = 0; j < SensedData.Length; j++) - length += SensedData[j].Length; - return length; - } - } - public RequesterBlock Requester; - public SensedDataBlock[] SensedData; - - public ScriptSensorReplyPacket() - { - HasVariableBlocks = true; - Type = PacketType.ScriptSensorReply; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 248; - Header.Reliable = true; - Header.Zerocoded = true; - Requester = new RequesterBlock(); - SensedData = null; - } - - public ScriptSensorReplyPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - Requester.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(SensedData == null || SensedData.Length != -1) { - SensedData = new SensedDataBlock[count]; - for(int j = 0; j < count; j++) - { SensedData[j] = new SensedDataBlock(); } - } - for (int j = 0; j < count; j++) - { SensedData[j].FromBytes(bytes, ref i); } - } - - public ScriptSensorReplyPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - Requester.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(SensedData == null || SensedData.Length != count) { - SensedData = new SensedDataBlock[count]; - for(int j = 0; j < count; j++) - { SensedData[j] = new SensedDataBlock(); } - } - for (int j = 0; j < count; j++) - { SensedData[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += Requester.Length; - length++; - for (int j = 0; j < SensedData.Length; j++) { length += SensedData[j].Length; } - if (Header.AckList != null && 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); - bytes[i++] = (byte)SensedData.Length; - for (int j = 0; j < SensedData.Length; j++) { SensedData[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += Requester.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - Requester.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int SensedDataStart = 0; - do - { - int variableLength = 0; - int SensedDataCount = 0; - - i = SensedDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < SensedData.Length) { - int blockLength = SensedData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == SensedDataStart) { - variableLength += blockLength; - ++SensedDataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)SensedDataCount; - for (i = SensedDataStart; i < SensedDataStart + SensedDataCount; i++) { SensedData[i].ToBytes(packet, ref length); } - SensedDataStart += SensedDataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - SensedDataStart < SensedData.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class CompleteAgentMovementPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - public uint CircuitCode; - - public override int Length - { - get - { - return 36; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - CircuitCode = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - Utils.UIntToBytes(CircuitCode, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - return length; - } - } - public AgentDataBlock AgentData; - - public CompleteAgentMovementPacket() - { - HasVariableBlocks = false; - Type = PacketType.CompleteAgentMovement; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 249; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - } - - public CompleteAgentMovementPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - } - - public CompleteAgentMovementPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class AgentMovementCompletePacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class DataBlock : PacketBlock - { - public Vector3 Position; - public Vector3 LookAt; - public ulong RegionHandle; - public uint Timestamp; - - public override int Length - { - get - { - return 36; - } - } - - public DataBlock() { } - public DataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - Position.FromBytes(bytes, i); i += 12; - LookAt.FromBytes(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)); - Timestamp = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Position.ToBytes(bytes, i); i += 12; - LookAt.ToBytes(bytes, i); i += 12; - Utils.UInt64ToBytes(RegionHandle, bytes, i); i += 8; - Utils.UIntToBytes(Timestamp, bytes, i); i += 4; - } - - } - - /// - public sealed class SimDataBlock : PacketBlock - { - public byte[] ChannelVersion; - - public override int Length - { - get - { - int length = 2; - if (ChannelVersion != null) { length += ChannelVersion.Length; } - return length; - } - } - - public SimDataBlock() { } - public SimDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - length = (bytes[i++] + (bytes[i++] << 8)); - ChannelVersion = new byte[length]; - Buffer.BlockCopy(bytes, i, ChannelVersion, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - bytes[i++] = (byte)(ChannelVersion.Length % 256); - bytes[i++] = (byte)((ChannelVersion.Length >> 8) % 256); - Buffer.BlockCopy(ChannelVersion, 0, bytes, i, ChannelVersion.Length); i += ChannelVersion.Length; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += Data.Length; - length += SimData.Length; - return length; - } - } - public AgentDataBlock AgentData; - public DataBlock Data; - public SimDataBlock SimData; - - public AgentMovementCompletePacket() - { - HasVariableBlocks = false; - Type = PacketType.AgentMovementComplete; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 250; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - Data = new DataBlock(); - SimData = new SimDataBlock(); - } - - public AgentMovementCompletePacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - Data.FromBytes(bytes, ref i); - SimData.FromBytes(bytes, ref i); - } - - public AgentMovementCompletePacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - Data.FromBytes(bytes, ref i); - SimData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += Data.Length; - length += SimData.Length; - if (Header.AckList != null && 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); - Data.ToBytes(bytes, ref i); - SimData.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class LogoutRequestPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - return length; - } - } - public AgentDataBlock AgentData; - - public LogoutRequestPacket() - { - HasVariableBlocks = false; - Type = PacketType.LogoutRequest; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 252; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - } - - public LogoutRequestPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - } - - public LogoutRequestPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class LogoutReplyPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class InventoryDataBlock : PacketBlock - { - public UUID ItemID; - - public override int Length - { - get - { - return 16; - } - } - - public InventoryDataBlock() { } - public InventoryDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - ItemID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - ItemID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentData.Length; - for (int j = 0; j < InventoryData.Length; j++) - length += InventoryData[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public InventoryDataBlock[] InventoryData; - - public LogoutReplyPacket() - { - HasVariableBlocks = true; - Type = PacketType.LogoutReply; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 253; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - InventoryData = null; - } - - public LogoutReplyPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(InventoryData == null || InventoryData.Length != -1) { - InventoryData = new InventoryDataBlock[count]; - for(int j = 0; j < count; j++) - { InventoryData[j] = new InventoryDataBlock(); } - } - for (int j = 0; j < count; j++) - { InventoryData[j].FromBytes(bytes, ref i); } - } - - public LogoutReplyPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(InventoryData == null || InventoryData.Length != count) { - InventoryData = new InventoryDataBlock[count]; - for(int j = 0; j < count; j++) - { InventoryData[j] = new InventoryDataBlock(); } - } - for (int j = 0; j < count; j++) - { InventoryData[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length++; - for (int j = 0; j < InventoryData.Length; j++) { length += InventoryData[j].Length; } - if (Header.AckList != null && 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)InventoryData.Length; - for (int j = 0; j < InventoryData.Length; j++) { InventoryData[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int InventoryDataStart = 0; - do - { - int variableLength = 0; - int InventoryDataCount = 0; - - i = InventoryDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < InventoryData.Length) { - int blockLength = InventoryData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == InventoryDataStart) { - variableLength += blockLength; - ++InventoryDataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)InventoryDataCount; - for (i = InventoryDataStart; i < InventoryDataStart + InventoryDataCount; i++) { InventoryData[i].ToBytes(packet, ref length); } - InventoryDataStart += InventoryDataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - InventoryDataStart < InventoryData.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class ImprovedInstantMessagePacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class MessageBlockBlock : PacketBlock - { - public bool FromGroup; - public UUID ToAgentID; - public uint ParentEstateID; - public UUID RegionID; - public Vector3 Position; - public byte Offline; - public byte Dialog; - public UUID ID; - public uint Timestamp; - public byte[] FromAgentName; - public byte[] Message; - public byte[] BinaryBucket; - - public override int Length - { - get - { - int length = 76; - if (FromAgentName != null) { length += FromAgentName.Length; } - if (Message != null) { length += Message.Length; } - if (BinaryBucket != null) { length += BinaryBucket.Length; } - return length; - } - } - - public MessageBlockBlock() { } - public MessageBlockBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - FromGroup = (bytes[i++] != 0) ? (bool)true : (bool)false; - ToAgentID.FromBytes(bytes, i); i += 16; - ParentEstateID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - RegionID.FromBytes(bytes, i); i += 16; - Position.FromBytes(bytes, i); i += 12; - Offline = (byte)bytes[i++]; - Dialog = (byte)bytes[i++]; - ID.FromBytes(bytes, i); i += 16; - Timestamp = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - length = bytes[i++]; - FromAgentName = new byte[length]; - Buffer.BlockCopy(bytes, i, FromAgentName, 0, length); i += length; - length = (bytes[i++] + (bytes[i++] << 8)); - Message = new byte[length]; - Buffer.BlockCopy(bytes, i, Message, 0, length); i += length; - length = (bytes[i++] + (bytes[i++] << 8)); - BinaryBucket = new byte[length]; - Buffer.BlockCopy(bytes, i, BinaryBucket, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - bytes[i++] = (byte)((FromGroup) ? 1 : 0); - ToAgentID.ToBytes(bytes, i); i += 16; - Utils.UIntToBytes(ParentEstateID, bytes, i); i += 4; - RegionID.ToBytes(bytes, i); i += 16; - Position.ToBytes(bytes, i); i += 12; - bytes[i++] = Offline; - bytes[i++] = Dialog; - ID.ToBytes(bytes, i); i += 16; - Utils.UIntToBytes(Timestamp, bytes, i); i += 4; - bytes[i++] = (byte)FromAgentName.Length; - Buffer.BlockCopy(FromAgentName, 0, bytes, i, FromAgentName.Length); i += FromAgentName.Length; - bytes[i++] = (byte)(Message.Length % 256); - bytes[i++] = (byte)((Message.Length >> 8) % 256); - Buffer.BlockCopy(Message, 0, bytes, i, Message.Length); i += Message.Length; - bytes[i++] = (byte)(BinaryBucket.Length % 256); - bytes[i++] = (byte)((BinaryBucket.Length >> 8) % 256); - Buffer.BlockCopy(BinaryBucket, 0, bytes, i, BinaryBucket.Length); i += BinaryBucket.Length; - } - - } - - /// - public sealed class EstateBlockBlock : PacketBlock - { - public uint EstateID; - - public override int Length - { - get - { - return 4; - } - } - - public EstateBlockBlock() { } - public EstateBlockBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - EstateID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UIntToBytes(EstateID, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += MessageBlock.Length; - length += EstateBlock.Length; - return length; - } - } - public AgentDataBlock AgentData; - public MessageBlockBlock MessageBlock; - public EstateBlockBlock EstateBlock; - - public ImprovedInstantMessagePacket() - { - HasVariableBlocks = false; - Type = PacketType.ImprovedInstantMessage; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 254; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - MessageBlock = new MessageBlockBlock(); - EstateBlock = new EstateBlockBlock(); - } - - public ImprovedInstantMessagePacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - MessageBlock.FromBytes(bytes, ref i); - EstateBlock.FromBytes(bytes, ref i); - } - - public ImprovedInstantMessagePacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - MessageBlock.FromBytes(bytes, ref i); - EstateBlock.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += MessageBlock.Length; - length += EstateBlock.Length; - if (Header.AckList != null && 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); - MessageBlock.ToBytes(bytes, ref i); - EstateBlock.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class RetrieveInstantMessagesPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - return length; - } - } - public AgentDataBlock AgentData; - - public RetrieveInstantMessagesPacket() - { - HasVariableBlocks = false; - Type = PacketType.RetrieveInstantMessages; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 255; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - } - - public RetrieveInstantMessagesPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - } - - public RetrieveInstantMessagesPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class FindAgentPacket : Packet - { - /// - public sealed class AgentBlockBlock : PacketBlock - { - public UUID Hunter; - public UUID Prey; - public uint SpaceIP; - - public override int Length - { - get - { - return 36; - } - } - - public AgentBlockBlock() { } - public AgentBlockBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - Hunter.FromBytes(bytes, i); i += 16; - Prey.FromBytes(bytes, i); i += 16; - SpaceIP = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Hunter.ToBytes(bytes, i); i += 16; - Prey.ToBytes(bytes, i); i += 16; - Utils.UIntToBytes(SpaceIP, bytes, i); i += 4; - } - - } - - /// - public sealed class LocationBlockBlock : PacketBlock - { - public double GlobalX; - public double GlobalY; - - public override int Length - { - get - { - return 16; - } - } - - public LocationBlockBlock() { } - public LocationBlockBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - GlobalX = Utils.BytesToDouble(bytes, i); i += 8; - GlobalY = Utils.BytesToDouble(bytes, i); i += 8; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.DoubleToBytes(GlobalX, bytes, i); i += 8; - Utils.DoubleToBytes(GlobalY, bytes, i); i += 8; - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentBlock.Length; - for (int j = 0; j < LocationBlock.Length; j++) - length += LocationBlock[j].Length; - return length; - } - } - public AgentBlockBlock AgentBlock; - public LocationBlockBlock[] LocationBlock; - - public FindAgentPacket() - { - HasVariableBlocks = true; - Type = PacketType.FindAgent; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 256; - Header.Reliable = true; - AgentBlock = new AgentBlockBlock(); - LocationBlock = null; - } - - public FindAgentPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentBlock.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(LocationBlock == null || LocationBlock.Length != -1) { - LocationBlock = new LocationBlockBlock[count]; - for(int j = 0; j < count; j++) - { LocationBlock[j] = new LocationBlockBlock(); } - } - for (int j = 0; j < count; j++) - { LocationBlock[j].FromBytes(bytes, ref i); } - } - - public FindAgentPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentBlock.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(LocationBlock == null || LocationBlock.Length != count) { - LocationBlock = new LocationBlockBlock[count]; - for(int j = 0; j < count; j++) - { LocationBlock[j] = new LocationBlockBlock(); } - } - for (int j = 0; j < count; j++) - { LocationBlock[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentBlock.Length; - length++; - for (int j = 0; j < LocationBlock.Length; j++) { length += LocationBlock[j].Length; } - if (Header.AckList != null && 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); - bytes[i++] = (byte)LocationBlock.Length; - for (int j = 0; j < LocationBlock.Length; j++) { LocationBlock[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentBlock.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentBlock.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int LocationBlockStart = 0; - do - { - int variableLength = 0; - int LocationBlockCount = 0; - - i = LocationBlockStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < LocationBlock.Length) { - int blockLength = LocationBlock[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == LocationBlockStart) { - variableLength += blockLength; - ++LocationBlockCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)LocationBlockCount; - for (i = LocationBlockStart; i < LocationBlockStart + LocationBlockCount; i++) { LocationBlock[i].ToBytes(packet, ref length); } - LocationBlockStart += LocationBlockCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - LocationBlockStart < LocationBlock.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class RequestGodlikePowersPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class RequestBlockBlock : PacketBlock - { - public bool Godlike; - public UUID Token; - - public override int Length - { - get - { - return 17; - } - } - - public RequestBlockBlock() { } - public RequestBlockBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - Godlike = (bytes[i++] != 0) ? (bool)true : (bool)false; - Token.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - bytes[i++] = (byte)((Godlike) ? 1 : 0); - Token.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += RequestBlock.Length; - return length; - } - } - public AgentDataBlock AgentData; - public RequestBlockBlock RequestBlock; - - public RequestGodlikePowersPacket() - { - HasVariableBlocks = false; - Type = PacketType.RequestGodlikePowers; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 257; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - RequestBlock = new RequestBlockBlock(); - } - - public RequestGodlikePowersPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - RequestBlock.FromBytes(bytes, ref i); - } - - public RequestGodlikePowersPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - RequestBlock.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += RequestBlock.Length; - if (Header.AckList != null && 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); - RequestBlock.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class GrantGodlikePowersPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class GrantDataBlock : PacketBlock - { - public byte GodLevel; - public UUID Token; - - public override int Length - { - get - { - return 17; - } - } - - public GrantDataBlock() { } - public GrantDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - GodLevel = (byte)bytes[i++]; - Token.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - bytes[i++] = GodLevel; - Token.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += GrantData.Length; - return length; - } - } - public AgentDataBlock AgentData; - public GrantDataBlock GrantData; - - public GrantGodlikePowersPacket() - { - HasVariableBlocks = false; - Type = PacketType.GrantGodlikePowers; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 258; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - GrantData = new GrantDataBlock(); - } - - public GrantGodlikePowersPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - GrantData.FromBytes(bytes, ref i); - } - - public GrantGodlikePowersPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - GrantData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += GrantData.Length; - if (Header.AckList != null && 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); - GrantData.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class GodlikeMessagePacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - public UUID TransactionID; - - public override int Length - { - get - { - return 48; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - TransactionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - TransactionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class MethodDataBlock : PacketBlock - { - public byte[] Method; - public UUID Invoice; - - public override int Length - { - get - { - int length = 17; - if (Method != null) { length += Method.Length; } - return length; - } - } - - public MethodDataBlock() { } - public MethodDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - length = bytes[i++]; - Method = new byte[length]; - Buffer.BlockCopy(bytes, i, Method, 0, length); i += length; - Invoice.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - bytes[i++] = (byte)Method.Length; - Buffer.BlockCopy(Method, 0, bytes, i, Method.Length); i += Method.Length; - Invoice.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class ParamListBlock : PacketBlock - { - public byte[] Parameter; - - public override int Length - { - get - { - int length = 1; - if (Parameter != null) { length += Parameter.Length; } - return length; - } - } - - public ParamListBlock() { } - public ParamListBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - length = bytes[i++]; - Parameter = new byte[length]; - Buffer.BlockCopy(bytes, i, Parameter, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - bytes[i++] = (byte)Parameter.Length; - Buffer.BlockCopy(Parameter, 0, bytes, i, Parameter.Length); i += Parameter.Length; - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentData.Length; - length += MethodData.Length; - for (int j = 0; j < ParamList.Length; j++) - length += ParamList[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public MethodDataBlock MethodData; - public ParamListBlock[] ParamList; - - public GodlikeMessagePacket() - { - HasVariableBlocks = true; - Type = PacketType.GodlikeMessage; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 259; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - MethodData = new MethodDataBlock(); - ParamList = null; - } - - public GodlikeMessagePacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - MethodData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ParamList == null || ParamList.Length != -1) { - ParamList = new ParamListBlock[count]; - for(int j = 0; j < count; j++) - { ParamList[j] = new ParamListBlock(); } - } - for (int j = 0; j < count; j++) - { ParamList[j].FromBytes(bytes, ref i); } - } - - public GodlikeMessagePacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - MethodData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ParamList == null || ParamList.Length != count) { - ParamList = new ParamListBlock[count]; - for(int j = 0; j < count; j++) - { ParamList[j] = new ParamListBlock(); } - } - for (int j = 0; j < count; j++) - { ParamList[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += MethodData.Length; - length++; - for (int j = 0; j < ParamList.Length; j++) { length += ParamList[j].Length; } - if (Header.AckList != null && 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); - 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - fixedLength += MethodData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - MethodData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int ParamListStart = 0; - do - { - int variableLength = 0; - int ParamListCount = 0; - - i = ParamListStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < ParamList.Length) { - int blockLength = ParamList[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ParamListStart) { - variableLength += blockLength; - ++ParamListCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)ParamListCount; - for (i = ParamListStart; i < ParamListStart + ParamListCount; i++) { ParamList[i].ToBytes(packet, ref length); } - ParamListStart += ParamListCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - ParamListStart < ParamList.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class EstateOwnerMessagePacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - public UUID TransactionID; - - public override int Length - { - get - { - return 48; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - TransactionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - TransactionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class MethodDataBlock : PacketBlock - { - public byte[] Method; - public UUID Invoice; - - public override int Length - { - get - { - int length = 17; - if (Method != null) { length += Method.Length; } - return length; - } - } - - public MethodDataBlock() { } - public MethodDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - length = bytes[i++]; - Method = new byte[length]; - Buffer.BlockCopy(bytes, i, Method, 0, length); i += length; - Invoice.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - bytes[i++] = (byte)Method.Length; - Buffer.BlockCopy(Method, 0, bytes, i, Method.Length); i += Method.Length; - Invoice.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class ParamListBlock : PacketBlock - { - public byte[] Parameter; - - public override int Length - { - get - { - int length = 1; - if (Parameter != null) { length += Parameter.Length; } - return length; - } - } - - public ParamListBlock() { } - public ParamListBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - length = bytes[i++]; - Parameter = new byte[length]; - Buffer.BlockCopy(bytes, i, Parameter, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - bytes[i++] = (byte)Parameter.Length; - Buffer.BlockCopy(Parameter, 0, bytes, i, Parameter.Length); i += Parameter.Length; - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentData.Length; - length += MethodData.Length; - for (int j = 0; j < ParamList.Length; j++) - length += ParamList[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public MethodDataBlock MethodData; - public ParamListBlock[] ParamList; - - public EstateOwnerMessagePacket() - { - HasVariableBlocks = true; - Type = PacketType.EstateOwnerMessage; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 260; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - MethodData = new MethodDataBlock(); - ParamList = null; - } - - public EstateOwnerMessagePacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - MethodData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ParamList == null || ParamList.Length != -1) { - ParamList = new ParamListBlock[count]; - for(int j = 0; j < count; j++) - { ParamList[j] = new ParamListBlock(); } - } - for (int j = 0; j < count; j++) - { ParamList[j].FromBytes(bytes, ref i); } - } - - public EstateOwnerMessagePacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - MethodData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ParamList == null || ParamList.Length != count) { - ParamList = new ParamListBlock[count]; - for(int j = 0; j < count; j++) - { ParamList[j] = new ParamListBlock(); } - } - for (int j = 0; j < count; j++) - { ParamList[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += MethodData.Length; - length++; - for (int j = 0; j < ParamList.Length; j++) { length += ParamList[j].Length; } - if (Header.AckList != null && 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); - 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - fixedLength += MethodData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - MethodData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int ParamListStart = 0; - do - { - int variableLength = 0; - int ParamListCount = 0; - - i = ParamListStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < ParamList.Length) { - int blockLength = ParamList[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ParamListStart) { - variableLength += blockLength; - ++ParamListCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)ParamListCount; - for (i = ParamListStart; i < ParamListStart + ParamListCount; i++) { ParamList[i].ToBytes(packet, ref length); } - ParamListStart += ParamListCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - ParamListStart < ParamList.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class GenericMessagePacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - public UUID TransactionID; - - public override int Length - { - get - { - return 48; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - TransactionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - TransactionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class MethodDataBlock : PacketBlock - { - public byte[] Method; - public UUID Invoice; - - public override int Length - { - get - { - int length = 17; - if (Method != null) { length += Method.Length; } - return length; - } - } - - public MethodDataBlock() { } - public MethodDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - length = bytes[i++]; - Method = new byte[length]; - Buffer.BlockCopy(bytes, i, Method, 0, length); i += length; - Invoice.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - bytes[i++] = (byte)Method.Length; - Buffer.BlockCopy(Method, 0, bytes, i, Method.Length); i += Method.Length; - Invoice.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class ParamListBlock : PacketBlock - { - public byte[] Parameter; - - public override int Length - { - get - { - int length = 1; - if (Parameter != null) { length += Parameter.Length; } - return length; - } - } - - public ParamListBlock() { } - public ParamListBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - length = bytes[i++]; - Parameter = new byte[length]; - Buffer.BlockCopy(bytes, i, Parameter, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - bytes[i++] = (byte)Parameter.Length; - Buffer.BlockCopy(Parameter, 0, bytes, i, Parameter.Length); i += Parameter.Length; - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentData.Length; - length += MethodData.Length; - for (int j = 0; j < ParamList.Length; j++) - length += ParamList[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public MethodDataBlock MethodData; - public ParamListBlock[] ParamList; - - public GenericMessagePacket() - { - HasVariableBlocks = true; - Type = PacketType.GenericMessage; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 261; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - MethodData = new MethodDataBlock(); - ParamList = null; - } - - public GenericMessagePacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - MethodData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ParamList == null || ParamList.Length != -1) { - ParamList = new ParamListBlock[count]; - for(int j = 0; j < count; j++) - { ParamList[j] = new ParamListBlock(); } - } - for (int j = 0; j < count; j++) - { ParamList[j].FromBytes(bytes, ref i); } - } - - public GenericMessagePacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - MethodData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ParamList == null || ParamList.Length != count) { - ParamList = new ParamListBlock[count]; - for(int j = 0; j < count; j++) - { ParamList[j] = new ParamListBlock(); } - } - for (int j = 0; j < count; j++) - { ParamList[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += MethodData.Length; - length++; - for (int j = 0; j < ParamList.Length; j++) { length += ParamList[j].Length; } - if (Header.AckList != null && 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); - 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - fixedLength += MethodData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - MethodData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int ParamListStart = 0; - do - { - int variableLength = 0; - int ParamListCount = 0; - - i = ParamListStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < ParamList.Length) { - int blockLength = ParamList[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ParamListStart) { - variableLength += blockLength; - ++ParamListCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)ParamListCount; - for (i = ParamListStart; i < ParamListStart + ParamListCount; i++) { ParamList[i].ToBytes(packet, ref length); } - ParamListStart += ParamListCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - ParamListStart < ParamList.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class MuteListRequestPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class MuteDataBlock : PacketBlock - { - public uint MuteCRC; - - public override int Length - { - get - { - return 4; - } - } - - public MuteDataBlock() { } - public MuteDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - MuteCRC = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UIntToBytes(MuteCRC, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += MuteData.Length; - return length; - } - } - public AgentDataBlock AgentData; - public MuteDataBlock MuteData; - - public MuteListRequestPacket() - { - HasVariableBlocks = false; - Type = PacketType.MuteListRequest; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 262; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - MuteData = new MuteDataBlock(); - } - - public MuteListRequestPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - MuteData.FromBytes(bytes, ref i); - } - - public MuteListRequestPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - MuteData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += MuteData.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class UpdateMuteListEntryPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class MuteDataBlock : PacketBlock - { - public UUID MuteID; - public byte[] MuteName; - public int MuteType; - public uint MuteFlags; - - public override int Length - { - get - { - int length = 25; - if (MuteName != null) { length += MuteName.Length; } - return length; - } - } - - public MuteDataBlock() { } - public MuteDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - MuteID.FromBytes(bytes, i); i += 16; - length = bytes[i++]; - MuteName = new byte[length]; - Buffer.BlockCopy(bytes, i, MuteName, 0, length); i += length; - MuteType = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - MuteFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - MuteID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)MuteName.Length; - Buffer.BlockCopy(MuteName, 0, bytes, i, MuteName.Length); i += MuteName.Length; - Utils.IntToBytes(MuteType, bytes, i); i += 4; - Utils.UIntToBytes(MuteFlags, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += MuteData.Length; - return length; - } - } - public AgentDataBlock AgentData; - public MuteDataBlock MuteData; - - public UpdateMuteListEntryPacket() - { - HasVariableBlocks = false; - Type = PacketType.UpdateMuteListEntry; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 263; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - MuteData = new MuteDataBlock(); - } - - public UpdateMuteListEntryPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - MuteData.FromBytes(bytes, ref i); - } - - public UpdateMuteListEntryPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - MuteData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += MuteData.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class RemoveMuteListEntryPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class MuteDataBlock : PacketBlock - { - public UUID MuteID; - public byte[] MuteName; - - public override int Length - { - get - { - int length = 17; - if (MuteName != null) { length += MuteName.Length; } - return length; - } - } - - public MuteDataBlock() { } - public MuteDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - MuteID.FromBytes(bytes, i); i += 16; - length = bytes[i++]; - MuteName = new byte[length]; - Buffer.BlockCopy(bytes, i, MuteName, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - MuteID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)MuteName.Length; - Buffer.BlockCopy(MuteName, 0, bytes, i, MuteName.Length); i += MuteName.Length; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += MuteData.Length; - return length; - } - } - public AgentDataBlock AgentData; - public MuteDataBlock MuteData; - - public RemoveMuteListEntryPacket() - { - HasVariableBlocks = false; - Type = PacketType.RemoveMuteListEntry; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 264; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - MuteData = new MuteDataBlock(); - } - - public RemoveMuteListEntryPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - MuteData.FromBytes(bytes, ref i); - } - - public RemoveMuteListEntryPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - MuteData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += MuteData.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class CopyInventoryFromNotecardPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class NotecardDataBlock : PacketBlock - { - public UUID NotecardItemID; - public UUID ObjectID; - - public override int Length - { - get - { - return 32; - } - } - - public NotecardDataBlock() { } - public NotecardDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - NotecardItemID.FromBytes(bytes, i); i += 16; - ObjectID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - NotecardItemID.ToBytes(bytes, i); i += 16; - ObjectID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class InventoryDataBlock : PacketBlock - { - public UUID ItemID; - public UUID FolderID; - - public override int Length - { - get - { - return 32; - } - } - - public InventoryDataBlock() { } - public InventoryDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - ItemID.FromBytes(bytes, i); i += 16; - FolderID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - ItemID.ToBytes(bytes, i); i += 16; - FolderID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentData.Length; - length += NotecardData.Length; - for (int j = 0; j < InventoryData.Length; j++) - length += InventoryData[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public NotecardDataBlock NotecardData; - public InventoryDataBlock[] InventoryData; - - public CopyInventoryFromNotecardPacket() - { - HasVariableBlocks = true; - Type = PacketType.CopyInventoryFromNotecard; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 265; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - NotecardData = new NotecardDataBlock(); - InventoryData = null; - } - - public CopyInventoryFromNotecardPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - NotecardData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(InventoryData == null || InventoryData.Length != -1) { - InventoryData = new InventoryDataBlock[count]; - for(int j = 0; j < count; j++) - { InventoryData[j] = new InventoryDataBlock(); } - } - for (int j = 0; j < count; j++) - { InventoryData[j].FromBytes(bytes, ref i); } - } - - public CopyInventoryFromNotecardPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - NotecardData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(InventoryData == null || InventoryData.Length != count) { - InventoryData = new InventoryDataBlock[count]; - for(int j = 0; j < count; j++) - { InventoryData[j] = new InventoryDataBlock(); } - } - for (int j = 0; j < count; j++) - { InventoryData[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += NotecardData.Length; - length++; - for (int j = 0; j < InventoryData.Length; j++) { length += InventoryData[j].Length; } - if (Header.AckList != null && 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); - NotecardData.ToBytes(bytes, ref i); - bytes[i++] = (byte)InventoryData.Length; - for (int j = 0; j < InventoryData.Length; j++) { InventoryData[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - fixedLength += NotecardData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - NotecardData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int InventoryDataStart = 0; - do - { - int variableLength = 0; - int InventoryDataCount = 0; - - i = InventoryDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < InventoryData.Length) { - int blockLength = InventoryData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == InventoryDataStart) { - variableLength += blockLength; - ++InventoryDataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)InventoryDataCount; - for (i = InventoryDataStart; i < InventoryDataStart + InventoryDataCount; i++) { InventoryData[i].ToBytes(packet, ref length); } - InventoryDataStart += InventoryDataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - InventoryDataStart < InventoryData.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class UpdateInventoryItemPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - public UUID TransactionID; - - public override int Length - { - get - { - return 48; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - TransactionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - TransactionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class InventoryDataBlock : PacketBlock - { - public UUID ItemID; - public UUID FolderID; - public uint CallbackID; - public UUID CreatorID; - public UUID OwnerID; - public UUID GroupID; - public uint BaseMask; - public uint OwnerMask; - public uint GroupMask; - public uint EveryoneMask; - public uint NextOwnerMask; - public bool GroupOwned; - public UUID TransactionID; - public sbyte Type; - public sbyte InvType; - public uint Flags; - public byte SaleType; - public int SalePrice; - public byte[] Name; - public byte[] Description; - public int CreationDate; - public uint CRC; - - public override int Length - { - get - { - int length = 142; - if (Name != null) { length += Name.Length; } - if (Description != null) { length += Description.Length; } - return length; - } - } - - public InventoryDataBlock() { } - public InventoryDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - ItemID.FromBytes(bytes, i); i += 16; - FolderID.FromBytes(bytes, i); i += 16; - CallbackID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - CreatorID.FromBytes(bytes, i); i += 16; - OwnerID.FromBytes(bytes, i); i += 16; - GroupID.FromBytes(bytes, i); i += 16; - BaseMask = (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)); - GroupMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - 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)); - GroupOwned = (bytes[i++] != 0) ? (bool)true : (bool)false; - TransactionID.FromBytes(bytes, i); i += 16; - Type = (sbyte)bytes[i++]; - InvType = (sbyte)bytes[i++]; - Flags = (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)); - length = bytes[i++]; - Name = new byte[length]; - Buffer.BlockCopy(bytes, i, Name, 0, length); i += length; - length = bytes[i++]; - Description = new byte[length]; - Buffer.BlockCopy(bytes, i, Description, 0, length); i += length; - CreationDate = (int)(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(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - ItemID.ToBytes(bytes, i); i += 16; - FolderID.ToBytes(bytes, i); i += 16; - Utils.UIntToBytes(CallbackID, bytes, i); i += 4; - CreatorID.ToBytes(bytes, i); i += 16; - OwnerID.ToBytes(bytes, i); i += 16; - GroupID.ToBytes(bytes, i); i += 16; - Utils.UIntToBytes(BaseMask, bytes, i); i += 4; - Utils.UIntToBytes(OwnerMask, bytes, i); i += 4; - Utils.UIntToBytes(GroupMask, bytes, i); i += 4; - Utils.UIntToBytes(EveryoneMask, bytes, i); i += 4; - Utils.UIntToBytes(NextOwnerMask, bytes, i); i += 4; - bytes[i++] = (byte)((GroupOwned) ? 1 : 0); - TransactionID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)Type; - bytes[i++] = (byte)InvType; - Utils.UIntToBytes(Flags, bytes, i); i += 4; - bytes[i++] = SaleType; - Utils.IntToBytes(SalePrice, bytes, i); i += 4; - bytes[i++] = (byte)Name.Length; - Buffer.BlockCopy(Name, 0, bytes, i, Name.Length); i += Name.Length; - bytes[i++] = (byte)Description.Length; - Buffer.BlockCopy(Description, 0, bytes, i, Description.Length); i += Description.Length; - Utils.IntToBytes(CreationDate, bytes, i); i += 4; - Utils.UIntToBytes(CRC, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentData.Length; - for (int j = 0; j < InventoryData.Length; j++) - length += InventoryData[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public InventoryDataBlock[] InventoryData; - - public UpdateInventoryItemPacket() - { - HasVariableBlocks = true; - Type = PacketType.UpdateInventoryItem; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 266; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - InventoryData = null; - } - - public UpdateInventoryItemPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(InventoryData == null || InventoryData.Length != -1) { - InventoryData = new InventoryDataBlock[count]; - for(int j = 0; j < count; j++) - { InventoryData[j] = new InventoryDataBlock(); } - } - for (int j = 0; j < count; j++) - { InventoryData[j].FromBytes(bytes, ref i); } - } - - public UpdateInventoryItemPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(InventoryData == null || InventoryData.Length != count) { - InventoryData = new InventoryDataBlock[count]; - for(int j = 0; j < count; j++) - { InventoryData[j] = new InventoryDataBlock(); } - } - for (int j = 0; j < count; j++) - { InventoryData[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length++; - for (int j = 0; j < InventoryData.Length; j++) { length += InventoryData[j].Length; } - if (Header.AckList != null && 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)InventoryData.Length; - for (int j = 0; j < InventoryData.Length; j++) { InventoryData[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int InventoryDataStart = 0; - do - { - int variableLength = 0; - int InventoryDataCount = 0; - - i = InventoryDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < InventoryData.Length) { - int blockLength = InventoryData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == InventoryDataStart) { - variableLength += blockLength; - ++InventoryDataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)InventoryDataCount; - for (i = InventoryDataStart; i < InventoryDataStart + InventoryDataCount; i++) { InventoryData[i].ToBytes(packet, ref length); } - InventoryDataStart += InventoryDataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - InventoryDataStart < InventoryData.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class UpdateCreateInventoryItemPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public bool SimApproved; - public UUID TransactionID; - - public override int Length - { - get - { - return 33; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SimApproved = (bytes[i++] != 0) ? (bool)true : (bool)false; - TransactionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)((SimApproved) ? 1 : 0); - TransactionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class InventoryDataBlock : PacketBlock - { - public UUID ItemID; - public UUID FolderID; - public uint CallbackID; - public UUID CreatorID; - public UUID OwnerID; - public UUID GroupID; - public uint BaseMask; - public uint OwnerMask; - public uint GroupMask; - public uint EveryoneMask; - public uint NextOwnerMask; - public bool GroupOwned; - public UUID AssetID; - public sbyte Type; - public sbyte InvType; - public uint Flags; - public byte SaleType; - public int SalePrice; - public byte[] Name; - public byte[] Description; - public int CreationDate; - public uint CRC; - - public override int Length - { - get - { - int length = 142; - if (Name != null) { length += Name.Length; } - if (Description != null) { length += Description.Length; } - return length; - } - } - - public InventoryDataBlock() { } - public InventoryDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - ItemID.FromBytes(bytes, i); i += 16; - FolderID.FromBytes(bytes, i); i += 16; - CallbackID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - CreatorID.FromBytes(bytes, i); i += 16; - OwnerID.FromBytes(bytes, i); i += 16; - GroupID.FromBytes(bytes, i); i += 16; - BaseMask = (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)); - GroupMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - 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)); - GroupOwned = (bytes[i++] != 0) ? (bool)true : (bool)false; - AssetID.FromBytes(bytes, i); i += 16; - Type = (sbyte)bytes[i++]; - InvType = (sbyte)bytes[i++]; - Flags = (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)); - length = bytes[i++]; - Name = new byte[length]; - Buffer.BlockCopy(bytes, i, Name, 0, length); i += length; - length = bytes[i++]; - Description = new byte[length]; - Buffer.BlockCopy(bytes, i, Description, 0, length); i += length; - CreationDate = (int)(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(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - ItemID.ToBytes(bytes, i); i += 16; - FolderID.ToBytes(bytes, i); i += 16; - Utils.UIntToBytes(CallbackID, bytes, i); i += 4; - CreatorID.ToBytes(bytes, i); i += 16; - OwnerID.ToBytes(bytes, i); i += 16; - GroupID.ToBytes(bytes, i); i += 16; - Utils.UIntToBytes(BaseMask, bytes, i); i += 4; - Utils.UIntToBytes(OwnerMask, bytes, i); i += 4; - Utils.UIntToBytes(GroupMask, bytes, i); i += 4; - Utils.UIntToBytes(EveryoneMask, bytes, i); i += 4; - Utils.UIntToBytes(NextOwnerMask, bytes, i); i += 4; - bytes[i++] = (byte)((GroupOwned) ? 1 : 0); - AssetID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)Type; - bytes[i++] = (byte)InvType; - Utils.UIntToBytes(Flags, bytes, i); i += 4; - bytes[i++] = SaleType; - Utils.IntToBytes(SalePrice, bytes, i); i += 4; - bytes[i++] = (byte)Name.Length; - Buffer.BlockCopy(Name, 0, bytes, i, Name.Length); i += Name.Length; - bytes[i++] = (byte)Description.Length; - Buffer.BlockCopy(Description, 0, bytes, i, Description.Length); i += Description.Length; - Utils.IntToBytes(CreationDate, bytes, i); i += 4; - Utils.UIntToBytes(CRC, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentData.Length; - for (int j = 0; j < InventoryData.Length; j++) - length += InventoryData[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public InventoryDataBlock[] InventoryData; - - public UpdateCreateInventoryItemPacket() - { - HasVariableBlocks = true; - Type = PacketType.UpdateCreateInventoryItem; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 267; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - InventoryData = null; - } - - public UpdateCreateInventoryItemPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(InventoryData == null || InventoryData.Length != -1) { - InventoryData = new InventoryDataBlock[count]; - for(int j = 0; j < count; j++) - { InventoryData[j] = new InventoryDataBlock(); } - } - for (int j = 0; j < count; j++) - { InventoryData[j].FromBytes(bytes, ref i); } - } - - public UpdateCreateInventoryItemPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(InventoryData == null || InventoryData.Length != count) { - InventoryData = new InventoryDataBlock[count]; - for(int j = 0; j < count; j++) - { InventoryData[j] = new InventoryDataBlock(); } - } - for (int j = 0; j < count; j++) - { InventoryData[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length++; - for (int j = 0; j < InventoryData.Length; j++) { length += InventoryData[j].Length; } - if (Header.AckList != null && 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)InventoryData.Length; - for (int j = 0; j < InventoryData.Length; j++) { InventoryData[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int InventoryDataStart = 0; - do - { - int variableLength = 0; - int InventoryDataCount = 0; - - i = InventoryDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < InventoryData.Length) { - int blockLength = InventoryData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == InventoryDataStart) { - variableLength += blockLength; - ++InventoryDataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)InventoryDataCount; - for (i = InventoryDataStart; i < InventoryDataStart + InventoryDataCount; i++) { InventoryData[i].ToBytes(packet, ref length); } - InventoryDataStart += InventoryDataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - InventoryDataStart < InventoryData.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class MoveInventoryItemPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - public bool Stamp; - - public override int Length - { - get - { - return 33; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - Stamp = (bytes[i++] != 0) ? (bool)true : (bool)false; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)((Stamp) ? 1 : 0); - } - - } - - /// - public sealed class InventoryDataBlock : PacketBlock - { - public UUID ItemID; - public UUID FolderID; - public byte[] NewName; - - public override int Length - { - get - { - int length = 33; - if (NewName != null) { length += NewName.Length; } - return length; - } - } - - public InventoryDataBlock() { } - public InventoryDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - ItemID.FromBytes(bytes, i); i += 16; - FolderID.FromBytes(bytes, i); i += 16; - length = bytes[i++]; - NewName = new byte[length]; - Buffer.BlockCopy(bytes, i, NewName, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - ItemID.ToBytes(bytes, i); i += 16; - FolderID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)NewName.Length; - Buffer.BlockCopy(NewName, 0, bytes, i, NewName.Length); i += NewName.Length; - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentData.Length; - for (int j = 0; j < InventoryData.Length; j++) - length += InventoryData[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public InventoryDataBlock[] InventoryData; - - public MoveInventoryItemPacket() - { - HasVariableBlocks = true; - Type = PacketType.MoveInventoryItem; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 268; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - InventoryData = null; - } - - public MoveInventoryItemPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(InventoryData == null || InventoryData.Length != -1) { - InventoryData = new InventoryDataBlock[count]; - for(int j = 0; j < count; j++) - { InventoryData[j] = new InventoryDataBlock(); } - } - for (int j = 0; j < count; j++) - { InventoryData[j].FromBytes(bytes, ref i); } - } - - public MoveInventoryItemPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(InventoryData == null || InventoryData.Length != count) { - InventoryData = new InventoryDataBlock[count]; - for(int j = 0; j < count; j++) - { InventoryData[j] = new InventoryDataBlock(); } - } - for (int j = 0; j < count; j++) - { InventoryData[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length++; - for (int j = 0; j < InventoryData.Length; j++) { length += InventoryData[j].Length; } - if (Header.AckList != null && 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)InventoryData.Length; - for (int j = 0; j < InventoryData.Length; j++) { InventoryData[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int InventoryDataStart = 0; - do - { - int variableLength = 0; - int InventoryDataCount = 0; - - i = InventoryDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < InventoryData.Length) { - int blockLength = InventoryData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == InventoryDataStart) { - variableLength += blockLength; - ++InventoryDataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)InventoryDataCount; - for (i = InventoryDataStart; i < InventoryDataStart + InventoryDataCount; i++) { InventoryData[i].ToBytes(packet, ref length); } - InventoryDataStart += InventoryDataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - InventoryDataStart < InventoryData.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class CopyInventoryItemPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class InventoryDataBlock : PacketBlock - { - public uint CallbackID; - public UUID OldAgentID; - public UUID OldItemID; - public UUID NewFolderID; - public byte[] NewName; - - public override int Length - { - get - { - int length = 53; - if (NewName != null) { length += NewName.Length; } - return length; - } - } - - public InventoryDataBlock() { } - public InventoryDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - CallbackID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - OldAgentID.FromBytes(bytes, i); i += 16; - OldItemID.FromBytes(bytes, i); i += 16; - NewFolderID.FromBytes(bytes, i); i += 16; - length = bytes[i++]; - NewName = new byte[length]; - Buffer.BlockCopy(bytes, i, NewName, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UIntToBytes(CallbackID, bytes, i); i += 4; - OldAgentID.ToBytes(bytes, i); i += 16; - OldItemID.ToBytes(bytes, i); i += 16; - NewFolderID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)NewName.Length; - Buffer.BlockCopy(NewName, 0, bytes, i, NewName.Length); i += NewName.Length; - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentData.Length; - for (int j = 0; j < InventoryData.Length; j++) - length += InventoryData[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public InventoryDataBlock[] InventoryData; - - public CopyInventoryItemPacket() - { - HasVariableBlocks = true; - Type = PacketType.CopyInventoryItem; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 269; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - InventoryData = null; - } - - public CopyInventoryItemPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(InventoryData == null || InventoryData.Length != -1) { - InventoryData = new InventoryDataBlock[count]; - for(int j = 0; j < count; j++) - { InventoryData[j] = new InventoryDataBlock(); } - } - for (int j = 0; j < count; j++) - { InventoryData[j].FromBytes(bytes, ref i); } - } - - public CopyInventoryItemPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(InventoryData == null || InventoryData.Length != count) { - InventoryData = new InventoryDataBlock[count]; - for(int j = 0; j < count; j++) - { InventoryData[j] = new InventoryDataBlock(); } - } - for (int j = 0; j < count; j++) - { InventoryData[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length++; - for (int j = 0; j < InventoryData.Length; j++) { length += InventoryData[j].Length; } - if (Header.AckList != null && 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)InventoryData.Length; - for (int j = 0; j < InventoryData.Length; j++) { InventoryData[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int InventoryDataStart = 0; - do - { - int variableLength = 0; - int InventoryDataCount = 0; - - i = InventoryDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < InventoryData.Length) { - int blockLength = InventoryData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == InventoryDataStart) { - variableLength += blockLength; - ++InventoryDataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)InventoryDataCount; - for (i = InventoryDataStart; i < InventoryDataStart + InventoryDataCount; i++) { InventoryData[i].ToBytes(packet, ref length); } - InventoryDataStart += InventoryDataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - InventoryDataStart < InventoryData.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class RemoveInventoryItemPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class InventoryDataBlock : PacketBlock - { - public UUID ItemID; - - public override int Length - { - get - { - return 16; - } - } - - public InventoryDataBlock() { } - public InventoryDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - ItemID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - ItemID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentData.Length; - for (int j = 0; j < InventoryData.Length; j++) - length += InventoryData[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public InventoryDataBlock[] InventoryData; - - public RemoveInventoryItemPacket() - { - HasVariableBlocks = true; - Type = PacketType.RemoveInventoryItem; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 270; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - InventoryData = null; - } - - public RemoveInventoryItemPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(InventoryData == null || InventoryData.Length != -1) { - InventoryData = new InventoryDataBlock[count]; - for(int j = 0; j < count; j++) - { InventoryData[j] = new InventoryDataBlock(); } - } - for (int j = 0; j < count; j++) - { InventoryData[j].FromBytes(bytes, ref i); } - } - - public RemoveInventoryItemPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(InventoryData == null || InventoryData.Length != count) { - InventoryData = new InventoryDataBlock[count]; - for(int j = 0; j < count; j++) - { InventoryData[j] = new InventoryDataBlock(); } - } - for (int j = 0; j < count; j++) - { InventoryData[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length++; - for (int j = 0; j < InventoryData.Length; j++) { length += InventoryData[j].Length; } - if (Header.AckList != null && 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)InventoryData.Length; - for (int j = 0; j < InventoryData.Length; j++) { InventoryData[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int InventoryDataStart = 0; - do - { - int variableLength = 0; - int InventoryDataCount = 0; - - i = InventoryDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < InventoryData.Length) { - int blockLength = InventoryData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == InventoryDataStart) { - variableLength += blockLength; - ++InventoryDataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)InventoryDataCount; - for (i = InventoryDataStart; i < InventoryDataStart + InventoryDataCount; i++) { InventoryData[i].ToBytes(packet, ref length); } - InventoryDataStart += InventoryDataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - InventoryDataStart < InventoryData.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class ChangeInventoryItemFlagsPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class InventoryDataBlock : PacketBlock - { - public UUID ItemID; - public uint Flags; - - public override int Length - { - get - { - return 20; - } - } - - public InventoryDataBlock() { } - public InventoryDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - ItemID.FromBytes(bytes, i); i += 16; - Flags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - ItemID.ToBytes(bytes, i); i += 16; - Utils.UIntToBytes(Flags, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentData.Length; - for (int j = 0; j < InventoryData.Length; j++) - length += InventoryData[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public InventoryDataBlock[] InventoryData; - - public ChangeInventoryItemFlagsPacket() - { - HasVariableBlocks = true; - Type = PacketType.ChangeInventoryItemFlags; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 271; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - InventoryData = null; - } - - public ChangeInventoryItemFlagsPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(InventoryData == null || InventoryData.Length != -1) { - InventoryData = new InventoryDataBlock[count]; - for(int j = 0; j < count; j++) - { InventoryData[j] = new InventoryDataBlock(); } - } - for (int j = 0; j < count; j++) - { InventoryData[j].FromBytes(bytes, ref i); } - } - - public ChangeInventoryItemFlagsPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(InventoryData == null || InventoryData.Length != count) { - InventoryData = new InventoryDataBlock[count]; - for(int j = 0; j < count; j++) - { InventoryData[j] = new InventoryDataBlock(); } - } - for (int j = 0; j < count; j++) - { InventoryData[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length++; - for (int j = 0; j < InventoryData.Length; j++) { length += InventoryData[j].Length; } - if (Header.AckList != null && 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)InventoryData.Length; - for (int j = 0; j < InventoryData.Length; j++) { InventoryData[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int InventoryDataStart = 0; - do - { - int variableLength = 0; - int InventoryDataCount = 0; - - i = InventoryDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < InventoryData.Length) { - int blockLength = InventoryData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == InventoryDataStart) { - variableLength += blockLength; - ++InventoryDataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)InventoryDataCount; - for (i = InventoryDataStart; i < InventoryDataStart + InventoryDataCount; i++) { InventoryData[i].ToBytes(packet, ref length); } - InventoryDataStart += InventoryDataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - InventoryDataStart < InventoryData.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class SaveAssetIntoInventoryPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - - public override int Length - { - get - { - return 16; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class InventoryDataBlock : PacketBlock - { - public UUID ItemID; - public UUID NewAssetID; - - public override int Length - { - get - { - return 32; - } - } - - public InventoryDataBlock() { } - public InventoryDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - ItemID.FromBytes(bytes, i); i += 16; - NewAssetID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - ItemID.ToBytes(bytes, i); i += 16; - NewAssetID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += InventoryData.Length; - return length; - } - } - public AgentDataBlock AgentData; - public InventoryDataBlock InventoryData; - - public SaveAssetIntoInventoryPacket() - { - HasVariableBlocks = false; - Type = PacketType.SaveAssetIntoInventory; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 272; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - InventoryData = new InventoryDataBlock(); - } - - public SaveAssetIntoInventoryPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - InventoryData.FromBytes(bytes, ref i); - } - - public SaveAssetIntoInventoryPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - InventoryData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += InventoryData.Length; - if (Header.AckList != null && 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); - InventoryData.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class CreateInventoryFolderPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class FolderDataBlock : PacketBlock - { - public UUID FolderID; - public UUID ParentID; - public sbyte Type; - public byte[] Name; - - public override int Length - { - get - { - int length = 34; - if (Name != null) { length += Name.Length; } - return length; - } - } - - public FolderDataBlock() { } - public FolderDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - FolderID.FromBytes(bytes, i); i += 16; - ParentID.FromBytes(bytes, i); i += 16; - Type = (sbyte)bytes[i++]; - length = bytes[i++]; - Name = new byte[length]; - Buffer.BlockCopy(bytes, i, Name, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - FolderID.ToBytes(bytes, i); i += 16; - ParentID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)Type; - bytes[i++] = (byte)Name.Length; - Buffer.BlockCopy(Name, 0, bytes, i, Name.Length); i += Name.Length; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += FolderData.Length; - return length; - } - } - public AgentDataBlock AgentData; - public FolderDataBlock FolderData; - - public CreateInventoryFolderPacket() - { - HasVariableBlocks = false; - Type = PacketType.CreateInventoryFolder; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 273; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - FolderData = new FolderDataBlock(); - } - - public CreateInventoryFolderPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - FolderData.FromBytes(bytes, ref i); - } - - public CreateInventoryFolderPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - FolderData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += FolderData.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class UpdateInventoryFolderPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class FolderDataBlock : PacketBlock - { - public UUID FolderID; - public UUID ParentID; - public sbyte Type; - public byte[] Name; - - public override int Length - { - get - { - int length = 34; - if (Name != null) { length += Name.Length; } - return length; - } - } - - public FolderDataBlock() { } - public FolderDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - FolderID.FromBytes(bytes, i); i += 16; - ParentID.FromBytes(bytes, i); i += 16; - Type = (sbyte)bytes[i++]; - length = bytes[i++]; - Name = new byte[length]; - Buffer.BlockCopy(bytes, i, Name, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - FolderID.ToBytes(bytes, i); i += 16; - ParentID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)Type; - bytes[i++] = (byte)Name.Length; - Buffer.BlockCopy(Name, 0, bytes, i, Name.Length); i += Name.Length; - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentData.Length; - for (int j = 0; j < FolderData.Length; j++) - length += FolderData[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public FolderDataBlock[] FolderData; - - public UpdateInventoryFolderPacket() - { - HasVariableBlocks = true; - Type = PacketType.UpdateInventoryFolder; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 274; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - FolderData = null; - } - - public UpdateInventoryFolderPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(FolderData == null || FolderData.Length != -1) { - FolderData = new FolderDataBlock[count]; - for(int j = 0; j < count; j++) - { FolderData[j] = new FolderDataBlock(); } - } - for (int j = 0; j < count; j++) - { FolderData[j].FromBytes(bytes, ref i); } - } - - public UpdateInventoryFolderPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(FolderData == null || FolderData.Length != count) { - FolderData = new FolderDataBlock[count]; - for(int j = 0; j < count; j++) - { FolderData[j] = new FolderDataBlock(); } - } - for (int j = 0; j < count; j++) - { FolderData[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length++; - for (int j = 0; j < FolderData.Length; j++) { length += FolderData[j].Length; } - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int FolderDataStart = 0; - do - { - int variableLength = 0; - int FolderDataCount = 0; - - i = FolderDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < FolderData.Length) { - int blockLength = FolderData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == FolderDataStart) { - variableLength += blockLength; - ++FolderDataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)FolderDataCount; - for (i = FolderDataStart; i < FolderDataStart + FolderDataCount; i++) { FolderData[i].ToBytes(packet, ref length); } - FolderDataStart += FolderDataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - FolderDataStart < FolderData.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class MoveInventoryFolderPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - public bool Stamp; - - public override int Length - { - get - { - return 33; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - Stamp = (bytes[i++] != 0) ? (bool)true : (bool)false; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)((Stamp) ? 1 : 0); - } - - } - - /// - public sealed class InventoryDataBlock : PacketBlock - { - public UUID FolderID; - public UUID ParentID; - - public override int Length - { - get - { - return 32; - } - } - - public InventoryDataBlock() { } - public InventoryDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - FolderID.FromBytes(bytes, i); i += 16; - ParentID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - FolderID.ToBytes(bytes, i); i += 16; - ParentID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentData.Length; - for (int j = 0; j < InventoryData.Length; j++) - length += InventoryData[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public InventoryDataBlock[] InventoryData; - - public MoveInventoryFolderPacket() - { - HasVariableBlocks = true; - Type = PacketType.MoveInventoryFolder; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 275; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - InventoryData = null; - } - - public MoveInventoryFolderPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(InventoryData == null || InventoryData.Length != -1) { - InventoryData = new InventoryDataBlock[count]; - for(int j = 0; j < count; j++) - { InventoryData[j] = new InventoryDataBlock(); } - } - for (int j = 0; j < count; j++) - { InventoryData[j].FromBytes(bytes, ref i); } - } - - public MoveInventoryFolderPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(InventoryData == null || InventoryData.Length != count) { - InventoryData = new InventoryDataBlock[count]; - for(int j = 0; j < count; j++) - { InventoryData[j] = new InventoryDataBlock(); } - } - for (int j = 0; j < count; j++) - { InventoryData[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length++; - for (int j = 0; j < InventoryData.Length; j++) { length += InventoryData[j].Length; } - if (Header.AckList != null && 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)InventoryData.Length; - for (int j = 0; j < InventoryData.Length; j++) { InventoryData[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int InventoryDataStart = 0; - do - { - int variableLength = 0; - int InventoryDataCount = 0; - - i = InventoryDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < InventoryData.Length) { - int blockLength = InventoryData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == InventoryDataStart) { - variableLength += blockLength; - ++InventoryDataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)InventoryDataCount; - for (i = InventoryDataStart; i < InventoryDataStart + InventoryDataCount; i++) { InventoryData[i].ToBytes(packet, ref length); } - InventoryDataStart += InventoryDataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - InventoryDataStart < InventoryData.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class RemoveInventoryFolderPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class FolderDataBlock : PacketBlock - { - public UUID FolderID; - - public override int Length - { - get - { - return 16; - } - } - - public FolderDataBlock() { } - public FolderDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - FolderID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - FolderID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentData.Length; - for (int j = 0; j < FolderData.Length; j++) - length += FolderData[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public FolderDataBlock[] FolderData; - - public RemoveInventoryFolderPacket() - { - HasVariableBlocks = true; - Type = PacketType.RemoveInventoryFolder; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 276; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - FolderData = null; - } - - public RemoveInventoryFolderPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(FolderData == null || FolderData.Length != -1) { - FolderData = new FolderDataBlock[count]; - for(int j = 0; j < count; j++) - { FolderData[j] = new FolderDataBlock(); } - } - for (int j = 0; j < count; j++) - { FolderData[j].FromBytes(bytes, ref i); } - } - - public RemoveInventoryFolderPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(FolderData == null || FolderData.Length != count) { - FolderData = new FolderDataBlock[count]; - for(int j = 0; j < count; j++) - { FolderData[j] = new FolderDataBlock(); } - } - for (int j = 0; j < count; j++) - { FolderData[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length++; - for (int j = 0; j < FolderData.Length; j++) { length += FolderData[j].Length; } - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int FolderDataStart = 0; - do - { - int variableLength = 0; - int FolderDataCount = 0; - - i = FolderDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < FolderData.Length) { - int blockLength = FolderData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == FolderDataStart) { - variableLength += blockLength; - ++FolderDataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)FolderDataCount; - for (i = FolderDataStart; i < FolderDataStart + FolderDataCount; i++) { FolderData[i].ToBytes(packet, ref length); } - FolderDataStart += FolderDataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - FolderDataStart < FolderData.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class FetchInventoryDescendentsPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class InventoryDataBlock : PacketBlock - { - public UUID FolderID; - public UUID OwnerID; - public int SortOrder; - public bool FetchFolders; - public bool FetchItems; - - public override int Length - { - get - { - return 38; - } - } - - public InventoryDataBlock() { } - public InventoryDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - FolderID.FromBytes(bytes, i); i += 16; - OwnerID.FromBytes(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(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - FolderID.ToBytes(bytes, i); i += 16; - OwnerID.ToBytes(bytes, i); i += 16; - Utils.IntToBytes(SortOrder, bytes, i); i += 4; - bytes[i++] = (byte)((FetchFolders) ? 1 : 0); - bytes[i++] = (byte)((FetchItems) ? 1 : 0); - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += InventoryData.Length; - return length; - } - } - public AgentDataBlock AgentData; - public InventoryDataBlock InventoryData; - - public FetchInventoryDescendentsPacket() - { - HasVariableBlocks = false; - Type = PacketType.FetchInventoryDescendents; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 277; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - InventoryData = new InventoryDataBlock(); - } - - public FetchInventoryDescendentsPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - InventoryData.FromBytes(bytes, ref i); - } - - public FetchInventoryDescendentsPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - InventoryData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += InventoryData.Length; - if (Header.AckList != null && 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); - InventoryData.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class InventoryDescendentsPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID FolderID; - public UUID OwnerID; - public int Version; - public int Descendents; - - public override int Length - { - get - { - return 56; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - FolderID.FromBytes(bytes, i); i += 16; - OwnerID.FromBytes(bytes, i); i += 16; - Version = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - Descendents = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - FolderID.ToBytes(bytes, i); i += 16; - OwnerID.ToBytes(bytes, i); i += 16; - Utils.IntToBytes(Version, bytes, i); i += 4; - Utils.IntToBytes(Descendents, bytes, i); i += 4; - } - - } - - /// - public sealed class FolderDataBlock : PacketBlock - { - public UUID FolderID; - public UUID ParentID; - public sbyte Type; - public byte[] Name; - - public override int Length - { - get - { - int length = 34; - if (Name != null) { length += Name.Length; } - return length; - } - } - - public FolderDataBlock() { } - public FolderDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - FolderID.FromBytes(bytes, i); i += 16; - ParentID.FromBytes(bytes, i); i += 16; - Type = (sbyte)bytes[i++]; - length = bytes[i++]; - Name = new byte[length]; - Buffer.BlockCopy(bytes, i, Name, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - FolderID.ToBytes(bytes, i); i += 16; - ParentID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)Type; - bytes[i++] = (byte)Name.Length; - Buffer.BlockCopy(Name, 0, bytes, i, Name.Length); i += Name.Length; - } - - } - - /// - public sealed class ItemDataBlock : PacketBlock - { - public UUID ItemID; - public UUID FolderID; - public UUID CreatorID; - public UUID OwnerID; - public UUID GroupID; - public uint BaseMask; - public uint OwnerMask; - public uint GroupMask; - public uint EveryoneMask; - public uint NextOwnerMask; - public bool GroupOwned; - public UUID AssetID; - public sbyte Type; - public sbyte InvType; - public uint Flags; - public byte SaleType; - public int SalePrice; - public byte[] Name; - public byte[] Description; - public int CreationDate; - public uint CRC; - - public override int Length - { - get - { - int length = 138; - if (Name != null) { length += Name.Length; } - if (Description != null) { length += Description.Length; } - return length; - } - } - - public ItemDataBlock() { } - public ItemDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - ItemID.FromBytes(bytes, i); i += 16; - FolderID.FromBytes(bytes, i); i += 16; - CreatorID.FromBytes(bytes, i); i += 16; - OwnerID.FromBytes(bytes, i); i += 16; - GroupID.FromBytes(bytes, i); i += 16; - BaseMask = (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)); - GroupMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - 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)); - GroupOwned = (bytes[i++] != 0) ? (bool)true : (bool)false; - AssetID.FromBytes(bytes, i); i += 16; - Type = (sbyte)bytes[i++]; - InvType = (sbyte)bytes[i++]; - Flags = (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)); - length = bytes[i++]; - Name = new byte[length]; - Buffer.BlockCopy(bytes, i, Name, 0, length); i += length; - length = bytes[i++]; - Description = new byte[length]; - Buffer.BlockCopy(bytes, i, Description, 0, length); i += length; - CreationDate = (int)(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(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - ItemID.ToBytes(bytes, i); i += 16; - FolderID.ToBytes(bytes, i); i += 16; - CreatorID.ToBytes(bytes, i); i += 16; - OwnerID.ToBytes(bytes, i); i += 16; - GroupID.ToBytes(bytes, i); i += 16; - Utils.UIntToBytes(BaseMask, bytes, i); i += 4; - Utils.UIntToBytes(OwnerMask, bytes, i); i += 4; - Utils.UIntToBytes(GroupMask, bytes, i); i += 4; - Utils.UIntToBytes(EveryoneMask, bytes, i); i += 4; - Utils.UIntToBytes(NextOwnerMask, bytes, i); i += 4; - bytes[i++] = (byte)((GroupOwned) ? 1 : 0); - AssetID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)Type; - bytes[i++] = (byte)InvType; - Utils.UIntToBytes(Flags, bytes, i); i += 4; - bytes[i++] = SaleType; - Utils.IntToBytes(SalePrice, bytes, i); i += 4; - bytes[i++] = (byte)Name.Length; - Buffer.BlockCopy(Name, 0, bytes, i, Name.Length); i += Name.Length; - bytes[i++] = (byte)Description.Length; - Buffer.BlockCopy(Description, 0, bytes, i, Description.Length); i += Description.Length; - Utils.IntToBytes(CreationDate, bytes, i); i += 4; - Utils.UIntToBytes(CRC, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 12; - length += AgentData.Length; - for (int j = 0; j < FolderData.Length; j++) - length += FolderData[j].Length; - for (int j = 0; j < ItemData.Length; j++) - length += ItemData[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public FolderDataBlock[] FolderData; - public ItemDataBlock[] ItemData; - - public InventoryDescendentsPacket() - { - HasVariableBlocks = true; - Type = PacketType.InventoryDescendents; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 278; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - FolderData = null; - ItemData = null; - } - - public InventoryDescendentsPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(FolderData == null || FolderData.Length != -1) { - FolderData = new FolderDataBlock[count]; - for(int j = 0; j < count; j++) - { FolderData[j] = new FolderDataBlock(); } - } - for (int j = 0; j < count; j++) - { FolderData[j].FromBytes(bytes, ref i); } - count = (int)bytes[i++]; - if(ItemData == null || ItemData.Length != -1) { - ItemData = new ItemDataBlock[count]; - for(int j = 0; j < count; j++) - { ItemData[j] = new ItemDataBlock(); } - } - for (int j = 0; j < count; j++) - { ItemData[j].FromBytes(bytes, ref i); } - } - - public InventoryDescendentsPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(FolderData == null || FolderData.Length != count) { - FolderData = new FolderDataBlock[count]; - for(int j = 0; j < count; j++) - { FolderData[j] = new FolderDataBlock(); } - } - for (int j = 0; j < count; j++) - { FolderData[j].FromBytes(bytes, ref i); } - count = (int)bytes[i++]; - if(ItemData == null || ItemData.Length != count) { - ItemData = new ItemDataBlock[count]; - for(int j = 0; j < count; j++) - { ItemData[j] = new ItemDataBlock(); } - } - for (int j = 0; j < count; j++) - { ItemData[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length++; - for (int j = 0; j < FolderData.Length; j++) { length += FolderData[j].Length; } - length++; - for (int j = 0; j < ItemData.Length; j++) { length += ItemData[j].Length; } - if (Header.AckList != null && 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); } - bytes[i++] = (byte)ItemData.Length; - for (int j = 0; j < ItemData.Length; j++) { ItemData[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - fixedLength += 2; - - int FolderDataStart = 0; - int ItemDataStart = 0; - do - { - int variableLength = 0; - int FolderDataCount = 0; - int ItemDataCount = 0; - - i = FolderDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < FolderData.Length) { - int blockLength = FolderData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == FolderDataStart) { - variableLength += blockLength; - ++FolderDataCount; - } - else { break; } - ++i; - } - - i = ItemDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < ItemData.Length) { - int blockLength = ItemData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ItemDataStart) { - variableLength += blockLength; - ++ItemDataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)FolderDataCount; - for (i = FolderDataStart; i < FolderDataStart + FolderDataCount; i++) { FolderData[i].ToBytes(packet, ref length); } - FolderDataStart += FolderDataCount; - - packet[length++] = (byte)ItemDataCount; - for (i = ItemDataStart; i < ItemDataStart + ItemDataCount; i++) { ItemData[i].ToBytes(packet, ref length); } - ItemDataStart += ItemDataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - FolderDataStart < FolderData.Length || - ItemDataStart < ItemData.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class FetchInventoryPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class InventoryDataBlock : PacketBlock - { - public UUID OwnerID; - public UUID ItemID; - - public override int Length - { - get - { - return 32; - } - } - - public InventoryDataBlock() { } - public InventoryDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - OwnerID.FromBytes(bytes, i); i += 16; - ItemID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - OwnerID.ToBytes(bytes, i); i += 16; - ItemID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentData.Length; - for (int j = 0; j < InventoryData.Length; j++) - length += InventoryData[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public InventoryDataBlock[] InventoryData; - - public FetchInventoryPacket() - { - HasVariableBlocks = true; - Type = PacketType.FetchInventory; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 279; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - InventoryData = null; - } - - public FetchInventoryPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(InventoryData == null || InventoryData.Length != -1) { - InventoryData = new InventoryDataBlock[count]; - for(int j = 0; j < count; j++) - { InventoryData[j] = new InventoryDataBlock(); } - } - for (int j = 0; j < count; j++) - { InventoryData[j].FromBytes(bytes, ref i); } - } - - public FetchInventoryPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(InventoryData == null || InventoryData.Length != count) { - InventoryData = new InventoryDataBlock[count]; - for(int j = 0; j < count; j++) - { InventoryData[j] = new InventoryDataBlock(); } - } - for (int j = 0; j < count; j++) - { InventoryData[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length++; - for (int j = 0; j < InventoryData.Length; j++) { length += InventoryData[j].Length; } - if (Header.AckList != null && 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)InventoryData.Length; - for (int j = 0; j < InventoryData.Length; j++) { InventoryData[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int InventoryDataStart = 0; - do - { - int variableLength = 0; - int InventoryDataCount = 0; - - i = InventoryDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < InventoryData.Length) { - int blockLength = InventoryData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == InventoryDataStart) { - variableLength += blockLength; - ++InventoryDataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)InventoryDataCount; - for (i = InventoryDataStart; i < InventoryDataStart + InventoryDataCount; i++) { InventoryData[i].ToBytes(packet, ref length); } - InventoryDataStart += InventoryDataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - InventoryDataStart < InventoryData.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class FetchInventoryReplyPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - - public override int Length - { - get - { - return 16; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class InventoryDataBlock : PacketBlock - { - public UUID ItemID; - public UUID FolderID; - public UUID CreatorID; - public UUID OwnerID; - public UUID GroupID; - public uint BaseMask; - public uint OwnerMask; - public uint GroupMask; - public uint EveryoneMask; - public uint NextOwnerMask; - public bool GroupOwned; - public UUID AssetID; - public sbyte Type; - public sbyte InvType; - public uint Flags; - public byte SaleType; - public int SalePrice; - public byte[] Name; - public byte[] Description; - public int CreationDate; - public uint CRC; - - public override int Length - { - get - { - int length = 138; - if (Name != null) { length += Name.Length; } - if (Description != null) { length += Description.Length; } - return length; - } - } - - public InventoryDataBlock() { } - public InventoryDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - ItemID.FromBytes(bytes, i); i += 16; - FolderID.FromBytes(bytes, i); i += 16; - CreatorID.FromBytes(bytes, i); i += 16; - OwnerID.FromBytes(bytes, i); i += 16; - GroupID.FromBytes(bytes, i); i += 16; - BaseMask = (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)); - GroupMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - 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)); - GroupOwned = (bytes[i++] != 0) ? (bool)true : (bool)false; - AssetID.FromBytes(bytes, i); i += 16; - Type = (sbyte)bytes[i++]; - InvType = (sbyte)bytes[i++]; - Flags = (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)); - length = bytes[i++]; - Name = new byte[length]; - Buffer.BlockCopy(bytes, i, Name, 0, length); i += length; - length = bytes[i++]; - Description = new byte[length]; - Buffer.BlockCopy(bytes, i, Description, 0, length); i += length; - CreationDate = (int)(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(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - ItemID.ToBytes(bytes, i); i += 16; - FolderID.ToBytes(bytes, i); i += 16; - CreatorID.ToBytes(bytes, i); i += 16; - OwnerID.ToBytes(bytes, i); i += 16; - GroupID.ToBytes(bytes, i); i += 16; - Utils.UIntToBytes(BaseMask, bytes, i); i += 4; - Utils.UIntToBytes(OwnerMask, bytes, i); i += 4; - Utils.UIntToBytes(GroupMask, bytes, i); i += 4; - Utils.UIntToBytes(EveryoneMask, bytes, i); i += 4; - Utils.UIntToBytes(NextOwnerMask, bytes, i); i += 4; - bytes[i++] = (byte)((GroupOwned) ? 1 : 0); - AssetID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)Type; - bytes[i++] = (byte)InvType; - Utils.UIntToBytes(Flags, bytes, i); i += 4; - bytes[i++] = SaleType; - Utils.IntToBytes(SalePrice, bytes, i); i += 4; - bytes[i++] = (byte)Name.Length; - Buffer.BlockCopy(Name, 0, bytes, i, Name.Length); i += Name.Length; - bytes[i++] = (byte)Description.Length; - Buffer.BlockCopy(Description, 0, bytes, i, Description.Length); i += Description.Length; - Utils.IntToBytes(CreationDate, bytes, i); i += 4; - Utils.UIntToBytes(CRC, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentData.Length; - for (int j = 0; j < InventoryData.Length; j++) - length += InventoryData[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public InventoryDataBlock[] InventoryData; - - public FetchInventoryReplyPacket() - { - HasVariableBlocks = true; - Type = PacketType.FetchInventoryReply; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 280; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - InventoryData = null; - } - - public FetchInventoryReplyPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(InventoryData == null || InventoryData.Length != -1) { - InventoryData = new InventoryDataBlock[count]; - for(int j = 0; j < count; j++) - { InventoryData[j] = new InventoryDataBlock(); } - } - for (int j = 0; j < count; j++) - { InventoryData[j].FromBytes(bytes, ref i); } - } - - public FetchInventoryReplyPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(InventoryData == null || InventoryData.Length != count) { - InventoryData = new InventoryDataBlock[count]; - for(int j = 0; j < count; j++) - { InventoryData[j] = new InventoryDataBlock(); } - } - for (int j = 0; j < count; j++) - { InventoryData[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length++; - for (int j = 0; j < InventoryData.Length; j++) { length += InventoryData[j].Length; } - if (Header.AckList != null && 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)InventoryData.Length; - for (int j = 0; j < InventoryData.Length; j++) { InventoryData[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int InventoryDataStart = 0; - do - { - int variableLength = 0; - int InventoryDataCount = 0; - - i = InventoryDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < InventoryData.Length) { - int blockLength = InventoryData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == InventoryDataStart) { - variableLength += blockLength; - ++InventoryDataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)InventoryDataCount; - for (i = InventoryDataStart; i < InventoryDataStart + InventoryDataCount; i++) { InventoryData[i].ToBytes(packet, ref length); } - InventoryDataStart += InventoryDataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - InventoryDataStart < InventoryData.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class BulkUpdateInventoryPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID TransactionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - TransactionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - TransactionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class FolderDataBlock : PacketBlock - { - public UUID FolderID; - public UUID ParentID; - public sbyte Type; - public byte[] Name; - - public override int Length - { - get - { - int length = 34; - if (Name != null) { length += Name.Length; } - return length; - } - } - - public FolderDataBlock() { } - public FolderDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - FolderID.FromBytes(bytes, i); i += 16; - ParentID.FromBytes(bytes, i); i += 16; - Type = (sbyte)bytes[i++]; - length = bytes[i++]; - Name = new byte[length]; - Buffer.BlockCopy(bytes, i, Name, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - FolderID.ToBytes(bytes, i); i += 16; - ParentID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)Type; - bytes[i++] = (byte)Name.Length; - Buffer.BlockCopy(Name, 0, bytes, i, Name.Length); i += Name.Length; - } - - } - - /// - public sealed class ItemDataBlock : PacketBlock - { - public UUID ItemID; - public uint CallbackID; - public UUID FolderID; - public UUID CreatorID; - public UUID OwnerID; - public UUID GroupID; - public uint BaseMask; - public uint OwnerMask; - public uint GroupMask; - public uint EveryoneMask; - public uint NextOwnerMask; - public bool GroupOwned; - public UUID AssetID; - public sbyte Type; - public sbyte InvType; - public uint Flags; - public byte SaleType; - public int SalePrice; - public byte[] Name; - public byte[] Description; - public int CreationDate; - public uint CRC; - - public override int Length - { - get - { - int length = 142; - if (Name != null) { length += Name.Length; } - if (Description != null) { length += Description.Length; } - return length; - } - } - - public ItemDataBlock() { } - public ItemDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - ItemID.FromBytes(bytes, i); i += 16; - CallbackID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - FolderID.FromBytes(bytes, i); i += 16; - CreatorID.FromBytes(bytes, i); i += 16; - OwnerID.FromBytes(bytes, i); i += 16; - GroupID.FromBytes(bytes, i); i += 16; - BaseMask = (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)); - GroupMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - 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)); - GroupOwned = (bytes[i++] != 0) ? (bool)true : (bool)false; - AssetID.FromBytes(bytes, i); i += 16; - Type = (sbyte)bytes[i++]; - InvType = (sbyte)bytes[i++]; - Flags = (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)); - length = bytes[i++]; - Name = new byte[length]; - Buffer.BlockCopy(bytes, i, Name, 0, length); i += length; - length = bytes[i++]; - Description = new byte[length]; - Buffer.BlockCopy(bytes, i, Description, 0, length); i += length; - CreationDate = (int)(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(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - ItemID.ToBytes(bytes, i); i += 16; - Utils.UIntToBytes(CallbackID, bytes, i); i += 4; - FolderID.ToBytes(bytes, i); i += 16; - CreatorID.ToBytes(bytes, i); i += 16; - OwnerID.ToBytes(bytes, i); i += 16; - GroupID.ToBytes(bytes, i); i += 16; - Utils.UIntToBytes(BaseMask, bytes, i); i += 4; - Utils.UIntToBytes(OwnerMask, bytes, i); i += 4; - Utils.UIntToBytes(GroupMask, bytes, i); i += 4; - Utils.UIntToBytes(EveryoneMask, bytes, i); i += 4; - Utils.UIntToBytes(NextOwnerMask, bytes, i); i += 4; - bytes[i++] = (byte)((GroupOwned) ? 1 : 0); - AssetID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)Type; - bytes[i++] = (byte)InvType; - Utils.UIntToBytes(Flags, bytes, i); i += 4; - bytes[i++] = SaleType; - Utils.IntToBytes(SalePrice, bytes, i); i += 4; - bytes[i++] = (byte)Name.Length; - Buffer.BlockCopy(Name, 0, bytes, i, Name.Length); i += Name.Length; - bytes[i++] = (byte)Description.Length; - Buffer.BlockCopy(Description, 0, bytes, i, Description.Length); i += Description.Length; - Utils.IntToBytes(CreationDate, bytes, i); i += 4; - Utils.UIntToBytes(CRC, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 12; - length += AgentData.Length; - for (int j = 0; j < FolderData.Length; j++) - length += FolderData[j].Length; - for (int j = 0; j < ItemData.Length; j++) - length += ItemData[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public FolderDataBlock[] FolderData; - public ItemDataBlock[] ItemData; - - public BulkUpdateInventoryPacket() - { - HasVariableBlocks = true; - Type = PacketType.BulkUpdateInventory; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 281; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - FolderData = null; - ItemData = null; - } - - public BulkUpdateInventoryPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(FolderData == null || FolderData.Length != -1) { - FolderData = new FolderDataBlock[count]; - for(int j = 0; j < count; j++) - { FolderData[j] = new FolderDataBlock(); } - } - for (int j = 0; j < count; j++) - { FolderData[j].FromBytes(bytes, ref i); } - count = (int)bytes[i++]; - if(ItemData == null || ItemData.Length != -1) { - ItemData = new ItemDataBlock[count]; - for(int j = 0; j < count; j++) - { ItemData[j] = new ItemDataBlock(); } - } - for (int j = 0; j < count; j++) - { ItemData[j].FromBytes(bytes, ref i); } - } - - public BulkUpdateInventoryPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(FolderData == null || FolderData.Length != count) { - FolderData = new FolderDataBlock[count]; - for(int j = 0; j < count; j++) - { FolderData[j] = new FolderDataBlock(); } - } - for (int j = 0; j < count; j++) - { FolderData[j].FromBytes(bytes, ref i); } - count = (int)bytes[i++]; - if(ItemData == null || ItemData.Length != count) { - ItemData = new ItemDataBlock[count]; - for(int j = 0; j < count; j++) - { ItemData[j] = new ItemDataBlock(); } - } - for (int j = 0; j < count; j++) - { ItemData[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length++; - for (int j = 0; j < FolderData.Length; j++) { length += FolderData[j].Length; } - length++; - for (int j = 0; j < ItemData.Length; j++) { length += ItemData[j].Length; } - if (Header.AckList != null && 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); } - bytes[i++] = (byte)ItemData.Length; - for (int j = 0; j < ItemData.Length; j++) { ItemData[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - fixedLength += 2; - - int FolderDataStart = 0; - int ItemDataStart = 0; - do - { - int variableLength = 0; - int FolderDataCount = 0; - int ItemDataCount = 0; - - i = FolderDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < FolderData.Length) { - int blockLength = FolderData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == FolderDataStart) { - variableLength += blockLength; - ++FolderDataCount; - } - else { break; } - ++i; - } - - i = ItemDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < ItemData.Length) { - int blockLength = ItemData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ItemDataStart) { - variableLength += blockLength; - ++ItemDataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)FolderDataCount; - for (i = FolderDataStart; i < FolderDataStart + FolderDataCount; i++) { FolderData[i].ToBytes(packet, ref length); } - FolderDataStart += FolderDataCount; - - packet[length++] = (byte)ItemDataCount; - for (i = ItemDataStart; i < ItemDataStart + ItemDataCount; i++) { ItemData[i].ToBytes(packet, ref length); } - ItemDataStart += ItemDataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - FolderDataStart < FolderData.Length || - ItemDataStart < ItemData.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class RemoveInventoryObjectsPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class FolderDataBlock : PacketBlock - { - public UUID FolderID; - - public override int Length - { - get - { - return 16; - } - } - - public FolderDataBlock() { } - public FolderDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - FolderID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - FolderID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class ItemDataBlock : PacketBlock - { - public UUID ItemID; - - public override int Length - { - get - { - return 16; - } - } - - public ItemDataBlock() { } - public ItemDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - ItemID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - ItemID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 12; - length += AgentData.Length; - for (int j = 0; j < FolderData.Length; j++) - length += FolderData[j].Length; - for (int j = 0; j < ItemData.Length; j++) - length += ItemData[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public FolderDataBlock[] FolderData; - public ItemDataBlock[] ItemData; - - public RemoveInventoryObjectsPacket() - { - HasVariableBlocks = true; - Type = PacketType.RemoveInventoryObjects; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 284; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - FolderData = null; - ItemData = null; - } - - public RemoveInventoryObjectsPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(FolderData == null || FolderData.Length != -1) { - FolderData = new FolderDataBlock[count]; - for(int j = 0; j < count; j++) - { FolderData[j] = new FolderDataBlock(); } - } - for (int j = 0; j < count; j++) - { FolderData[j].FromBytes(bytes, ref i); } - count = (int)bytes[i++]; - if(ItemData == null || ItemData.Length != -1) { - ItemData = new ItemDataBlock[count]; - for(int j = 0; j < count; j++) - { ItemData[j] = new ItemDataBlock(); } - } - for (int j = 0; j < count; j++) - { ItemData[j].FromBytes(bytes, ref i); } - } - - public RemoveInventoryObjectsPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(FolderData == null || FolderData.Length != count) { - FolderData = new FolderDataBlock[count]; - for(int j = 0; j < count; j++) - { FolderData[j] = new FolderDataBlock(); } - } - for (int j = 0; j < count; j++) - { FolderData[j].FromBytes(bytes, ref i); } - count = (int)bytes[i++]; - if(ItemData == null || ItemData.Length != count) { - ItemData = new ItemDataBlock[count]; - for(int j = 0; j < count; j++) - { ItemData[j] = new ItemDataBlock(); } - } - for (int j = 0; j < count; j++) - { ItemData[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length++; - for (int j = 0; j < FolderData.Length; j++) { length += FolderData[j].Length; } - length++; - for (int j = 0; j < ItemData.Length; j++) { length += ItemData[j].Length; } - if (Header.AckList != null && 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); } - bytes[i++] = (byte)ItemData.Length; - for (int j = 0; j < ItemData.Length; j++) { ItemData[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - fixedLength += 2; - - int FolderDataStart = 0; - int ItemDataStart = 0; - do - { - int variableLength = 0; - int FolderDataCount = 0; - int ItemDataCount = 0; - - i = FolderDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < FolderData.Length) { - int blockLength = FolderData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == FolderDataStart) { - variableLength += blockLength; - ++FolderDataCount; - } - else { break; } - ++i; - } - - i = ItemDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < ItemData.Length) { - int blockLength = ItemData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ItemDataStart) { - variableLength += blockLength; - ++ItemDataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)FolderDataCount; - for (i = FolderDataStart; i < FolderDataStart + FolderDataCount; i++) { FolderData[i].ToBytes(packet, ref length); } - FolderDataStart += FolderDataCount; - - packet[length++] = (byte)ItemDataCount; - for (i = ItemDataStart; i < ItemDataStart + ItemDataCount; i++) { ItemData[i].ToBytes(packet, ref length); } - ItemDataStart += ItemDataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - FolderDataStart < FolderData.Length || - ItemDataStart < ItemData.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class PurgeInventoryDescendentsPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class InventoryDataBlock : PacketBlock - { - public UUID FolderID; - - public override int Length - { - get - { - return 16; - } - } - - public InventoryDataBlock() { } - public InventoryDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - FolderID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - FolderID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += InventoryData.Length; - return length; - } - } - public AgentDataBlock AgentData; - public InventoryDataBlock InventoryData; - - public PurgeInventoryDescendentsPacket() - { - HasVariableBlocks = false; - Type = PacketType.PurgeInventoryDescendents; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 285; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - InventoryData = new InventoryDataBlock(); - } - - public PurgeInventoryDescendentsPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - InventoryData.FromBytes(bytes, ref i); - } - - public PurgeInventoryDescendentsPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - InventoryData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += InventoryData.Length; - if (Header.AckList != null && 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); - InventoryData.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class UpdateTaskInventoryPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class UpdateDataBlock : PacketBlock - { - public uint LocalID; - public byte Key; - - public override int Length - { - get - { - return 5; - } - } - - public UpdateDataBlock() { } - public UpdateDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - LocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - Key = (byte)bytes[i++]; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UIntToBytes(LocalID, bytes, i); i += 4; - bytes[i++] = Key; - } - - } - - /// - public sealed class InventoryDataBlock : PacketBlock - { - public UUID ItemID; - public UUID FolderID; - public UUID CreatorID; - public UUID OwnerID; - public UUID GroupID; - public uint BaseMask; - public uint OwnerMask; - public uint GroupMask; - public uint EveryoneMask; - public uint NextOwnerMask; - public bool GroupOwned; - public UUID TransactionID; - public sbyte Type; - public sbyte InvType; - public uint Flags; - public byte SaleType; - public int SalePrice; - public byte[] Name; - public byte[] Description; - public int CreationDate; - public uint CRC; - - public override int Length - { - get - { - int length = 138; - if (Name != null) { length += Name.Length; } - if (Description != null) { length += Description.Length; } - return length; - } - } - - public InventoryDataBlock() { } - public InventoryDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - ItemID.FromBytes(bytes, i); i += 16; - FolderID.FromBytes(bytes, i); i += 16; - CreatorID.FromBytes(bytes, i); i += 16; - OwnerID.FromBytes(bytes, i); i += 16; - GroupID.FromBytes(bytes, i); i += 16; - BaseMask = (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)); - GroupMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - 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)); - GroupOwned = (bytes[i++] != 0) ? (bool)true : (bool)false; - TransactionID.FromBytes(bytes, i); i += 16; - Type = (sbyte)bytes[i++]; - InvType = (sbyte)bytes[i++]; - Flags = (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)); - length = bytes[i++]; - Name = new byte[length]; - Buffer.BlockCopy(bytes, i, Name, 0, length); i += length; - length = bytes[i++]; - Description = new byte[length]; - Buffer.BlockCopy(bytes, i, Description, 0, length); i += length; - CreationDate = (int)(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(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - ItemID.ToBytes(bytes, i); i += 16; - FolderID.ToBytes(bytes, i); i += 16; - CreatorID.ToBytes(bytes, i); i += 16; - OwnerID.ToBytes(bytes, i); i += 16; - GroupID.ToBytes(bytes, i); i += 16; - Utils.UIntToBytes(BaseMask, bytes, i); i += 4; - Utils.UIntToBytes(OwnerMask, bytes, i); i += 4; - Utils.UIntToBytes(GroupMask, bytes, i); i += 4; - Utils.UIntToBytes(EveryoneMask, bytes, i); i += 4; - Utils.UIntToBytes(NextOwnerMask, bytes, i); i += 4; - bytes[i++] = (byte)((GroupOwned) ? 1 : 0); - TransactionID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)Type; - bytes[i++] = (byte)InvType; - Utils.UIntToBytes(Flags, bytes, i); i += 4; - bytes[i++] = SaleType; - Utils.IntToBytes(SalePrice, bytes, i); i += 4; - bytes[i++] = (byte)Name.Length; - Buffer.BlockCopy(Name, 0, bytes, i, Name.Length); i += Name.Length; - bytes[i++] = (byte)Description.Length; - Buffer.BlockCopy(Description, 0, bytes, i, Description.Length); i += Description.Length; - Utils.IntToBytes(CreationDate, bytes, i); i += 4; - Utils.UIntToBytes(CRC, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += UpdateData.Length; - length += InventoryData.Length; - return length; - } - } - public AgentDataBlock AgentData; - public UpdateDataBlock UpdateData; - public InventoryDataBlock InventoryData; - - public UpdateTaskInventoryPacket() - { - HasVariableBlocks = false; - Type = PacketType.UpdateTaskInventory; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 286; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - UpdateData = new UpdateDataBlock(); - InventoryData = new InventoryDataBlock(); - } - - public UpdateTaskInventoryPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - UpdateData.FromBytes(bytes, ref i); - InventoryData.FromBytes(bytes, ref i); - } - - public UpdateTaskInventoryPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - UpdateData.FromBytes(bytes, ref i); - InventoryData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += UpdateData.Length; - length += InventoryData.Length; - if (Header.AckList != null && 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); - UpdateData.ToBytes(bytes, ref i); - InventoryData.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class RemoveTaskInventoryPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class InventoryDataBlock : PacketBlock - { - public uint LocalID; - public UUID ItemID; - - public override int Length - { - get - { - return 20; - } - } - - public InventoryDataBlock() { } - public InventoryDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - LocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - ItemID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UIntToBytes(LocalID, bytes, i); i += 4; - ItemID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += InventoryData.Length; - return length; - } - } - public AgentDataBlock AgentData; - public InventoryDataBlock InventoryData; - - public RemoveTaskInventoryPacket() - { - HasVariableBlocks = false; - Type = PacketType.RemoveTaskInventory; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 287; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - InventoryData = new InventoryDataBlock(); - } - - public RemoveTaskInventoryPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - InventoryData.FromBytes(bytes, ref i); - } - - public RemoveTaskInventoryPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - InventoryData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += InventoryData.Length; - if (Header.AckList != null && 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); - InventoryData.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class MoveTaskInventoryPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - public UUID FolderID; - - public override int Length - { - get - { - return 48; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - FolderID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - FolderID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class InventoryDataBlock : PacketBlock - { - public uint LocalID; - public UUID ItemID; - - public override int Length - { - get - { - return 20; - } - } - - public InventoryDataBlock() { } - public InventoryDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - LocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - ItemID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UIntToBytes(LocalID, bytes, i); i += 4; - ItemID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += InventoryData.Length; - return length; - } - } - public AgentDataBlock AgentData; - public InventoryDataBlock InventoryData; - - public MoveTaskInventoryPacket() - { - HasVariableBlocks = false; - Type = PacketType.MoveTaskInventory; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 288; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - InventoryData = new InventoryDataBlock(); - } - - public MoveTaskInventoryPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - InventoryData.FromBytes(bytes, ref i); - } - - public MoveTaskInventoryPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - InventoryData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += InventoryData.Length; - if (Header.AckList != null && 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); - InventoryData.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class RequestTaskInventoryPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class InventoryDataBlock : PacketBlock - { - public uint LocalID; - - public override int Length - { - get - { - return 4; - } - } - - public InventoryDataBlock() { } - public InventoryDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - LocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UIntToBytes(LocalID, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += InventoryData.Length; - return length; - } - } - public AgentDataBlock AgentData; - public InventoryDataBlock InventoryData; - - public RequestTaskInventoryPacket() - { - HasVariableBlocks = false; - Type = PacketType.RequestTaskInventory; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 289; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - InventoryData = new InventoryDataBlock(); - } - - public RequestTaskInventoryPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - InventoryData.FromBytes(bytes, ref i); - } - - public RequestTaskInventoryPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - InventoryData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += InventoryData.Length; - if (Header.AckList != null && 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); - InventoryData.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class ReplyTaskInventoryPacket : Packet - { - /// - public sealed class InventoryDataBlock : PacketBlock - { - public UUID TaskID; - public short Serial; - public byte[] Filename; - - public override int Length - { - get - { - int length = 19; - if (Filename != null) { length += Filename.Length; } - return length; - } - } - - public InventoryDataBlock() { } - public InventoryDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - TaskID.FromBytes(bytes, i); i += 16; - Serial = (short)(bytes[i++] + (bytes[i++] << 8)); - length = bytes[i++]; - Filename = new byte[length]; - Buffer.BlockCopy(bytes, i, Filename, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - TaskID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)(Serial % 256); - bytes[i++] = (byte)((Serial >> 8) % 256); - bytes[i++] = (byte)Filename.Length; - Buffer.BlockCopy(Filename, 0, bytes, i, Filename.Length); i += Filename.Length; - } - - } - - public override int Length - { - get - { - int length = 10; - length += InventoryData.Length; - return length; - } - } - public InventoryDataBlock InventoryData; - - public ReplyTaskInventoryPacket() - { - HasVariableBlocks = false; - Type = PacketType.ReplyTaskInventory; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 290; - Header.Reliable = true; - Header.Zerocoded = true; - InventoryData = new InventoryDataBlock(); - } - - public ReplyTaskInventoryPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - InventoryData.FromBytes(bytes, ref i); - } - - public ReplyTaskInventoryPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - InventoryData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += InventoryData.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class DeRezObjectPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class AgentBlockBlock : PacketBlock - { - public UUID GroupID; - public byte Destination; - public UUID DestinationID; - public UUID TransactionID; - public byte PacketCount; - public byte PacketNumber; - - public override int Length - { - get - { - return 51; - } - } - - public AgentBlockBlock() { } - public AgentBlockBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - GroupID.FromBytes(bytes, i); i += 16; - Destination = (byte)bytes[i++]; - DestinationID.FromBytes(bytes, i); i += 16; - TransactionID.FromBytes(bytes, i); i += 16; - PacketCount = (byte)bytes[i++]; - PacketNumber = (byte)bytes[i++]; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - GroupID.ToBytes(bytes, i); i += 16; - bytes[i++] = Destination; - DestinationID.ToBytes(bytes, i); i += 16; - TransactionID.ToBytes(bytes, i); i += 16; - bytes[i++] = PacketCount; - bytes[i++] = PacketNumber; - } - - } - - /// - public sealed class ObjectDataBlock : PacketBlock - { - public uint ObjectLocalID; - - public override int Length - { - get - { - return 4; - } - } - - public ObjectDataBlock() { } - public ObjectDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - ObjectLocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UIntToBytes(ObjectLocalID, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentData.Length; - length += AgentBlock.Length; - for (int j = 0; j < ObjectData.Length; j++) - length += ObjectData[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public AgentBlockBlock AgentBlock; - public ObjectDataBlock[] ObjectData; - - public DeRezObjectPacket() - { - HasVariableBlocks = true; - Type = PacketType.DeRezObject; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 291; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - AgentBlock = new AgentBlockBlock(); - ObjectData = null; - } - - public DeRezObjectPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - AgentBlock.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ObjectData == null || ObjectData.Length != -1) { - ObjectData = new ObjectDataBlock[count]; - for(int j = 0; j < count; j++) - { ObjectData[j] = new ObjectDataBlock(); } - } - for (int j = 0; j < count; j++) - { ObjectData[j].FromBytes(bytes, ref i); } - } - - public DeRezObjectPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - AgentBlock.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ObjectData == null || ObjectData.Length != count) { - ObjectData = new ObjectDataBlock[count]; - for(int j = 0; j < count; j++) - { ObjectData[j] = new ObjectDataBlock(); } - } - for (int j = 0; j < count; j++) - { ObjectData[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += AgentBlock.Length; - length++; - for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } - if (Header.AckList != null && 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); - AgentBlock.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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - fixedLength += AgentBlock.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - AgentBlock.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int ObjectDataStart = 0; - do - { - int variableLength = 0; - int ObjectDataCount = 0; - - i = ObjectDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < ObjectData.Length) { - int blockLength = ObjectData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ObjectDataStart) { - variableLength += blockLength; - ++ObjectDataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)ObjectDataCount; - for (i = ObjectDataStart; i < ObjectDataStart + ObjectDataCount; i++) { ObjectData[i].ToBytes(packet, ref length); } - ObjectDataStart += ObjectDataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - ObjectDataStart < ObjectData.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class DeRezAckPacket : Packet - { - /// - public sealed class TransactionDataBlock : PacketBlock - { - public UUID TransactionID; - public bool Success; - - public override int Length - { - get - { - return 17; - } - } - - public TransactionDataBlock() { } - public TransactionDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - TransactionID.FromBytes(bytes, i); i += 16; - Success = (bytes[i++] != 0) ? (bool)true : (bool)false; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - TransactionID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)((Success) ? 1 : 0); - } - - } - - public override int Length - { - get - { - int length = 10; - length += TransactionData.Length; - return length; - } - } - public TransactionDataBlock TransactionData; - - public DeRezAckPacket() - { - HasVariableBlocks = false; - Type = PacketType.DeRezAck; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 292; - Header.Reliable = true; - TransactionData = new TransactionDataBlock(); - } - - public DeRezAckPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - TransactionData.FromBytes(bytes, ref i); - } - - public DeRezAckPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - TransactionData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += TransactionData.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class RezObjectPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - public UUID GroupID; - - public override int Length - { - get - { - return 48; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - GroupID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - GroupID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class RezDataBlock : PacketBlock - { - public UUID FromTaskID; - public byte BypassRaycast; - public Vector3 RayStart; - public Vector3 RayEnd; - public UUID RayTargetID; - public bool RayEndIsIntersection; - public bool RezSelected; - public bool RemoveItem; - public uint ItemFlags; - public uint GroupMask; - public uint EveryoneMask; - public uint NextOwnerMask; - - public override int Length - { - get - { - return 76; - } - } - - public RezDataBlock() { } - public RezDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - FromTaskID.FromBytes(bytes, i); i += 16; - BypassRaycast = (byte)bytes[i++]; - RayStart.FromBytes(bytes, i); i += 12; - RayEnd.FromBytes(bytes, i); i += 12; - RayTargetID.FromBytes(bytes, i); i += 16; - RayEndIsIntersection = (bytes[i++] != 0) ? (bool)true : (bool)false; - RezSelected = (bytes[i++] != 0) ? (bool)true : (bool)false; - RemoveItem = (bytes[i++] != 0) ? (bool)true : (bool)false; - ItemFlags = (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)); - 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)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - FromTaskID.ToBytes(bytes, i); i += 16; - bytes[i++] = BypassRaycast; - RayStart.ToBytes(bytes, i); i += 12; - RayEnd.ToBytes(bytes, i); i += 12; - RayTargetID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)((RayEndIsIntersection) ? 1 : 0); - bytes[i++] = (byte)((RezSelected) ? 1 : 0); - bytes[i++] = (byte)((RemoveItem) ? 1 : 0); - Utils.UIntToBytes(ItemFlags, bytes, i); i += 4; - Utils.UIntToBytes(GroupMask, bytes, i); i += 4; - Utils.UIntToBytes(EveryoneMask, bytes, i); i += 4; - Utils.UIntToBytes(NextOwnerMask, bytes, i); i += 4; - } - - } - - /// - public sealed class InventoryDataBlock : PacketBlock - { - public UUID ItemID; - public UUID FolderID; - public UUID CreatorID; - public UUID OwnerID; - public UUID GroupID; - public uint BaseMask; - public uint OwnerMask; - public uint GroupMask; - public uint EveryoneMask; - public uint NextOwnerMask; - public bool GroupOwned; - public UUID TransactionID; - public sbyte Type; - public sbyte InvType; - public uint Flags; - public byte SaleType; - public int SalePrice; - public byte[] Name; - public byte[] Description; - public int CreationDate; - public uint CRC; - - public override int Length - { - get - { - int length = 138; - if (Name != null) { length += Name.Length; } - if (Description != null) { length += Description.Length; } - return length; - } - } - - public InventoryDataBlock() { } - public InventoryDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - ItemID.FromBytes(bytes, i); i += 16; - FolderID.FromBytes(bytes, i); i += 16; - CreatorID.FromBytes(bytes, i); i += 16; - OwnerID.FromBytes(bytes, i); i += 16; - GroupID.FromBytes(bytes, i); i += 16; - BaseMask = (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)); - GroupMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - 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)); - GroupOwned = (bytes[i++] != 0) ? (bool)true : (bool)false; - TransactionID.FromBytes(bytes, i); i += 16; - Type = (sbyte)bytes[i++]; - InvType = (sbyte)bytes[i++]; - Flags = (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)); - length = bytes[i++]; - Name = new byte[length]; - Buffer.BlockCopy(bytes, i, Name, 0, length); i += length; - length = bytes[i++]; - Description = new byte[length]; - Buffer.BlockCopy(bytes, i, Description, 0, length); i += length; - CreationDate = (int)(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(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - ItemID.ToBytes(bytes, i); i += 16; - FolderID.ToBytes(bytes, i); i += 16; - CreatorID.ToBytes(bytes, i); i += 16; - OwnerID.ToBytes(bytes, i); i += 16; - GroupID.ToBytes(bytes, i); i += 16; - Utils.UIntToBytes(BaseMask, bytes, i); i += 4; - Utils.UIntToBytes(OwnerMask, bytes, i); i += 4; - Utils.UIntToBytes(GroupMask, bytes, i); i += 4; - Utils.UIntToBytes(EveryoneMask, bytes, i); i += 4; - Utils.UIntToBytes(NextOwnerMask, bytes, i); i += 4; - bytes[i++] = (byte)((GroupOwned) ? 1 : 0); - TransactionID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)Type; - bytes[i++] = (byte)InvType; - Utils.UIntToBytes(Flags, bytes, i); i += 4; - bytes[i++] = SaleType; - Utils.IntToBytes(SalePrice, bytes, i); i += 4; - bytes[i++] = (byte)Name.Length; - Buffer.BlockCopy(Name, 0, bytes, i, Name.Length); i += Name.Length; - bytes[i++] = (byte)Description.Length; - Buffer.BlockCopy(Description, 0, bytes, i, Description.Length); i += Description.Length; - Utils.IntToBytes(CreationDate, bytes, i); i += 4; - Utils.UIntToBytes(CRC, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += RezData.Length; - length += InventoryData.Length; - return length; - } - } - public AgentDataBlock AgentData; - public RezDataBlock RezData; - public InventoryDataBlock InventoryData; - - public RezObjectPacket() - { - HasVariableBlocks = false; - Type = PacketType.RezObject; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 293; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - RezData = new RezDataBlock(); - InventoryData = new InventoryDataBlock(); - } - - public RezObjectPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - RezData.FromBytes(bytes, ref i); - InventoryData.FromBytes(bytes, ref i); - } - - public RezObjectPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - RezData.FromBytes(bytes, ref i); - InventoryData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += RezData.Length; - length += InventoryData.Length; - if (Header.AckList != null && 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); - RezData.ToBytes(bytes, ref i); - InventoryData.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class RezObjectFromNotecardPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - public UUID GroupID; - - public override int Length - { - get - { - return 48; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - GroupID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - GroupID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class RezDataBlock : PacketBlock - { - public UUID FromTaskID; - public byte BypassRaycast; - public Vector3 RayStart; - public Vector3 RayEnd; - public UUID RayTargetID; - public bool RayEndIsIntersection; - public bool RezSelected; - public bool RemoveItem; - public uint ItemFlags; - public uint GroupMask; - public uint EveryoneMask; - public uint NextOwnerMask; - - public override int Length - { - get - { - return 76; - } - } - - public RezDataBlock() { } - public RezDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - FromTaskID.FromBytes(bytes, i); i += 16; - BypassRaycast = (byte)bytes[i++]; - RayStart.FromBytes(bytes, i); i += 12; - RayEnd.FromBytes(bytes, i); i += 12; - RayTargetID.FromBytes(bytes, i); i += 16; - RayEndIsIntersection = (bytes[i++] != 0) ? (bool)true : (bool)false; - RezSelected = (bytes[i++] != 0) ? (bool)true : (bool)false; - RemoveItem = (bytes[i++] != 0) ? (bool)true : (bool)false; - ItemFlags = (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)); - 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)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - FromTaskID.ToBytes(bytes, i); i += 16; - bytes[i++] = BypassRaycast; - RayStart.ToBytes(bytes, i); i += 12; - RayEnd.ToBytes(bytes, i); i += 12; - RayTargetID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)((RayEndIsIntersection) ? 1 : 0); - bytes[i++] = (byte)((RezSelected) ? 1 : 0); - bytes[i++] = (byte)((RemoveItem) ? 1 : 0); - Utils.UIntToBytes(ItemFlags, bytes, i); i += 4; - Utils.UIntToBytes(GroupMask, bytes, i); i += 4; - Utils.UIntToBytes(EveryoneMask, bytes, i); i += 4; - Utils.UIntToBytes(NextOwnerMask, bytes, i); i += 4; - } - - } - - /// - public sealed class NotecardDataBlock : PacketBlock - { - public UUID NotecardItemID; - public UUID ObjectID; - - public override int Length - { - get - { - return 32; - } - } - - public NotecardDataBlock() { } - public NotecardDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - NotecardItemID.FromBytes(bytes, i); i += 16; - ObjectID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - NotecardItemID.ToBytes(bytes, i); i += 16; - ObjectID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class InventoryDataBlock : PacketBlock - { - public UUID ItemID; - - public override int Length - { - get - { - return 16; - } - } - - public InventoryDataBlock() { } - public InventoryDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - ItemID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - ItemID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentData.Length; - length += RezData.Length; - length += NotecardData.Length; - for (int j = 0; j < InventoryData.Length; j++) - length += InventoryData[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public RezDataBlock RezData; - public NotecardDataBlock NotecardData; - public InventoryDataBlock[] InventoryData; - - public RezObjectFromNotecardPacket() - { - HasVariableBlocks = true; - Type = PacketType.RezObjectFromNotecard; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 294; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - RezData = new RezDataBlock(); - NotecardData = new NotecardDataBlock(); - InventoryData = null; - } - - public RezObjectFromNotecardPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - RezData.FromBytes(bytes, ref i); - NotecardData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(InventoryData == null || InventoryData.Length != -1) { - InventoryData = new InventoryDataBlock[count]; - for(int j = 0; j < count; j++) - { InventoryData[j] = new InventoryDataBlock(); } - } - for (int j = 0; j < count; j++) - { InventoryData[j].FromBytes(bytes, ref i); } - } - - public RezObjectFromNotecardPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - RezData.FromBytes(bytes, ref i); - NotecardData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(InventoryData == null || InventoryData.Length != count) { - InventoryData = new InventoryDataBlock[count]; - for(int j = 0; j < count; j++) - { InventoryData[j] = new InventoryDataBlock(); } - } - for (int j = 0; j < count; j++) - { InventoryData[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += RezData.Length; - length += NotecardData.Length; - length++; - for (int j = 0; j < InventoryData.Length; j++) { length += InventoryData[j].Length; } - if (Header.AckList != null && 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); - RezData.ToBytes(bytes, ref i); - NotecardData.ToBytes(bytes, ref i); - bytes[i++] = (byte)InventoryData.Length; - for (int j = 0; j < InventoryData.Length; j++) { InventoryData[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - fixedLength += RezData.Length; - fixedLength += NotecardData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - RezData.ToBytes(fixedBytes, ref i); - NotecardData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int InventoryDataStart = 0; - do - { - int variableLength = 0; - int InventoryDataCount = 0; - - i = InventoryDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < InventoryData.Length) { - int blockLength = InventoryData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == InventoryDataStart) { - variableLength += blockLength; - ++InventoryDataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)InventoryDataCount; - for (i = InventoryDataStart; i < InventoryDataStart + InventoryDataCount; i++) { InventoryData[i].ToBytes(packet, ref length); } - InventoryDataStart += InventoryDataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - InventoryDataStart < InventoryData.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class AcceptFriendshipPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class TransactionBlockBlock : PacketBlock - { - public UUID TransactionID; - - public override int Length - { - get - { - return 16; - } - } - - public TransactionBlockBlock() { } - public TransactionBlockBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - TransactionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - TransactionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class FolderDataBlock : PacketBlock - { - public UUID FolderID; - - public override int Length - { - get - { - return 16; - } - } - - public FolderDataBlock() { } - public FolderDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - FolderID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - FolderID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentData.Length; - length += TransactionBlock.Length; - for (int j = 0; j < FolderData.Length; j++) - length += FolderData[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public TransactionBlockBlock TransactionBlock; - public FolderDataBlock[] FolderData; - - public AcceptFriendshipPacket() - { - HasVariableBlocks = true; - Type = PacketType.AcceptFriendship; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 297; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - TransactionBlock = new TransactionBlockBlock(); - FolderData = null; - } - - public AcceptFriendshipPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - TransactionBlock.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(FolderData == null || FolderData.Length != -1) { - FolderData = new FolderDataBlock[count]; - for(int j = 0; j < count; j++) - { FolderData[j] = new FolderDataBlock(); } - } - for (int j = 0; j < count; j++) - { FolderData[j].FromBytes(bytes, ref i); } - } - - public AcceptFriendshipPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - TransactionBlock.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(FolderData == null || FolderData.Length != count) { - FolderData = new FolderDataBlock[count]; - for(int j = 0; j < count; j++) - { FolderData[j] = new FolderDataBlock(); } - } - for (int j = 0; j < count; j++) - { FolderData[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += TransactionBlock.Length; - length++; - for (int j = 0; j < FolderData.Length; j++) { length += FolderData[j].Length; } - if (Header.AckList != null && 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); - TransactionBlock.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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - fixedLength += TransactionBlock.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - TransactionBlock.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int FolderDataStart = 0; - do - { - int variableLength = 0; - int FolderDataCount = 0; - - i = FolderDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < FolderData.Length) { - int blockLength = FolderData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == FolderDataStart) { - variableLength += blockLength; - ++FolderDataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)FolderDataCount; - for (i = FolderDataStart; i < FolderDataStart + FolderDataCount; i++) { FolderData[i].ToBytes(packet, ref length); } - FolderDataStart += FolderDataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - FolderDataStart < FolderData.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class DeclineFriendshipPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class TransactionBlockBlock : PacketBlock - { - public UUID TransactionID; - - public override int Length - { - get - { - return 16; - } - } - - public TransactionBlockBlock() { } - public TransactionBlockBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - TransactionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - TransactionID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += TransactionBlock.Length; - return length; - } - } - public AgentDataBlock AgentData; - public TransactionBlockBlock TransactionBlock; - - public DeclineFriendshipPacket() - { - HasVariableBlocks = false; - Type = PacketType.DeclineFriendship; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 298; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - TransactionBlock = new TransactionBlockBlock(); - } - - public DeclineFriendshipPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - TransactionBlock.FromBytes(bytes, ref i); - } - - public DeclineFriendshipPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - TransactionBlock.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += TransactionBlock.Length; - if (Header.AckList != null && 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); - TransactionBlock.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class TerminateFriendshipPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class ExBlockBlock : PacketBlock - { - public UUID OtherID; - - public override int Length - { - get - { - return 16; - } - } - - public ExBlockBlock() { } - public ExBlockBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - OtherID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - OtherID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += ExBlock.Length; - return length; - } - } - public AgentDataBlock AgentData; - public ExBlockBlock ExBlock; - - public TerminateFriendshipPacket() - { - HasVariableBlocks = false; - Type = PacketType.TerminateFriendship; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 300; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - ExBlock = new ExBlockBlock(); - } - - public TerminateFriendshipPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - ExBlock.FromBytes(bytes, ref i); - } - - public TerminateFriendshipPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - ExBlock.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += ExBlock.Length; - if (Header.AckList != null && 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); - ExBlock.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class OfferCallingCardPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class AgentBlockBlock : PacketBlock - { - public UUID DestID; - public UUID TransactionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentBlockBlock() { } - public AgentBlockBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - DestID.FromBytes(bytes, i); i += 16; - TransactionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - DestID.ToBytes(bytes, i); i += 16; - TransactionID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += AgentBlock.Length; - return length; - } - } - public AgentDataBlock AgentData; - public AgentBlockBlock AgentBlock; - - public OfferCallingCardPacket() - { - HasVariableBlocks = false; - Type = PacketType.OfferCallingCard; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 301; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - AgentBlock = new AgentBlockBlock(); - } - - public OfferCallingCardPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - AgentBlock.FromBytes(bytes, ref i); - } - - public OfferCallingCardPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - AgentBlock.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += AgentBlock.Length; - if (Header.AckList != null && 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); - AgentBlock.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class AcceptCallingCardPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class TransactionBlockBlock : PacketBlock - { - public UUID TransactionID; - - public override int Length - { - get - { - return 16; - } - } - - public TransactionBlockBlock() { } - public TransactionBlockBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - TransactionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - TransactionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class FolderDataBlock : PacketBlock - { - public UUID FolderID; - - public override int Length - { - get - { - return 16; - } - } - - public FolderDataBlock() { } - public FolderDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - FolderID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - FolderID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentData.Length; - length += TransactionBlock.Length; - for (int j = 0; j < FolderData.Length; j++) - length += FolderData[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public TransactionBlockBlock TransactionBlock; - public FolderDataBlock[] FolderData; - - public AcceptCallingCardPacket() - { - HasVariableBlocks = true; - Type = PacketType.AcceptCallingCard; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 302; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - TransactionBlock = new TransactionBlockBlock(); - FolderData = null; - } - - public AcceptCallingCardPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - TransactionBlock.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(FolderData == null || FolderData.Length != -1) { - FolderData = new FolderDataBlock[count]; - for(int j = 0; j < count; j++) - { FolderData[j] = new FolderDataBlock(); } - } - for (int j = 0; j < count; j++) - { FolderData[j].FromBytes(bytes, ref i); } - } - - public AcceptCallingCardPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - TransactionBlock.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(FolderData == null || FolderData.Length != count) { - FolderData = new FolderDataBlock[count]; - for(int j = 0; j < count; j++) - { FolderData[j] = new FolderDataBlock(); } - } - for (int j = 0; j < count; j++) - { FolderData[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += TransactionBlock.Length; - length++; - for (int j = 0; j < FolderData.Length; j++) { length += FolderData[j].Length; } - if (Header.AckList != null && 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); - TransactionBlock.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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - fixedLength += TransactionBlock.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - TransactionBlock.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int FolderDataStart = 0; - do - { - int variableLength = 0; - int FolderDataCount = 0; - - i = FolderDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < FolderData.Length) { - int blockLength = FolderData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == FolderDataStart) { - variableLength += blockLength; - ++FolderDataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)FolderDataCount; - for (i = FolderDataStart; i < FolderDataStart + FolderDataCount; i++) { FolderData[i].ToBytes(packet, ref length); } - FolderDataStart += FolderDataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - FolderDataStart < FolderData.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class DeclineCallingCardPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class TransactionBlockBlock : PacketBlock - { - public UUID TransactionID; - - public override int Length - { - get - { - return 16; - } - } - - public TransactionBlockBlock() { } - public TransactionBlockBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - TransactionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - TransactionID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += TransactionBlock.Length; - return length; - } - } - public AgentDataBlock AgentData; - public TransactionBlockBlock TransactionBlock; - - public DeclineCallingCardPacket() - { - HasVariableBlocks = false; - Type = PacketType.DeclineCallingCard; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 303; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - TransactionBlock = new TransactionBlockBlock(); - } - - public DeclineCallingCardPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - TransactionBlock.FromBytes(bytes, ref i); - } - - public DeclineCallingCardPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - TransactionBlock.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += TransactionBlock.Length; - if (Header.AckList != null && 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); - TransactionBlock.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class RezScriptPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - public UUID GroupID; - - public override int Length - { - get - { - return 48; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - GroupID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - GroupID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class UpdateBlockBlock : PacketBlock - { - public uint ObjectLocalID; - public bool Enabled; - - public override int Length - { - get - { - return 5; - } - } - - public UpdateBlockBlock() { } - public UpdateBlockBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - ObjectLocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - Enabled = (bytes[i++] != 0) ? (bool)true : (bool)false; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UIntToBytes(ObjectLocalID, bytes, i); i += 4; - bytes[i++] = (byte)((Enabled) ? 1 : 0); - } - - } - - /// - public sealed class InventoryBlockBlock : PacketBlock - { - public UUID ItemID; - public UUID FolderID; - public UUID CreatorID; - public UUID OwnerID; - public UUID GroupID; - public uint BaseMask; - public uint OwnerMask; - public uint GroupMask; - public uint EveryoneMask; - public uint NextOwnerMask; - public bool GroupOwned; - public UUID TransactionID; - public sbyte Type; - public sbyte InvType; - public uint Flags; - public byte SaleType; - public int SalePrice; - public byte[] Name; - public byte[] Description; - public int CreationDate; - public uint CRC; - - public override int Length - { - get - { - int length = 138; - if (Name != null) { length += Name.Length; } - if (Description != null) { length += Description.Length; } - return length; - } - } - - public InventoryBlockBlock() { } - public InventoryBlockBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - ItemID.FromBytes(bytes, i); i += 16; - FolderID.FromBytes(bytes, i); i += 16; - CreatorID.FromBytes(bytes, i); i += 16; - OwnerID.FromBytes(bytes, i); i += 16; - GroupID.FromBytes(bytes, i); i += 16; - BaseMask = (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)); - GroupMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - 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)); - GroupOwned = (bytes[i++] != 0) ? (bool)true : (bool)false; - TransactionID.FromBytes(bytes, i); i += 16; - Type = (sbyte)bytes[i++]; - InvType = (sbyte)bytes[i++]; - Flags = (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)); - length = bytes[i++]; - Name = new byte[length]; - Buffer.BlockCopy(bytes, i, Name, 0, length); i += length; - length = bytes[i++]; - Description = new byte[length]; - Buffer.BlockCopy(bytes, i, Description, 0, length); i += length; - CreationDate = (int)(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(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - ItemID.ToBytes(bytes, i); i += 16; - FolderID.ToBytes(bytes, i); i += 16; - CreatorID.ToBytes(bytes, i); i += 16; - OwnerID.ToBytes(bytes, i); i += 16; - GroupID.ToBytes(bytes, i); i += 16; - Utils.UIntToBytes(BaseMask, bytes, i); i += 4; - Utils.UIntToBytes(OwnerMask, bytes, i); i += 4; - Utils.UIntToBytes(GroupMask, bytes, i); i += 4; - Utils.UIntToBytes(EveryoneMask, bytes, i); i += 4; - Utils.UIntToBytes(NextOwnerMask, bytes, i); i += 4; - bytes[i++] = (byte)((GroupOwned) ? 1 : 0); - TransactionID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)Type; - bytes[i++] = (byte)InvType; - Utils.UIntToBytes(Flags, bytes, i); i += 4; - bytes[i++] = SaleType; - Utils.IntToBytes(SalePrice, bytes, i); i += 4; - bytes[i++] = (byte)Name.Length; - Buffer.BlockCopy(Name, 0, bytes, i, Name.Length); i += Name.Length; - bytes[i++] = (byte)Description.Length; - Buffer.BlockCopy(Description, 0, bytes, i, Description.Length); i += Description.Length; - Utils.IntToBytes(CreationDate, bytes, i); i += 4; - Utils.UIntToBytes(CRC, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += UpdateBlock.Length; - length += InventoryBlock.Length; - return length; - } - } - public AgentDataBlock AgentData; - public UpdateBlockBlock UpdateBlock; - public InventoryBlockBlock InventoryBlock; - - public RezScriptPacket() - { - HasVariableBlocks = false; - Type = PacketType.RezScript; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 304; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - UpdateBlock = new UpdateBlockBlock(); - InventoryBlock = new InventoryBlockBlock(); - } - - public RezScriptPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - UpdateBlock.FromBytes(bytes, ref i); - InventoryBlock.FromBytes(bytes, ref i); - } - - public RezScriptPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - UpdateBlock.FromBytes(bytes, ref i); - InventoryBlock.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += UpdateBlock.Length; - length += InventoryBlock.Length; - if (Header.AckList != null && 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); - UpdateBlock.ToBytes(bytes, ref i); - InventoryBlock.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class CreateInventoryItemPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class InventoryBlockBlock : PacketBlock - { - public uint CallbackID; - public UUID FolderID; - public UUID TransactionID; - public uint NextOwnerMask; - public sbyte Type; - public sbyte InvType; - public byte WearableType; - public byte[] Name; - public byte[] Description; - - public override int Length - { - get - { - int length = 45; - if (Name != null) { length += Name.Length; } - if (Description != null) { length += Description.Length; } - return length; - } - } - - public InventoryBlockBlock() { } - public InventoryBlockBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - CallbackID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - FolderID.FromBytes(bytes, i); i += 16; - TransactionID.FromBytes(bytes, i); i += 16; - NextOwnerMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - Type = (sbyte)bytes[i++]; - InvType = (sbyte)bytes[i++]; - WearableType = (byte)bytes[i++]; - length = bytes[i++]; - Name = new byte[length]; - Buffer.BlockCopy(bytes, i, Name, 0, length); i += length; - length = bytes[i++]; - Description = new byte[length]; - Buffer.BlockCopy(bytes, i, Description, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UIntToBytes(CallbackID, bytes, i); i += 4; - FolderID.ToBytes(bytes, i); i += 16; - TransactionID.ToBytes(bytes, i); i += 16; - Utils.UIntToBytes(NextOwnerMask, bytes, i); i += 4; - bytes[i++] = (byte)Type; - bytes[i++] = (byte)InvType; - bytes[i++] = WearableType; - bytes[i++] = (byte)Name.Length; - Buffer.BlockCopy(Name, 0, bytes, i, Name.Length); i += Name.Length; - bytes[i++] = (byte)Description.Length; - Buffer.BlockCopy(Description, 0, bytes, i, Description.Length); i += Description.Length; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += InventoryBlock.Length; - return length; - } - } - public AgentDataBlock AgentData; - public InventoryBlockBlock InventoryBlock; - - public CreateInventoryItemPacket() - { - HasVariableBlocks = false; - Type = PacketType.CreateInventoryItem; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 305; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - InventoryBlock = new InventoryBlockBlock(); - } - - public CreateInventoryItemPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - InventoryBlock.FromBytes(bytes, ref i); - } - - public CreateInventoryItemPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - InventoryBlock.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += InventoryBlock.Length; - if (Header.AckList != null && 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); - InventoryBlock.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class CreateLandmarkForEventPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class EventDataBlock : PacketBlock - { - public uint EventID; - - public override int Length - { - get - { - return 4; - } - } - - public EventDataBlock() { } - public EventDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - EventID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UIntToBytes(EventID, bytes, i); i += 4; - } - - } - - /// - public sealed class InventoryBlockBlock : PacketBlock - { - public UUID FolderID; - public byte[] Name; - - public override int Length - { - get - { - int length = 17; - if (Name != null) { length += Name.Length; } - return length; - } - } - - public InventoryBlockBlock() { } - public InventoryBlockBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - FolderID.FromBytes(bytes, i); i += 16; - length = bytes[i++]; - Name = new byte[length]; - Buffer.BlockCopy(bytes, i, Name, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - FolderID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)Name.Length; - Buffer.BlockCopy(Name, 0, bytes, i, Name.Length); i += Name.Length; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += EventData.Length; - length += InventoryBlock.Length; - return length; - } - } - public AgentDataBlock AgentData; - public EventDataBlock EventData; - public InventoryBlockBlock InventoryBlock; - - public CreateLandmarkForEventPacket() - { - HasVariableBlocks = false; - Type = PacketType.CreateLandmarkForEvent; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 306; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - EventData = new EventDataBlock(); - InventoryBlock = new InventoryBlockBlock(); - } - - public CreateLandmarkForEventPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - EventData.FromBytes(bytes, ref i); - InventoryBlock.FromBytes(bytes, ref i); - } - - public CreateLandmarkForEventPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - EventData.FromBytes(bytes, ref i); - InventoryBlock.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += EventData.Length; - length += InventoryBlock.Length; - if (Header.AckList != null && 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); - EventData.ToBytes(bytes, ref i); - InventoryBlock.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class RegionHandleRequestPacket : Packet - { - /// - public sealed class RequestBlockBlock : PacketBlock - { - public UUID RegionID; - - public override int Length - { - get - { - return 16; - } - } - - public RequestBlockBlock() { } - public RequestBlockBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - RegionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - RegionID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 10; - length += RequestBlock.Length; - return length; - } - } - public RequestBlockBlock RequestBlock; - - public RegionHandleRequestPacket() - { - HasVariableBlocks = false; - Type = PacketType.RegionHandleRequest; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 309; - Header.Reliable = true; - RequestBlock = new RequestBlockBlock(); - } - - public RegionHandleRequestPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - RequestBlock.FromBytes(bytes, ref i); - } - - public RegionHandleRequestPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - RequestBlock.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += RequestBlock.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class RegionIDAndHandleReplyPacket : Packet - { - /// - public sealed class ReplyBlockBlock : PacketBlock - { - public UUID RegionID; - public ulong RegionHandle; - - public override int Length - { - get - { - return 24; - } - } - - public ReplyBlockBlock() { } - public ReplyBlockBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - RegionID.FromBytes(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(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - RegionID.ToBytes(bytes, i); i += 16; - Utils.UInt64ToBytes(RegionHandle, bytes, i); i += 8; - } - - } - - public override int Length - { - get - { - int length = 10; - length += ReplyBlock.Length; - return length; - } - } - public ReplyBlockBlock ReplyBlock; - - public RegionIDAndHandleReplyPacket() - { - HasVariableBlocks = false; - Type = PacketType.RegionIDAndHandleReply; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 310; - Header.Reliable = true; - ReplyBlock = new ReplyBlockBlock(); - } - - public RegionIDAndHandleReplyPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - ReplyBlock.FromBytes(bytes, ref i); - } - - public RegionIDAndHandleReplyPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - ReplyBlock.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += ReplyBlock.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class MoneyTransferRequestPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class MoneyDataBlock : PacketBlock - { - public UUID SourceID; - public UUID DestID; - public byte Flags; - public int Amount; - public byte AggregatePermNextOwner; - public byte AggregatePermInventory; - public int TransactionType; - public byte[] Description; - - public override int Length - { - get - { - int length = 44; - if (Description != null) { length += Description.Length; } - return length; - } - } - - public MoneyDataBlock() { } - public MoneyDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - SourceID.FromBytes(bytes, i); i += 16; - DestID.FromBytes(bytes, i); i += 16; - Flags = (byte)bytes[i++]; - Amount = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - AggregatePermNextOwner = (byte)bytes[i++]; - AggregatePermInventory = (byte)bytes[i++]; - TransactionType = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - length = bytes[i++]; - Description = new byte[length]; - Buffer.BlockCopy(bytes, i, Description, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - SourceID.ToBytes(bytes, i); i += 16; - DestID.ToBytes(bytes, i); i += 16; - bytes[i++] = Flags; - Utils.IntToBytes(Amount, bytes, i); i += 4; - bytes[i++] = AggregatePermNextOwner; - bytes[i++] = AggregatePermInventory; - Utils.IntToBytes(TransactionType, bytes, i); i += 4; - bytes[i++] = (byte)Description.Length; - Buffer.BlockCopy(Description, 0, bytes, i, Description.Length); i += Description.Length; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += MoneyData.Length; - return length; - } - } - public AgentDataBlock AgentData; - public MoneyDataBlock MoneyData; - - public MoneyTransferRequestPacket() - { - HasVariableBlocks = false; - Type = PacketType.MoneyTransferRequest; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 311; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - MoneyData = new MoneyDataBlock(); - } - - public MoneyTransferRequestPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - MoneyData.FromBytes(bytes, ref i); - } - - public MoneyTransferRequestPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - MoneyData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += MoneyData.Length; - if (Header.AckList != null && 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); - MoneyData.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class MoneyBalanceRequestPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class MoneyDataBlock : PacketBlock - { - public UUID TransactionID; - - public override int Length - { - get - { - return 16; - } - } - - public MoneyDataBlock() { } - public MoneyDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - TransactionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - TransactionID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += MoneyData.Length; - return length; - } - } - public AgentDataBlock AgentData; - public MoneyDataBlock MoneyData; - - public MoneyBalanceRequestPacket() - { - HasVariableBlocks = false; - Type = PacketType.MoneyBalanceRequest; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 313; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - MoneyData = new MoneyDataBlock(); - } - - public MoneyBalanceRequestPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - MoneyData.FromBytes(bytes, ref i); - } - - public MoneyBalanceRequestPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - MoneyData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += MoneyData.Length; - if (Header.AckList != null && 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); - MoneyData.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class MoneyBalanceReplyPacket : Packet - { - /// - public sealed class MoneyDataBlock : PacketBlock - { - public UUID AgentID; - public UUID TransactionID; - public bool TransactionSuccess; - public int MoneyBalance; - public int SquareMetersCredit; - public int SquareMetersCommitted; - public byte[] Description; - - public override int Length - { - get - { - int length = 46; - if (Description != null) { length += Description.Length; } - return length; - } - } - - public MoneyDataBlock() { } - public MoneyDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - AgentID.FromBytes(bytes, i); i += 16; - TransactionID.FromBytes(bytes, i); i += 16; - TransactionSuccess = (bytes[i++] != 0) ? (bool)true : (bool)false; - 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)); - SquareMetersCommitted = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - length = bytes[i++]; - Description = new byte[length]; - Buffer.BlockCopy(bytes, i, Description, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - TransactionID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)((TransactionSuccess) ? 1 : 0); - Utils.IntToBytes(MoneyBalance, bytes, i); i += 4; - Utils.IntToBytes(SquareMetersCredit, bytes, i); i += 4; - Utils.IntToBytes(SquareMetersCommitted, bytes, i); i += 4; - bytes[i++] = (byte)Description.Length; - Buffer.BlockCopy(Description, 0, bytes, i, Description.Length); i += Description.Length; - } - - } - - /// - public sealed class TransactionInfoBlock : PacketBlock - { - public int TransactionType; - public UUID SourceID; - public bool IsSourceGroup; - public UUID DestID; - public bool IsDestGroup; - public int Amount; - public byte[] ItemDescription; - - public override int Length - { - get - { - int length = 43; - if (ItemDescription != null) { length += ItemDescription.Length; } - return length; - } - } - - public TransactionInfoBlock() { } - public TransactionInfoBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - TransactionType = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - SourceID.FromBytes(bytes, i); i += 16; - IsSourceGroup = (bytes[i++] != 0) ? (bool)true : (bool)false; - DestID.FromBytes(bytes, i); i += 16; - IsDestGroup = (bytes[i++] != 0) ? (bool)true : (bool)false; - Amount = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - length = bytes[i++]; - ItemDescription = new byte[length]; - Buffer.BlockCopy(bytes, i, ItemDescription, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.IntToBytes(TransactionType, bytes, i); i += 4; - SourceID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)((IsSourceGroup) ? 1 : 0); - DestID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)((IsDestGroup) ? 1 : 0); - Utils.IntToBytes(Amount, bytes, i); i += 4; - bytes[i++] = (byte)ItemDescription.Length; - Buffer.BlockCopy(ItemDescription, 0, bytes, i, ItemDescription.Length); i += ItemDescription.Length; - } - - } - - public override int Length - { - get - { - int length = 10; - length += MoneyData.Length; - length += TransactionInfo.Length; - return length; - } - } - public MoneyDataBlock MoneyData; - public TransactionInfoBlock TransactionInfo; - - public MoneyBalanceReplyPacket() - { - HasVariableBlocks = false; - Type = PacketType.MoneyBalanceReply; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 314; - Header.Reliable = true; - Header.Zerocoded = true; - MoneyData = new MoneyDataBlock(); - TransactionInfo = new TransactionInfoBlock(); - } - - public MoneyBalanceReplyPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - MoneyData.FromBytes(bytes, ref i); - TransactionInfo.FromBytes(bytes, ref i); - } - - public MoneyBalanceReplyPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - MoneyData.FromBytes(bytes, ref i); - TransactionInfo.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += MoneyData.Length; - length += TransactionInfo.Length; - if (Header.AckList != null && 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); - TransactionInfo.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class RoutedMoneyBalanceReplyPacket : Packet - { - /// - public sealed class TargetBlockBlock : PacketBlock - { - public uint TargetIP; - public ushort TargetPort; - - public override int Length - { - get - { - return 6; - } - } - - public TargetBlockBlock() { } - public TargetBlockBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(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(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UIntToBytes(TargetIP, bytes, i); i += 4; - bytes[i++] = (byte)((TargetPort >> 8) % 256); - bytes[i++] = (byte)(TargetPort % 256); - } - - } - - /// - public sealed class MoneyDataBlock : PacketBlock - { - public UUID AgentID; - public UUID TransactionID; - public bool TransactionSuccess; - public int MoneyBalance; - public int SquareMetersCredit; - public int SquareMetersCommitted; - public byte[] Description; - - public override int Length - { - get - { - int length = 46; - if (Description != null) { length += Description.Length; } - return length; - } - } - - public MoneyDataBlock() { } - public MoneyDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - AgentID.FromBytes(bytes, i); i += 16; - TransactionID.FromBytes(bytes, i); i += 16; - TransactionSuccess = (bytes[i++] != 0) ? (bool)true : (bool)false; - 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)); - SquareMetersCommitted = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - length = bytes[i++]; - Description = new byte[length]; - Buffer.BlockCopy(bytes, i, Description, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - TransactionID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)((TransactionSuccess) ? 1 : 0); - Utils.IntToBytes(MoneyBalance, bytes, i); i += 4; - Utils.IntToBytes(SquareMetersCredit, bytes, i); i += 4; - Utils.IntToBytes(SquareMetersCommitted, bytes, i); i += 4; - bytes[i++] = (byte)Description.Length; - Buffer.BlockCopy(Description, 0, bytes, i, Description.Length); i += Description.Length; - } - - } - - /// - public sealed class TransactionInfoBlock : PacketBlock - { - public int TransactionType; - public UUID SourceID; - public bool IsSourceGroup; - public UUID DestID; - public bool IsDestGroup; - public int Amount; - public byte[] ItemDescription; - - public override int Length - { - get - { - int length = 43; - if (ItemDescription != null) { length += ItemDescription.Length; } - return length; - } - } - - public TransactionInfoBlock() { } - public TransactionInfoBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - TransactionType = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - SourceID.FromBytes(bytes, i); i += 16; - IsSourceGroup = (bytes[i++] != 0) ? (bool)true : (bool)false; - DestID.FromBytes(bytes, i); i += 16; - IsDestGroup = (bytes[i++] != 0) ? (bool)true : (bool)false; - Amount = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - length = bytes[i++]; - ItemDescription = new byte[length]; - Buffer.BlockCopy(bytes, i, ItemDescription, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.IntToBytes(TransactionType, bytes, i); i += 4; - SourceID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)((IsSourceGroup) ? 1 : 0); - DestID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)((IsDestGroup) ? 1 : 0); - Utils.IntToBytes(Amount, bytes, i); i += 4; - bytes[i++] = (byte)ItemDescription.Length; - Buffer.BlockCopy(ItemDescription, 0, bytes, i, ItemDescription.Length); i += ItemDescription.Length; - } - - } - - public override int Length - { - get - { - int length = 10; - length += TargetBlock.Length; - length += MoneyData.Length; - length += TransactionInfo.Length; - return length; - } - } - public TargetBlockBlock TargetBlock; - public MoneyDataBlock MoneyData; - public TransactionInfoBlock TransactionInfo; - - public RoutedMoneyBalanceReplyPacket() - { - HasVariableBlocks = false; - Type = PacketType.RoutedMoneyBalanceReply; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 315; - Header.Reliable = true; - Header.Zerocoded = true; - TargetBlock = new TargetBlockBlock(); - MoneyData = new MoneyDataBlock(); - TransactionInfo = new TransactionInfoBlock(); - } - - public RoutedMoneyBalanceReplyPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - TargetBlock.FromBytes(bytes, ref i); - MoneyData.FromBytes(bytes, ref i); - TransactionInfo.FromBytes(bytes, ref i); - } - - public RoutedMoneyBalanceReplyPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - TargetBlock.FromBytes(bytes, ref i); - MoneyData.FromBytes(bytes, ref i); - TransactionInfo.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += TargetBlock.Length; - length += MoneyData.Length; - length += TransactionInfo.Length; - if (Header.AckList != null && 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); - TransactionInfo.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class ActivateGesturesPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - public uint Flags; - - public override int Length - { - get - { - return 36; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - Flags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - Utils.UIntToBytes(Flags, bytes, i); i += 4; - } - - } - - /// - public sealed class DataBlock : PacketBlock - { - public UUID ItemID; - public UUID AssetID; - public uint GestureFlags; - - public override int Length - { - get - { - return 36; - } - } - - public DataBlock() { } - public DataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - ItemID.FromBytes(bytes, i); i += 16; - AssetID.FromBytes(bytes, i); i += 16; - GestureFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - ItemID.ToBytes(bytes, i); i += 16; - AssetID.ToBytes(bytes, i); i += 16; - Utils.UIntToBytes(GestureFlags, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentData.Length; - for (int j = 0; j < Data.Length; j++) - length += Data[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public DataBlock[] Data; - - public ActivateGesturesPacket() - { - HasVariableBlocks = true; - Type = PacketType.ActivateGestures; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 316; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - Data = null; - } - - public ActivateGesturesPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(Data == null || Data.Length != -1) { - Data = new DataBlock[count]; - for(int j = 0; j < count; j++) - { Data[j] = new DataBlock(); } - } - for (int j = 0; j < count; j++) - { Data[j].FromBytes(bytes, ref i); } - } - - public ActivateGesturesPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(Data == null || Data.Length != count) { - Data = new DataBlock[count]; - for(int j = 0; j < count; j++) - { Data[j] = new DataBlock(); } - } - for (int j = 0; j < count; j++) - { Data[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length++; - for (int j = 0; j < Data.Length; j++) { length += Data[j].Length; } - if (Header.AckList != null && 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)Data.Length; - for (int j = 0; j < Data.Length; j++) { Data[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int DataStart = 0; - do - { - int variableLength = 0; - int DataCount = 0; - - i = DataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < Data.Length) { - int blockLength = Data[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == DataStart) { - variableLength += blockLength; - ++DataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)DataCount; - for (i = DataStart; i < DataStart + DataCount; i++) { Data[i].ToBytes(packet, ref length); } - DataStart += DataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - DataStart < Data.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class DeactivateGesturesPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - public uint Flags; - - public override int Length - { - get - { - return 36; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - Flags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - Utils.UIntToBytes(Flags, bytes, i); i += 4; - } - - } - - /// - public sealed class DataBlock : PacketBlock - { - public UUID ItemID; - public uint GestureFlags; - - public override int Length - { - get - { - return 20; - } - } - - public DataBlock() { } - public DataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - ItemID.FromBytes(bytes, i); i += 16; - GestureFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - ItemID.ToBytes(bytes, i); i += 16; - Utils.UIntToBytes(GestureFlags, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentData.Length; - for (int j = 0; j < Data.Length; j++) - length += Data[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public DataBlock[] Data; - - public DeactivateGesturesPacket() - { - HasVariableBlocks = true; - Type = PacketType.DeactivateGestures; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 317; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - Data = null; - } - - public DeactivateGesturesPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(Data == null || Data.Length != -1) { - Data = new DataBlock[count]; - for(int j = 0; j < count; j++) - { Data[j] = new DataBlock(); } - } - for (int j = 0; j < count; j++) - { Data[j].FromBytes(bytes, ref i); } - } - - public DeactivateGesturesPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(Data == null || Data.Length != count) { - Data = new DataBlock[count]; - for(int j = 0; j < count; j++) - { Data[j] = new DataBlock(); } - } - for (int j = 0; j < count; j++) - { Data[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length++; - for (int j = 0; j < Data.Length; j++) { length += Data[j].Length; } - if (Header.AckList != null && 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)Data.Length; - for (int j = 0; j < Data.Length; j++) { Data[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int DataStart = 0; - do - { - int variableLength = 0; - int DataCount = 0; - - i = DataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < Data.Length) { - int blockLength = Data[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == DataStart) { - variableLength += blockLength; - ++DataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)DataCount; - for (i = DataStart; i < DataStart + DataCount; i++) { Data[i].ToBytes(packet, ref length); } - DataStart += DataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - DataStart < Data.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class MuteListUpdatePacket : Packet - { - /// - public sealed class MuteDataBlock : PacketBlock - { - public UUID AgentID; - public byte[] Filename; - - public override int Length - { - get - { - int length = 17; - if (Filename != null) { length += Filename.Length; } - return length; - } - } - - public MuteDataBlock() { } - public MuteDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - AgentID.FromBytes(bytes, i); i += 16; - length = bytes[i++]; - Filename = new byte[length]; - Buffer.BlockCopy(bytes, i, Filename, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)Filename.Length; - Buffer.BlockCopy(Filename, 0, bytes, i, Filename.Length); i += Filename.Length; - } - - } - - public override int Length - { - get - { - int length = 10; - length += MuteData.Length; - return length; - } - } - public MuteDataBlock MuteData; - - public MuteListUpdatePacket() - { - HasVariableBlocks = false; - Type = PacketType.MuteListUpdate; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 318; - Header.Reliable = true; - MuteData = new MuteDataBlock(); - } - - public MuteListUpdatePacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - MuteData.FromBytes(bytes, ref i); - } - - public MuteListUpdatePacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - MuteData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += MuteData.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class UseCachedMuteListPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - - public override int Length - { - get - { - return 16; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - return length; - } - } - public AgentDataBlock AgentData; - - public UseCachedMuteListPacket() - { - HasVariableBlocks = false; - Type = PacketType.UseCachedMuteList; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 319; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - } - - public UseCachedMuteListPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - } - - public UseCachedMuteListPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class GrantUserRightsPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class RightsBlock : PacketBlock - { - public UUID AgentRelated; - public int RelatedRights; - - public override int Length - { - get - { - return 20; - } - } - - public RightsBlock() { } - public RightsBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentRelated.FromBytes(bytes, i); i += 16; - RelatedRights = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentRelated.ToBytes(bytes, i); i += 16; - Utils.IntToBytes(RelatedRights, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentData.Length; - for (int j = 0; j < Rights.Length; j++) - length += Rights[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public RightsBlock[] Rights; - - public GrantUserRightsPacket() - { - HasVariableBlocks = true; - Type = PacketType.GrantUserRights; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 320; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - Rights = null; - } - - public GrantUserRightsPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(Rights == null || Rights.Length != -1) { - Rights = new RightsBlock[count]; - for(int j = 0; j < count; j++) - { Rights[j] = new RightsBlock(); } - } - for (int j = 0; j < count; j++) - { Rights[j].FromBytes(bytes, ref i); } - } - - public GrantUserRightsPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(Rights == null || Rights.Length != count) { - Rights = new RightsBlock[count]; - for(int j = 0; j < count; j++) - { Rights[j] = new RightsBlock(); } - } - for (int j = 0; j < count; j++) - { Rights[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length++; - for (int j = 0; j < Rights.Length; j++) { length += Rights[j].Length; } - if (Header.AckList != null && 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)Rights.Length; - for (int j = 0; j < Rights.Length; j++) { Rights[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int RightsStart = 0; - do - { - int variableLength = 0; - int RightsCount = 0; - - i = RightsStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < Rights.Length) { - int blockLength = Rights[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == RightsStart) { - variableLength += blockLength; - ++RightsCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)RightsCount; - for (i = RightsStart; i < RightsStart + RightsCount; i++) { Rights[i].ToBytes(packet, ref length); } - RightsStart += RightsCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - RightsStart < Rights.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class ChangeUserRightsPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - - public override int Length - { - get - { - return 16; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class RightsBlock : PacketBlock - { - public UUID AgentRelated; - public int RelatedRights; - - public override int Length - { - get - { - return 20; - } - } - - public RightsBlock() { } - public RightsBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentRelated.FromBytes(bytes, i); i += 16; - RelatedRights = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentRelated.ToBytes(bytes, i); i += 16; - Utils.IntToBytes(RelatedRights, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentData.Length; - for (int j = 0; j < Rights.Length; j++) - length += Rights[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public RightsBlock[] Rights; - - public ChangeUserRightsPacket() - { - HasVariableBlocks = true; - Type = PacketType.ChangeUserRights; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 321; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - Rights = null; - } - - public ChangeUserRightsPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(Rights == null || Rights.Length != -1) { - Rights = new RightsBlock[count]; - for(int j = 0; j < count; j++) - { Rights[j] = new RightsBlock(); } - } - for (int j = 0; j < count; j++) - { Rights[j].FromBytes(bytes, ref i); } - } - - public ChangeUserRightsPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(Rights == null || Rights.Length != count) { - Rights = new RightsBlock[count]; - for(int j = 0; j < count; j++) - { Rights[j] = new RightsBlock(); } - } - for (int j = 0; j < count; j++) - { Rights[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length++; - for (int j = 0; j < Rights.Length; j++) { length += Rights[j].Length; } - if (Header.AckList != null && 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)Rights.Length; - for (int j = 0; j < Rights.Length; j++) { Rights[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int RightsStart = 0; - do - { - int variableLength = 0; - int RightsCount = 0; - - i = RightsStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < Rights.Length) { - int blockLength = Rights[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == RightsStart) { - variableLength += blockLength; - ++RightsCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)RightsCount; - for (i = RightsStart; i < RightsStart + RightsCount; i++) { Rights[i].ToBytes(packet, ref length); } - RightsStart += RightsCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - RightsStart < Rights.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class OnlineNotificationPacket : Packet - { - /// - public sealed class AgentBlockBlock : PacketBlock - { - public UUID AgentID; - - public override int Length - { - get - { - return 16; - } - } - - public AgentBlockBlock() { } - public AgentBlockBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 11; - for (int j = 0; j < AgentBlock.Length; j++) - length += AgentBlock[j].Length; - return length; - } - } - public AgentBlockBlock[] AgentBlock; - - public OnlineNotificationPacket() - { - HasVariableBlocks = true; - Type = PacketType.OnlineNotification; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 322; - Header.Reliable = true; - AgentBlock = null; - } - - public OnlineNotificationPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - int count = (int)bytes[i++]; - if(AgentBlock == null || AgentBlock.Length != -1) { - AgentBlock = new AgentBlockBlock[count]; - for(int j = 0; j < count; j++) - { AgentBlock[j] = new AgentBlockBlock(); } - } - for (int j = 0; j < count; j++) - { AgentBlock[j].FromBytes(bytes, ref i); } - } - - public OnlineNotificationPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - int count = (int)bytes[i++]; - if(AgentBlock == null || AgentBlock.Length != count) { - AgentBlock = new AgentBlockBlock[count]; - for(int j = 0; j < count; j++) - { AgentBlock[j] = new AgentBlockBlock(); } - } - for (int j = 0; j < count; j++) - { AgentBlock[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length++; - for (int j = 0; j < AgentBlock.Length; j++) { length += AgentBlock[j].Length; } - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int AgentBlockStart = 0; - do - { - int variableLength = 0; - int AgentBlockCount = 0; - - i = AgentBlockStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < AgentBlock.Length) { - int blockLength = AgentBlock[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == AgentBlockStart) { - variableLength += blockLength; - ++AgentBlockCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)AgentBlockCount; - for (i = AgentBlockStart; i < AgentBlockStart + AgentBlockCount; i++) { AgentBlock[i].ToBytes(packet, ref length); } - AgentBlockStart += AgentBlockCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - AgentBlockStart < AgentBlock.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class OfflineNotificationPacket : Packet - { - /// - public sealed class AgentBlockBlock : PacketBlock - { - public UUID AgentID; - - public override int Length - { - get - { - return 16; - } - } - - public AgentBlockBlock() { } - public AgentBlockBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 11; - for (int j = 0; j < AgentBlock.Length; j++) - length += AgentBlock[j].Length; - return length; - } - } - public AgentBlockBlock[] AgentBlock; - - public OfflineNotificationPacket() - { - HasVariableBlocks = true; - Type = PacketType.OfflineNotification; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 323; - Header.Reliable = true; - AgentBlock = null; - } - - public OfflineNotificationPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - int count = (int)bytes[i++]; - if(AgentBlock == null || AgentBlock.Length != -1) { - AgentBlock = new AgentBlockBlock[count]; - for(int j = 0; j < count; j++) - { AgentBlock[j] = new AgentBlockBlock(); } - } - for (int j = 0; j < count; j++) - { AgentBlock[j].FromBytes(bytes, ref i); } - } - - public OfflineNotificationPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - int count = (int)bytes[i++]; - if(AgentBlock == null || AgentBlock.Length != count) { - AgentBlock = new AgentBlockBlock[count]; - for(int j = 0; j < count; j++) - { AgentBlock[j] = new AgentBlockBlock(); } - } - for (int j = 0; j < count; j++) - { AgentBlock[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length++; - for (int j = 0; j < AgentBlock.Length; j++) { length += AgentBlock[j].Length; } - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int AgentBlockStart = 0; - do - { - int variableLength = 0; - int AgentBlockCount = 0; - - i = AgentBlockStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < AgentBlock.Length) { - int blockLength = AgentBlock[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == AgentBlockStart) { - variableLength += blockLength; - ++AgentBlockCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)AgentBlockCount; - for (i = AgentBlockStart; i < AgentBlockStart + AgentBlockCount; i++) { AgentBlock[i].ToBytes(packet, ref length); } - AgentBlockStart += AgentBlockCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - AgentBlockStart < AgentBlock.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class SetStartLocationRequestPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class StartLocationDataBlock : PacketBlock - { - public byte[] SimName; - public uint LocationID; - public Vector3 LocationPos; - public Vector3 LocationLookAt; - - public override int Length - { - get - { - int length = 29; - if (SimName != null) { length += SimName.Length; } - return length; - } - } - - public StartLocationDataBlock() { } - public StartLocationDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - length = bytes[i++]; - SimName = new byte[length]; - Buffer.BlockCopy(bytes, i, SimName, 0, length); i += length; - LocationID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - LocationPos.FromBytes(bytes, i); i += 12; - LocationLookAt.FromBytes(bytes, i); i += 12; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - bytes[i++] = (byte)SimName.Length; - Buffer.BlockCopy(SimName, 0, bytes, i, SimName.Length); i += SimName.Length; - Utils.UIntToBytes(LocationID, bytes, i); i += 4; - LocationPos.ToBytes(bytes, i); i += 12; - LocationLookAt.ToBytes(bytes, i); i += 12; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += StartLocationData.Length; - return length; - } - } - public AgentDataBlock AgentData; - public StartLocationDataBlock StartLocationData; - - public SetStartLocationRequestPacket() - { - HasVariableBlocks = false; - Type = PacketType.SetStartLocationRequest; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 324; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - StartLocationData = new StartLocationDataBlock(); - } - - public SetStartLocationRequestPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - StartLocationData.FromBytes(bytes, ref i); - } - - public SetStartLocationRequestPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - StartLocationData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += StartLocationData.Length; - if (Header.AckList != null && 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); - StartLocationData.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class AssetUploadRequestPacket : Packet - { - /// - public sealed class AssetBlockBlock : PacketBlock - { - public UUID TransactionID; - public sbyte Type; - public bool Tempfile; - public bool StoreLocal; - public byte[] AssetData; - - public override int Length - { - get - { - int length = 21; - if (AssetData != null) { length += AssetData.Length; } - return length; - } - } - - public AssetBlockBlock() { } - public AssetBlockBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - TransactionID.FromBytes(bytes, i); i += 16; - Type = (sbyte)bytes[i++]; - Tempfile = (bytes[i++] != 0) ? (bool)true : (bool)false; - StoreLocal = (bytes[i++] != 0) ? (bool)true : (bool)false; - length = (bytes[i++] + (bytes[i++] << 8)); - AssetData = new byte[length]; - Buffer.BlockCopy(bytes, i, AssetData, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - TransactionID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)Type; - bytes[i++] = (byte)((Tempfile) ? 1 : 0); - bytes[i++] = (byte)((StoreLocal) ? 1 : 0); - bytes[i++] = (byte)(AssetData.Length % 256); - bytes[i++] = (byte)((AssetData.Length >> 8) % 256); - Buffer.BlockCopy(AssetData, 0, bytes, i, AssetData.Length); i += AssetData.Length; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AssetBlock.Length; - return length; - } - } - public AssetBlockBlock AssetBlock; - - public AssetUploadRequestPacket() - { - HasVariableBlocks = false; - Type = PacketType.AssetUploadRequest; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 333; - Header.Reliable = true; - AssetBlock = new AssetBlockBlock(); - } - - public AssetUploadRequestPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AssetBlock.FromBytes(bytes, ref i); - } - - public AssetUploadRequestPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AssetBlock.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AssetBlock.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class AssetUploadCompletePacket : Packet - { - /// - public sealed class AssetBlockBlock : PacketBlock - { - public UUID UUID; - public sbyte Type; - public bool Success; - - public override int Length - { - get - { - return 18; - } - } - - public AssetBlockBlock() { } - public AssetBlockBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - UUID.FromBytes(bytes, i); i += 16; - Type = (sbyte)bytes[i++]; - Success = (bytes[i++] != 0) ? (bool)true : (bool)false; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - UUID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)Type; - bytes[i++] = (byte)((Success) ? 1 : 0); - } - - } - - public override int Length - { - get - { - int length = 10; - length += AssetBlock.Length; - return length; - } - } - public AssetBlockBlock AssetBlock; - - public AssetUploadCompletePacket() - { - HasVariableBlocks = false; - Type = PacketType.AssetUploadComplete; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 334; - Header.Reliable = true; - AssetBlock = new AssetBlockBlock(); - } - - public AssetUploadCompletePacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AssetBlock.FromBytes(bytes, ref i); - } - - public AssetUploadCompletePacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AssetBlock.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AssetBlock.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class CreateGroupRequestPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class GroupDataBlock : PacketBlock - { - public byte[] Name; - public byte[] Charter; - public bool ShowInList; - public UUID InsigniaID; - public int MembershipFee; - public bool OpenEnrollment; - public bool AllowPublish; - public bool MaturePublish; - - public override int Length - { - get - { - int length = 27; - if (Name != null) { length += Name.Length; } - if (Charter != null) { length += Charter.Length; } - return length; - } - } - - public GroupDataBlock() { } - public GroupDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - length = bytes[i++]; - Name = new byte[length]; - Buffer.BlockCopy(bytes, i, Name, 0, length); i += length; - length = (bytes[i++] + (bytes[i++] << 8)); - Charter = new byte[length]; - Buffer.BlockCopy(bytes, i, Charter, 0, length); i += length; - ShowInList = (bytes[i++] != 0) ? (bool)true : (bool)false; - InsigniaID.FromBytes(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; - AllowPublish = (bytes[i++] != 0) ? (bool)true : (bool)false; - MaturePublish = (bytes[i++] != 0) ? (bool)true : (bool)false; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - bytes[i++] = (byte)Name.Length; - Buffer.BlockCopy(Name, 0, bytes, i, Name.Length); i += Name.Length; - bytes[i++] = (byte)(Charter.Length % 256); - bytes[i++] = (byte)((Charter.Length >> 8) % 256); - Buffer.BlockCopy(Charter, 0, bytes, i, Charter.Length); i += Charter.Length; - bytes[i++] = (byte)((ShowInList) ? 1 : 0); - InsigniaID.ToBytes(bytes, i); i += 16; - Utils.IntToBytes(MembershipFee, bytes, i); i += 4; - bytes[i++] = (byte)((OpenEnrollment) ? 1 : 0); - bytes[i++] = (byte)((AllowPublish) ? 1 : 0); - bytes[i++] = (byte)((MaturePublish) ? 1 : 0); - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += GroupData.Length; - return length; - } - } - public AgentDataBlock AgentData; - public GroupDataBlock GroupData; - - public CreateGroupRequestPacket() - { - HasVariableBlocks = false; - Type = PacketType.CreateGroupRequest; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 339; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - GroupData = new GroupDataBlock(); - } - - public CreateGroupRequestPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - GroupData.FromBytes(bytes, ref i); - } - - public CreateGroupRequestPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - GroupData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += GroupData.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class CreateGroupReplyPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - - public override int Length - { - get - { - return 16; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class ReplyDataBlock : PacketBlock - { - public UUID GroupID; - public bool Success; - public byte[] Message; - - public override int Length - { - get - { - int length = 18; - if (Message != null) { length += Message.Length; } - return length; - } - } - - public ReplyDataBlock() { } - public ReplyDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - GroupID.FromBytes(bytes, i); i += 16; - Success = (bytes[i++] != 0) ? (bool)true : (bool)false; - length = bytes[i++]; - Message = new byte[length]; - Buffer.BlockCopy(bytes, i, Message, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - GroupID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)((Success) ? 1 : 0); - bytes[i++] = (byte)Message.Length; - Buffer.BlockCopy(Message, 0, bytes, i, Message.Length); i += Message.Length; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += ReplyData.Length; - return length; - } - } - public AgentDataBlock AgentData; - public ReplyDataBlock ReplyData; - - public CreateGroupReplyPacket() - { - HasVariableBlocks = false; - Type = PacketType.CreateGroupReply; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 340; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - ReplyData = new ReplyDataBlock(); - } - - public CreateGroupReplyPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - ReplyData.FromBytes(bytes, ref i); - } - - public CreateGroupReplyPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - ReplyData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += ReplyData.Length; - if (Header.AckList != null && 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); - ReplyData.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class UpdateGroupInfoPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class GroupDataBlock : PacketBlock - { - public UUID GroupID; - public byte[] Charter; - public bool ShowInList; - public UUID InsigniaID; - public int MembershipFee; - public bool OpenEnrollment; - public bool AllowPublish; - public bool MaturePublish; - - public override int Length - { - get - { - int length = 42; - if (Charter != null) { length += Charter.Length; } - return length; - } - } - - public GroupDataBlock() { } - public GroupDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - GroupID.FromBytes(bytes, i); i += 16; - length = (bytes[i++] + (bytes[i++] << 8)); - Charter = new byte[length]; - Buffer.BlockCopy(bytes, i, Charter, 0, length); i += length; - ShowInList = (bytes[i++] != 0) ? (bool)true : (bool)false; - InsigniaID.FromBytes(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; - AllowPublish = (bytes[i++] != 0) ? (bool)true : (bool)false; - MaturePublish = (bytes[i++] != 0) ? (bool)true : (bool)false; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - GroupID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)(Charter.Length % 256); - bytes[i++] = (byte)((Charter.Length >> 8) % 256); - Buffer.BlockCopy(Charter, 0, bytes, i, Charter.Length); i += Charter.Length; - bytes[i++] = (byte)((ShowInList) ? 1 : 0); - InsigniaID.ToBytes(bytes, i); i += 16; - Utils.IntToBytes(MembershipFee, bytes, i); i += 4; - bytes[i++] = (byte)((OpenEnrollment) ? 1 : 0); - bytes[i++] = (byte)((AllowPublish) ? 1 : 0); - bytes[i++] = (byte)((MaturePublish) ? 1 : 0); - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += GroupData.Length; - return length; - } - } - public AgentDataBlock AgentData; - public GroupDataBlock GroupData; - - public UpdateGroupInfoPacket() - { - HasVariableBlocks = false; - Type = PacketType.UpdateGroupInfo; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 341; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - GroupData = new GroupDataBlock(); - } - - public UpdateGroupInfoPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - GroupData.FromBytes(bytes, ref i); - } - - public UpdateGroupInfoPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - GroupData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += GroupData.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class GroupRoleChangesPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - public UUID GroupID; - - public override int Length - { - get - { - return 48; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - GroupID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - GroupID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class RoleChangeBlock : PacketBlock - { - public UUID RoleID; - public UUID MemberID; - public uint Change; - - public override int Length - { - get - { - return 36; - } - } - - public RoleChangeBlock() { } - public RoleChangeBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - RoleID.FromBytes(bytes, i); i += 16; - MemberID.FromBytes(bytes, i); i += 16; - Change = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - RoleID.ToBytes(bytes, i); i += 16; - MemberID.ToBytes(bytes, i); i += 16; - Utils.UIntToBytes(Change, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentData.Length; - for (int j = 0; j < RoleChange.Length; j++) - length += RoleChange[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public RoleChangeBlock[] RoleChange; - - public GroupRoleChangesPacket() - { - HasVariableBlocks = true; - Type = PacketType.GroupRoleChanges; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 342; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - RoleChange = null; - } - - public GroupRoleChangesPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(RoleChange == null || RoleChange.Length != -1) { - RoleChange = new RoleChangeBlock[count]; - for(int j = 0; j < count; j++) - { RoleChange[j] = new RoleChangeBlock(); } - } - for (int j = 0; j < count; j++) - { RoleChange[j].FromBytes(bytes, ref i); } - } - - public GroupRoleChangesPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(RoleChange == null || RoleChange.Length != count) { - RoleChange = new RoleChangeBlock[count]; - for(int j = 0; j < count; j++) - { RoleChange[j] = new RoleChangeBlock(); } - } - for (int j = 0; j < count; j++) - { RoleChange[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length++; - for (int j = 0; j < RoleChange.Length; j++) { length += RoleChange[j].Length; } - if (Header.AckList != null && 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)RoleChange.Length; - for (int j = 0; j < RoleChange.Length; j++) { RoleChange[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int RoleChangeStart = 0; - do - { - int variableLength = 0; - int RoleChangeCount = 0; - - i = RoleChangeStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < RoleChange.Length) { - int blockLength = RoleChange[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == RoleChangeStart) { - variableLength += blockLength; - ++RoleChangeCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)RoleChangeCount; - for (i = RoleChangeStart; i < RoleChangeStart + RoleChangeCount; i++) { RoleChange[i].ToBytes(packet, ref length); } - RoleChangeStart += RoleChangeCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - RoleChangeStart < RoleChange.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class JoinGroupRequestPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class GroupDataBlock : PacketBlock - { - public UUID GroupID; - - public override int Length - { - get - { - return 16; - } - } - - public GroupDataBlock() { } - public GroupDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - GroupID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - GroupID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += GroupData.Length; - return length; - } - } - public AgentDataBlock AgentData; - public GroupDataBlock GroupData; - - public JoinGroupRequestPacket() - { - HasVariableBlocks = false; - Type = PacketType.JoinGroupRequest; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 343; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - GroupData = new GroupDataBlock(); - } - - public JoinGroupRequestPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - GroupData.FromBytes(bytes, ref i); - } - - public JoinGroupRequestPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - GroupData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += GroupData.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class JoinGroupReplyPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - - public override int Length - { - get - { - return 16; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class GroupDataBlock : PacketBlock - { - public UUID GroupID; - public bool Success; - - public override int Length - { - get - { - return 17; - } - } - - public GroupDataBlock() { } - public GroupDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - GroupID.FromBytes(bytes, i); i += 16; - Success = (bytes[i++] != 0) ? (bool)true : (bool)false; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - GroupID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)((Success) ? 1 : 0); - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += GroupData.Length; - return length; - } - } - public AgentDataBlock AgentData; - public GroupDataBlock GroupData; - - public JoinGroupReplyPacket() - { - HasVariableBlocks = false; - Type = PacketType.JoinGroupReply; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 344; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - GroupData = new GroupDataBlock(); - } - - public JoinGroupReplyPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - GroupData.FromBytes(bytes, ref i); - } - - public JoinGroupReplyPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - GroupData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += GroupData.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class EjectGroupMemberRequestPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class GroupDataBlock : PacketBlock - { - public UUID GroupID; - - public override int Length - { - get - { - return 16; - } - } - - public GroupDataBlock() { } - public GroupDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - GroupID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - GroupID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class EjectDataBlock : PacketBlock - { - public UUID EjecteeID; - - public override int Length - { - get - { - return 16; - } - } - - public EjectDataBlock() { } - public EjectDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - EjecteeID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - EjecteeID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentData.Length; - length += GroupData.Length; - for (int j = 0; j < EjectData.Length; j++) - length += EjectData[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public GroupDataBlock GroupData; - public EjectDataBlock[] EjectData; - - public EjectGroupMemberRequestPacket() - { - HasVariableBlocks = true; - Type = PacketType.EjectGroupMemberRequest; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 345; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - GroupData = new GroupDataBlock(); - EjectData = null; - } - - public EjectGroupMemberRequestPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - GroupData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(EjectData == null || EjectData.Length != -1) { - EjectData = new EjectDataBlock[count]; - for(int j = 0; j < count; j++) - { EjectData[j] = new EjectDataBlock(); } - } - for (int j = 0; j < count; j++) - { EjectData[j].FromBytes(bytes, ref i); } - } - - public EjectGroupMemberRequestPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - GroupData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(EjectData == null || EjectData.Length != count) { - EjectData = new EjectDataBlock[count]; - for(int j = 0; j < count; j++) - { EjectData[j] = new EjectDataBlock(); } - } - for (int j = 0; j < count; j++) - { EjectData[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += GroupData.Length; - length++; - for (int j = 0; j < EjectData.Length; j++) { length += EjectData[j].Length; } - if (Header.AckList != null && 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); - bytes[i++] = (byte)EjectData.Length; - for (int j = 0; j < EjectData.Length; j++) { EjectData[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - fixedLength += GroupData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - GroupData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int EjectDataStart = 0; - do - { - int variableLength = 0; - int EjectDataCount = 0; - - i = EjectDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < EjectData.Length) { - int blockLength = EjectData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == EjectDataStart) { - variableLength += blockLength; - ++EjectDataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)EjectDataCount; - for (i = EjectDataStart; i < EjectDataStart + EjectDataCount; i++) { EjectData[i].ToBytes(packet, ref length); } - EjectDataStart += EjectDataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - EjectDataStart < EjectData.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class EjectGroupMemberReplyPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - - public override int Length - { - get - { - return 16; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class GroupDataBlock : PacketBlock - { - public UUID GroupID; - - public override int Length - { - get - { - return 16; - } - } - - public GroupDataBlock() { } - public GroupDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - GroupID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - GroupID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class EjectDataBlock : PacketBlock - { - public bool Success; - - public override int Length - { - get - { - return 1; - } - } - - public EjectDataBlock() { } - public EjectDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - Success = (bytes[i++] != 0) ? (bool)true : (bool)false; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - bytes[i++] = (byte)((Success) ? 1 : 0); - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += GroupData.Length; - length += EjectData.Length; - return length; - } - } - public AgentDataBlock AgentData; - public GroupDataBlock GroupData; - public EjectDataBlock EjectData; - - public EjectGroupMemberReplyPacket() - { - HasVariableBlocks = false; - Type = PacketType.EjectGroupMemberReply; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 346; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - GroupData = new GroupDataBlock(); - EjectData = new EjectDataBlock(); - } - - public EjectGroupMemberReplyPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - GroupData.FromBytes(bytes, ref i); - EjectData.FromBytes(bytes, ref i); - } - - public EjectGroupMemberReplyPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - GroupData.FromBytes(bytes, ref i); - EjectData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += GroupData.Length; - length += EjectData.Length; - if (Header.AckList != null && 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); - EjectData.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class LeaveGroupRequestPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class GroupDataBlock : PacketBlock - { - public UUID GroupID; - - public override int Length - { - get - { - return 16; - } - } - - public GroupDataBlock() { } - public GroupDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - GroupID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - GroupID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += GroupData.Length; - return length; - } - } - public AgentDataBlock AgentData; - public GroupDataBlock GroupData; - - public LeaveGroupRequestPacket() - { - HasVariableBlocks = false; - Type = PacketType.LeaveGroupRequest; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 347; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - GroupData = new GroupDataBlock(); - } - - public LeaveGroupRequestPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - GroupData.FromBytes(bytes, ref i); - } - - public LeaveGroupRequestPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - GroupData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += GroupData.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class LeaveGroupReplyPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - - public override int Length - { - get - { - return 16; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class GroupDataBlock : PacketBlock - { - public UUID GroupID; - public bool Success; - - public override int Length - { - get - { - return 17; - } - } - - public GroupDataBlock() { } - public GroupDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - GroupID.FromBytes(bytes, i); i += 16; - Success = (bytes[i++] != 0) ? (bool)true : (bool)false; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - GroupID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)((Success) ? 1 : 0); - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += GroupData.Length; - return length; - } - } - public AgentDataBlock AgentData; - public GroupDataBlock GroupData; - - public LeaveGroupReplyPacket() - { - HasVariableBlocks = false; - Type = PacketType.LeaveGroupReply; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 348; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - GroupData = new GroupDataBlock(); - } - - public LeaveGroupReplyPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - GroupData.FromBytes(bytes, ref i); - } - - public LeaveGroupReplyPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - GroupData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += GroupData.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class InviteGroupRequestPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class GroupDataBlock : PacketBlock - { - public UUID GroupID; - - public override int Length - { - get - { - return 16; - } - } - - public GroupDataBlock() { } - public GroupDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - GroupID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - GroupID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class InviteDataBlock : PacketBlock - { - public UUID InviteeID; - public UUID RoleID; - - public override int Length - { - get - { - return 32; - } - } - - public InviteDataBlock() { } - public InviteDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - InviteeID.FromBytes(bytes, i); i += 16; - RoleID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - InviteeID.ToBytes(bytes, i); i += 16; - RoleID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentData.Length; - length += GroupData.Length; - for (int j = 0; j < InviteData.Length; j++) - length += InviteData[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public GroupDataBlock GroupData; - public InviteDataBlock[] InviteData; - - public InviteGroupRequestPacket() - { - HasVariableBlocks = true; - Type = PacketType.InviteGroupRequest; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 349; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - GroupData = new GroupDataBlock(); - InviteData = null; - } - - public InviteGroupRequestPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - GroupData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(InviteData == null || InviteData.Length != -1) { - InviteData = new InviteDataBlock[count]; - for(int j = 0; j < count; j++) - { InviteData[j] = new InviteDataBlock(); } - } - for (int j = 0; j < count; j++) - { InviteData[j].FromBytes(bytes, ref i); } - } - - public InviteGroupRequestPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - GroupData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(InviteData == null || InviteData.Length != count) { - InviteData = new InviteDataBlock[count]; - for(int j = 0; j < count; j++) - { InviteData[j] = new InviteDataBlock(); } - } - for (int j = 0; j < count; j++) - { InviteData[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += GroupData.Length; - length++; - for (int j = 0; j < InviteData.Length; j++) { length += InviteData[j].Length; } - if (Header.AckList != null && 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); - bytes[i++] = (byte)InviteData.Length; - for (int j = 0; j < InviteData.Length; j++) { InviteData[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - fixedLength += GroupData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - GroupData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int InviteDataStart = 0; - do - { - int variableLength = 0; - int InviteDataCount = 0; - - i = InviteDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < InviteData.Length) { - int blockLength = InviteData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == InviteDataStart) { - variableLength += blockLength; - ++InviteDataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)InviteDataCount; - for (i = InviteDataStart; i < InviteDataStart + InviteDataCount; i++) { InviteData[i].ToBytes(packet, ref length); } - InviteDataStart += InviteDataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - InviteDataStart < InviteData.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class GroupProfileRequestPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class GroupDataBlock : PacketBlock - { - public UUID GroupID; - - public override int Length - { - get - { - return 16; - } - } - - public GroupDataBlock() { } - public GroupDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - GroupID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - GroupID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += GroupData.Length; - return length; - } - } - public AgentDataBlock AgentData; - public GroupDataBlock GroupData; - - public GroupProfileRequestPacket() - { - HasVariableBlocks = false; - Type = PacketType.GroupProfileRequest; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 351; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - GroupData = new GroupDataBlock(); - } - - public GroupProfileRequestPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - GroupData.FromBytes(bytes, ref i); - } - - public GroupProfileRequestPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - GroupData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += GroupData.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class GroupProfileReplyPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - - public override int Length - { - get - { - return 16; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class GroupDataBlock : PacketBlock - { - public UUID GroupID; - public byte[] Name; - public byte[] Charter; - public bool ShowInList; - public byte[] MemberTitle; - public ulong PowersMask; - public UUID InsigniaID; - public UUID FounderID; - public int MembershipFee; - public bool OpenEnrollment; - public int Money; - public int GroupMembershipCount; - public int GroupRolesCount; - public bool AllowPublish; - public bool MaturePublish; - public UUID OwnerRole; - - public override int Length - { - get - { - int length = 96; - if (Name != null) { length += Name.Length; } - if (Charter != null) { length += Charter.Length; } - if (MemberTitle != null) { length += MemberTitle.Length; } - return length; - } - } - - public GroupDataBlock() { } - public GroupDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - GroupID.FromBytes(bytes, i); i += 16; - length = bytes[i++]; - Name = new byte[length]; - Buffer.BlockCopy(bytes, i, Name, 0, length); i += length; - length = (bytes[i++] + (bytes[i++] << 8)); - Charter = new byte[length]; - Buffer.BlockCopy(bytes, i, Charter, 0, length); i += length; - ShowInList = (bytes[i++] != 0) ? (bool)true : (bool)false; - length = bytes[i++]; - MemberTitle = new byte[length]; - Buffer.BlockCopy(bytes, i, MemberTitle, 0, length); i += length; - 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)); - InsigniaID.FromBytes(bytes, i); i += 16; - FounderID.FromBytes(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; - Money = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - GroupMembershipCount = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - GroupRolesCount = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - AllowPublish = (bytes[i++] != 0) ? (bool)true : (bool)false; - MaturePublish = (bytes[i++] != 0) ? (bool)true : (bool)false; - OwnerRole.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - GroupID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)Name.Length; - Buffer.BlockCopy(Name, 0, bytes, i, Name.Length); i += Name.Length; - bytes[i++] = (byte)(Charter.Length % 256); - bytes[i++] = (byte)((Charter.Length >> 8) % 256); - Buffer.BlockCopy(Charter, 0, bytes, i, Charter.Length); i += Charter.Length; - bytes[i++] = (byte)((ShowInList) ? 1 : 0); - bytes[i++] = (byte)MemberTitle.Length; - Buffer.BlockCopy(MemberTitle, 0, bytes, i, MemberTitle.Length); i += MemberTitle.Length; - Utils.UInt64ToBytes(PowersMask, bytes, i); i += 8; - InsigniaID.ToBytes(bytes, i); i += 16; - FounderID.ToBytes(bytes, i); i += 16; - Utils.IntToBytes(MembershipFee, bytes, i); i += 4; - bytes[i++] = (byte)((OpenEnrollment) ? 1 : 0); - Utils.IntToBytes(Money, bytes, i); i += 4; - Utils.IntToBytes(GroupMembershipCount, bytes, i); i += 4; - Utils.IntToBytes(GroupRolesCount, bytes, i); i += 4; - bytes[i++] = (byte)((AllowPublish) ? 1 : 0); - bytes[i++] = (byte)((MaturePublish) ? 1 : 0); - OwnerRole.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += GroupData.Length; - return length; - } - } - public AgentDataBlock AgentData; - public GroupDataBlock GroupData; - - public GroupProfileReplyPacket() - { - HasVariableBlocks = false; - Type = PacketType.GroupProfileReply; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 352; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - GroupData = new GroupDataBlock(); - } - - public GroupProfileReplyPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - GroupData.FromBytes(bytes, ref i); - } - - public GroupProfileReplyPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - GroupData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += GroupData.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class GroupAccountSummaryRequestPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - public UUID GroupID; - - public override int Length - { - get - { - return 48; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - GroupID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - GroupID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class MoneyDataBlock : PacketBlock - { - public UUID RequestID; - public int IntervalDays; - public int CurrentInterval; - - public override int Length - { - get - { - return 24; - } - } - - public MoneyDataBlock() { } - public MoneyDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - RequestID.FromBytes(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(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - RequestID.ToBytes(bytes, i); i += 16; - Utils.IntToBytes(IntervalDays, bytes, i); i += 4; - Utils.IntToBytes(CurrentInterval, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += MoneyData.Length; - return length; - } - } - public AgentDataBlock AgentData; - public MoneyDataBlock MoneyData; - - public GroupAccountSummaryRequestPacket() - { - HasVariableBlocks = false; - Type = PacketType.GroupAccountSummaryRequest; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 353; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - MoneyData = new MoneyDataBlock(); - } - - public GroupAccountSummaryRequestPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - MoneyData.FromBytes(bytes, ref i); - } - - public GroupAccountSummaryRequestPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - MoneyData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += MoneyData.Length; - if (Header.AckList != null && 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); - MoneyData.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class GroupAccountSummaryReplyPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID GroupID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - GroupID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - GroupID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class MoneyDataBlock : PacketBlock - { - public UUID RequestID; - public int IntervalDays; - public int CurrentInterval; - public byte[] StartDate; - public int Balance; - public int TotalCredits; - public int TotalDebits; - public int ObjectTaxCurrent; - public int LightTaxCurrent; - public int LandTaxCurrent; - public int GroupTaxCurrent; - public int ParcelDirFeeCurrent; - public int ObjectTaxEstimate; - public int LightTaxEstimate; - public int LandTaxEstimate; - public int GroupTaxEstimate; - public int ParcelDirFeeEstimate; - public int NonExemptMembers; - public byte[] LastTaxDate; - public byte[] TaxDate; - - public override int Length - { - get - { - int length = 83; - if (StartDate != null) { length += StartDate.Length; } - if (LastTaxDate != null) { length += LastTaxDate.Length; } - if (TaxDate != null) { length += TaxDate.Length; } - return length; - } - } - - public MoneyDataBlock() { } - public MoneyDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - RequestID.FromBytes(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)); - length = bytes[i++]; - StartDate = new byte[length]; - Buffer.BlockCopy(bytes, i, StartDate, 0, length); i += length; - Balance = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - TotalCredits = (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)); - 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)); - ParcelDirFeeCurrent = (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)); - ParcelDirFeeEstimate = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - NonExemptMembers = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - length = bytes[i++]; - LastTaxDate = new byte[length]; - Buffer.BlockCopy(bytes, i, LastTaxDate, 0, length); i += length; - length = bytes[i++]; - TaxDate = new byte[length]; - Buffer.BlockCopy(bytes, i, TaxDate, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - RequestID.ToBytes(bytes, i); i += 16; - Utils.IntToBytes(IntervalDays, bytes, i); i += 4; - Utils.IntToBytes(CurrentInterval, bytes, i); i += 4; - bytes[i++] = (byte)StartDate.Length; - Buffer.BlockCopy(StartDate, 0, bytes, i, StartDate.Length); i += StartDate.Length; - Utils.IntToBytes(Balance, bytes, i); i += 4; - Utils.IntToBytes(TotalCredits, bytes, i); i += 4; - Utils.IntToBytes(TotalDebits, bytes, i); i += 4; - Utils.IntToBytes(ObjectTaxCurrent, bytes, i); i += 4; - Utils.IntToBytes(LightTaxCurrent, bytes, i); i += 4; - Utils.IntToBytes(LandTaxCurrent, bytes, i); i += 4; - Utils.IntToBytes(GroupTaxCurrent, bytes, i); i += 4; - Utils.IntToBytes(ParcelDirFeeCurrent, bytes, i); i += 4; - Utils.IntToBytes(ObjectTaxEstimate, bytes, i); i += 4; - Utils.IntToBytes(LightTaxEstimate, bytes, i); i += 4; - Utils.IntToBytes(LandTaxEstimate, bytes, i); i += 4; - Utils.IntToBytes(GroupTaxEstimate, bytes, i); i += 4; - Utils.IntToBytes(ParcelDirFeeEstimate, bytes, i); i += 4; - Utils.IntToBytes(NonExemptMembers, bytes, i); i += 4; - bytes[i++] = (byte)LastTaxDate.Length; - Buffer.BlockCopy(LastTaxDate, 0, bytes, i, LastTaxDate.Length); i += LastTaxDate.Length; - bytes[i++] = (byte)TaxDate.Length; - Buffer.BlockCopy(TaxDate, 0, bytes, i, TaxDate.Length); i += TaxDate.Length; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += MoneyData.Length; - return length; - } - } - public AgentDataBlock AgentData; - public MoneyDataBlock MoneyData; - - public GroupAccountSummaryReplyPacket() - { - HasVariableBlocks = false; - Type = PacketType.GroupAccountSummaryReply; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 354; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - MoneyData = new MoneyDataBlock(); - } - - public GroupAccountSummaryReplyPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - MoneyData.FromBytes(bytes, ref i); - } - - public GroupAccountSummaryReplyPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - MoneyData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += MoneyData.Length; - if (Header.AckList != null && 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); - MoneyData.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class GroupAccountDetailsRequestPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - public UUID GroupID; - - public override int Length - { - get - { - return 48; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - GroupID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - GroupID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class MoneyDataBlock : PacketBlock - { - public UUID RequestID; - public int IntervalDays; - public int CurrentInterval; - - public override int Length - { - get - { - return 24; - } - } - - public MoneyDataBlock() { } - public MoneyDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - RequestID.FromBytes(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(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - RequestID.ToBytes(bytes, i); i += 16; - Utils.IntToBytes(IntervalDays, bytes, i); i += 4; - Utils.IntToBytes(CurrentInterval, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += MoneyData.Length; - return length; - } - } - public AgentDataBlock AgentData; - public MoneyDataBlock MoneyData; - - public GroupAccountDetailsRequestPacket() - { - HasVariableBlocks = false; - Type = PacketType.GroupAccountDetailsRequest; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 355; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - MoneyData = new MoneyDataBlock(); - } - - public GroupAccountDetailsRequestPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - MoneyData.FromBytes(bytes, ref i); - } - - public GroupAccountDetailsRequestPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - MoneyData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += MoneyData.Length; - if (Header.AckList != null && 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); - MoneyData.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class GroupAccountDetailsReplyPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID GroupID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - GroupID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - GroupID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class MoneyDataBlock : PacketBlock - { - public UUID RequestID; - public int IntervalDays; - public int CurrentInterval; - public byte[] StartDate; - - public override int Length - { - get - { - int length = 25; - if (StartDate != null) { length += StartDate.Length; } - return length; - } - } - - public MoneyDataBlock() { } - public MoneyDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - RequestID.FromBytes(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)); - length = bytes[i++]; - StartDate = new byte[length]; - Buffer.BlockCopy(bytes, i, StartDate, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - RequestID.ToBytes(bytes, i); i += 16; - Utils.IntToBytes(IntervalDays, bytes, i); i += 4; - Utils.IntToBytes(CurrentInterval, bytes, i); i += 4; - bytes[i++] = (byte)StartDate.Length; - Buffer.BlockCopy(StartDate, 0, bytes, i, StartDate.Length); i += StartDate.Length; - } - - } - - /// - public sealed class HistoryDataBlock : PacketBlock - { - public byte[] Description; - public int Amount; - - public override int Length - { - get - { - int length = 5; - if (Description != null) { length += Description.Length; } - return length; - } - } - - public HistoryDataBlock() { } - public HistoryDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - length = bytes[i++]; - Description = new byte[length]; - Buffer.BlockCopy(bytes, i, Description, 0, length); i += length; - Amount = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - bytes[i++] = (byte)Description.Length; - Buffer.BlockCopy(Description, 0, bytes, i, Description.Length); i += Description.Length; - Utils.IntToBytes(Amount, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentData.Length; - length += MoneyData.Length; - for (int j = 0; j < HistoryData.Length; j++) - length += HistoryData[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public MoneyDataBlock MoneyData; - public HistoryDataBlock[] HistoryData; - - public GroupAccountDetailsReplyPacket() - { - HasVariableBlocks = true; - Type = PacketType.GroupAccountDetailsReply; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 356; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - MoneyData = new MoneyDataBlock(); - HistoryData = null; - } - - public GroupAccountDetailsReplyPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - MoneyData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(HistoryData == null || HistoryData.Length != -1) { - HistoryData = new HistoryDataBlock[count]; - for(int j = 0; j < count; j++) - { HistoryData[j] = new HistoryDataBlock(); } - } - for (int j = 0; j < count; j++) - { HistoryData[j].FromBytes(bytes, ref i); } - } - - public GroupAccountDetailsReplyPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - MoneyData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(HistoryData == null || HistoryData.Length != count) { - HistoryData = new HistoryDataBlock[count]; - for(int j = 0; j < count; j++) - { HistoryData[j] = new HistoryDataBlock(); } - } - for (int j = 0; j < count; j++) - { HistoryData[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += MoneyData.Length; - length++; - for (int j = 0; j < HistoryData.Length; j++) { length += HistoryData[j].Length; } - if (Header.AckList != null && 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); - MoneyData.ToBytes(bytes, ref i); - bytes[i++] = (byte)HistoryData.Length; - for (int j = 0; j < HistoryData.Length; j++) { HistoryData[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - fixedLength += MoneyData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - MoneyData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int HistoryDataStart = 0; - do - { - int variableLength = 0; - int HistoryDataCount = 0; - - i = HistoryDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < HistoryData.Length) { - int blockLength = HistoryData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == HistoryDataStart) { - variableLength += blockLength; - ++HistoryDataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)HistoryDataCount; - for (i = HistoryDataStart; i < HistoryDataStart + HistoryDataCount; i++) { HistoryData[i].ToBytes(packet, ref length); } - HistoryDataStart += HistoryDataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - HistoryDataStart < HistoryData.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class GroupAccountTransactionsRequestPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - public UUID GroupID; - - public override int Length - { - get - { - return 48; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - GroupID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - GroupID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class MoneyDataBlock : PacketBlock - { - public UUID RequestID; - public int IntervalDays; - public int CurrentInterval; - - public override int Length - { - get - { - return 24; - } - } - - public MoneyDataBlock() { } - public MoneyDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - RequestID.FromBytes(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(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - RequestID.ToBytes(bytes, i); i += 16; - Utils.IntToBytes(IntervalDays, bytes, i); i += 4; - Utils.IntToBytes(CurrentInterval, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += MoneyData.Length; - return length; - } - } - public AgentDataBlock AgentData; - public MoneyDataBlock MoneyData; - - public GroupAccountTransactionsRequestPacket() - { - HasVariableBlocks = false; - Type = PacketType.GroupAccountTransactionsRequest; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 357; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - MoneyData = new MoneyDataBlock(); - } - - public GroupAccountTransactionsRequestPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - MoneyData.FromBytes(bytes, ref i); - } - - public GroupAccountTransactionsRequestPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - MoneyData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += MoneyData.Length; - if (Header.AckList != null && 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); - MoneyData.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class GroupAccountTransactionsReplyPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID GroupID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - GroupID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - GroupID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class MoneyDataBlock : PacketBlock - { - public UUID RequestID; - public int IntervalDays; - public int CurrentInterval; - public byte[] StartDate; - - public override int Length - { - get - { - int length = 25; - if (StartDate != null) { length += StartDate.Length; } - return length; - } - } - - public MoneyDataBlock() { } - public MoneyDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - RequestID.FromBytes(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)); - length = bytes[i++]; - StartDate = new byte[length]; - Buffer.BlockCopy(bytes, i, StartDate, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - RequestID.ToBytes(bytes, i); i += 16; - Utils.IntToBytes(IntervalDays, bytes, i); i += 4; - Utils.IntToBytes(CurrentInterval, bytes, i); i += 4; - bytes[i++] = (byte)StartDate.Length; - Buffer.BlockCopy(StartDate, 0, bytes, i, StartDate.Length); i += StartDate.Length; - } - - } - - /// - public sealed class HistoryDataBlock : PacketBlock - { - public byte[] Time; - public byte[] User; - public int Type; - public byte[] Item; - public int Amount; - - public override int Length - { - get - { - int length = 11; - if (Time != null) { length += Time.Length; } - if (User != null) { length += User.Length; } - if (Item != null) { length += Item.Length; } - return length; - } - } - - public HistoryDataBlock() { } - public HistoryDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - length = bytes[i++]; - Time = new byte[length]; - Buffer.BlockCopy(bytes, i, Time, 0, length); i += length; - length = bytes[i++]; - User = new byte[length]; - Buffer.BlockCopy(bytes, i, User, 0, length); i += length; - Type = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - length = bytes[i++]; - Item = new byte[length]; - Buffer.BlockCopy(bytes, i, Item, 0, length); i += length; - Amount = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - bytes[i++] = (byte)Time.Length; - Buffer.BlockCopy(Time, 0, bytes, i, Time.Length); i += Time.Length; - bytes[i++] = (byte)User.Length; - Buffer.BlockCopy(User, 0, bytes, i, User.Length); i += User.Length; - Utils.IntToBytes(Type, bytes, i); i += 4; - bytes[i++] = (byte)Item.Length; - Buffer.BlockCopy(Item, 0, bytes, i, Item.Length); i += Item.Length; - Utils.IntToBytes(Amount, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentData.Length; - length += MoneyData.Length; - for (int j = 0; j < HistoryData.Length; j++) - length += HistoryData[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public MoneyDataBlock MoneyData; - public HistoryDataBlock[] HistoryData; - - public GroupAccountTransactionsReplyPacket() - { - HasVariableBlocks = true; - Type = PacketType.GroupAccountTransactionsReply; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 358; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - MoneyData = new MoneyDataBlock(); - HistoryData = null; - } - - public GroupAccountTransactionsReplyPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - MoneyData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(HistoryData == null || HistoryData.Length != -1) { - HistoryData = new HistoryDataBlock[count]; - for(int j = 0; j < count; j++) - { HistoryData[j] = new HistoryDataBlock(); } - } - for (int j = 0; j < count; j++) - { HistoryData[j].FromBytes(bytes, ref i); } - } - - public GroupAccountTransactionsReplyPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - MoneyData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(HistoryData == null || HistoryData.Length != count) { - HistoryData = new HistoryDataBlock[count]; - for(int j = 0; j < count; j++) - { HistoryData[j] = new HistoryDataBlock(); } - } - for (int j = 0; j < count; j++) - { HistoryData[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += MoneyData.Length; - length++; - for (int j = 0; j < HistoryData.Length; j++) { length += HistoryData[j].Length; } - if (Header.AckList != null && 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); - MoneyData.ToBytes(bytes, ref i); - bytes[i++] = (byte)HistoryData.Length; - for (int j = 0; j < HistoryData.Length; j++) { HistoryData[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - fixedLength += MoneyData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - MoneyData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int HistoryDataStart = 0; - do - { - int variableLength = 0; - int HistoryDataCount = 0; - - i = HistoryDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < HistoryData.Length) { - int blockLength = HistoryData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == HistoryDataStart) { - variableLength += blockLength; - ++HistoryDataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)HistoryDataCount; - for (i = HistoryDataStart; i < HistoryDataStart + HistoryDataCount; i++) { HistoryData[i].ToBytes(packet, ref length); } - HistoryDataStart += HistoryDataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - HistoryDataStart < HistoryData.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class GroupActiveProposalsRequestPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class GroupDataBlock : PacketBlock - { - public UUID GroupID; - - public override int Length - { - get - { - return 16; - } - } - - public GroupDataBlock() { } - public GroupDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - GroupID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - GroupID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class TransactionDataBlock : PacketBlock - { - public UUID TransactionID; - - public override int Length - { - get - { - return 16; - } - } - - public TransactionDataBlock() { } - public TransactionDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - TransactionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - TransactionID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += GroupData.Length; - length += TransactionData.Length; - return length; - } - } - public AgentDataBlock AgentData; - public GroupDataBlock GroupData; - public TransactionDataBlock TransactionData; - - public GroupActiveProposalsRequestPacket() - { - HasVariableBlocks = false; - Type = PacketType.GroupActiveProposalsRequest; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 359; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - GroupData = new GroupDataBlock(); - TransactionData = new TransactionDataBlock(); - } - - public GroupActiveProposalsRequestPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - GroupData.FromBytes(bytes, ref i); - TransactionData.FromBytes(bytes, ref i); - } - - public GroupActiveProposalsRequestPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - GroupData.FromBytes(bytes, ref i); - TransactionData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += GroupData.Length; - length += TransactionData.Length; - if (Header.AckList != null && 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); - TransactionData.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class GroupActiveProposalItemReplyPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID GroupID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - GroupID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - GroupID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class TransactionDataBlock : PacketBlock - { - public UUID TransactionID; - public uint TotalNumItems; - - public override int Length - { - get - { - return 20; - } - } - - public TransactionDataBlock() { } - public TransactionDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - TransactionID.FromBytes(bytes, i); i += 16; - TotalNumItems = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - TransactionID.ToBytes(bytes, i); i += 16; - Utils.UIntToBytes(TotalNumItems, bytes, i); i += 4; - } - - } - - /// - public sealed class ProposalDataBlock : PacketBlock - { - public UUID VoteID; - public UUID VoteInitiator; - public byte[] TerseDateID; - public byte[] StartDateTime; - public byte[] EndDateTime; - public bool AlreadyVoted; - public byte[] VoteCast; - public float Majority; - public int Quorum; - public byte[] ProposalText; - - public override int Length - { - get - { - int length = 46; - if (TerseDateID != null) { length += TerseDateID.Length; } - if (StartDateTime != null) { length += StartDateTime.Length; } - if (EndDateTime != null) { length += EndDateTime.Length; } - if (VoteCast != null) { length += VoteCast.Length; } - if (ProposalText != null) { length += ProposalText.Length; } - return length; - } - } - - public ProposalDataBlock() { } - public ProposalDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - VoteID.FromBytes(bytes, i); i += 16; - VoteInitiator.FromBytes(bytes, i); i += 16; - length = bytes[i++]; - TerseDateID = new byte[length]; - Buffer.BlockCopy(bytes, i, TerseDateID, 0, length); i += length; - length = bytes[i++]; - StartDateTime = new byte[length]; - Buffer.BlockCopy(bytes, i, StartDateTime, 0, length); i += length; - length = bytes[i++]; - EndDateTime = new byte[length]; - Buffer.BlockCopy(bytes, i, EndDateTime, 0, length); i += length; - AlreadyVoted = (bytes[i++] != 0) ? (bool)true : (bool)false; - length = bytes[i++]; - VoteCast = new byte[length]; - Buffer.BlockCopy(bytes, i, VoteCast, 0, length); i += length; - Majority = Utils.BytesToFloat(bytes, i); i += 4; - Quorum = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - length = bytes[i++]; - ProposalText = new byte[length]; - Buffer.BlockCopy(bytes, i, ProposalText, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - VoteID.ToBytes(bytes, i); i += 16; - VoteInitiator.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)TerseDateID.Length; - Buffer.BlockCopy(TerseDateID, 0, bytes, i, TerseDateID.Length); i += TerseDateID.Length; - bytes[i++] = (byte)StartDateTime.Length; - Buffer.BlockCopy(StartDateTime, 0, bytes, i, StartDateTime.Length); i += StartDateTime.Length; - bytes[i++] = (byte)EndDateTime.Length; - Buffer.BlockCopy(EndDateTime, 0, bytes, i, EndDateTime.Length); i += EndDateTime.Length; - bytes[i++] = (byte)((AlreadyVoted) ? 1 : 0); - bytes[i++] = (byte)VoteCast.Length; - Buffer.BlockCopy(VoteCast, 0, bytes, i, VoteCast.Length); i += VoteCast.Length; - Utils.FloatToBytes(Majority, bytes, i); i += 4; - Utils.IntToBytes(Quorum, bytes, i); i += 4; - bytes[i++] = (byte)ProposalText.Length; - Buffer.BlockCopy(ProposalText, 0, bytes, i, ProposalText.Length); i += ProposalText.Length; - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentData.Length; - length += TransactionData.Length; - for (int j = 0; j < ProposalData.Length; j++) - length += ProposalData[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public TransactionDataBlock TransactionData; - public ProposalDataBlock[] ProposalData; - - public GroupActiveProposalItemReplyPacket() - { - HasVariableBlocks = true; - Type = PacketType.GroupActiveProposalItemReply; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 360; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - TransactionData = new TransactionDataBlock(); - ProposalData = null; - } - - public GroupActiveProposalItemReplyPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - TransactionData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ProposalData == null || ProposalData.Length != -1) { - ProposalData = new ProposalDataBlock[count]; - for(int j = 0; j < count; j++) - { ProposalData[j] = new ProposalDataBlock(); } - } - for (int j = 0; j < count; j++) - { ProposalData[j].FromBytes(bytes, ref i); } - } - - public GroupActiveProposalItemReplyPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - TransactionData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ProposalData == null || ProposalData.Length != count) { - ProposalData = new ProposalDataBlock[count]; - for(int j = 0; j < count; j++) - { ProposalData[j] = new ProposalDataBlock(); } - } - for (int j = 0; j < count; j++) - { ProposalData[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += TransactionData.Length; - length++; - for (int j = 0; j < ProposalData.Length; j++) { length += ProposalData[j].Length; } - if (Header.AckList != null && 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); - bytes[i++] = (byte)ProposalData.Length; - for (int j = 0; j < ProposalData.Length; j++) { ProposalData[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - fixedLength += TransactionData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - TransactionData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int ProposalDataStart = 0; - do - { - int variableLength = 0; - int ProposalDataCount = 0; - - i = ProposalDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < ProposalData.Length) { - int blockLength = ProposalData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ProposalDataStart) { - variableLength += blockLength; - ++ProposalDataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)ProposalDataCount; - for (i = ProposalDataStart; i < ProposalDataStart + ProposalDataCount; i++) { ProposalData[i].ToBytes(packet, ref length); } - ProposalDataStart += ProposalDataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - ProposalDataStart < ProposalData.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class GroupVoteHistoryRequestPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class GroupDataBlock : PacketBlock - { - public UUID GroupID; - - public override int Length - { - get - { - return 16; - } - } - - public GroupDataBlock() { } - public GroupDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - GroupID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - GroupID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class TransactionDataBlock : PacketBlock - { - public UUID TransactionID; - - public override int Length - { - get - { - return 16; - } - } - - public TransactionDataBlock() { } - public TransactionDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - TransactionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - TransactionID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += GroupData.Length; - length += TransactionData.Length; - return length; - } - } - public AgentDataBlock AgentData; - public GroupDataBlock GroupData; - public TransactionDataBlock TransactionData; - - public GroupVoteHistoryRequestPacket() - { - HasVariableBlocks = false; - Type = PacketType.GroupVoteHistoryRequest; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 361; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - GroupData = new GroupDataBlock(); - TransactionData = new TransactionDataBlock(); - } - - public GroupVoteHistoryRequestPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - GroupData.FromBytes(bytes, ref i); - TransactionData.FromBytes(bytes, ref i); - } - - public GroupVoteHistoryRequestPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - GroupData.FromBytes(bytes, ref i); - TransactionData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += GroupData.Length; - length += TransactionData.Length; - if (Header.AckList != null && 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); - TransactionData.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class GroupVoteHistoryItemReplyPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID GroupID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - GroupID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - GroupID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class TransactionDataBlock : PacketBlock - { - public UUID TransactionID; - public uint TotalNumItems; - - public override int Length - { - get - { - return 20; - } - } - - public TransactionDataBlock() { } - public TransactionDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - TransactionID.FromBytes(bytes, i); i += 16; - TotalNumItems = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - TransactionID.ToBytes(bytes, i); i += 16; - Utils.UIntToBytes(TotalNumItems, bytes, i); i += 4; - } - - } - - /// - public sealed class HistoryItemDataBlock : PacketBlock - { - public UUID VoteID; - public byte[] TerseDateID; - public byte[] StartDateTime; - public byte[] EndDateTime; - public UUID VoteInitiator; - public byte[] VoteType; - public byte[] VoteResult; - public float Majority; - public int Quorum; - public byte[] ProposalText; - - public override int Length - { - get - { - int length = 47; - if (TerseDateID != null) { length += TerseDateID.Length; } - if (StartDateTime != null) { length += StartDateTime.Length; } - if (EndDateTime != null) { length += EndDateTime.Length; } - if (VoteType != null) { length += VoteType.Length; } - if (VoteResult != null) { length += VoteResult.Length; } - if (ProposalText != null) { length += ProposalText.Length; } - return length; - } - } - - public HistoryItemDataBlock() { } - public HistoryItemDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - VoteID.FromBytes(bytes, i); i += 16; - length = bytes[i++]; - TerseDateID = new byte[length]; - Buffer.BlockCopy(bytes, i, TerseDateID, 0, length); i += length; - length = bytes[i++]; - StartDateTime = new byte[length]; - Buffer.BlockCopy(bytes, i, StartDateTime, 0, length); i += length; - length = bytes[i++]; - EndDateTime = new byte[length]; - Buffer.BlockCopy(bytes, i, EndDateTime, 0, length); i += length; - VoteInitiator.FromBytes(bytes, i); i += 16; - length = bytes[i++]; - VoteType = new byte[length]; - Buffer.BlockCopy(bytes, i, VoteType, 0, length); i += length; - length = bytes[i++]; - VoteResult = new byte[length]; - Buffer.BlockCopy(bytes, i, VoteResult, 0, length); i += length; - Majority = Utils.BytesToFloat(bytes, i); i += 4; - Quorum = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - length = (bytes[i++] + (bytes[i++] << 8)); - ProposalText = new byte[length]; - Buffer.BlockCopy(bytes, i, ProposalText, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - VoteID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)TerseDateID.Length; - Buffer.BlockCopy(TerseDateID, 0, bytes, i, TerseDateID.Length); i += TerseDateID.Length; - bytes[i++] = (byte)StartDateTime.Length; - Buffer.BlockCopy(StartDateTime, 0, bytes, i, StartDateTime.Length); i += StartDateTime.Length; - bytes[i++] = (byte)EndDateTime.Length; - Buffer.BlockCopy(EndDateTime, 0, bytes, i, EndDateTime.Length); i += EndDateTime.Length; - VoteInitiator.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)VoteType.Length; - Buffer.BlockCopy(VoteType, 0, bytes, i, VoteType.Length); i += VoteType.Length; - bytes[i++] = (byte)VoteResult.Length; - Buffer.BlockCopy(VoteResult, 0, bytes, i, VoteResult.Length); i += VoteResult.Length; - Utils.FloatToBytes(Majority, bytes, i); i += 4; - Utils.IntToBytes(Quorum, bytes, i); i += 4; - bytes[i++] = (byte)(ProposalText.Length % 256); - bytes[i++] = (byte)((ProposalText.Length >> 8) % 256); - Buffer.BlockCopy(ProposalText, 0, bytes, i, ProposalText.Length); i += ProposalText.Length; - } - - } - - /// - public sealed class VoteItemBlock : PacketBlock - { - public UUID CandidateID; - public byte[] VoteCast; - public int NumVotes; - - public override int Length - { - get - { - int length = 21; - if (VoteCast != null) { length += VoteCast.Length; } - return length; - } - } - - public VoteItemBlock() { } - public VoteItemBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - CandidateID.FromBytes(bytes, i); i += 16; - length = bytes[i++]; - VoteCast = new byte[length]; - Buffer.BlockCopy(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(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - CandidateID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)VoteCast.Length; - Buffer.BlockCopy(VoteCast, 0, bytes, i, VoteCast.Length); i += VoteCast.Length; - Utils.IntToBytes(NumVotes, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentData.Length; - length += TransactionData.Length; - length += HistoryItemData.Length; - for (int j = 0; j < VoteItem.Length; j++) - length += VoteItem[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public TransactionDataBlock TransactionData; - public HistoryItemDataBlock HistoryItemData; - public VoteItemBlock[] VoteItem; - - public GroupVoteHistoryItemReplyPacket() - { - HasVariableBlocks = true; - Type = PacketType.GroupVoteHistoryItemReply; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 362; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - TransactionData = new TransactionDataBlock(); - HistoryItemData = new HistoryItemDataBlock(); - VoteItem = null; - } - - public GroupVoteHistoryItemReplyPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - TransactionData.FromBytes(bytes, ref i); - HistoryItemData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(VoteItem == null || VoteItem.Length != -1) { - VoteItem = new VoteItemBlock[count]; - for(int j = 0; j < count; j++) - { VoteItem[j] = new VoteItemBlock(); } - } - for (int j = 0; j < count; j++) - { VoteItem[j].FromBytes(bytes, ref i); } - } - - public GroupVoteHistoryItemReplyPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - TransactionData.FromBytes(bytes, ref i); - HistoryItemData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(VoteItem == null || VoteItem.Length != count) { - VoteItem = new VoteItemBlock[count]; - for(int j = 0; j < count; j++) - { VoteItem[j] = new VoteItemBlock(); } - } - for (int j = 0; j < count; j++) - { VoteItem[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += TransactionData.Length; - length += HistoryItemData.Length; - length++; - for (int j = 0; j < VoteItem.Length; j++) { length += VoteItem[j].Length; } - if (Header.AckList != null && 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); - HistoryItemData.ToBytes(bytes, ref i); - bytes[i++] = (byte)VoteItem.Length; - for (int j = 0; j < VoteItem.Length; j++) { VoteItem[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - fixedLength += TransactionData.Length; - fixedLength += HistoryItemData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - TransactionData.ToBytes(fixedBytes, ref i); - HistoryItemData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int VoteItemStart = 0; - do - { - int variableLength = 0; - int VoteItemCount = 0; - - i = VoteItemStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < VoteItem.Length) { - int blockLength = VoteItem[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == VoteItemStart) { - variableLength += blockLength; - ++VoteItemCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)VoteItemCount; - for (i = VoteItemStart; i < VoteItemStart + VoteItemCount; i++) { VoteItem[i].ToBytes(packet, ref length); } - VoteItemStart += VoteItemCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - VoteItemStart < VoteItem.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class StartGroupProposalPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class ProposalDataBlock : PacketBlock - { - public UUID GroupID; - public int Quorum; - public float Majority; - public int Duration; - public byte[] ProposalText; - - public override int Length - { - get - { - int length = 29; - if (ProposalText != null) { length += ProposalText.Length; } - return length; - } - } - - public ProposalDataBlock() { } - public ProposalDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - GroupID.FromBytes(bytes, i); i += 16; - Quorum = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - Majority = Utils.BytesToFloat(bytes, i); i += 4; - Duration = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - length = bytes[i++]; - ProposalText = new byte[length]; - Buffer.BlockCopy(bytes, i, ProposalText, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - GroupID.ToBytes(bytes, i); i += 16; - Utils.IntToBytes(Quorum, bytes, i); i += 4; - Utils.FloatToBytes(Majority, bytes, i); i += 4; - Utils.IntToBytes(Duration, bytes, i); i += 4; - bytes[i++] = (byte)ProposalText.Length; - Buffer.BlockCopy(ProposalText, 0, bytes, i, ProposalText.Length); i += ProposalText.Length; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += ProposalData.Length; - return length; - } - } - public AgentDataBlock AgentData; - public ProposalDataBlock ProposalData; - - public StartGroupProposalPacket() - { - HasVariableBlocks = false; - Type = PacketType.StartGroupProposal; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 363; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - ProposalData = new ProposalDataBlock(); - } - - public StartGroupProposalPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - ProposalData.FromBytes(bytes, ref i); - } - - public StartGroupProposalPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - ProposalData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += ProposalData.Length; - if (Header.AckList != null && 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); - ProposalData.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class GroupProposalBallotPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class ProposalDataBlock : PacketBlock - { - public UUID ProposalID; - public UUID GroupID; - public byte[] VoteCast; - - public override int Length - { - get - { - int length = 33; - if (VoteCast != null) { length += VoteCast.Length; } - return length; - } - } - - public ProposalDataBlock() { } - public ProposalDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - ProposalID.FromBytes(bytes, i); i += 16; - GroupID.FromBytes(bytes, i); i += 16; - length = bytes[i++]; - VoteCast = new byte[length]; - Buffer.BlockCopy(bytes, i, VoteCast, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - ProposalID.ToBytes(bytes, i); i += 16; - GroupID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)VoteCast.Length; - Buffer.BlockCopy(VoteCast, 0, bytes, i, VoteCast.Length); i += VoteCast.Length; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += ProposalData.Length; - return length; - } - } - public AgentDataBlock AgentData; - public ProposalDataBlock ProposalData; - - public GroupProposalBallotPacket() - { - HasVariableBlocks = false; - Type = PacketType.GroupProposalBallot; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 364; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - ProposalData = new ProposalDataBlock(); - } - - public GroupProposalBallotPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - ProposalData.FromBytes(bytes, ref i); - } - - public GroupProposalBallotPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - ProposalData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += ProposalData.Length; - if (Header.AckList != null && 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); - ProposalData.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class GroupMembersRequestPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class GroupDataBlock : PacketBlock - { - public UUID GroupID; - public UUID RequestID; - - public override int Length - { - get - { - return 32; - } - } - - public GroupDataBlock() { } - public GroupDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - GroupID.FromBytes(bytes, i); i += 16; - RequestID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - GroupID.ToBytes(bytes, i); i += 16; - RequestID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += GroupData.Length; - return length; - } - } - public AgentDataBlock AgentData; - public GroupDataBlock GroupData; - - public GroupMembersRequestPacket() - { - HasVariableBlocks = false; - Type = PacketType.GroupMembersRequest; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 366; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - GroupData = new GroupDataBlock(); - } - - public GroupMembersRequestPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - GroupData.FromBytes(bytes, ref i); - } - - public GroupMembersRequestPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - GroupData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += GroupData.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class GroupMembersReplyPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - - public override int Length - { - get - { - return 16; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class GroupDataBlock : PacketBlock - { - public UUID GroupID; - public UUID RequestID; - public int MemberCount; - - public override int Length - { - get - { - return 36; - } - } - - public GroupDataBlock() { } - public GroupDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - GroupID.FromBytes(bytes, i); i += 16; - RequestID.FromBytes(bytes, i); i += 16; - MemberCount = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - GroupID.ToBytes(bytes, i); i += 16; - RequestID.ToBytes(bytes, i); i += 16; - Utils.IntToBytes(MemberCount, bytes, i); i += 4; - } - - } - - /// - public sealed class MemberDataBlock : PacketBlock - { - public UUID AgentID; - public int Contribution; - public byte[] OnlineStatus; - public ulong AgentPowers; - public byte[] Title; - public bool IsOwner; - - public override int Length - { - get - { - int length = 31; - if (OnlineStatus != null) { length += OnlineStatus.Length; } - if (Title != null) { length += Title.Length; } - return length; - } - } - - public MemberDataBlock() { } - public MemberDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - AgentID.FromBytes(bytes, i); i += 16; - Contribution = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - length = bytes[i++]; - OnlineStatus = new byte[length]; - Buffer.BlockCopy(bytes, i, OnlineStatus, 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)); - length = bytes[i++]; - Title = new byte[length]; - Buffer.BlockCopy(bytes, i, Title, 0, length); i += length; - IsOwner = (bytes[i++] != 0) ? (bool)true : (bool)false; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - Utils.IntToBytes(Contribution, bytes, i); i += 4; - bytes[i++] = (byte)OnlineStatus.Length; - Buffer.BlockCopy(OnlineStatus, 0, bytes, i, OnlineStatus.Length); i += OnlineStatus.Length; - Utils.UInt64ToBytes(AgentPowers, bytes, i); i += 8; - bytes[i++] = (byte)Title.Length; - Buffer.BlockCopy(Title, 0, bytes, i, Title.Length); i += Title.Length; - bytes[i++] = (byte)((IsOwner) ? 1 : 0); - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentData.Length; - length += GroupData.Length; - for (int j = 0; j < MemberData.Length; j++) - length += MemberData[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public GroupDataBlock GroupData; - public MemberDataBlock[] MemberData; - - public GroupMembersReplyPacket() - { - HasVariableBlocks = true; - Type = PacketType.GroupMembersReply; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 367; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - GroupData = new GroupDataBlock(); - MemberData = null; - } - - public GroupMembersReplyPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - GroupData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(MemberData == null || MemberData.Length != -1) { - MemberData = new MemberDataBlock[count]; - for(int j = 0; j < count; j++) - { MemberData[j] = new MemberDataBlock(); } - } - for (int j = 0; j < count; j++) - { MemberData[j].FromBytes(bytes, ref i); } - } - - public GroupMembersReplyPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - GroupData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(MemberData == null || MemberData.Length != count) { - MemberData = new MemberDataBlock[count]; - for(int j = 0; j < count; j++) - { MemberData[j] = new MemberDataBlock(); } - } - for (int j = 0; j < count; j++) - { MemberData[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += GroupData.Length; - length++; - for (int j = 0; j < MemberData.Length; j++) { length += MemberData[j].Length; } - if (Header.AckList != null && 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); - bytes[i++] = (byte)MemberData.Length; - for (int j = 0; j < MemberData.Length; j++) { MemberData[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - fixedLength += GroupData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - GroupData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int MemberDataStart = 0; - do - { - int variableLength = 0; - int MemberDataCount = 0; - - i = MemberDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < MemberData.Length) { - int blockLength = MemberData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == MemberDataStart) { - variableLength += blockLength; - ++MemberDataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)MemberDataCount; - for (i = MemberDataStart; i < MemberDataStart + MemberDataCount; i++) { MemberData[i].ToBytes(packet, ref length); } - MemberDataStart += MemberDataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - MemberDataStart < MemberData.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class ActivateGroupPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - public UUID GroupID; - - public override int Length - { - get - { - return 48; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - GroupID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - GroupID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - return length; - } - } - public AgentDataBlock AgentData; - - public ActivateGroupPacket() - { - HasVariableBlocks = false; - Type = PacketType.ActivateGroup; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 368; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - } - - public ActivateGroupPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - } - - public ActivateGroupPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class SetGroupContributionPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class DataBlock : PacketBlock - { - public UUID GroupID; - public int Contribution; - - public override int Length - { - get - { - return 20; - } - } - - public DataBlock() { } - public DataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - GroupID.FromBytes(bytes, i); i += 16; - Contribution = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - GroupID.ToBytes(bytes, i); i += 16; - Utils.IntToBytes(Contribution, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += Data.Length; - return length; - } - } - public AgentDataBlock AgentData; - public DataBlock Data; - - public SetGroupContributionPacket() - { - HasVariableBlocks = false; - Type = PacketType.SetGroupContribution; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 369; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - Data = new DataBlock(); - } - - public SetGroupContributionPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - Data.FromBytes(bytes, ref i); - } - - public SetGroupContributionPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - Data.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += Data.Length; - if (Header.AckList != null && 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); - Data.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class SetGroupAcceptNoticesPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class DataBlock : PacketBlock - { - public UUID GroupID; - public bool AcceptNotices; - - public override int Length - { - get - { - return 17; - } - } - - public DataBlock() { } - public DataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - GroupID.FromBytes(bytes, i); i += 16; - AcceptNotices = (bytes[i++] != 0) ? (bool)true : (bool)false; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - GroupID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)((AcceptNotices) ? 1 : 0); - } - - } - - /// - public sealed class NewDataBlock : PacketBlock - { - public bool ListInProfile; - - public override int Length - { - get - { - return 1; - } - } - - public NewDataBlock() { } - public NewDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - ListInProfile = (bytes[i++] != 0) ? (bool)true : (bool)false; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - bytes[i++] = (byte)((ListInProfile) ? 1 : 0); - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += Data.Length; - length += NewData.Length; - return length; - } - } - public AgentDataBlock AgentData; - public DataBlock Data; - public NewDataBlock NewData; - - public SetGroupAcceptNoticesPacket() - { - HasVariableBlocks = false; - Type = PacketType.SetGroupAcceptNotices; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 370; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - Data = new DataBlock(); - NewData = new NewDataBlock(); - } - - public SetGroupAcceptNoticesPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - Data.FromBytes(bytes, ref i); - NewData.FromBytes(bytes, ref i); - } - - public SetGroupAcceptNoticesPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - Data.FromBytes(bytes, ref i); - NewData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += Data.Length; - length += NewData.Length; - if (Header.AckList != null && 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); - Data.ToBytes(bytes, ref i); - NewData.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class GroupRoleDataRequestPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class GroupDataBlock : PacketBlock - { - public UUID GroupID; - public UUID RequestID; - - public override int Length - { - get - { - return 32; - } - } - - public GroupDataBlock() { } - public GroupDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - GroupID.FromBytes(bytes, i); i += 16; - RequestID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - GroupID.ToBytes(bytes, i); i += 16; - RequestID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += GroupData.Length; - return length; - } - } - public AgentDataBlock AgentData; - public GroupDataBlock GroupData; - - public GroupRoleDataRequestPacket() - { - HasVariableBlocks = false; - Type = PacketType.GroupRoleDataRequest; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 371; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - GroupData = new GroupDataBlock(); - } - - public GroupRoleDataRequestPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - GroupData.FromBytes(bytes, ref i); - } - - public GroupRoleDataRequestPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - GroupData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += GroupData.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class GroupRoleDataReplyPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - - public override int Length - { - get - { - return 16; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class GroupDataBlock : PacketBlock - { - public UUID GroupID; - public UUID RequestID; - public int RoleCount; - - public override int Length - { - get - { - return 36; - } - } - - public GroupDataBlock() { } - public GroupDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - GroupID.FromBytes(bytes, i); i += 16; - RequestID.FromBytes(bytes, i); i += 16; - RoleCount = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - GroupID.ToBytes(bytes, i); i += 16; - RequestID.ToBytes(bytes, i); i += 16; - Utils.IntToBytes(RoleCount, bytes, i); i += 4; - } - - } - - /// - public sealed class RoleDataBlock : PacketBlock - { - public UUID RoleID; - public byte[] Name; - public byte[] Title; - public byte[] Description; - public ulong Powers; - public uint Members; - - public override int Length - { - get - { - int length = 31; - if (Name != null) { length += Name.Length; } - if (Title != null) { length += Title.Length; } - if (Description != null) { length += Description.Length; } - return length; - } - } - - public RoleDataBlock() { } - public RoleDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - RoleID.FromBytes(bytes, i); i += 16; - length = bytes[i++]; - Name = new byte[length]; - Buffer.BlockCopy(bytes, i, Name, 0, length); i += length; - length = bytes[i++]; - Title = new byte[length]; - Buffer.BlockCopy(bytes, i, Title, 0, length); i += length; - length = bytes[i++]; - Description = new byte[length]; - Buffer.BlockCopy(bytes, i, Description, 0, length); i += length; - 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)); - Members = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - RoleID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)Name.Length; - Buffer.BlockCopy(Name, 0, bytes, i, Name.Length); i += Name.Length; - bytes[i++] = (byte)Title.Length; - Buffer.BlockCopy(Title, 0, bytes, i, Title.Length); i += Title.Length; - bytes[i++] = (byte)Description.Length; - Buffer.BlockCopy(Description, 0, bytes, i, Description.Length); i += Description.Length; - Utils.UInt64ToBytes(Powers, bytes, i); i += 8; - Utils.UIntToBytes(Members, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentData.Length; - length += GroupData.Length; - for (int j = 0; j < RoleData.Length; j++) - length += RoleData[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public GroupDataBlock GroupData; - public RoleDataBlock[] RoleData; - - public GroupRoleDataReplyPacket() - { - HasVariableBlocks = true; - Type = PacketType.GroupRoleDataReply; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 372; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - GroupData = new GroupDataBlock(); - RoleData = null; - } - - public GroupRoleDataReplyPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - GroupData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(RoleData == null || RoleData.Length != -1) { - RoleData = new RoleDataBlock[count]; - for(int j = 0; j < count; j++) - { RoleData[j] = new RoleDataBlock(); } - } - for (int j = 0; j < count; j++) - { RoleData[j].FromBytes(bytes, ref i); } - } - - public GroupRoleDataReplyPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - GroupData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(RoleData == null || RoleData.Length != count) { - RoleData = new RoleDataBlock[count]; - for(int j = 0; j < count; j++) - { RoleData[j] = new RoleDataBlock(); } - } - for (int j = 0; j < count; j++) - { RoleData[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += GroupData.Length; - length++; - for (int j = 0; j < RoleData.Length; j++) { length += RoleData[j].Length; } - if (Header.AckList != null && 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); - bytes[i++] = (byte)RoleData.Length; - for (int j = 0; j < RoleData.Length; j++) { RoleData[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - fixedLength += GroupData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - GroupData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int RoleDataStart = 0; - do - { - int variableLength = 0; - int RoleDataCount = 0; - - i = RoleDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < RoleData.Length) { - int blockLength = RoleData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == RoleDataStart) { - variableLength += blockLength; - ++RoleDataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)RoleDataCount; - for (i = RoleDataStart; i < RoleDataStart + RoleDataCount; i++) { RoleData[i].ToBytes(packet, ref length); } - RoleDataStart += RoleDataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - RoleDataStart < RoleData.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class GroupRoleMembersRequestPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class GroupDataBlock : PacketBlock - { - public UUID GroupID; - public UUID RequestID; - - public override int Length - { - get - { - return 32; - } - } - - public GroupDataBlock() { } - public GroupDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - GroupID.FromBytes(bytes, i); i += 16; - RequestID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - GroupID.ToBytes(bytes, i); i += 16; - RequestID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += GroupData.Length; - return length; - } - } - public AgentDataBlock AgentData; - public GroupDataBlock GroupData; - - public GroupRoleMembersRequestPacket() - { - HasVariableBlocks = false; - Type = PacketType.GroupRoleMembersRequest; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 373; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - GroupData = new GroupDataBlock(); - } - - public GroupRoleMembersRequestPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - GroupData.FromBytes(bytes, ref i); - } - - public GroupRoleMembersRequestPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - GroupData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += GroupData.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class GroupRoleMembersReplyPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID GroupID; - public UUID RequestID; - public uint TotalPairs; - - public override int Length - { - get - { - return 52; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - GroupID.FromBytes(bytes, i); i += 16; - RequestID.FromBytes(bytes, i); i += 16; - TotalPairs = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - GroupID.ToBytes(bytes, i); i += 16; - RequestID.ToBytes(bytes, i); i += 16; - Utils.UIntToBytes(TotalPairs, bytes, i); i += 4; - } - - } - - /// - public sealed class MemberDataBlock : PacketBlock - { - public UUID RoleID; - public UUID MemberID; - - public override int Length - { - get - { - return 32; - } - } - - public MemberDataBlock() { } - public MemberDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - RoleID.FromBytes(bytes, i); i += 16; - MemberID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - RoleID.ToBytes(bytes, i); i += 16; - MemberID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentData.Length; - for (int j = 0; j < MemberData.Length; j++) - length += MemberData[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public MemberDataBlock[] MemberData; - - public GroupRoleMembersReplyPacket() - { - HasVariableBlocks = true; - Type = PacketType.GroupRoleMembersReply; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 374; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - MemberData = null; - } - - public GroupRoleMembersReplyPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(MemberData == null || MemberData.Length != -1) { - MemberData = new MemberDataBlock[count]; - for(int j = 0; j < count; j++) - { MemberData[j] = new MemberDataBlock(); } - } - for (int j = 0; j < count; j++) - { MemberData[j].FromBytes(bytes, ref i); } - } - - public GroupRoleMembersReplyPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(MemberData == null || MemberData.Length != count) { - MemberData = new MemberDataBlock[count]; - for(int j = 0; j < count; j++) - { MemberData[j] = new MemberDataBlock(); } - } - for (int j = 0; j < count; j++) - { MemberData[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length++; - for (int j = 0; j < MemberData.Length; j++) { length += MemberData[j].Length; } - if (Header.AckList != null && 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)MemberData.Length; - for (int j = 0; j < MemberData.Length; j++) { MemberData[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int MemberDataStart = 0; - do - { - int variableLength = 0; - int MemberDataCount = 0; - - i = MemberDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < MemberData.Length) { - int blockLength = MemberData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == MemberDataStart) { - variableLength += blockLength; - ++MemberDataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)MemberDataCount; - for (i = MemberDataStart; i < MemberDataStart + MemberDataCount; i++) { MemberData[i].ToBytes(packet, ref length); } - MemberDataStart += MemberDataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - MemberDataStart < MemberData.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class GroupTitlesRequestPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - public UUID GroupID; - public UUID RequestID; - - public override int Length - { - get - { - return 64; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - GroupID.FromBytes(bytes, i); i += 16; - RequestID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - GroupID.ToBytes(bytes, i); i += 16; - RequestID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - return length; - } - } - public AgentDataBlock AgentData; - - public GroupTitlesRequestPacket() - { - HasVariableBlocks = false; - Type = PacketType.GroupTitlesRequest; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 375; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - } - - public GroupTitlesRequestPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - } - - public GroupTitlesRequestPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class GroupTitlesReplyPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID GroupID; - public UUID RequestID; - - public override int Length - { - get - { - return 48; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - GroupID.FromBytes(bytes, i); i += 16; - RequestID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - GroupID.ToBytes(bytes, i); i += 16; - RequestID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class GroupDataBlock : PacketBlock - { - public byte[] Title; - public UUID RoleID; - public bool Selected; - - public override int Length - { - get - { - int length = 18; - if (Title != null) { length += Title.Length; } - return length; - } - } - - public GroupDataBlock() { } - public GroupDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - length = bytes[i++]; - Title = new byte[length]; - Buffer.BlockCopy(bytes, i, Title, 0, length); i += length; - RoleID.FromBytes(bytes, i); i += 16; - Selected = (bytes[i++] != 0) ? (bool)true : (bool)false; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - bytes[i++] = (byte)Title.Length; - Buffer.BlockCopy(Title, 0, bytes, i, Title.Length); i += Title.Length; - RoleID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)((Selected) ? 1 : 0); - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentData.Length; - for (int j = 0; j < GroupData.Length; j++) - length += GroupData[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public GroupDataBlock[] GroupData; - - public GroupTitlesReplyPacket() - { - HasVariableBlocks = true; - Type = PacketType.GroupTitlesReply; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 376; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - GroupData = null; - } - - public GroupTitlesReplyPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(GroupData == null || GroupData.Length != -1) { - GroupData = new GroupDataBlock[count]; - for(int j = 0; j < count; j++) - { GroupData[j] = new GroupDataBlock(); } - } - for (int j = 0; j < count; j++) - { GroupData[j].FromBytes(bytes, ref i); } - } - - public GroupTitlesReplyPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(GroupData == null || GroupData.Length != count) { - GroupData = new GroupDataBlock[count]; - for(int j = 0; j < count; j++) - { GroupData[j] = new GroupDataBlock(); } - } - for (int j = 0; j < count; j++) - { GroupData[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length++; - for (int j = 0; j < GroupData.Length; j++) { length += GroupData[j].Length; } - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int GroupDataStart = 0; - do - { - int variableLength = 0; - int GroupDataCount = 0; - - i = GroupDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < GroupData.Length) { - int blockLength = GroupData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == GroupDataStart) { - variableLength += blockLength; - ++GroupDataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)GroupDataCount; - for (i = GroupDataStart; i < GroupDataStart + GroupDataCount; i++) { GroupData[i].ToBytes(packet, ref length); } - GroupDataStart += GroupDataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - GroupDataStart < GroupData.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class GroupTitleUpdatePacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - public UUID GroupID; - public UUID TitleRoleID; - - public override int Length - { - get - { - return 64; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - GroupID.FromBytes(bytes, i); i += 16; - TitleRoleID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - GroupID.ToBytes(bytes, i); i += 16; - TitleRoleID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - return length; - } - } - public AgentDataBlock AgentData; - - public GroupTitleUpdatePacket() - { - HasVariableBlocks = false; - Type = PacketType.GroupTitleUpdate; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 377; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - } - - public GroupTitleUpdatePacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - } - - public GroupTitleUpdatePacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class GroupRoleUpdatePacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - public UUID GroupID; - - public override int Length - { - get - { - return 48; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - GroupID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - GroupID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class RoleDataBlock : PacketBlock - { - public UUID RoleID; - public byte[] Name; - public byte[] Description; - public byte[] Title; - public ulong Powers; - public byte UpdateType; - - public override int Length - { - get - { - int length = 28; - if (Name != null) { length += Name.Length; } - if (Description != null) { length += Description.Length; } - if (Title != null) { length += Title.Length; } - return length; - } - } - - public RoleDataBlock() { } - public RoleDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - RoleID.FromBytes(bytes, i); i += 16; - length = bytes[i++]; - Name = new byte[length]; - Buffer.BlockCopy(bytes, i, Name, 0, length); i += length; - length = bytes[i++]; - Description = new byte[length]; - Buffer.BlockCopy(bytes, i, Description, 0, length); i += length; - length = bytes[i++]; - Title = new byte[length]; - Buffer.BlockCopy(bytes, i, Title, 0, length); i += length; - 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)); - UpdateType = (byte)bytes[i++]; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - RoleID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)Name.Length; - Buffer.BlockCopy(Name, 0, bytes, i, Name.Length); i += Name.Length; - bytes[i++] = (byte)Description.Length; - Buffer.BlockCopy(Description, 0, bytes, i, Description.Length); i += Description.Length; - bytes[i++] = (byte)Title.Length; - Buffer.BlockCopy(Title, 0, bytes, i, Title.Length); i += Title.Length; - Utils.UInt64ToBytes(Powers, bytes, i); i += 8; - bytes[i++] = UpdateType; - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentData.Length; - for (int j = 0; j < RoleData.Length; j++) - length += RoleData[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public RoleDataBlock[] RoleData; - - public GroupRoleUpdatePacket() - { - HasVariableBlocks = true; - Type = PacketType.GroupRoleUpdate; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 378; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - RoleData = null; - } - - public GroupRoleUpdatePacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(RoleData == null || RoleData.Length != -1) { - RoleData = new RoleDataBlock[count]; - for(int j = 0; j < count; j++) - { RoleData[j] = new RoleDataBlock(); } - } - for (int j = 0; j < count; j++) - { RoleData[j].FromBytes(bytes, ref i); } - } - - public GroupRoleUpdatePacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(RoleData == null || RoleData.Length != count) { - RoleData = new RoleDataBlock[count]; - for(int j = 0; j < count; j++) - { RoleData[j] = new RoleDataBlock(); } - } - for (int j = 0; j < count; j++) - { RoleData[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length++; - for (int j = 0; j < RoleData.Length; j++) { length += RoleData[j].Length; } - if (Header.AckList != null && 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)RoleData.Length; - for (int j = 0; j < RoleData.Length; j++) { RoleData[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int RoleDataStart = 0; - do - { - int variableLength = 0; - int RoleDataCount = 0; - - i = RoleDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < RoleData.Length) { - int blockLength = RoleData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == RoleDataStart) { - variableLength += blockLength; - ++RoleDataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)RoleDataCount; - for (i = RoleDataStart; i < RoleDataStart + RoleDataCount; i++) { RoleData[i].ToBytes(packet, ref length); } - RoleDataStart += RoleDataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - RoleDataStart < RoleData.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class LiveHelpGroupRequestPacket : Packet - { - /// - public sealed class RequestDataBlock : PacketBlock - { - public UUID RequestID; - public UUID AgentID; - - public override int Length - { - get - { - return 32; - } - } - - public RequestDataBlock() { } - public RequestDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - RequestID.FromBytes(bytes, i); i += 16; - AgentID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - RequestID.ToBytes(bytes, i); i += 16; - AgentID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 10; - length += RequestData.Length; - return length; - } - } - public RequestDataBlock RequestData; - - public LiveHelpGroupRequestPacket() - { - HasVariableBlocks = false; - Type = PacketType.LiveHelpGroupRequest; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 379; - Header.Reliable = true; - RequestData = new RequestDataBlock(); - } - - public LiveHelpGroupRequestPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - RequestData.FromBytes(bytes, ref i); - } - - public LiveHelpGroupRequestPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - RequestData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += RequestData.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class LiveHelpGroupReplyPacket : Packet - { - /// - public sealed class ReplyDataBlock : PacketBlock - { - public UUID RequestID; - public UUID GroupID; - public byte[] Selection; - - public override int Length - { - get - { - int length = 33; - if (Selection != null) { length += Selection.Length; } - return length; - } - } - - public ReplyDataBlock() { } - public ReplyDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - RequestID.FromBytes(bytes, i); i += 16; - GroupID.FromBytes(bytes, i); i += 16; - length = bytes[i++]; - Selection = new byte[length]; - Buffer.BlockCopy(bytes, i, Selection, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - RequestID.ToBytes(bytes, i); i += 16; - GroupID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)Selection.Length; - Buffer.BlockCopy(Selection, 0, bytes, i, Selection.Length); i += Selection.Length; - } - - } - - public override int Length - { - get - { - int length = 10; - length += ReplyData.Length; - return length; - } - } - public ReplyDataBlock ReplyData; - - public LiveHelpGroupReplyPacket() - { - HasVariableBlocks = false; - Type = PacketType.LiveHelpGroupReply; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 380; - Header.Reliable = true; - ReplyData = new ReplyDataBlock(); - } - - public LiveHelpGroupReplyPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - ReplyData.FromBytes(bytes, ref i); - } - - public LiveHelpGroupReplyPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - ReplyData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += ReplyData.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class AgentWearablesRequestPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - return length; - } - } - public AgentDataBlock AgentData; - - public AgentWearablesRequestPacket() - { - HasVariableBlocks = false; - Type = PacketType.AgentWearablesRequest; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 381; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - } - - public AgentWearablesRequestPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - } - - public AgentWearablesRequestPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class AgentWearablesUpdatePacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - public uint SerialNum; - - public override int Length - { - get - { - return 36; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - SerialNum = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - Utils.UIntToBytes(SerialNum, bytes, i); i += 4; - } - - } - - /// - public sealed class WearableDataBlock : PacketBlock - { - public UUID ItemID; - public UUID AssetID; - public byte WearableType; - - public override int Length - { - get - { - return 33; - } - } - - public WearableDataBlock() { } - public WearableDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - ItemID.FromBytes(bytes, i); i += 16; - AssetID.FromBytes(bytes, i); i += 16; - WearableType = (byte)bytes[i++]; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - ItemID.ToBytes(bytes, i); i += 16; - AssetID.ToBytes(bytes, i); i += 16; - bytes[i++] = WearableType; - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentData.Length; - for (int j = 0; j < WearableData.Length; j++) - length += WearableData[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public WearableDataBlock[] WearableData; - - public AgentWearablesUpdatePacket() - { - HasVariableBlocks = true; - Type = PacketType.AgentWearablesUpdate; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 382; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - WearableData = null; - } - - public AgentWearablesUpdatePacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(WearableData == null || WearableData.Length != -1) { - WearableData = new WearableDataBlock[count]; - for(int j = 0; j < count; j++) - { WearableData[j] = new WearableDataBlock(); } - } - for (int j = 0; j < count; j++) - { WearableData[j].FromBytes(bytes, ref i); } - } - - public AgentWearablesUpdatePacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(WearableData == null || WearableData.Length != count) { - WearableData = new WearableDataBlock[count]; - for(int j = 0; j < count; j++) - { WearableData[j] = new WearableDataBlock(); } - } - for (int j = 0; j < count; j++) - { WearableData[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length++; - for (int j = 0; j < WearableData.Length; j++) { length += WearableData[j].Length; } - if (Header.AckList != null && 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)WearableData.Length; - for (int j = 0; j < WearableData.Length; j++) { WearableData[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int WearableDataStart = 0; - do - { - int variableLength = 0; - int WearableDataCount = 0; - - i = WearableDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < WearableData.Length) { - int blockLength = WearableData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == WearableDataStart) { - variableLength += blockLength; - ++WearableDataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)WearableDataCount; - for (i = WearableDataStart; i < WearableDataStart + WearableDataCount; i++) { WearableData[i].ToBytes(packet, ref length); } - WearableDataStart += WearableDataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - WearableDataStart < WearableData.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class AgentIsNowWearingPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class WearableDataBlock : PacketBlock - { - public UUID ItemID; - public byte WearableType; - - public override int Length - { - get - { - return 17; - } - } - - public WearableDataBlock() { } - public WearableDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - ItemID.FromBytes(bytes, i); i += 16; - WearableType = (byte)bytes[i++]; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - ItemID.ToBytes(bytes, i); i += 16; - bytes[i++] = WearableType; - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentData.Length; - for (int j = 0; j < WearableData.Length; j++) - length += WearableData[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public WearableDataBlock[] WearableData; - - public AgentIsNowWearingPacket() - { - HasVariableBlocks = true; - Type = PacketType.AgentIsNowWearing; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 383; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - WearableData = null; - } - - public AgentIsNowWearingPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(WearableData == null || WearableData.Length != -1) { - WearableData = new WearableDataBlock[count]; - for(int j = 0; j < count; j++) - { WearableData[j] = new WearableDataBlock(); } - } - for (int j = 0; j < count; j++) - { WearableData[j].FromBytes(bytes, ref i); } - } - - public AgentIsNowWearingPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(WearableData == null || WearableData.Length != count) { - WearableData = new WearableDataBlock[count]; - for(int j = 0; j < count; j++) - { WearableData[j] = new WearableDataBlock(); } - } - for (int j = 0; j < count; j++) - { WearableData[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length++; - for (int j = 0; j < WearableData.Length; j++) { length += WearableData[j].Length; } - if (Header.AckList != null && 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)WearableData.Length; - for (int j = 0; j < WearableData.Length; j++) { WearableData[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int WearableDataStart = 0; - do - { - int variableLength = 0; - int WearableDataCount = 0; - - i = WearableDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < WearableData.Length) { - int blockLength = WearableData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == WearableDataStart) { - variableLength += blockLength; - ++WearableDataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)WearableDataCount; - for (i = WearableDataStart; i < WearableDataStart + WearableDataCount; i++) { WearableData[i].ToBytes(packet, ref length); } - WearableDataStart += WearableDataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - WearableDataStart < WearableData.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class AgentCachedTexturePacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - public int SerialNum; - - public override int Length - { - get - { - return 36; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - SerialNum = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - Utils.IntToBytes(SerialNum, bytes, i); i += 4; - } - - } - - /// - public sealed class WearableDataBlock : PacketBlock - { - public UUID ID; - public byte TextureIndex; - - public override int Length - { - get - { - return 17; - } - } - - public WearableDataBlock() { } - public WearableDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - ID.FromBytes(bytes, i); i += 16; - TextureIndex = (byte)bytes[i++]; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - ID.ToBytes(bytes, i); i += 16; - bytes[i++] = TextureIndex; - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentData.Length; - for (int j = 0; j < WearableData.Length; j++) - length += WearableData[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public WearableDataBlock[] WearableData; - - public AgentCachedTexturePacket() - { - HasVariableBlocks = true; - Type = PacketType.AgentCachedTexture; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 384; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - WearableData = null; - } - - public AgentCachedTexturePacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(WearableData == null || WearableData.Length != -1) { - WearableData = new WearableDataBlock[count]; - for(int j = 0; j < count; j++) - { WearableData[j] = new WearableDataBlock(); } - } - for (int j = 0; j < count; j++) - { WearableData[j].FromBytes(bytes, ref i); } - } - - public AgentCachedTexturePacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(WearableData == null || WearableData.Length != count) { - WearableData = new WearableDataBlock[count]; - for(int j = 0; j < count; j++) - { WearableData[j] = new WearableDataBlock(); } - } - for (int j = 0; j < count; j++) - { WearableData[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length++; - for (int j = 0; j < WearableData.Length; j++) { length += WearableData[j].Length; } - if (Header.AckList != null && 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)WearableData.Length; - for (int j = 0; j < WearableData.Length; j++) { WearableData[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int WearableDataStart = 0; - do - { - int variableLength = 0; - int WearableDataCount = 0; - - i = WearableDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < WearableData.Length) { - int blockLength = WearableData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == WearableDataStart) { - variableLength += blockLength; - ++WearableDataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)WearableDataCount; - for (i = WearableDataStart; i < WearableDataStart + WearableDataCount; i++) { WearableData[i].ToBytes(packet, ref length); } - WearableDataStart += WearableDataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - WearableDataStart < WearableData.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class AgentCachedTextureResponsePacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - public int SerialNum; - - public override int Length - { - get - { - return 36; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - SerialNum = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - Utils.IntToBytes(SerialNum, bytes, i); i += 4; - } - - } - - /// - public sealed class WearableDataBlock : PacketBlock - { - public UUID TextureID; - public byte TextureIndex; - public byte[] HostName; - - public override int Length - { - get - { - int length = 18; - if (HostName != null) { length += HostName.Length; } - return length; - } - } - - public WearableDataBlock() { } - public WearableDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - TextureID.FromBytes(bytes, i); i += 16; - TextureIndex = (byte)bytes[i++]; - length = bytes[i++]; - HostName = new byte[length]; - Buffer.BlockCopy(bytes, i, HostName, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - TextureID.ToBytes(bytes, i); i += 16; - bytes[i++] = TextureIndex; - bytes[i++] = (byte)HostName.Length; - Buffer.BlockCopy(HostName, 0, bytes, i, HostName.Length); i += HostName.Length; - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentData.Length; - for (int j = 0; j < WearableData.Length; j++) - length += WearableData[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public WearableDataBlock[] WearableData; - - public AgentCachedTextureResponsePacket() - { - HasVariableBlocks = true; - Type = PacketType.AgentCachedTextureResponse; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 385; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - WearableData = null; - } - - public AgentCachedTextureResponsePacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(WearableData == null || WearableData.Length != -1) { - WearableData = new WearableDataBlock[count]; - for(int j = 0; j < count; j++) - { WearableData[j] = new WearableDataBlock(); } - } - for (int j = 0; j < count; j++) - { WearableData[j].FromBytes(bytes, ref i); } - } - - public AgentCachedTextureResponsePacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(WearableData == null || WearableData.Length != count) { - WearableData = new WearableDataBlock[count]; - for(int j = 0; j < count; j++) - { WearableData[j] = new WearableDataBlock(); } - } - for (int j = 0; j < count; j++) - { WearableData[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length++; - for (int j = 0; j < WearableData.Length; j++) { length += WearableData[j].Length; } - if (Header.AckList != null && 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)WearableData.Length; - for (int j = 0; j < WearableData.Length; j++) { WearableData[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int WearableDataStart = 0; - do - { - int variableLength = 0; - int WearableDataCount = 0; - - i = WearableDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < WearableData.Length) { - int blockLength = WearableData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == WearableDataStart) { - variableLength += blockLength; - ++WearableDataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)WearableDataCount; - for (i = WearableDataStart; i < WearableDataStart + WearableDataCount; i++) { WearableData[i].ToBytes(packet, ref length); } - WearableDataStart += WearableDataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - WearableDataStart < WearableData.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class AgentDataUpdateRequestPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - return length; - } - } - public AgentDataBlock AgentData; - - public AgentDataUpdateRequestPacket() - { - HasVariableBlocks = false; - Type = PacketType.AgentDataUpdateRequest; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 386; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - } - - public AgentDataUpdateRequestPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - } - - public AgentDataUpdateRequestPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class AgentDataUpdatePacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public byte[] FirstName; - public byte[] LastName; - public byte[] GroupTitle; - public UUID ActiveGroupID; - public ulong GroupPowers; - public byte[] GroupName; - - public override int Length - { - get - { - int length = 44; - if (FirstName != null) { length += FirstName.Length; } - if (LastName != null) { length += LastName.Length; } - if (GroupTitle != null) { length += GroupTitle.Length; } - if (GroupName != null) { length += GroupName.Length; } - return length; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - AgentID.FromBytes(bytes, i); i += 16; - length = bytes[i++]; - FirstName = new byte[length]; - Buffer.BlockCopy(bytes, i, FirstName, 0, length); i += length; - length = bytes[i++]; - LastName = new byte[length]; - Buffer.BlockCopy(bytes, i, LastName, 0, length); i += length; - length = bytes[i++]; - GroupTitle = new byte[length]; - Buffer.BlockCopy(bytes, i, GroupTitle, 0, length); i += length; - ActiveGroupID.FromBytes(bytes, i); i += 16; - 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)); - length = bytes[i++]; - GroupName = new byte[length]; - Buffer.BlockCopy(bytes, i, GroupName, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)FirstName.Length; - Buffer.BlockCopy(FirstName, 0, bytes, i, FirstName.Length); i += FirstName.Length; - bytes[i++] = (byte)LastName.Length; - Buffer.BlockCopy(LastName, 0, bytes, i, LastName.Length); i += LastName.Length; - bytes[i++] = (byte)GroupTitle.Length; - Buffer.BlockCopy(GroupTitle, 0, bytes, i, GroupTitle.Length); i += GroupTitle.Length; - ActiveGroupID.ToBytes(bytes, i); i += 16; - Utils.UInt64ToBytes(GroupPowers, bytes, i); i += 8; - bytes[i++] = (byte)GroupName.Length; - Buffer.BlockCopy(GroupName, 0, bytes, i, GroupName.Length); i += GroupName.Length; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - return length; - } - } - public AgentDataBlock AgentData; - - public AgentDataUpdatePacket() - { - HasVariableBlocks = false; - Type = PacketType.AgentDataUpdate; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 387; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - } - - public AgentDataUpdatePacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - } - - public AgentDataUpdatePacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class GroupDataUpdatePacket : Packet - { - /// - public sealed class AgentGroupDataBlock : PacketBlock - { - public UUID AgentID; - public UUID GroupID; - public ulong AgentPowers; - public byte[] GroupTitle; - - public override int Length - { - get - { - int length = 41; - if (GroupTitle != null) { length += GroupTitle.Length; } - return length; - } - } - - public AgentGroupDataBlock() { } - public AgentGroupDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - AgentID.FromBytes(bytes, i); i += 16; - GroupID.FromBytes(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)); - length = bytes[i++]; - GroupTitle = new byte[length]; - Buffer.BlockCopy(bytes, i, GroupTitle, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - GroupID.ToBytes(bytes, i); i += 16; - Utils.UInt64ToBytes(AgentPowers, bytes, i); i += 8; - bytes[i++] = (byte)GroupTitle.Length; - Buffer.BlockCopy(GroupTitle, 0, bytes, i, GroupTitle.Length); i += GroupTitle.Length; - } - - } - - public override int Length - { - get - { - int length = 11; - for (int j = 0; j < AgentGroupData.Length; j++) - length += AgentGroupData[j].Length; - return length; - } - } - public AgentGroupDataBlock[] AgentGroupData; - - public GroupDataUpdatePacket() - { - HasVariableBlocks = true; - Type = PacketType.GroupDataUpdate; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 388; - Header.Reliable = true; - Header.Zerocoded = true; - AgentGroupData = null; - } - - public GroupDataUpdatePacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - int count = (int)bytes[i++]; - if(AgentGroupData == null || AgentGroupData.Length != -1) { - AgentGroupData = new AgentGroupDataBlock[count]; - for(int j = 0; j < count; j++) - { AgentGroupData[j] = new AgentGroupDataBlock(); } - } - for (int j = 0; j < count; j++) - { AgentGroupData[j].FromBytes(bytes, ref i); } - } - - public GroupDataUpdatePacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - int count = (int)bytes[i++]; - if(AgentGroupData == null || AgentGroupData.Length != count) { - AgentGroupData = new AgentGroupDataBlock[count]; - for(int j = 0; j < count; j++) - { AgentGroupData[j] = new AgentGroupDataBlock(); } - } - for (int j = 0; j < count; j++) - { AgentGroupData[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length++; - for (int j = 0; j < AgentGroupData.Length; j++) { length += AgentGroupData[j].Length; } - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int AgentGroupDataStart = 0; - do - { - int variableLength = 0; - int AgentGroupDataCount = 0; - - i = AgentGroupDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < AgentGroupData.Length) { - int blockLength = AgentGroupData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == AgentGroupDataStart) { - variableLength += blockLength; - ++AgentGroupDataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)AgentGroupDataCount; - for (i = AgentGroupDataStart; i < AgentGroupDataStart + AgentGroupDataCount; i++) { AgentGroupData[i].ToBytes(packet, ref length); } - AgentGroupDataStart += AgentGroupDataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - AgentGroupDataStart < AgentGroupData.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class AgentGroupDataUpdatePacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - - public override int Length - { - get - { - return 16; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class GroupDataBlock : PacketBlock - { - public UUID GroupID; - public ulong GroupPowers; - public bool AcceptNotices; - public UUID GroupInsigniaID; - public int Contribution; - public byte[] GroupName; - - public override int Length - { - get - { - int length = 46; - if (GroupName != null) { length += GroupName.Length; } - return length; - } - } - - public GroupDataBlock() { } - public GroupDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - GroupID.FromBytes(bytes, i); i += 16; - 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)); - AcceptNotices = (bytes[i++] != 0) ? (bool)true : (bool)false; - GroupInsigniaID.FromBytes(bytes, i); i += 16; - Contribution = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - length = bytes[i++]; - GroupName = new byte[length]; - Buffer.BlockCopy(bytes, i, GroupName, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - GroupID.ToBytes(bytes, i); i += 16; - Utils.UInt64ToBytes(GroupPowers, bytes, i); i += 8; - bytes[i++] = (byte)((AcceptNotices) ? 1 : 0); - GroupInsigniaID.ToBytes(bytes, i); i += 16; - Utils.IntToBytes(Contribution, bytes, i); i += 4; - bytes[i++] = (byte)GroupName.Length; - Buffer.BlockCopy(GroupName, 0, bytes, i, GroupName.Length); i += GroupName.Length; - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentData.Length; - for (int j = 0; j < GroupData.Length; j++) - length += GroupData[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public GroupDataBlock[] GroupData; - - public AgentGroupDataUpdatePacket() - { - HasVariableBlocks = true; - Type = PacketType.AgentGroupDataUpdate; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 389; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - GroupData = null; - } - - public AgentGroupDataUpdatePacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(GroupData == null || GroupData.Length != -1) { - GroupData = new GroupDataBlock[count]; - for(int j = 0; j < count; j++) - { GroupData[j] = new GroupDataBlock(); } - } - for (int j = 0; j < count; j++) - { GroupData[j].FromBytes(bytes, ref i); } - } - - public AgentGroupDataUpdatePacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(GroupData == null || GroupData.Length != count) { - GroupData = new GroupDataBlock[count]; - for(int j = 0; j < count; j++) - { GroupData[j] = new GroupDataBlock(); } - } - for (int j = 0; j < count; j++) - { GroupData[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length++; - for (int j = 0; j < GroupData.Length; j++) { length += GroupData[j].Length; } - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int GroupDataStart = 0; - do - { - int variableLength = 0; - int GroupDataCount = 0; - - i = GroupDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < GroupData.Length) { - int blockLength = GroupData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == GroupDataStart) { - variableLength += blockLength; - ++GroupDataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)GroupDataCount; - for (i = GroupDataStart; i < GroupDataStart + GroupDataCount; i++) { GroupData[i].ToBytes(packet, ref length); } - GroupDataStart += GroupDataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - GroupDataStart < GroupData.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class AgentDropGroupPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID GroupID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - GroupID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - GroupID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - return length; - } - } - public AgentDataBlock AgentData; - - public AgentDropGroupPacket() - { - HasVariableBlocks = false; - Type = PacketType.AgentDropGroup; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 390; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - } - - public AgentDropGroupPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - } - - public AgentDropGroupPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class RezSingleAttachmentFromInvPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class ObjectDataBlock : PacketBlock - { - public UUID ItemID; - public UUID OwnerID; - public byte AttachmentPt; - public uint ItemFlags; - public uint GroupMask; - public uint EveryoneMask; - public uint NextOwnerMask; - public byte[] Name; - public byte[] Description; - - public override int Length - { - get - { - int length = 51; - if (Name != null) { length += Name.Length; } - if (Description != null) { length += Description.Length; } - return length; - } - } - - public ObjectDataBlock() { } - public ObjectDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - ItemID.FromBytes(bytes, i); i += 16; - OwnerID.FromBytes(bytes, i); i += 16; - AttachmentPt = (byte)bytes[i++]; - ItemFlags = (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)); - 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)); - length = bytes[i++]; - Name = new byte[length]; - Buffer.BlockCopy(bytes, i, Name, 0, length); i += length; - length = bytes[i++]; - Description = new byte[length]; - Buffer.BlockCopy(bytes, i, Description, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - ItemID.ToBytes(bytes, i); i += 16; - OwnerID.ToBytes(bytes, i); i += 16; - bytes[i++] = AttachmentPt; - Utils.UIntToBytes(ItemFlags, bytes, i); i += 4; - Utils.UIntToBytes(GroupMask, bytes, i); i += 4; - Utils.UIntToBytes(EveryoneMask, bytes, i); i += 4; - Utils.UIntToBytes(NextOwnerMask, bytes, i); i += 4; - bytes[i++] = (byte)Name.Length; - Buffer.BlockCopy(Name, 0, bytes, i, Name.Length); i += Name.Length; - bytes[i++] = (byte)Description.Length; - Buffer.BlockCopy(Description, 0, bytes, i, Description.Length); i += Description.Length; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += ObjectData.Length; - return length; - } - } - public AgentDataBlock AgentData; - public ObjectDataBlock ObjectData; - - public RezSingleAttachmentFromInvPacket() - { - HasVariableBlocks = false; - Type = PacketType.RezSingleAttachmentFromInv; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 395; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - ObjectData = new ObjectDataBlock(); - } - - public RezSingleAttachmentFromInvPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - ObjectData.FromBytes(bytes, ref i); - } - - public RezSingleAttachmentFromInvPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - ObjectData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += ObjectData.Length; - if (Header.AckList != null && 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); - ObjectData.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class RezMultipleAttachmentsFromInvPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class HeaderDataBlock : PacketBlock - { - public UUID CompoundMsgID; - public byte TotalObjects; - public bool FirstDetachAll; - - public override int Length - { - get - { - return 18; - } - } - - public HeaderDataBlock() { } - public HeaderDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - CompoundMsgID.FromBytes(bytes, i); i += 16; - TotalObjects = (byte)bytes[i++]; - FirstDetachAll = (bytes[i++] != 0) ? (bool)true : (bool)false; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - CompoundMsgID.ToBytes(bytes, i); i += 16; - bytes[i++] = TotalObjects; - bytes[i++] = (byte)((FirstDetachAll) ? 1 : 0); - } - - } - - /// - public sealed class ObjectDataBlock : PacketBlock - { - public UUID ItemID; - public UUID OwnerID; - public byte AttachmentPt; - public uint ItemFlags; - public uint GroupMask; - public uint EveryoneMask; - public uint NextOwnerMask; - public byte[] Name; - public byte[] Description; - - public override int Length - { - get - { - int length = 51; - if (Name != null) { length += Name.Length; } - if (Description != null) { length += Description.Length; } - return length; - } - } - - public ObjectDataBlock() { } - public ObjectDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - ItemID.FromBytes(bytes, i); i += 16; - OwnerID.FromBytes(bytes, i); i += 16; - AttachmentPt = (byte)bytes[i++]; - ItemFlags = (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)); - 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)); - length = bytes[i++]; - Name = new byte[length]; - Buffer.BlockCopy(bytes, i, Name, 0, length); i += length; - length = bytes[i++]; - Description = new byte[length]; - Buffer.BlockCopy(bytes, i, Description, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - ItemID.ToBytes(bytes, i); i += 16; - OwnerID.ToBytes(bytes, i); i += 16; - bytes[i++] = AttachmentPt; - Utils.UIntToBytes(ItemFlags, bytes, i); i += 4; - Utils.UIntToBytes(GroupMask, bytes, i); i += 4; - Utils.UIntToBytes(EveryoneMask, bytes, i); i += 4; - Utils.UIntToBytes(NextOwnerMask, bytes, i); i += 4; - bytes[i++] = (byte)Name.Length; - Buffer.BlockCopy(Name, 0, bytes, i, Name.Length); i += Name.Length; - bytes[i++] = (byte)Description.Length; - Buffer.BlockCopy(Description, 0, bytes, i, Description.Length); i += Description.Length; - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentData.Length; - length += HeaderData.Length; - for (int j = 0; j < ObjectData.Length; j++) - length += ObjectData[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public HeaderDataBlock HeaderData; - public ObjectDataBlock[] ObjectData; - - public RezMultipleAttachmentsFromInvPacket() - { - HasVariableBlocks = true; - Type = PacketType.RezMultipleAttachmentsFromInv; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 396; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - HeaderData = new HeaderDataBlock(); - ObjectData = null; - } - - public RezMultipleAttachmentsFromInvPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - HeaderData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ObjectData == null || ObjectData.Length != -1) { - ObjectData = new ObjectDataBlock[count]; - for(int j = 0; j < count; j++) - { ObjectData[j] = new ObjectDataBlock(); } - } - for (int j = 0; j < count; j++) - { ObjectData[j].FromBytes(bytes, ref i); } - } - - public RezMultipleAttachmentsFromInvPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - HeaderData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ObjectData == null || ObjectData.Length != count) { - ObjectData = new ObjectDataBlock[count]; - for(int j = 0; j < count; j++) - { ObjectData[j] = new ObjectDataBlock(); } - } - for (int j = 0; j < count; j++) - { ObjectData[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += HeaderData.Length; - length++; - for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } - if (Header.AckList != null && 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); - HeaderData.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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - fixedLength += HeaderData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - HeaderData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int ObjectDataStart = 0; - do - { - int variableLength = 0; - int ObjectDataCount = 0; - - i = ObjectDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < ObjectData.Length) { - int blockLength = ObjectData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ObjectDataStart) { - variableLength += blockLength; - ++ObjectDataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)ObjectDataCount; - for (i = ObjectDataStart; i < ObjectDataStart + ObjectDataCount; i++) { ObjectData[i].ToBytes(packet, ref length); } - ObjectDataStart += ObjectDataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - ObjectDataStart < ObjectData.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class DetachAttachmentIntoInvPacket : Packet - { - /// - public sealed class ObjectDataBlock : PacketBlock - { - public UUID AgentID; - public UUID ItemID; - - public override int Length - { - get - { - return 32; - } - } - - public ObjectDataBlock() { } - public ObjectDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - ItemID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - ItemID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 10; - length += ObjectData.Length; - return length; - } - } - public ObjectDataBlock ObjectData; - - public DetachAttachmentIntoInvPacket() - { - HasVariableBlocks = false; - Type = PacketType.DetachAttachmentIntoInv; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 397; - Header.Reliable = true; - ObjectData = new ObjectDataBlock(); - } - - public DetachAttachmentIntoInvPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - ObjectData.FromBytes(bytes, ref i); - } - - public DetachAttachmentIntoInvPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - ObjectData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += ObjectData.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class CreateNewOutfitAttachmentsPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class HeaderDataBlock : PacketBlock - { - public UUID NewFolderID; - - public override int Length - { - get - { - return 16; - } - } - - public HeaderDataBlock() { } - public HeaderDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - NewFolderID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - NewFolderID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class ObjectDataBlock : PacketBlock - { - public UUID OldItemID; - public UUID OldFolderID; - - public override int Length - { - get - { - return 32; - } - } - - public ObjectDataBlock() { } - public ObjectDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - OldItemID.FromBytes(bytes, i); i += 16; - OldFolderID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - OldItemID.ToBytes(bytes, i); i += 16; - OldFolderID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentData.Length; - length += HeaderData.Length; - for (int j = 0; j < ObjectData.Length; j++) - length += ObjectData[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public HeaderDataBlock HeaderData; - public ObjectDataBlock[] ObjectData; - - public CreateNewOutfitAttachmentsPacket() - { - HasVariableBlocks = true; - Type = PacketType.CreateNewOutfitAttachments; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 398; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - HeaderData = new HeaderDataBlock(); - ObjectData = null; - } - - public CreateNewOutfitAttachmentsPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - HeaderData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ObjectData == null || ObjectData.Length != -1) { - ObjectData = new ObjectDataBlock[count]; - for(int j = 0; j < count; j++) - { ObjectData[j] = new ObjectDataBlock(); } - } - for (int j = 0; j < count; j++) - { ObjectData[j].FromBytes(bytes, ref i); } - } - - public CreateNewOutfitAttachmentsPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - HeaderData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ObjectData == null || ObjectData.Length != count) { - ObjectData = new ObjectDataBlock[count]; - for(int j = 0; j < count; j++) - { ObjectData[j] = new ObjectDataBlock(); } - } - for (int j = 0; j < count; j++) - { ObjectData[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += HeaderData.Length; - length++; - for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } - if (Header.AckList != null && 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); - HeaderData.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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - fixedLength += HeaderData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - HeaderData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int ObjectDataStart = 0; - do - { - int variableLength = 0; - int ObjectDataCount = 0; - - i = ObjectDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < ObjectData.Length) { - int blockLength = ObjectData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ObjectDataStart) { - variableLength += blockLength; - ++ObjectDataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)ObjectDataCount; - for (i = ObjectDataStart; i < ObjectDataStart + ObjectDataCount; i++) { ObjectData[i].ToBytes(packet, ref length); } - ObjectDataStart += ObjectDataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - ObjectDataStart < ObjectData.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class UserInfoRequestPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - return length; - } - } - public AgentDataBlock AgentData; - - public UserInfoRequestPacket() - { - HasVariableBlocks = false; - Type = PacketType.UserInfoRequest; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 399; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - } - - public UserInfoRequestPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - } - - public UserInfoRequestPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class UserInfoReplyPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - - public override int Length - { - get - { - return 16; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class UserDataBlock : PacketBlock - { - public bool IMViaEMail; - public byte[] DirectoryVisibility; - public byte[] EMail; - - public override int Length - { - get - { - int length = 4; - if (DirectoryVisibility != null) { length += DirectoryVisibility.Length; } - if (EMail != null) { length += EMail.Length; } - return length; - } - } - - public UserDataBlock() { } - public UserDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - IMViaEMail = (bytes[i++] != 0) ? (bool)true : (bool)false; - length = bytes[i++]; - DirectoryVisibility = new byte[length]; - Buffer.BlockCopy(bytes, i, DirectoryVisibility, 0, length); i += length; - length = (bytes[i++] + (bytes[i++] << 8)); - EMail = new byte[length]; - Buffer.BlockCopy(bytes, i, EMail, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - bytes[i++] = (byte)((IMViaEMail) ? 1 : 0); - bytes[i++] = (byte)DirectoryVisibility.Length; - Buffer.BlockCopy(DirectoryVisibility, 0, bytes, i, DirectoryVisibility.Length); i += DirectoryVisibility.Length; - bytes[i++] = (byte)(EMail.Length % 256); - bytes[i++] = (byte)((EMail.Length >> 8) % 256); - Buffer.BlockCopy(EMail, 0, bytes, i, EMail.Length); i += EMail.Length; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += UserData.Length; - return length; - } - } - public AgentDataBlock AgentData; - public UserDataBlock UserData; - - public UserInfoReplyPacket() - { - HasVariableBlocks = false; - Type = PacketType.UserInfoReply; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 400; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - UserData = new UserDataBlock(); - } - - public UserInfoReplyPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - UserData.FromBytes(bytes, ref i); - } - - public UserInfoReplyPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - UserData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += UserData.Length; - if (Header.AckList != null && 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); - UserData.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class UpdateUserInfoPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class UserDataBlock : PacketBlock - { - public bool IMViaEMail; - public byte[] DirectoryVisibility; - - public override int Length - { - get - { - int length = 2; - if (DirectoryVisibility != null) { length += DirectoryVisibility.Length; } - return length; - } - } - - public UserDataBlock() { } - public UserDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - IMViaEMail = (bytes[i++] != 0) ? (bool)true : (bool)false; - length = bytes[i++]; - DirectoryVisibility = new byte[length]; - Buffer.BlockCopy(bytes, i, DirectoryVisibility, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - bytes[i++] = (byte)((IMViaEMail) ? 1 : 0); - bytes[i++] = (byte)DirectoryVisibility.Length; - Buffer.BlockCopy(DirectoryVisibility, 0, bytes, i, DirectoryVisibility.Length); i += DirectoryVisibility.Length; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += UserData.Length; - return length; - } - } - public AgentDataBlock AgentData; - public UserDataBlock UserData; - - public UpdateUserInfoPacket() - { - HasVariableBlocks = false; - Type = PacketType.UpdateUserInfo; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 401; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - UserData = new UserDataBlock(); - } - - public UpdateUserInfoPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - UserData.FromBytes(bytes, ref i); - } - - public UpdateUserInfoPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - UserData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += UserData.Length; - if (Header.AckList != null && 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); - UserData.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class InitiateDownloadPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - - public override int Length - { - get - { - return 16; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class FileDataBlock : PacketBlock - { - public byte[] SimFilename; - public byte[] ViewerFilename; - - public override int Length - { - get - { - int length = 2; - if (SimFilename != null) { length += SimFilename.Length; } - if (ViewerFilename != null) { length += ViewerFilename.Length; } - return length; - } - } - - public FileDataBlock() { } - public FileDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - length = bytes[i++]; - SimFilename = new byte[length]; - Buffer.BlockCopy(bytes, i, SimFilename, 0, length); i += length; - length = bytes[i++]; - ViewerFilename = new byte[length]; - Buffer.BlockCopy(bytes, i, ViewerFilename, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - bytes[i++] = (byte)SimFilename.Length; - Buffer.BlockCopy(SimFilename, 0, bytes, i, SimFilename.Length); i += SimFilename.Length; - bytes[i++] = (byte)ViewerFilename.Length; - Buffer.BlockCopy(ViewerFilename, 0, bytes, i, ViewerFilename.Length); i += ViewerFilename.Length; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += FileData.Length; - return length; - } - } - public AgentDataBlock AgentData; - public FileDataBlock FileData; - - public InitiateDownloadPacket() - { - HasVariableBlocks = false; - Type = PacketType.InitiateDownload; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 403; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - FileData = new FileDataBlock(); - } - - public InitiateDownloadPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - FileData.FromBytes(bytes, ref i); - } - - public InitiateDownloadPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - FileData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += FileData.Length; - if (Header.AckList != null && 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); - FileData.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class MapLayerRequestPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - public uint Flags; - public uint EstateID; - public bool Godlike; - - public override int Length - { - get - { - return 41; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - 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)); - Godlike = (bytes[i++] != 0) ? (bool)true : (bool)false; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - Utils.UIntToBytes(Flags, bytes, i); i += 4; - Utils.UIntToBytes(EstateID, bytes, i); i += 4; - bytes[i++] = (byte)((Godlike) ? 1 : 0); - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - return length; - } - } - public AgentDataBlock AgentData; - - public MapLayerRequestPacket() - { - HasVariableBlocks = false; - Type = PacketType.MapLayerRequest; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 405; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - } - - public MapLayerRequestPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - } - - public MapLayerRequestPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class MapLayerReplyPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public uint Flags; - - public override int Length - { - get - { - return 20; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - Flags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - Utils.UIntToBytes(Flags, bytes, i); i += 4; - } - - } - - /// - public sealed class LayerDataBlock : PacketBlock - { - public uint Left; - public uint Right; - public uint Top; - public uint Bottom; - public UUID ImageID; - - public override int Length - { - get - { - return 32; - } - } - - public LayerDataBlock() { } - public LayerDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - Left = (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)); - Top = (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)); - ImageID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UIntToBytes(Left, bytes, i); i += 4; - Utils.UIntToBytes(Right, bytes, i); i += 4; - Utils.UIntToBytes(Top, bytes, i); i += 4; - Utils.UIntToBytes(Bottom, bytes, i); i += 4; - ImageID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentData.Length; - for (int j = 0; j < LayerData.Length; j++) - length += LayerData[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public LayerDataBlock[] LayerData; - - public MapLayerReplyPacket() - { - HasVariableBlocks = true; - Type = PacketType.MapLayerReply; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 406; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - LayerData = null; - } - - public MapLayerReplyPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(LayerData == null || LayerData.Length != -1) { - LayerData = new LayerDataBlock[count]; - for(int j = 0; j < count; j++) - { LayerData[j] = new LayerDataBlock(); } - } - for (int j = 0; j < count; j++) - { LayerData[j].FromBytes(bytes, ref i); } - } - - public MapLayerReplyPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(LayerData == null || LayerData.Length != count) { - LayerData = new LayerDataBlock[count]; - for(int j = 0; j < count; j++) - { LayerData[j] = new LayerDataBlock(); } - } - for (int j = 0; j < count; j++) - { LayerData[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length++; - for (int j = 0; j < LayerData.Length; j++) { length += LayerData[j].Length; } - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int LayerDataStart = 0; - do - { - int variableLength = 0; - int LayerDataCount = 0; - - i = LayerDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < LayerData.Length) { - int blockLength = LayerData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == LayerDataStart) { - variableLength += blockLength; - ++LayerDataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)LayerDataCount; - for (i = LayerDataStart; i < LayerDataStart + LayerDataCount; i++) { LayerData[i].ToBytes(packet, ref length); } - LayerDataStart += LayerDataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - LayerDataStart < LayerData.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class MapBlockRequestPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - public uint Flags; - public uint EstateID; - public bool Godlike; - - public override int Length - { - get - { - return 41; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - 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)); - Godlike = (bytes[i++] != 0) ? (bool)true : (bool)false; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - Utils.UIntToBytes(Flags, bytes, i); i += 4; - Utils.UIntToBytes(EstateID, bytes, i); i += 4; - bytes[i++] = (byte)((Godlike) ? 1 : 0); - } - - } - - /// - public sealed class PositionDataBlock : PacketBlock - { - public ushort MinX; - public ushort MaxX; - public ushort MinY; - public ushort MaxY; - - public override int Length - { - get - { - return 8; - } - } - - public PositionDataBlock() { } - public PositionDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - MinX = (ushort)(bytes[i++] + (bytes[i++] << 8)); - MaxX = (ushort)(bytes[i++] + (bytes[i++] << 8)); - MinY = (ushort)(bytes[i++] + (bytes[i++] << 8)); - MaxY = (ushort)(bytes[i++] + (bytes[i++] << 8)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - bytes[i++] = (byte)(MinX % 256); - bytes[i++] = (byte)((MinX >> 8) % 256); - bytes[i++] = (byte)(MaxX % 256); - bytes[i++] = (byte)((MaxX >> 8) % 256); - bytes[i++] = (byte)(MinY % 256); - bytes[i++] = (byte)((MinY >> 8) % 256); - bytes[i++] = (byte)(MaxY % 256); - bytes[i++] = (byte)((MaxY >> 8) % 256); - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += PositionData.Length; - return length; - } - } - public AgentDataBlock AgentData; - public PositionDataBlock PositionData; - - public MapBlockRequestPacket() - { - HasVariableBlocks = false; - Type = PacketType.MapBlockRequest; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 407; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - PositionData = new PositionDataBlock(); - } - - public MapBlockRequestPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - PositionData.FromBytes(bytes, ref i); - } - - public MapBlockRequestPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - PositionData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += PositionData.Length; - if (Header.AckList != null && 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); - PositionData.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class MapNameRequestPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - public uint Flags; - public uint EstateID; - public bool Godlike; - - public override int Length - { - get - { - return 41; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - 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)); - Godlike = (bytes[i++] != 0) ? (bool)true : (bool)false; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - Utils.UIntToBytes(Flags, bytes, i); i += 4; - Utils.UIntToBytes(EstateID, bytes, i); i += 4; - bytes[i++] = (byte)((Godlike) ? 1 : 0); - } - - } - - /// - public sealed class NameDataBlock : PacketBlock - { - public byte[] Name; - - public override int Length - { - get - { - int length = 1; - if (Name != null) { length += Name.Length; } - return length; - } - } - - public NameDataBlock() { } - public NameDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - length = bytes[i++]; - Name = new byte[length]; - Buffer.BlockCopy(bytes, i, Name, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - bytes[i++] = (byte)Name.Length; - Buffer.BlockCopy(Name, 0, bytes, i, Name.Length); i += Name.Length; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += NameData.Length; - return length; - } - } - public AgentDataBlock AgentData; - public NameDataBlock NameData; - - public MapNameRequestPacket() - { - HasVariableBlocks = false; - Type = PacketType.MapNameRequest; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 408; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - NameData = new NameDataBlock(); - } - - public MapNameRequestPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - NameData.FromBytes(bytes, ref i); - } - - public MapNameRequestPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - NameData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += NameData.Length; - if (Header.AckList != null && 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); - NameData.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class MapBlockReplyPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public uint Flags; - - public override int Length - { - get - { - return 20; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - Flags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - Utils.UIntToBytes(Flags, bytes, i); i += 4; - } - - } - - /// - public sealed class DataBlock : PacketBlock - { - public ushort X; - public ushort Y; - public byte[] Name; - public byte Access; - public uint RegionFlags; - public byte WaterHeight; - public byte Agents; - public UUID MapImageID; - - public override int Length - { - get - { - int length = 28; - if (Name != null) { length += Name.Length; } - return length; - } - } - - public DataBlock() { } - public DataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - X = (ushort)(bytes[i++] + (bytes[i++] << 8)); - Y = (ushort)(bytes[i++] + (bytes[i++] << 8)); - length = bytes[i++]; - Name = new byte[length]; - Buffer.BlockCopy(bytes, i, Name, 0, length); i += length; - Access = (byte)bytes[i++]; - RegionFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - WaterHeight = (byte)bytes[i++]; - Agents = (byte)bytes[i++]; - MapImageID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override 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)Name.Length; - Buffer.BlockCopy(Name, 0, bytes, i, Name.Length); i += Name.Length; - bytes[i++] = Access; - Utils.UIntToBytes(RegionFlags, bytes, i); i += 4; - bytes[i++] = WaterHeight; - bytes[i++] = Agents; - MapImageID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class SizeBlock : PacketBlock - { - public ushort SizeX; - public ushort SizeY; - - public override int Length - { - get - { - return 4; - } - } - - public SizeBlock() { } - public SizeBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - SizeX = (ushort)(bytes[i++] + (bytes[i++] << 8)); - SizeY = (ushort)(bytes[i++] + (bytes[i++] << 8)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - bytes[i++] = (byte)(SizeX % 256); - bytes[i++] = (byte)((SizeX >> 8) % 256); - bytes[i++] = (byte)(SizeY % 256); - bytes[i++] = (byte)((SizeY >> 8) % 256); - } - - } - - public override int Length - { - get - { - int length = 12; - length += AgentData.Length; - for (int j = 0; j < Data.Length; j++) - length += Data[j].Length; - for (int j = 0; j < Size.Length; j++) - length += Size[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public DataBlock[] Data; - public SizeBlock[] Size; - - public MapBlockReplyPacket() - { - HasVariableBlocks = true; - Type = PacketType.MapBlockReply; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 409; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - Data = null; - Size = null; - } - - public MapBlockReplyPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(Data == null || Data.Length != -1) { - Data = new DataBlock[count]; - for(int j = 0; j < count; j++) - { Data[j] = new DataBlock(); } - } - for (int j = 0; j < count; j++) - { Data[j].FromBytes(bytes, ref i); } - count = (int)bytes[i++]; - if(Size == null || Size.Length != -1) { - Size = new SizeBlock[count]; - for(int j = 0; j < count; j++) - { Size[j] = new SizeBlock(); } - } - for (int j = 0; j < count; j++) - { Size[j].FromBytes(bytes, ref i); } - } - - public MapBlockReplyPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(Data == null || Data.Length != count) { - Data = new DataBlock[count]; - for(int j = 0; j < count; j++) - { Data[j] = new DataBlock(); } - } - for (int j = 0; j < count; j++) - { Data[j].FromBytes(bytes, ref i); } - count = (int)bytes[i++]; - if(Size == null || Size.Length != count) { - Size = new SizeBlock[count]; - for(int j = 0; j < count; j++) - { Size[j] = new SizeBlock(); } - } - for (int j = 0; j < count; j++) - { Size[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length++; - for (int j = 0; j < Data.Length; j++) { length += Data[j].Length; } - length++; - for (int j = 0; j < Size.Length; j++) { length += Size[j].Length; } - if (Header.AckList != null && 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)Data.Length; - for (int j = 0; j < Data.Length; j++) { Data[j].ToBytes(bytes, ref i); } - bytes[i++] = (byte)Size.Length; - for (int j = 0; j < Size.Length; j++) { Size[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - fixedLength += 2; - - int DataStart = 0; - int SizeStart = 0; - do - { - int variableLength = 0; - int DataCount = 0; - int SizeCount = 0; - - i = DataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < Data.Length) { - int blockLength = Data[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == DataStart) { - variableLength += blockLength; - ++DataCount; - } - else { break; } - ++i; - } - - i = SizeStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < Size.Length) { - int blockLength = Size[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == SizeStart) { - variableLength += blockLength; - ++SizeCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)DataCount; - for (i = DataStart; i < DataStart + DataCount; i++) { Data[i].ToBytes(packet, ref length); } - DataStart += DataCount; - - packet[length++] = (byte)SizeCount; - for (i = SizeStart; i < SizeStart + SizeCount; i++) { Size[i].ToBytes(packet, ref length); } - SizeStart += SizeCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - DataStart < Data.Length || - SizeStart < Size.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class MapItemRequestPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - public uint Flags; - public uint EstateID; - public bool Godlike; - - public override int Length - { - get - { - return 41; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - 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)); - Godlike = (bytes[i++] != 0) ? (bool)true : (bool)false; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - Utils.UIntToBytes(Flags, bytes, i); i += 4; - Utils.UIntToBytes(EstateID, bytes, i); i += 4; - bytes[i++] = (byte)((Godlike) ? 1 : 0); - } - - } - - /// - public sealed class RequestDataBlock : PacketBlock - { - public uint ItemType; - public ulong RegionHandle; - - public override int Length - { - get - { - return 12; - } - } - - public RequestDataBlock() { } - public RequestDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - ItemType = (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)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UIntToBytes(ItemType, bytes, i); i += 4; - Utils.UInt64ToBytes(RegionHandle, bytes, i); i += 8; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += RequestData.Length; - return length; - } - } - public AgentDataBlock AgentData; - public RequestDataBlock RequestData; - - public MapItemRequestPacket() - { - HasVariableBlocks = false; - Type = PacketType.MapItemRequest; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 410; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - RequestData = new RequestDataBlock(); - } - - public MapItemRequestPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - RequestData.FromBytes(bytes, ref i); - } - - public MapItemRequestPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - RequestData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += RequestData.Length; - if (Header.AckList != null && 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); - RequestData.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class MapItemReplyPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public uint Flags; - - public override int Length - { - get - { - return 20; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - Flags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - Utils.UIntToBytes(Flags, bytes, i); i += 4; - } - - } - - /// - public sealed class RequestDataBlock : PacketBlock - { - public uint ItemType; - - public override int Length - { - get - { - return 4; - } - } - - public RequestDataBlock() { } - public RequestDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - ItemType = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UIntToBytes(ItemType, bytes, i); i += 4; - } - - } - - /// - public sealed class DataBlock : PacketBlock - { - public uint X; - public uint Y; - public UUID ID; - public int Extra; - public int Extra2; - public byte[] Name; - - public override int Length - { - get - { - int length = 33; - if (Name != null) { length += Name.Length; } - return length; - } - } - - public DataBlock() { } - public DataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(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.FromBytes(bytes, i); i += 16; - Extra = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - Extra2 = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - length = bytes[i++]; - Name = new byte[length]; - Buffer.BlockCopy(bytes, i, Name, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UIntToBytes(X, bytes, i); i += 4; - Utils.UIntToBytes(Y, bytes, i); i += 4; - ID.ToBytes(bytes, i); i += 16; - Utils.IntToBytes(Extra, bytes, i); i += 4; - Utils.IntToBytes(Extra2, bytes, i); i += 4; - bytes[i++] = (byte)Name.Length; - Buffer.BlockCopy(Name, 0, bytes, i, Name.Length); i += Name.Length; - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentData.Length; - length += RequestData.Length; - for (int j = 0; j < Data.Length; j++) - length += Data[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public RequestDataBlock RequestData; - public DataBlock[] Data; - - public MapItemReplyPacket() - { - HasVariableBlocks = true; - Type = PacketType.MapItemReply; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 411; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - RequestData = new RequestDataBlock(); - Data = null; - } - - public MapItemReplyPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - RequestData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(Data == null || Data.Length != -1) { - Data = new DataBlock[count]; - for(int j = 0; j < count; j++) - { Data[j] = new DataBlock(); } - } - for (int j = 0; j < count; j++) - { Data[j].FromBytes(bytes, ref i); } - } - - public MapItemReplyPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - RequestData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(Data == null || Data.Length != count) { - Data = new DataBlock[count]; - for(int j = 0; j < count; j++) - { Data[j] = new DataBlock(); } - } - for (int j = 0; j < count; j++) - { Data[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += RequestData.Length; - length++; - for (int j = 0; j < Data.Length; j++) { length += Data[j].Length; } - if (Header.AckList != null && 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); - RequestData.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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - fixedLength += RequestData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - RequestData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int DataStart = 0; - do - { - int variableLength = 0; - int DataCount = 0; - - i = DataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < Data.Length) { - int blockLength = Data[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == DataStart) { - variableLength += blockLength; - ++DataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)DataCount; - for (i = DataStart; i < DataStart + DataCount; i++) { Data[i].ToBytes(packet, ref length); } - DataStart += DataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - DataStart < Data.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class SendPostcardPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - public UUID AssetID; - public Vector3d PosGlobal; - public byte[] To; - public byte[] From; - public byte[] Name; - public byte[] Subject; - public byte[] Msg; - public bool AllowPublish; - public bool MaturePublish; - - public override int Length - { - get - { - int length = 80; - if (To != null) { length += To.Length; } - if (From != null) { length += From.Length; } - if (Name != null) { length += Name.Length; } - if (Subject != null) { length += Subject.Length; } - if (Msg != null) { length += Msg.Length; } - return length; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - AssetID.FromBytes(bytes, i); i += 16; - PosGlobal.FromBytes(bytes, i); i += 24; - length = bytes[i++]; - To = new byte[length]; - Buffer.BlockCopy(bytes, i, To, 0, length); i += length; - length = bytes[i++]; - From = new byte[length]; - Buffer.BlockCopy(bytes, i, From, 0, length); i += length; - length = bytes[i++]; - Name = new byte[length]; - Buffer.BlockCopy(bytes, i, Name, 0, length); i += length; - length = bytes[i++]; - Subject = new byte[length]; - Buffer.BlockCopy(bytes, i, Subject, 0, length); i += length; - length = (bytes[i++] + (bytes[i++] << 8)); - Msg = new byte[length]; - Buffer.BlockCopy(bytes, i, Msg, 0, length); i += length; - AllowPublish = (bytes[i++] != 0) ? (bool)true : (bool)false; - MaturePublish = (bytes[i++] != 0) ? (bool)true : (bool)false; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - AssetID.ToBytes(bytes, i); i += 16; - PosGlobal.ToBytes(bytes, i); i += 24; - bytes[i++] = (byte)To.Length; - Buffer.BlockCopy(To, 0, bytes, i, To.Length); i += To.Length; - bytes[i++] = (byte)From.Length; - Buffer.BlockCopy(From, 0, bytes, i, From.Length); i += From.Length; - bytes[i++] = (byte)Name.Length; - Buffer.BlockCopy(Name, 0, bytes, i, Name.Length); i += Name.Length; - bytes[i++] = (byte)Subject.Length; - Buffer.BlockCopy(Subject, 0, bytes, i, Subject.Length); i += Subject.Length; - bytes[i++] = (byte)(Msg.Length % 256); - bytes[i++] = (byte)((Msg.Length >> 8) % 256); - Buffer.BlockCopy(Msg, 0, bytes, i, Msg.Length); i += Msg.Length; - bytes[i++] = (byte)((AllowPublish) ? 1 : 0); - bytes[i++] = (byte)((MaturePublish) ? 1 : 0); - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - return length; - } - } - public AgentDataBlock AgentData; - - public SendPostcardPacket() - { - HasVariableBlocks = false; - Type = PacketType.SendPostcard; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 412; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - } - - public SendPostcardPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - } - - public SendPostcardPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class ParcelMediaCommandMessagePacket : Packet - { - /// - public sealed class CommandBlockBlock : PacketBlock - { - public uint Flags; - public uint Command; - public float Time; - - public override int Length - { - get - { - return 12; - } - } - - public CommandBlockBlock() { } - public CommandBlockBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - Flags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - Command = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - Time = Utils.BytesToFloat(bytes, i); i += 4; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UIntToBytes(Flags, bytes, i); i += 4; - Utils.UIntToBytes(Command, bytes, i); i += 4; - Utils.FloatToBytes(Time, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 10; - length += CommandBlock.Length; - return length; - } - } - public CommandBlockBlock CommandBlock; - - public ParcelMediaCommandMessagePacket() - { - HasVariableBlocks = false; - Type = PacketType.ParcelMediaCommandMessage; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 419; - Header.Reliable = true; - CommandBlock = new CommandBlockBlock(); - } - - public ParcelMediaCommandMessagePacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - CommandBlock.FromBytes(bytes, ref i); - } - - public ParcelMediaCommandMessagePacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - CommandBlock.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += CommandBlock.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class ParcelMediaUpdatePacket : Packet - { - /// - public sealed class DataBlockBlock : PacketBlock - { - public byte[] MediaURL; - public UUID MediaID; - public byte MediaAutoScale; - - public override int Length - { - get - { - int length = 18; - if (MediaURL != null) { length += MediaURL.Length; } - return length; - } - } - - public DataBlockBlock() { } - public DataBlockBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - length = bytes[i++]; - MediaURL = new byte[length]; - Buffer.BlockCopy(bytes, i, MediaURL, 0, length); i += length; - MediaID.FromBytes(bytes, i); i += 16; - MediaAutoScale = (byte)bytes[i++]; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - bytes[i++] = (byte)MediaURL.Length; - Buffer.BlockCopy(MediaURL, 0, bytes, i, MediaURL.Length); i += MediaURL.Length; - MediaID.ToBytes(bytes, i); i += 16; - bytes[i++] = MediaAutoScale; - } - - } - - /// - public sealed class DataBlockExtendedBlock : PacketBlock - { - public byte[] MediaType; - public byte[] MediaDesc; - public int MediaWidth; - public int MediaHeight; - public byte MediaLoop; - - public override int Length - { - get - { - int length = 11; - if (MediaType != null) { length += MediaType.Length; } - if (MediaDesc != null) { length += MediaDesc.Length; } - return length; - } - } - - public DataBlockExtendedBlock() { } - public DataBlockExtendedBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - length = bytes[i++]; - MediaType = new byte[length]; - Buffer.BlockCopy(bytes, i, MediaType, 0, length); i += length; - length = bytes[i++]; - MediaDesc = new byte[length]; - Buffer.BlockCopy(bytes, i, MediaDesc, 0, length); i += length; - MediaWidth = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - MediaHeight = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - MediaLoop = (byte)bytes[i++]; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - bytes[i++] = (byte)MediaType.Length; - Buffer.BlockCopy(MediaType, 0, bytes, i, MediaType.Length); i += MediaType.Length; - bytes[i++] = (byte)MediaDesc.Length; - Buffer.BlockCopy(MediaDesc, 0, bytes, i, MediaDesc.Length); i += MediaDesc.Length; - Utils.IntToBytes(MediaWidth, bytes, i); i += 4; - Utils.IntToBytes(MediaHeight, bytes, i); i += 4; - bytes[i++] = MediaLoop; - } - - } - - public override int Length - { - get - { - int length = 10; - length += DataBlock.Length; - length += DataBlockExtended.Length; - return length; - } - } - public DataBlockBlock DataBlock; - public DataBlockExtendedBlock DataBlockExtended; - - public ParcelMediaUpdatePacket() - { - HasVariableBlocks = false; - Type = PacketType.ParcelMediaUpdate; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 420; - Header.Reliable = true; - DataBlock = new DataBlockBlock(); - DataBlockExtended = new DataBlockExtendedBlock(); - } - - public ParcelMediaUpdatePacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - DataBlock.FromBytes(bytes, ref i); - DataBlockExtended.FromBytes(bytes, ref i); - } - - public ParcelMediaUpdatePacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - DataBlock.FromBytes(bytes, ref i); - DataBlockExtended.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += DataBlock.Length; - length += DataBlockExtended.Length; - if (Header.AckList != null && 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); - DataBlockExtended.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class LandStatRequestPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class RequestDataBlock : PacketBlock - { - public uint ReportType; - public uint RequestFlags; - public byte[] Filter; - public int ParcelLocalID; - - public override int Length - { - get - { - int length = 13; - if (Filter != null) { length += Filter.Length; } - return length; - } - } - - public RequestDataBlock() { } - public RequestDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - ReportType = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - RequestFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - length = bytes[i++]; - Filter = new byte[length]; - Buffer.BlockCopy(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(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UIntToBytes(ReportType, bytes, i); i += 4; - Utils.UIntToBytes(RequestFlags, bytes, i); i += 4; - bytes[i++] = (byte)Filter.Length; - Buffer.BlockCopy(Filter, 0, bytes, i, Filter.Length); i += Filter.Length; - Utils.IntToBytes(ParcelLocalID, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += RequestData.Length; - return length; - } - } - public AgentDataBlock AgentData; - public RequestDataBlock RequestData; - - public LandStatRequestPacket() - { - HasVariableBlocks = false; - Type = PacketType.LandStatRequest; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 421; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - RequestData = new RequestDataBlock(); - } - - public LandStatRequestPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - RequestData.FromBytes(bytes, ref i); - } - - public LandStatRequestPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - RequestData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += RequestData.Length; - if (Header.AckList != null && 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); - RequestData.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class LandStatReplyPacket : Packet - { - /// - public sealed class RequestDataBlock : PacketBlock - { - public uint ReportType; - public uint RequestFlags; - public uint TotalObjectCount; - - public override int Length - { - get - { - return 12; - } - } - - public RequestDataBlock() { } - public RequestDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - ReportType = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - RequestFlags = (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(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UIntToBytes(ReportType, bytes, i); i += 4; - Utils.UIntToBytes(RequestFlags, bytes, i); i += 4; - Utils.UIntToBytes(TotalObjectCount, bytes, i); i += 4; - } - - } - - /// - public sealed class ReportDataBlock : PacketBlock - { - public uint TaskLocalID; - public UUID TaskID; - public float LocationX; - public float LocationY; - public float LocationZ; - public float Score; - public byte[] TaskName; - public byte[] OwnerName; - - public override int Length - { - get - { - int length = 38; - if (TaskName != null) { length += TaskName.Length; } - if (OwnerName != null) { length += OwnerName.Length; } - return length; - } - } - - public ReportDataBlock() { } - public ReportDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - TaskLocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - TaskID.FromBytes(bytes, i); i += 16; - LocationX = Utils.BytesToFloat(bytes, i); i += 4; - LocationY = Utils.BytesToFloat(bytes, i); i += 4; - LocationZ = Utils.BytesToFloat(bytes, i); i += 4; - Score = Utils.BytesToFloat(bytes, i); i += 4; - length = bytes[i++]; - TaskName = new byte[length]; - Buffer.BlockCopy(bytes, i, TaskName, 0, length); i += length; - length = bytes[i++]; - OwnerName = new byte[length]; - Buffer.BlockCopy(bytes, i, OwnerName, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UIntToBytes(TaskLocalID, bytes, i); i += 4; - TaskID.ToBytes(bytes, i); i += 16; - Utils.FloatToBytes(LocationX, bytes, i); i += 4; - Utils.FloatToBytes(LocationY, bytes, i); i += 4; - Utils.FloatToBytes(LocationZ, bytes, i); i += 4; - Utils.FloatToBytes(Score, bytes, i); i += 4; - bytes[i++] = (byte)TaskName.Length; - Buffer.BlockCopy(TaskName, 0, bytes, i, TaskName.Length); i += TaskName.Length; - bytes[i++] = (byte)OwnerName.Length; - Buffer.BlockCopy(OwnerName, 0, bytes, i, OwnerName.Length); i += OwnerName.Length; - } - - } - - public override int Length - { - get - { - int length = 11; - length += RequestData.Length; - for (int j = 0; j < ReportData.Length; j++) - length += ReportData[j].Length; - return length; - } - } - public RequestDataBlock RequestData; - public ReportDataBlock[] ReportData; - - public LandStatReplyPacket() - { - HasVariableBlocks = true; - Type = PacketType.LandStatReply; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 422; - Header.Reliable = true; - RequestData = new RequestDataBlock(); - ReportData = null; - } - - public LandStatReplyPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - RequestData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ReportData == null || ReportData.Length != -1) { - ReportData = new ReportDataBlock[count]; - for(int j = 0; j < count; j++) - { ReportData[j] = new ReportDataBlock(); } - } - for (int j = 0; j < count; j++) - { ReportData[j].FromBytes(bytes, ref i); } - } - - public LandStatReplyPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - RequestData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ReportData == null || ReportData.Length != count) { - ReportData = new ReportDataBlock[count]; - for(int j = 0; j < count; j++) - { ReportData[j] = new ReportDataBlock(); } - } - for (int j = 0; j < count; j++) - { ReportData[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += RequestData.Length; - length++; - for (int j = 0; j < ReportData.Length; j++) { length += ReportData[j].Length; } - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += RequestData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - RequestData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int ReportDataStart = 0; - do - { - int variableLength = 0; - int ReportDataCount = 0; - - i = ReportDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < ReportData.Length) { - int blockLength = ReportData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ReportDataStart) { - variableLength += blockLength; - ++ReportDataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)ReportDataCount; - for (i = ReportDataStart; i < ReportDataStart + ReportDataCount; i++) { ReportData[i].ToBytes(packet, ref length); } - ReportDataStart += ReportDataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - ReportDataStart < ReportData.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class ErrorPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - - public override int Length - { - get - { - return 16; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class DataBlock : PacketBlock - { - public int Code; - public byte[] Token; - public UUID ID; - public byte[] System; - public byte[] Message; - public byte[] Data; - - public override int Length - { - get - { - int length = 26; - if (Token != null) { length += Token.Length; } - if (System != null) { length += System.Length; } - if (Message != null) { length += Message.Length; } - if (Data != null) { length += Data.Length; } - return length; - } - } - - public DataBlock() { } - public DataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - Code = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - length = bytes[i++]; - Token = new byte[length]; - Buffer.BlockCopy(bytes, i, Token, 0, length); i += length; - ID.FromBytes(bytes, i); i += 16; - length = bytes[i++]; - System = new byte[length]; - Buffer.BlockCopy(bytes, i, System, 0, length); i += length; - length = (bytes[i++] + (bytes[i++] << 8)); - Message = new byte[length]; - Buffer.BlockCopy(bytes, i, Message, 0, length); i += length; - length = (bytes[i++] + (bytes[i++] << 8)); - Data = new byte[length]; - Buffer.BlockCopy(bytes, i, Data, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.IntToBytes(Code, bytes, i); i += 4; - bytes[i++] = (byte)Token.Length; - Buffer.BlockCopy(Token, 0, bytes, i, Token.Length); i += Token.Length; - ID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)System.Length; - Buffer.BlockCopy(System, 0, bytes, i, System.Length); i += System.Length; - bytes[i++] = (byte)(Message.Length % 256); - bytes[i++] = (byte)((Message.Length >> 8) % 256); - Buffer.BlockCopy(Message, 0, bytes, i, Message.Length); i += Message.Length; - bytes[i++] = (byte)(Data.Length % 256); - bytes[i++] = (byte)((Data.Length >> 8) % 256); - Buffer.BlockCopy(Data, 0, bytes, i, Data.Length); i += Data.Length; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += Data.Length; - return length; - } - } - public AgentDataBlock AgentData; - public DataBlock Data; - - public ErrorPacket() - { - HasVariableBlocks = false; - Type = PacketType.Error; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 423; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - Data = new DataBlock(); - } - - public ErrorPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - Data.FromBytes(bytes, ref i); - } - - public ErrorPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - Data.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += Data.Length; - if (Header.AckList != null && 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); - Data.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class ObjectIncludeInSearchPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class ObjectDataBlock : PacketBlock - { - public uint ObjectLocalID; - public bool IncludeInSearch; - - public override int Length - { - get - { - return 5; - } - } - - public ObjectDataBlock() { } - public ObjectDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - ObjectLocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - IncludeInSearch = (bytes[i++] != 0) ? (bool)true : (bool)false; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UIntToBytes(ObjectLocalID, bytes, i); i += 4; - bytes[i++] = (byte)((IncludeInSearch) ? 1 : 0); - } - - } - - public override int Length - { - get - { - int length = 11; - length += AgentData.Length; - for (int j = 0; j < ObjectData.Length; j++) - length += ObjectData[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public ObjectDataBlock[] ObjectData; - - public ObjectIncludeInSearchPacket() - { - HasVariableBlocks = true; - Type = PacketType.ObjectIncludeInSearch; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 424; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - ObjectData = null; - } - - public ObjectIncludeInSearchPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ObjectData == null || ObjectData.Length != -1) { - ObjectData = new ObjectDataBlock[count]; - for(int j = 0; j < count; j++) - { ObjectData[j] = new ObjectDataBlock(); } - } - for (int j = 0; j < count; j++) - { ObjectData[j].FromBytes(bytes, ref i); } - } - - public ObjectIncludeInSearchPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ObjectData == null || ObjectData.Length != count) { - ObjectData = new ObjectDataBlock[count]; - for(int j = 0; j < count; j++) - { ObjectData[j] = new ObjectDataBlock(); } - } - for (int j = 0; j < count; j++) - { ObjectData[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length++; - for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } - if (Header.AckList != null && 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)ObjectData.Length; - for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int ObjectDataStart = 0; - do - { - int variableLength = 0; - int ObjectDataCount = 0; - - i = ObjectDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < ObjectData.Length) { - int blockLength = ObjectData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ObjectDataStart) { - variableLength += blockLength; - ++ObjectDataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)ObjectDataCount; - for (i = ObjectDataStart; i < ObjectDataStart + ObjectDataCount; i++) { ObjectData[i].ToBytes(packet, ref length); } - ObjectDataStart += ObjectDataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - ObjectDataStart < ObjectData.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class RezRestoreToWorldPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class InventoryDataBlock : PacketBlock - { - public UUID ItemID; - public UUID FolderID; - public UUID CreatorID; - public UUID OwnerID; - public UUID GroupID; - public uint BaseMask; - public uint OwnerMask; - public uint GroupMask; - public uint EveryoneMask; - public uint NextOwnerMask; - public bool GroupOwned; - public UUID TransactionID; - public sbyte Type; - public sbyte InvType; - public uint Flags; - public byte SaleType; - public int SalePrice; - public byte[] Name; - public byte[] Description; - public int CreationDate; - public uint CRC; - - public override int Length - { - get - { - int length = 138; - if (Name != null) { length += Name.Length; } - if (Description != null) { length += Description.Length; } - return length; - } - } - - public InventoryDataBlock() { } - public InventoryDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - ItemID.FromBytes(bytes, i); i += 16; - FolderID.FromBytes(bytes, i); i += 16; - CreatorID.FromBytes(bytes, i); i += 16; - OwnerID.FromBytes(bytes, i); i += 16; - GroupID.FromBytes(bytes, i); i += 16; - BaseMask = (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)); - GroupMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - 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)); - GroupOwned = (bytes[i++] != 0) ? (bool)true : (bool)false; - TransactionID.FromBytes(bytes, i); i += 16; - Type = (sbyte)bytes[i++]; - InvType = (sbyte)bytes[i++]; - Flags = (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)); - length = bytes[i++]; - Name = new byte[length]; - Buffer.BlockCopy(bytes, i, Name, 0, length); i += length; - length = bytes[i++]; - Description = new byte[length]; - Buffer.BlockCopy(bytes, i, Description, 0, length); i += length; - CreationDate = (int)(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(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - ItemID.ToBytes(bytes, i); i += 16; - FolderID.ToBytes(bytes, i); i += 16; - CreatorID.ToBytes(bytes, i); i += 16; - OwnerID.ToBytes(bytes, i); i += 16; - GroupID.ToBytes(bytes, i); i += 16; - Utils.UIntToBytes(BaseMask, bytes, i); i += 4; - Utils.UIntToBytes(OwnerMask, bytes, i); i += 4; - Utils.UIntToBytes(GroupMask, bytes, i); i += 4; - Utils.UIntToBytes(EveryoneMask, bytes, i); i += 4; - Utils.UIntToBytes(NextOwnerMask, bytes, i); i += 4; - bytes[i++] = (byte)((GroupOwned) ? 1 : 0); - TransactionID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)Type; - bytes[i++] = (byte)InvType; - Utils.UIntToBytes(Flags, bytes, i); i += 4; - bytes[i++] = SaleType; - Utils.IntToBytes(SalePrice, bytes, i); i += 4; - bytes[i++] = (byte)Name.Length; - Buffer.BlockCopy(Name, 0, bytes, i, Name.Length); i += Name.Length; - bytes[i++] = (byte)Description.Length; - Buffer.BlockCopy(Description, 0, bytes, i, Description.Length); i += Description.Length; - Utils.IntToBytes(CreationDate, bytes, i); i += 4; - Utils.UIntToBytes(CRC, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += InventoryData.Length; - return length; - } - } - public AgentDataBlock AgentData; - public InventoryDataBlock InventoryData; - - public RezRestoreToWorldPacket() - { - HasVariableBlocks = false; - Type = PacketType.RezRestoreToWorld; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 425; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - InventoryData = new InventoryDataBlock(); - } - - public RezRestoreToWorldPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - InventoryData.FromBytes(bytes, ref i); - } - - public RezRestoreToWorldPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - InventoryData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += InventoryData.Length; - if (Header.AckList != null && 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); - InventoryData.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class LinkInventoryItemPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class InventoryBlockBlock : PacketBlock - { - public uint CallbackID; - public UUID FolderID; - public UUID TransactionID; - public UUID OldItemID; - public sbyte Type; - public sbyte InvType; - public byte[] Name; - public byte[] Description; - - public override int Length - { - get - { - int length = 56; - if (Name != null) { length += Name.Length; } - if (Description != null) { length += Description.Length; } - return length; - } - } - - public InventoryBlockBlock() { } - public InventoryBlockBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - CallbackID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - FolderID.FromBytes(bytes, i); i += 16; - TransactionID.FromBytes(bytes, i); i += 16; - OldItemID.FromBytes(bytes, i); i += 16; - Type = (sbyte)bytes[i++]; - InvType = (sbyte)bytes[i++]; - length = bytes[i++]; - Name = new byte[length]; - Buffer.BlockCopy(bytes, i, Name, 0, length); i += length; - length = bytes[i++]; - Description = new byte[length]; - Buffer.BlockCopy(bytes, i, Description, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UIntToBytes(CallbackID, bytes, i); i += 4; - FolderID.ToBytes(bytes, i); i += 16; - TransactionID.ToBytes(bytes, i); i += 16; - OldItemID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)Type; - bytes[i++] = (byte)InvType; - bytes[i++] = (byte)Name.Length; - Buffer.BlockCopy(Name, 0, bytes, i, Name.Length); i += Name.Length; - bytes[i++] = (byte)Description.Length; - Buffer.BlockCopy(Description, 0, bytes, i, Description.Length); i += Description.Length; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += InventoryBlock.Length; - return length; - } - } - public AgentDataBlock AgentData; - public InventoryBlockBlock InventoryBlock; - - public LinkInventoryItemPacket() - { - HasVariableBlocks = false; - Type = PacketType.LinkInventoryItem; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 426; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - InventoryBlock = new InventoryBlockBlock(); - } - - public LinkInventoryItemPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - InventoryBlock.FromBytes(bytes, ref i); - } - - public LinkInventoryItemPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - InventoryBlock.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += InventoryBlock.Length; - if (Header.AckList != null && 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); - InventoryBlock.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class RetrieveIMsExtendedPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - public bool IsPremium; - - public override int Length - { - get - { - return 33; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - IsPremium = (bytes[i++] != 0) ? (bool)true : (bool)false; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)((IsPremium) ? 1 : 0); - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - return length; - } - } - public AgentDataBlock AgentData; - - public RetrieveIMsExtendedPacket() - { - HasVariableBlocks = false; - Type = PacketType.RetrieveIMsExtended; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 427; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - } - - public RetrieveIMsExtendedPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - } - - public RetrieveIMsExtendedPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class JoinGroupRequestExtendedPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - public int GroupLimit; - - public override int Length - { - get - { - return 36; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - GroupLimit = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - Utils.IntToBytes(GroupLimit, bytes, i); i += 4; - } - - } - - /// - public sealed class GroupDataBlock : PacketBlock - { - public UUID GroupID; - - public override int Length - { - get - { - return 16; - } - } - - public GroupDataBlock() { } - public GroupDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - GroupID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - GroupID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += GroupData.Length; - return length; - } - } - public AgentDataBlock AgentData; - public GroupDataBlock GroupData; - - public JoinGroupRequestExtendedPacket() - { - HasVariableBlocks = false; - Type = PacketType.JoinGroupRequestExtended; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 428; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - GroupData = new GroupDataBlock(); - } - - public JoinGroupRequestExtendedPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - GroupData.FromBytes(bytes, ref i); - } - - public JoinGroupRequestExtendedPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - GroupData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += GroupData.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class CreateGroupRequestExtendedPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - public int GroupLimit; - - public override int Length - { - get - { - return 36; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - GroupLimit = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - Utils.IntToBytes(GroupLimit, bytes, i); i += 4; - } - - } - - /// - public sealed class GroupDataBlock : PacketBlock - { - public byte[] Name; - public byte[] Charter; - public bool ShowInList; - public UUID InsigniaID; - public int MembershipFee; - public bool OpenEnrollment; - public bool AllowPublish; - public bool MaturePublish; - - public override int Length - { - get - { - int length = 27; - if (Name != null) { length += Name.Length; } - if (Charter != null) { length += Charter.Length; } - return length; - } - } - - public GroupDataBlock() { } - public GroupDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - length = bytes[i++]; - Name = new byte[length]; - Buffer.BlockCopy(bytes, i, Name, 0, length); i += length; - length = (bytes[i++] + (bytes[i++] << 8)); - Charter = new byte[length]; - Buffer.BlockCopy(bytes, i, Charter, 0, length); i += length; - ShowInList = (bytes[i++] != 0) ? (bool)true : (bool)false; - InsigniaID.FromBytes(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; - AllowPublish = (bytes[i++] != 0) ? (bool)true : (bool)false; - MaturePublish = (bytes[i++] != 0) ? (bool)true : (bool)false; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - bytes[i++] = (byte)Name.Length; - Buffer.BlockCopy(Name, 0, bytes, i, Name.Length); i += Name.Length; - bytes[i++] = (byte)(Charter.Length % 256); - bytes[i++] = (byte)((Charter.Length >> 8) % 256); - Buffer.BlockCopy(Charter, 0, bytes, i, Charter.Length); i += Charter.Length; - bytes[i++] = (byte)((ShowInList) ? 1 : 0); - InsigniaID.ToBytes(bytes, i); i += 16; - Utils.IntToBytes(MembershipFee, bytes, i); i += 4; - bytes[i++] = (byte)((OpenEnrollment) ? 1 : 0); - bytes[i++] = (byte)((AllowPublish) ? 1 : 0); - bytes[i++] = (byte)((MaturePublish) ? 1 : 0); - } - - } - - public override int Length - { - get - { - int length = 10; - length += AgentData.Length; - length += GroupData.Length; - return length; - } - } - public AgentDataBlock AgentData; - public GroupDataBlock GroupData; - - public CreateGroupRequestExtendedPacket() - { - HasVariableBlocks = false; - Type = PacketType.CreateGroupRequestExtended; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 429; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - GroupData = new GroupDataBlock(); - } - - public CreateGroupRequestExtendedPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - GroupData.FromBytes(bytes, ref i); - } - - public CreateGroupRequestExtendedPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - GroupData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += AgentData.Length; - length += GroupData.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class PacketAckPacket : Packet - { - public override bool UsesBufferPooling - { - get - { - return true; - } - } - - /// - public sealed class PacketsBlock : PacketBlock - { - public uint ID; - - public override int Length - { - get - { - return 4; - } - } - - public PacketsBlock() { } - public PacketsBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - ID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UIntToBytes(ID, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 11; - for (int j = 0; j < Packets.Length; j++) - length += Packets[j].Length; - return length; - } - } - public PacketsBlock[] Packets; - - public PacketAckPacket() - { - HasVariableBlocks = true; - Type = PacketType.PacketAck; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 65531; - Header.Reliable = true; - Packets = null; - } - - public PacketAckPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - int count = (int)bytes[i++]; - if(Packets == null || Packets.Length != -1) { - Packets = new PacketsBlock[count]; - for(int j = 0; j < count; j++) - { Packets[j] = new PacketsBlock(); } - } - for (int j = 0; j < count; j++) - { Packets[j].FromBytes(bytes, ref i); } - } - - public PacketAckPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - int count = (int)bytes[i++]; - if(Packets == null || Packets.Length != count) { - Packets = new PacketsBlock[count]; - for(int j = 0; j < count; j++) - { Packets[j] = new PacketsBlock(); } - } - for (int j = 0; j < count; j++) - { Packets[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 10; - length++; - for (int j = 0; j < Packets.Length; j++) { length += Packets[j].Length; } - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int PacketsStart = 0; - do - { - int variableLength = 0; - int PacketsCount = 0; - - i = PacketsStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < Packets.Length) { - int blockLength = Packets[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == PacketsStart) { - variableLength += blockLength; - ++PacketsCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)PacketsCount; - for (i = PacketsStart; i < PacketsStart + PacketsCount; i++) { Packets[i].ToBytes(packet, ref length); } - PacketsStart += PacketsCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - PacketsStart < Packets.Length); - - return packets.ToArray(); - } - - public override byte[] ToBytes(Interfaces.IByteBufferPool pool, ref int size) - { - int length = 10; - length++; - for (int j = 0; j < Packets.Length; j++) { length += Packets[j].Length; } - if (Header.AckList != null && Header.AckList.Length > 0) { length += Header.AckList.Length * 4 + 1; } - byte[] bytes = pool.LeaseBytes(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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - - size = length; - return bytes; - } - - public override byte[][] ToBytesMultiple(Interfaces.IByteBufferPool pool, out int[] sizes) - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - System.Collections.Generic.List retSizes = new System.Collections.Generic.List(); - - int i = 0; - int fixedLength = 10; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) - { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int PacketsStart = 0; - do - { - int variableLength = 0; - int PacketsCount = 0; - - i = PacketsStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < Packets.Length) - { - int blockLength = Packets[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU) - { - variableLength += blockLength; - ++PacketsCount; - } - else { break; } - ++i; - } - - int packetSize = fixedLength + variableLength + acksLength; - byte[] packet = pool.LeaseBytes(packetSize); - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)PacketsCount; - for (i = PacketsStart; i < PacketsStart + PacketsCount; i++) { Packets[i].ToBytes(packet, ref length); } - PacketsStart += PacketsCount; - - if (acksLength > 0) - { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - retSizes.Add(packetSize); - packets.Add(packet); - } while ( - PacketsStart < Packets.Length); - - sizes = retSizes.ToArray(); - return packets.ToArray(); - } - - } - - /// - public sealed class OpenCircuitPacket : Packet - { - /// - public sealed class CircuitInfoBlock : PacketBlock - { - public uint IP; - public ushort Port; - - public override int Length - { - get - { - return 6; - } - } - - public CircuitInfoBlock() { } - public CircuitInfoBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(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(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UIntToBytes(IP, bytes, i); i += 4; - bytes[i++] = (byte)((Port >> 8) % 256); - bytes[i++] = (byte)(Port % 256); - } - - } - - public override int Length - { - get - { - int length = 10; - length += CircuitInfo.Length; - return length; - } - } - public CircuitInfoBlock CircuitInfo; - - public OpenCircuitPacket() - { - HasVariableBlocks = false; - Type = PacketType.OpenCircuit; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 65532; - Header.Reliable = true; - CircuitInfo = new CircuitInfoBlock(); - } - - public OpenCircuitPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - CircuitInfo.FromBytes(bytes, ref i); - } - - public OpenCircuitPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - CircuitInfo.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 10; - length += CircuitInfo.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class CloseCircuitPacket : Packet - { - public override int Length - { - get - { - int length = 10; - return length; - } - } - - public CloseCircuitPacket() - { - HasVariableBlocks = false; - Type = PacketType.CloseCircuit; - Header = new Header(); - Header.Frequency = PacketFrequency.Low; - Header.ID = 65533; - Header.Reliable = true; - } - - public CloseCircuitPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - } - - public CloseCircuitPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - } - - public override byte[] ToBytes() - { - int length = 10; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class ObjectAddPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - public UUID GroupID; - - public override int Length - { - get - { - return 48; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - GroupID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - GroupID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class ObjectDataBlock : PacketBlock - { - public byte PCode; - public byte Material; - public uint AddFlags; - public byte PathCurve; - public byte ProfileCurve; - public ushort PathBegin; - public ushort PathEnd; - public byte PathScaleX; - public byte PathScaleY; - public byte PathShearX; - public byte PathShearY; - public sbyte PathTwist; - public sbyte PathTwistBegin; - public sbyte PathRadiusOffset; - public sbyte PathTaperX; - public sbyte PathTaperY; - public byte PathRevolutions; - public sbyte PathSkew; - public ushort ProfileBegin; - public ushort ProfileEnd; - public ushort ProfileHollow; - public byte BypassRaycast; - public Vector3 RayStart; - public Vector3 RayEnd; - public UUID RayTargetID; - public byte RayEndIsIntersection; - public Vector3 Scale; - public Quaternion Rotation; - public byte State; - - public override int Length - { - get - { - return 96; - } - } - - public ObjectDataBlock() { } - public ObjectDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - PCode = (byte)bytes[i++]; - Material = (byte)bytes[i++]; - AddFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - PathCurve = (byte)bytes[i++]; - ProfileCurve = (byte)bytes[i++]; - PathBegin = (ushort)(bytes[i++] + (bytes[i++] << 8)); - PathEnd = (ushort)(bytes[i++] + (bytes[i++] << 8)); - PathScaleX = (byte)bytes[i++]; - PathScaleY = (byte)bytes[i++]; - PathShearX = (byte)bytes[i++]; - PathShearY = (byte)bytes[i++]; - PathTwist = (sbyte)bytes[i++]; - PathTwistBegin = (sbyte)bytes[i++]; - PathRadiusOffset = (sbyte)bytes[i++]; - PathTaperX = (sbyte)bytes[i++]; - PathTaperY = (sbyte)bytes[i++]; - PathRevolutions = (byte)bytes[i++]; - PathSkew = (sbyte)bytes[i++]; - ProfileBegin = (ushort)(bytes[i++] + (bytes[i++] << 8)); - ProfileEnd = (ushort)(bytes[i++] + (bytes[i++] << 8)); - ProfileHollow = (ushort)(bytes[i++] + (bytes[i++] << 8)); - BypassRaycast = (byte)bytes[i++]; - RayStart.FromBytes(bytes, i); i += 12; - RayEnd.FromBytes(bytes, i); i += 12; - RayTargetID.FromBytes(bytes, i); i += 16; - RayEndIsIntersection = (byte)bytes[i++]; - Scale.FromBytes(bytes, i); i += 12; - Rotation.FromBytes(bytes, i, true); i += 12; - State = (byte)bytes[i++]; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - bytes[i++] = PCode; - bytes[i++] = Material; - Utils.UIntToBytes(AddFlags, bytes, i); i += 4; - bytes[i++] = PathCurve; - bytes[i++] = ProfileCurve; - bytes[i++] = (byte)(PathBegin % 256); - bytes[i++] = (byte)((PathBegin >> 8) % 256); - bytes[i++] = (byte)(PathEnd % 256); - bytes[i++] = (byte)((PathEnd >> 8) % 256); - bytes[i++] = PathScaleX; - bytes[i++] = PathScaleY; - bytes[i++] = PathShearX; - bytes[i++] = PathShearY; - bytes[i++] = (byte)PathTwist; - bytes[i++] = (byte)PathTwistBegin; - bytes[i++] = (byte)PathRadiusOffset; - bytes[i++] = (byte)PathTaperX; - bytes[i++] = (byte)PathTaperY; - bytes[i++] = PathRevolutions; - bytes[i++] = (byte)PathSkew; - bytes[i++] = (byte)(ProfileBegin % 256); - bytes[i++] = (byte)((ProfileBegin >> 8) % 256); - bytes[i++] = (byte)(ProfileEnd % 256); - bytes[i++] = (byte)((ProfileEnd >> 8) % 256); - bytes[i++] = (byte)(ProfileHollow % 256); - bytes[i++] = (byte)((ProfileHollow >> 8) % 256); - bytes[i++] = BypassRaycast; - RayStart.ToBytes(bytes, i); i += 12; - RayEnd.ToBytes(bytes, i); i += 12; - RayTargetID.ToBytes(bytes, i); i += 16; - bytes[i++] = RayEndIsIntersection; - Scale.ToBytes(bytes, i); i += 12; - Rotation.ToBytes(bytes, i); i += 12; - bytes[i++] = State; - } - - } - - public override int Length - { - get - { - int length = 8; - length += AgentData.Length; - length += ObjectData.Length; - return length; - } - } - public AgentDataBlock AgentData; - public ObjectDataBlock ObjectData; - - public ObjectAddPacket() - { - HasVariableBlocks = false; - Type = PacketType.ObjectAdd; - Header = new Header(); - Header.Frequency = PacketFrequency.Medium; - Header.ID = 1; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - ObjectData = new ObjectDataBlock(); - } - - public ObjectAddPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - ObjectData.FromBytes(bytes, ref i); - } - - public ObjectAddPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - ObjectData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 8; - length += AgentData.Length; - length += ObjectData.Length; - if (Header.AckList != null && 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); - ObjectData.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class MultipleObjectUpdatePacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class ObjectDataBlock : PacketBlock - { - public uint ObjectLocalID; - public byte Type; - public byte[] Data; - - public override int Length - { - get - { - int length = 6; - if (Data != null) { length += Data.Length; } - return length; - } - } - - public ObjectDataBlock() { } - public ObjectDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - ObjectLocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - Type = (byte)bytes[i++]; - length = bytes[i++]; - Data = new byte[length]; - Buffer.BlockCopy(bytes, i, Data, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UIntToBytes(ObjectLocalID, bytes, i); i += 4; - bytes[i++] = Type; - bytes[i++] = (byte)Data.Length; - Buffer.BlockCopy(Data, 0, bytes, i, Data.Length); i += Data.Length; - } - - } - - public override int Length - { - get - { - int length = 9; - length += AgentData.Length; - for (int j = 0; j < ObjectData.Length; j++) - length += ObjectData[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public ObjectDataBlock[] ObjectData; - - public MultipleObjectUpdatePacket() - { - HasVariableBlocks = true; - Type = PacketType.MultipleObjectUpdate; - Header = new Header(); - Header.Frequency = PacketFrequency.Medium; - Header.ID = 2; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - ObjectData = null; - } - - public MultipleObjectUpdatePacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ObjectData == null || ObjectData.Length != -1) { - ObjectData = new ObjectDataBlock[count]; - for(int j = 0; j < count; j++) - { ObjectData[j] = new ObjectDataBlock(); } - } - for (int j = 0; j < count; j++) - { ObjectData[j].FromBytes(bytes, ref i); } - } - - public MultipleObjectUpdatePacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ObjectData == null || ObjectData.Length != count) { - ObjectData = new ObjectDataBlock[count]; - for(int j = 0; j < count; j++) - { ObjectData[j] = new ObjectDataBlock(); } - } - for (int j = 0; j < count; j++) - { ObjectData[j].FromBytes(bytes, ref i); } - } - - 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 != null && 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)ObjectData.Length; - for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 8; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int ObjectDataStart = 0; - do - { - int variableLength = 0; - int ObjectDataCount = 0; - - i = ObjectDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < ObjectData.Length) { - int blockLength = ObjectData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ObjectDataStart) { - variableLength += blockLength; - ++ObjectDataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)ObjectDataCount; - for (i = ObjectDataStart; i < ObjectDataStart + ObjectDataCount; i++) { ObjectData[i].ToBytes(packet, ref length); } - ObjectDataStart += ObjectDataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - ObjectDataStart < ObjectData.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class RequestMultipleObjectsPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class ObjectDataBlock : PacketBlock - { - public byte CacheMissType; - public uint ID; - - public override int Length - { - get - { - return 5; - } - } - - public ObjectDataBlock() { } - public ObjectDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - CacheMissType = (byte)bytes[i++]; - ID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - bytes[i++] = CacheMissType; - Utils.UIntToBytes(ID, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 9; - length += AgentData.Length; - for (int j = 0; j < ObjectData.Length; j++) - length += ObjectData[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public ObjectDataBlock[] ObjectData; - - public RequestMultipleObjectsPacket() - { - HasVariableBlocks = true; - Type = PacketType.RequestMultipleObjects; - Header = new Header(); - Header.Frequency = PacketFrequency.Medium; - Header.ID = 3; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - ObjectData = null; - } - - public RequestMultipleObjectsPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ObjectData == null || ObjectData.Length != -1) { - ObjectData = new ObjectDataBlock[count]; - for(int j = 0; j < count; j++) - { ObjectData[j] = new ObjectDataBlock(); } - } - for (int j = 0; j < count; j++) - { ObjectData[j].FromBytes(bytes, ref i); } - } - - public RequestMultipleObjectsPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ObjectData == null || ObjectData.Length != count) { - ObjectData = new ObjectDataBlock[count]; - for(int j = 0; j < count; j++) - { ObjectData[j] = new ObjectDataBlock(); } - } - for (int j = 0; j < count; j++) - { ObjectData[j].FromBytes(bytes, ref i); } - } - - 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 != null && 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)ObjectData.Length; - for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 8; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int ObjectDataStart = 0; - do - { - int variableLength = 0; - int ObjectDataCount = 0; - - i = ObjectDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < ObjectData.Length) { - int blockLength = ObjectData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ObjectDataStart) { - variableLength += blockLength; - ++ObjectDataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)ObjectDataCount; - for (i = ObjectDataStart; i < ObjectDataStart + ObjectDataCount; i++) { ObjectData[i].ToBytes(packet, ref length); } - ObjectDataStart += ObjectDataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - ObjectDataStart < ObjectData.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class ObjectPositionPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class ObjectDataBlock : PacketBlock - { - public uint ObjectLocalID; - public Vector3 Position; - - public override int Length - { - get - { - return 16; - } - } - - public ObjectDataBlock() { } - public ObjectDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - ObjectLocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - Position.FromBytes(bytes, i); i += 12; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UIntToBytes(ObjectLocalID, bytes, i); i += 4; - Position.ToBytes(bytes, i); i += 12; - } - - } - - public override int Length - { - get - { - int length = 9; - length += AgentData.Length; - for (int j = 0; j < ObjectData.Length; j++) - length += ObjectData[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public ObjectDataBlock[] ObjectData; - - public ObjectPositionPacket() - { - HasVariableBlocks = true; - Type = PacketType.ObjectPosition; - Header = new Header(); - Header.Frequency = PacketFrequency.Medium; - Header.ID = 4; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - ObjectData = null; - } - - public ObjectPositionPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ObjectData == null || ObjectData.Length != -1) { - ObjectData = new ObjectDataBlock[count]; - for(int j = 0; j < count; j++) - { ObjectData[j] = new ObjectDataBlock(); } - } - for (int j = 0; j < count; j++) - { ObjectData[j].FromBytes(bytes, ref i); } - } - - public ObjectPositionPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ObjectData == null || ObjectData.Length != count) { - ObjectData = new ObjectDataBlock[count]; - for(int j = 0; j < count; j++) - { ObjectData[j] = new ObjectDataBlock(); } - } - for (int j = 0; j < count; j++) - { ObjectData[j].FromBytes(bytes, ref i); } - } - - 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 != null && 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)ObjectData.Length; - for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 8; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int ObjectDataStart = 0; - do - { - int variableLength = 0; - int ObjectDataCount = 0; - - i = ObjectDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < ObjectData.Length) { - int blockLength = ObjectData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ObjectDataStart) { - variableLength += blockLength; - ++ObjectDataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)ObjectDataCount; - for (i = ObjectDataStart; i < ObjectDataStart + ObjectDataCount; i++) { ObjectData[i].ToBytes(packet, ref length); } - ObjectDataStart += ObjectDataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - ObjectDataStart < ObjectData.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class RequestObjectPropertiesFamilyPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class ObjectDataBlock : PacketBlock - { - public uint RequestFlags; - public UUID ObjectID; - - public override int Length - { - get - { - return 20; - } - } - - public ObjectDataBlock() { } - public ObjectDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - RequestFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - ObjectID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UIntToBytes(RequestFlags, bytes, i); i += 4; - ObjectID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 8; - length += AgentData.Length; - length += ObjectData.Length; - return length; - } - } - public AgentDataBlock AgentData; - public ObjectDataBlock ObjectData; - - public RequestObjectPropertiesFamilyPacket() - { - HasVariableBlocks = false; - Type = PacketType.RequestObjectPropertiesFamily; - Header = new Header(); - Header.Frequency = PacketFrequency.Medium; - Header.ID = 5; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - ObjectData = new ObjectDataBlock(); - } - - public RequestObjectPropertiesFamilyPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - ObjectData.FromBytes(bytes, ref i); - } - - public RequestObjectPropertiesFamilyPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - ObjectData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 8; - length += AgentData.Length; - length += ObjectData.Length; - if (Header.AckList != null && 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); - ObjectData.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class CoarseLocationUpdatePacket : Packet - { - /// - public sealed class LocationBlock : PacketBlock - { - public byte X; - public byte Y; - public byte Z; - - public override int Length - { - get - { - return 3; - } - } - - public LocationBlock() { } - public LocationBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - X = (byte)bytes[i++]; - Y = (byte)bytes[i++]; - Z = (byte)bytes[i++]; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - bytes[i++] = X; - bytes[i++] = Y; - bytes[i++] = Z; - } - - } - - /// - public sealed class IndexBlock : PacketBlock - { - public short You; - public short Prey; - - public override int Length - { - get - { - return 4; - } - } - - public IndexBlock() { } - public IndexBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(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(); - } - } - - public override 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); - } - - } - - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - - public override int Length - { - get - { - return 16; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 10; - for (int j = 0; j < Location.Length; j++) - length += Location[j].Length; - length += Index.Length; - for (int j = 0; j < AgentData.Length; j++) - length += AgentData[j].Length; - return length; - } - } - public LocationBlock[] Location; - public IndexBlock Index; - public AgentDataBlock[] AgentData; - - public CoarseLocationUpdatePacket() - { - HasVariableBlocks = true; - Type = PacketType.CoarseLocationUpdate; - Header = new Header(); - Header.Frequency = PacketFrequency.Medium; - Header.ID = 6; - Header.Reliable = true; - Location = null; - Index = new IndexBlock(); - AgentData = null; - } - - public CoarseLocationUpdatePacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - int count = (int)bytes[i++]; - if(Location == null || Location.Length != -1) { - Location = new LocationBlock[count]; - for(int j = 0; j < count; j++) - { Location[j] = new LocationBlock(); } - } - for (int j = 0; j < count; j++) - { Location[j].FromBytes(bytes, ref i); } - Index.FromBytes(bytes, ref i); - count = (int)bytes[i++]; - if(AgentData == null || AgentData.Length != -1) { - AgentData = new AgentDataBlock[count]; - for(int j = 0; j < count; j++) - { AgentData[j] = new AgentDataBlock(); } - } - for (int j = 0; j < count; j++) - { AgentData[j].FromBytes(bytes, ref i); } - } - - public CoarseLocationUpdatePacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - int count = (int)bytes[i++]; - if(Location == null || Location.Length != count) { - Location = new LocationBlock[count]; - for(int j = 0; j < count; j++) - { Location[j] = new LocationBlock(); } - } - for (int j = 0; j < count; j++) - { Location[j].FromBytes(bytes, ref i); } - Index.FromBytes(bytes, ref i); - count = (int)bytes[i++]; - if(AgentData == null || AgentData.Length != count) { - AgentData = new AgentDataBlock[count]; - for(int j = 0; j < count; j++) - { AgentData[j] = new AgentDataBlock(); } - } - for (int j = 0; j < count; j++) - { AgentData[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 8; - length += Index.Length; - length++; - for (int j = 0; j < Location.Length; j++) { length += Location[j].Length; } - length++; - for (int j = 0; j < AgentData.Length; j++) { length += AgentData[j].Length; } - if (Header.AckList != null && 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); - bytes[i++] = (byte)AgentData.Length; - for (int j = 0; j < AgentData.Length; j++) { AgentData[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class CrossedRegionPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class RegionDataBlock : PacketBlock - { - public uint SimIP; - public ushort SimPort; - public ulong RegionHandle; - public byte[] SeedCapability; - - public override int Length - { - get - { - int length = 16; - if (SeedCapability != null) { length += SeedCapability.Length; } - return length; - } - } - - public RegionDataBlock() { } - public RegionDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - SimIP = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - 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)); - length = (bytes[i++] + (bytes[i++] << 8)); - SeedCapability = new byte[length]; - Buffer.BlockCopy(bytes, i, SeedCapability, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UIntToBytes(SimIP, bytes, i); i += 4; - bytes[i++] = (byte)((SimPort >> 8) % 256); - bytes[i++] = (byte)(SimPort % 256); - Utils.UInt64ToBytes(RegionHandle, bytes, i); i += 8; - bytes[i++] = (byte)(SeedCapability.Length % 256); - bytes[i++] = (byte)((SeedCapability.Length >> 8) % 256); - Buffer.BlockCopy(SeedCapability, 0, bytes, i, SeedCapability.Length); i += SeedCapability.Length; - } - - } - - /// - public sealed class InfoBlock : PacketBlock - { - public Vector3 Position; - public Vector3 LookAt; - - public override int Length - { - get - { - return 24; - } - } - - public InfoBlock() { } - public InfoBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - Position.FromBytes(bytes, i); i += 12; - LookAt.FromBytes(bytes, i); i += 12; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Position.ToBytes(bytes, i); i += 12; - LookAt.ToBytes(bytes, i); i += 12; - } - - } - - public override int Length - { - get - { - int length = 8; - length += AgentData.Length; - length += RegionData.Length; - length += Info.Length; - return length; - } - } - public AgentDataBlock AgentData; - public RegionDataBlock RegionData; - public InfoBlock Info; - - public CrossedRegionPacket() - { - HasVariableBlocks = false; - Type = PacketType.CrossedRegion; - Header = new Header(); - Header.Frequency = PacketFrequency.Medium; - Header.ID = 7; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - RegionData = new RegionDataBlock(); - Info = new InfoBlock(); - } - - public CrossedRegionPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - RegionData.FromBytes(bytes, ref i); - Info.FromBytes(bytes, ref i); - } - - public CrossedRegionPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - RegionData.FromBytes(bytes, ref i); - Info.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 8; - length += AgentData.Length; - length += RegionData.Length; - length += Info.Length; - if (Header.AckList != null && 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); - RegionData.ToBytes(bytes, ref i); - Info.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class ConfirmEnableSimulatorPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 8; - length += AgentData.Length; - return length; - } - } - public AgentDataBlock AgentData; - - public ConfirmEnableSimulatorPacket() - { - HasVariableBlocks = false; - Type = PacketType.ConfirmEnableSimulator; - Header = new Header(); - Header.Frequency = PacketFrequency.Medium; - Header.ID = 8; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - } - - public ConfirmEnableSimulatorPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - } - - public ConfirmEnableSimulatorPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 8; - length += AgentData.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class ObjectPropertiesPacket : Packet - { - /// - public sealed class ObjectDataBlock : PacketBlock - { - public UUID ObjectID; - public UUID CreatorID; - public UUID OwnerID; - public UUID GroupID; - public ulong CreationDate; - public uint BaseMask; - public uint OwnerMask; - public uint GroupMask; - public uint EveryoneMask; - public uint NextOwnerMask; - public int OwnershipCost; - public byte SaleType; - public int SalePrice; - public byte AggregatePerms; - public byte AggregatePermTextures; - public byte AggregatePermTexturesOwner; - public uint Category; - public short InventorySerial; - public UUID ItemID; - public UUID FolderID; - public UUID FromTaskID; - public UUID LastOwnerID; - public byte[] Name; - public byte[] Description; - public byte[] TouchName; - public byte[] SitName; - public byte[] TextureID; - - public override int Length - { - get - { - int length = 179; - if (Name != null) { length += Name.Length; } - if (Description != null) { length += Description.Length; } - if (TouchName != null) { length += TouchName.Length; } - if (SitName != null) { length += SitName.Length; } - if (TextureID != null) { length += TextureID.Length; } - return length; - } - } - - public ObjectDataBlock() { } - public ObjectDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - ObjectID.FromBytes(bytes, i); i += 16; - CreatorID.FromBytes(bytes, i); i += 16; - OwnerID.FromBytes(bytes, i); i += 16; - GroupID.FromBytes(bytes, i); i += 16; - CreationDate = (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)); - BaseMask = (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)); - GroupMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - 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)); - OwnershipCost = (int)(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)); - AggregatePerms = (byte)bytes[i++]; - AggregatePermTextures = (byte)bytes[i++]; - AggregatePermTexturesOwner = (byte)bytes[i++]; - Category = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - InventorySerial = (short)(bytes[i++] + (bytes[i++] << 8)); - ItemID.FromBytes(bytes, i); i += 16; - FolderID.FromBytes(bytes, i); i += 16; - FromTaskID.FromBytes(bytes, i); i += 16; - LastOwnerID.FromBytes(bytes, i); i += 16; - length = bytes[i++]; - Name = new byte[length]; - Buffer.BlockCopy(bytes, i, Name, 0, length); i += length; - length = bytes[i++]; - Description = new byte[length]; - Buffer.BlockCopy(bytes, i, Description, 0, length); i += length; - length = bytes[i++]; - TouchName = new byte[length]; - Buffer.BlockCopy(bytes, i, TouchName, 0, length); i += length; - length = bytes[i++]; - SitName = new byte[length]; - Buffer.BlockCopy(bytes, i, SitName, 0, length); i += length; - length = bytes[i++]; - TextureID = new byte[length]; - Buffer.BlockCopy(bytes, i, TextureID, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - ObjectID.ToBytes(bytes, i); i += 16; - CreatorID.ToBytes(bytes, i); i += 16; - OwnerID.ToBytes(bytes, i); i += 16; - GroupID.ToBytes(bytes, i); i += 16; - Utils.UInt64ToBytes(CreationDate, bytes, i); i += 8; - Utils.UIntToBytes(BaseMask, bytes, i); i += 4; - Utils.UIntToBytes(OwnerMask, bytes, i); i += 4; - Utils.UIntToBytes(GroupMask, bytes, i); i += 4; - Utils.UIntToBytes(EveryoneMask, bytes, i); i += 4; - Utils.UIntToBytes(NextOwnerMask, bytes, i); i += 4; - Utils.IntToBytes(OwnershipCost, bytes, i); i += 4; - bytes[i++] = SaleType; - Utils.IntToBytes(SalePrice, bytes, i); i += 4; - bytes[i++] = AggregatePerms; - bytes[i++] = AggregatePermTextures; - bytes[i++] = AggregatePermTexturesOwner; - Utils.UIntToBytes(Category, bytes, i); i += 4; - bytes[i++] = (byte)(InventorySerial % 256); - bytes[i++] = (byte)((InventorySerial >> 8) % 256); - ItemID.ToBytes(bytes, i); i += 16; - FolderID.ToBytes(bytes, i); i += 16; - FromTaskID.ToBytes(bytes, i); i += 16; - LastOwnerID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)Name.Length; - Buffer.BlockCopy(Name, 0, bytes, i, Name.Length); i += Name.Length; - bytes[i++] = (byte)Description.Length; - Buffer.BlockCopy(Description, 0, bytes, i, Description.Length); i += Description.Length; - bytes[i++] = (byte)TouchName.Length; - Buffer.BlockCopy(TouchName, 0, bytes, i, TouchName.Length); i += TouchName.Length; - bytes[i++] = (byte)SitName.Length; - Buffer.BlockCopy(SitName, 0, bytes, i, SitName.Length); i += SitName.Length; - bytes[i++] = (byte)TextureID.Length; - Buffer.BlockCopy(TextureID, 0, bytes, i, TextureID.Length); i += TextureID.Length; - } - - } - - public override int Length - { - get - { - int length = 9; - for (int j = 0; j < ObjectData.Length; j++) - length += ObjectData[j].Length; - return length; - } - } - public ObjectDataBlock[] ObjectData; - - public ObjectPropertiesPacket() - { - HasVariableBlocks = true; - Type = PacketType.ObjectProperties; - Header = new Header(); - Header.Frequency = PacketFrequency.Medium; - Header.ID = 9; - Header.Reliable = true; - Header.Zerocoded = true; - ObjectData = null; - } - - public ObjectPropertiesPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - int count = (int)bytes[i++]; - if(ObjectData == null || ObjectData.Length != -1) { - ObjectData = new ObjectDataBlock[count]; - for(int j = 0; j < count; j++) - { ObjectData[j] = new ObjectDataBlock(); } - } - for (int j = 0; j < count; j++) - { ObjectData[j].FromBytes(bytes, ref i); } - } - - public ObjectPropertiesPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - int count = (int)bytes[i++]; - if(ObjectData == null || ObjectData.Length != count) { - ObjectData = new ObjectDataBlock[count]; - for(int j = 0; j < count; j++) - { ObjectData[j] = new ObjectDataBlock(); } - } - for (int j = 0; j < count; j++) - { ObjectData[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 8; - length++; - for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 8; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int ObjectDataStart = 0; - do - { - int variableLength = 0; - int ObjectDataCount = 0; - - i = ObjectDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < ObjectData.Length) { - int blockLength = ObjectData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ObjectDataStart) { - variableLength += blockLength; - ++ObjectDataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)ObjectDataCount; - for (i = ObjectDataStart; i < ObjectDataStart + ObjectDataCount; i++) { ObjectData[i].ToBytes(packet, ref length); } - ObjectDataStart += ObjectDataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - ObjectDataStart < ObjectData.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class ObjectPropertiesFamilyPacket : Packet - { - /// - public sealed class ObjectDataBlock : PacketBlock - { - public uint RequestFlags; - public UUID ObjectID; - public UUID OwnerID; - public UUID GroupID; - public uint BaseMask; - public uint OwnerMask; - public uint GroupMask; - public uint EveryoneMask; - public uint NextOwnerMask; - public int OwnershipCost; - public byte SaleType; - public int SalePrice; - public uint Category; - public UUID LastOwnerID; - public byte[] Name; - public byte[] Description; - - public override int Length - { - get - { - int length = 103; - if (Name != null) { length += Name.Length; } - if (Description != null) { length += Description.Length; } - return length; - } - } - - public ObjectDataBlock() { } - public ObjectDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - RequestFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - ObjectID.FromBytes(bytes, i); i += 16; - OwnerID.FromBytes(bytes, i); i += 16; - GroupID.FromBytes(bytes, i); i += 16; - BaseMask = (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)); - GroupMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - 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)); - OwnershipCost = (int)(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)); - Category = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - LastOwnerID.FromBytes(bytes, i); i += 16; - length = bytes[i++]; - Name = new byte[length]; - Buffer.BlockCopy(bytes, i, Name, 0, length); i += length; - length = bytes[i++]; - Description = new byte[length]; - Buffer.BlockCopy(bytes, i, Description, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UIntToBytes(RequestFlags, bytes, i); i += 4; - ObjectID.ToBytes(bytes, i); i += 16; - OwnerID.ToBytes(bytes, i); i += 16; - GroupID.ToBytes(bytes, i); i += 16; - Utils.UIntToBytes(BaseMask, bytes, i); i += 4; - Utils.UIntToBytes(OwnerMask, bytes, i); i += 4; - Utils.UIntToBytes(GroupMask, bytes, i); i += 4; - Utils.UIntToBytes(EveryoneMask, bytes, i); i += 4; - Utils.UIntToBytes(NextOwnerMask, bytes, i); i += 4; - Utils.IntToBytes(OwnershipCost, bytes, i); i += 4; - bytes[i++] = SaleType; - Utils.IntToBytes(SalePrice, bytes, i); i += 4; - Utils.UIntToBytes(Category, bytes, i); i += 4; - LastOwnerID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)Name.Length; - Buffer.BlockCopy(Name, 0, bytes, i, Name.Length); i += Name.Length; - bytes[i++] = (byte)Description.Length; - Buffer.BlockCopy(Description, 0, bytes, i, Description.Length); i += Description.Length; - } - - } - - public override int Length - { - get - { - int length = 8; - length += ObjectData.Length; - return length; - } - } - public ObjectDataBlock ObjectData; - - public ObjectPropertiesFamilyPacket() - { - HasVariableBlocks = false; - Type = PacketType.ObjectPropertiesFamily; - Header = new Header(); - Header.Frequency = PacketFrequency.Medium; - Header.ID = 10; - Header.Reliable = true; - Header.Zerocoded = true; - ObjectData = new ObjectDataBlock(); - } - - public ObjectPropertiesFamilyPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - ObjectData.FromBytes(bytes, ref i); - } - - public ObjectPropertiesFamilyPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - ObjectData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 8; - length += ObjectData.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class ParcelPropertiesRequestPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class ParcelDataBlock : PacketBlock - { - public int SequenceID; - public float West; - public float South; - public float East; - public float North; - public bool SnapSelection; - - public override int Length - { - get - { - return 21; - } - } - - public ParcelDataBlock() { } - public ParcelDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - SequenceID = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - West = Utils.BytesToFloat(bytes, i); i += 4; - South = Utils.BytesToFloat(bytes, i); i += 4; - East = Utils.BytesToFloat(bytes, i); i += 4; - North = Utils.BytesToFloat(bytes, i); i += 4; - SnapSelection = (bytes[i++] != 0) ? (bool)true : (bool)false; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.IntToBytes(SequenceID, bytes, i); i += 4; - Utils.FloatToBytes(West, bytes, i); i += 4; - Utils.FloatToBytes(South, bytes, i); i += 4; - Utils.FloatToBytes(East, bytes, i); i += 4; - Utils.FloatToBytes(North, bytes, i); i += 4; - bytes[i++] = (byte)((SnapSelection) ? 1 : 0); - } - - } - - public override int Length - { - get - { - int length = 8; - length += AgentData.Length; - length += ParcelData.Length; - return length; - } - } - public AgentDataBlock AgentData; - public ParcelDataBlock ParcelData; - - public ParcelPropertiesRequestPacket() - { - HasVariableBlocks = false; - Type = PacketType.ParcelPropertiesRequest; - Header = new Header(); - Header.Frequency = PacketFrequency.Medium; - Header.ID = 11; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - ParcelData = new ParcelDataBlock(); - } - - public ParcelPropertiesRequestPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - ParcelData.FromBytes(bytes, ref i); - } - - public ParcelPropertiesRequestPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - ParcelData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 8; - length += AgentData.Length; - length += ParcelData.Length; - if (Header.AckList != null && 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); - ParcelData.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class AttachedSoundPacket : Packet - { - /// - public sealed class DataBlockBlock : PacketBlock - { - public UUID SoundID; - public UUID ObjectID; - public UUID OwnerID; - public float Gain; - public byte Flags; - - public override int Length - { - get - { - return 53; - } - } - - public DataBlockBlock() { } - public DataBlockBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - SoundID.FromBytes(bytes, i); i += 16; - ObjectID.FromBytes(bytes, i); i += 16; - OwnerID.FromBytes(bytes, i); i += 16; - Gain = Utils.BytesToFloat(bytes, i); i += 4; - Flags = (byte)bytes[i++]; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - SoundID.ToBytes(bytes, i); i += 16; - ObjectID.ToBytes(bytes, i); i += 16; - OwnerID.ToBytes(bytes, i); i += 16; - Utils.FloatToBytes(Gain, bytes, i); i += 4; - bytes[i++] = Flags; - } - - } - - public override int Length - { - get - { - int length = 8; - length += DataBlock.Length; - return length; - } - } - public DataBlockBlock DataBlock; - - public AttachedSoundPacket() - { - HasVariableBlocks = false; - Type = PacketType.AttachedSound; - Header = new Header(); - Header.Frequency = PacketFrequency.Medium; - Header.ID = 13; - Header.Reliable = true; - DataBlock = new DataBlockBlock(); - } - - public AttachedSoundPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - DataBlock.FromBytes(bytes, ref i); - } - - public AttachedSoundPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - DataBlock.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 8; - length += DataBlock.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class AttachedSoundGainChangePacket : Packet - { - /// - public sealed class DataBlockBlock : PacketBlock - { - public UUID ObjectID; - public float Gain; - - public override int Length - { - get - { - return 20; - } - } - - public DataBlockBlock() { } - public DataBlockBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - ObjectID.FromBytes(bytes, i); i += 16; - Gain = Utils.BytesToFloat(bytes, i); i += 4; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - ObjectID.ToBytes(bytes, i); i += 16; - Utils.FloatToBytes(Gain, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 8; - length += DataBlock.Length; - return length; - } - } - public DataBlockBlock DataBlock; - - public AttachedSoundGainChangePacket() - { - HasVariableBlocks = false; - Type = PacketType.AttachedSoundGainChange; - Header = new Header(); - Header.Frequency = PacketFrequency.Medium; - Header.ID = 14; - Header.Reliable = true; - DataBlock = new DataBlockBlock(); - } - - public AttachedSoundGainChangePacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - DataBlock.FromBytes(bytes, ref i); - } - - public AttachedSoundGainChangePacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - DataBlock.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 8; - length += DataBlock.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - } - - /// - public sealed class PreloadSoundPacket : Packet - { - /// - public sealed class DataBlockBlock : PacketBlock - { - public UUID ObjectID; - public UUID OwnerID; - public UUID SoundID; - - public override int Length - { - get - { - return 48; - } - } - - public DataBlockBlock() { } - public DataBlockBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - ObjectID.FromBytes(bytes, i); i += 16; - OwnerID.FromBytes(bytes, i); i += 16; - SoundID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - ObjectID.ToBytes(bytes, i); i += 16; - OwnerID.ToBytes(bytes, i); i += 16; - SoundID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 9; - for (int j = 0; j < DataBlock.Length; j++) - length += DataBlock[j].Length; - return length; - } - } - public DataBlockBlock[] DataBlock; - - public PreloadSoundPacket() - { - HasVariableBlocks = true; - Type = PacketType.PreloadSound; - Header = new Header(); - Header.Frequency = PacketFrequency.Medium; - Header.ID = 15; - Header.Reliable = true; - DataBlock = null; - } - - public PreloadSoundPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - int count = (int)bytes[i++]; - if(DataBlock == null || DataBlock.Length != -1) { - DataBlock = new DataBlockBlock[count]; - for(int j = 0; j < count; j++) - { DataBlock[j] = new DataBlockBlock(); } - } - for (int j = 0; j < count; j++) - { DataBlock[j].FromBytes(bytes, ref i); } - } - - public PreloadSoundPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - int count = (int)bytes[i++]; - if(DataBlock == null || DataBlock.Length != count) { - DataBlock = new DataBlockBlock[count]; - for(int j = 0; j < count; j++) - { DataBlock[j] = new DataBlockBlock(); } - } - for (int j = 0; j < count; j++) - { DataBlock[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 8; - length++; - for (int j = 0; j < DataBlock.Length; j++) { length += DataBlock[j].Length; } - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 8; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int DataBlockStart = 0; - do - { - int variableLength = 0; - int DataBlockCount = 0; - - i = DataBlockStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < DataBlock.Length) { - int blockLength = DataBlock[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == DataBlockStart) { - variableLength += blockLength; - ++DataBlockCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)DataBlockCount; - for (i = DataBlockStart; i < DataBlockStart + DataBlockCount; i++) { DataBlock[i].ToBytes(packet, ref length); } - DataBlockStart += DataBlockCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - DataBlockStart < DataBlock.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class ViewerEffectPacket : Packet - { - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class EffectBlock : PacketBlock - { - public UUID ID; - public UUID AgentID; - public byte Type; - public float Duration; - public byte[] Color; - public byte[] TypeData; - - public override int Length - { - get - { - int length = 42; - if (TypeData != null) { length += TypeData.Length; } - return length; - } - } - - public EffectBlock() { } - public EffectBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - ID.FromBytes(bytes, i); i += 16; - AgentID.FromBytes(bytes, i); i += 16; - Type = (byte)bytes[i++]; - Duration = Utils.BytesToFloat(bytes, i); i += 4; - Color = new byte[4]; - Buffer.BlockCopy(bytes, i, Color, 0, 4); i += 4; - length = bytes[i++]; - TypeData = new byte[length]; - Buffer.BlockCopy(bytes, i, TypeData, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - ID.ToBytes(bytes, i); i += 16; - AgentID.ToBytes(bytes, i); i += 16; - bytes[i++] = Type; - Utils.FloatToBytes(Duration, bytes, i); i += 4; - Buffer.BlockCopy(Color, 0, bytes, i, 4);i += 4; - bytes[i++] = (byte)TypeData.Length; - Buffer.BlockCopy(TypeData, 0, bytes, i, TypeData.Length); i += TypeData.Length; - } - - } - - public override int Length - { - get - { - int length = 9; - length += AgentData.Length; - for (int j = 0; j < Effect.Length; j++) - length += Effect[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public EffectBlock[] Effect; - - public ViewerEffectPacket() - { - HasVariableBlocks = true; - Type = PacketType.ViewerEffect; - Header = new Header(); - Header.Frequency = PacketFrequency.Medium; - Header.ID = 17; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - Effect = null; - } - - public ViewerEffectPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(Effect == null || Effect.Length != -1) { - Effect = new EffectBlock[count]; - for(int j = 0; j < count; j++) - { Effect[j] = new EffectBlock(); } - } - for (int j = 0; j < count; j++) - { Effect[j].FromBytes(bytes, ref i); } - } - - public ViewerEffectPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(Effect == null || Effect.Length != count) { - Effect = new EffectBlock[count]; - for(int j = 0; j < count; j++) - { Effect[j] = new EffectBlock(); } - } - for (int j = 0; j < count; j++) - { Effect[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 8; - length += AgentData.Length; - length++; - for (int j = 0; j < Effect.Length; j++) { length += Effect[j].Length; } - if (Header.AckList != null && 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)Effect.Length; - for (int j = 0; j < Effect.Length; j++) { Effect[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 8; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int EffectStart = 0; - do - { - int variableLength = 0; - int EffectCount = 0; - - i = EffectStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < Effect.Length) { - int blockLength = Effect[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == EffectStart) { - variableLength += blockLength; - ++EffectCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)EffectCount; - for (i = EffectStart; i < EffectStart + EffectCount; i++) { Effect[i].ToBytes(packet, ref length); } - EffectStart += EffectCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - EffectStart < Effect.Length); - - return packets.ToArray(); - } - } - - /// - public sealed class StartPingCheckPacket : Packet - { - public override bool UsesBufferPooling - { - get - { - return true; - } - } - - /// - public sealed class PingIDBlock : PacketBlock - { - public byte PingID; - public uint OldestUnacked; - - public override int Length - { - get - { - return 5; - } - } - - public PingIDBlock() { } - public PingIDBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(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(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - bytes[i++] = PingID; - Utils.UIntToBytes(OldestUnacked, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 7; - length += PingID.Length; - return length; - } - } - public PingIDBlock PingID; - - public StartPingCheckPacket() - { - HasVariableBlocks = false; - Type = PacketType.StartPingCheck; - Header = new Header(); - Header.Frequency = PacketFrequency.High; - Header.ID = 1; - Header.Reliable = true; - PingID = new PingIDBlock(); - } - - public StartPingCheckPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - PingID.FromBytes(bytes, ref i); - } - - public StartPingCheckPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - PingID.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 7; - length += PingID.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - - public override byte[] ToBytes(Interfaces.IByteBufferPool pool, ref int size) - { - int length = 7; - length += PingID.Length; - if (Header.AckList != null && Header.AckList.Length > 0) { length += Header.AckList.Length * 4 + 1; } - byte[] bytes = pool.LeaseBytes(length); - int i = 0; - Header.ToBytes(bytes, ref i); - PingID.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - - size = length; - return bytes; - } - - public override byte[][] ToBytesMultiple(Interfaces.IByteBufferPool pool, out int[] sizes) - { - sizes = new int[1]; - return new byte[][] { this.ToBytes(pool, ref sizes[0]) }; - } - } - - /// - public sealed class CompletePingCheckPacket : Packet - { - public override bool UsesBufferPooling - { - get - { - return true; - } - } - - /// - public sealed class PingIDBlock : PacketBlock - { - public byte PingID; - - public override int Length - { - get - { - return 1; - } - } - - public PingIDBlock() { } - public PingIDBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - PingID = (byte)bytes[i++]; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - bytes[i++] = PingID; - } - - } - - public override int Length - { - get - { - int length = 7; - length += PingID.Length; - return length; - } - } - public PingIDBlock PingID; - - public CompletePingCheckPacket() - { - HasVariableBlocks = false; - Type = PacketType.CompletePingCheck; - Header = new Header(); - Header.Frequency = PacketFrequency.High; - Header.ID = 2; - Header.Reliable = true; - PingID = new PingIDBlock(); - } - - public CompletePingCheckPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - PingID.FromBytes(bytes, ref i); - } - - public CompletePingCheckPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - PingID.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 7; - length += PingID.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - - public override byte[] ToBytes(Interfaces.IByteBufferPool pool, ref int size) - { - int length = 7; - length += PingID.Length; - if (Header.AckList != null && Header.AckList.Length > 0) { length += Header.AckList.Length * 4 + 1; } - byte[] bytes = pool.LeaseBytes(length); - int i = 0; - Header.ToBytes(bytes, ref i); - PingID.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - - size = length; - return bytes; - } - - public override byte[][] ToBytesMultiple(Interfaces.IByteBufferPool pool, out int[] sizes) - { - sizes = new int[1]; - return new byte[][] { this.ToBytes(pool, ref sizes[0]) }; - } - } - - /// - public sealed class AgentUpdatePacket : Packet - { - public override bool UsesBufferPooling - { - get - { - return true; - } - } - - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - public Quaternion BodyRotation; - public Quaternion HeadRotation; - public byte State; - public Vector3 CameraCenter; - public Vector3 CameraAtAxis; - public Vector3 CameraLeftAxis; - public Vector3 CameraUpAxis; - public float Far; - public uint ControlFlags; - public byte Flags; - - public override int Length - { - get - { - return 114; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - BodyRotation.FromBytes(bytes, i, true); i += 12; - HeadRotation.FromBytes(bytes, i, true); i += 12; - State = (byte)bytes[i++]; - CameraCenter.FromBytes(bytes, i); i += 12; - CameraAtAxis.FromBytes(bytes, i); i += 12; - CameraLeftAxis.FromBytes(bytes, i); i += 12; - CameraUpAxis.FromBytes(bytes, i); i += 12; - Far = Utils.BytesToFloat(bytes, i); i += 4; - ControlFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - Flags = (byte)bytes[i++]; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - BodyRotation.ToBytes(bytes, i); i += 12; - HeadRotation.ToBytes(bytes, i); i += 12; - bytes[i++] = State; - CameraCenter.ToBytes(bytes, i); i += 12; - CameraAtAxis.ToBytes(bytes, i); i += 12; - CameraLeftAxis.ToBytes(bytes, i); i += 12; - CameraUpAxis.ToBytes(bytes, i); i += 12; - Utils.FloatToBytes(Far, bytes, i); i += 4; - Utils.UIntToBytes(ControlFlags, bytes, i); i += 4; - bytes[i++] = Flags; - } - - } - - public override int Length - { - get - { - int length = 7; - length += AgentData.Length; - return length; - } - } - public AgentDataBlock AgentData; - - public AgentUpdatePacket() - { - HasVariableBlocks = false; - Type = PacketType.AgentUpdate; - Header = new Header(); - Header.Frequency = PacketFrequency.High; - Header.ID = 4; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - } - - public AgentUpdatePacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - } - - public AgentUpdatePacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 7; - length += AgentData.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - - public override byte[] ToBytes(Interfaces.IByteBufferPool pool, ref int size) - { - int length = 7; - length += AgentData.Length; - if (Header.AckList != null && Header.AckList.Length > 0) { length += Header.AckList.Length * 4 + 1; } - byte[] bytes = pool.LeaseBytes(length); - int i = 0; - Header.ToBytes(bytes, ref i); - AgentData.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - - size = length; - return bytes; - } - - public override byte[][] ToBytesMultiple(Interfaces.IByteBufferPool pool, out int[] sizes) - { - sizes = new int[1]; - return new byte[][] { this.ToBytes(pool, ref sizes[0]) }; - } - } - - /// - public sealed class AgentAnimationPacket : Packet - { - public override bool UsesBufferPooling - { - get - { - return true; - } - } - - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class AnimationListBlock : PacketBlock - { - public UUID AnimID; - public bool StartAnim; - - public override int Length - { - get - { - return 17; - } - } - - public AnimationListBlock() { } - public AnimationListBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AnimID.FromBytes(bytes, i); i += 16; - StartAnim = (bytes[i++] != 0) ? (bool)true : (bool)false; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AnimID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)((StartAnim) ? 1 : 0); - } - - } - - /// - public sealed class PhysicalAvatarEventListBlock : PacketBlock - { - public byte[] TypeData; - - public override int Length - { - get - { - int length = 1; - if (TypeData != null) { length += TypeData.Length; } - return length; - } - } - - public PhysicalAvatarEventListBlock() { } - public PhysicalAvatarEventListBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - length = bytes[i++]; - TypeData = new byte[length]; - Buffer.BlockCopy(bytes, i, TypeData, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - bytes[i++] = (byte)TypeData.Length; - Buffer.BlockCopy(TypeData, 0, bytes, i, TypeData.Length); i += TypeData.Length; - } - - } - - public override int Length - { - get - { - int length = 9; - length += AgentData.Length; - for (int j = 0; j < AnimationList.Length; j++) - length += AnimationList[j].Length; - for (int j = 0; j < PhysicalAvatarEventList.Length; j++) - length += PhysicalAvatarEventList[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public AnimationListBlock[] AnimationList; - public PhysicalAvatarEventListBlock[] PhysicalAvatarEventList; - - public AgentAnimationPacket() - { - HasVariableBlocks = true; - Type = PacketType.AgentAnimation; - Header = new Header(); - Header.Frequency = PacketFrequency.High; - Header.ID = 5; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - AnimationList = null; - PhysicalAvatarEventList = null; - } - - public AgentAnimationPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(AnimationList == null || AnimationList.Length != -1) { - AnimationList = new AnimationListBlock[count]; - for(int j = 0; j < count; j++) - { AnimationList[j] = new AnimationListBlock(); } - } - for (int j = 0; j < count; j++) - { AnimationList[j].FromBytes(bytes, ref i); } - count = (int)bytes[i++]; - if(PhysicalAvatarEventList == null || PhysicalAvatarEventList.Length != -1) { - PhysicalAvatarEventList = new PhysicalAvatarEventListBlock[count]; - for(int j = 0; j < count; j++) - { PhysicalAvatarEventList[j] = new PhysicalAvatarEventListBlock(); } - } - for (int j = 0; j < count; j++) - { PhysicalAvatarEventList[j].FromBytes(bytes, ref i); } - } - - public AgentAnimationPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(AnimationList == null || AnimationList.Length != count) { - AnimationList = new AnimationListBlock[count]; - for(int j = 0; j < count; j++) - { AnimationList[j] = new AnimationListBlock(); } - } - for (int j = 0; j < count; j++) - { AnimationList[j].FromBytes(bytes, ref i); } - count = (int)bytes[i++]; - if(PhysicalAvatarEventList == null || PhysicalAvatarEventList.Length != count) { - PhysicalAvatarEventList = new PhysicalAvatarEventListBlock[count]; - for(int j = 0; j < count; j++) - { PhysicalAvatarEventList[j] = new PhysicalAvatarEventListBlock(); } - } - for (int j = 0; j < count; j++) - { PhysicalAvatarEventList[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 7; - length += AgentData.Length; - length++; - for (int j = 0; j < AnimationList.Length; j++) { length += AnimationList[j].Length; } - length++; - for (int j = 0; j < PhysicalAvatarEventList.Length; j++) { length += PhysicalAvatarEventList[j].Length; } - if (Header.AckList != null && 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)AnimationList.Length; - for (int j = 0; j < AnimationList.Length; j++) { AnimationList[j].ToBytes(bytes, ref i); } - bytes[i++] = (byte)PhysicalAvatarEventList.Length; - for (int j = 0; j < PhysicalAvatarEventList.Length; j++) { PhysicalAvatarEventList[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 7; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - fixedLength += 2; - - int AnimationListStart = 0; - int PhysicalAvatarEventListStart = 0; - do - { - int variableLength = 0; - int AnimationListCount = 0; - int PhysicalAvatarEventListCount = 0; - - i = AnimationListStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < AnimationList.Length) { - int blockLength = AnimationList[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == AnimationListStart) { - variableLength += blockLength; - ++AnimationListCount; - } - else { break; } - ++i; - } - - i = PhysicalAvatarEventListStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < PhysicalAvatarEventList.Length) { - int blockLength = PhysicalAvatarEventList[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == PhysicalAvatarEventListStart) { - variableLength += blockLength; - ++PhysicalAvatarEventListCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)AnimationListCount; - for (i = AnimationListStart; i < AnimationListStart + AnimationListCount; i++) { AnimationList[i].ToBytes(packet, ref length); } - AnimationListStart += AnimationListCount; - - packet[length++] = (byte)PhysicalAvatarEventListCount; - for (i = PhysicalAvatarEventListStart; i < PhysicalAvatarEventListStart + PhysicalAvatarEventListCount; i++) { PhysicalAvatarEventList[i].ToBytes(packet, ref length); } - PhysicalAvatarEventListStart += PhysicalAvatarEventListCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - AnimationListStart < AnimationList.Length || - PhysicalAvatarEventListStart < PhysicalAvatarEventList.Length); - - return packets.ToArray(); - } - - public override byte[] ToBytes(Interfaces.IByteBufferPool pool, ref int size) - { - int length = 7; - length += AgentData.Length; - length++; - for (int j = 0; j < AnimationList.Length; j++) { length += AnimationList[j].Length; } - length++; - for (int j = 0; j < PhysicalAvatarEventList.Length; j++) { length += PhysicalAvatarEventList[j].Length; } - if (Header.AckList != null && Header.AckList.Length > 0) { length += Header.AckList.Length * 4 + 1; } - byte[] bytes = pool.LeaseBytes(length); - int i = 0; - Header.ToBytes(bytes, ref i); - AgentData.ToBytes(bytes, ref i); - bytes[i++] = (byte)AnimationList.Length; - for (int j = 0; j < AnimationList.Length; j++) { AnimationList[j].ToBytes(bytes, ref i); } - bytes[i++] = (byte)PhysicalAvatarEventList.Length; - for (int j = 0; j < PhysicalAvatarEventList.Length; j++) { PhysicalAvatarEventList[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - - size = length; - return bytes; - } - - public override byte[][] ToBytesMultiple(Interfaces.IByteBufferPool pool, out int[] sizes) - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - System.Collections.Generic.List retSizes = new System.Collections.Generic.List(); - - int i = 0; - int fixedLength = 7; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) - { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - fixedLength += 2; - - int AnimationListStart = 0; - int PhysicalAvatarEventListStart = 0; - do - { - int variableLength = 0; - int AnimationListCount = 0; - int PhysicalAvatarEventListCount = 0; - - i = AnimationListStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < AnimationList.Length) - { - int blockLength = AnimationList[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU) - { - variableLength += blockLength; - ++AnimationListCount; - } - else { break; } - ++i; - } - - i = PhysicalAvatarEventListStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < PhysicalAvatarEventList.Length) - { - int blockLength = PhysicalAvatarEventList[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU) - { - variableLength += blockLength; - ++PhysicalAvatarEventListCount; - } - else { break; } - ++i; - } - - byte[] packet = pool.LeaseBytes(fixedLength + variableLength + acksLength); - int packetSize = fixedLength + variableLength + acksLength; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)AnimationListCount; - for (i = AnimationListStart; i < AnimationListStart + AnimationListCount; i++) { AnimationList[i].ToBytes(packet, ref length); } - AnimationListStart += AnimationListCount; - - packet[length++] = (byte)PhysicalAvatarEventListCount; - for (i = PhysicalAvatarEventListStart; i < PhysicalAvatarEventListStart + PhysicalAvatarEventListCount; i++) { PhysicalAvatarEventList[i].ToBytes(packet, ref length); } - PhysicalAvatarEventListStart += PhysicalAvatarEventListCount; - - if (acksLength > 0) - { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - retSizes.Add(packetSize); - } while ( - AnimationListStart < AnimationList.Length || - PhysicalAvatarEventListStart < PhysicalAvatarEventList.Length); - - sizes = retSizes.ToArray(); - return packets.ToArray(); - } - } - - /// - public sealed class AgentRequestSitPacket : Packet - { - public override bool UsesBufferPooling - { - get - { - return true; - } - } - - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class TargetObjectBlock : PacketBlock - { - public UUID TargetID; - public Vector3 Offset; - - public override int Length - { - get - { - return 28; - } - } - - public TargetObjectBlock() { } - public TargetObjectBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - TargetID.FromBytes(bytes, i); i += 16; - Offset.FromBytes(bytes, i); i += 12; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - TargetID.ToBytes(bytes, i); i += 16; - Offset.ToBytes(bytes, i); i += 12; - } - - } - - public override int Length - { - get - { - int length = 7; - length += AgentData.Length; - length += TargetObject.Length; - return length; - } - } - public AgentDataBlock AgentData; - public TargetObjectBlock TargetObject; - - public AgentRequestSitPacket() - { - HasVariableBlocks = false; - Type = PacketType.AgentRequestSit; - Header = new Header(); - Header.Frequency = PacketFrequency.High; - Header.ID = 6; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - TargetObject = new TargetObjectBlock(); - } - - public AgentRequestSitPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - TargetObject.FromBytes(bytes, ref i); - } - - public AgentRequestSitPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - TargetObject.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 7; - length += AgentData.Length; - length += TargetObject.Length; - if (Header.AckList != null && 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); - TargetObject.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - - public override byte[] ToBytes(Interfaces.IByteBufferPool pool, ref int size) - { - int length = 7; - length += AgentData.Length; - length += TargetObject.Length; - if (Header.AckList != null && Header.AckList.Length > 0) { length += Header.AckList.Length * 4 + 1; } - byte[] bytes = pool.LeaseBytes(length); - int i = 0; - Header.ToBytes(bytes, ref i); - AgentData.ToBytes(bytes, ref i); - TargetObject.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - - size = length; - return bytes; - } - - public override byte[][] ToBytesMultiple(Interfaces.IByteBufferPool pool, out int[] sizes) - { - sizes = new int[1]; - return new byte[][] { this.ToBytes(pool, ref sizes[0]) }; - } - } - - /// - public sealed class AgentSitPacket : Packet - { - public override bool UsesBufferPooling - { - get - { - return true; - } - } - - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 7; - length += AgentData.Length; - return length; - } - } - public AgentDataBlock AgentData; - - public AgentSitPacket() - { - HasVariableBlocks = false; - Type = PacketType.AgentSit; - Header = new Header(); - Header.Frequency = PacketFrequency.High; - Header.ID = 7; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - } - - public AgentSitPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - } - - public AgentSitPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 7; - length += AgentData.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - - public override byte[] ToBytes(Interfaces.IByteBufferPool pool, ref int size) - { - int length = 7; - length += AgentData.Length; - if (Header.AckList != null && Header.AckList.Length > 0) { length += Header.AckList.Length * 4 + 1; } - byte[] bytes = pool.LeaseBytes(length); - int i = 0; - Header.ToBytes(bytes, ref i); - AgentData.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - - size = length; - return bytes; - } - - public override byte[][] ToBytesMultiple(Interfaces.IByteBufferPool pool, out int[] sizes) - { - sizes = new int[1]; - return new byte[][] { this.ToBytes(pool, ref sizes[0]) }; - } - } - - /// - public sealed class RequestImagePacket : Packet - { - public override bool UsesBufferPooling - { - get - { - return true; - } - } - - /// - public sealed class AgentDataBlock : PacketBlock - { - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 32; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class RequestImageBlock : PacketBlock - { - public UUID Image; - public sbyte DiscardLevel; - public float DownloadPriority; - public uint Packet; - public byte Type; - - public override int Length - { - get - { - return 26; - } - } - - public RequestImageBlock() { } - public RequestImageBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - Image.FromBytes(bytes, i); i += 16; - DiscardLevel = (sbyte)bytes[i++]; - DownloadPriority = Utils.BytesToFloat(bytes, i); i += 4; - Packet = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - Type = (byte)bytes[i++]; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Image.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)DiscardLevel; - Utils.FloatToBytes(DownloadPriority, bytes, i); i += 4; - Utils.UIntToBytes(Packet, bytes, i); i += 4; - bytes[i++] = Type; - } - - } - - public override int Length - { - get - { - int length = 8; - length += AgentData.Length; - for (int j = 0; j < RequestImage.Length; j++) - length += RequestImage[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public RequestImageBlock[] RequestImage; - - public RequestImagePacket() - { - HasVariableBlocks = true; - Type = PacketType.RequestImage; - Header = new Header(); - Header.Frequency = PacketFrequency.High; - Header.ID = 8; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - RequestImage = null; - } - - public RequestImagePacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(RequestImage == null || RequestImage.Length != -1) { - RequestImage = new RequestImageBlock[count]; - for(int j = 0; j < count; j++) - { RequestImage[j] = new RequestImageBlock(); } - } - for (int j = 0; j < count; j++) - { RequestImage[j].FromBytes(bytes, ref i); } - } - - public RequestImagePacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(RequestImage == null || RequestImage.Length != count) { - RequestImage = new RequestImageBlock[count]; - for(int j = 0; j < count; j++) - { RequestImage[j] = new RequestImageBlock(); } - } - for (int j = 0; j < count; j++) - { RequestImage[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 7; - length += AgentData.Length; - length++; - for (int j = 0; j < RequestImage.Length; j++) { length += RequestImage[j].Length; } - if (Header.AckList != null && 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)RequestImage.Length; - for (int j = 0; j < RequestImage.Length; j++) { RequestImage[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 7; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int RequestImageStart = 0; - do - { - int variableLength = 0; - int RequestImageCount = 0; - - i = RequestImageStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < RequestImage.Length) { - int blockLength = RequestImage[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == RequestImageStart) { - variableLength += blockLength; - ++RequestImageCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)RequestImageCount; - for (i = RequestImageStart; i < RequestImageStart + RequestImageCount; i++) { RequestImage[i].ToBytes(packet, ref length); } - RequestImageStart += RequestImageCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - RequestImageStart < RequestImage.Length); - - return packets.ToArray(); - } - - public override byte[] ToBytes(Interfaces.IByteBufferPool pool, ref int size) - { - int length = 7; - length += AgentData.Length; - length++; - for (int j = 0; j < RequestImage.Length; j++) { length += RequestImage[j].Length; } - if (Header.AckList != null && Header.AckList.Length > 0) { length += Header.AckList.Length * 4 + 1; } - byte[] bytes = pool.LeaseBytes(length); - int i = 0; - Header.ToBytes(bytes, ref i); - AgentData.ToBytes(bytes, ref i); - bytes[i++] = (byte)RequestImage.Length; - for (int j = 0; j < RequestImage.Length; j++) { RequestImage[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - - size = length; - return bytes; - } - - public override byte[][] ToBytesMultiple(Interfaces.IByteBufferPool pool, out int[] sizes) - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - System.Collections.Generic.List retSizes = new System.Collections.Generic.List(); - - int i = 0; - int fixedLength = 7; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) - { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int RequestImageStart = 0; - do - { - int variableLength = 0; - int RequestImageCount = 0; - - i = RequestImageStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < RequestImage.Length) - { - int blockLength = RequestImage[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU) - { - variableLength += blockLength; - ++RequestImageCount; - } - else { break; } - ++i; - } - - byte[] packet = pool.LeaseBytes(fixedLength + variableLength + acksLength); - int packetSize = fixedLength + variableLength + acksLength; - - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)RequestImageCount; - for (i = RequestImageStart; i < RequestImageStart + RequestImageCount; i++) { RequestImage[i].ToBytes(packet, ref length); } - RequestImageStart += RequestImageCount; - - if (acksLength > 0) - { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - retSizes.Add(packetSize); - packets.Add(packet); - } while ( - RequestImageStart < RequestImage.Length); - - sizes = retSizes.ToArray(); - return packets.ToArray(); - } - } - - /// - public sealed class ImageDataPacket : Packet - { - public override bool UsesBufferPooling - { - get - { - return true; - } - } - - /// - public sealed class ImageIDBlock : PacketBlock - { - public UUID ID; - public byte Codec; - public uint Size; - public ushort Packets; - - public override int Length - { - get - { - return 23; - } - } - - public ImageIDBlock() { } - public ImageIDBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - ID.FromBytes(bytes, i); i += 16; - Codec = (byte)bytes[i++]; - Size = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - Packets = (ushort)(bytes[i++] + (bytes[i++] << 8)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - ID.ToBytes(bytes, i); i += 16; - bytes[i++] = Codec; - Utils.UIntToBytes(Size, bytes, i); i += 4; - bytes[i++] = (byte)(Packets % 256); - bytes[i++] = (byte)((Packets >> 8) % 256); - } - - } - - /// - public sealed class ImageDataBlock : PacketBlock - { - public byte[] Data; - - public override int Length - { - get - { - int length = 2; - if (Data != null) { length += Data.Length; } - return length; - } - } - - public ImageDataBlock() { } - public ImageDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - length = (bytes[i++] + (bytes[i++] << 8)); - Data = new byte[length]; - Buffer.BlockCopy(bytes, i, Data, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - bytes[i++] = (byte)(Data.Length % 256); - bytes[i++] = (byte)((Data.Length >> 8) % 256); - Buffer.BlockCopy(Data, 0, bytes, i, Data.Length); i += Data.Length; - } - - } - - public override int Length - { - get - { - int length = 7; - length += ImageID.Length; - length += ImageData.Length; - return length; - } - } - public ImageIDBlock ImageID; - public ImageDataBlock ImageData; - - public ImageDataPacket() - { - HasVariableBlocks = false; - Type = PacketType.ImageData; - Header = new Header(); - Header.Frequency = PacketFrequency.High; - Header.ID = 9; - Header.Reliable = true; - ImageID = new ImageIDBlock(); - ImageData = new ImageDataBlock(); - } - - public ImageDataPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - ImageID.FromBytes(bytes, ref i); - ImageData.FromBytes(bytes, ref i); - } - - public ImageDataPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - ImageID.FromBytes(bytes, ref i); - ImageData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 7; - length += ImageID.Length; - length += ImageData.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - - public override byte[] ToBytes(Interfaces.IByteBufferPool pool, ref int size) - { - int length = 7; - length += ImageID.Length; - length += ImageData.Length; - if (Header.AckList != null && Header.AckList.Length > 0) { length += Header.AckList.Length * 4 + 1; } - byte[] bytes = pool.LeaseBytes(length); - int i = 0; - Header.ToBytes(bytes, ref i); - ImageID.ToBytes(bytes, ref i); - ImageData.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - - size = length; - return bytes; - } - - public override byte[][] ToBytesMultiple(Interfaces.IByteBufferPool pool, out int[] sizes) - { - sizes = new int[1]; - return new byte[][] { this.ToBytes(pool, ref sizes[0]) }; - } - - } - - /// - public sealed class ImagePacketPacket : Packet - { - public override bool UsesBufferPooling - { - get - { - return true; - } - } - - /// - public sealed class ImageIDBlock : PacketBlock - { - public UUID ID; - public ushort Packet; - - public override int Length - { - get - { - return 18; - } - } - - public ImageIDBlock() { } - public ImageIDBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - ID.FromBytes(bytes, i); i += 16; - Packet = (ushort)(bytes[i++] + (bytes[i++] << 8)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - ID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)(Packet % 256); - bytes[i++] = (byte)((Packet >> 8) % 256); - } - - } - - /// - public sealed class ImageDataBlock : PacketBlock - { - public byte[] Data; - - public override int Length - { - get - { - int length = 2; - if (Data != null) { length += Data.Length; } - return length; - } - } - - public ImageDataBlock() { } - public ImageDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - length = (bytes[i++] + (bytes[i++] << 8)); - Data = new byte[length]; - Buffer.BlockCopy(bytes, i, Data, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - bytes[i++] = (byte)(Data.Length % 256); - bytes[i++] = (byte)((Data.Length >> 8) % 256); - Buffer.BlockCopy(Data, 0, bytes, i, Data.Length); i += Data.Length; - } - - } - - public override int Length - { - get - { - int length = 7; - length += ImageID.Length; - length += ImageData.Length; - return length; - } - } - public ImageIDBlock ImageID; - public ImageDataBlock ImageData; - - public ImagePacketPacket() - { - HasVariableBlocks = false; - Type = PacketType.ImagePacket; - Header = new Header(); - Header.Frequency = PacketFrequency.High; - Header.ID = 10; - Header.Reliable = true; - ImageID = new ImageIDBlock(); - ImageData = new ImageDataBlock(); - } - - public ImagePacketPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - ImageID.FromBytes(bytes, ref i); - ImageData.FromBytes(bytes, ref i); - } - - public ImagePacketPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - ImageID.FromBytes(bytes, ref i); - ImageData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 7; - length += ImageID.Length; - length += ImageData.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - - public override byte[] ToBytes(Interfaces.IByteBufferPool pool, ref int size) - { - int length = 7; - length += ImageID.Length; - length += ImageData.Length; - if (Header.AckList != null && Header.AckList.Length > 0) { length += Header.AckList.Length * 4 + 1; } - byte[] bytes = pool.LeaseBytes(length); - int i = 0; - Header.ToBytes(bytes, ref i); - ImageID.ToBytes(bytes, ref i); - ImageData.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - - size = length; - return bytes; - } - - public override byte[][] ToBytesMultiple(Interfaces.IByteBufferPool pool, out int[] sizes) - { - sizes = new int[1]; - return new byte[][] { this.ToBytes(pool, ref sizes[0]) }; - } - } - - /// - public sealed class LayerDataPacket : Packet - { - public override bool UsesBufferPooling - { - get - { - return true; - } - } - - /// - public sealed class LayerIDBlock : PacketBlock - { - public byte Type; - - public override int Length - { - get - { - return 1; - } - } - - public LayerIDBlock() { } - public LayerIDBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - Type = (byte)bytes[i++]; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - bytes[i++] = Type; - } - - } - - /// - public sealed class LayerDataBlock : PacketBlock - { - public byte[] Data; - - public override int Length - { - get - { - int length = 2; - if (Data != null) { length += Data.Length; } - return length; - } - } - - public LayerDataBlock() { } - public LayerDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - length = (bytes[i++] + (bytes[i++] << 8)); - Data = new byte[length]; - Buffer.BlockCopy(bytes, i, Data, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - bytes[i++] = (byte)(Data.Length % 256); - bytes[i++] = (byte)((Data.Length >> 8) % 256); - Buffer.BlockCopy(Data, 0, bytes, i, Data.Length); i += Data.Length; - } - - } - - public override int Length - { - get - { - int length = 7; - length += LayerID.Length; - length += LayerData.Length; - return length; - } - } - public LayerIDBlock LayerID; - public LayerDataBlock LayerData; - - public LayerDataPacket() - { - HasVariableBlocks = false; - Type = PacketType.LayerData; - Header = new Header(); - Header.Frequency = PacketFrequency.High; - Header.ID = 11; - Header.Reliable = true; - LayerID = new LayerIDBlock(); - LayerData = new LayerDataBlock(); - } - - public LayerDataPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - LayerID.FromBytes(bytes, ref i); - LayerData.FromBytes(bytes, ref i); - } - - public LayerDataPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - LayerID.FromBytes(bytes, ref i); - LayerData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 7; - length += LayerID.Length; - length += LayerData.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - - public override byte[] ToBytes(Interfaces.IByteBufferPool pool, ref int size) - { - int length = 7; - length += LayerID.Length; - length += LayerData.Length; - if (Header.AckList != null && Header.AckList.Length > 0) { length += Header.AckList.Length * 4 + 1; } - byte[] bytes = pool.LeaseBytes(length); - int i = 0; - Header.ToBytes(bytes, ref i); - LayerID.ToBytes(bytes, ref i); - LayerData.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - - size = length; - return bytes; - } - - public override byte[][] ToBytesMultiple(Interfaces.IByteBufferPool pool, out int[] sizes) - { - sizes = new int[1]; - return new byte[][] { this.ToBytes(pool, ref sizes[0]) }; - } - } - - /// - public sealed class ObjectUpdatePacket : Packet - { - public override bool UsesBufferPooling - { - get - { - return true; - } - } - - /// - public sealed class RegionDataBlock : PacketBlock - { - public ulong RegionHandle; - public ushort TimeDilation; - - public override int Length - { - get - { - return 10; - } - } - - public RegionDataBlock() { } - public RegionDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(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)); - TimeDilation = (ushort)(bytes[i++] + (bytes[i++] << 8)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UInt64ToBytes(RegionHandle, bytes, i); i += 8; - bytes[i++] = (byte)(TimeDilation % 256); - bytes[i++] = (byte)((TimeDilation >> 8) % 256); - } - - } - - /// - public sealed class ObjectDataBlock : PacketBlock - { - public uint ID; - public byte State; - public UUID FullID; - public uint CRC; - public byte PCode; - public byte Material; - public byte ClickAction; - public Vector3 Scale; - public byte[] ObjectData; - public uint ParentID; - public uint UpdateFlags; - public byte PathCurve; - public byte ProfileCurve; - public ushort PathBegin; - public ushort PathEnd; - public byte PathScaleX; - public byte PathScaleY; - public byte PathShearX; - public byte PathShearY; - public sbyte PathTwist; - public sbyte PathTwistBegin; - public sbyte PathRadiusOffset; - public sbyte PathTaperX; - public sbyte PathTaperY; - public byte PathRevolutions; - public sbyte PathSkew; - public ushort ProfileBegin; - public ushort ProfileEnd; - public ushort ProfileHollow; - public byte[] TextureEntry; - public byte[] TextureAnim; - public byte[] NameValue; - public byte[] Data; - public byte[] Text; - public byte[] TextColor; - public byte[] MediaURL; - public byte[] PSBlock; - public byte[] ExtraParams; - public UUID Sound; - public UUID OwnerID; - public float Gain; - public byte Flags; - public float Radius; - public byte JointType; - public Vector3 JointPivot; - public Vector3 JointAxisOrAnchor; - - public override int Length - { - get - { - int length = 153; - if (ObjectData != null) { length += (byte)ObjectData.Length; } - if (TextureEntry != null) { length += Math.Min(TextureEntry.Length, 65535); } - if (TextureAnim != null) { length += (byte)TextureAnim.Length; } - if (NameValue != null) { length += Math.Min(NameValue.Length, 65535); } - if (Data != null) { length += Math.Min(Data.Length, 65535); ; } - if (Text != null) { length += (byte)Text.Length; } - if (MediaURL != null) { length += (byte)MediaURL.Length; } - if (PSBlock != null) { length += (byte)PSBlock.Length; } - if (ExtraParams != null) { length += (byte)ExtraParams.Length; } - return length; - } - } - - public ObjectDataBlock() { } - public ObjectDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - ID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - State = (byte)bytes[i++]; - FullID.FromBytes(bytes, i); i += 16; - CRC = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - PCode = (byte)bytes[i++]; - Material = (byte)bytes[i++]; - ClickAction = (byte)bytes[i++]; - Scale.FromBytes(bytes, i); i += 12; - length = bytes[i++]; - ObjectData = new byte[length]; - Buffer.BlockCopy(bytes, i, ObjectData, 0, length); i += length; - ParentID = (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)); - PathCurve = (byte)bytes[i++]; - ProfileCurve = (byte)bytes[i++]; - PathBegin = (ushort)(bytes[i++] + (bytes[i++] << 8)); - PathEnd = (ushort)(bytes[i++] + (bytes[i++] << 8)); - PathScaleX = (byte)bytes[i++]; - PathScaleY = (byte)bytes[i++]; - PathShearX = (byte)bytes[i++]; - PathShearY = (byte)bytes[i++]; - PathTwist = (sbyte)bytes[i++]; - PathTwistBegin = (sbyte)bytes[i++]; - PathRadiusOffset = (sbyte)bytes[i++]; - PathTaperX = (sbyte)bytes[i++]; - PathTaperY = (sbyte)bytes[i++]; - PathRevolutions = (byte)bytes[i++]; - PathSkew = (sbyte)bytes[i++]; - ProfileBegin = (ushort)(bytes[i++] + (bytes[i++] << 8)); - ProfileEnd = (ushort)(bytes[i++] + (bytes[i++] << 8)); - ProfileHollow = (ushort)(bytes[i++] + (bytes[i++] << 8)); - length = (bytes[i++] + (bytes[i++] << 8)); - TextureEntry = new byte[length]; - Buffer.BlockCopy(bytes, i, TextureEntry, 0, length); i += length; - length = bytes[i++]; - TextureAnim = new byte[length]; - Buffer.BlockCopy(bytes, i, TextureAnim, 0, length); i += length; - length = (bytes[i++] + (bytes[i++] << 8)); - NameValue = new byte[length]; - Buffer.BlockCopy(bytes, i, NameValue, 0, length); i += length; - length = (bytes[i++] + (bytes[i++] << 8)); - Data = new byte[length]; - Buffer.BlockCopy(bytes, i, Data, 0, length); i += length; - length = bytes[i++]; - Text = new byte[length]; - Buffer.BlockCopy(bytes, i, Text, 0, length); i += length; - TextColor = new byte[4]; - Buffer.BlockCopy(bytes, i, TextColor, 0, 4); i += 4; - length = bytes[i++]; - MediaURL = new byte[length]; - Buffer.BlockCopy(bytes, i, MediaURL, 0, length); i += length; - length = bytes[i++]; - PSBlock = new byte[length]; - Buffer.BlockCopy(bytes, i, PSBlock, 0, length); i += length; - length = bytes[i++]; - ExtraParams = new byte[length]; - Buffer.BlockCopy(bytes, i, ExtraParams, 0, length); i += length; - Sound.FromBytes(bytes, i); i += 16; - OwnerID.FromBytes(bytes, i); i += 16; - Gain = Utils.BytesToFloat(bytes, i); i += 4; - Flags = (byte)bytes[i++]; - Radius = Utils.BytesToFloat(bytes, i); i += 4; - JointType = (byte)bytes[i++]; - JointPivot.FromBytes(bytes, i); i += 12; - JointAxisOrAnchor.FromBytes(bytes, i); i += 12; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UIntToBytes(ID, bytes, i); i += 4; - bytes[i++] = State; - FullID.ToBytes(bytes, i); i += 16; - Utils.UIntToBytes(CRC, bytes, i); i += 4; - bytes[i++] = PCode; - bytes[i++] = Material; - bytes[i++] = ClickAction; - Scale.ToBytes(bytes, i); i += 12; - bytes[i++] = (byte)ObjectData.Length; - Buffer.BlockCopy(ObjectData, 0, bytes, i, (byte)ObjectData.Length); i += (byte)ObjectData.Length; - Utils.UIntToBytes(ParentID, bytes, i); i += 4; - Utils.UIntToBytes(UpdateFlags, bytes, i); i += 4; - bytes[i++] = PathCurve; - bytes[i++] = ProfileCurve; - bytes[i++] = (byte)(PathBegin % 256); - bytes[i++] = (byte)((PathBegin >> 8) % 256); - bytes[i++] = (byte)(PathEnd % 256); - bytes[i++] = (byte)((PathEnd >> 8) % 256); - bytes[i++] = PathScaleX; - bytes[i++] = PathScaleY; - bytes[i++] = PathShearX; - bytes[i++] = PathShearY; - bytes[i++] = (byte)PathTwist; - bytes[i++] = (byte)PathTwistBegin; - bytes[i++] = (byte)PathRadiusOffset; - bytes[i++] = (byte)PathTaperX; - bytes[i++] = (byte)PathTaperY; - bytes[i++] = PathRevolutions; - bytes[i++] = (byte)PathSkew; - bytes[i++] = (byte)(ProfileBegin % 256); - bytes[i++] = (byte)((ProfileBegin >> 8) % 256); - bytes[i++] = (byte)(ProfileEnd % 256); - bytes[i++] = (byte)((ProfileEnd >> 8) % 256); - bytes[i++] = (byte)(ProfileHollow % 256); - bytes[i++] = (byte)((ProfileHollow >> 8) % 256); - - int truncTextureEntryLen = Math.Min(TextureEntry.Length, 65535); - bytes[i++] = (byte)(truncTextureEntryLen % 256); - bytes[i++] = (byte)((truncTextureEntryLen >> 8) % 256); - Buffer.BlockCopy(TextureEntry, 0, bytes, i, truncTextureEntryLen); i += truncTextureEntryLen; - - byte truncTextureAnimLen = (byte)TextureAnim.Length; - bytes[i++] = truncTextureAnimLen; - Buffer.BlockCopy(TextureAnim, 0, bytes, i, truncTextureAnimLen); i += truncTextureAnimLen; - - int truncNameValueLen = Math.Min(NameValue.Length, 65535); - bytes[i++] = (byte)(truncNameValueLen % 256); - bytes[i++] = (byte)((truncNameValueLen >> 8) % 256); - Buffer.BlockCopy(NameValue, 0, bytes, i, truncNameValueLen); i += truncNameValueLen; - - int truncDataLen = Math.Min(Data.Length, 65535); - bytes[i++] = (byte)(truncDataLen % 256); - bytes[i++] = (byte)((truncDataLen >> 8) % 256); - Buffer.BlockCopy(Data, 0, bytes, i, truncDataLen); i += truncDataLen; - - byte truncTextLen = (byte)Text.Length; - bytes[i++] = truncTextLen; - Buffer.BlockCopy(Text, 0, bytes, i, truncTextLen); i += truncTextLen; - - Buffer.BlockCopy(TextColor, 0, bytes, i, 4);i += 4; - - byte truncMediaUrlLen = (byte)MediaURL.Length; - bytes[i++] = truncMediaUrlLen; - Buffer.BlockCopy(MediaURL, 0, bytes, i, truncMediaUrlLen); i += truncMediaUrlLen; - - byte truncPsBlockLen = (byte)PSBlock.Length; - bytes[i++] = truncPsBlockLen; - Buffer.BlockCopy(PSBlock, 0, bytes, i, truncPsBlockLen); i += truncPsBlockLen; - - byte truncExtraParamsLen = (byte)ExtraParams.Length; - bytes[i++] = truncExtraParamsLen; - Buffer.BlockCopy(ExtraParams, 0, bytes, i, truncExtraParamsLen); i += truncExtraParamsLen; - - Sound.ToBytes(bytes, i); i += 16; - OwnerID.ToBytes(bytes, i); i += 16; - Utils.FloatToBytes(Gain, bytes, i); i += 4; - bytes[i++] = Flags; - Utils.FloatToBytes(Radius, bytes, i); i += 4; - bytes[i++] = JointType; - JointPivot.ToBytes(bytes, i); i += 12; - JointAxisOrAnchor.ToBytes(bytes, i); i += 12; - } - - } - - public override int Length - { - get - { - int length = 8; - length += RegionData.Length; - for (int j = 0; j < ObjectData.Length; j++) - length += ObjectData[j].Length; - return length; - } - } - public RegionDataBlock RegionData; - public ObjectDataBlock[] ObjectData; - - public ObjectUpdatePacket() - { - HasVariableBlocks = true; - Type = PacketType.ObjectUpdate; - Header = new Header(); - Header.Frequency = PacketFrequency.High; - Header.ID = 12; - Header.Reliable = true; - Header.Zerocoded = true; - RegionData = new RegionDataBlock(); - ObjectData = null; - } - - public ObjectUpdatePacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - RegionData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ObjectData == null || ObjectData.Length != -1) { - ObjectData = new ObjectDataBlock[count]; - for(int j = 0; j < count; j++) - { ObjectData[j] = new ObjectDataBlock(); } - } - for (int j = 0; j < count; j++) - { ObjectData[j].FromBytes(bytes, ref i); } - } - - public ObjectUpdatePacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - RegionData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ObjectData == null || ObjectData.Length != count) { - ObjectData = new ObjectDataBlock[count]; - for(int j = 0; j < count; j++) - { ObjectData[j] = new ObjectDataBlock(); } - } - for (int j = 0; j < count; j++) - { ObjectData[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 7; - length += RegionData.Length; - length++; - for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } - if (Header.AckList != null && 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)ObjectData.Length; - for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 7; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += RegionData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - RegionData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int ObjectDataStart = 0; - do - { - int variableLength = 0; - int ObjectDataCount = 0; - - i = ObjectDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < ObjectData.Length) { - int blockLength = ObjectData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ObjectDataStart) { - variableLength += blockLength; - ++ObjectDataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)ObjectDataCount; - for (i = ObjectDataStart; i < ObjectDataStart + ObjectDataCount; i++) { ObjectData[i].ToBytes(packet, ref length); } - ObjectDataStart += ObjectDataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - ObjectDataStart < ObjectData.Length); - - return packets.ToArray(); - } - - public override byte[] ToBytes(Interfaces.IByteBufferPool pool, ref int size) - { - int length = 7; - length += RegionData.Length; - length++; - for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } - if (Header.AckList != null && Header.AckList.Length > 0) { length += Header.AckList.Length * 4 + 1; } - byte[] bytes = pool.LeaseBytes(length); - int i = 0; - Header.ToBytes(bytes, ref i); - RegionData.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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - - size = length; - return bytes; - } - - public override byte[][] ToBytesMultiple(Interfaces.IByteBufferPool pool, out int[] sizes) - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - System.Collections.Generic.List retSizes = new System.Collections.Generic.List(); - - int i = 0; - int fixedLength = 7; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) - { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += RegionData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - RegionData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int ObjectDataStart = 0; - do - { - int variableLength = 0; - int ObjectDataCount = 0; - - i = ObjectDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < ObjectData.Length) - { - int blockLength = ObjectData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ObjectDataStart) - { - variableLength += blockLength; - ++ObjectDataCount; - } - else { break; } - ++i; - } - - int packetSize = fixedLength + variableLength + acksLength; - byte[] packet = pool.LeaseBytes(packetSize); - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)ObjectDataCount; - for (i = ObjectDataStart; i < ObjectDataStart + ObjectDataCount; i++) { ObjectData[i].ToBytes(packet, ref length); } - ObjectDataStart += ObjectDataCount; - - if (acksLength > 0) - { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - retSizes.Add(packetSize); - packets.Add(packet); - } while ( - ObjectDataStart < ObjectData.Length); - - sizes = retSizes.ToArray(); - return packets.ToArray(); - } - } - - /// - public sealed class ObjectUpdateCompressedPacket : Packet - { - public override bool UsesBufferPooling - { - get - { - return true; - } - } - - /// - public sealed class RegionDataBlock : PacketBlock - { - public ulong RegionHandle; - public ushort TimeDilation; - - public override int Length - { - get - { - return 10; - } - } - - public RegionDataBlock() { } - public RegionDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(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)); - TimeDilation = (ushort)(bytes[i++] + (bytes[i++] << 8)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UInt64ToBytes(RegionHandle, bytes, i); i += 8; - bytes[i++] = (byte)(TimeDilation % 256); - bytes[i++] = (byte)((TimeDilation >> 8) % 256); - } - - } - - /// - public sealed class ObjectDataBlock : PacketBlock - { - public uint UpdateFlags; - public byte[] Data; - - public override int Length - { - get - { - int length = 6; - if (Data != null) { length += Data.Length; } - return length; - } - } - - public ObjectDataBlock() { } - public ObjectDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - UpdateFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - length = (bytes[i++] + (bytes[i++] << 8)); - Data = new byte[length]; - Buffer.BlockCopy(bytes, i, Data, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UIntToBytes(UpdateFlags, bytes, i); i += 4; - bytes[i++] = (byte)(Data.Length % 256); - bytes[i++] = (byte)((Data.Length >> 8) % 256); - Buffer.BlockCopy(Data, 0, bytes, i, Data.Length); i += Data.Length; - } - - } - - public override int Length - { - get - { - int length = 8; - length += RegionData.Length; - for (int j = 0; j < ObjectData.Length; j++) - length += ObjectData[j].Length; - return length; - } - } - public RegionDataBlock RegionData; - public ObjectDataBlock[] ObjectData; - - public ObjectUpdateCompressedPacket() - { - HasVariableBlocks = true; - Type = PacketType.ObjectUpdateCompressed; - Header = new Header(); - Header.Frequency = PacketFrequency.High; - Header.ID = 13; - Header.Reliable = true; - RegionData = new RegionDataBlock(); - ObjectData = null; - } - - public ObjectUpdateCompressedPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - RegionData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ObjectData == null || ObjectData.Length != -1) { - ObjectData = new ObjectDataBlock[count]; - for(int j = 0; j < count; j++) - { ObjectData[j] = new ObjectDataBlock(); } - } - for (int j = 0; j < count; j++) - { ObjectData[j].FromBytes(bytes, ref i); } - } - - public ObjectUpdateCompressedPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - RegionData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ObjectData == null || ObjectData.Length != count) { - ObjectData = new ObjectDataBlock[count]; - for(int j = 0; j < count; j++) - { ObjectData[j] = new ObjectDataBlock(); } - } - for (int j = 0; j < count; j++) - { ObjectData[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 7; - length += RegionData.Length; - length++; - for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } - if (Header.AckList != null && 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)ObjectData.Length; - for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 7; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += RegionData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - RegionData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int ObjectDataStart = 0; - do - { - int variableLength = 0; - int ObjectDataCount = 0; - - i = ObjectDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < ObjectData.Length) { - int blockLength = ObjectData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ObjectDataStart) { - variableLength += blockLength; - ++ObjectDataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)ObjectDataCount; - for (i = ObjectDataStart; i < ObjectDataStart + ObjectDataCount; i++) { ObjectData[i].ToBytes(packet, ref length); } - ObjectDataStart += ObjectDataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - ObjectDataStart < ObjectData.Length); - - return packets.ToArray(); - } - - public override byte[] ToBytes(Interfaces.IByteBufferPool pool, ref int size) - { - int length = 7; - length += RegionData.Length; - length++; - for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } - if (Header.AckList != null && Header.AckList.Length > 0) { length += Header.AckList.Length * 4 + 1; } - byte[] bytes = pool.LeaseBytes(length); - int i = 0; - Header.ToBytes(bytes, ref i); - RegionData.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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - - size = length; - return bytes; - } - - public override byte[][] ToBytesMultiple(Interfaces.IByteBufferPool pool, out int[] sizes) - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - System.Collections.Generic.List retSizes = new System.Collections.Generic.List(); - - int i = 0; - int fixedLength = 7; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) - { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += RegionData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - RegionData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int ObjectDataStart = 0; - do - { - int variableLength = 0; - int ObjectDataCount = 0; - - i = ObjectDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < ObjectData.Length) - { - int blockLength = ObjectData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU) - { - variableLength += blockLength; - ++ObjectDataCount; - } - else { break; } - ++i; - } - - int packetSize = fixedLength + variableLength + acksLength; - byte[] packet = pool.LeaseBytes(packetSize); - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)ObjectDataCount; - for (i = ObjectDataStart; i < ObjectDataStart + ObjectDataCount; i++) { ObjectData[i].ToBytes(packet, ref length); } - ObjectDataStart += ObjectDataCount; - - if (acksLength > 0) - { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - retSizes.Add(packetSize); - packets.Add(packet); - } while ( - ObjectDataStart < ObjectData.Length); - - sizes = retSizes.ToArray(); - return packets.ToArray(); - } - } - - /// - public sealed class ObjectUpdateCachedPacket : Packet - { - public override bool UsesBufferPooling - { - get - { - return true; - } - } - - /// - public sealed class RegionDataBlock : PacketBlock - { - public ulong RegionHandle; - public ushort TimeDilation; - - public override int Length - { - get - { - return 10; - } - } - - public RegionDataBlock() { } - public RegionDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(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)); - TimeDilation = (ushort)(bytes[i++] + (bytes[i++] << 8)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UInt64ToBytes(RegionHandle, bytes, i); i += 8; - bytes[i++] = (byte)(TimeDilation % 256); - bytes[i++] = (byte)((TimeDilation >> 8) % 256); - } - - } - - /// - public sealed class ObjectDataBlock : PacketBlock - { - public uint ID; - public uint CRC; - public uint UpdateFlags; - - public override int Length - { - get - { - return 12; - } - } - - public ObjectDataBlock() { } - public ObjectDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - ID = (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)); - UpdateFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UIntToBytes(ID, bytes, i); i += 4; - Utils.UIntToBytes(CRC, bytes, i); i += 4; - Utils.UIntToBytes(UpdateFlags, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 8; - length += RegionData.Length; - for (int j = 0; j < ObjectData.Length; j++) - length += ObjectData[j].Length; - return length; - } - } - public RegionDataBlock RegionData; - public ObjectDataBlock[] ObjectData; - - public ObjectUpdateCachedPacket() - { - HasVariableBlocks = true; - Type = PacketType.ObjectUpdateCached; - Header = new Header(); - Header.Frequency = PacketFrequency.High; - Header.ID = 14; - Header.Reliable = true; - RegionData = new RegionDataBlock(); - ObjectData = null; - } - - public ObjectUpdateCachedPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - RegionData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ObjectData == null || ObjectData.Length != -1) { - ObjectData = new ObjectDataBlock[count]; - for(int j = 0; j < count; j++) - { ObjectData[j] = new ObjectDataBlock(); } - } - for (int j = 0; j < count; j++) - { ObjectData[j].FromBytes(bytes, ref i); } - } - - public ObjectUpdateCachedPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - RegionData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ObjectData == null || ObjectData.Length != count) { - ObjectData = new ObjectDataBlock[count]; - for(int j = 0; j < count; j++) - { ObjectData[j] = new ObjectDataBlock(); } - } - for (int j = 0; j < count; j++) - { ObjectData[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 7; - length += RegionData.Length; - length++; - for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } - if (Header.AckList != null && 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)ObjectData.Length; - for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 7; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += RegionData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - RegionData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int ObjectDataStart = 0; - do - { - int variableLength = 0; - int ObjectDataCount = 0; - - i = ObjectDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < ObjectData.Length) { - int blockLength = ObjectData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ObjectDataStart) { - variableLength += blockLength; - ++ObjectDataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)ObjectDataCount; - for (i = ObjectDataStart; i < ObjectDataStart + ObjectDataCount; i++) { ObjectData[i].ToBytes(packet, ref length); } - ObjectDataStart += ObjectDataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - ObjectDataStart < ObjectData.Length); - - return packets.ToArray(); - } - - public override byte[] ToBytes(Interfaces.IByteBufferPool pool, ref int size) - { - int length = 7; - length += RegionData.Length; - length++; - for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } - if (Header.AckList != null && Header.AckList.Length > 0) { length += Header.AckList.Length * 4 + 1; } - byte[] bytes = pool.LeaseBytes(length); - int i = 0; - Header.ToBytes(bytes, ref i); - RegionData.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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - - size = length; - return bytes; - } - - public override byte[][] ToBytesMultiple(Interfaces.IByteBufferPool pool, out int[] sizes) - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - System.Collections.Generic.List retSizes = new System.Collections.Generic.List(); - - int i = 0; - int fixedLength = 7; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) - { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += RegionData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - RegionData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int ObjectDataStart = 0; - do - { - int variableLength = 0; - int ObjectDataCount = 0; - - i = ObjectDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < ObjectData.Length) - { - int blockLength = ObjectData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU) - { - variableLength += blockLength; - ++ObjectDataCount; - } - else { break; } - ++i; - } - - int packetSize = fixedLength + variableLength + acksLength; - byte[] packet = pool.LeaseBytes(packetSize); - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)ObjectDataCount; - for (i = ObjectDataStart; i < ObjectDataStart + ObjectDataCount; i++) { ObjectData[i].ToBytes(packet, ref length); } - ObjectDataStart += ObjectDataCount; - - if (acksLength > 0) - { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - retSizes.Add(packetSize); - packets.Add(packet); - } while ( - ObjectDataStart < ObjectData.Length); - - sizes = retSizes.ToArray(); - return packets.ToArray(); - } - } - - /// - public sealed class ImprovedTerseObjectUpdatePacket : Packet - { - public override bool UsesBufferPooling - { - get - { - return true; - } - } - - /// - public sealed class RegionDataBlock : PacketBlock - { - public ulong RegionHandle; - public ushort TimeDilation; - - public override int Length - { - get - { - return 10; - } - } - - public RegionDataBlock() { } - public RegionDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(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)); - TimeDilation = (ushort)(bytes[i++] + (bytes[i++] << 8)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UInt64ToBytes(RegionHandle, bytes, i); i += 8; - bytes[i++] = (byte)(TimeDilation % 256); - bytes[i++] = (byte)((TimeDilation >> 8) % 256); - } - - } - - /// - public sealed class ObjectDataBlock : PacketBlock - { - public byte[] Data; - public byte[] TextureEntry; - - public override int Length - { - get - { - int length = 3; - if (Data != null) { length += Data.Length; } - if (TextureEntry != null) { length += TextureEntry.Length; } - return length; - } - } - - public ObjectDataBlock() { } - public ObjectDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - length = bytes[i++]; - Data = new byte[length]; - Buffer.BlockCopy(bytes, i, Data, 0, length); i += length; - length = (bytes[i++] + (bytes[i++] << 8)); - TextureEntry = new byte[length]; - Buffer.BlockCopy(bytes, i, TextureEntry, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - bytes[i++] = (byte)Data.Length; - Buffer.BlockCopy(Data, 0, bytes, i, Data.Length); i += Data.Length; - bytes[i++] = (byte)(TextureEntry.Length % 256); - bytes[i++] = (byte)((TextureEntry.Length >> 8) % 256); - Buffer.BlockCopy(TextureEntry, 0, bytes, i, TextureEntry.Length); i += TextureEntry.Length; - } - - } - - public override int Length - { - get - { - int length = 8; - length += RegionData.Length; - for (int j = 0; j < ObjectData.Length; j++) - length += ObjectData[j].Length; - return length; - } - } - public RegionDataBlock RegionData; - public ObjectDataBlock[] ObjectData; - - public ImprovedTerseObjectUpdatePacket() - { - HasVariableBlocks = true; - Type = PacketType.ImprovedTerseObjectUpdate; - Header = new Header(); - Header.Frequency = PacketFrequency.High; - Header.ID = 15; - Header.Reliable = true; - RegionData = new RegionDataBlock(); - ObjectData = null; - } - - public ImprovedTerseObjectUpdatePacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - RegionData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ObjectData == null || ObjectData.Length != -1) { - ObjectData = new ObjectDataBlock[count]; - for(int j = 0; j < count; j++) - { ObjectData[j] = new ObjectDataBlock(); } - } - for (int j = 0; j < count; j++) - { ObjectData[j].FromBytes(bytes, ref i); } - } - - public ImprovedTerseObjectUpdatePacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - RegionData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(ObjectData == null || ObjectData.Length != count) { - ObjectData = new ObjectDataBlock[count]; - for(int j = 0; j < count; j++) - { ObjectData[j] = new ObjectDataBlock(); } - } - for (int j = 0; j < count; j++) - { ObjectData[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 7; - length += RegionData.Length; - length++; - for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } - if (Header.AckList != null && 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)ObjectData.Length; - for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 7; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += RegionData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - RegionData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int ObjectDataStart = 0; - do - { - int variableLength = 0; - int ObjectDataCount = 0; - - i = ObjectDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < ObjectData.Length) { - int blockLength = ObjectData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ObjectDataStart) { - variableLength += blockLength; - ++ObjectDataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)ObjectDataCount; - for (i = ObjectDataStart; i < ObjectDataStart + ObjectDataCount; i++) { ObjectData[i].ToBytes(packet, ref length); } - ObjectDataStart += ObjectDataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - ObjectDataStart < ObjectData.Length); - - return packets.ToArray(); - } - - public override byte[] ToBytes(Interfaces.IByteBufferPool pool, ref int size) - { - int length = 7; - length += RegionData.Length; - length++; - for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } - if (Header.AckList != null && Header.AckList.Length > 0) { length += Header.AckList.Length * 4 + 1; } - byte[] bytes = pool.LeaseBytes(length); - int i = 0; - Header.ToBytes(bytes, ref i); - RegionData.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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - - size = length; - return bytes; - } - - public override byte[][] ToBytesMultiple(Interfaces.IByteBufferPool pool, out int[] sizes) - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - System.Collections.Generic.List retSizes = new System.Collections.Generic.List(); - - - int i = 0; - int fixedLength = 7; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) - { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += RegionData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - RegionData.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int ObjectDataStart = 0; - do - { - int variableLength = 0; - int ObjectDataCount = 0; - - i = ObjectDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < ObjectData.Length) - { - int blockLength = ObjectData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU) - { - variableLength += blockLength; - ++ObjectDataCount; - } - else { break; } - ++i; - } - - int packetSize = fixedLength + variableLength + acksLength; - byte[] packet = pool.LeaseBytes(packetSize); - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)ObjectDataCount; - for (i = ObjectDataStart; i < ObjectDataStart + ObjectDataCount; i++) { ObjectData[i].ToBytes(packet, ref length); } - ObjectDataStart += ObjectDataCount; - - if (acksLength > 0) - { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - retSizes.Add(packetSize); - packets.Add(packet); - } while ( - ObjectDataStart < ObjectData.Length); - - sizes = retSizes.ToArray(); - return packets.ToArray(); - } - } - - /// - public sealed class KillObjectPacket : Packet - { - public override bool UsesBufferPooling - { - get - { - return true; - } - } - - /// - public sealed class ObjectDataBlock : PacketBlock - { - public uint ID; - - public override int Length - { - get - { - return 4; - } - } - - public ObjectDataBlock() { } - public ObjectDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - ID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UIntToBytes(ID, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 8; - for (int j = 0; j < ObjectData.Length; j++) - length += ObjectData[j].Length; - return length; - } - } - public ObjectDataBlock[] ObjectData; - - public KillObjectPacket() - { - HasVariableBlocks = true; - Type = PacketType.KillObject; - Header = new Header(); - Header.Frequency = PacketFrequency.High; - Header.ID = 16; - Header.Reliable = true; - ObjectData = null; - } - - public KillObjectPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - int count = (int)bytes[i++]; - if(ObjectData == null || ObjectData.Length != -1) { - ObjectData = new ObjectDataBlock[count]; - for(int j = 0; j < count; j++) - { ObjectData[j] = new ObjectDataBlock(); } - } - for (int j = 0; j < count; j++) - { ObjectData[j].FromBytes(bytes, ref i); } - } - - public KillObjectPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - int count = (int)bytes[i++]; - if(ObjectData == null || ObjectData.Length != count) { - ObjectData = new ObjectDataBlock[count]; - for(int j = 0; j < count; j++) - { ObjectData[j] = new ObjectDataBlock(); } - } - for (int j = 0; j < count; j++) - { ObjectData[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 7; - length++; - for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 7; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int ObjectDataStart = 0; - do - { - int variableLength = 0; - int ObjectDataCount = 0; - - i = ObjectDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < ObjectData.Length) { - int blockLength = ObjectData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ObjectDataStart) { - variableLength += blockLength; - ++ObjectDataCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)ObjectDataCount; - for (i = ObjectDataStart; i < ObjectDataStart + ObjectDataCount; i++) { ObjectData[i].ToBytes(packet, ref length); } - ObjectDataStart += ObjectDataCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - ObjectDataStart < ObjectData.Length); - - return packets.ToArray(); - } - - public override byte[] ToBytes(Interfaces.IByteBufferPool pool, ref int size) - { - int length = 7; - length++; - for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } - if (Header.AckList != null && Header.AckList.Length > 0) { length += Header.AckList.Length * 4 + 1; } - byte[] bytes = pool.LeaseBytes(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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - - size = length; - return bytes; - } - - public override byte[][] ToBytesMultiple(Interfaces.IByteBufferPool pool, out int[] sizes) - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - System.Collections.Generic.List retSizes = new System.Collections.Generic.List(); - - int i = 0; - int fixedLength = 7; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) - { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int ObjectDataStart = 0; - do - { - int variableLength = 0; - int ObjectDataCount = 0; - - i = ObjectDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < ObjectData.Length) - { - int blockLength = ObjectData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU) - { - variableLength += blockLength; - ++ObjectDataCount; - } - else { break; } - ++i; - } - - int packetSize = fixedLength + variableLength + acksLength; - byte[] packet = pool.LeaseBytes(packetSize); - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)ObjectDataCount; - for (i = ObjectDataStart; i < ObjectDataStart + ObjectDataCount; i++) { ObjectData[i].ToBytes(packet, ref length); } - ObjectDataStart += ObjectDataCount; - - if (acksLength > 0) - { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - retSizes.Add(packetSize); - packets.Add(packet); - } while ( - ObjectDataStart < ObjectData.Length); - - sizes = retSizes.ToArray(); - return packets.ToArray(); - } - } - - /// - public sealed class TransferPacketPacket : Packet - { - public override bool UsesBufferPooling - { - get - { - return true; - } - } - - /// - public sealed class TransferDataBlock : PacketBlock - { - public UUID TransferID; - public int ChannelType; - public int Packet; - public int Status; - public byte[] Data; - - public override int Length - { - get - { - int length = 30; - if (Data != null) { length += Data.Length; } - return length; - } - } - - public TransferDataBlock() { } - public TransferDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - TransferID.FromBytes(bytes, i); i += 16; - ChannelType = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - Packet = (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)); - length = (bytes[i++] + (bytes[i++] << 8)); - Data = new byte[length]; - Buffer.BlockCopy(bytes, i, Data, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - TransferID.ToBytes(bytes, i); i += 16; - Utils.IntToBytes(ChannelType, bytes, i); i += 4; - Utils.IntToBytes(Packet, bytes, i); i += 4; - Utils.IntToBytes(Status, bytes, i); i += 4; - bytes[i++] = (byte)(Data.Length % 256); - bytes[i++] = (byte)((Data.Length >> 8) % 256); - Buffer.BlockCopy(Data, 0, bytes, i, Data.Length); i += Data.Length; - } - - } - - public override int Length - { - get - { - int length = 7; - length += TransferData.Length; - return length; - } - } - public TransferDataBlock TransferData; - - public TransferPacketPacket() - { - HasVariableBlocks = false; - Type = PacketType.TransferPacket; - Header = new Header(); - Header.Frequency = PacketFrequency.High; - Header.ID = 17; - Header.Reliable = true; - TransferData = new TransferDataBlock(); - } - - public TransferPacketPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - TransferData.FromBytes(bytes, ref i); - } - - public TransferPacketPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - TransferData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 7; - length += TransferData.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - - public override byte[] ToBytes(Interfaces.IByteBufferPool pool, ref int size) - { - int length = 7; - length += TransferData.Length; - if (Header.AckList != null && Header.AckList.Length > 0) { length += Header.AckList.Length * 4 + 1; } - byte[] bytes = pool.LeaseBytes(length); - int i = 0; - Header.ToBytes(bytes, ref i); - TransferData.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - - size = length; - return bytes; - } - - public override byte[][] ToBytesMultiple(Interfaces.IByteBufferPool pool, out int[] sizes) - { - sizes = new int[1]; - return new byte[][] { this.ToBytes(pool, ref sizes[0]) }; - } - } - - /// - public sealed class SendXferPacketPacket : Packet - { - public override bool UsesBufferPooling - { - get - { - return true; - } - } - - /// - public sealed class XferIDBlock : PacketBlock - { - public ulong ID; - public uint Packet; - - public override int Length - { - get - { - return 12; - } - } - - public XferIDBlock() { } - public XferIDBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(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(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UInt64ToBytes(ID, bytes, i); i += 8; - Utils.UIntToBytes(Packet, bytes, i); i += 4; - } - - } - - /// - public sealed class DataPacketBlock : PacketBlock - { - public byte[] Data; - - public override int Length - { - get - { - int length = 2; - if (Data != null) { length += Data.Length; } - return length; - } - } - - public DataPacketBlock() { } - public DataPacketBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - length = (bytes[i++] + (bytes[i++] << 8)); - Data = new byte[length]; - Buffer.BlockCopy(bytes, i, Data, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - bytes[i++] = (byte)(Data.Length % 256); - bytes[i++] = (byte)((Data.Length >> 8) % 256); - Buffer.BlockCopy(Data, 0, bytes, i, Data.Length); i += Data.Length; - } - - } - - public override int Length - { - get - { - int length = 7; - length += XferID.Length; - length += DataPacket.Length; - return length; - } - } - public XferIDBlock XferID; - public DataPacketBlock DataPacket; - - public SendXferPacketPacket() - { - HasVariableBlocks = false; - Type = PacketType.SendXferPacket; - Header = new Header(); - Header.Frequency = PacketFrequency.High; - Header.ID = 18; - Header.Reliable = true; - XferID = new XferIDBlock(); - DataPacket = new DataPacketBlock(); - } - - public SendXferPacketPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - XferID.FromBytes(bytes, ref i); - DataPacket.FromBytes(bytes, ref i); - } - - public SendXferPacketPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - XferID.FromBytes(bytes, ref i); - DataPacket.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 7; - length += XferID.Length; - length += DataPacket.Length; - if (Header.AckList != null && 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); - DataPacket.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - - public override byte[] ToBytes(Interfaces.IByteBufferPool pool, ref int size) - { - int length = 7; - length += XferID.Length; - length += DataPacket.Length; - if (Header.AckList != null && Header.AckList.Length > 0) { length += Header.AckList.Length * 4 + 1; } - byte[] bytes = pool.LeaseBytes(length); - int i = 0; - Header.ToBytes(bytes, ref i); - XferID.ToBytes(bytes, ref i); - DataPacket.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - - size = length; - return bytes; - } - - public override byte[][] ToBytesMultiple(Interfaces.IByteBufferPool pool, out int[] sizes) - { - sizes = new int[1]; - return new byte[][] { this.ToBytes(pool, ref sizes[0]) }; - } - } - - /// - public sealed class ConfirmXferPacketPacket : Packet - { - public override bool UsesBufferPooling - { - get - { - return true; - } - } - - /// - public sealed class XferIDBlock : PacketBlock - { - public ulong ID; - public uint Packet; - - public override int Length - { - get - { - return 12; - } - } - - public XferIDBlock() { } - public XferIDBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(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(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UInt64ToBytes(ID, bytes, i); i += 8; - Utils.UIntToBytes(Packet, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 7; - length += XferID.Length; - return length; - } - } - public XferIDBlock XferID; - - public ConfirmXferPacketPacket() - { - HasVariableBlocks = false; - Type = PacketType.ConfirmXferPacket; - Header = new Header(); - Header.Frequency = PacketFrequency.High; - Header.ID = 19; - Header.Reliable = true; - XferID = new XferIDBlock(); - } - - public ConfirmXferPacketPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - XferID.FromBytes(bytes, ref i); - } - - public ConfirmXferPacketPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - XferID.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 7; - length += XferID.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - - public override byte[] ToBytes(Interfaces.IByteBufferPool pool, ref int size) - { - int length = 7; - length += XferID.Length; - if (Header.AckList != null && Header.AckList.Length > 0) { length += Header.AckList.Length * 4 + 1; } - byte[] bytes = pool.LeaseBytes(length); - int i = 0; - Header.ToBytes(bytes, ref i); - XferID.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - - size = length; - return bytes; - } - - public override byte[][] ToBytesMultiple(Interfaces.IByteBufferPool pool, out int[] sizes) - { - sizes = new int[1]; - return new byte[][] { this.ToBytes(pool, ref sizes[0]) }; - } - } - - /// - public sealed class AvatarAnimationPacket : Packet - { - public override bool UsesBufferPooling - { - get - { - return true; - } - } - - /// - public sealed class SenderBlock : PacketBlock - { - public UUID ID; - - public override int Length - { - get - { - return 16; - } - } - - public SenderBlock() { } - public SenderBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - ID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - ID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class AnimationListBlock : PacketBlock - { - public UUID AnimID; - public int AnimSequenceID; - - public override int Length - { - get - { - return 20; - } - } - - public AnimationListBlock() { } - public AnimationListBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AnimID.FromBytes(bytes, i); i += 16; - AnimSequenceID = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AnimID.ToBytes(bytes, i); i += 16; - Utils.IntToBytes(AnimSequenceID, bytes, i); i += 4; - } - - } - - /// - public sealed class AnimationSourceListBlock : PacketBlock - { - public UUID ObjectID; - - public override int Length - { - get - { - return 16; - } - } - - public AnimationSourceListBlock() { } - public AnimationSourceListBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - ObjectID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - ObjectID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class PhysicalAvatarEventListBlock : PacketBlock - { - public byte[] TypeData; - - public override int Length - { - get - { - int length = 1; - if (TypeData != null) { length += TypeData.Length; } - return length; - } - } - - public PhysicalAvatarEventListBlock() { } - public PhysicalAvatarEventListBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - length = bytes[i++]; - TypeData = new byte[length]; - Buffer.BlockCopy(bytes, i, TypeData, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - bytes[i++] = (byte)TypeData.Length; - Buffer.BlockCopy(TypeData, 0, bytes, i, TypeData.Length); i += TypeData.Length; - } - - } - - public override int Length - { - get - { - int length = 10; - length += Sender.Length; - for (int j = 0; j < AnimationList.Length; j++) - length += AnimationList[j].Length; - for (int j = 0; j < AnimationSourceList.Length; j++) - length += AnimationSourceList[j].Length; - for (int j = 0; j < PhysicalAvatarEventList.Length; j++) - length += PhysicalAvatarEventList[j].Length; - return length; - } - } - public SenderBlock Sender; - public AnimationListBlock[] AnimationList; - public AnimationSourceListBlock[] AnimationSourceList; - public PhysicalAvatarEventListBlock[] PhysicalAvatarEventList; - - public AvatarAnimationPacket() - { - HasVariableBlocks = true; - Type = PacketType.AvatarAnimation; - Header = new Header(); - Header.Frequency = PacketFrequency.High; - Header.ID = 20; - Header.Reliable = true; - Sender = new SenderBlock(); - AnimationList = null; - AnimationSourceList = null; - PhysicalAvatarEventList = null; - } - - public AvatarAnimationPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - Sender.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(AnimationList == null || AnimationList.Length != -1) { - AnimationList = new AnimationListBlock[count]; - for(int j = 0; j < count; j++) - { AnimationList[j] = new AnimationListBlock(); } - } - for (int j = 0; j < count; j++) - { AnimationList[j].FromBytes(bytes, ref i); } - count = (int)bytes[i++]; - if(AnimationSourceList == null || AnimationSourceList.Length != -1) { - AnimationSourceList = new AnimationSourceListBlock[count]; - for(int j = 0; j < count; j++) - { AnimationSourceList[j] = new AnimationSourceListBlock(); } - } - for (int j = 0; j < count; j++) - { AnimationSourceList[j].FromBytes(bytes, ref i); } - count = (int)bytes[i++]; - if(PhysicalAvatarEventList == null || PhysicalAvatarEventList.Length != -1) { - PhysicalAvatarEventList = new PhysicalAvatarEventListBlock[count]; - for(int j = 0; j < count; j++) - { PhysicalAvatarEventList[j] = new PhysicalAvatarEventListBlock(); } - } - for (int j = 0; j < count; j++) - { PhysicalAvatarEventList[j].FromBytes(bytes, ref i); } - } - - public AvatarAnimationPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - Sender.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(AnimationList == null || AnimationList.Length != count) { - AnimationList = new AnimationListBlock[count]; - for(int j = 0; j < count; j++) - { AnimationList[j] = new AnimationListBlock(); } - } - for (int j = 0; j < count; j++) - { AnimationList[j].FromBytes(bytes, ref i); } - count = (int)bytes[i++]; - if(AnimationSourceList == null || AnimationSourceList.Length != count) { - AnimationSourceList = new AnimationSourceListBlock[count]; - for(int j = 0; j < count; j++) - { AnimationSourceList[j] = new AnimationSourceListBlock(); } - } - for (int j = 0; j < count; j++) - { AnimationSourceList[j].FromBytes(bytes, ref i); } - count = (int)bytes[i++]; - if(PhysicalAvatarEventList == null || PhysicalAvatarEventList.Length != count) { - PhysicalAvatarEventList = new PhysicalAvatarEventListBlock[count]; - for(int j = 0; j < count; j++) - { PhysicalAvatarEventList[j] = new PhysicalAvatarEventListBlock(); } - } - for (int j = 0; j < count; j++) - { PhysicalAvatarEventList[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 7; - length += Sender.Length; - length++; - for (int j = 0; j < AnimationList.Length; j++) { length += AnimationList[j].Length; } - length++; - for (int j = 0; j < AnimationSourceList.Length; j++) { length += AnimationSourceList[j].Length; } - length++; - for (int j = 0; j < PhysicalAvatarEventList.Length; j++) { length += PhysicalAvatarEventList[j].Length; } - if (Header.AckList != null && 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); - bytes[i++] = (byte)AnimationList.Length; - for (int j = 0; j < AnimationList.Length; j++) { AnimationList[j].ToBytes(bytes, ref i); } - bytes[i++] = (byte)AnimationSourceList.Length; - for (int j = 0; j < AnimationSourceList.Length; j++) { AnimationSourceList[j].ToBytes(bytes, ref i); } - bytes[i++] = (byte)PhysicalAvatarEventList.Length; - for (int j = 0; j < PhysicalAvatarEventList.Length; j++) { PhysicalAvatarEventList[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 7; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += Sender.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - Sender.ToBytes(fixedBytes, ref i); - fixedLength += 3; - - int AnimationListStart = 0; - int AnimationSourceListStart = 0; - int PhysicalAvatarEventListStart = 0; - do - { - int variableLength = 0; - int AnimationListCount = 0; - int AnimationSourceListCount = 0; - int PhysicalAvatarEventListCount = 0; - - i = AnimationListStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < AnimationList.Length) { - int blockLength = AnimationList[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == AnimationListStart) { - variableLength += blockLength; - ++AnimationListCount; - } - else { break; } - ++i; - } - - i = AnimationSourceListStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < AnimationSourceList.Length) { - int blockLength = AnimationSourceList[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == AnimationSourceListStart) { - variableLength += blockLength; - ++AnimationSourceListCount; - } - else { break; } - ++i; - } - - i = PhysicalAvatarEventListStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < PhysicalAvatarEventList.Length) { - int blockLength = PhysicalAvatarEventList[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == PhysicalAvatarEventListStart) { - variableLength += blockLength; - ++PhysicalAvatarEventListCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)AnimationListCount; - for (i = AnimationListStart; i < AnimationListStart + AnimationListCount; i++) { AnimationList[i].ToBytes(packet, ref length); } - AnimationListStart += AnimationListCount; - - packet[length++] = (byte)AnimationSourceListCount; - for (i = AnimationSourceListStart; i < AnimationSourceListStart + AnimationSourceListCount; i++) { AnimationSourceList[i].ToBytes(packet, ref length); } - AnimationSourceListStart += AnimationSourceListCount; - - packet[length++] = (byte)PhysicalAvatarEventListCount; - for (i = PhysicalAvatarEventListStart; i < PhysicalAvatarEventListStart + PhysicalAvatarEventListCount; i++) { PhysicalAvatarEventList[i].ToBytes(packet, ref length); } - PhysicalAvatarEventListStart += PhysicalAvatarEventListCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - AnimationListStart < AnimationList.Length || - AnimationSourceListStart < AnimationSourceList.Length || - PhysicalAvatarEventListStart < PhysicalAvatarEventList.Length); - - return packets.ToArray(); - } - - public override byte[] ToBytes(Interfaces.IByteBufferPool pool, ref int size) - { - int length = 7; - length += Sender.Length; - length++; - for (int j = 0; j < AnimationList.Length; j++) { length += AnimationList[j].Length; } - length++; - for (int j = 0; j < AnimationSourceList.Length; j++) { length += AnimationSourceList[j].Length; } - length++; - for (int j = 0; j < PhysicalAvatarEventList.Length; j++) { length += PhysicalAvatarEventList[j].Length; } - if (Header.AckList != null && Header.AckList.Length > 0) { length += Header.AckList.Length * 4 + 1; } - byte[] bytes = pool.LeaseBytes(length); - int i = 0; - Header.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); } - bytes[i++] = (byte)AnimationSourceList.Length; - for (int j = 0; j < AnimationSourceList.Length; j++) { AnimationSourceList[j].ToBytes(bytes, ref i); } - bytes[i++] = (byte)PhysicalAvatarEventList.Length; - for (int j = 0; j < PhysicalAvatarEventList.Length; j++) { PhysicalAvatarEventList[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - - size = length; - return bytes; - } - - public override byte[][] ToBytesMultiple(Interfaces.IByteBufferPool pool, out int[] sizes) - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - System.Collections.Generic.List retSizes = new System.Collections.Generic.List(); - - int i = 0; - int fixedLength = 7; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) - { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += Sender.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - Sender.ToBytes(fixedBytes, ref i); - fixedLength += 3; - - int AnimationListStart = 0; - int AnimationSourceListStart = 0; - int PhysicalAvatarEventListStart = 0; - do - { - int variableLength = 0; - int AnimationListCount = 0; - int AnimationSourceListCount = 0; - int PhysicalAvatarEventListCount = 0; - - i = AnimationListStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < AnimationList.Length) - { - int blockLength = AnimationList[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU) - { - variableLength += blockLength; - ++AnimationListCount; - } - else { break; } - ++i; - } - - i = AnimationSourceListStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < AnimationSourceList.Length) - { - int blockLength = AnimationSourceList[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU) - { - variableLength += blockLength; - ++AnimationSourceListCount; - } - else { break; } - ++i; - } - - i = PhysicalAvatarEventListStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < PhysicalAvatarEventList.Length) - { - int blockLength = PhysicalAvatarEventList[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU) - { - variableLength += blockLength; - ++PhysicalAvatarEventListCount; - } - else { break; } - ++i; - } - - int packetSize = fixedLength + variableLength + acksLength; - byte[] packet = pool.LeaseBytes(packetSize); - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)AnimationListCount; - for (i = AnimationListStart; i < AnimationListStart + AnimationListCount; i++) { AnimationList[i].ToBytes(packet, ref length); } - AnimationListStart += AnimationListCount; - - packet[length++] = (byte)AnimationSourceListCount; - for (i = AnimationSourceListStart; i < AnimationSourceListStart + AnimationSourceListCount; i++) { AnimationSourceList[i].ToBytes(packet, ref length); } - AnimationSourceListStart += AnimationSourceListCount; - - packet[length++] = (byte)PhysicalAvatarEventListCount; - for (i = PhysicalAvatarEventListStart; i < PhysicalAvatarEventListStart + PhysicalAvatarEventListCount; i++) { PhysicalAvatarEventList[i].ToBytes(packet, ref length); } - PhysicalAvatarEventListStart += PhysicalAvatarEventListCount; - - if (acksLength > 0) - { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - retSizes.Add(packetSize); - packets.Add(packet); - } while ( - AnimationListStart < AnimationList.Length || - AnimationSourceListStart < AnimationSourceList.Length || - PhysicalAvatarEventListStart < PhysicalAvatarEventList.Length); - - sizes = retSizes.ToArray(); - return packets.ToArray(); - } - } - - /// - public sealed class AvatarSitResponsePacket : Packet - { - public override bool UsesBufferPooling - { - get - { - return true; - } - } - - /// - public sealed class SitObjectBlock : PacketBlock - { - public UUID ID; - - public override int Length - { - get - { - return 16; - } - } - - public SitObjectBlock() { } - public SitObjectBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - ID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - ID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class SitTransformBlock : PacketBlock - { - public bool AutoPilot; - public Vector3 SitPosition; - public Quaternion SitRotation; - public Vector3 CameraEyeOffset; - public Vector3 CameraAtOffset; - public bool ForceMouselook; - - public override int Length - { - get - { - return 50; - } - } - - public SitTransformBlock() { } - public SitTransformBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AutoPilot = (bytes[i++] != 0) ? (bool)true : (bool)false; - SitPosition.FromBytes(bytes, i); i += 12; - SitRotation.FromBytes(bytes, i, true); i += 12; - CameraEyeOffset.FromBytes(bytes, i); i += 12; - CameraAtOffset.FromBytes(bytes, i); i += 12; - ForceMouselook = (bytes[i++] != 0) ? (bool)true : (bool)false; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - bytes[i++] = (byte)((AutoPilot) ? 1 : 0); - SitPosition.ToBytes(bytes, i); i += 12; - SitRotation.ToBytes(bytes, i); i += 12; - CameraEyeOffset.ToBytes(bytes, i); i += 12; - CameraAtOffset.ToBytes(bytes, i); i += 12; - bytes[i++] = (byte)((ForceMouselook) ? 1 : 0); - } - - } - - public override int Length - { - get - { - int length = 7; - length += SitObject.Length; - length += SitTransform.Length; - return length; - } - } - public SitObjectBlock SitObject; - public SitTransformBlock SitTransform; - - public AvatarSitResponsePacket() - { - HasVariableBlocks = false; - Type = PacketType.AvatarSitResponse; - Header = new Header(); - Header.Frequency = PacketFrequency.High; - Header.ID = 21; - Header.Reliable = true; - Header.Zerocoded = true; - SitObject = new SitObjectBlock(); - SitTransform = new SitTransformBlock(); - } - - public AvatarSitResponsePacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - SitObject.FromBytes(bytes, ref i); - SitTransform.FromBytes(bytes, ref i); - } - - public AvatarSitResponsePacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - SitObject.FromBytes(bytes, ref i); - SitTransform.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 7; - length += SitObject.Length; - length += SitTransform.Length; - if (Header.AckList != null && Header.AckList.Length > 0) { length += Header.AckList.Length * 4 + 1; } - byte[] bytes = new byte[length]; - int i = 0; - Header.ToBytes(bytes, ref i); - SitObject.ToBytes(bytes, ref i); - SitTransform.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - - public override byte[] ToBytes(Interfaces.IByteBufferPool pool, ref int size) - { - int length = 7; - length += SitObject.Length; - length += SitTransform.Length; - if (Header.AckList != null && Header.AckList.Length > 0) { length += Header.AckList.Length * 4 + 1; } - byte[] bytes = pool.LeaseBytes(length); - int i = 0; - Header.ToBytes(bytes, ref i); - SitObject.ToBytes(bytes, ref i); - SitTransform.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - - size = length; - return bytes; - } - - public override byte[][] ToBytesMultiple(Interfaces.IByteBufferPool pool, out int[] sizes) - { - sizes = new int[1]; - return new byte[][] { this.ToBytes(pool, ref sizes[0]) }; - } - } - - /// - public sealed class CameraConstraintPacket : Packet - { - public override bool UsesBufferPooling - { - get - { - return true; - } - } - - /// - public sealed class CameraCollidePlaneBlock : PacketBlock - { - public Vector4 Plane; - - public override int Length - { - get - { - return 16; - } - } - - public CameraCollidePlaneBlock() { } - public CameraCollidePlaneBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - Plane.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Plane.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 7; - length += CameraCollidePlane.Length; - return length; - } - } - public CameraCollidePlaneBlock CameraCollidePlane; - - public CameraConstraintPacket() - { - HasVariableBlocks = false; - Type = PacketType.CameraConstraint; - Header = new Header(); - Header.Frequency = PacketFrequency.High; - Header.ID = 22; - Header.Reliable = true; - Header.Zerocoded = true; - CameraCollidePlane = new CameraCollidePlaneBlock(); - } - - public CameraConstraintPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - CameraCollidePlane.FromBytes(bytes, ref i); - } - - public CameraConstraintPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - CameraCollidePlane.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 7; - length += CameraCollidePlane.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - - public override byte[] ToBytes(Interfaces.IByteBufferPool pool, ref int size) - { - int length = 7; - length += CameraCollidePlane.Length; - if (Header.AckList != null && Header.AckList.Length > 0) { length += Header.AckList.Length * 4 + 1; } - byte[] bytes = pool.LeaseBytes(length); - int i = 0; - Header.ToBytes(bytes, ref i); - CameraCollidePlane.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - - size = length; - return bytes; - } - - public override byte[][] ToBytesMultiple(Interfaces.IByteBufferPool pool, out int[] sizes) - { - sizes = new int[1]; - return new byte[][] { this.ToBytes(pool, ref sizes[0]) }; - } - } - - /// - public sealed class ParcelPropertiesPacket : Packet - { - public override bool UsesBufferPooling - { - get - { - return true; - } - } - - /// - public sealed class ParcelDataBlock : PacketBlock - { - public int RequestResult; - public int SequenceID; - public bool SnapSelection; - public int SelfCount; - public int OtherCount; - public int PublicCount; - public int LocalID; - public UUID OwnerID; - public bool IsGroupOwned; - public uint AuctionID; - public int ClaimDate; - public int ClaimPrice; - public int RentPrice; - public Vector3 AABBMin; - public Vector3 AABBMax; - public byte[] Bitmap; - public int Area; - public byte Status; - public int SimWideMaxPrims; - public int SimWideTotalPrims; - public int MaxPrims; - public int TotalPrims; - public int OwnerPrims; - public int GroupPrims; - public int OtherPrims; - public int SelectedPrims; - public float ParcelPrimBonus; - public int OtherCleanTime; - public uint ParcelFlags; - public int SalePrice; - public byte[] Name; - public byte[] Desc; - public byte[] MusicURL; - public byte[] MediaURL; - public UUID MediaID; - public byte MediaAutoScale; - public UUID GroupID; - public int PassPrice; - public float PassHours; - public byte Category; - public UUID AuthBuyerID; - public UUID SnapshotID; - public Vector3 UserLocation; - public Vector3 UserLookAt; - public byte LandingType; - public bool RegionPushOverride; - public bool RegionDenyAnonymous; - public bool RegionDenyIdentified; - public bool RegionDenyTransacted; - - public override int Length - { - get - { - int length = 244; - if (Bitmap != null) { length += Bitmap.Length; } - if (Name != null) { length += Name.Length; } - if (Desc != null) { length += Desc.Length; } - if (MusicURL != null) { length += MusicURL.Length; } - if (MediaURL != null) { length += MediaURL.Length; } - return length; - } - } - - public ParcelDataBlock() { } - public ParcelDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - RequestResult = (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)); - SnapSelection = (bytes[i++] != 0) ? (bool)true : (bool)false; - SelfCount = (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)); - PublicCount = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - LocalID = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - OwnerID.FromBytes(bytes, i); i += 16; - IsGroupOwned = (bytes[i++] != 0) ? (bool)true : (bool)false; - AuctionID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - ClaimDate = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - 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)); - AABBMin.FromBytes(bytes, i); i += 12; - AABBMax.FromBytes(bytes, i); i += 12; - length = (bytes[i++] + (bytes[i++] << 8)); - Bitmap = new byte[length]; - Buffer.BlockCopy(bytes, i, Bitmap, 0, length); i += length; - Area = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - Status = (byte)bytes[i++]; - SimWideMaxPrims = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - SimWideTotalPrims = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - MaxPrims = (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)); - OwnerPrims = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - GroupPrims = (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)); - SelectedPrims = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - ParcelPrimBonus = Utils.BytesToFloat(bytes, i); i += 4; - OtherCleanTime = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - ParcelFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - SalePrice = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - length = bytes[i++]; - Name = new byte[length]; - Buffer.BlockCopy(bytes, i, Name, 0, length); i += length; - length = bytes[i++]; - Desc = new byte[length]; - Buffer.BlockCopy(bytes, i, Desc, 0, length); i += length; - length = bytes[i++]; - MusicURL = new byte[length]; - Buffer.BlockCopy(bytes, i, MusicURL, 0, length); i += length; - length = bytes[i++]; - MediaURL = new byte[length]; - Buffer.BlockCopy(bytes, i, MediaURL, 0, length); i += length; - MediaID.FromBytes(bytes, i); i += 16; - MediaAutoScale = (byte)bytes[i++]; - GroupID.FromBytes(bytes, i); i += 16; - PassPrice = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - PassHours = Utils.BytesToFloat(bytes, i); i += 4; - Category = (byte)bytes[i++]; - AuthBuyerID.FromBytes(bytes, i); i += 16; - SnapshotID.FromBytes(bytes, i); i += 16; - UserLocation.FromBytes(bytes, i); i += 12; - UserLookAt.FromBytes(bytes, i); i += 12; - LandingType = (byte)bytes[i++]; - RegionPushOverride = (bytes[i++] != 0) ? (bool)true : (bool)false; - RegionDenyAnonymous = (bytes[i++] != 0) ? (bool)true : (bool)false; - RegionDenyIdentified = (bytes[i++] != 0) ? (bool)true : (bool)false; - RegionDenyTransacted = (bytes[i++] != 0) ? (bool)true : (bool)false; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.IntToBytes(RequestResult, bytes, i); i += 4; - Utils.IntToBytes(SequenceID, bytes, i); i += 4; - bytes[i++] = (byte)((SnapSelection) ? 1 : 0); - Utils.IntToBytes(SelfCount, bytes, i); i += 4; - Utils.IntToBytes(OtherCount, bytes, i); i += 4; - Utils.IntToBytes(PublicCount, bytes, i); i += 4; - Utils.IntToBytes(LocalID, bytes, i); i += 4; - OwnerID.ToBytes(bytes, i); i += 16; - bytes[i++] = (byte)((IsGroupOwned) ? 1 : 0); - Utils.UIntToBytes(AuctionID, bytes, i); i += 4; - Utils.IntToBytes(ClaimDate, bytes, i); i += 4; - Utils.IntToBytes(ClaimPrice, bytes, i); i += 4; - Utils.IntToBytes(RentPrice, bytes, i); i += 4; - AABBMin.ToBytes(bytes, i); i += 12; - AABBMax.ToBytes(bytes, i); i += 12; - bytes[i++] = (byte)(Bitmap.Length % 256); - bytes[i++] = (byte)((Bitmap.Length >> 8) % 256); - Buffer.BlockCopy(Bitmap, 0, bytes, i, Bitmap.Length); i += Bitmap.Length; - Utils.IntToBytes(Area, bytes, i); i += 4; - bytes[i++] = Status; - Utils.IntToBytes(SimWideMaxPrims, bytes, i); i += 4; - Utils.IntToBytes(SimWideTotalPrims, bytes, i); i += 4; - Utils.IntToBytes(MaxPrims, bytes, i); i += 4; - Utils.IntToBytes(TotalPrims, bytes, i); i += 4; - Utils.IntToBytes(OwnerPrims, bytes, i); i += 4; - Utils.IntToBytes(GroupPrims, bytes, i); i += 4; - Utils.IntToBytes(OtherPrims, bytes, i); i += 4; - Utils.IntToBytes(SelectedPrims, bytes, i); i += 4; - Utils.FloatToBytes(ParcelPrimBonus, bytes, i); i += 4; - Utils.IntToBytes(OtherCleanTime, bytes, i); i += 4; - Utils.UIntToBytes(ParcelFlags, bytes, i); i += 4; - Utils.IntToBytes(SalePrice, bytes, i); i += 4; - bytes[i++] = (byte)Name.Length; - Buffer.BlockCopy(Name, 0, bytes, i, Name.Length); i += Name.Length; - bytes[i++] = (byte)Desc.Length; - Buffer.BlockCopy(Desc, 0, bytes, i, Desc.Length); i += Desc.Length; - bytes[i++] = (byte)MusicURL.Length; - Buffer.BlockCopy(MusicURL, 0, bytes, i, MusicURL.Length); i += MusicURL.Length; - bytes[i++] = (byte)MediaURL.Length; - Buffer.BlockCopy(MediaURL, 0, bytes, i, MediaURL.Length); i += MediaURL.Length; - MediaID.ToBytes(bytes, i); i += 16; - bytes[i++] = MediaAutoScale; - GroupID.ToBytes(bytes, i); i += 16; - Utils.IntToBytes(PassPrice, bytes, i); i += 4; - Utils.FloatToBytes(PassHours, bytes, i); i += 4; - bytes[i++] = Category; - AuthBuyerID.ToBytes(bytes, i); i += 16; - SnapshotID.ToBytes(bytes, i); i += 16; - UserLocation.ToBytes(bytes, i); i += 12; - UserLookAt.ToBytes(bytes, i); i += 12; - bytes[i++] = LandingType; - bytes[i++] = (byte)((RegionPushOverride) ? 1 : 0); - bytes[i++] = (byte)((RegionDenyAnonymous) ? 1 : 0); - bytes[i++] = (byte)((RegionDenyIdentified) ? 1 : 0); - bytes[i++] = (byte)((RegionDenyTransacted) ? 1 : 0); - } - - } - - /// - public sealed class AgeVerificationBlockBlock : PacketBlock - { - public bool RegionDenyAgeUnverified; - - public override int Length - { - get - { - return 1; - } - } - - public AgeVerificationBlockBlock() { } - public AgeVerificationBlockBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - RegionDenyAgeUnverified = (bytes[i++] != 0) ? (bool)true : (bool)false; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - bytes[i++] = (byte)((RegionDenyAgeUnverified) ? 1 : 0); - } - - } - - /// - public sealed class RegionAllowAccessBlockBlock : PacketBlock - { - public bool RegionAllowAccessOverride; - - public override int Length - { - get - { - return 1; - } - } - - public RegionAllowAccessBlockBlock() { } - public RegionAllowAccessBlockBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - RegionAllowAccessOverride = (bytes[i++] != 0) ? (bool)true : (bool)false; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - bytes[i++] = (byte)((RegionAllowAccessOverride) ? 1 : 0); - } - - } - - public override int Length - { - get - { - int length = 7; - length += ParcelData.Length; - length += AgeVerificationBlock.Length; - length += RegionAllowAccessBlock.Length; - return length; - } - } - public ParcelDataBlock ParcelData; - public AgeVerificationBlockBlock AgeVerificationBlock; - public RegionAllowAccessBlockBlock RegionAllowAccessBlock; - - public ParcelPropertiesPacket() - { - HasVariableBlocks = false; - Type = PacketType.ParcelProperties; - Header = new Header(); - Header.Frequency = PacketFrequency.High; - Header.ID = 23; - Header.Reliable = true; - Header.Zerocoded = true; - ParcelData = new ParcelDataBlock(); - AgeVerificationBlock = new AgeVerificationBlockBlock(); - RegionAllowAccessBlock = new RegionAllowAccessBlockBlock(); - } - - public ParcelPropertiesPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - ParcelData.FromBytes(bytes, ref i); - AgeVerificationBlock.FromBytes(bytes, ref i); - RegionAllowAccessBlock.FromBytes(bytes, ref i); - } - - public ParcelPropertiesPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - ParcelData.FromBytes(bytes, ref i); - AgeVerificationBlock.FromBytes(bytes, ref i); - RegionAllowAccessBlock.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 7; - length += ParcelData.Length; - length += AgeVerificationBlock.Length; - length += RegionAllowAccessBlock.Length; - if (Header.AckList != null && 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); - AgeVerificationBlock.ToBytes(bytes, ref i); - RegionAllowAccessBlock.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - - public override byte[] ToBytes(Interfaces.IByteBufferPool pool, ref int size) - { - int length = 7; - length += ParcelData.Length; - length += AgeVerificationBlock.Length; - if (Header.AckList != null && Header.AckList.Length > 0) { length += Header.AckList.Length * 4 + 1; } - byte[] bytes = pool.LeaseBytes(length); - int i = 0; - Header.ToBytes(bytes, ref i); - ParcelData.ToBytes(bytes, ref i); - AgeVerificationBlock.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - - size = length; - return bytes; - } - - public override byte[][] ToBytesMultiple(Interfaces.IByteBufferPool pool, out int[] sizes) - { - sizes = new int[1]; - return new byte[][] { this.ToBytes(pool, ref sizes[0]) }; - } - } - - /// - public sealed class ChildAgentUpdatePacket : Packet - { - public override bool UsesBufferPooling - { - get - { - return true; - } - } - - /// - public sealed class AgentDataBlock : PacketBlock - { - public ulong RegionHandle; - public uint ViewerCircuitCode; - public UUID AgentID; - public UUID SessionID; - public Vector3 AgentPos; - public Vector3 AgentVel; - public Vector3 Center; - public Vector3 Size; - public Vector3 AtAxis; - public Vector3 LeftAxis; - public Vector3 UpAxis; - public bool ChangedGrid; - public float Far; - public float Aspect; - public byte[] Throttles; - public uint LocomotionState; - public Quaternion HeadRotation; - public Quaternion BodyRotation; - public uint ControlFlags; - public float EnergyLevel; - public byte GodLevel; - public bool AlwaysRun; - public UUID PreyAgent; - public byte AgentAccess; - public byte[] AgentTextures; - public UUID ActiveGroupID; - - public override int Length - { - get - { - int length = 211; - if (Throttles != null) { length += Throttles.Length; } - if (AgentTextures != null) { length += AgentTextures.Length; } - return length; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - 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)); - ViewerCircuitCode = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - AgentPos.FromBytes(bytes, i); i += 12; - AgentVel.FromBytes(bytes, i); i += 12; - Center.FromBytes(bytes, i); i += 12; - Size.FromBytes(bytes, i); i += 12; - AtAxis.FromBytes(bytes, i); i += 12; - LeftAxis.FromBytes(bytes, i); i += 12; - UpAxis.FromBytes(bytes, i); i += 12; - ChangedGrid = (bytes[i++] != 0) ? (bool)true : (bool)false; - Far = Utils.BytesToFloat(bytes, i); i += 4; - Aspect = Utils.BytesToFloat(bytes, i); i += 4; - length = bytes[i++]; - Throttles = new byte[length]; - Buffer.BlockCopy(bytes, i, Throttles, 0, length); i += length; - LocomotionState = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - HeadRotation.FromBytes(bytes, i, true); i += 12; - BodyRotation.FromBytes(bytes, i, true); i += 12; - ControlFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - EnergyLevel = Utils.BytesToFloat(bytes, i); i += 4; - GodLevel = (byte)bytes[i++]; - AlwaysRun = (bytes[i++] != 0) ? (bool)true : (bool)false; - PreyAgent.FromBytes(bytes, i); i += 16; - AgentAccess = (byte)bytes[i++]; - length = (bytes[i++] + (bytes[i++] << 8)); - AgentTextures = new byte[length]; - Buffer.BlockCopy(bytes, i, AgentTextures, 0, length); i += length; - ActiveGroupID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UInt64ToBytes(RegionHandle, bytes, i); i += 8; - Utils.UIntToBytes(ViewerCircuitCode, bytes, i); i += 4; - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - AgentPos.ToBytes(bytes, i); i += 12; - AgentVel.ToBytes(bytes, i); i += 12; - Center.ToBytes(bytes, i); i += 12; - Size.ToBytes(bytes, i); i += 12; - AtAxis.ToBytes(bytes, i); i += 12; - LeftAxis.ToBytes(bytes, i); i += 12; - UpAxis.ToBytes(bytes, i); i += 12; - bytes[i++] = (byte)((ChangedGrid) ? 1 : 0); - Utils.FloatToBytes(Far, bytes, i); i += 4; - Utils.FloatToBytes(Aspect, bytes, i); i += 4; - bytes[i++] = (byte)Throttles.Length; - Buffer.BlockCopy(Throttles, 0, bytes, i, Throttles.Length); i += Throttles.Length; - Utils.UIntToBytes(LocomotionState, bytes, i); i += 4; - HeadRotation.ToBytes(bytes, i); i += 12; - BodyRotation.ToBytes(bytes, i); i += 12; - Utils.UIntToBytes(ControlFlags, bytes, i); i += 4; - Utils.FloatToBytes(EnergyLevel, bytes, i); i += 4; - bytes[i++] = GodLevel; - bytes[i++] = (byte)((AlwaysRun) ? 1 : 0); - PreyAgent.ToBytes(bytes, i); i += 16; - bytes[i++] = AgentAccess; - bytes[i++] = (byte)(AgentTextures.Length % 256); - bytes[i++] = (byte)((AgentTextures.Length >> 8) % 256); - Buffer.BlockCopy(AgentTextures, 0, bytes, i, AgentTextures.Length); i += AgentTextures.Length; - ActiveGroupID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class GroupDataBlock : PacketBlock - { - public UUID GroupID; - public ulong GroupPowers; - public bool AcceptNotices; - - public override int Length - { - get - { - return 25; - } - } - - public GroupDataBlock() { } - public GroupDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - GroupID.FromBytes(bytes, i); i += 16; - 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)); - AcceptNotices = (bytes[i++] != 0) ? (bool)true : (bool)false; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - GroupID.ToBytes(bytes, i); i += 16; - Utils.UInt64ToBytes(GroupPowers, bytes, i); i += 8; - bytes[i++] = (byte)((AcceptNotices) ? 1 : 0); - } - - } - - /// - public sealed class AnimationDataBlock : PacketBlock - { - public UUID Animation; - public UUID ObjectID; - - public override int Length - { - get - { - return 32; - } - } - - public AnimationDataBlock() { } - public AnimationDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - Animation.FromBytes(bytes, i); i += 16; - ObjectID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Animation.ToBytes(bytes, i); i += 16; - ObjectID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class GranterBlockBlock : PacketBlock - { - public UUID GranterID; - - public override int Length - { - get - { - return 16; - } - } - - public GranterBlockBlock() { } - public GranterBlockBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - GranterID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - GranterID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class NVPairDataBlock : PacketBlock - { - public byte[] NVPairs; - - public override int Length - { - get - { - int length = 2; - if (NVPairs != null) { length += NVPairs.Length; } - return length; - } - } - - public NVPairDataBlock() { } - public NVPairDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - length = (bytes[i++] + (bytes[i++] << 8)); - NVPairs = new byte[length]; - Buffer.BlockCopy(bytes, i, NVPairs, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - bytes[i++] = (byte)(NVPairs.Length % 256); - bytes[i++] = (byte)((NVPairs.Length >> 8) % 256); - Buffer.BlockCopy(NVPairs, 0, bytes, i, NVPairs.Length); i += NVPairs.Length; - } - - } - - /// - public sealed class VisualParamBlock : PacketBlock - { - public byte ParamValue; - - public override int Length - { - get - { - return 1; - } - } - - public VisualParamBlock() { } - public VisualParamBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - ParamValue = (byte)bytes[i++]; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - bytes[i++] = ParamValue; - } - - } - - /// - public sealed class AgentAccessBlock : PacketBlock - { - public byte AgentLegacyAccess; - public byte AgentMaxAccess; - - public override int Length - { - get - { - return 2; - } - } - - public AgentAccessBlock() { } - public AgentAccessBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AgentLegacyAccess = (byte)bytes[i++]; - AgentMaxAccess = (byte)bytes[i++]; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - bytes[i++] = AgentLegacyAccess; - bytes[i++] = AgentMaxAccess; - } - - } - - /// - public sealed class AgentInfoBlock : PacketBlock - { - public uint Flags; - - public override int Length - { - get - { - return 4; - } - } - - public AgentInfoBlock() { } - public AgentInfoBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - Flags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UIntToBytes(Flags, bytes, i); i += 4; - } - - } - - /// - public sealed class AgentInventoryHostBlock : PacketBlock - { - public byte[] InventoryHost; - - public override int Length - { - get - { - int length = 1; - if (InventoryHost != null) { length += InventoryHost.Length; } - return length; - } - } - - public AgentInventoryHostBlock() { } - public AgentInventoryHostBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - int length; - try - { - length = bytes[i++]; - InventoryHost = new byte[length]; - Buffer.BlockCopy(bytes, i, InventoryHost, 0, length); i += length; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - bytes[i++] = (byte)InventoryHost.Length; - Buffer.BlockCopy(InventoryHost, 0, bytes, i, InventoryHost.Length); i += InventoryHost.Length; - } - - } - - public override int Length - { - get - { - int length = 15; - length += AgentData.Length; - for (int j = 0; j < GroupData.Length; j++) - length += GroupData[j].Length; - for (int j = 0; j < AnimationData.Length; j++) - length += AnimationData[j].Length; - for (int j = 0; j < GranterBlock.Length; j++) - length += GranterBlock[j].Length; - for (int j = 0; j < NVPairData.Length; j++) - length += NVPairData[j].Length; - for (int j = 0; j < VisualParam.Length; j++) - length += VisualParam[j].Length; - for (int j = 0; j < AgentAccess.Length; j++) - length += AgentAccess[j].Length; - for (int j = 0; j < AgentInfo.Length; j++) - length += AgentInfo[j].Length; - for (int j = 0; j < AgentInventoryHost.Length; j++) - length += AgentInventoryHost[j].Length; - return length; - } - } - public AgentDataBlock AgentData; - public GroupDataBlock[] GroupData; - public AnimationDataBlock[] AnimationData; - public GranterBlockBlock[] GranterBlock; - public NVPairDataBlock[] NVPairData; - public VisualParamBlock[] VisualParam; - public AgentAccessBlock[] AgentAccess; - public AgentInfoBlock[] AgentInfo; - public AgentInventoryHostBlock[] AgentInventoryHost; - - public ChildAgentUpdatePacket() - { - HasVariableBlocks = true; - Type = PacketType.ChildAgentUpdate; - Header = new Header(); - Header.Frequency = PacketFrequency.High; - Header.ID = 25; - Header.Reliable = true; - Header.Zerocoded = true; - AgentData = new AgentDataBlock(); - GroupData = null; - AnimationData = null; - GranterBlock = null; - NVPairData = null; - VisualParam = null; - AgentAccess = null; - AgentInfo = null; - AgentInventoryHost = null; - } - - public ChildAgentUpdatePacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(GroupData == null || GroupData.Length != -1) { - GroupData = new GroupDataBlock[count]; - for(int j = 0; j < count; j++) - { GroupData[j] = new GroupDataBlock(); } - } - for (int j = 0; j < count; j++) - { GroupData[j].FromBytes(bytes, ref i); } - count = (int)bytes[i++]; - if(AnimationData == null || AnimationData.Length != -1) { - AnimationData = new AnimationDataBlock[count]; - for(int j = 0; j < count; j++) - { AnimationData[j] = new AnimationDataBlock(); } - } - for (int j = 0; j < count; j++) - { AnimationData[j].FromBytes(bytes, ref i); } - count = (int)bytes[i++]; - if(GranterBlock == null || GranterBlock.Length != -1) { - GranterBlock = new GranterBlockBlock[count]; - for(int j = 0; j < count; j++) - { GranterBlock[j] = new GranterBlockBlock(); } - } - for (int j = 0; j < count; j++) - { GranterBlock[j].FromBytes(bytes, ref i); } - count = (int)bytes[i++]; - if(NVPairData == null || NVPairData.Length != -1) { - NVPairData = new NVPairDataBlock[count]; - for(int j = 0; j < count; j++) - { NVPairData[j] = new NVPairDataBlock(); } - } - for (int j = 0; j < count; j++) - { NVPairData[j].FromBytes(bytes, ref i); } - count = (int)bytes[i++]; - if(VisualParam == null || VisualParam.Length != -1) { - VisualParam = new VisualParamBlock[count]; - for(int j = 0; j < count; j++) - { VisualParam[j] = new VisualParamBlock(); } - } - for (int j = 0; j < count; j++) - { VisualParam[j].FromBytes(bytes, ref i); } - count = (int)bytes[i++]; - if(AgentAccess == null || AgentAccess.Length != -1) { - AgentAccess = new AgentAccessBlock[count]; - for(int j = 0; j < count; j++) - { AgentAccess[j] = new AgentAccessBlock(); } - } - for (int j = 0; j < count; j++) - { AgentAccess[j].FromBytes(bytes, ref i); } - count = (int)bytes[i++]; - if(AgentInfo == null || AgentInfo.Length != -1) { - AgentInfo = new AgentInfoBlock[count]; - for(int j = 0; j < count; j++) - { AgentInfo[j] = new AgentInfoBlock(); } - } - for (int j = 0; j < count; j++) - { AgentInfo[j].FromBytes(bytes, ref i); } - count = (int)bytes[i++]; - if(AgentInventoryHost == null || AgentInventoryHost.Length != -1) { - AgentInventoryHost = new AgentInventoryHostBlock[count]; - for(int j = 0; j < count; j++) - { AgentInventoryHost[j] = new AgentInventoryHostBlock(); } - } - for (int j = 0; j < count; j++) - { AgentInventoryHost[j].FromBytes(bytes, ref i); } - } - - public ChildAgentUpdatePacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(GroupData == null || GroupData.Length != count) { - GroupData = new GroupDataBlock[count]; - for(int j = 0; j < count; j++) - { GroupData[j] = new GroupDataBlock(); } - } - for (int j = 0; j < count; j++) - { GroupData[j].FromBytes(bytes, ref i); } - count = (int)bytes[i++]; - if(AnimationData == null || AnimationData.Length != count) { - AnimationData = new AnimationDataBlock[count]; - for(int j = 0; j < count; j++) - { AnimationData[j] = new AnimationDataBlock(); } - } - for (int j = 0; j < count; j++) - { AnimationData[j].FromBytes(bytes, ref i); } - count = (int)bytes[i++]; - if(GranterBlock == null || GranterBlock.Length != count) { - GranterBlock = new GranterBlockBlock[count]; - for(int j = 0; j < count; j++) - { GranterBlock[j] = new GranterBlockBlock(); } - } - for (int j = 0; j < count; j++) - { GranterBlock[j].FromBytes(bytes, ref i); } - count = (int)bytes[i++]; - if(NVPairData == null || NVPairData.Length != count) { - NVPairData = new NVPairDataBlock[count]; - for(int j = 0; j < count; j++) - { NVPairData[j] = new NVPairDataBlock(); } - } - for (int j = 0; j < count; j++) - { NVPairData[j].FromBytes(bytes, ref i); } - count = (int)bytes[i++]; - if(VisualParam == null || VisualParam.Length != count) { - VisualParam = new VisualParamBlock[count]; - for(int j = 0; j < count; j++) - { VisualParam[j] = new VisualParamBlock(); } - } - for (int j = 0; j < count; j++) - { VisualParam[j].FromBytes(bytes, ref i); } - count = (int)bytes[i++]; - if(AgentAccess == null || AgentAccess.Length != count) { - AgentAccess = new AgentAccessBlock[count]; - for(int j = 0; j < count; j++) - { AgentAccess[j] = new AgentAccessBlock(); } - } - for (int j = 0; j < count; j++) - { AgentAccess[j].FromBytes(bytes, ref i); } - count = (int)bytes[i++]; - if(AgentInfo == null || AgentInfo.Length != count) { - AgentInfo = new AgentInfoBlock[count]; - for(int j = 0; j < count; j++) - { AgentInfo[j] = new AgentInfoBlock(); } - } - for (int j = 0; j < count; j++) - { AgentInfo[j].FromBytes(bytes, ref i); } - count = (int)bytes[i++]; - if(AgentInventoryHost == null || AgentInventoryHost.Length != count) { - AgentInventoryHost = new AgentInventoryHostBlock[count]; - for(int j = 0; j < count; j++) - { AgentInventoryHost[j] = new AgentInventoryHostBlock(); } - } - for (int j = 0; j < count; j++) - { AgentInventoryHost[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 7; - length += AgentData.Length; - length++; - for (int j = 0; j < GroupData.Length; j++) { length += GroupData[j].Length; } - length++; - for (int j = 0; j < AnimationData.Length; j++) { length += AnimationData[j].Length; } - length++; - for (int j = 0; j < GranterBlock.Length; j++) { length += GranterBlock[j].Length; } - length++; - for (int j = 0; j < NVPairData.Length; j++) { length += NVPairData[j].Length; } - length++; - for (int j = 0; j < VisualParam.Length; j++) { length += VisualParam[j].Length; } - length++; - for (int j = 0; j < AgentAccess.Length; j++) { length += AgentAccess[j].Length; } - length++; - for (int j = 0; j < AgentInfo.Length; j++) { length += AgentInfo[j].Length; } - length++; - for (int j = 0; j < AgentInventoryHost.Length; j++) { length += AgentInventoryHost[j].Length; } - if (Header.AckList != null && 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); } - bytes[i++] = (byte)AnimationData.Length; - for (int j = 0; j < AnimationData.Length; j++) { AnimationData[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)NVPairData.Length; - for (int j = 0; j < NVPairData.Length; j++) { NVPairData[j].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)AgentAccess.Length; - for (int j = 0; j < AgentAccess.Length; j++) { AgentAccess[j].ToBytes(bytes, ref i); } - bytes[i++] = (byte)AgentInfo.Length; - for (int j = 0; j < AgentInfo.Length; j++) { AgentInfo[j].ToBytes(bytes, ref i); } - bytes[i++] = (byte)AgentInventoryHost.Length; - for (int j = 0; j < AgentInventoryHost.Length; j++) { AgentInventoryHost[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 7; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - fixedLength += 8; - - int GroupDataStart = 0; - int AnimationDataStart = 0; - int GranterBlockStart = 0; - int NVPairDataStart = 0; - int VisualParamStart = 0; - int AgentAccessStart = 0; - int AgentInfoStart = 0; - int AgentInventoryHostStart = 0; - do - { - int variableLength = 0; - int GroupDataCount = 0; - int AnimationDataCount = 0; - int GranterBlockCount = 0; - int NVPairDataCount = 0; - int VisualParamCount = 0; - int AgentAccessCount = 0; - int AgentInfoCount = 0; - int AgentInventoryHostCount = 0; - - i = GroupDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < GroupData.Length) { - int blockLength = GroupData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == GroupDataStart) { - variableLength += blockLength; - ++GroupDataCount; - } - else { break; } - ++i; - } - - i = AnimationDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < AnimationData.Length) { - int blockLength = AnimationData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == AnimationDataStart) { - variableLength += blockLength; - ++AnimationDataCount; - } - else { break; } - ++i; - } - - i = GranterBlockStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < GranterBlock.Length) { - int blockLength = GranterBlock[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == GranterBlockStart) { - variableLength += blockLength; - ++GranterBlockCount; - } - else { break; } - ++i; - } - - i = NVPairDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < NVPairData.Length) { - int blockLength = NVPairData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == NVPairDataStart) { - variableLength += blockLength; - ++NVPairDataCount; - } - else { break; } - ++i; - } - - i = VisualParamStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < VisualParam.Length) { - int blockLength = VisualParam[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == VisualParamStart) { - variableLength += blockLength; - ++VisualParamCount; - } - else { break; } - ++i; - } - - i = AgentAccessStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < AgentAccess.Length) { - int blockLength = AgentAccess[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == AgentAccessStart) { - variableLength += blockLength; - ++AgentAccessCount; - } - else { break; } - ++i; - } - - i = AgentInfoStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < AgentInfo.Length) { - int blockLength = AgentInfo[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == AgentInfoStart) { - variableLength += blockLength; - ++AgentInfoCount; - } - else { break; } - ++i; - } - - i = AgentInventoryHostStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < AgentInventoryHost.Length) { - int blockLength = AgentInventoryHost[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == AgentInventoryHostStart) { - variableLength += blockLength; - ++AgentInventoryHostCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)GroupDataCount; - for (i = GroupDataStart; i < GroupDataStart + GroupDataCount; i++) { GroupData[i].ToBytes(packet, ref length); } - GroupDataStart += GroupDataCount; - - packet[length++] = (byte)AnimationDataCount; - for (i = AnimationDataStart; i < AnimationDataStart + AnimationDataCount; i++) { AnimationData[i].ToBytes(packet, ref length); } - AnimationDataStart += AnimationDataCount; - - packet[length++] = (byte)GranterBlockCount; - for (i = GranterBlockStart; i < GranterBlockStart + GranterBlockCount; i++) { GranterBlock[i].ToBytes(packet, ref length); } - GranterBlockStart += GranterBlockCount; - - packet[length++] = (byte)NVPairDataCount; - for (i = NVPairDataStart; i < NVPairDataStart + NVPairDataCount; i++) { NVPairData[i].ToBytes(packet, ref length); } - NVPairDataStart += NVPairDataCount; - - packet[length++] = (byte)VisualParamCount; - for (i = VisualParamStart; i < VisualParamStart + VisualParamCount; i++) { VisualParam[i].ToBytes(packet, ref length); } - VisualParamStart += VisualParamCount; - - packet[length++] = (byte)AgentAccessCount; - for (i = AgentAccessStart; i < AgentAccessStart + AgentAccessCount; i++) { AgentAccess[i].ToBytes(packet, ref length); } - AgentAccessStart += AgentAccessCount; - - packet[length++] = (byte)AgentInfoCount; - for (i = AgentInfoStart; i < AgentInfoStart + AgentInfoCount; i++) { AgentInfo[i].ToBytes(packet, ref length); } - AgentInfoStart += AgentInfoCount; - - packet[length++] = (byte)AgentInventoryHostCount; - for (i = AgentInventoryHostStart; i < AgentInventoryHostStart + AgentInventoryHostCount; i++) { AgentInventoryHost[i].ToBytes(packet, ref length); } - AgentInventoryHostStart += AgentInventoryHostCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - GroupDataStart < GroupData.Length || - AnimationDataStart < AnimationData.Length || - GranterBlockStart < GranterBlock.Length || - NVPairDataStart < NVPairData.Length || - VisualParamStart < VisualParam.Length || - AgentAccessStart < AgentAccess.Length || - AgentInfoStart < AgentInfo.Length || - AgentInventoryHostStart < AgentInventoryHost.Length); - - return packets.ToArray(); - } - - public override byte[] ToBytes(Interfaces.IByteBufferPool pool, ref int size) - { - int length = 7; - length += AgentData.Length; - length++; - for (int j = 0; j < GroupData.Length; j++) { length += GroupData[j].Length; } - length++; - for (int j = 0; j < AnimationData.Length; j++) { length += AnimationData[j].Length; } - length++; - for (int j = 0; j < GranterBlock.Length; j++) { length += GranterBlock[j].Length; } - length++; - for (int j = 0; j < NVPairData.Length; j++) { length += NVPairData[j].Length; } - length++; - for (int j = 0; j < VisualParam.Length; j++) { length += VisualParam[j].Length; } - length++; - for (int j = 0; j < AgentAccess.Length; j++) { length += AgentAccess[j].Length; } - length++; - for (int j = 0; j < AgentInfo.Length; j++) { length += AgentInfo[j].Length; } - if (Header.AckList != null && Header.AckList.Length > 0) { length += Header.AckList.Length * 4 + 1; } - byte[] bytes = pool.LeaseBytes(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); } - bytes[i++] = (byte)AnimationData.Length; - for (int j = 0; j < AnimationData.Length; j++) { AnimationData[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)NVPairData.Length; - for (int j = 0; j < NVPairData.Length; j++) { NVPairData[j].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)AgentAccess.Length; - for (int j = 0; j < AgentAccess.Length; j++) { AgentAccess[j].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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - - size = length; - return bytes; - } - - public override byte[][] ToBytesMultiple(Interfaces.IByteBufferPool pool, out int[] sizes) - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - System.Collections.Generic.List retSizes = new System.Collections.Generic.List(); - - int i = 0; - int fixedLength = 7; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) - { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += AgentData.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - AgentData.ToBytes(fixedBytes, ref i); - fixedLength += 7; - - int GroupDataStart = 0; - int AnimationDataStart = 0; - int GranterBlockStart = 0; - int NVPairDataStart = 0; - int VisualParamStart = 0; - int AgentAccessStart = 0; - int AgentInfoStart = 0; - do - { - int variableLength = 0; - int GroupDataCount = 0; - int AnimationDataCount = 0; - int GranterBlockCount = 0; - int NVPairDataCount = 0; - int VisualParamCount = 0; - int AgentAccessCount = 0; - int AgentInfoCount = 0; - - i = GroupDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < GroupData.Length) - { - int blockLength = GroupData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU) - { - variableLength += blockLength; - ++GroupDataCount; - } - else { break; } - ++i; - } - - i = AnimationDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < AnimationData.Length) - { - int blockLength = AnimationData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU) - { - variableLength += blockLength; - ++AnimationDataCount; - } - else { break; } - ++i; - } - - i = GranterBlockStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < GranterBlock.Length) - { - int blockLength = GranterBlock[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU) - { - variableLength += blockLength; - ++GranterBlockCount; - } - else { break; } - ++i; - } - - i = NVPairDataStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < NVPairData.Length) - { - int blockLength = NVPairData[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU) - { - variableLength += blockLength; - ++NVPairDataCount; - } - else { break; } - ++i; - } - - i = VisualParamStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < VisualParam.Length) - { - int blockLength = VisualParam[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU) - { - variableLength += blockLength; - ++VisualParamCount; - } - else { break; } - ++i; - } - - i = AgentAccessStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < AgentAccess.Length) - { - int blockLength = AgentAccess[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU) - { - variableLength += blockLength; - ++AgentAccessCount; - } - else { break; } - ++i; - } - - i = AgentInfoStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < AgentInfo.Length) - { - int blockLength = AgentInfo[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU) - { - variableLength += blockLength; - ++AgentInfoCount; - } - else { break; } - ++i; - } - - int packetSize = fixedLength + variableLength + acksLength; - byte[] packet = pool.LeaseBytes(packetSize); - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)GroupDataCount; - for (i = GroupDataStart; i < GroupDataStart + GroupDataCount; i++) { GroupData[i].ToBytes(packet, ref length); } - GroupDataStart += GroupDataCount; - - packet[length++] = (byte)AnimationDataCount; - for (i = AnimationDataStart; i < AnimationDataStart + AnimationDataCount; i++) { AnimationData[i].ToBytes(packet, ref length); } - AnimationDataStart += AnimationDataCount; - - packet[length++] = (byte)GranterBlockCount; - for (i = GranterBlockStart; i < GranterBlockStart + GranterBlockCount; i++) { GranterBlock[i].ToBytes(packet, ref length); } - GranterBlockStart += GranterBlockCount; - - packet[length++] = (byte)NVPairDataCount; - for (i = NVPairDataStart; i < NVPairDataStart + NVPairDataCount; i++) { NVPairData[i].ToBytes(packet, ref length); } - NVPairDataStart += NVPairDataCount; - - packet[length++] = (byte)VisualParamCount; - for (i = VisualParamStart; i < VisualParamStart + VisualParamCount; i++) { VisualParam[i].ToBytes(packet, ref length); } - VisualParamStart += VisualParamCount; - - packet[length++] = (byte)AgentAccessCount; - for (i = AgentAccessStart; i < AgentAccessStart + AgentAccessCount; i++) { AgentAccess[i].ToBytes(packet, ref length); } - AgentAccessStart += AgentAccessCount; - - packet[length++] = (byte)AgentInfoCount; - for (i = AgentInfoStart; i < AgentInfoStart + AgentInfoCount; i++) { AgentInfo[i].ToBytes(packet, ref length); } - AgentInfoStart += AgentInfoCount; - - if (acksLength > 0) - { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - retSizes.Add(packetSize); - packets.Add(packet); - - } while ( - GroupDataStart < GroupData.Length || - AnimationDataStart < AnimationData.Length || - GranterBlockStart < GranterBlock.Length || - NVPairDataStart < NVPairData.Length || - VisualParamStart < VisualParam.Length || - AgentAccessStart < AgentAccess.Length || - AgentInfoStart < AgentInfo.Length); - - sizes = retSizes.ToArray(); - return packets.ToArray(); - } - } - - /// - public sealed class ChildAgentAlivePacket : Packet - { - public override bool UsesBufferPooling - { - get - { - return true; - } - } - - /// - public sealed class AgentDataBlock : PacketBlock - { - public ulong RegionHandle; - public uint ViewerCircuitCode; - public UUID AgentID; - public UUID SessionID; - - public override int Length - { - get - { - return 44; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(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)); - ViewerCircuitCode = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UInt64ToBytes(RegionHandle, bytes, i); i += 8; - Utils.UIntToBytes(ViewerCircuitCode, bytes, i); i += 4; - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - } - - } - - public override int Length - { - get - { - int length = 7; - length += AgentData.Length; - return length; - } - } - public AgentDataBlock AgentData; - - public ChildAgentAlivePacket() - { - HasVariableBlocks = false; - Type = PacketType.ChildAgentAlive; - Header = new Header(); - Header.Frequency = PacketFrequency.High; - Header.ID = 26; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - } - - public ChildAgentAlivePacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - } - - public ChildAgentAlivePacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 7; - length += AgentData.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - - public override byte[] ToBytes(Interfaces.IByteBufferPool pool, ref int size) - { - int length = 7; - length += AgentData.Length; - if (Header.AckList != null && Header.AckList.Length > 0) { length += Header.AckList.Length * 4 + 1; } - byte[] bytes = pool.LeaseBytes(length); - int i = 0; - Header.ToBytes(bytes, ref i); - AgentData.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - - size = length; - return bytes; - } - - public override byte[][] ToBytesMultiple(Interfaces.IByteBufferPool pool, out int[] sizes) - { - sizes = new int[1]; - return new byte[][] { this.ToBytes(pool, ref sizes[0]) }; - } - } - - /// - public sealed class ChildAgentPositionUpdatePacket : Packet - { - public override bool UsesBufferPooling - { - get - { - return true; - } - } - - /// - public sealed class AgentDataBlock : PacketBlock - { - public ulong RegionHandle; - public uint ViewerCircuitCode; - public UUID AgentID; - public UUID SessionID; - public Vector3 AgentPos; - public Vector3 AgentVel; - public Vector3 Center; - public Vector3 Size; - public Vector3 AtAxis; - public Vector3 LeftAxis; - public Vector3 UpAxis; - public bool ChangedGrid; - - public override int Length - { - get - { - return 129; - } - } - - public AgentDataBlock() { } - public AgentDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(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)); - ViewerCircuitCode = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - AgentID.FromBytes(bytes, i); i += 16; - SessionID.FromBytes(bytes, i); i += 16; - AgentPos.FromBytes(bytes, i); i += 12; - AgentVel.FromBytes(bytes, i); i += 12; - Center.FromBytes(bytes, i); i += 12; - Size.FromBytes(bytes, i); i += 12; - AtAxis.FromBytes(bytes, i); i += 12; - LeftAxis.FromBytes(bytes, i); i += 12; - UpAxis.FromBytes(bytes, i); i += 12; - ChangedGrid = (bytes[i++] != 0) ? (bool)true : (bool)false; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - Utils.UInt64ToBytes(RegionHandle, bytes, i); i += 8; - Utils.UIntToBytes(ViewerCircuitCode, bytes, i); i += 4; - AgentID.ToBytes(bytes, i); i += 16; - SessionID.ToBytes(bytes, i); i += 16; - AgentPos.ToBytes(bytes, i); i += 12; - AgentVel.ToBytes(bytes, i); i += 12; - Center.ToBytes(bytes, i); i += 12; - Size.ToBytes(bytes, i); i += 12; - AtAxis.ToBytes(bytes, i); i += 12; - LeftAxis.ToBytes(bytes, i); i += 12; - UpAxis.ToBytes(bytes, i); i += 12; - bytes[i++] = (byte)((ChangedGrid) ? 1 : 0); - } - - } - - public override int Length - { - get - { - int length = 7; - length += AgentData.Length; - return length; - } - } - public AgentDataBlock AgentData; - - public ChildAgentPositionUpdatePacket() - { - HasVariableBlocks = false; - Type = PacketType.ChildAgentPositionUpdate; - Header = new Header(); - Header.Frequency = PacketFrequency.High; - Header.ID = 27; - Header.Reliable = true; - AgentData = new AgentDataBlock(); - } - - public ChildAgentPositionUpdatePacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - AgentData.FromBytes(bytes, ref i); - } - - public ChildAgentPositionUpdatePacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - AgentData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 7; - length += AgentData.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - - public override byte[] ToBytes(Interfaces.IByteBufferPool pool, ref int size) - { - int length = 7; - length += AgentData.Length; - if (Header.AckList != null && Header.AckList.Length > 0) { length += Header.AckList.Length * 4 + 1; } - byte[] bytes = pool.LeaseBytes(length); - int i = 0; - Header.ToBytes(bytes, ref i); - AgentData.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - - size = length; - return bytes; - } - - public override byte[][] ToBytesMultiple(Interfaces.IByteBufferPool pool, out int[] sizes) - { - sizes = new int[1]; - return new byte[][] { this.ToBytes(pool, ref sizes[0]) }; - } - } - - /// - public sealed class SoundTriggerPacket : Packet - { - public override bool UsesBufferPooling - { - get - { - return true; - } - } - - /// - public sealed class SoundDataBlock : PacketBlock - { - public UUID SoundID; - public UUID OwnerID; - public UUID ObjectID; - public UUID ParentID; - public ulong Handle; - public Vector3 Position; - public float Gain; - - public override int Length - { - get - { - return 88; - } - } - - public SoundDataBlock() { } - public SoundDataBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - SoundID.FromBytes(bytes, i); i += 16; - OwnerID.FromBytes(bytes, i); i += 16; - ObjectID.FromBytes(bytes, i); i += 16; - ParentID.FromBytes(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.FromBytes(bytes, i); i += 12; - Gain = Utils.BytesToFloat(bytes, i); i += 4; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - SoundID.ToBytes(bytes, i); i += 16; - OwnerID.ToBytes(bytes, i); i += 16; - ObjectID.ToBytes(bytes, i); i += 16; - ParentID.ToBytes(bytes, i); i += 16; - Utils.UInt64ToBytes(Handle, bytes, i); i += 8; - Position.ToBytes(bytes, i); i += 12; - Utils.FloatToBytes(Gain, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 7; - length += SoundData.Length; - return length; - } - } - public SoundDataBlock SoundData; - - public SoundTriggerPacket() - { - HasVariableBlocks = false; - Type = PacketType.SoundTrigger; - Header = new Header(); - Header.Frequency = PacketFrequency.High; - Header.ID = 29; - Header.Reliable = true; - SoundData = new SoundDataBlock(); - } - - public SoundTriggerPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - SoundData.FromBytes(bytes, ref i); - } - - public SoundTriggerPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - SoundData.FromBytes(bytes, ref i); - } - - public override byte[] ToBytes() - { - int length = 7; - length += SoundData.Length; - if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - return new byte[][] { ToBytes() }; - } - - public override byte[] ToBytes(Interfaces.IByteBufferPool pool, ref int size) - { - int length = 7; - length += SoundData.Length; - if (Header.AckList != null && Header.AckList.Length > 0) { length += Header.AckList.Length * 4 + 1; } - byte[] bytes = pool.LeaseBytes(length); - int i = 0; - Header.ToBytes(bytes, ref i); - SoundData.ToBytes(bytes, ref i); - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - - size = length; - return bytes; - } - - public override byte[][] ToBytesMultiple(Interfaces.IByteBufferPool pool, out int[] sizes) - { - sizes = new int[1]; - return new byte[][] { this.ToBytes(pool, ref sizes[0]) }; - } - } - - /// - public sealed class ObjectAnimationPacket : Packet - { - /// - public sealed class SenderBlock : PacketBlock - { - public UUID ID; - - public override int Length - { - get - { - return 16; - } - } - - public SenderBlock() { } - public SenderBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - ID.FromBytes(bytes, i); i += 16; - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - ID.ToBytes(bytes, i); i += 16; - } - - } - - /// - public sealed class AnimationListBlock : PacketBlock - { - public UUID AnimID; - public int AnimSequenceID; - - public override int Length - { - get - { - return 20; - } - } - - public AnimationListBlock() { } - public AnimationListBlock(byte[] bytes, ref int i) - { - FromBytes(bytes, ref i); - } - - public override void FromBytes(byte[] bytes, ref int i) - { - try - { - AnimID.FromBytes(bytes, i); i += 16; - AnimSequenceID = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); - } - catch (Exception) - { - throw new MalformedDataException(); - } - } - - public override void ToBytes(byte[] bytes, ref int i) - { - AnimID.ToBytes(bytes, i); i += 16; - Utils.IntToBytes(AnimSequenceID, bytes, i); i += 4; - } - - } - - public override int Length - { - get - { - int length = 8; - length += Sender.Length; - for (int j = 0; j < AnimationList.Length; j++) - length += AnimationList[j].Length; - return length; - } - } - public SenderBlock Sender; - public AnimationListBlock[] AnimationList; - - public ObjectAnimationPacket() - { - HasVariableBlocks = true; - Type = PacketType.ObjectAnimation; - Header = new Header(); - Header.Frequency = PacketFrequency.High; - Header.ID = 30; - Header.Reliable = true; - Sender = new SenderBlock(); - AnimationList = null; - } - - public ObjectAnimationPacket(byte[] bytes, ref int i) : this() - { - int packetEnd = bytes.Length - 1; - FromBytes(bytes, ref i, ref packetEnd, null); - } - - override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) - { - Header.FromBytes(bytes, ref i, ref packetEnd); - if (Header.Zerocoded && zeroBuffer != null) - { - packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; - bytes = zeroBuffer; - } - Sender.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(AnimationList == null || AnimationList.Length != -1) { - AnimationList = new AnimationListBlock[count]; - for(int j = 0; j < count; j++) - { AnimationList[j] = new AnimationListBlock(); } - } - for (int j = 0; j < count; j++) - { AnimationList[j].FromBytes(bytes, ref i); } - } - - public ObjectAnimationPacket(Header head, byte[] bytes, ref int i): this() - { - int packetEnd = bytes.Length - 1; - FromBytes(head, bytes, ref i, ref packetEnd); - } - - override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) - { - Header = header; - Sender.FromBytes(bytes, ref i); - int count = (int)bytes[i++]; - if(AnimationList == null || AnimationList.Length != count) { - AnimationList = new AnimationListBlock[count]; - for(int j = 0; j < count; j++) - { AnimationList[j] = new AnimationListBlock(); } - } - for (int j = 0; j < count; j++) - { AnimationList[j].FromBytes(bytes, ref i); } - } - - public override byte[] ToBytes() - { - int length = 7; - length += Sender.Length; - length++; - for (int j = 0; j < AnimationList.Length; j++) { length += AnimationList[j].Length; } - if (Header.AckList != null && 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); - bytes[i++] = (byte)AnimationList.Length; - for (int j = 0; j < AnimationList.Length; j++) { AnimationList[j].ToBytes(bytes, ref i); } - if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } - return bytes; - } - - public override byte[][] ToBytesMultiple() - { - System.Collections.Generic.List packets = new System.Collections.Generic.List(); - int i = 0; - int fixedLength = 7; - - byte[] ackBytes = null; - int acksLength = 0; - if (Header.AckList != null && Header.AckList.Length > 0) { - Header.AppendedAcks = true; - ackBytes = new byte[Header.AckList.Length * 4 + 1]; - Header.AcksToBytes(ackBytes, ref acksLength); - } - - fixedLength += Sender.Length; - byte[] fixedBytes = new byte[fixedLength]; - Header.ToBytes(fixedBytes, ref i); - Sender.ToBytes(fixedBytes, ref i); - fixedLength += 1; - - int AnimationListStart = 0; - do - { - int variableLength = 0; - int AnimationListCount = 0; - - i = AnimationListStart; - while (fixedLength + variableLength + acksLength < Packet.MTU && i < AnimationList.Length) { - int blockLength = AnimationList[i].Length; - if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == AnimationListStart) { - variableLength += blockLength; - ++AnimationListCount; - } - else { break; } - ++i; - } - - byte[] packet = new byte[fixedLength + variableLength + acksLength]; - int length = fixedBytes.Length; - Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); - if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } - - packet[length++] = (byte)AnimationListCount; - for (i = AnimationListStart; i < AnimationListStart + AnimationListCount; i++) { AnimationList[i].ToBytes(packet, ref length); } - AnimationListStart += AnimationListCount; - - if (acksLength > 0) { - Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); - acksLength = 0; - } - - packets.Add(packet); - } while ( - AnimationListStart < AnimationList.Length); - - return packets.ToArray(); - } - } - -} +/* + * Copyright (c) 2006-2016, openmetaverse.co + * 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; + +namespace OpenMetaverse +{ + /// + /// + /// + public enum PacketFrequency : byte + { + /// + Low, + /// + Medium, + /// + High + } +} + +namespace OpenMetaverse.Packets +{ + /// + /// Thrown when a packet could not be successfully deserialized + /// + [Serializable] + public class MalformedDataException : ApplicationException + { + /// + /// Default constructor + /// + public MalformedDataException() { } + + /// + /// Constructor that takes an additional error message + /// + /// An error message to attach to this exception + public MalformedDataException(string Message) + : base(Message) + { + this.Source = "Packet decoding"; + } + } + + /// + /// The header of a message template packet. Holds packet flags, sequence + /// number, packet ID, and any ACKs that will be appended at the end of + /// the packet + /// + public struct Header + { + public bool Reliable; + public bool Resent; + public bool Zerocoded; + public bool AppendedAcks; + public uint Sequence; + public ushort ID; + public PacketFrequency Frequency; + public uint[] AckList; + + public void ToBytes(byte[] bytes, ref int i) + { + byte flags = 0; + if (Reliable) flags |= Helpers.MSG_RELIABLE; + if (Resent) flags |= Helpers.MSG_RESENT; + if (Zerocoded) flags |= Helpers.MSG_ZEROCODED; + if (AppendedAcks) flags |= Helpers.MSG_APPENDED_ACKS; + + // Flags + bytes[i++] = flags; + + // Sequence number + Utils.UIntToBytesBig(Sequence, bytes, i); + i += 4; + + // Extra byte + bytes[i++] = 0; + + // Packet ID + switch (Frequency) + { + case PacketFrequency.High: + // 1 byte ID + bytes[i++] = (byte)ID; + break; + case PacketFrequency.Medium: + // 2 byte ID + bytes[i++] = 0xFF; + bytes[i++] = (byte)ID; + break; + case PacketFrequency.Low: + // 4 byte ID + bytes[i++] = 0xFF; + bytes[i++] = 0xFF; + Utils.UInt16ToBytesBig(ID, bytes, i); + i += 2; + break; + } + } + + public void FromBytes(byte[] bytes, ref int pos, ref int packetEnd) + { + this = BuildHeader(bytes, ref pos, ref packetEnd); + } + + /// + /// Convert the AckList to a byte array, used for packet serializing + /// + /// Reference to the target byte array + /// Beginning position to start writing to in the byte + /// array, will be updated with the ending position of the ACK list + public void AcksToBytes(byte[] bytes, ref int i) + { + foreach (uint ack in AckList) + { + Utils.UIntToBytesBig(ack, bytes, i); + i += 4; + } + if (AckList.Length > 0) { bytes[i++] = (byte)AckList.Length; } + } + + /// + /// + /// + /// + /// + /// + /// + public static Header BuildHeader(byte[] bytes, ref int pos, ref int packetEnd) + { + Header header; + byte flags = bytes[pos]; + + header.AppendedAcks = (flags & Helpers.MSG_APPENDED_ACKS) != 0; + header.Reliable = (flags & Helpers.MSG_RELIABLE) != 0; + header.Resent = (flags & Helpers.MSG_RESENT) != 0; + header.Zerocoded = (flags & Helpers.MSG_ZEROCODED) != 0; + header.Sequence = (uint)((bytes[pos + 1] << 24) + (bytes[pos + 2] << 16) + (bytes[pos + 3] << 8) + bytes[pos + 4]); + + // Set the frequency and packet ID number + if (bytes[pos + 6] == 0xFF) + { + if (bytes[pos + 7] == 0xFF) + { + header.Frequency = PacketFrequency.Low; + if (header.Zerocoded && bytes[pos + 8] == 0) + header.ID = bytes[pos + 10]; + else + header.ID = (ushort)((bytes[pos + 8] << 8) + bytes[pos + 9]); + + pos += 10; + } + else + { + header.Frequency = PacketFrequency.Medium; + header.ID = bytes[pos + 7]; + + pos += 8; + } + } + else + { + header.Frequency = PacketFrequency.High; + header.ID = bytes[pos + 6]; + + pos += 7; + } + + header.AckList = null; + CreateAckList(ref header, bytes, ref packetEnd); + + return header; + } + + /// + /// + /// + /// + /// + /// + static void CreateAckList(ref Header header, byte[] bytes, ref int packetEnd) + { + if (header.AppendedAcks) + { + int count = bytes[packetEnd--]; + header.AckList = new uint[count]; + + for (int i = 0; i < count; i++) + { + header.AckList[i] = (uint)( + (bytes[(packetEnd - i * 4) - 3] << 24) | + (bytes[(packetEnd - i * 4) - 2] << 16) | + (bytes[(packetEnd - i * 4) - 1] << 8) | + (bytes[(packetEnd - i * 4) ])); + } + + packetEnd -= (count * 4); + } + } + } + + /// + /// A block of data in a packet. Packets are composed of one or more blocks, + /// each block containing one or more fields + /// + public abstract class PacketBlock + { + /// Current length of the data in this packet + public abstract int Length { get; } + + /// + /// Create a block from a byte array + /// + /// Byte array containing the serialized block + /// Starting position of the block in the byte array. + /// This will point to the data after the end of the block when the + /// call returns + public abstract void FromBytes(byte[] bytes, ref int i); + + /// + /// Serialize this block into a byte array + /// + /// Byte array to serialize this block into + /// Starting position in the byte array to serialize to. + /// This will point to the position directly after the end of the + /// serialized block when the call returns + public abstract void ToBytes(byte[] bytes, ref int i); + } + + public enum PacketType + { + /// A generic value, not an actual packet type + Default, + TestMessage = 65537, + UseCircuitCode = 65539, + TelehubInfo = 65546, + EconomyDataRequest = 65560, + EconomyData = 65561, + AvatarPickerRequest = 65562, + AvatarPickerReply = 65564, + PlacesQuery = 65565, + PlacesReply = 65566, + DirFindQuery = 65567, + DirPlacesQuery = 65569, + DirPlacesReply = 65571, + DirPeopleReply = 65572, + DirEventsReply = 65573, + DirGroupsReply = 65574, + DirClassifiedQuery = 65575, + DirClassifiedReply = 65577, + AvatarClassifiedReply = 65578, + ClassifiedInfoRequest = 65579, + ClassifiedInfoReply = 65580, + ClassifiedInfoUpdate = 65581, + ClassifiedDelete = 65582, + ClassifiedGodDelete = 65583, + DirLandQuery = 65584, + DirLandReply = 65586, + DirPopularQuery = 65587, + DirPopularReply = 65589, + ParcelInfoRequest = 65590, + ParcelInfoReply = 65591, + ParcelObjectOwnersRequest = 65592, + ParcelObjectOwnersReply = 65593, + GroupNoticesListRequest = 65594, + GroupNoticesListReply = 65595, + GroupNoticeRequest = 65596, + TeleportRequest = 65598, + TeleportLocationRequest = 65599, + TeleportLocal = 65600, + TeleportLandmarkRequest = 65601, + TeleportProgress = 65602, + TeleportFinish = 65605, + StartLure = 65606, + TeleportLureRequest = 65607, + TeleportCancel = 65608, + TeleportStart = 65609, + TeleportFailed = 65610, + Undo = 65611, + Redo = 65612, + UndoLand = 65613, + AgentPause = 65614, + AgentResume = 65615, + ChatFromViewer = 65616, + AgentThrottle = 65617, + AgentFOV = 65618, + AgentHeightWidth = 65619, + AgentSetAppearance = 65620, + AgentQuitCopy = 65621, + ImageNotInDatabase = 65622, + RebakeAvatarTextures = 65623, + SetAlwaysRun = 65624, + ObjectDelete = 65625, + ObjectDuplicate = 65626, + ObjectDuplicateOnRay = 65627, + ObjectScale = 65628, + ObjectRotation = 65629, + ObjectFlagUpdate = 65630, + ObjectClickAction = 65631, + ObjectImage = 65632, + ObjectMaterial = 65633, + ObjectShape = 65634, + ObjectExtraParams = 65635, + ObjectOwner = 65636, + ObjectGroup = 65637, + ObjectBuy = 65638, + BuyObjectInventory = 65639, + DerezContainer = 65640, + ObjectPermissions = 65641, + ObjectSaleInfo = 65642, + ObjectName = 65643, + ObjectDescription = 65644, + ObjectCategory = 65645, + ObjectSelect = 65646, + ObjectDeselect = 65647, + ObjectAttach = 65648, + ObjectDetach = 65649, + ObjectDrop = 65650, + ObjectLink = 65651, + ObjectDelink = 65652, + ObjectGrab = 65653, + ObjectGrabUpdate = 65654, + ObjectDeGrab = 65655, + ObjectSpinStart = 65656, + ObjectSpinUpdate = 65657, + ObjectSpinStop = 65658, + ObjectExportSelected = 65659, + ModifyLand = 65660, + VelocityInterpolateOn = 65661, + VelocityInterpolateOff = 65662, + StateSave = 65663, + ReportAutosaveCrash = 65664, + SimWideDeletes = 65665, + TrackAgent = 65666, + ViewerStats = 65667, + ScriptAnswerYes = 65668, + UserReport = 65669, + AlertMessage = 65670, + AgentAlertMessage = 65671, + MeanCollisionAlert = 65672, + ViewerFrozenMessage = 65673, + HealthMessage = 65674, + ChatFromSimulator = 65675, + SimStats = 65676, + RequestRegionInfo = 65677, + RegionInfo = 65678, + GodUpdateRegionInfo = 65679, + RegionHandshake = 65684, + RegionHandshakeReply = 65685, + SimulatorViewerTimeMessage = 65686, + EnableSimulator = 65687, + DisableSimulator = 65688, + TransferRequest = 65689, + TransferInfo = 65690, + TransferAbort = 65691, + RequestXfer = 65692, + AbortXfer = 65693, + AvatarAppearance = 65694, + SetFollowCamProperties = 65695, + ClearFollowCamProperties = 65696, + RequestPayPrice = 65697, + PayPriceReply = 65698, + KickUser = 65699, + GodKickUser = 65701, + EjectUser = 65703, + FreezeUser = 65704, + AvatarPropertiesRequest = 65705, + AvatarPropertiesReply = 65707, + AvatarInterestsReply = 65708, + AvatarGroupsReply = 65709, + AvatarPropertiesUpdate = 65710, + AvatarInterestsUpdate = 65711, + AvatarNotesReply = 65712, + AvatarNotesUpdate = 65713, + AvatarPicksReply = 65714, + EventInfoRequest = 65715, + EventInfoReply = 65716, + EventNotificationAddRequest = 65717, + EventNotificationRemoveRequest = 65718, + EventGodDelete = 65719, + PickInfoReply = 65720, + PickInfoUpdate = 65721, + PickDelete = 65722, + PickGodDelete = 65723, + ScriptQuestion = 65724, + ScriptControlChange = 65725, + ScriptDialog = 65726, + ScriptDialogReply = 65727, + ForceScriptControlRelease = 65728, + RevokePermissions = 65729, + LoadURL = 65730, + ScriptTeleportRequest = 65731, + ParcelOverlay = 65732, + ParcelPropertiesRequestByID = 65733, + ParcelPropertiesUpdate = 65734, + ParcelReturnObjects = 65735, + ParcelSetOtherCleanTime = 65736, + ParcelDisableObjects = 65737, + ParcelSelectObjects = 65738, + EstateCovenantRequest = 65739, + EstateCovenantReply = 65740, + ForceObjectSelect = 65741, + ParcelBuyPass = 65742, + ParcelDeedToGroup = 65743, + ParcelReclaim = 65744, + ParcelClaim = 65745, + ParcelJoin = 65746, + ParcelDivide = 65747, + ParcelRelease = 65748, + ParcelBuy = 65749, + ParcelGodForceOwner = 65750, + ParcelAccessListRequest = 65751, + ParcelAccessListReply = 65752, + ParcelAccessListUpdate = 65753, + ParcelDwellRequest = 65754, + ParcelDwellReply = 65755, + ParcelGodMarkAsContent = 65763, + ViewerStartAuction = 65764, + UUIDNameRequest = 65771, + UUIDNameReply = 65772, + UUIDGroupNameRequest = 65773, + UUIDGroupNameReply = 65774, + ChildAgentDying = 65776, + ChildAgentUnknown = 65777, + GetScriptRunning = 65779, + ScriptRunningReply = 65780, + SetScriptRunning = 65781, + ScriptReset = 65782, + ScriptSensorRequest = 65783, + ScriptSensorReply = 65784, + CompleteAgentMovement = 65785, + AgentMovementComplete = 65786, + LogoutRequest = 65788, + LogoutReply = 65789, + ImprovedInstantMessage = 65790, + RetrieveInstantMessages = 65791, + FindAgent = 65792, + RequestGodlikePowers = 65793, + GrantGodlikePowers = 65794, + GodlikeMessage = 65795, + EstateOwnerMessage = 65796, + GenericMessage = 65797, + MuteListRequest = 65798, + UpdateMuteListEntry = 65799, + RemoveMuteListEntry = 65800, + CopyInventoryFromNotecard = 65801, + UpdateInventoryItem = 65802, + UpdateCreateInventoryItem = 65803, + MoveInventoryItem = 65804, + CopyInventoryItem = 65805, + RemoveInventoryItem = 65806, + ChangeInventoryItemFlags = 65807, + SaveAssetIntoInventory = 65808, + CreateInventoryFolder = 65809, + UpdateInventoryFolder = 65810, + MoveInventoryFolder = 65811, + RemoveInventoryFolder = 65812, + FetchInventoryDescendents = 65813, + InventoryDescendents = 65814, + FetchInventory = 65815, + FetchInventoryReply = 65816, + BulkUpdateInventory = 65817, + RemoveInventoryObjects = 65820, + PurgeInventoryDescendents = 65821, + UpdateTaskInventory = 65822, + RemoveTaskInventory = 65823, + MoveTaskInventory = 65824, + RequestTaskInventory = 65825, + ReplyTaskInventory = 65826, + DeRezObject = 65827, + DeRezAck = 65828, + RezObject = 65829, + RezObjectFromNotecard = 65830, + AcceptFriendship = 65833, + DeclineFriendship = 65834, + TerminateFriendship = 65836, + OfferCallingCard = 65837, + AcceptCallingCard = 65838, + DeclineCallingCard = 65839, + RezScript = 65840, + CreateInventoryItem = 65841, + CreateLandmarkForEvent = 65842, + RegionHandleRequest = 65845, + RegionIDAndHandleReply = 65846, + MoneyTransferRequest = 65847, + MoneyBalanceRequest = 65849, + MoneyBalanceReply = 65850, + RoutedMoneyBalanceReply = 65851, + ActivateGestures = 65852, + DeactivateGestures = 65853, + MuteListUpdate = 65854, + UseCachedMuteList = 65855, + GrantUserRights = 65856, + ChangeUserRights = 65857, + OnlineNotification = 65858, + OfflineNotification = 65859, + SetStartLocationRequest = 65860, + AssetUploadRequest = 65869, + AssetUploadComplete = 65870, + CreateGroupRequest = 65875, + CreateGroupReply = 65876, + UpdateGroupInfo = 65877, + GroupRoleChanges = 65878, + JoinGroupRequest = 65879, + JoinGroupReply = 65880, + EjectGroupMemberRequest = 65881, + EjectGroupMemberReply = 65882, + LeaveGroupRequest = 65883, + LeaveGroupReply = 65884, + InviteGroupRequest = 65885, + GroupProfileRequest = 65887, + GroupProfileReply = 65888, + GroupAccountSummaryRequest = 65889, + GroupAccountSummaryReply = 65890, + GroupAccountDetailsRequest = 65891, + GroupAccountDetailsReply = 65892, + GroupAccountTransactionsRequest = 65893, + GroupAccountTransactionsReply = 65894, + GroupActiveProposalsRequest = 65895, + GroupActiveProposalItemReply = 65896, + GroupVoteHistoryRequest = 65897, + GroupVoteHistoryItemReply = 65898, + StartGroupProposal = 65899, + GroupProposalBallot = 65900, + GroupMembersRequest = 65902, + GroupMembersReply = 65903, + ActivateGroup = 65904, + SetGroupContribution = 65905, + SetGroupAcceptNotices = 65906, + GroupRoleDataRequest = 65907, + GroupRoleDataReply = 65908, + GroupRoleMembersRequest = 65909, + GroupRoleMembersReply = 65910, + GroupTitlesRequest = 65911, + GroupTitlesReply = 65912, + GroupTitleUpdate = 65913, + GroupRoleUpdate = 65914, + LiveHelpGroupRequest = 65915, + LiveHelpGroupReply = 65916, + AgentWearablesRequest = 65917, + AgentWearablesUpdate = 65918, + AgentIsNowWearing = 65919, + AgentCachedTexture = 65920, + AgentCachedTextureResponse = 65921, + AgentDataUpdateRequest = 65922, + AgentDataUpdate = 65923, + GroupDataUpdate = 65924, + AgentGroupDataUpdate = 65925, + AgentDropGroup = 65926, + RezSingleAttachmentFromInv = 65931, + RezMultipleAttachmentsFromInv = 65932, + DetachAttachmentIntoInv = 65933, + CreateNewOutfitAttachments = 65934, + UserInfoRequest = 65935, + UserInfoReply = 65936, + UpdateUserInfo = 65937, + InitiateDownload = 65939, + MapLayerRequest = 65941, + MapLayerReply = 65942, + MapBlockRequest = 65943, + MapNameRequest = 65944, + MapBlockReply = 65945, + MapItemRequest = 65946, + MapItemReply = 65947, + SendPostcard = 65948, + ParcelMediaCommandMessage = 65955, + ParcelMediaUpdate = 65956, + LandStatRequest = 65957, + LandStatReply = 65958, + Error = 65959, + ObjectIncludeInSearch = 65960, + RezRestoreToWorld = 65961, + LinkInventoryItem = 65962, + RetrieveIMsExtended = 65963, + JoinGroupRequestExtended = 65964, + CreateGroupRequestExtended = 65965, + PacketAck = 131067, + OpenCircuit = 131068, + CloseCircuit = 131069, + ObjectAdd = 131073, + MultipleObjectUpdate = 131074, + RequestMultipleObjects = 131075, + ObjectPosition = 131076, + RequestObjectPropertiesFamily = 131077, + CoarseLocationUpdate = 131078, + CrossedRegion = 131079, + ConfirmEnableSimulator = 131080, + ObjectProperties = 131081, + ObjectPropertiesFamily = 131082, + ParcelPropertiesRequest = 131083, + AttachedSound = 131085, + AttachedSoundGainChange = 131086, + PreloadSound = 131087, + ViewerEffect = 131089, + StartPingCheck = 196609, + CompletePingCheck = 196610, + AgentUpdate = 196612, + AgentAnimation = 196613, + AgentRequestSit = 196614, + AgentSit = 196615, + RequestImage = 196616, + ImageData = 196617, + ImagePacket = 196618, + LayerData = 196619, + ObjectUpdate = 196620, + ObjectUpdateCompressed = 196621, + ObjectUpdateCached = 196622, + ImprovedTerseObjectUpdate = 196623, + KillObject = 196624, + TransferPacket = 196625, + SendXferPacket = 196626, + ConfirmXferPacket = 196627, + AvatarAnimation = 196628, + AvatarSitResponse = 196629, + CameraConstraint = 196630, + ParcelProperties = 196631, + ChildAgentUpdate = 196633, + ChildAgentAlive = 196634, + ChildAgentPositionUpdate = 196635, + SoundTrigger = 196637, + ObjectAnimation = 196638, + } + + public abstract partial class Packet + { + public const int MTU = 1200; + + public Header Header; + public bool HasVariableBlocks; + public PacketType Type; + public abstract int Length { get; } + public abstract void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer); + public abstract void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd); + public abstract byte[] ToBytes(); + public abstract byte[][] ToBytesMultiple(); + + public virtual byte[] ToBytes(Interfaces.IByteBufferPool pool, ref int size) + { + throw new NotImplementedException(); + } + + public virtual byte[][] ToBytesMultiple(Interfaces.IByteBufferPool pool, out int[] sizes) + { + throw new NotImplementedException(); + } + + public virtual bool UsesBufferPooling + { + get + { + return false; + } + } + + public static PacketType GetType(ushort id, PacketFrequency frequency) + { + switch (frequency) + { + case PacketFrequency.Low: + switch (id) + { + case 1: return PacketType.TestMessage; + case 3: return PacketType.UseCircuitCode; + case 10: return PacketType.TelehubInfo; + case 24: return PacketType.EconomyDataRequest; + case 25: return PacketType.EconomyData; + case 26: return PacketType.AvatarPickerRequest; + case 28: return PacketType.AvatarPickerReply; + case 29: return PacketType.PlacesQuery; + case 30: return PacketType.PlacesReply; + case 31: return PacketType.DirFindQuery; + case 33: return PacketType.DirPlacesQuery; + case 35: return PacketType.DirPlacesReply; + case 36: return PacketType.DirPeopleReply; + case 37: return PacketType.DirEventsReply; + case 38: return PacketType.DirGroupsReply; + case 39: return PacketType.DirClassifiedQuery; + case 41: return PacketType.DirClassifiedReply; + case 42: return PacketType.AvatarClassifiedReply; + case 43: return PacketType.ClassifiedInfoRequest; + case 44: return PacketType.ClassifiedInfoReply; + case 45: return PacketType.ClassifiedInfoUpdate; + case 46: return PacketType.ClassifiedDelete; + case 47: return PacketType.ClassifiedGodDelete; + case 48: return PacketType.DirLandQuery; + case 50: return PacketType.DirLandReply; + case 51: return PacketType.DirPopularQuery; + case 53: return PacketType.DirPopularReply; + case 54: return PacketType.ParcelInfoRequest; + case 55: return PacketType.ParcelInfoReply; + case 56: return PacketType.ParcelObjectOwnersRequest; + case 57: return PacketType.ParcelObjectOwnersReply; + case 58: return PacketType.GroupNoticesListRequest; + case 59: return PacketType.GroupNoticesListReply; + case 60: return PacketType.GroupNoticeRequest; + case 62: return PacketType.TeleportRequest; + case 63: return PacketType.TeleportLocationRequest; + case 64: return PacketType.TeleportLocal; + case 65: return PacketType.TeleportLandmarkRequest; + case 66: return PacketType.TeleportProgress; + case 69: return PacketType.TeleportFinish; + case 70: return PacketType.StartLure; + case 71: return PacketType.TeleportLureRequest; + case 72: return PacketType.TeleportCancel; + case 73: return PacketType.TeleportStart; + case 74: return PacketType.TeleportFailed; + case 75: return PacketType.Undo; + case 76: return PacketType.Redo; + case 77: return PacketType.UndoLand; + case 78: return PacketType.AgentPause; + case 79: return PacketType.AgentResume; + case 80: return PacketType.ChatFromViewer; + case 81: return PacketType.AgentThrottle; + case 82: return PacketType.AgentFOV; + case 83: return PacketType.AgentHeightWidth; + case 84: return PacketType.AgentSetAppearance; + case 85: return PacketType.AgentQuitCopy; + case 86: return PacketType.ImageNotInDatabase; + case 87: return PacketType.RebakeAvatarTextures; + case 88: return PacketType.SetAlwaysRun; + case 89: return PacketType.ObjectDelete; + case 90: return PacketType.ObjectDuplicate; + case 91: return PacketType.ObjectDuplicateOnRay; + case 92: return PacketType.ObjectScale; + case 93: return PacketType.ObjectRotation; + case 94: return PacketType.ObjectFlagUpdate; + case 95: return PacketType.ObjectClickAction; + case 96: return PacketType.ObjectImage; + case 97: return PacketType.ObjectMaterial; + case 98: return PacketType.ObjectShape; + case 99: return PacketType.ObjectExtraParams; + case 100: return PacketType.ObjectOwner; + case 101: return PacketType.ObjectGroup; + case 102: return PacketType.ObjectBuy; + case 103: return PacketType.BuyObjectInventory; + case 104: return PacketType.DerezContainer; + case 105: return PacketType.ObjectPermissions; + case 106: return PacketType.ObjectSaleInfo; + case 107: return PacketType.ObjectName; + case 108: return PacketType.ObjectDescription; + case 109: return PacketType.ObjectCategory; + case 110: return PacketType.ObjectSelect; + case 111: return PacketType.ObjectDeselect; + case 112: return PacketType.ObjectAttach; + case 113: return PacketType.ObjectDetach; + case 114: return PacketType.ObjectDrop; + case 115: return PacketType.ObjectLink; + case 116: return PacketType.ObjectDelink; + case 117: return PacketType.ObjectGrab; + case 118: return PacketType.ObjectGrabUpdate; + case 119: return PacketType.ObjectDeGrab; + case 120: return PacketType.ObjectSpinStart; + case 121: return PacketType.ObjectSpinUpdate; + case 122: return PacketType.ObjectSpinStop; + case 123: return PacketType.ObjectExportSelected; + case 124: return PacketType.ModifyLand; + case 125: return PacketType.VelocityInterpolateOn; + case 126: return PacketType.VelocityInterpolateOff; + case 127: return PacketType.StateSave; + case 128: return PacketType.ReportAutosaveCrash; + case 129: return PacketType.SimWideDeletes; + case 130: return PacketType.TrackAgent; + case 131: return PacketType.ViewerStats; + case 132: return PacketType.ScriptAnswerYes; + case 133: return PacketType.UserReport; + case 134: return PacketType.AlertMessage; + case 135: return PacketType.AgentAlertMessage; + case 136: return PacketType.MeanCollisionAlert; + case 137: return PacketType.ViewerFrozenMessage; + case 138: return PacketType.HealthMessage; + case 139: return PacketType.ChatFromSimulator; + case 140: return PacketType.SimStats; + case 141: return PacketType.RequestRegionInfo; + case 142: return PacketType.RegionInfo; + case 143: return PacketType.GodUpdateRegionInfo; + case 148: return PacketType.RegionHandshake; + case 149: return PacketType.RegionHandshakeReply; + case 150: return PacketType.SimulatorViewerTimeMessage; + case 151: return PacketType.EnableSimulator; + case 152: return PacketType.DisableSimulator; + case 153: return PacketType.TransferRequest; + case 154: return PacketType.TransferInfo; + case 155: return PacketType.TransferAbort; + case 156: return PacketType.RequestXfer; + case 157: return PacketType.AbortXfer; + case 158: return PacketType.AvatarAppearance; + case 159: return PacketType.SetFollowCamProperties; + case 160: return PacketType.ClearFollowCamProperties; + case 161: return PacketType.RequestPayPrice; + case 162: return PacketType.PayPriceReply; + case 163: return PacketType.KickUser; + case 165: return PacketType.GodKickUser; + case 167: return PacketType.EjectUser; + case 168: return PacketType.FreezeUser; + case 169: return PacketType.AvatarPropertiesRequest; + case 171: return PacketType.AvatarPropertiesReply; + case 172: return PacketType.AvatarInterestsReply; + case 173: return PacketType.AvatarGroupsReply; + case 174: return PacketType.AvatarPropertiesUpdate; + case 175: return PacketType.AvatarInterestsUpdate; + case 176: return PacketType.AvatarNotesReply; + case 177: return PacketType.AvatarNotesUpdate; + case 178: return PacketType.AvatarPicksReply; + case 179: return PacketType.EventInfoRequest; + case 180: return PacketType.EventInfoReply; + case 181: return PacketType.EventNotificationAddRequest; + case 182: return PacketType.EventNotificationRemoveRequest; + case 183: return PacketType.EventGodDelete; + case 184: return PacketType.PickInfoReply; + case 185: return PacketType.PickInfoUpdate; + case 186: return PacketType.PickDelete; + case 187: return PacketType.PickGodDelete; + case 188: return PacketType.ScriptQuestion; + case 189: return PacketType.ScriptControlChange; + case 190: return PacketType.ScriptDialog; + case 191: return PacketType.ScriptDialogReply; + case 192: return PacketType.ForceScriptControlRelease; + case 193: return PacketType.RevokePermissions; + case 194: return PacketType.LoadURL; + case 195: return PacketType.ScriptTeleportRequest; + case 196: return PacketType.ParcelOverlay; + case 197: return PacketType.ParcelPropertiesRequestByID; + case 198: return PacketType.ParcelPropertiesUpdate; + case 199: return PacketType.ParcelReturnObjects; + case 200: return PacketType.ParcelSetOtherCleanTime; + case 201: return PacketType.ParcelDisableObjects; + case 202: return PacketType.ParcelSelectObjects; + case 203: return PacketType.EstateCovenantRequest; + case 204: return PacketType.EstateCovenantReply; + case 205: return PacketType.ForceObjectSelect; + case 206: return PacketType.ParcelBuyPass; + case 207: return PacketType.ParcelDeedToGroup; + case 208: return PacketType.ParcelReclaim; + case 209: return PacketType.ParcelClaim; + case 210: return PacketType.ParcelJoin; + case 211: return PacketType.ParcelDivide; + case 212: return PacketType.ParcelRelease; + case 213: return PacketType.ParcelBuy; + case 214: return PacketType.ParcelGodForceOwner; + case 215: return PacketType.ParcelAccessListRequest; + case 216: return PacketType.ParcelAccessListReply; + case 217: return PacketType.ParcelAccessListUpdate; + case 218: return PacketType.ParcelDwellRequest; + case 219: return PacketType.ParcelDwellReply; + case 227: return PacketType.ParcelGodMarkAsContent; + case 228: return PacketType.ViewerStartAuction; + case 235: return PacketType.UUIDNameRequest; + case 236: return PacketType.UUIDNameReply; + case 237: return PacketType.UUIDGroupNameRequest; + case 238: return PacketType.UUIDGroupNameReply; + case 240: return PacketType.ChildAgentDying; + case 241: return PacketType.ChildAgentUnknown; + case 243: return PacketType.GetScriptRunning; + case 244: return PacketType.ScriptRunningReply; + case 245: return PacketType.SetScriptRunning; + case 246: return PacketType.ScriptReset; + case 247: return PacketType.ScriptSensorRequest; + case 248: return PacketType.ScriptSensorReply; + case 249: return PacketType.CompleteAgentMovement; + case 250: return PacketType.AgentMovementComplete; + case 252: return PacketType.LogoutRequest; + case 253: return PacketType.LogoutReply; + case 254: return PacketType.ImprovedInstantMessage; + case 255: return PacketType.RetrieveInstantMessages; + case 256: return PacketType.FindAgent; + case 257: return PacketType.RequestGodlikePowers; + case 258: return PacketType.GrantGodlikePowers; + case 259: return PacketType.GodlikeMessage; + case 260: return PacketType.EstateOwnerMessage; + case 261: return PacketType.GenericMessage; + case 262: return PacketType.MuteListRequest; + case 263: return PacketType.UpdateMuteListEntry; + case 264: return PacketType.RemoveMuteListEntry; + case 265: return PacketType.CopyInventoryFromNotecard; + case 266: return PacketType.UpdateInventoryItem; + case 267: return PacketType.UpdateCreateInventoryItem; + case 268: return PacketType.MoveInventoryItem; + case 269: return PacketType.CopyInventoryItem; + case 270: return PacketType.RemoveInventoryItem; + case 271: return PacketType.ChangeInventoryItemFlags; + case 272: return PacketType.SaveAssetIntoInventory; + case 273: return PacketType.CreateInventoryFolder; + case 274: return PacketType.UpdateInventoryFolder; + case 275: return PacketType.MoveInventoryFolder; + case 276: return PacketType.RemoveInventoryFolder; + case 277: return PacketType.FetchInventoryDescendents; + case 278: return PacketType.InventoryDescendents; + case 279: return PacketType.FetchInventory; + case 280: return PacketType.FetchInventoryReply; + case 281: return PacketType.BulkUpdateInventory; + case 284: return PacketType.RemoveInventoryObjects; + case 285: return PacketType.PurgeInventoryDescendents; + case 286: return PacketType.UpdateTaskInventory; + case 287: return PacketType.RemoveTaskInventory; + case 288: return PacketType.MoveTaskInventory; + case 289: return PacketType.RequestTaskInventory; + case 290: return PacketType.ReplyTaskInventory; + case 291: return PacketType.DeRezObject; + case 292: return PacketType.DeRezAck; + case 293: return PacketType.RezObject; + case 294: return PacketType.RezObjectFromNotecard; + case 297: return PacketType.AcceptFriendship; + case 298: return PacketType.DeclineFriendship; + case 300: return PacketType.TerminateFriendship; + case 301: return PacketType.OfferCallingCard; + case 302: return PacketType.AcceptCallingCard; + case 303: return PacketType.DeclineCallingCard; + case 304: return PacketType.RezScript; + case 305: return PacketType.CreateInventoryItem; + case 306: return PacketType.CreateLandmarkForEvent; + case 309: return PacketType.RegionHandleRequest; + case 310: return PacketType.RegionIDAndHandleReply; + case 311: return PacketType.MoneyTransferRequest; + case 313: return PacketType.MoneyBalanceRequest; + case 314: return PacketType.MoneyBalanceReply; + case 315: return PacketType.RoutedMoneyBalanceReply; + case 316: return PacketType.ActivateGestures; + case 317: return PacketType.DeactivateGestures; + case 318: return PacketType.MuteListUpdate; + case 319: return PacketType.UseCachedMuteList; + case 320: return PacketType.GrantUserRights; + case 321: return PacketType.ChangeUserRights; + case 322: return PacketType.OnlineNotification; + case 323: return PacketType.OfflineNotification; + case 324: return PacketType.SetStartLocationRequest; + case 333: return PacketType.AssetUploadRequest; + case 334: return PacketType.AssetUploadComplete; + case 339: return PacketType.CreateGroupRequest; + case 340: return PacketType.CreateGroupReply; + case 341: return PacketType.UpdateGroupInfo; + case 342: return PacketType.GroupRoleChanges; + case 343: return PacketType.JoinGroupRequest; + case 344: return PacketType.JoinGroupReply; + case 345: return PacketType.EjectGroupMemberRequest; + case 346: return PacketType.EjectGroupMemberReply; + case 347: return PacketType.LeaveGroupRequest; + case 348: return PacketType.LeaveGroupReply; + case 349: return PacketType.InviteGroupRequest; + case 351: return PacketType.GroupProfileRequest; + case 352: return PacketType.GroupProfileReply; + case 353: return PacketType.GroupAccountSummaryRequest; + case 354: return PacketType.GroupAccountSummaryReply; + case 355: return PacketType.GroupAccountDetailsRequest; + case 356: return PacketType.GroupAccountDetailsReply; + case 357: return PacketType.GroupAccountTransactionsRequest; + case 358: return PacketType.GroupAccountTransactionsReply; + case 359: return PacketType.GroupActiveProposalsRequest; + case 360: return PacketType.GroupActiveProposalItemReply; + case 361: return PacketType.GroupVoteHistoryRequest; + case 362: return PacketType.GroupVoteHistoryItemReply; + case 363: return PacketType.StartGroupProposal; + case 364: return PacketType.GroupProposalBallot; + case 366: return PacketType.GroupMembersRequest; + case 367: return PacketType.GroupMembersReply; + case 368: return PacketType.ActivateGroup; + case 369: return PacketType.SetGroupContribution; + case 370: return PacketType.SetGroupAcceptNotices; + case 371: return PacketType.GroupRoleDataRequest; + case 372: return PacketType.GroupRoleDataReply; + case 373: return PacketType.GroupRoleMembersRequest; + case 374: return PacketType.GroupRoleMembersReply; + case 375: return PacketType.GroupTitlesRequest; + case 376: return PacketType.GroupTitlesReply; + case 377: return PacketType.GroupTitleUpdate; + case 378: return PacketType.GroupRoleUpdate; + case 379: return PacketType.LiveHelpGroupRequest; + case 380: return PacketType.LiveHelpGroupReply; + case 381: return PacketType.AgentWearablesRequest; + case 382: return PacketType.AgentWearablesUpdate; + case 383: return PacketType.AgentIsNowWearing; + case 384: return PacketType.AgentCachedTexture; + case 385: return PacketType.AgentCachedTextureResponse; + case 386: return PacketType.AgentDataUpdateRequest; + case 387: return PacketType.AgentDataUpdate; + case 388: return PacketType.GroupDataUpdate; + case 389: return PacketType.AgentGroupDataUpdate; + case 390: return PacketType.AgentDropGroup; + case 395: return PacketType.RezSingleAttachmentFromInv; + case 396: return PacketType.RezMultipleAttachmentsFromInv; + case 397: return PacketType.DetachAttachmentIntoInv; + case 398: return PacketType.CreateNewOutfitAttachments; + case 399: return PacketType.UserInfoRequest; + case 400: return PacketType.UserInfoReply; + case 401: return PacketType.UpdateUserInfo; + case 403: return PacketType.InitiateDownload; + case 405: return PacketType.MapLayerRequest; + case 406: return PacketType.MapLayerReply; + case 407: return PacketType.MapBlockRequest; + case 408: return PacketType.MapNameRequest; + case 409: return PacketType.MapBlockReply; + case 410: return PacketType.MapItemRequest; + case 411: return PacketType.MapItemReply; + case 412: return PacketType.SendPostcard; + case 419: return PacketType.ParcelMediaCommandMessage; + case 420: return PacketType.ParcelMediaUpdate; + case 421: return PacketType.LandStatRequest; + case 422: return PacketType.LandStatReply; + case 423: return PacketType.Error; + case 424: return PacketType.ObjectIncludeInSearch; + case 425: return PacketType.RezRestoreToWorld; + case 426: return PacketType.LinkInventoryItem; + case 427: return PacketType.RetrieveIMsExtended; + case 428: return PacketType.JoinGroupRequestExtended; + case 429: return PacketType.CreateGroupRequestExtended; + case 65531: return PacketType.PacketAck; + case 65532: return PacketType.OpenCircuit; + case 65533: return PacketType.CloseCircuit; + } + break; + case PacketFrequency.Medium: + switch (id) + { + case 1: return PacketType.ObjectAdd; + case 2: return PacketType.MultipleObjectUpdate; + case 3: return PacketType.RequestMultipleObjects; + case 4: return PacketType.ObjectPosition; + case 5: return PacketType.RequestObjectPropertiesFamily; + case 6: return PacketType.CoarseLocationUpdate; + case 7: return PacketType.CrossedRegion; + case 8: return PacketType.ConfirmEnableSimulator; + case 9: return PacketType.ObjectProperties; + case 10: return PacketType.ObjectPropertiesFamily; + case 11: return PacketType.ParcelPropertiesRequest; + case 13: return PacketType.AttachedSound; + case 14: return PacketType.AttachedSoundGainChange; + case 15: return PacketType.PreloadSound; + case 17: return PacketType.ViewerEffect; + } + break; + case PacketFrequency.High: + switch (id) + { + case 1: return PacketType.StartPingCheck; + case 2: return PacketType.CompletePingCheck; + case 4: return PacketType.AgentUpdate; + case 5: return PacketType.AgentAnimation; + case 6: return PacketType.AgentRequestSit; + case 7: return PacketType.AgentSit; + case 8: return PacketType.RequestImage; + case 9: return PacketType.ImageData; + case 10: return PacketType.ImagePacket; + case 11: return PacketType.LayerData; + case 12: return PacketType.ObjectUpdate; + case 13: return PacketType.ObjectUpdateCompressed; + case 14: return PacketType.ObjectUpdateCached; + case 15: return PacketType.ImprovedTerseObjectUpdate; + case 16: return PacketType.KillObject; + case 17: return PacketType.TransferPacket; + case 18: return PacketType.SendXferPacket; + case 19: return PacketType.ConfirmXferPacket; + case 20: return PacketType.AvatarAnimation; + case 21: return PacketType.AvatarSitResponse; + case 22: return PacketType.CameraConstraint; + case 23: return PacketType.ParcelProperties; + case 25: return PacketType.ChildAgentUpdate; + case 26: return PacketType.ChildAgentAlive; + case 27: return PacketType.ChildAgentPositionUpdate; + case 29: return PacketType.SoundTrigger; + case 30: return PacketType.ObjectAnimation; + } + break; + } + + return PacketType.Default; + } + + public static Packet BuildPacket(PacketType type) + { + if(type == PacketType.StartPingCheck) return new StartPingCheckPacket(); + if(type == PacketType.CompletePingCheck) return new CompletePingCheckPacket(); + if(type == PacketType.AgentUpdate) return new AgentUpdatePacket(); + if(type == PacketType.AgentAnimation) return new AgentAnimationPacket(); + if(type == PacketType.AgentRequestSit) return new AgentRequestSitPacket(); + if(type == PacketType.AgentSit) return new AgentSitPacket(); + if(type == PacketType.RequestImage) return new RequestImagePacket(); + if(type == PacketType.ImageData) return new ImageDataPacket(); + if(type == PacketType.ImagePacket) return new ImagePacketPacket(); + if(type == PacketType.LayerData) return new LayerDataPacket(); + if(type == PacketType.ObjectUpdate) return new ObjectUpdatePacket(); + if(type == PacketType.ObjectUpdateCompressed) return new ObjectUpdateCompressedPacket(); + if(type == PacketType.ObjectUpdateCached) return new ObjectUpdateCachedPacket(); + if(type == PacketType.ImprovedTerseObjectUpdate) return new ImprovedTerseObjectUpdatePacket(); + if(type == PacketType.KillObject) return new KillObjectPacket(); + if(type == PacketType.TransferPacket) return new TransferPacketPacket(); + if(type == PacketType.SendXferPacket) return new SendXferPacketPacket(); + if(type == PacketType.ConfirmXferPacket) return new ConfirmXferPacketPacket(); + if(type == PacketType.AvatarAnimation) return new AvatarAnimationPacket(); + if(type == PacketType.AvatarSitResponse) return new AvatarSitResponsePacket(); + if(type == PacketType.CameraConstraint) return new CameraConstraintPacket(); + if(type == PacketType.ParcelProperties) return new ParcelPropertiesPacket(); + if(type == PacketType.ChildAgentUpdate) return new ChildAgentUpdatePacket(); + if(type == PacketType.ChildAgentAlive) return new ChildAgentAlivePacket(); + if(type == PacketType.ChildAgentPositionUpdate) return new ChildAgentPositionUpdatePacket(); + if(type == PacketType.SoundTrigger) return new SoundTriggerPacket(); + if(type == PacketType.ObjectAnimation) return new ObjectAnimationPacket(); + if(type == PacketType.ObjectAdd) return new ObjectAddPacket(); + if(type == PacketType.MultipleObjectUpdate) return new MultipleObjectUpdatePacket(); + if(type == PacketType.RequestMultipleObjects) return new RequestMultipleObjectsPacket(); + if(type == PacketType.ObjectPosition) return new ObjectPositionPacket(); + if(type == PacketType.RequestObjectPropertiesFamily) return new RequestObjectPropertiesFamilyPacket(); + if(type == PacketType.CoarseLocationUpdate) return new CoarseLocationUpdatePacket(); + if(type == PacketType.CrossedRegion) return new CrossedRegionPacket(); + if(type == PacketType.ConfirmEnableSimulator) return new ConfirmEnableSimulatorPacket(); + if(type == PacketType.ObjectProperties) return new ObjectPropertiesPacket(); + if(type == PacketType.ObjectPropertiesFamily) return new ObjectPropertiesFamilyPacket(); + if(type == PacketType.ParcelPropertiesRequest) return new ParcelPropertiesRequestPacket(); + if(type == PacketType.AttachedSound) return new AttachedSoundPacket(); + if(type == PacketType.AttachedSoundGainChange) return new AttachedSoundGainChangePacket(); + if(type == PacketType.PreloadSound) return new PreloadSoundPacket(); + if(type == PacketType.ViewerEffect) return new ViewerEffectPacket(); + if(type == PacketType.TestMessage) return new TestMessagePacket(); + if(type == PacketType.UseCircuitCode) return new UseCircuitCodePacket(); + if(type == PacketType.TelehubInfo) return new TelehubInfoPacket(); + if(type == PacketType.EconomyDataRequest) return new EconomyDataRequestPacket(); + if(type == PacketType.EconomyData) return new EconomyDataPacket(); + if(type == PacketType.AvatarPickerRequest) return new AvatarPickerRequestPacket(); + if(type == PacketType.AvatarPickerReply) return new AvatarPickerReplyPacket(); + if(type == PacketType.PlacesQuery) return new PlacesQueryPacket(); + if(type == PacketType.PlacesReply) return new PlacesReplyPacket(); + if(type == PacketType.DirFindQuery) return new DirFindQueryPacket(); + if(type == PacketType.DirPlacesQuery) return new DirPlacesQueryPacket(); + if(type == PacketType.DirPlacesReply) return new DirPlacesReplyPacket(); + if(type == PacketType.DirPeopleReply) return new DirPeopleReplyPacket(); + if(type == PacketType.DirEventsReply) return new DirEventsReplyPacket(); + if(type == PacketType.DirGroupsReply) return new DirGroupsReplyPacket(); + if(type == PacketType.DirClassifiedQuery) return new DirClassifiedQueryPacket(); + if(type == PacketType.DirClassifiedReply) return new DirClassifiedReplyPacket(); + if(type == PacketType.AvatarClassifiedReply) return new AvatarClassifiedReplyPacket(); + if(type == PacketType.ClassifiedInfoRequest) return new ClassifiedInfoRequestPacket(); + if(type == PacketType.ClassifiedInfoReply) return new ClassifiedInfoReplyPacket(); + if(type == PacketType.ClassifiedInfoUpdate) return new ClassifiedInfoUpdatePacket(); + if(type == PacketType.ClassifiedDelete) return new ClassifiedDeletePacket(); + if(type == PacketType.ClassifiedGodDelete) return new ClassifiedGodDeletePacket(); + if(type == PacketType.DirLandQuery) return new DirLandQueryPacket(); + if(type == PacketType.DirLandReply) return new DirLandReplyPacket(); + if(type == PacketType.DirPopularQuery) return new DirPopularQueryPacket(); + if(type == PacketType.DirPopularReply) return new DirPopularReplyPacket(); + if(type == PacketType.ParcelInfoRequest) return new ParcelInfoRequestPacket(); + if(type == PacketType.ParcelInfoReply) return new ParcelInfoReplyPacket(); + if(type == PacketType.ParcelObjectOwnersRequest) return new ParcelObjectOwnersRequestPacket(); + if(type == PacketType.ParcelObjectOwnersReply) return new ParcelObjectOwnersReplyPacket(); + if(type == PacketType.GroupNoticesListRequest) return new GroupNoticesListRequestPacket(); + if(type == PacketType.GroupNoticesListReply) return new GroupNoticesListReplyPacket(); + if(type == PacketType.GroupNoticeRequest) return new GroupNoticeRequestPacket(); + if(type == PacketType.TeleportRequest) return new TeleportRequestPacket(); + if(type == PacketType.TeleportLocationRequest) return new TeleportLocationRequestPacket(); + if(type == PacketType.TeleportLocal) return new TeleportLocalPacket(); + if(type == PacketType.TeleportLandmarkRequest) return new TeleportLandmarkRequestPacket(); + if(type == PacketType.TeleportProgress) return new TeleportProgressPacket(); + if(type == PacketType.TeleportFinish) return new TeleportFinishPacket(); + if(type == PacketType.StartLure) return new StartLurePacket(); + if(type == PacketType.TeleportLureRequest) return new TeleportLureRequestPacket(); + if(type == PacketType.TeleportCancel) return new TeleportCancelPacket(); + if(type == PacketType.TeleportStart) return new TeleportStartPacket(); + if(type == PacketType.TeleportFailed) return new TeleportFailedPacket(); + if(type == PacketType.Undo) return new UndoPacket(); + if(type == PacketType.Redo) return new RedoPacket(); + if(type == PacketType.UndoLand) return new UndoLandPacket(); + if(type == PacketType.AgentPause) return new AgentPausePacket(); + if(type == PacketType.AgentResume) return new AgentResumePacket(); + if(type == PacketType.ChatFromViewer) return new ChatFromViewerPacket(); + if(type == PacketType.AgentThrottle) return new AgentThrottlePacket(); + if(type == PacketType.AgentFOV) return new AgentFOVPacket(); + if(type == PacketType.AgentHeightWidth) return new AgentHeightWidthPacket(); + if(type == PacketType.AgentSetAppearance) return new AgentSetAppearancePacket(); + if(type == PacketType.AgentQuitCopy) return new AgentQuitCopyPacket(); + if(type == PacketType.ImageNotInDatabase) return new ImageNotInDatabasePacket(); + if(type == PacketType.RebakeAvatarTextures) return new RebakeAvatarTexturesPacket(); + if(type == PacketType.SetAlwaysRun) return new SetAlwaysRunPacket(); + if(type == PacketType.ObjectDelete) return new ObjectDeletePacket(); + if(type == PacketType.ObjectDuplicate) return new ObjectDuplicatePacket(); + if(type == PacketType.ObjectDuplicateOnRay) return new ObjectDuplicateOnRayPacket(); + if(type == PacketType.ObjectScale) return new ObjectScalePacket(); + if(type == PacketType.ObjectRotation) return new ObjectRotationPacket(); + if(type == PacketType.ObjectFlagUpdate) return new ObjectFlagUpdatePacket(); + if(type == PacketType.ObjectClickAction) return new ObjectClickActionPacket(); + if(type == PacketType.ObjectImage) return new ObjectImagePacket(); + if(type == PacketType.ObjectMaterial) return new ObjectMaterialPacket(); + if(type == PacketType.ObjectShape) return new ObjectShapePacket(); + if(type == PacketType.ObjectExtraParams) return new ObjectExtraParamsPacket(); + if(type == PacketType.ObjectOwner) return new ObjectOwnerPacket(); + if(type == PacketType.ObjectGroup) return new ObjectGroupPacket(); + if(type == PacketType.ObjectBuy) return new ObjectBuyPacket(); + if(type == PacketType.BuyObjectInventory) return new BuyObjectInventoryPacket(); + if(type == PacketType.DerezContainer) return new DerezContainerPacket(); + if(type == PacketType.ObjectPermissions) return new ObjectPermissionsPacket(); + if(type == PacketType.ObjectSaleInfo) return new ObjectSaleInfoPacket(); + if(type == PacketType.ObjectName) return new ObjectNamePacket(); + if(type == PacketType.ObjectDescription) return new ObjectDescriptionPacket(); + if(type == PacketType.ObjectCategory) return new ObjectCategoryPacket(); + if(type == PacketType.ObjectSelect) return new ObjectSelectPacket(); + if(type == PacketType.ObjectDeselect) return new ObjectDeselectPacket(); + if(type == PacketType.ObjectAttach) return new ObjectAttachPacket(); + if(type == PacketType.ObjectDetach) return new ObjectDetachPacket(); + if(type == PacketType.ObjectDrop) return new ObjectDropPacket(); + if(type == PacketType.ObjectLink) return new ObjectLinkPacket(); + if(type == PacketType.ObjectDelink) return new ObjectDelinkPacket(); + if(type == PacketType.ObjectGrab) return new ObjectGrabPacket(); + if(type == PacketType.ObjectGrabUpdate) return new ObjectGrabUpdatePacket(); + if(type == PacketType.ObjectDeGrab) return new ObjectDeGrabPacket(); + if(type == PacketType.ObjectSpinStart) return new ObjectSpinStartPacket(); + if(type == PacketType.ObjectSpinUpdate) return new ObjectSpinUpdatePacket(); + if(type == PacketType.ObjectSpinStop) return new ObjectSpinStopPacket(); + if(type == PacketType.ObjectExportSelected) return new ObjectExportSelectedPacket(); + if(type == PacketType.ModifyLand) return new ModifyLandPacket(); + if(type == PacketType.VelocityInterpolateOn) return new VelocityInterpolateOnPacket(); + if(type == PacketType.VelocityInterpolateOff) return new VelocityInterpolateOffPacket(); + if(type == PacketType.StateSave) return new StateSavePacket(); + if(type == PacketType.ReportAutosaveCrash) return new ReportAutosaveCrashPacket(); + if(type == PacketType.SimWideDeletes) return new SimWideDeletesPacket(); + if(type == PacketType.TrackAgent) return new TrackAgentPacket(); + if(type == PacketType.ViewerStats) return new ViewerStatsPacket(); + if(type == PacketType.ScriptAnswerYes) return new ScriptAnswerYesPacket(); + if(type == PacketType.UserReport) return new UserReportPacket(); + if(type == PacketType.AlertMessage) return new AlertMessagePacket(); + if(type == PacketType.AgentAlertMessage) return new AgentAlertMessagePacket(); + if(type == PacketType.MeanCollisionAlert) return new MeanCollisionAlertPacket(); + if(type == PacketType.ViewerFrozenMessage) return new ViewerFrozenMessagePacket(); + if(type == PacketType.HealthMessage) return new HealthMessagePacket(); + if(type == PacketType.ChatFromSimulator) return new ChatFromSimulatorPacket(); + if(type == PacketType.SimStats) return new SimStatsPacket(); + if(type == PacketType.RequestRegionInfo) return new RequestRegionInfoPacket(); + if(type == PacketType.RegionInfo) return new RegionInfoPacket(); + if(type == PacketType.GodUpdateRegionInfo) return new GodUpdateRegionInfoPacket(); + if(type == PacketType.RegionHandshake) return new RegionHandshakePacket(); + if(type == PacketType.RegionHandshakeReply) return new RegionHandshakeReplyPacket(); + if(type == PacketType.SimulatorViewerTimeMessage) return new SimulatorViewerTimeMessagePacket(); + if(type == PacketType.EnableSimulator) return new EnableSimulatorPacket(); + if(type == PacketType.DisableSimulator) return new DisableSimulatorPacket(); + if(type == PacketType.TransferRequest) return new TransferRequestPacket(); + if(type == PacketType.TransferInfo) return new TransferInfoPacket(); + if(type == PacketType.TransferAbort) return new TransferAbortPacket(); + if(type == PacketType.RequestXfer) return new RequestXferPacket(); + if(type == PacketType.AbortXfer) return new AbortXferPacket(); + if(type == PacketType.AvatarAppearance) return new AvatarAppearancePacket(); + if(type == PacketType.SetFollowCamProperties) return new SetFollowCamPropertiesPacket(); + if(type == PacketType.ClearFollowCamProperties) return new ClearFollowCamPropertiesPacket(); + if(type == PacketType.RequestPayPrice) return new RequestPayPricePacket(); + if(type == PacketType.PayPriceReply) return new PayPriceReplyPacket(); + if(type == PacketType.KickUser) return new KickUserPacket(); + if(type == PacketType.GodKickUser) return new GodKickUserPacket(); + if(type == PacketType.EjectUser) return new EjectUserPacket(); + if(type == PacketType.FreezeUser) return new FreezeUserPacket(); + if(type == PacketType.AvatarPropertiesRequest) return new AvatarPropertiesRequestPacket(); + if(type == PacketType.AvatarPropertiesReply) return new AvatarPropertiesReplyPacket(); + if(type == PacketType.AvatarInterestsReply) return new AvatarInterestsReplyPacket(); + if(type == PacketType.AvatarGroupsReply) return new AvatarGroupsReplyPacket(); + if(type == PacketType.AvatarPropertiesUpdate) return new AvatarPropertiesUpdatePacket(); + if(type == PacketType.AvatarInterestsUpdate) return new AvatarInterestsUpdatePacket(); + if(type == PacketType.AvatarNotesReply) return new AvatarNotesReplyPacket(); + if(type == PacketType.AvatarNotesUpdate) return new AvatarNotesUpdatePacket(); + if(type == PacketType.AvatarPicksReply) return new AvatarPicksReplyPacket(); + if(type == PacketType.EventInfoRequest) return new EventInfoRequestPacket(); + if(type == PacketType.EventInfoReply) return new EventInfoReplyPacket(); + if(type == PacketType.EventNotificationAddRequest) return new EventNotificationAddRequestPacket(); + if(type == PacketType.EventNotificationRemoveRequest) return new EventNotificationRemoveRequestPacket(); + if(type == PacketType.EventGodDelete) return new EventGodDeletePacket(); + if(type == PacketType.PickInfoReply) return new PickInfoReplyPacket(); + if(type == PacketType.PickInfoUpdate) return new PickInfoUpdatePacket(); + if(type == PacketType.PickDelete) return new PickDeletePacket(); + if(type == PacketType.PickGodDelete) return new PickGodDeletePacket(); + if(type == PacketType.ScriptQuestion) return new ScriptQuestionPacket(); + if(type == PacketType.ScriptControlChange) return new ScriptControlChangePacket(); + if(type == PacketType.ScriptDialog) return new ScriptDialogPacket(); + if(type == PacketType.ScriptDialogReply) return new ScriptDialogReplyPacket(); + if(type == PacketType.ForceScriptControlRelease) return new ForceScriptControlReleasePacket(); + if(type == PacketType.RevokePermissions) return new RevokePermissionsPacket(); + if(type == PacketType.LoadURL) return new LoadURLPacket(); + if(type == PacketType.ScriptTeleportRequest) return new ScriptTeleportRequestPacket(); + if(type == PacketType.ParcelOverlay) return new ParcelOverlayPacket(); + if(type == PacketType.ParcelPropertiesRequestByID) return new ParcelPropertiesRequestByIDPacket(); + if(type == PacketType.ParcelPropertiesUpdate) return new ParcelPropertiesUpdatePacket(); + if(type == PacketType.ParcelReturnObjects) return new ParcelReturnObjectsPacket(); + if(type == PacketType.ParcelSetOtherCleanTime) return new ParcelSetOtherCleanTimePacket(); + if(type == PacketType.ParcelDisableObjects) return new ParcelDisableObjectsPacket(); + if(type == PacketType.ParcelSelectObjects) return new ParcelSelectObjectsPacket(); + if(type == PacketType.EstateCovenantRequest) return new EstateCovenantRequestPacket(); + if(type == PacketType.EstateCovenantReply) return new EstateCovenantReplyPacket(); + if(type == PacketType.ForceObjectSelect) return new ForceObjectSelectPacket(); + if(type == PacketType.ParcelBuyPass) return new ParcelBuyPassPacket(); + if(type == PacketType.ParcelDeedToGroup) return new ParcelDeedToGroupPacket(); + if(type == PacketType.ParcelReclaim) return new ParcelReclaimPacket(); + if(type == PacketType.ParcelClaim) return new ParcelClaimPacket(); + if(type == PacketType.ParcelJoin) return new ParcelJoinPacket(); + if(type == PacketType.ParcelDivide) return new ParcelDividePacket(); + if(type == PacketType.ParcelRelease) return new ParcelReleasePacket(); + if(type == PacketType.ParcelBuy) return new ParcelBuyPacket(); + if(type == PacketType.ParcelGodForceOwner) return new ParcelGodForceOwnerPacket(); + if(type == PacketType.ParcelAccessListRequest) return new ParcelAccessListRequestPacket(); + if(type == PacketType.ParcelAccessListReply) return new ParcelAccessListReplyPacket(); + if(type == PacketType.ParcelAccessListUpdate) return new ParcelAccessListUpdatePacket(); + if(type == PacketType.ParcelDwellRequest) return new ParcelDwellRequestPacket(); + if(type == PacketType.ParcelDwellReply) return new ParcelDwellReplyPacket(); + if(type == PacketType.ParcelGodMarkAsContent) return new ParcelGodMarkAsContentPacket(); + if(type == PacketType.ViewerStartAuction) return new ViewerStartAuctionPacket(); + if(type == PacketType.UUIDNameRequest) return new UUIDNameRequestPacket(); + if(type == PacketType.UUIDNameReply) return new UUIDNameReplyPacket(); + if(type == PacketType.UUIDGroupNameRequest) return new UUIDGroupNameRequestPacket(); + if(type == PacketType.UUIDGroupNameReply) return new UUIDGroupNameReplyPacket(); + if(type == PacketType.ChildAgentDying) return new ChildAgentDyingPacket(); + if(type == PacketType.ChildAgentUnknown) return new ChildAgentUnknownPacket(); + if(type == PacketType.GetScriptRunning) return new GetScriptRunningPacket(); + if(type == PacketType.ScriptRunningReply) return new ScriptRunningReplyPacket(); + if(type == PacketType.SetScriptRunning) return new SetScriptRunningPacket(); + if(type == PacketType.ScriptReset) return new ScriptResetPacket(); + if(type == PacketType.ScriptSensorRequest) return new ScriptSensorRequestPacket(); + if(type == PacketType.ScriptSensorReply) return new ScriptSensorReplyPacket(); + if(type == PacketType.CompleteAgentMovement) return new CompleteAgentMovementPacket(); + if(type == PacketType.AgentMovementComplete) return new AgentMovementCompletePacket(); + if(type == PacketType.LogoutRequest) return new LogoutRequestPacket(); + if(type == PacketType.LogoutReply) return new LogoutReplyPacket(); + if(type == PacketType.ImprovedInstantMessage) return new ImprovedInstantMessagePacket(); + if(type == PacketType.RetrieveInstantMessages) return new RetrieveInstantMessagesPacket(); + if(type == PacketType.FindAgent) return new FindAgentPacket(); + if(type == PacketType.RequestGodlikePowers) return new RequestGodlikePowersPacket(); + if(type == PacketType.GrantGodlikePowers) return new GrantGodlikePowersPacket(); + if(type == PacketType.GodlikeMessage) return new GodlikeMessagePacket(); + if(type == PacketType.EstateOwnerMessage) return new EstateOwnerMessagePacket(); + if(type == PacketType.GenericMessage) return new GenericMessagePacket(); + if(type == PacketType.MuteListRequest) return new MuteListRequestPacket(); + if(type == PacketType.UpdateMuteListEntry) return new UpdateMuteListEntryPacket(); + if(type == PacketType.RemoveMuteListEntry) return new RemoveMuteListEntryPacket(); + if(type == PacketType.CopyInventoryFromNotecard) return new CopyInventoryFromNotecardPacket(); + if(type == PacketType.UpdateInventoryItem) return new UpdateInventoryItemPacket(); + if(type == PacketType.UpdateCreateInventoryItem) return new UpdateCreateInventoryItemPacket(); + if(type == PacketType.MoveInventoryItem) return new MoveInventoryItemPacket(); + if(type == PacketType.CopyInventoryItem) return new CopyInventoryItemPacket(); + if(type == PacketType.RemoveInventoryItem) return new RemoveInventoryItemPacket(); + if(type == PacketType.ChangeInventoryItemFlags) return new ChangeInventoryItemFlagsPacket(); + if(type == PacketType.SaveAssetIntoInventory) return new SaveAssetIntoInventoryPacket(); + if(type == PacketType.CreateInventoryFolder) return new CreateInventoryFolderPacket(); + if(type == PacketType.UpdateInventoryFolder) return new UpdateInventoryFolderPacket(); + if(type == PacketType.MoveInventoryFolder) return new MoveInventoryFolderPacket(); + if(type == PacketType.RemoveInventoryFolder) return new RemoveInventoryFolderPacket(); + if(type == PacketType.FetchInventoryDescendents) return new FetchInventoryDescendentsPacket(); + if(type == PacketType.InventoryDescendents) return new InventoryDescendentsPacket(); + if(type == PacketType.FetchInventory) return new FetchInventoryPacket(); + if(type == PacketType.FetchInventoryReply) return new FetchInventoryReplyPacket(); + if(type == PacketType.BulkUpdateInventory) return new BulkUpdateInventoryPacket(); + if(type == PacketType.RemoveInventoryObjects) return new RemoveInventoryObjectsPacket(); + if(type == PacketType.PurgeInventoryDescendents) return new PurgeInventoryDescendentsPacket(); + if(type == PacketType.UpdateTaskInventory) return new UpdateTaskInventoryPacket(); + if(type == PacketType.RemoveTaskInventory) return new RemoveTaskInventoryPacket(); + if(type == PacketType.MoveTaskInventory) return new MoveTaskInventoryPacket(); + if(type == PacketType.RequestTaskInventory) return new RequestTaskInventoryPacket(); + if(type == PacketType.ReplyTaskInventory) return new ReplyTaskInventoryPacket(); + if(type == PacketType.DeRezObject) return new DeRezObjectPacket(); + if(type == PacketType.DeRezAck) return new DeRezAckPacket(); + if(type == PacketType.RezObject) return new RezObjectPacket(); + if(type == PacketType.RezObjectFromNotecard) return new RezObjectFromNotecardPacket(); + if(type == PacketType.AcceptFriendship) return new AcceptFriendshipPacket(); + if(type == PacketType.DeclineFriendship) return new DeclineFriendshipPacket(); + if(type == PacketType.TerminateFriendship) return new TerminateFriendshipPacket(); + if(type == PacketType.OfferCallingCard) return new OfferCallingCardPacket(); + if(type == PacketType.AcceptCallingCard) return new AcceptCallingCardPacket(); + if(type == PacketType.DeclineCallingCard) return new DeclineCallingCardPacket(); + if(type == PacketType.RezScript) return new RezScriptPacket(); + if(type == PacketType.CreateInventoryItem) return new CreateInventoryItemPacket(); + if(type == PacketType.CreateLandmarkForEvent) return new CreateLandmarkForEventPacket(); + if(type == PacketType.RegionHandleRequest) return new RegionHandleRequestPacket(); + if(type == PacketType.RegionIDAndHandleReply) return new RegionIDAndHandleReplyPacket(); + if(type == PacketType.MoneyTransferRequest) return new MoneyTransferRequestPacket(); + if(type == PacketType.MoneyBalanceRequest) return new MoneyBalanceRequestPacket(); + if(type == PacketType.MoneyBalanceReply) return new MoneyBalanceReplyPacket(); + if(type == PacketType.RoutedMoneyBalanceReply) return new RoutedMoneyBalanceReplyPacket(); + if(type == PacketType.ActivateGestures) return new ActivateGesturesPacket(); + if(type == PacketType.DeactivateGestures) return new DeactivateGesturesPacket(); + if(type == PacketType.MuteListUpdate) return new MuteListUpdatePacket(); + if(type == PacketType.UseCachedMuteList) return new UseCachedMuteListPacket(); + if(type == PacketType.GrantUserRights) return new GrantUserRightsPacket(); + if(type == PacketType.ChangeUserRights) return new ChangeUserRightsPacket(); + if(type == PacketType.OnlineNotification) return new OnlineNotificationPacket(); + if(type == PacketType.OfflineNotification) return new OfflineNotificationPacket(); + if(type == PacketType.SetStartLocationRequest) return new SetStartLocationRequestPacket(); + if(type == PacketType.AssetUploadRequest) return new AssetUploadRequestPacket(); + if(type == PacketType.AssetUploadComplete) return new AssetUploadCompletePacket(); + if(type == PacketType.CreateGroupRequest) return new CreateGroupRequestPacket(); + if(type == PacketType.CreateGroupReply) return new CreateGroupReplyPacket(); + if(type == PacketType.UpdateGroupInfo) return new UpdateGroupInfoPacket(); + if(type == PacketType.GroupRoleChanges) return new GroupRoleChangesPacket(); + if(type == PacketType.JoinGroupRequest) return new JoinGroupRequestPacket(); + if(type == PacketType.JoinGroupReply) return new JoinGroupReplyPacket(); + if(type == PacketType.EjectGroupMemberRequest) return new EjectGroupMemberRequestPacket(); + if(type == PacketType.EjectGroupMemberReply) return new EjectGroupMemberReplyPacket(); + if(type == PacketType.LeaveGroupRequest) return new LeaveGroupRequestPacket(); + if(type == PacketType.LeaveGroupReply) return new LeaveGroupReplyPacket(); + if(type == PacketType.InviteGroupRequest) return new InviteGroupRequestPacket(); + if(type == PacketType.GroupProfileRequest) return new GroupProfileRequestPacket(); + if(type == PacketType.GroupProfileReply) return new GroupProfileReplyPacket(); + if(type == PacketType.GroupAccountSummaryRequest) return new GroupAccountSummaryRequestPacket(); + if(type == PacketType.GroupAccountSummaryReply) return new GroupAccountSummaryReplyPacket(); + if(type == PacketType.GroupAccountDetailsRequest) return new GroupAccountDetailsRequestPacket(); + if(type == PacketType.GroupAccountDetailsReply) return new GroupAccountDetailsReplyPacket(); + if(type == PacketType.GroupAccountTransactionsRequest) return new GroupAccountTransactionsRequestPacket(); + if(type == PacketType.GroupAccountTransactionsReply) return new GroupAccountTransactionsReplyPacket(); + if(type == PacketType.GroupActiveProposalsRequest) return new GroupActiveProposalsRequestPacket(); + if(type == PacketType.GroupActiveProposalItemReply) return new GroupActiveProposalItemReplyPacket(); + if(type == PacketType.GroupVoteHistoryRequest) return new GroupVoteHistoryRequestPacket(); + if(type == PacketType.GroupVoteHistoryItemReply) return new GroupVoteHistoryItemReplyPacket(); + if(type == PacketType.StartGroupProposal) return new StartGroupProposalPacket(); + if(type == PacketType.GroupProposalBallot) return new GroupProposalBallotPacket(); + if(type == PacketType.GroupMembersRequest) return new GroupMembersRequestPacket(); + if(type == PacketType.GroupMembersReply) return new GroupMembersReplyPacket(); + if(type == PacketType.ActivateGroup) return new ActivateGroupPacket(); + if(type == PacketType.SetGroupContribution) return new SetGroupContributionPacket(); + if(type == PacketType.SetGroupAcceptNotices) return new SetGroupAcceptNoticesPacket(); + if(type == PacketType.GroupRoleDataRequest) return new GroupRoleDataRequestPacket(); + if(type == PacketType.GroupRoleDataReply) return new GroupRoleDataReplyPacket(); + if(type == PacketType.GroupRoleMembersRequest) return new GroupRoleMembersRequestPacket(); + if(type == PacketType.GroupRoleMembersReply) return new GroupRoleMembersReplyPacket(); + if(type == PacketType.GroupTitlesRequest) return new GroupTitlesRequestPacket(); + if(type == PacketType.GroupTitlesReply) return new GroupTitlesReplyPacket(); + if(type == PacketType.GroupTitleUpdate) return new GroupTitleUpdatePacket(); + if(type == PacketType.GroupRoleUpdate) return new GroupRoleUpdatePacket(); + if(type == PacketType.LiveHelpGroupRequest) return new LiveHelpGroupRequestPacket(); + if(type == PacketType.LiveHelpGroupReply) return new LiveHelpGroupReplyPacket(); + if(type == PacketType.AgentWearablesRequest) return new AgentWearablesRequestPacket(); + if(type == PacketType.AgentWearablesUpdate) return new AgentWearablesUpdatePacket(); + if(type == PacketType.AgentIsNowWearing) return new AgentIsNowWearingPacket(); + if(type == PacketType.AgentCachedTexture) return new AgentCachedTexturePacket(); + if(type == PacketType.AgentCachedTextureResponse) return new AgentCachedTextureResponsePacket(); + if(type == PacketType.AgentDataUpdateRequest) return new AgentDataUpdateRequestPacket(); + if(type == PacketType.AgentDataUpdate) return new AgentDataUpdatePacket(); + if(type == PacketType.GroupDataUpdate) return new GroupDataUpdatePacket(); + if(type == PacketType.AgentGroupDataUpdate) return new AgentGroupDataUpdatePacket(); + if(type == PacketType.AgentDropGroup) return new AgentDropGroupPacket(); + if(type == PacketType.RezSingleAttachmentFromInv) return new RezSingleAttachmentFromInvPacket(); + if(type == PacketType.RezMultipleAttachmentsFromInv) return new RezMultipleAttachmentsFromInvPacket(); + if(type == PacketType.DetachAttachmentIntoInv) return new DetachAttachmentIntoInvPacket(); + if(type == PacketType.CreateNewOutfitAttachments) return new CreateNewOutfitAttachmentsPacket(); + if(type == PacketType.UserInfoRequest) return new UserInfoRequestPacket(); + if(type == PacketType.UserInfoReply) return new UserInfoReplyPacket(); + if(type == PacketType.UpdateUserInfo) return new UpdateUserInfoPacket(); + if(type == PacketType.InitiateDownload) return new InitiateDownloadPacket(); + if(type == PacketType.MapLayerRequest) return new MapLayerRequestPacket(); + if(type == PacketType.MapLayerReply) return new MapLayerReplyPacket(); + if(type == PacketType.MapBlockRequest) return new MapBlockRequestPacket(); + if(type == PacketType.MapNameRequest) return new MapNameRequestPacket(); + if(type == PacketType.MapBlockReply) return new MapBlockReplyPacket(); + if(type == PacketType.MapItemRequest) return new MapItemRequestPacket(); + if(type == PacketType.MapItemReply) return new MapItemReplyPacket(); + if(type == PacketType.SendPostcard) return new SendPostcardPacket(); + if(type == PacketType.ParcelMediaCommandMessage) return new ParcelMediaCommandMessagePacket(); + if(type == PacketType.ParcelMediaUpdate) return new ParcelMediaUpdatePacket(); + if(type == PacketType.LandStatRequest) return new LandStatRequestPacket(); + if(type == PacketType.LandStatReply) return new LandStatReplyPacket(); + if(type == PacketType.Error) return new ErrorPacket(); + if(type == PacketType.ObjectIncludeInSearch) return new ObjectIncludeInSearchPacket(); + if(type == PacketType.RezRestoreToWorld) return new RezRestoreToWorldPacket(); + if(type == PacketType.LinkInventoryItem) return new LinkInventoryItemPacket(); + if(type == PacketType.RetrieveIMsExtended) return new RetrieveIMsExtendedPacket(); + if(type == PacketType.JoinGroupRequestExtended) return new JoinGroupRequestExtendedPacket(); + if(type == PacketType.CreateGroupRequestExtended) return new CreateGroupRequestExtendedPacket(); + if(type == PacketType.PacketAck) return new PacketAckPacket(); + if(type == PacketType.OpenCircuit) return new OpenCircuitPacket(); + if(type == PacketType.CloseCircuit) return new CloseCircuitPacket(); + return null; + + } + + public static Packet BuildPacket(byte[] packetBuffer, ref int packetEnd, byte[] zeroBuffer) + { + byte[] bytes; + int i = 0; + Header header = Header.BuildHeader(packetBuffer, ref i, ref packetEnd); + if (header.Zerocoded) + { + packetEnd = Helpers.ZeroDecode(packetBuffer, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + else + { + bytes = packetBuffer; + } + Array.Clear(bytes, packetEnd + 1, bytes.Length - packetEnd - 1); + + switch (header.Frequency) + { + case PacketFrequency.Low: + switch (header.ID) + { + case 1: return new TestMessagePacket(header, bytes, ref i); + case 3: return new UseCircuitCodePacket(header, bytes, ref i); + case 10: return new TelehubInfoPacket(header, bytes, ref i); + case 24: return new EconomyDataRequestPacket(header, bytes, ref i); + case 25: return new EconomyDataPacket(header, bytes, ref i); + case 26: return new AvatarPickerRequestPacket(header, bytes, ref i); + case 28: return new AvatarPickerReplyPacket(header, bytes, ref i); + case 29: return new PlacesQueryPacket(header, bytes, ref i); + case 30: return new PlacesReplyPacket(header, bytes, ref i); + case 31: return new DirFindQueryPacket(header, bytes, ref i); + case 33: return new DirPlacesQueryPacket(header, bytes, ref i); + case 35: return new DirPlacesReplyPacket(header, bytes, ref i); + case 36: return new DirPeopleReplyPacket(header, bytes, ref i); + case 37: return new DirEventsReplyPacket(header, bytes, ref i); + case 38: return new DirGroupsReplyPacket(header, bytes, ref i); + case 39: return new DirClassifiedQueryPacket(header, bytes, ref i); + case 41: return new DirClassifiedReplyPacket(header, bytes, ref i); + case 42: return new AvatarClassifiedReplyPacket(header, bytes, ref i); + case 43: return new ClassifiedInfoRequestPacket(header, bytes, ref i); + case 44: return new ClassifiedInfoReplyPacket(header, bytes, ref i); + case 45: return new ClassifiedInfoUpdatePacket(header, bytes, ref i); + case 46: return new ClassifiedDeletePacket(header, bytes, ref i); + case 47: return new ClassifiedGodDeletePacket(header, bytes, ref i); + case 48: return new DirLandQueryPacket(header, bytes, ref i); + case 50: return new DirLandReplyPacket(header, bytes, ref i); + case 51: return new DirPopularQueryPacket(header, bytes, ref i); + case 53: return new DirPopularReplyPacket(header, bytes, ref i); + case 54: return new ParcelInfoRequestPacket(header, bytes, ref i); + case 55: return new ParcelInfoReplyPacket(header, bytes, ref i); + case 56: return new ParcelObjectOwnersRequestPacket(header, bytes, ref i); + case 57: return new ParcelObjectOwnersReplyPacket(header, bytes, ref i); + case 58: return new GroupNoticesListRequestPacket(header, bytes, ref i); + case 59: return new GroupNoticesListReplyPacket(header, bytes, ref i); + case 60: return new GroupNoticeRequestPacket(header, bytes, ref i); + case 62: return new TeleportRequestPacket(header, bytes, ref i); + case 63: return new TeleportLocationRequestPacket(header, bytes, ref i); + case 64: return new TeleportLocalPacket(header, bytes, ref i); + case 65: return new TeleportLandmarkRequestPacket(header, bytes, ref i); + case 66: return new TeleportProgressPacket(header, bytes, ref i); + case 69: return new TeleportFinishPacket(header, bytes, ref i); + case 70: return new StartLurePacket(header, bytes, ref i); + case 71: return new TeleportLureRequestPacket(header, bytes, ref i); + case 72: return new TeleportCancelPacket(header, bytes, ref i); + case 73: return new TeleportStartPacket(header, bytes, ref i); + case 74: return new TeleportFailedPacket(header, bytes, ref i); + case 75: return new UndoPacket(header, bytes, ref i); + case 76: return new RedoPacket(header, bytes, ref i); + case 77: return new UndoLandPacket(header, bytes, ref i); + case 78: return new AgentPausePacket(header, bytes, ref i); + case 79: return new AgentResumePacket(header, bytes, ref i); + case 80: return new ChatFromViewerPacket(header, bytes, ref i); + case 81: return new AgentThrottlePacket(header, bytes, ref i); + case 82: return new AgentFOVPacket(header, bytes, ref i); + case 83: return new AgentHeightWidthPacket(header, bytes, ref i); + case 84: return new AgentSetAppearancePacket(header, bytes, ref i); + case 85: return new AgentQuitCopyPacket(header, bytes, ref i); + case 86: return new ImageNotInDatabasePacket(header, bytes, ref i); + case 87: return new RebakeAvatarTexturesPacket(header, bytes, ref i); + case 88: return new SetAlwaysRunPacket(header, bytes, ref i); + case 89: return new ObjectDeletePacket(header, bytes, ref i); + case 90: return new ObjectDuplicatePacket(header, bytes, ref i); + case 91: return new ObjectDuplicateOnRayPacket(header, bytes, ref i); + case 92: return new ObjectScalePacket(header, bytes, ref i); + case 93: return new ObjectRotationPacket(header, bytes, ref i); + case 94: return new ObjectFlagUpdatePacket(header, bytes, ref i); + case 95: return new ObjectClickActionPacket(header, bytes, ref i); + case 96: return new ObjectImagePacket(header, bytes, ref i); + case 97: return new ObjectMaterialPacket(header, bytes, ref i); + case 98: return new ObjectShapePacket(header, bytes, ref i); + case 99: return new ObjectExtraParamsPacket(header, bytes, ref i); + case 100: return new ObjectOwnerPacket(header, bytes, ref i); + case 101: return new ObjectGroupPacket(header, bytes, ref i); + case 102: return new ObjectBuyPacket(header, bytes, ref i); + case 103: return new BuyObjectInventoryPacket(header, bytes, ref i); + case 104: return new DerezContainerPacket(header, bytes, ref i); + case 105: return new ObjectPermissionsPacket(header, bytes, ref i); + case 106: return new ObjectSaleInfoPacket(header, bytes, ref i); + case 107: return new ObjectNamePacket(header, bytes, ref i); + case 108: return new ObjectDescriptionPacket(header, bytes, ref i); + case 109: return new ObjectCategoryPacket(header, bytes, ref i); + case 110: return new ObjectSelectPacket(header, bytes, ref i); + case 111: return new ObjectDeselectPacket(header, bytes, ref i); + case 112: return new ObjectAttachPacket(header, bytes, ref i); + case 113: return new ObjectDetachPacket(header, bytes, ref i); + case 114: return new ObjectDropPacket(header, bytes, ref i); + case 115: return new ObjectLinkPacket(header, bytes, ref i); + case 116: return new ObjectDelinkPacket(header, bytes, ref i); + case 117: return new ObjectGrabPacket(header, bytes, ref i); + case 118: return new ObjectGrabUpdatePacket(header, bytes, ref i); + case 119: return new ObjectDeGrabPacket(header, bytes, ref i); + case 120: return new ObjectSpinStartPacket(header, bytes, ref i); + case 121: return new ObjectSpinUpdatePacket(header, bytes, ref i); + case 122: return new ObjectSpinStopPacket(header, bytes, ref i); + case 123: return new ObjectExportSelectedPacket(header, bytes, ref i); + case 124: return new ModifyLandPacket(header, bytes, ref i); + case 125: return new VelocityInterpolateOnPacket(header, bytes, ref i); + case 126: return new VelocityInterpolateOffPacket(header, bytes, ref i); + case 127: return new StateSavePacket(header, bytes, ref i); + case 128: return new ReportAutosaveCrashPacket(header, bytes, ref i); + case 129: return new SimWideDeletesPacket(header, bytes, ref i); + case 130: return new TrackAgentPacket(header, bytes, ref i); + case 131: return new ViewerStatsPacket(header, bytes, ref i); + case 132: return new ScriptAnswerYesPacket(header, bytes, ref i); + case 133: return new UserReportPacket(header, bytes, ref i); + case 134: return new AlertMessagePacket(header, bytes, ref i); + case 135: return new AgentAlertMessagePacket(header, bytes, ref i); + case 136: return new MeanCollisionAlertPacket(header, bytes, ref i); + case 137: return new ViewerFrozenMessagePacket(header, bytes, ref i); + case 138: return new HealthMessagePacket(header, bytes, ref i); + case 139: return new ChatFromSimulatorPacket(header, bytes, ref i); + case 140: return new SimStatsPacket(header, bytes, ref i); + case 141: return new RequestRegionInfoPacket(header, bytes, ref i); + case 142: return new RegionInfoPacket(header, bytes, ref i); + case 143: return new GodUpdateRegionInfoPacket(header, bytes, ref i); + case 148: return new RegionHandshakePacket(header, bytes, ref i); + case 149: return new RegionHandshakeReplyPacket(header, bytes, ref i); + case 150: return new SimulatorViewerTimeMessagePacket(header, bytes, ref i); + case 151: return new EnableSimulatorPacket(header, bytes, ref i); + case 152: return new DisableSimulatorPacket(header, bytes, ref i); + case 153: return new TransferRequestPacket(header, bytes, ref i); + case 154: return new TransferInfoPacket(header, bytes, ref i); + case 155: return new TransferAbortPacket(header, bytes, ref i); + case 156: return new RequestXferPacket(header, bytes, ref i); + case 157: return new AbortXferPacket(header, bytes, ref i); + case 158: return new AvatarAppearancePacket(header, bytes, ref i); + case 159: return new SetFollowCamPropertiesPacket(header, bytes, ref i); + case 160: return new ClearFollowCamPropertiesPacket(header, bytes, ref i); + case 161: return new RequestPayPricePacket(header, bytes, ref i); + case 162: return new PayPriceReplyPacket(header, bytes, ref i); + case 163: return new KickUserPacket(header, bytes, ref i); + case 165: return new GodKickUserPacket(header, bytes, ref i); + case 167: return new EjectUserPacket(header, bytes, ref i); + case 168: return new FreezeUserPacket(header, bytes, ref i); + case 169: return new AvatarPropertiesRequestPacket(header, bytes, ref i); + case 171: return new AvatarPropertiesReplyPacket(header, bytes, ref i); + case 172: return new AvatarInterestsReplyPacket(header, bytes, ref i); + case 173: return new AvatarGroupsReplyPacket(header, bytes, ref i); + case 174: return new AvatarPropertiesUpdatePacket(header, bytes, ref i); + case 175: return new AvatarInterestsUpdatePacket(header, bytes, ref i); + case 176: return new AvatarNotesReplyPacket(header, bytes, ref i); + case 177: return new AvatarNotesUpdatePacket(header, bytes, ref i); + case 178: return new AvatarPicksReplyPacket(header, bytes, ref i); + case 179: return new EventInfoRequestPacket(header, bytes, ref i); + case 180: return new EventInfoReplyPacket(header, bytes, ref i); + case 181: return new EventNotificationAddRequestPacket(header, bytes, ref i); + case 182: return new EventNotificationRemoveRequestPacket(header, bytes, ref i); + case 183: return new EventGodDeletePacket(header, bytes, ref i); + case 184: return new PickInfoReplyPacket(header, bytes, ref i); + case 185: return new PickInfoUpdatePacket(header, bytes, ref i); + case 186: return new PickDeletePacket(header, bytes, ref i); + case 187: return new PickGodDeletePacket(header, bytes, ref i); + case 188: return new ScriptQuestionPacket(header, bytes, ref i); + case 189: return new ScriptControlChangePacket(header, bytes, ref i); + case 190: return new ScriptDialogPacket(header, bytes, ref i); + case 191: return new ScriptDialogReplyPacket(header, bytes, ref i); + case 192: return new ForceScriptControlReleasePacket(header, bytes, ref i); + case 193: return new RevokePermissionsPacket(header, bytes, ref i); + case 194: return new LoadURLPacket(header, bytes, ref i); + case 195: return new ScriptTeleportRequestPacket(header, bytes, ref i); + case 196: return new ParcelOverlayPacket(header, bytes, ref i); + case 197: return new ParcelPropertiesRequestByIDPacket(header, bytes, ref i); + case 198: return new ParcelPropertiesUpdatePacket(header, bytes, ref i); + case 199: return new ParcelReturnObjectsPacket(header, bytes, ref i); + case 200: return new ParcelSetOtherCleanTimePacket(header, bytes, ref i); + case 201: return new ParcelDisableObjectsPacket(header, bytes, ref i); + case 202: return new ParcelSelectObjectsPacket(header, bytes, ref i); + case 203: return new EstateCovenantRequestPacket(header, bytes, ref i); + case 204: return new EstateCovenantReplyPacket(header, bytes, ref i); + case 205: return new ForceObjectSelectPacket(header, bytes, ref i); + case 206: return new ParcelBuyPassPacket(header, bytes, ref i); + case 207: return new ParcelDeedToGroupPacket(header, bytes, ref i); + case 208: return new ParcelReclaimPacket(header, bytes, ref i); + case 209: return new ParcelClaimPacket(header, bytes, ref i); + case 210: return new ParcelJoinPacket(header, bytes, ref i); + case 211: return new ParcelDividePacket(header, bytes, ref i); + case 212: return new ParcelReleasePacket(header, bytes, ref i); + case 213: return new ParcelBuyPacket(header, bytes, ref i); + case 214: return new ParcelGodForceOwnerPacket(header, bytes, ref i); + case 215: return new ParcelAccessListRequestPacket(header, bytes, ref i); + case 216: return new ParcelAccessListReplyPacket(header, bytes, ref i); + case 217: return new ParcelAccessListUpdatePacket(header, bytes, ref i); + case 218: return new ParcelDwellRequestPacket(header, bytes, ref i); + case 219: return new ParcelDwellReplyPacket(header, bytes, ref i); + case 227: return new ParcelGodMarkAsContentPacket(header, bytes, ref i); + case 228: return new ViewerStartAuctionPacket(header, bytes, ref i); + case 235: return new UUIDNameRequestPacket(header, bytes, ref i); + case 236: return new UUIDNameReplyPacket(header, bytes, ref i); + case 237: return new UUIDGroupNameRequestPacket(header, bytes, ref i); + case 238: return new UUIDGroupNameReplyPacket(header, bytes, ref i); + case 240: return new ChildAgentDyingPacket(header, bytes, ref i); + case 241: return new ChildAgentUnknownPacket(header, bytes, ref i); + case 243: return new GetScriptRunningPacket(header, bytes, ref i); + case 244: return new ScriptRunningReplyPacket(header, bytes, ref i); + case 245: return new SetScriptRunningPacket(header, bytes, ref i); + case 246: return new ScriptResetPacket(header, bytes, ref i); + case 247: return new ScriptSensorRequestPacket(header, bytes, ref i); + case 248: return new ScriptSensorReplyPacket(header, bytes, ref i); + case 249: return new CompleteAgentMovementPacket(header, bytes, ref i); + case 250: return new AgentMovementCompletePacket(header, bytes, ref i); + case 252: return new LogoutRequestPacket(header, bytes, ref i); + case 253: return new LogoutReplyPacket(header, bytes, ref i); + case 254: return new ImprovedInstantMessagePacket(header, bytes, ref i); + case 255: return new RetrieveInstantMessagesPacket(header, bytes, ref i); + case 256: return new FindAgentPacket(header, bytes, ref i); + case 257: return new RequestGodlikePowersPacket(header, bytes, ref i); + case 258: return new GrantGodlikePowersPacket(header, bytes, ref i); + case 259: return new GodlikeMessagePacket(header, bytes, ref i); + case 260: return new EstateOwnerMessagePacket(header, bytes, ref i); + case 261: return new GenericMessagePacket(header, bytes, ref i); + case 262: return new MuteListRequestPacket(header, bytes, ref i); + case 263: return new UpdateMuteListEntryPacket(header, bytes, ref i); + case 264: return new RemoveMuteListEntryPacket(header, bytes, ref i); + case 265: return new CopyInventoryFromNotecardPacket(header, bytes, ref i); + case 266: return new UpdateInventoryItemPacket(header, bytes, ref i); + case 267: return new UpdateCreateInventoryItemPacket(header, bytes, ref i); + case 268: return new MoveInventoryItemPacket(header, bytes, ref i); + case 269: return new CopyInventoryItemPacket(header, bytes, ref i); + case 270: return new RemoveInventoryItemPacket(header, bytes, ref i); + case 271: return new ChangeInventoryItemFlagsPacket(header, bytes, ref i); + case 272: return new SaveAssetIntoInventoryPacket(header, bytes, ref i); + case 273: return new CreateInventoryFolderPacket(header, bytes, ref i); + case 274: return new UpdateInventoryFolderPacket(header, bytes, ref i); + case 275: return new MoveInventoryFolderPacket(header, bytes, ref i); + case 276: return new RemoveInventoryFolderPacket(header, bytes, ref i); + case 277: return new FetchInventoryDescendentsPacket(header, bytes, ref i); + case 278: return new InventoryDescendentsPacket(header, bytes, ref i); + case 279: return new FetchInventoryPacket(header, bytes, ref i); + case 280: return new FetchInventoryReplyPacket(header, bytes, ref i); + case 281: return new BulkUpdateInventoryPacket(header, bytes, ref i); + case 284: return new RemoveInventoryObjectsPacket(header, bytes, ref i); + case 285: return new PurgeInventoryDescendentsPacket(header, bytes, ref i); + case 286: return new UpdateTaskInventoryPacket(header, bytes, ref i); + case 287: return new RemoveTaskInventoryPacket(header, bytes, ref i); + case 288: return new MoveTaskInventoryPacket(header, bytes, ref i); + case 289: return new RequestTaskInventoryPacket(header, bytes, ref i); + case 290: return new ReplyTaskInventoryPacket(header, bytes, ref i); + case 291: return new DeRezObjectPacket(header, bytes, ref i); + case 292: return new DeRezAckPacket(header, bytes, ref i); + case 293: return new RezObjectPacket(header, bytes, ref i); + case 294: return new RezObjectFromNotecardPacket(header, bytes, ref i); + case 297: return new AcceptFriendshipPacket(header, bytes, ref i); + case 298: return new DeclineFriendshipPacket(header, bytes, ref i); + case 300: return new TerminateFriendshipPacket(header, bytes, ref i); + case 301: return new OfferCallingCardPacket(header, bytes, ref i); + case 302: return new AcceptCallingCardPacket(header, bytes, ref i); + case 303: return new DeclineCallingCardPacket(header, bytes, ref i); + case 304: return new RezScriptPacket(header, bytes, ref i); + case 305: return new CreateInventoryItemPacket(header, bytes, ref i); + case 306: return new CreateLandmarkForEventPacket(header, bytes, ref i); + case 309: return new RegionHandleRequestPacket(header, bytes, ref i); + case 310: return new RegionIDAndHandleReplyPacket(header, bytes, ref i); + case 311: return new MoneyTransferRequestPacket(header, bytes, ref i); + case 313: return new MoneyBalanceRequestPacket(header, bytes, ref i); + case 314: return new MoneyBalanceReplyPacket(header, bytes, ref i); + case 315: return new RoutedMoneyBalanceReplyPacket(header, bytes, ref i); + case 316: return new ActivateGesturesPacket(header, bytes, ref i); + case 317: return new DeactivateGesturesPacket(header, bytes, ref i); + case 318: return new MuteListUpdatePacket(header, bytes, ref i); + case 319: return new UseCachedMuteListPacket(header, bytes, ref i); + case 320: return new GrantUserRightsPacket(header, bytes, ref i); + case 321: return new ChangeUserRightsPacket(header, bytes, ref i); + case 322: return new OnlineNotificationPacket(header, bytes, ref i); + case 323: return new OfflineNotificationPacket(header, bytes, ref i); + case 324: return new SetStartLocationRequestPacket(header, bytes, ref i); + case 333: return new AssetUploadRequestPacket(header, bytes, ref i); + case 334: return new AssetUploadCompletePacket(header, bytes, ref i); + case 339: return new CreateGroupRequestPacket(header, bytes, ref i); + case 340: return new CreateGroupReplyPacket(header, bytes, ref i); + case 341: return new UpdateGroupInfoPacket(header, bytes, ref i); + case 342: return new GroupRoleChangesPacket(header, bytes, ref i); + case 343: return new JoinGroupRequestPacket(header, bytes, ref i); + case 344: return new JoinGroupReplyPacket(header, bytes, ref i); + case 345: return new EjectGroupMemberRequestPacket(header, bytes, ref i); + case 346: return new EjectGroupMemberReplyPacket(header, bytes, ref i); + case 347: return new LeaveGroupRequestPacket(header, bytes, ref i); + case 348: return new LeaveGroupReplyPacket(header, bytes, ref i); + case 349: return new InviteGroupRequestPacket(header, bytes, ref i); + case 351: return new GroupProfileRequestPacket(header, bytes, ref i); + case 352: return new GroupProfileReplyPacket(header, bytes, ref i); + case 353: return new GroupAccountSummaryRequestPacket(header, bytes, ref i); + case 354: return new GroupAccountSummaryReplyPacket(header, bytes, ref i); + case 355: return new GroupAccountDetailsRequestPacket(header, bytes, ref i); + case 356: return new GroupAccountDetailsReplyPacket(header, bytes, ref i); + case 357: return new GroupAccountTransactionsRequestPacket(header, bytes, ref i); + case 358: return new GroupAccountTransactionsReplyPacket(header, bytes, ref i); + case 359: return new GroupActiveProposalsRequestPacket(header, bytes, ref i); + case 360: return new GroupActiveProposalItemReplyPacket(header, bytes, ref i); + case 361: return new GroupVoteHistoryRequestPacket(header, bytes, ref i); + case 362: return new GroupVoteHistoryItemReplyPacket(header, bytes, ref i); + case 363: return new StartGroupProposalPacket(header, bytes, ref i); + case 364: return new GroupProposalBallotPacket(header, bytes, ref i); + case 366: return new GroupMembersRequestPacket(header, bytes, ref i); + case 367: return new GroupMembersReplyPacket(header, bytes, ref i); + case 368: return new ActivateGroupPacket(header, bytes, ref i); + case 369: return new SetGroupContributionPacket(header, bytes, ref i); + case 370: return new SetGroupAcceptNoticesPacket(header, bytes, ref i); + case 371: return new GroupRoleDataRequestPacket(header, bytes, ref i); + case 372: return new GroupRoleDataReplyPacket(header, bytes, ref i); + case 373: return new GroupRoleMembersRequestPacket(header, bytes, ref i); + case 374: return new GroupRoleMembersReplyPacket(header, bytes, ref i); + case 375: return new GroupTitlesRequestPacket(header, bytes, ref i); + case 376: return new GroupTitlesReplyPacket(header, bytes, ref i); + case 377: return new GroupTitleUpdatePacket(header, bytes, ref i); + case 378: return new GroupRoleUpdatePacket(header, bytes, ref i); + case 379: return new LiveHelpGroupRequestPacket(header, bytes, ref i); + case 380: return new LiveHelpGroupReplyPacket(header, bytes, ref i); + case 381: return new AgentWearablesRequestPacket(header, bytes, ref i); + case 382: return new AgentWearablesUpdatePacket(header, bytes, ref i); + case 383: return new AgentIsNowWearingPacket(header, bytes, ref i); + case 384: return new AgentCachedTexturePacket(header, bytes, ref i); + case 385: return new AgentCachedTextureResponsePacket(header, bytes, ref i); + case 386: return new AgentDataUpdateRequestPacket(header, bytes, ref i); + case 387: return new AgentDataUpdatePacket(header, bytes, ref i); + case 388: return new GroupDataUpdatePacket(header, bytes, ref i); + case 389: return new AgentGroupDataUpdatePacket(header, bytes, ref i); + case 390: return new AgentDropGroupPacket(header, bytes, ref i); + case 395: return new RezSingleAttachmentFromInvPacket(header, bytes, ref i); + case 396: return new RezMultipleAttachmentsFromInvPacket(header, bytes, ref i); + case 397: return new DetachAttachmentIntoInvPacket(header, bytes, ref i); + case 398: return new CreateNewOutfitAttachmentsPacket(header, bytes, ref i); + case 399: return new UserInfoRequestPacket(header, bytes, ref i); + case 400: return new UserInfoReplyPacket(header, bytes, ref i); + case 401: return new UpdateUserInfoPacket(header, bytes, ref i); + case 403: return new InitiateDownloadPacket(header, bytes, ref i); + case 405: return new MapLayerRequestPacket(header, bytes, ref i); + case 406: return new MapLayerReplyPacket(header, bytes, ref i); + case 407: return new MapBlockRequestPacket(header, bytes, ref i); + case 408: return new MapNameRequestPacket(header, bytes, ref i); + case 409: return new MapBlockReplyPacket(header, bytes, ref i); + case 410: return new MapItemRequestPacket(header, bytes, ref i); + case 411: return new MapItemReplyPacket(header, bytes, ref i); + case 412: return new SendPostcardPacket(header, bytes, ref i); + case 419: return new ParcelMediaCommandMessagePacket(header, bytes, ref i); + case 420: return new ParcelMediaUpdatePacket(header, bytes, ref i); + case 421: return new LandStatRequestPacket(header, bytes, ref i); + case 422: return new LandStatReplyPacket(header, bytes, ref i); + case 423: return new ErrorPacket(header, bytes, ref i); + case 424: return new ObjectIncludeInSearchPacket(header, bytes, ref i); + case 425: return new RezRestoreToWorldPacket(header, bytes, ref i); + case 426: return new LinkInventoryItemPacket(header, bytes, ref i); + case 427: return new RetrieveIMsExtendedPacket(header, bytes, ref i); + case 428: return new JoinGroupRequestExtendedPacket(header, bytes, ref i); + case 429: return new CreateGroupRequestExtendedPacket(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); + + } + break; + case PacketFrequency.Medium: + switch (header.ID) + { + case 1: return new ObjectAddPacket(header, bytes, ref i); + case 2: return new MultipleObjectUpdatePacket(header, bytes, ref i); + case 3: return new RequestMultipleObjectsPacket(header, bytes, ref i); + case 4: return new ObjectPositionPacket(header, bytes, ref i); + case 5: return new RequestObjectPropertiesFamilyPacket(header, bytes, ref i); + case 6: return new CoarseLocationUpdatePacket(header, bytes, ref i); + case 7: return new CrossedRegionPacket(header, bytes, ref i); + case 8: return new ConfirmEnableSimulatorPacket(header, bytes, ref i); + case 9: return new ObjectPropertiesPacket(header, bytes, ref i); + case 10: return new ObjectPropertiesFamilyPacket(header, bytes, ref i); + case 11: return new ParcelPropertiesRequestPacket(header, bytes, ref i); + case 13: return new AttachedSoundPacket(header, bytes, ref i); + case 14: return new AttachedSoundGainChangePacket(header, bytes, ref i); + case 15: return new PreloadSoundPacket(header, bytes, ref i); + case 17: return new ViewerEffectPacket(header, bytes, ref i); + + } + break; + case PacketFrequency.High: + switch (header.ID) + { + case 1: return new StartPingCheckPacket(header, bytes, ref i); + case 2: return new CompletePingCheckPacket(header, bytes, ref i); + case 4: return new AgentUpdatePacket(header, bytes, ref i); + case 5: return new AgentAnimationPacket(header, bytes, ref i); + case 6: return new AgentRequestSitPacket(header, bytes, ref i); + case 7: return new AgentSitPacket(header, bytes, ref i); + case 8: return new RequestImagePacket(header, bytes, ref i); + case 9: return new ImageDataPacket(header, bytes, ref i); + case 10: return new ImagePacketPacket(header, bytes, ref i); + case 11: return new LayerDataPacket(header, bytes, ref i); + case 12: return new ObjectUpdatePacket(header, bytes, ref i); + case 13: return new ObjectUpdateCompressedPacket(header, bytes, ref i); + case 14: return new ObjectUpdateCachedPacket(header, bytes, ref i); + case 15: return new ImprovedTerseObjectUpdatePacket(header, bytes, ref i); + case 16: return new KillObjectPacket(header, bytes, ref i); + case 17: return new TransferPacketPacket(header, bytes, ref i); + case 18: return new SendXferPacketPacket(header, bytes, ref i); + case 19: return new ConfirmXferPacketPacket(header, bytes, ref i); + case 20: return new AvatarAnimationPacket(header, bytes, ref i); + case 21: return new AvatarSitResponsePacket(header, bytes, ref i); + case 22: return new CameraConstraintPacket(header, bytes, ref i); + case 23: return new ParcelPropertiesPacket(header, bytes, ref i); + case 25: return new ChildAgentUpdatePacket(header, bytes, ref i); + case 26: return new ChildAgentAlivePacket(header, bytes, ref i); + case 27: return new ChildAgentPositionUpdatePacket(header, bytes, ref i); + case 29: return new SoundTriggerPacket(header, bytes, ref i); + case 30: return new ObjectAnimationPacket(header, bytes, ref i); + + } + break; + } + + throw new MalformedDataException("Unknown packet ID " + header.Frequency + " " + header.ID); + } + } + /// + public sealed class TestMessagePacket : Packet + { + /// + public sealed class TestBlock1Block : PacketBlock + { + public uint Test1; + + public override int Length + { + get + { + return 4; + } + } + + public TestBlock1Block() { } + public TestBlock1Block(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + Test1 = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UIntToBytes(Test1, bytes, i); i += 4; + } + + } + + /// + public sealed class NeighborBlockBlock : PacketBlock + { + public uint Test0; + public uint Test1; + public uint Test2; + + public override int Length + { + get + { + return 12; + } + } + + public NeighborBlockBlock() { } + public NeighborBlockBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(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(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UIntToBytes(Test0, bytes, i); i += 4; + Utils.UIntToBytes(Test1, bytes, i); i += 4; + Utils.UIntToBytes(Test2, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 10; + length += TestBlock1.Length; + for (int j = 0; j < 4; j++) + length += NeighborBlock[j].Length; + return length; + } + } + public TestBlock1Block TestBlock1; + public NeighborBlockBlock[] NeighborBlock; + + public TestMessagePacket() + { + HasVariableBlocks = false; + Type = PacketType.TestMessage; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 1; + Header.Reliable = true; + Header.Zerocoded = true; + TestBlock1 = new TestBlock1Block(); + NeighborBlock = new NeighborBlockBlock[4]; + } + + public TestMessagePacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + TestBlock1.FromBytes(bytes, ref i); + if(NeighborBlock == null || NeighborBlock.Length != 4) { + NeighborBlock = new NeighborBlockBlock[4]; + for(int j = 0; j < 4; j++) + { NeighborBlock[j] = new NeighborBlockBlock(); } + } + for (int j = 0; j < 4; j++) + { NeighborBlock[j].FromBytes(bytes, ref i); } + } + + public TestMessagePacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + TestBlock1.FromBytes(bytes, ref i); + if(NeighborBlock == null || NeighborBlock.Length != 4) { + NeighborBlock = new NeighborBlockBlock[4]; + for(int j = 0; j < 4; j++) + { NeighborBlock[j] = new NeighborBlockBlock(); } + } + for (int j = 0; j < 4; j++) + { NeighborBlock[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += TestBlock1.Length; + for (int j = 0; j < 4; j++) { length += NeighborBlock[j].Length; } + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class UseCircuitCodePacket : Packet + { + /// + public sealed class CircuitCodeBlock : PacketBlock + { + public uint Code; + public UUID SessionID; + public UUID ID; + + public override int Length + { + get + { + return 36; + } + } + + public CircuitCodeBlock() { } + public CircuitCodeBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + Code = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + SessionID.FromBytes(bytes, i); i += 16; + ID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UIntToBytes(Code, bytes, i); i += 4; + SessionID.ToBytes(bytes, i); i += 16; + ID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 10; + length += CircuitCode.Length; + return length; + } + } + public CircuitCodeBlock CircuitCode; + + public UseCircuitCodePacket() + { + HasVariableBlocks = false; + Type = PacketType.UseCircuitCode; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 3; + Header.Reliable = true; + CircuitCode = new CircuitCodeBlock(); + } + + public UseCircuitCodePacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + CircuitCode.FromBytes(bytes, ref i); + } + + public UseCircuitCodePacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + CircuitCode.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += CircuitCode.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class TelehubInfoPacket : Packet + { + /// + public sealed class TelehubBlockBlock : PacketBlock + { + public UUID ObjectID; + public byte[] ObjectName; + public Vector3 TelehubPos; + public Quaternion TelehubRot; + + public override int Length + { + get + { + int length = 41; + if (ObjectName != null) { length += ObjectName.Length; } + return length; + } + } + + public TelehubBlockBlock() { } + public TelehubBlockBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + ObjectID.FromBytes(bytes, i); i += 16; + length = bytes[i++]; + ObjectName = new byte[length]; + Buffer.BlockCopy(bytes, i, ObjectName, 0, length); i += length; + TelehubPos.FromBytes(bytes, i); i += 12; + TelehubRot.FromBytes(bytes, i, true); i += 12; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + ObjectID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)ObjectName.Length; + Buffer.BlockCopy(ObjectName, 0, bytes, i, ObjectName.Length); i += ObjectName.Length; + TelehubPos.ToBytes(bytes, i); i += 12; + TelehubRot.ToBytes(bytes, i); i += 12; + } + + } + + /// + public sealed class SpawnPointBlockBlock : PacketBlock + { + public Vector3 SpawnPointPos; + + public override int Length + { + get + { + return 12; + } + } + + public SpawnPointBlockBlock() { } + public SpawnPointBlockBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + SpawnPointPos.FromBytes(bytes, i); i += 12; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + SpawnPointPos.ToBytes(bytes, i); i += 12; + } + + } + + public override int Length + { + get + { + int length = 11; + length += TelehubBlock.Length; + for (int j = 0; j < SpawnPointBlock.Length; j++) + length += SpawnPointBlock[j].Length; + return length; + } + } + public TelehubBlockBlock TelehubBlock; + public SpawnPointBlockBlock[] SpawnPointBlock; + + public TelehubInfoPacket() + { + HasVariableBlocks = true; + Type = PacketType.TelehubInfo; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 10; + Header.Reliable = true; + TelehubBlock = new TelehubBlockBlock(); + SpawnPointBlock = null; + } + + public TelehubInfoPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + TelehubBlock.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(SpawnPointBlock == null || SpawnPointBlock.Length != -1) { + SpawnPointBlock = new SpawnPointBlockBlock[count]; + for(int j = 0; j < count; j++) + { SpawnPointBlock[j] = new SpawnPointBlockBlock(); } + } + for (int j = 0; j < count; j++) + { SpawnPointBlock[j].FromBytes(bytes, ref i); } + } + + public TelehubInfoPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + TelehubBlock.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(SpawnPointBlock == null || SpawnPointBlock.Length != count) { + SpawnPointBlock = new SpawnPointBlockBlock[count]; + for(int j = 0; j < count; j++) + { SpawnPointBlock[j] = new SpawnPointBlockBlock(); } + } + for (int j = 0; j < count; j++) + { SpawnPointBlock[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += TelehubBlock.Length; + length++; + for (int j = 0; j < SpawnPointBlock.Length; j++) { length += SpawnPointBlock[j].Length; } + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += TelehubBlock.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + TelehubBlock.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int SpawnPointBlockStart = 0; + do + { + int variableLength = 0; + int SpawnPointBlockCount = 0; + + i = SpawnPointBlockStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < SpawnPointBlock.Length) { + int blockLength = SpawnPointBlock[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == SpawnPointBlockStart) { + variableLength += blockLength; + ++SpawnPointBlockCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)SpawnPointBlockCount; + for (i = SpawnPointBlockStart; i < SpawnPointBlockStart + SpawnPointBlockCount; i++) { SpawnPointBlock[i].ToBytes(packet, ref length); } + SpawnPointBlockStart += SpawnPointBlockCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + SpawnPointBlockStart < SpawnPointBlock.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class EconomyDataRequestPacket : Packet + { + public override int Length + { + get + { + int length = 10; + return length; + } + } + + public EconomyDataRequestPacket() + { + HasVariableBlocks = false; + Type = PacketType.EconomyDataRequest; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 24; + Header.Reliable = true; + } + + public EconomyDataRequestPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + } + + public EconomyDataRequestPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + } + + public override byte[] ToBytes() + { + int length = 10; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class EconomyDataPacket : Packet + { + /// + public sealed class InfoBlock : PacketBlock + { + public int ObjectCapacity; + public int ObjectCount; + public int PriceEnergyUnit; + public int PriceObjectClaim; + public int PricePublicObjectDecay; + public int PricePublicObjectDelete; + public int PriceParcelClaim; + public float PriceParcelClaimFactor; + public int PriceUpload; + public int PriceRentLight; + public int TeleportMinPrice; + public float TeleportPriceExponent; + public float EnergyEfficiency; + public float PriceObjectRent; + public float PriceObjectScaleFactor; + public int PriceParcelRent; + public int PriceGroupCreate; + + public override int Length + { + get + { + return 68; + } + } + + public InfoBlock() { } + public InfoBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + ObjectCapacity = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + ObjectCount = (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)); + PriceObjectClaim = (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)); + PricePublicObjectDelete = (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)); + PriceParcelClaimFactor = Utils.BytesToFloat(bytes, i); i += 4; + PriceUpload = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + PriceRentLight = (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)); + TeleportPriceExponent = Utils.BytesToFloat(bytes, i); i += 4; + EnergyEfficiency = Utils.BytesToFloat(bytes, i); i += 4; + PriceObjectRent = Utils.BytesToFloat(bytes, i); i += 4; + PriceObjectScaleFactor = Utils.BytesToFloat(bytes, i); i += 4; + PriceParcelRent = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + PriceGroupCreate = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.IntToBytes(ObjectCapacity, bytes, i); i += 4; + Utils.IntToBytes(ObjectCount, bytes, i); i += 4; + Utils.IntToBytes(PriceEnergyUnit, bytes, i); i += 4; + Utils.IntToBytes(PriceObjectClaim, bytes, i); i += 4; + Utils.IntToBytes(PricePublicObjectDecay, bytes, i); i += 4; + Utils.IntToBytes(PricePublicObjectDelete, bytes, i); i += 4; + Utils.IntToBytes(PriceParcelClaim, bytes, i); i += 4; + Utils.FloatToBytes(PriceParcelClaimFactor, bytes, i); i += 4; + Utils.IntToBytes(PriceUpload, bytes, i); i += 4; + Utils.IntToBytes(PriceRentLight, bytes, i); i += 4; + Utils.IntToBytes(TeleportMinPrice, bytes, i); i += 4; + Utils.FloatToBytes(TeleportPriceExponent, bytes, i); i += 4; + Utils.FloatToBytes(EnergyEfficiency, bytes, i); i += 4; + Utils.FloatToBytes(PriceObjectRent, bytes, i); i += 4; + Utils.FloatToBytes(PriceObjectScaleFactor, bytes, i); i += 4; + Utils.IntToBytes(PriceParcelRent, bytes, i); i += 4; + Utils.IntToBytes(PriceGroupCreate, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 10; + length += Info.Length; + return length; + } + } + public InfoBlock Info; + + public EconomyDataPacket() + { + HasVariableBlocks = false; + Type = PacketType.EconomyData; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 25; + Header.Reliable = true; + Header.Zerocoded = true; + Info = new InfoBlock(); + } + + public EconomyDataPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + Info.FromBytes(bytes, ref i); + } + + public EconomyDataPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + Info.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += Info.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class AvatarPickerRequestPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + public UUID QueryID; + + public override int Length + { + get + { + return 48; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + QueryID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + QueryID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class DataBlock : PacketBlock + { + public byte[] Name; + + public override int Length + { + get + { + int length = 1; + if (Name != null) { length += Name.Length; } + return length; + } + } + + public DataBlock() { } + public DataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + length = bytes[i++]; + Name = new byte[length]; + Buffer.BlockCopy(bytes, i, Name, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + bytes[i++] = (byte)Name.Length; + Buffer.BlockCopy(Name, 0, bytes, i, Name.Length); i += Name.Length; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += Data.Length; + return length; + } + } + public AgentDataBlock AgentData; + public DataBlock Data; + + public AvatarPickerRequestPacket() + { + HasVariableBlocks = false; + Type = PacketType.AvatarPickerRequest; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 26; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + Data = new DataBlock(); + } + + public AvatarPickerRequestPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + Data.FromBytes(bytes, ref i); + } + + public AvatarPickerRequestPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + Data.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += Data.Length; + if (Header.AckList != null && 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); + Data.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class AvatarPickerReplyPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID QueryID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + QueryID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + QueryID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class DataBlock : PacketBlock + { + public UUID AvatarID; + public byte[] FirstName; + public byte[] LastName; + + public override int Length + { + get + { + int length = 18; + if (FirstName != null) { length += FirstName.Length; } + if (LastName != null) { length += LastName.Length; } + return length; + } + } + + public DataBlock() { } + public DataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + AvatarID.FromBytes(bytes, i); i += 16; + length = bytes[i++]; + FirstName = new byte[length]; + Buffer.BlockCopy(bytes, i, FirstName, 0, length); i += length; + length = bytes[i++]; + LastName = new byte[length]; + Buffer.BlockCopy(bytes, i, LastName, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AvatarID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)FirstName.Length; + Buffer.BlockCopy(FirstName, 0, bytes, i, FirstName.Length); i += FirstName.Length; + bytes[i++] = (byte)LastName.Length; + Buffer.BlockCopy(LastName, 0, bytes, i, LastName.Length); i += LastName.Length; + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentData.Length; + for (int j = 0; j < Data.Length; j++) + length += Data[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public DataBlock[] Data; + + public AvatarPickerReplyPacket() + { + HasVariableBlocks = true; + Type = PacketType.AvatarPickerReply; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 28; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + Data = null; + } + + public AvatarPickerReplyPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(Data == null || Data.Length != -1) { + Data = new DataBlock[count]; + for(int j = 0; j < count; j++) + { Data[j] = new DataBlock(); } + } + for (int j = 0; j < count; j++) + { Data[j].FromBytes(bytes, ref i); } + } + + public AvatarPickerReplyPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(Data == null || Data.Length != count) { + Data = new DataBlock[count]; + for(int j = 0; j < count; j++) + { Data[j] = new DataBlock(); } + } + for (int j = 0; j < count; j++) + { Data[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length++; + for (int j = 0; j < Data.Length; j++) { length += Data[j].Length; } + if (Header.AckList != null && 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)Data.Length; + for (int j = 0; j < Data.Length; j++) { Data[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int DataStart = 0; + do + { + int variableLength = 0; + int DataCount = 0; + + i = DataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < Data.Length) { + int blockLength = Data[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == DataStart) { + variableLength += blockLength; + ++DataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)DataCount; + for (i = DataStart; i < DataStart + DataCount; i++) { Data[i].ToBytes(packet, ref length); } + DataStart += DataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + DataStart < Data.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class PlacesQueryPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + public UUID QueryID; + + public override int Length + { + get + { + return 48; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + QueryID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + QueryID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class TransactionDataBlock : PacketBlock + { + public UUID TransactionID; + + public override int Length + { + get + { + return 16; + } + } + + public TransactionDataBlock() { } + public TransactionDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + TransactionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + TransactionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class QueryDataBlock : PacketBlock + { + public byte[] QueryText; + public uint QueryFlags; + public sbyte Category; + public byte[] SimName; + + public override int Length + { + get + { + int length = 7; + if (QueryText != null) { length += QueryText.Length; } + if (SimName != null) { length += SimName.Length; } + return length; + } + } + + public QueryDataBlock() { } + public QueryDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + length = bytes[i++]; + QueryText = new byte[length]; + Buffer.BlockCopy(bytes, i, QueryText, 0, length); i += length; + QueryFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + Category = (sbyte)bytes[i++]; + length = bytes[i++]; + SimName = new byte[length]; + Buffer.BlockCopy(bytes, i, SimName, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + bytes[i++] = (byte)QueryText.Length; + Buffer.BlockCopy(QueryText, 0, bytes, i, QueryText.Length); i += QueryText.Length; + Utils.UIntToBytes(QueryFlags, bytes, i); i += 4; + bytes[i++] = (byte)Category; + bytes[i++] = (byte)SimName.Length; + Buffer.BlockCopy(SimName, 0, bytes, i, SimName.Length); i += SimName.Length; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += TransactionData.Length; + length += QueryData.Length; + return length; + } + } + public AgentDataBlock AgentData; + public TransactionDataBlock TransactionData; + public QueryDataBlock QueryData; + + public PlacesQueryPacket() + { + HasVariableBlocks = false; + Type = PacketType.PlacesQuery; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 29; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + TransactionData = new TransactionDataBlock(); + QueryData = new QueryDataBlock(); + } + + public PlacesQueryPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + TransactionData.FromBytes(bytes, ref i); + QueryData.FromBytes(bytes, ref i); + } + + public PlacesQueryPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + TransactionData.FromBytes(bytes, ref i); + QueryData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += TransactionData.Length; + length += QueryData.Length; + if (Header.AckList != null && 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); + QueryData.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class PlacesReplyPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID QueryID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + QueryID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + QueryID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class TransactionDataBlock : PacketBlock + { + public UUID TransactionID; + + public override int Length + { + get + { + return 16; + } + } + + public TransactionDataBlock() { } + public TransactionDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + TransactionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + TransactionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class QueryDataBlock : PacketBlock + { + public UUID OwnerID; + public byte[] Name; + public byte[] Desc; + public int ActualArea; + public int BillableArea; + public byte Flags; + public float GlobalX; + public float GlobalY; + public float GlobalZ; + public byte[] SimName; + public UUID SnapshotID; + public float Dwell; + public int Price; + + public override int Length + { + get + { + int length = 64; + if (Name != null) { length += Name.Length; } + if (Desc != null) { length += Desc.Length; } + if (SimName != null) { length += SimName.Length; } + return length; + } + } + + public QueryDataBlock() { } + public QueryDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + OwnerID.FromBytes(bytes, i); i += 16; + length = bytes[i++]; + Name = new byte[length]; + Buffer.BlockCopy(bytes, i, Name, 0, length); i += length; + length = bytes[i++]; + Desc = new byte[length]; + Buffer.BlockCopy(bytes, i, Desc, 0, length); i += length; + ActualArea = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + BillableArea = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + Flags = (byte)bytes[i++]; + GlobalX = Utils.BytesToFloat(bytes, i); i += 4; + GlobalY = Utils.BytesToFloat(bytes, i); i += 4; + GlobalZ = Utils.BytesToFloat(bytes, i); i += 4; + length = bytes[i++]; + SimName = new byte[length]; + Buffer.BlockCopy(bytes, i, SimName, 0, length); i += length; + SnapshotID.FromBytes(bytes, i); i += 16; + Dwell = Utils.BytesToFloat(bytes, i); i += 4; + Price = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + OwnerID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)Name.Length; + Buffer.BlockCopy(Name, 0, bytes, i, Name.Length); i += Name.Length; + bytes[i++] = (byte)Desc.Length; + Buffer.BlockCopy(Desc, 0, bytes, i, Desc.Length); i += Desc.Length; + Utils.IntToBytes(ActualArea, bytes, i); i += 4; + Utils.IntToBytes(BillableArea, bytes, i); i += 4; + bytes[i++] = Flags; + Utils.FloatToBytes(GlobalX, bytes, i); i += 4; + Utils.FloatToBytes(GlobalY, bytes, i); i += 4; + Utils.FloatToBytes(GlobalZ, bytes, i); i += 4; + bytes[i++] = (byte)SimName.Length; + Buffer.BlockCopy(SimName, 0, bytes, i, SimName.Length); i += SimName.Length; + SnapshotID.ToBytes(bytes, i); i += 16; + Utils.FloatToBytes(Dwell, bytes, i); i += 4; + Utils.IntToBytes(Price, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentData.Length; + length += TransactionData.Length; + for (int j = 0; j < QueryData.Length; j++) + length += QueryData[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public TransactionDataBlock TransactionData; + public QueryDataBlock[] QueryData; + + public PlacesReplyPacket() + { + HasVariableBlocks = true; + Type = PacketType.PlacesReply; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 30; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + TransactionData = new TransactionDataBlock(); + QueryData = null; + } + + public PlacesReplyPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + TransactionData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(QueryData == null || QueryData.Length != -1) { + QueryData = new QueryDataBlock[count]; + for(int j = 0; j < count; j++) + { QueryData[j] = new QueryDataBlock(); } + } + for (int j = 0; j < count; j++) + { QueryData[j].FromBytes(bytes, ref i); } + } + + public PlacesReplyPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + TransactionData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(QueryData == null || QueryData.Length != count) { + QueryData = new QueryDataBlock[count]; + for(int j = 0; j < count; j++) + { QueryData[j] = new QueryDataBlock(); } + } + for (int j = 0; j < count; j++) + { QueryData[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += TransactionData.Length; + length++; + for (int j = 0; j < QueryData.Length; j++) { length += QueryData[j].Length; } + if (Header.AckList != null && 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); + bytes[i++] = (byte)QueryData.Length; + for (int j = 0; j < QueryData.Length; j++) { QueryData[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + fixedLength += TransactionData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + TransactionData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int QueryDataStart = 0; + do + { + int variableLength = 0; + int QueryDataCount = 0; + + i = QueryDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < QueryData.Length) { + int blockLength = QueryData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == QueryDataStart) { + variableLength += blockLength; + ++QueryDataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)QueryDataCount; + for (i = QueryDataStart; i < QueryDataStart + QueryDataCount; i++) { QueryData[i].ToBytes(packet, ref length); } + QueryDataStart += QueryDataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + QueryDataStart < QueryData.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class DirFindQueryPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class QueryDataBlock : PacketBlock + { + public UUID QueryID; + public byte[] QueryText; + public uint QueryFlags; + public int QueryStart; + + public override int Length + { + get + { + int length = 25; + if (QueryText != null) { length += QueryText.Length; } + return length; + } + } + + public QueryDataBlock() { } + public QueryDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + QueryID.FromBytes(bytes, i); i += 16; + length = bytes[i++]; + QueryText = new byte[length]; + Buffer.BlockCopy(bytes, i, QueryText, 0, length); i += length; + 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)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + QueryID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)QueryText.Length; + Buffer.BlockCopy(QueryText, 0, bytes, i, QueryText.Length); i += QueryText.Length; + Utils.UIntToBytes(QueryFlags, bytes, i); i += 4; + Utils.IntToBytes(QueryStart, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += QueryData.Length; + return length; + } + } + public AgentDataBlock AgentData; + public QueryDataBlock QueryData; + + public DirFindQueryPacket() + { + HasVariableBlocks = false; + Type = PacketType.DirFindQuery; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 31; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + QueryData = new QueryDataBlock(); + } + + public DirFindQueryPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + QueryData.FromBytes(bytes, ref i); + } + + public DirFindQueryPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + QueryData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += QueryData.Length; + if (Header.AckList != null && 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); + QueryData.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class DirPlacesQueryPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class QueryDataBlock : PacketBlock + { + public UUID QueryID; + public byte[] QueryText; + public uint QueryFlags; + public sbyte Category; + public byte[] SimName; + public int QueryStart; + + public override int Length + { + get + { + int length = 27; + if (QueryText != null) { length += QueryText.Length; } + if (SimName != null) { length += SimName.Length; } + return length; + } + } + + public QueryDataBlock() { } + public QueryDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + QueryID.FromBytes(bytes, i); i += 16; + length = bytes[i++]; + QueryText = new byte[length]; + Buffer.BlockCopy(bytes, i, QueryText, 0, length); i += length; + QueryFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + Category = (sbyte)bytes[i++]; + length = bytes[i++]; + SimName = new byte[length]; + Buffer.BlockCopy(bytes, i, SimName, 0, length); i += length; + QueryStart = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + QueryID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)QueryText.Length; + Buffer.BlockCopy(QueryText, 0, bytes, i, QueryText.Length); i += QueryText.Length; + Utils.UIntToBytes(QueryFlags, bytes, i); i += 4; + bytes[i++] = (byte)Category; + bytes[i++] = (byte)SimName.Length; + Buffer.BlockCopy(SimName, 0, bytes, i, SimName.Length); i += SimName.Length; + Utils.IntToBytes(QueryStart, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += QueryData.Length; + return length; + } + } + public AgentDataBlock AgentData; + public QueryDataBlock QueryData; + + public DirPlacesQueryPacket() + { + HasVariableBlocks = false; + Type = PacketType.DirPlacesQuery; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 33; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + QueryData = new QueryDataBlock(); + } + + public DirPlacesQueryPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + QueryData.FromBytes(bytes, ref i); + } + + public DirPlacesQueryPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + QueryData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += QueryData.Length; + if (Header.AckList != null && 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); + QueryData.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class DirPlacesReplyPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + + public override int Length + { + get + { + return 16; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class QueryDataBlock : PacketBlock + { + public UUID QueryID; + + public override int Length + { + get + { + return 16; + } + } + + public QueryDataBlock() { } + public QueryDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + QueryID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + QueryID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class QueryRepliesBlock : PacketBlock + { + public UUID ParcelID; + public byte[] Name; + public bool ForSale; + public bool Auction; + public float Dwell; + + public override int Length + { + get + { + int length = 23; + if (Name != null) { length += Name.Length; } + return length; + } + } + + public QueryRepliesBlock() { } + public QueryRepliesBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + ParcelID.FromBytes(bytes, i); i += 16; + length = bytes[i++]; + Name = new byte[length]; + Buffer.BlockCopy(bytes, i, Name, 0, length); i += length; + ForSale = (bytes[i++] != 0) ? (bool)true : (bool)false; + Auction = (bytes[i++] != 0) ? (bool)true : (bool)false; + Dwell = Utils.BytesToFloat(bytes, i); i += 4; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + ParcelID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)Name.Length; + Buffer.BlockCopy(Name, 0, bytes, i, Name.Length); i += Name.Length; + bytes[i++] = (byte)((ForSale) ? 1 : 0); + bytes[i++] = (byte)((Auction) ? 1 : 0); + Utils.FloatToBytes(Dwell, bytes, i); i += 4; + } + + } + + /// + public sealed class StatusDataBlock : PacketBlock + { + public uint Status; + + public override int Length + { + get + { + return 4; + } + } + + public StatusDataBlock() { } + public StatusDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + Status = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UIntToBytes(Status, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 13; + length += AgentData.Length; + for (int j = 0; j < QueryData.Length; j++) + length += QueryData[j].Length; + for (int j = 0; j < QueryReplies.Length; j++) + length += QueryReplies[j].Length; + for (int j = 0; j < StatusData.Length; j++) + length += StatusData[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public QueryDataBlock[] QueryData; + public QueryRepliesBlock[] QueryReplies; + public StatusDataBlock[] StatusData; + + public DirPlacesReplyPacket() + { + HasVariableBlocks = true; + Type = PacketType.DirPlacesReply; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 35; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + QueryData = null; + QueryReplies = null; + StatusData = null; + } + + public DirPlacesReplyPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(QueryData == null || QueryData.Length != -1) { + QueryData = new QueryDataBlock[count]; + for(int j = 0; j < count; j++) + { QueryData[j] = new QueryDataBlock(); } + } + for (int j = 0; j < count; j++) + { QueryData[j].FromBytes(bytes, ref i); } + count = (int)bytes[i++]; + if(QueryReplies == null || QueryReplies.Length != -1) { + QueryReplies = new QueryRepliesBlock[count]; + for(int j = 0; j < count; j++) + { QueryReplies[j] = new QueryRepliesBlock(); } + } + for (int j = 0; j < count; j++) + { QueryReplies[j].FromBytes(bytes, ref i); } + count = (int)bytes[i++]; + if(StatusData == null || StatusData.Length != -1) { + StatusData = new StatusDataBlock[count]; + for(int j = 0; j < count; j++) + { StatusData[j] = new StatusDataBlock(); } + } + for (int j = 0; j < count; j++) + { StatusData[j].FromBytes(bytes, ref i); } + } + + public DirPlacesReplyPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(QueryData == null || QueryData.Length != count) { + QueryData = new QueryDataBlock[count]; + for(int j = 0; j < count; j++) + { QueryData[j] = new QueryDataBlock(); } + } + for (int j = 0; j < count; j++) + { QueryData[j].FromBytes(bytes, ref i); } + count = (int)bytes[i++]; + if(QueryReplies == null || QueryReplies.Length != count) { + QueryReplies = new QueryRepliesBlock[count]; + for(int j = 0; j < count; j++) + { QueryReplies[j] = new QueryRepliesBlock(); } + } + for (int j = 0; j < count; j++) + { QueryReplies[j].FromBytes(bytes, ref i); } + count = (int)bytes[i++]; + if(StatusData == null || StatusData.Length != count) { + StatusData = new StatusDataBlock[count]; + for(int j = 0; j < count; j++) + { StatusData[j] = new StatusDataBlock(); } + } + for (int j = 0; j < count; j++) + { StatusData[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length++; + for (int j = 0; j < QueryData.Length; j++) { length += QueryData[j].Length; } + length++; + for (int j = 0; j < QueryReplies.Length; j++) { length += QueryReplies[j].Length; } + length++; + for (int j = 0; j < StatusData.Length; j++) { length += StatusData[j].Length; } + if (Header.AckList != null && 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)QueryData.Length; + for (int j = 0; j < QueryData.Length; j++) { QueryData[j].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)StatusData.Length; + for (int j = 0; j < StatusData.Length; j++) { StatusData[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + fixedLength += 3; + + int QueryDataStart = 0; + int QueryRepliesStart = 0; + int StatusDataStart = 0; + do + { + int variableLength = 0; + int QueryDataCount = 0; + int QueryRepliesCount = 0; + int StatusDataCount = 0; + + i = QueryDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < QueryData.Length) { + int blockLength = QueryData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == QueryDataStart) { + variableLength += blockLength; + ++QueryDataCount; + } + else { break; } + ++i; + } + + i = QueryRepliesStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < QueryReplies.Length) { + int blockLength = QueryReplies[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == QueryRepliesStart) { + variableLength += blockLength; + ++QueryRepliesCount; + } + else { break; } + ++i; + } + + i = StatusDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < StatusData.Length) { + int blockLength = StatusData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == StatusDataStart) { + variableLength += blockLength; + ++StatusDataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)QueryDataCount; + for (i = QueryDataStart; i < QueryDataStart + QueryDataCount; i++) { QueryData[i].ToBytes(packet, ref length); } + QueryDataStart += QueryDataCount; + + packet[length++] = (byte)QueryRepliesCount; + for (i = QueryRepliesStart; i < QueryRepliesStart + QueryRepliesCount; i++) { QueryReplies[i].ToBytes(packet, ref length); } + QueryRepliesStart += QueryRepliesCount; + + packet[length++] = (byte)StatusDataCount; + for (i = StatusDataStart; i < StatusDataStart + StatusDataCount; i++) { StatusData[i].ToBytes(packet, ref length); } + StatusDataStart += StatusDataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + QueryDataStart < QueryData.Length || + QueryRepliesStart < QueryReplies.Length || + StatusDataStart < StatusData.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class DirPeopleReplyPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + + public override int Length + { + get + { + return 16; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class QueryDataBlock : PacketBlock + { + public UUID QueryID; + + public override int Length + { + get + { + return 16; + } + } + + public QueryDataBlock() { } + public QueryDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + QueryID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + QueryID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class QueryRepliesBlock : PacketBlock + { + public UUID AgentID; + public byte[] FirstName; + public byte[] LastName; + public byte[] Group; + public bool Online; + public int Reputation; + + public override int Length + { + get + { + int length = 24; + if (FirstName != null) { length += FirstName.Length; } + if (LastName != null) { length += LastName.Length; } + if (Group != null) { length += Group.Length; } + return length; + } + } + + public QueryRepliesBlock() { } + public QueryRepliesBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + AgentID.FromBytes(bytes, i); i += 16; + length = bytes[i++]; + FirstName = new byte[length]; + Buffer.BlockCopy(bytes, i, FirstName, 0, length); i += length; + length = bytes[i++]; + LastName = new byte[length]; + Buffer.BlockCopy(bytes, i, LastName, 0, length); i += length; + length = bytes[i++]; + Group = new byte[length]; + Buffer.BlockCopy(bytes, i, Group, 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)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)FirstName.Length; + Buffer.BlockCopy(FirstName, 0, bytes, i, FirstName.Length); i += FirstName.Length; + bytes[i++] = (byte)LastName.Length; + Buffer.BlockCopy(LastName, 0, bytes, i, LastName.Length); i += LastName.Length; + bytes[i++] = (byte)Group.Length; + Buffer.BlockCopy(Group, 0, bytes, i, Group.Length); i += Group.Length; + bytes[i++] = (byte)((Online) ? 1 : 0); + Utils.IntToBytes(Reputation, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentData.Length; + length += QueryData.Length; + for (int j = 0; j < QueryReplies.Length; j++) + length += QueryReplies[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public QueryDataBlock QueryData; + public QueryRepliesBlock[] QueryReplies; + + public DirPeopleReplyPacket() + { + HasVariableBlocks = true; + Type = PacketType.DirPeopleReply; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 36; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + QueryData = new QueryDataBlock(); + QueryReplies = null; + } + + public DirPeopleReplyPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + QueryData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(QueryReplies == null || QueryReplies.Length != -1) { + QueryReplies = new QueryRepliesBlock[count]; + for(int j = 0; j < count; j++) + { QueryReplies[j] = new QueryRepliesBlock(); } + } + for (int j = 0; j < count; j++) + { QueryReplies[j].FromBytes(bytes, ref i); } + } + + public DirPeopleReplyPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + QueryData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(QueryReplies == null || QueryReplies.Length != count) { + QueryReplies = new QueryRepliesBlock[count]; + for(int j = 0; j < count; j++) + { QueryReplies[j] = new QueryRepliesBlock(); } + } + for (int j = 0; j < count; j++) + { QueryReplies[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += QueryData.Length; + length++; + for (int j = 0; j < QueryReplies.Length; j++) { length += QueryReplies[j].Length; } + if (Header.AckList != null && 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); + QueryData.ToBytes(bytes, ref i); + bytes[i++] = (byte)QueryReplies.Length; + for (int j = 0; j < QueryReplies.Length; j++) { QueryReplies[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + fixedLength += QueryData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + QueryData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int QueryRepliesStart = 0; + do + { + int variableLength = 0; + int QueryRepliesCount = 0; + + i = QueryRepliesStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < QueryReplies.Length) { + int blockLength = QueryReplies[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == QueryRepliesStart) { + variableLength += blockLength; + ++QueryRepliesCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)QueryRepliesCount; + for (i = QueryRepliesStart; i < QueryRepliesStart + QueryRepliesCount; i++) { QueryReplies[i].ToBytes(packet, ref length); } + QueryRepliesStart += QueryRepliesCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + QueryRepliesStart < QueryReplies.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class DirEventsReplyPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + + public override int Length + { + get + { + return 16; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class QueryDataBlock : PacketBlock + { + public UUID QueryID; + + public override int Length + { + get + { + return 16; + } + } + + public QueryDataBlock() { } + public QueryDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + QueryID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + QueryID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class QueryRepliesBlock : PacketBlock + { + public UUID OwnerID; + public byte[] Name; + public uint EventID; + public byte[] Date; + public uint UnixTime; + public uint EventFlags; + + public override int Length + { + get + { + int length = 30; + if (Name != null) { length += Name.Length; } + if (Date != null) { length += Date.Length; } + return length; + } + } + + public QueryRepliesBlock() { } + public QueryRepliesBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + OwnerID.FromBytes(bytes, i); i += 16; + length = bytes[i++]; + Name = new byte[length]; + Buffer.BlockCopy(bytes, i, Name, 0, length); i += length; + EventID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + length = bytes[i++]; + Date = new byte[length]; + Buffer.BlockCopy(bytes, i, Date, 0, length); i += length; + UnixTime = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + EventFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + OwnerID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)Name.Length; + Buffer.BlockCopy(Name, 0, bytes, i, Name.Length); i += Name.Length; + Utils.UIntToBytes(EventID, bytes, i); i += 4; + bytes[i++] = (byte)Date.Length; + Buffer.BlockCopy(Date, 0, bytes, i, Date.Length); i += Date.Length; + Utils.UIntToBytes(UnixTime, bytes, i); i += 4; + Utils.UIntToBytes(EventFlags, bytes, i); i += 4; + } + + } + + /// + public sealed class StatusDataBlock : PacketBlock + { + public uint Status; + + public override int Length + { + get + { + return 4; + } + } + + public StatusDataBlock() { } + public StatusDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + Status = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UIntToBytes(Status, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 12; + length += AgentData.Length; + length += QueryData.Length; + for (int j = 0; j < QueryReplies.Length; j++) + length += QueryReplies[j].Length; + for (int j = 0; j < StatusData.Length; j++) + length += StatusData[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public QueryDataBlock QueryData; + public QueryRepliesBlock[] QueryReplies; + public StatusDataBlock[] StatusData; + + public DirEventsReplyPacket() + { + HasVariableBlocks = true; + Type = PacketType.DirEventsReply; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 37; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + QueryData = new QueryDataBlock(); + QueryReplies = null; + StatusData = null; + } + + public DirEventsReplyPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + QueryData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(QueryReplies == null || QueryReplies.Length != -1) { + QueryReplies = new QueryRepliesBlock[count]; + for(int j = 0; j < count; j++) + { QueryReplies[j] = new QueryRepliesBlock(); } + } + for (int j = 0; j < count; j++) + { QueryReplies[j].FromBytes(bytes, ref i); } + count = (int)bytes[i++]; + if(StatusData == null || StatusData.Length != -1) { + StatusData = new StatusDataBlock[count]; + for(int j = 0; j < count; j++) + { StatusData[j] = new StatusDataBlock(); } + } + for (int j = 0; j < count; j++) + { StatusData[j].FromBytes(bytes, ref i); } + } + + public DirEventsReplyPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + QueryData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(QueryReplies == null || QueryReplies.Length != count) { + QueryReplies = new QueryRepliesBlock[count]; + for(int j = 0; j < count; j++) + { QueryReplies[j] = new QueryRepliesBlock(); } + } + for (int j = 0; j < count; j++) + { QueryReplies[j].FromBytes(bytes, ref i); } + count = (int)bytes[i++]; + if(StatusData == null || StatusData.Length != count) { + StatusData = new StatusDataBlock[count]; + for(int j = 0; j < count; j++) + { StatusData[j] = new StatusDataBlock(); } + } + for (int j = 0; j < count; j++) + { StatusData[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += QueryData.Length; + length++; + for (int j = 0; j < QueryReplies.Length; j++) { length += QueryReplies[j].Length; } + length++; + for (int j = 0; j < StatusData.Length; j++) { length += StatusData[j].Length; } + if (Header.AckList != null && 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); + QueryData.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)StatusData.Length; + for (int j = 0; j < StatusData.Length; j++) { StatusData[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + fixedLength += QueryData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + QueryData.ToBytes(fixedBytes, ref i); + fixedLength += 2; + + int QueryRepliesStart = 0; + int StatusDataStart = 0; + do + { + int variableLength = 0; + int QueryRepliesCount = 0; + int StatusDataCount = 0; + + i = QueryRepliesStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < QueryReplies.Length) { + int blockLength = QueryReplies[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == QueryRepliesStart) { + variableLength += blockLength; + ++QueryRepliesCount; + } + else { break; } + ++i; + } + + i = StatusDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < StatusData.Length) { + int blockLength = StatusData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == StatusDataStart) { + variableLength += blockLength; + ++StatusDataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)QueryRepliesCount; + for (i = QueryRepliesStart; i < QueryRepliesStart + QueryRepliesCount; i++) { QueryReplies[i].ToBytes(packet, ref length); } + QueryRepliesStart += QueryRepliesCount; + + packet[length++] = (byte)StatusDataCount; + for (i = StatusDataStart; i < StatusDataStart + StatusDataCount; i++) { StatusData[i].ToBytes(packet, ref length); } + StatusDataStart += StatusDataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + QueryRepliesStart < QueryReplies.Length || + StatusDataStart < StatusData.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class DirGroupsReplyPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + + public override int Length + { + get + { + return 16; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class QueryDataBlock : PacketBlock + { + public UUID QueryID; + + public override int Length + { + get + { + return 16; + } + } + + public QueryDataBlock() { } + public QueryDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + QueryID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + QueryID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class QueryRepliesBlock : PacketBlock + { + public UUID GroupID; + public byte[] GroupName; + public int Members; + public float SearchOrder; + + public override int Length + { + get + { + int length = 25; + if (GroupName != null) { length += GroupName.Length; } + return length; + } + } + + public QueryRepliesBlock() { } + public QueryRepliesBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + GroupID.FromBytes(bytes, i); i += 16; + length = bytes[i++]; + GroupName = new byte[length]; + Buffer.BlockCopy(bytes, i, GroupName, 0, length); i += length; + Members = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + SearchOrder = Utils.BytesToFloat(bytes, i); i += 4; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + GroupID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)GroupName.Length; + Buffer.BlockCopy(GroupName, 0, bytes, i, GroupName.Length); i += GroupName.Length; + Utils.IntToBytes(Members, bytes, i); i += 4; + Utils.FloatToBytes(SearchOrder, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentData.Length; + length += QueryData.Length; + for (int j = 0; j < QueryReplies.Length; j++) + length += QueryReplies[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public QueryDataBlock QueryData; + public QueryRepliesBlock[] QueryReplies; + + public DirGroupsReplyPacket() + { + HasVariableBlocks = true; + Type = PacketType.DirGroupsReply; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 38; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + QueryData = new QueryDataBlock(); + QueryReplies = null; + } + + public DirGroupsReplyPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + QueryData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(QueryReplies == null || QueryReplies.Length != -1) { + QueryReplies = new QueryRepliesBlock[count]; + for(int j = 0; j < count; j++) + { QueryReplies[j] = new QueryRepliesBlock(); } + } + for (int j = 0; j < count; j++) + { QueryReplies[j].FromBytes(bytes, ref i); } + } + + public DirGroupsReplyPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + QueryData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(QueryReplies == null || QueryReplies.Length != count) { + QueryReplies = new QueryRepliesBlock[count]; + for(int j = 0; j < count; j++) + { QueryReplies[j] = new QueryRepliesBlock(); } + } + for (int j = 0; j < count; j++) + { QueryReplies[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += QueryData.Length; + length++; + for (int j = 0; j < QueryReplies.Length; j++) { length += QueryReplies[j].Length; } + if (Header.AckList != null && 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); + QueryData.ToBytes(bytes, ref i); + bytes[i++] = (byte)QueryReplies.Length; + for (int j = 0; j < QueryReplies.Length; j++) { QueryReplies[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + fixedLength += QueryData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + QueryData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int QueryRepliesStart = 0; + do + { + int variableLength = 0; + int QueryRepliesCount = 0; + + i = QueryRepliesStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < QueryReplies.Length) { + int blockLength = QueryReplies[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == QueryRepliesStart) { + variableLength += blockLength; + ++QueryRepliesCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)QueryRepliesCount; + for (i = QueryRepliesStart; i < QueryRepliesStart + QueryRepliesCount; i++) { QueryReplies[i].ToBytes(packet, ref length); } + QueryRepliesStart += QueryRepliesCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + QueryRepliesStart < QueryReplies.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class DirClassifiedQueryPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class QueryDataBlock : PacketBlock + { + public UUID QueryID; + public byte[] QueryText; + public uint QueryFlags; + public uint Category; + public int QueryStart; + + public override int Length + { + get + { + int length = 29; + if (QueryText != null) { length += QueryText.Length; } + return length; + } + } + + public QueryDataBlock() { } + public QueryDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + QueryID.FromBytes(bytes, i); i += 16; + length = bytes[i++]; + QueryText = new byte[length]; + Buffer.BlockCopy(bytes, i, QueryText, 0, length); i += length; + QueryFlags = (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)); + QueryStart = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + QueryID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)QueryText.Length; + Buffer.BlockCopy(QueryText, 0, bytes, i, QueryText.Length); i += QueryText.Length; + Utils.UIntToBytes(QueryFlags, bytes, i); i += 4; + Utils.UIntToBytes(Category, bytes, i); i += 4; + Utils.IntToBytes(QueryStart, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += QueryData.Length; + return length; + } + } + public AgentDataBlock AgentData; + public QueryDataBlock QueryData; + + public DirClassifiedQueryPacket() + { + HasVariableBlocks = false; + Type = PacketType.DirClassifiedQuery; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 39; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + QueryData = new QueryDataBlock(); + } + + public DirClassifiedQueryPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + QueryData.FromBytes(bytes, ref i); + } + + public DirClassifiedQueryPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + QueryData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += QueryData.Length; + if (Header.AckList != null && 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); + QueryData.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class DirClassifiedReplyPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + + public override int Length + { + get + { + return 16; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class QueryDataBlock : PacketBlock + { + public UUID QueryID; + + public override int Length + { + get + { + return 16; + } + } + + public QueryDataBlock() { } + public QueryDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + QueryID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + QueryID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class QueryRepliesBlock : PacketBlock + { + public UUID ClassifiedID; + public byte[] Name; + public byte ClassifiedFlags; + public uint CreationDate; + public uint ExpirationDate; + public int PriceForListing; + + public override int Length + { + get + { + int length = 30; + if (Name != null) { length += Name.Length; } + return length; + } + } + + public QueryRepliesBlock() { } + public QueryRepliesBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + ClassifiedID.FromBytes(bytes, i); i += 16; + length = bytes[i++]; + Name = new byte[length]; + Buffer.BlockCopy(bytes, i, Name, 0, length); i += length; + ClassifiedFlags = (byte)bytes[i++]; + CreationDate = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + ExpirationDate = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + PriceForListing = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + ClassifiedID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)Name.Length; + Buffer.BlockCopy(Name, 0, bytes, i, Name.Length); i += Name.Length; + bytes[i++] = ClassifiedFlags; + Utils.UIntToBytes(CreationDate, bytes, i); i += 4; + Utils.UIntToBytes(ExpirationDate, bytes, i); i += 4; + Utils.IntToBytes(PriceForListing, bytes, i); i += 4; + } + + } + + /// + public sealed class StatusDataBlock : PacketBlock + { + public uint Status; + + public override int Length + { + get + { + return 4; + } + } + + public StatusDataBlock() { } + public StatusDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + Status = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UIntToBytes(Status, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 12; + length += AgentData.Length; + length += QueryData.Length; + for (int j = 0; j < QueryReplies.Length; j++) + length += QueryReplies[j].Length; + for (int j = 0; j < StatusData.Length; j++) + length += StatusData[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public QueryDataBlock QueryData; + public QueryRepliesBlock[] QueryReplies; + public StatusDataBlock[] StatusData; + + public DirClassifiedReplyPacket() + { + HasVariableBlocks = true; + Type = PacketType.DirClassifiedReply; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 41; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + QueryData = new QueryDataBlock(); + QueryReplies = null; + StatusData = null; + } + + public DirClassifiedReplyPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + QueryData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(QueryReplies == null || QueryReplies.Length != -1) { + QueryReplies = new QueryRepliesBlock[count]; + for(int j = 0; j < count; j++) + { QueryReplies[j] = new QueryRepliesBlock(); } + } + for (int j = 0; j < count; j++) + { QueryReplies[j].FromBytes(bytes, ref i); } + count = (int)bytes[i++]; + if(StatusData == null || StatusData.Length != -1) { + StatusData = new StatusDataBlock[count]; + for(int j = 0; j < count; j++) + { StatusData[j] = new StatusDataBlock(); } + } + for (int j = 0; j < count; j++) + { StatusData[j].FromBytes(bytes, ref i); } + } + + public DirClassifiedReplyPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + QueryData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(QueryReplies == null || QueryReplies.Length != count) { + QueryReplies = new QueryRepliesBlock[count]; + for(int j = 0; j < count; j++) + { QueryReplies[j] = new QueryRepliesBlock(); } + } + for (int j = 0; j < count; j++) + { QueryReplies[j].FromBytes(bytes, ref i); } + count = (int)bytes[i++]; + if(StatusData == null || StatusData.Length != count) { + StatusData = new StatusDataBlock[count]; + for(int j = 0; j < count; j++) + { StatusData[j] = new StatusDataBlock(); } + } + for (int j = 0; j < count; j++) + { StatusData[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += QueryData.Length; + length++; + for (int j = 0; j < QueryReplies.Length; j++) { length += QueryReplies[j].Length; } + length++; + for (int j = 0; j < StatusData.Length; j++) { length += StatusData[j].Length; } + if (Header.AckList != null && 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); + QueryData.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)StatusData.Length; + for (int j = 0; j < StatusData.Length; j++) { StatusData[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + fixedLength += QueryData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + QueryData.ToBytes(fixedBytes, ref i); + fixedLength += 2; + + int QueryRepliesStart = 0; + int StatusDataStart = 0; + do + { + int variableLength = 0; + int QueryRepliesCount = 0; + int StatusDataCount = 0; + + i = QueryRepliesStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < QueryReplies.Length) { + int blockLength = QueryReplies[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == QueryRepliesStart) { + variableLength += blockLength; + ++QueryRepliesCount; + } + else { break; } + ++i; + } + + i = StatusDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < StatusData.Length) { + int blockLength = StatusData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == StatusDataStart) { + variableLength += blockLength; + ++StatusDataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)QueryRepliesCount; + for (i = QueryRepliesStart; i < QueryRepliesStart + QueryRepliesCount; i++) { QueryReplies[i].ToBytes(packet, ref length); } + QueryRepliesStart += QueryRepliesCount; + + packet[length++] = (byte)StatusDataCount; + for (i = StatusDataStart; i < StatusDataStart + StatusDataCount; i++) { StatusData[i].ToBytes(packet, ref length); } + StatusDataStart += StatusDataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + QueryRepliesStart < QueryReplies.Length || + StatusDataStart < StatusData.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class AvatarClassifiedReplyPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID TargetID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + TargetID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + TargetID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class DataBlock : PacketBlock + { + public UUID ClassifiedID; + public byte[] Name; + + public override int Length + { + get + { + int length = 17; + if (Name != null) { length += Name.Length; } + return length; + } + } + + public DataBlock() { } + public DataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + ClassifiedID.FromBytes(bytes, i); i += 16; + length = bytes[i++]; + Name = new byte[length]; + Buffer.BlockCopy(bytes, i, Name, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + ClassifiedID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)Name.Length; + Buffer.BlockCopy(Name, 0, bytes, i, Name.Length); i += Name.Length; + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentData.Length; + for (int j = 0; j < Data.Length; j++) + length += Data[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public DataBlock[] Data; + + public AvatarClassifiedReplyPacket() + { + HasVariableBlocks = true; + Type = PacketType.AvatarClassifiedReply; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 42; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + Data = null; + } + + public AvatarClassifiedReplyPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(Data == null || Data.Length != -1) { + Data = new DataBlock[count]; + for(int j = 0; j < count; j++) + { Data[j] = new DataBlock(); } + } + for (int j = 0; j < count; j++) + { Data[j].FromBytes(bytes, ref i); } + } + + public AvatarClassifiedReplyPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(Data == null || Data.Length != count) { + Data = new DataBlock[count]; + for(int j = 0; j < count; j++) + { Data[j] = new DataBlock(); } + } + for (int j = 0; j < count; j++) + { Data[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length++; + for (int j = 0; j < Data.Length; j++) { length += Data[j].Length; } + if (Header.AckList != null && 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)Data.Length; + for (int j = 0; j < Data.Length; j++) { Data[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int DataStart = 0; + do + { + int variableLength = 0; + int DataCount = 0; + + i = DataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < Data.Length) { + int blockLength = Data[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == DataStart) { + variableLength += blockLength; + ++DataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)DataCount; + for (i = DataStart; i < DataStart + DataCount; i++) { Data[i].ToBytes(packet, ref length); } + DataStart += DataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + DataStart < Data.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class ClassifiedInfoRequestPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class DataBlock : PacketBlock + { + public UUID ClassifiedID; + + public override int Length + { + get + { + return 16; + } + } + + public DataBlock() { } + public DataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + ClassifiedID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + ClassifiedID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += Data.Length; + return length; + } + } + public AgentDataBlock AgentData; + public DataBlock Data; + + public ClassifiedInfoRequestPacket() + { + HasVariableBlocks = false; + Type = PacketType.ClassifiedInfoRequest; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 43; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + Data = new DataBlock(); + } + + public ClassifiedInfoRequestPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + Data.FromBytes(bytes, ref i); + } + + public ClassifiedInfoRequestPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + Data.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += Data.Length; + if (Header.AckList != null && 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); + Data.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class ClassifiedInfoReplyPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + + public override int Length + { + get + { + return 16; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class DataBlock : PacketBlock + { + public UUID ClassifiedID; + public UUID CreatorID; + public uint CreationDate; + public uint ExpirationDate; + public uint Category; + public byte[] Name; + public byte[] Desc; + public UUID ParcelID; + public uint ParentEstate; + public UUID SnapshotID; + public byte[] SimName; + public Vector3d PosGlobal; + public byte[] ParcelName; + public byte ClassifiedFlags; + public int PriceForListing; + + public override int Length + { + get + { + int length = 114; + if (Name != null) { length += Name.Length; } + if (Desc != null) { length += Desc.Length; } + if (SimName != null) { length += SimName.Length; } + if (ParcelName != null) { length += ParcelName.Length; } + return length; + } + } + + public DataBlock() { } + public DataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + ClassifiedID.FromBytes(bytes, i); i += 16; + CreatorID.FromBytes(bytes, i); i += 16; + CreationDate = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + ExpirationDate = (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)); + length = bytes[i++]; + Name = new byte[length]; + Buffer.BlockCopy(bytes, i, Name, 0, length); i += length; + length = (bytes[i++] + (bytes[i++] << 8)); + Desc = new byte[length]; + Buffer.BlockCopy(bytes, i, Desc, 0, length); i += length; + ParcelID.FromBytes(bytes, i); i += 16; + ParentEstate = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + SnapshotID.FromBytes(bytes, i); i += 16; + length = bytes[i++]; + SimName = new byte[length]; + Buffer.BlockCopy(bytes, i, SimName, 0, length); i += length; + PosGlobal.FromBytes(bytes, i); i += 24; + length = bytes[i++]; + ParcelName = new byte[length]; + Buffer.BlockCopy(bytes, i, ParcelName, 0, length); i += length; + ClassifiedFlags = (byte)bytes[i++]; + PriceForListing = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + ClassifiedID.ToBytes(bytes, i); i += 16; + CreatorID.ToBytes(bytes, i); i += 16; + Utils.UIntToBytes(CreationDate, bytes, i); i += 4; + Utils.UIntToBytes(ExpirationDate, bytes, i); i += 4; + Utils.UIntToBytes(Category, bytes, i); i += 4; + bytes[i++] = (byte)Name.Length; + Buffer.BlockCopy(Name, 0, bytes, i, Name.Length); i += Name.Length; + bytes[i++] = (byte)(Desc.Length % 256); + bytes[i++] = (byte)((Desc.Length >> 8) % 256); + Buffer.BlockCopy(Desc, 0, bytes, i, Desc.Length); i += Desc.Length; + ParcelID.ToBytes(bytes, i); i += 16; + Utils.UIntToBytes(ParentEstate, bytes, i); i += 4; + SnapshotID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)SimName.Length; + Buffer.BlockCopy(SimName, 0, bytes, i, SimName.Length); i += SimName.Length; + PosGlobal.ToBytes(bytes, i); i += 24; + bytes[i++] = (byte)ParcelName.Length; + Buffer.BlockCopy(ParcelName, 0, bytes, i, ParcelName.Length); i += ParcelName.Length; + bytes[i++] = ClassifiedFlags; + Utils.IntToBytes(PriceForListing, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += Data.Length; + return length; + } + } + public AgentDataBlock AgentData; + public DataBlock Data; + + public ClassifiedInfoReplyPacket() + { + HasVariableBlocks = false; + Type = PacketType.ClassifiedInfoReply; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 44; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + Data = new DataBlock(); + } + + public ClassifiedInfoReplyPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + Data.FromBytes(bytes, ref i); + } + + public ClassifiedInfoReplyPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + Data.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += Data.Length; + if (Header.AckList != null && 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); + Data.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class ClassifiedInfoUpdatePacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class DataBlock : PacketBlock + { + public UUID ClassifiedID; + public uint Category; + public byte[] Name; + public byte[] Desc; + public UUID ParcelID; + public uint ParentEstate; + public UUID SnapshotID; + public Vector3d PosGlobal; + public byte ClassifiedFlags; + public int PriceForListing; + + public override int Length + { + get + { + int length = 88; + if (Name != null) { length += Name.Length; } + if (Desc != null) { length += Desc.Length; } + return length; + } + } + + public DataBlock() { } + public DataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + ClassifiedID.FromBytes(bytes, i); i += 16; + Category = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + length = bytes[i++]; + Name = new byte[length]; + Buffer.BlockCopy(bytes, i, Name, 0, length); i += length; + length = (bytes[i++] + (bytes[i++] << 8)); + Desc = new byte[length]; + Buffer.BlockCopy(bytes, i, Desc, 0, length); i += length; + ParcelID.FromBytes(bytes, i); i += 16; + ParentEstate = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + SnapshotID.FromBytes(bytes, i); i += 16; + PosGlobal.FromBytes(bytes, i); i += 24; + ClassifiedFlags = (byte)bytes[i++]; + PriceForListing = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + ClassifiedID.ToBytes(bytes, i); i += 16; + Utils.UIntToBytes(Category, bytes, i); i += 4; + bytes[i++] = (byte)Name.Length; + Buffer.BlockCopy(Name, 0, bytes, i, Name.Length); i += Name.Length; + bytes[i++] = (byte)(Desc.Length % 256); + bytes[i++] = (byte)((Desc.Length >> 8) % 256); + Buffer.BlockCopy(Desc, 0, bytes, i, Desc.Length); i += Desc.Length; + ParcelID.ToBytes(bytes, i); i += 16; + Utils.UIntToBytes(ParentEstate, bytes, i); i += 4; + SnapshotID.ToBytes(bytes, i); i += 16; + PosGlobal.ToBytes(bytes, i); i += 24; + bytes[i++] = ClassifiedFlags; + Utils.IntToBytes(PriceForListing, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += Data.Length; + return length; + } + } + public AgentDataBlock AgentData; + public DataBlock Data; + + public ClassifiedInfoUpdatePacket() + { + HasVariableBlocks = false; + Type = PacketType.ClassifiedInfoUpdate; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 45; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + Data = new DataBlock(); + } + + public ClassifiedInfoUpdatePacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + Data.FromBytes(bytes, ref i); + } + + public ClassifiedInfoUpdatePacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + Data.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += Data.Length; + if (Header.AckList != null && 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); + Data.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class ClassifiedDeletePacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class DataBlock : PacketBlock + { + public UUID ClassifiedID; + + public override int Length + { + get + { + return 16; + } + } + + public DataBlock() { } + public DataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + ClassifiedID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + ClassifiedID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += Data.Length; + return length; + } + } + public AgentDataBlock AgentData; + public DataBlock Data; + + public ClassifiedDeletePacket() + { + HasVariableBlocks = false; + Type = PacketType.ClassifiedDelete; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 46; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + Data = new DataBlock(); + } + + public ClassifiedDeletePacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + Data.FromBytes(bytes, ref i); + } + + public ClassifiedDeletePacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + Data.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += Data.Length; + if (Header.AckList != null && 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); + Data.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class ClassifiedGodDeletePacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class DataBlock : PacketBlock + { + public UUID ClassifiedID; + public UUID QueryID; + + public override int Length + { + get + { + return 32; + } + } + + public DataBlock() { } + public DataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + ClassifiedID.FromBytes(bytes, i); i += 16; + QueryID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + ClassifiedID.ToBytes(bytes, i); i += 16; + QueryID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += Data.Length; + return length; + } + } + public AgentDataBlock AgentData; + public DataBlock Data; + + public ClassifiedGodDeletePacket() + { + HasVariableBlocks = false; + Type = PacketType.ClassifiedGodDelete; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 47; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + Data = new DataBlock(); + } + + public ClassifiedGodDeletePacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + Data.FromBytes(bytes, ref i); + } + + public ClassifiedGodDeletePacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + Data.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += Data.Length; + if (Header.AckList != null && 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); + Data.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class DirLandQueryPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class QueryDataBlock : PacketBlock + { + public UUID QueryID; + public uint QueryFlags; + public uint SearchType; + public int Price; + public int Area; + public int QueryStart; + + public override int Length + { + get + { + return 36; + } + } + + public QueryDataBlock() { } + public QueryDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + QueryID.FromBytes(bytes, i); i += 16; + QueryFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + SearchType = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + Price = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + Area = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + QueryStart = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + QueryID.ToBytes(bytes, i); i += 16; + Utils.UIntToBytes(QueryFlags, bytes, i); i += 4; + Utils.UIntToBytes(SearchType, bytes, i); i += 4; + Utils.IntToBytes(Price, bytes, i); i += 4; + Utils.IntToBytes(Area, bytes, i); i += 4; + Utils.IntToBytes(QueryStart, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += QueryData.Length; + return length; + } + } + public AgentDataBlock AgentData; + public QueryDataBlock QueryData; + + public DirLandQueryPacket() + { + HasVariableBlocks = false; + Type = PacketType.DirLandQuery; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 48; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + QueryData = new QueryDataBlock(); + } + + public DirLandQueryPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + QueryData.FromBytes(bytes, ref i); + } + + public DirLandQueryPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + QueryData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += QueryData.Length; + if (Header.AckList != null && 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); + QueryData.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class DirLandReplyPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + + public override int Length + { + get + { + return 16; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class QueryDataBlock : PacketBlock + { + public UUID QueryID; + + public override int Length + { + get + { + return 16; + } + } + + public QueryDataBlock() { } + public QueryDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + QueryID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + QueryID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class QueryRepliesBlock : PacketBlock + { + public UUID ParcelID; + public byte[] Name; + public bool Auction; + public bool ForSale; + public int SalePrice; + public int ActualArea; + + public override int Length + { + get + { + int length = 27; + if (Name != null) { length += Name.Length; } + return length; + } + } + + public QueryRepliesBlock() { } + public QueryRepliesBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + ParcelID.FromBytes(bytes, i); i += 16; + length = bytes[i++]; + Name = new byte[length]; + Buffer.BlockCopy(bytes, i, Name, 0, length); i += length; + Auction = (bytes[i++] != 0) ? (bool)true : (bool)false; + ForSale = (bytes[i++] != 0) ? (bool)true : (bool)false; + SalePrice = (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)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + ParcelID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)Name.Length; + Buffer.BlockCopy(Name, 0, bytes, i, Name.Length); i += Name.Length; + bytes[i++] = (byte)((Auction) ? 1 : 0); + bytes[i++] = (byte)((ForSale) ? 1 : 0); + Utils.IntToBytes(SalePrice, bytes, i); i += 4; + Utils.IntToBytes(ActualArea, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentData.Length; + length += QueryData.Length; + for (int j = 0; j < QueryReplies.Length; j++) + length += QueryReplies[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public QueryDataBlock QueryData; + public QueryRepliesBlock[] QueryReplies; + + public DirLandReplyPacket() + { + HasVariableBlocks = true; + Type = PacketType.DirLandReply; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 50; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + QueryData = new QueryDataBlock(); + QueryReplies = null; + } + + public DirLandReplyPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + QueryData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(QueryReplies == null || QueryReplies.Length != -1) { + QueryReplies = new QueryRepliesBlock[count]; + for(int j = 0; j < count; j++) + { QueryReplies[j] = new QueryRepliesBlock(); } + } + for (int j = 0; j < count; j++) + { QueryReplies[j].FromBytes(bytes, ref i); } + } + + public DirLandReplyPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + QueryData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(QueryReplies == null || QueryReplies.Length != count) { + QueryReplies = new QueryRepliesBlock[count]; + for(int j = 0; j < count; j++) + { QueryReplies[j] = new QueryRepliesBlock(); } + } + for (int j = 0; j < count; j++) + { QueryReplies[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += QueryData.Length; + length++; + for (int j = 0; j < QueryReplies.Length; j++) { length += QueryReplies[j].Length; } + if (Header.AckList != null && 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); + QueryData.ToBytes(bytes, ref i); + bytes[i++] = (byte)QueryReplies.Length; + for (int j = 0; j < QueryReplies.Length; j++) { QueryReplies[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + fixedLength += QueryData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + QueryData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int QueryRepliesStart = 0; + do + { + int variableLength = 0; + int QueryRepliesCount = 0; + + i = QueryRepliesStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < QueryReplies.Length) { + int blockLength = QueryReplies[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == QueryRepliesStart) { + variableLength += blockLength; + ++QueryRepliesCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)QueryRepliesCount; + for (i = QueryRepliesStart; i < QueryRepliesStart + QueryRepliesCount; i++) { QueryReplies[i].ToBytes(packet, ref length); } + QueryRepliesStart += QueryRepliesCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + QueryRepliesStart < QueryReplies.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class DirPopularQueryPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class QueryDataBlock : PacketBlock + { + public UUID QueryID; + public uint QueryFlags; + + public override int Length + { + get + { + return 20; + } + } + + public QueryDataBlock() { } + public QueryDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + QueryID.FromBytes(bytes, i); i += 16; + QueryFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + QueryID.ToBytes(bytes, i); i += 16; + Utils.UIntToBytes(QueryFlags, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += QueryData.Length; + return length; + } + } + public AgentDataBlock AgentData; + public QueryDataBlock QueryData; + + public DirPopularQueryPacket() + { + HasVariableBlocks = false; + Type = PacketType.DirPopularQuery; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 51; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + QueryData = new QueryDataBlock(); + } + + public DirPopularQueryPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + QueryData.FromBytes(bytes, ref i); + } + + public DirPopularQueryPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + QueryData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += QueryData.Length; + if (Header.AckList != null && 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); + QueryData.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class DirPopularReplyPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + + public override int Length + { + get + { + return 16; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class QueryDataBlock : PacketBlock + { + public UUID QueryID; + + public override int Length + { + get + { + return 16; + } + } + + public QueryDataBlock() { } + public QueryDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + QueryID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + QueryID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class QueryRepliesBlock : PacketBlock + { + public UUID ParcelID; + public byte[] Name; + public float Dwell; + + public override int Length + { + get + { + int length = 21; + if (Name != null) { length += Name.Length; } + return length; + } + } + + public QueryRepliesBlock() { } + public QueryRepliesBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + ParcelID.FromBytes(bytes, i); i += 16; + length = bytes[i++]; + Name = new byte[length]; + Buffer.BlockCopy(bytes, i, Name, 0, length); i += length; + Dwell = Utils.BytesToFloat(bytes, i); i += 4; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + ParcelID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)Name.Length; + Buffer.BlockCopy(Name, 0, bytes, i, Name.Length); i += Name.Length; + Utils.FloatToBytes(Dwell, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentData.Length; + length += QueryData.Length; + for (int j = 0; j < QueryReplies.Length; j++) + length += QueryReplies[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public QueryDataBlock QueryData; + public QueryRepliesBlock[] QueryReplies; + + public DirPopularReplyPacket() + { + HasVariableBlocks = true; + Type = PacketType.DirPopularReply; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 53; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + QueryData = new QueryDataBlock(); + QueryReplies = null; + } + + public DirPopularReplyPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + QueryData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(QueryReplies == null || QueryReplies.Length != -1) { + QueryReplies = new QueryRepliesBlock[count]; + for(int j = 0; j < count; j++) + { QueryReplies[j] = new QueryRepliesBlock(); } + } + for (int j = 0; j < count; j++) + { QueryReplies[j].FromBytes(bytes, ref i); } + } + + public DirPopularReplyPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + QueryData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(QueryReplies == null || QueryReplies.Length != count) { + QueryReplies = new QueryRepliesBlock[count]; + for(int j = 0; j < count; j++) + { QueryReplies[j] = new QueryRepliesBlock(); } + } + for (int j = 0; j < count; j++) + { QueryReplies[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += QueryData.Length; + length++; + for (int j = 0; j < QueryReplies.Length; j++) { length += QueryReplies[j].Length; } + if (Header.AckList != null && 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); + QueryData.ToBytes(bytes, ref i); + bytes[i++] = (byte)QueryReplies.Length; + for (int j = 0; j < QueryReplies.Length; j++) { QueryReplies[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + fixedLength += QueryData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + QueryData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int QueryRepliesStart = 0; + do + { + int variableLength = 0; + int QueryRepliesCount = 0; + + i = QueryRepliesStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < QueryReplies.Length) { + int blockLength = QueryReplies[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == QueryRepliesStart) { + variableLength += blockLength; + ++QueryRepliesCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)QueryRepliesCount; + for (i = QueryRepliesStart; i < QueryRepliesStart + QueryRepliesCount; i++) { QueryReplies[i].ToBytes(packet, ref length); } + QueryRepliesStart += QueryRepliesCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + QueryRepliesStart < QueryReplies.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class ParcelInfoRequestPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class DataBlock : PacketBlock + { + public UUID ParcelID; + + public override int Length + { + get + { + return 16; + } + } + + public DataBlock() { } + public DataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + ParcelID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + ParcelID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += Data.Length; + return length; + } + } + public AgentDataBlock AgentData; + public DataBlock Data; + + public ParcelInfoRequestPacket() + { + HasVariableBlocks = false; + Type = PacketType.ParcelInfoRequest; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 54; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + Data = new DataBlock(); + } + + public ParcelInfoRequestPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + Data.FromBytes(bytes, ref i); + } + + public ParcelInfoRequestPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + Data.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += Data.Length; + if (Header.AckList != null && 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); + Data.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class ParcelInfoReplyPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + + public override int Length + { + get + { + return 16; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class DataBlock : PacketBlock + { + public UUID ParcelID; + public UUID OwnerID; + public byte[] Name; + public byte[] Desc; + public int ActualArea; + public int BillableArea; + public byte Flags; + public float GlobalX; + public float GlobalY; + public float GlobalZ; + public byte[] SimName; + public UUID SnapshotID; + public float Dwell; + public int SalePrice; + public int AuctionID; + + public override int Length + { + get + { + int length = 84; + if (Name != null) { length += Name.Length; } + if (Desc != null) { length += Desc.Length; } + if (SimName != null) { length += SimName.Length; } + return length; + } + } + + public DataBlock() { } + public DataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + ParcelID.FromBytes(bytes, i); i += 16; + OwnerID.FromBytes(bytes, i); i += 16; + length = bytes[i++]; + Name = new byte[length]; + Buffer.BlockCopy(bytes, i, Name, 0, length); i += length; + length = bytes[i++]; + Desc = new byte[length]; + Buffer.BlockCopy(bytes, i, Desc, 0, length); i += length; + ActualArea = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + BillableArea = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + Flags = (byte)bytes[i++]; + GlobalX = Utils.BytesToFloat(bytes, i); i += 4; + GlobalY = Utils.BytesToFloat(bytes, i); i += 4; + GlobalZ = Utils.BytesToFloat(bytes, i); i += 4; + length = bytes[i++]; + SimName = new byte[length]; + Buffer.BlockCopy(bytes, i, SimName, 0, length); i += length; + SnapshotID.FromBytes(bytes, i); i += 16; + Dwell = Utils.BytesToFloat(bytes, i); i += 4; + SalePrice = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + AuctionID = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + ParcelID.ToBytes(bytes, i); i += 16; + OwnerID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)Name.Length; + Buffer.BlockCopy(Name, 0, bytes, i, Name.Length); i += Name.Length; + bytes[i++] = (byte)Desc.Length; + Buffer.BlockCopy(Desc, 0, bytes, i, Desc.Length); i += Desc.Length; + Utils.IntToBytes(ActualArea, bytes, i); i += 4; + Utils.IntToBytes(BillableArea, bytes, i); i += 4; + bytes[i++] = Flags; + Utils.FloatToBytes(GlobalX, bytes, i); i += 4; + Utils.FloatToBytes(GlobalY, bytes, i); i += 4; + Utils.FloatToBytes(GlobalZ, bytes, i); i += 4; + bytes[i++] = (byte)SimName.Length; + Buffer.BlockCopy(SimName, 0, bytes, i, SimName.Length); i += SimName.Length; + SnapshotID.ToBytes(bytes, i); i += 16; + Utils.FloatToBytes(Dwell, bytes, i); i += 4; + Utils.IntToBytes(SalePrice, bytes, i); i += 4; + Utils.IntToBytes(AuctionID, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += Data.Length; + return length; + } + } + public AgentDataBlock AgentData; + public DataBlock Data; + + public ParcelInfoReplyPacket() + { + HasVariableBlocks = false; + Type = PacketType.ParcelInfoReply; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 55; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + Data = new DataBlock(); + } + + public ParcelInfoReplyPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + Data.FromBytes(bytes, ref i); + } + + public ParcelInfoReplyPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + Data.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += Data.Length; + if (Header.AckList != null && 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); + Data.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class ParcelObjectOwnersRequestPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class ParcelDataBlock : PacketBlock + { + public int LocalID; + + public override int Length + { + get + { + return 4; + } + } + + public ParcelDataBlock() { } + public ParcelDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + LocalID = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.IntToBytes(LocalID, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += ParcelData.Length; + return length; + } + } + public AgentDataBlock AgentData; + public ParcelDataBlock ParcelData; + + public ParcelObjectOwnersRequestPacket() + { + HasVariableBlocks = false; + Type = PacketType.ParcelObjectOwnersRequest; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 56; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + ParcelData = new ParcelDataBlock(); + } + + public ParcelObjectOwnersRequestPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + ParcelData.FromBytes(bytes, ref i); + } + + public ParcelObjectOwnersRequestPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + ParcelData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += ParcelData.Length; + if (Header.AckList != null && 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); + ParcelData.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class ParcelObjectOwnersReplyPacket : Packet + { + /// + public sealed class DataBlock : PacketBlock + { + public UUID OwnerID; + public bool IsGroupOwned; + public int Count; + public bool OnlineStatus; + + public override int Length + { + get + { + return 22; + } + } + + public DataBlock() { } + public DataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + OwnerID.FromBytes(bytes, i); i += 16; + IsGroupOwned = (bytes[i++] != 0) ? (bool)true : (bool)false; + Count = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + OnlineStatus = (bytes[i++] != 0) ? (bool)true : (bool)false; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + OwnerID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)((IsGroupOwned) ? 1 : 0); + Utils.IntToBytes(Count, bytes, i); i += 4; + bytes[i++] = (byte)((OnlineStatus) ? 1 : 0); + } + + } + + public override int Length + { + get + { + int length = 11; + for (int j = 0; j < Data.Length; j++) + length += Data[j].Length; + return length; + } + } + public DataBlock[] Data; + + public ParcelObjectOwnersReplyPacket() + { + HasVariableBlocks = true; + Type = PacketType.ParcelObjectOwnersReply; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 57; + Header.Reliable = true; + Header.Zerocoded = true; + Data = null; + } + + public ParcelObjectOwnersReplyPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + int count = (int)bytes[i++]; + if(Data == null || Data.Length != -1) { + Data = new DataBlock[count]; + for(int j = 0; j < count; j++) + { Data[j] = new DataBlock(); } + } + for (int j = 0; j < count; j++) + { Data[j].FromBytes(bytes, ref i); } + } + + public ParcelObjectOwnersReplyPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + int count = (int)bytes[i++]; + if(Data == null || Data.Length != count) { + Data = new DataBlock[count]; + for(int j = 0; j < count; j++) + { Data[j] = new DataBlock(); } + } + for (int j = 0; j < count; j++) + { Data[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length++; + for (int j = 0; j < Data.Length; j++) { length += Data[j].Length; } + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int DataStart = 0; + do + { + int variableLength = 0; + int DataCount = 0; + + i = DataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < Data.Length) { + int blockLength = Data[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == DataStart) { + variableLength += blockLength; + ++DataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)DataCount; + for (i = DataStart; i < DataStart + DataCount; i++) { Data[i].ToBytes(packet, ref length); } + DataStart += DataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + DataStart < Data.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class GroupNoticesListRequestPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class DataBlock : PacketBlock + { + public UUID GroupID; + + public override int Length + { + get + { + return 16; + } + } + + public DataBlock() { } + public DataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + GroupID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + GroupID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += Data.Length; + return length; + } + } + public AgentDataBlock AgentData; + public DataBlock Data; + + public GroupNoticesListRequestPacket() + { + HasVariableBlocks = false; + Type = PacketType.GroupNoticesListRequest; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 58; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + Data = new DataBlock(); + } + + public GroupNoticesListRequestPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + Data.FromBytes(bytes, ref i); + } + + public GroupNoticesListRequestPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + Data.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += Data.Length; + if (Header.AckList != null && 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); + Data.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class GroupNoticesListReplyPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID GroupID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + GroupID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + GroupID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class DataBlock : PacketBlock + { + public UUID NoticeID; + public uint Timestamp; + public byte[] FromName; + public byte[] Subject; + public bool HasAttachment; + public byte AssetType; + + public override int Length + { + get + { + int length = 26; + if (FromName != null) { length += FromName.Length; } + if (Subject != null) { length += Subject.Length; } + return length; + } + } + + public DataBlock() { } + public DataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + NoticeID.FromBytes(bytes, i); i += 16; + Timestamp = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + length = (bytes[i++] + (bytes[i++] << 8)); + FromName = new byte[length]; + Buffer.BlockCopy(bytes, i, FromName, 0, length); i += length; + length = (bytes[i++] + (bytes[i++] << 8)); + Subject = new byte[length]; + Buffer.BlockCopy(bytes, i, Subject, 0, length); i += length; + HasAttachment = (bytes[i++] != 0) ? (bool)true : (bool)false; + AssetType = (byte)bytes[i++]; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + NoticeID.ToBytes(bytes, i); i += 16; + Utils.UIntToBytes(Timestamp, bytes, i); i += 4; + bytes[i++] = (byte)(FromName.Length % 256); + bytes[i++] = (byte)((FromName.Length >> 8) % 256); + Buffer.BlockCopy(FromName, 0, bytes, i, FromName.Length); i += FromName.Length; + bytes[i++] = (byte)(Subject.Length % 256); + bytes[i++] = (byte)((Subject.Length >> 8) % 256); + Buffer.BlockCopy(Subject, 0, bytes, i, Subject.Length); i += Subject.Length; + bytes[i++] = (byte)((HasAttachment) ? 1 : 0); + bytes[i++] = AssetType; + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentData.Length; + for (int j = 0; j < Data.Length; j++) + length += Data[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public DataBlock[] Data; + + public GroupNoticesListReplyPacket() + { + HasVariableBlocks = true; + Type = PacketType.GroupNoticesListReply; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 59; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + Data = null; + } + + public GroupNoticesListReplyPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(Data == null || Data.Length != -1) { + Data = new DataBlock[count]; + for(int j = 0; j < count; j++) + { Data[j] = new DataBlock(); } + } + for (int j = 0; j < count; j++) + { Data[j].FromBytes(bytes, ref i); } + } + + public GroupNoticesListReplyPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(Data == null || Data.Length != count) { + Data = new DataBlock[count]; + for(int j = 0; j < count; j++) + { Data[j] = new DataBlock(); } + } + for (int j = 0; j < count; j++) + { Data[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length++; + for (int j = 0; j < Data.Length; j++) { length += Data[j].Length; } + if (Header.AckList != null && 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)Data.Length; + for (int j = 0; j < Data.Length; j++) { Data[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int DataStart = 0; + do + { + int variableLength = 0; + int DataCount = 0; + + i = DataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < Data.Length) { + int blockLength = Data[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == DataStart) { + variableLength += blockLength; + ++DataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)DataCount; + for (i = DataStart; i < DataStart + DataCount; i++) { Data[i].ToBytes(packet, ref length); } + DataStart += DataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + DataStart < Data.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class GroupNoticeRequestPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class DataBlock : PacketBlock + { + public UUID GroupNoticeID; + + public override int Length + { + get + { + return 16; + } + } + + public DataBlock() { } + public DataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + GroupNoticeID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + GroupNoticeID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += Data.Length; + return length; + } + } + public AgentDataBlock AgentData; + public DataBlock Data; + + public GroupNoticeRequestPacket() + { + HasVariableBlocks = false; + Type = PacketType.GroupNoticeRequest; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 60; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + Data = new DataBlock(); + } + + public GroupNoticeRequestPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + Data.FromBytes(bytes, ref i); + } + + public GroupNoticeRequestPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + Data.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += Data.Length; + if (Header.AckList != null && 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); + Data.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class TeleportRequestPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class InfoBlock : PacketBlock + { + public UUID RegionID; + public Vector3 Position; + public Vector3 LookAt; + + public override int Length + { + get + { + return 40; + } + } + + public InfoBlock() { } + public InfoBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + RegionID.FromBytes(bytes, i); i += 16; + Position.FromBytes(bytes, i); i += 12; + LookAt.FromBytes(bytes, i); i += 12; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + RegionID.ToBytes(bytes, i); i += 16; + Position.ToBytes(bytes, i); i += 12; + LookAt.ToBytes(bytes, i); i += 12; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += Info.Length; + return length; + } + } + public AgentDataBlock AgentData; + public InfoBlock Info; + + public TeleportRequestPacket() + { + HasVariableBlocks = false; + Type = PacketType.TeleportRequest; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 62; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + Info = new InfoBlock(); + } + + public TeleportRequestPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + Info.FromBytes(bytes, ref i); + } + + public TeleportRequestPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + Info.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += Info.Length; + if (Header.AckList != null && 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); + Info.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class TeleportLocationRequestPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class InfoBlock : PacketBlock + { + public ulong RegionHandle; + public Vector3 Position; + public Vector3 LookAt; + + public override int Length + { + get + { + return 32; + } + } + + public InfoBlock() { } + public InfoBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(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)); + Position.FromBytes(bytes, i); i += 12; + LookAt.FromBytes(bytes, i); i += 12; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UInt64ToBytes(RegionHandle, bytes, i); i += 8; + Position.ToBytes(bytes, i); i += 12; + LookAt.ToBytes(bytes, i); i += 12; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += Info.Length; + return length; + } + } + public AgentDataBlock AgentData; + public InfoBlock Info; + + public TeleportLocationRequestPacket() + { + HasVariableBlocks = false; + Type = PacketType.TeleportLocationRequest; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 63; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + Info = new InfoBlock(); + } + + public TeleportLocationRequestPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + Info.FromBytes(bytes, ref i); + } + + public TeleportLocationRequestPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + Info.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += Info.Length; + if (Header.AckList != null && 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); + Info.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class TeleportLocalPacket : Packet + { + /// + public sealed class InfoBlock : PacketBlock + { + public UUID AgentID; + public uint LocationID; + public Vector3 Position; + public Vector3 LookAt; + public uint TeleportFlags; + + public override int Length + { + get + { + return 48; + } + } + + public InfoBlock() { } + public InfoBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + LocationID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + Position.FromBytes(bytes, i); i += 12; + LookAt.FromBytes(bytes, i); i += 12; + TeleportFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + Utils.UIntToBytes(LocationID, bytes, i); i += 4; + Position.ToBytes(bytes, i); i += 12; + LookAt.ToBytes(bytes, i); i += 12; + Utils.UIntToBytes(TeleportFlags, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 10; + length += Info.Length; + return length; + } + } + public InfoBlock Info; + + public TeleportLocalPacket() + { + HasVariableBlocks = false; + Type = PacketType.TeleportLocal; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 64; + Header.Reliable = true; + Info = new InfoBlock(); + } + + public TeleportLocalPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + Info.FromBytes(bytes, ref i); + } + + public TeleportLocalPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + Info.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += Info.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class TeleportLandmarkRequestPacket : Packet + { + /// + public sealed class InfoBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + public UUID LandmarkID; + + public override int Length + { + get + { + return 48; + } + } + + public InfoBlock() { } + public InfoBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + LandmarkID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + LandmarkID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 10; + length += Info.Length; + return length; + } + } + public InfoBlock Info; + + public TeleportLandmarkRequestPacket() + { + HasVariableBlocks = false; + Type = PacketType.TeleportLandmarkRequest; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 65; + Header.Reliable = true; + Header.Zerocoded = true; + Info = new InfoBlock(); + } + + public TeleportLandmarkRequestPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + Info.FromBytes(bytes, ref i); + } + + public TeleportLandmarkRequestPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + Info.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += Info.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class TeleportProgressPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + + public override int Length + { + get + { + return 16; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class InfoBlock : PacketBlock + { + public uint TeleportFlags; + public byte[] Message; + + public override int Length + { + get + { + int length = 5; + if (Message != null) { length += Message.Length; } + return length; + } + } + + public InfoBlock() { } + public InfoBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + TeleportFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + length = bytes[i++]; + Message = new byte[length]; + Buffer.BlockCopy(bytes, i, Message, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UIntToBytes(TeleportFlags, bytes, i); i += 4; + bytes[i++] = (byte)Message.Length; + Buffer.BlockCopy(Message, 0, bytes, i, Message.Length); i += Message.Length; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += Info.Length; + return length; + } + } + public AgentDataBlock AgentData; + public InfoBlock Info; + + public TeleportProgressPacket() + { + HasVariableBlocks = false; + Type = PacketType.TeleportProgress; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 66; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + Info = new InfoBlock(); + } + + public TeleportProgressPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + Info.FromBytes(bytes, ref i); + } + + public TeleportProgressPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + Info.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += Info.Length; + if (Header.AckList != null && 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); + Info.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class TeleportFinishPacket : Packet + { + /// + public sealed class InfoBlock : PacketBlock + { + public UUID AgentID; + public uint LocationID; + public uint SimIP; + public ushort SimPort; + public ulong RegionHandle; + public byte[] SeedCapability; + public byte SimAccess; + public uint TeleportFlags; + + public override int Length + { + get + { + int length = 41; + if (SeedCapability != null) { length += SeedCapability.Length; } + return length; + } + } + + public InfoBlock() { } + public InfoBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + AgentID.FromBytes(bytes, i); i += 16; + LocationID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + SimIP = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + 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)); + length = (bytes[i++] + (bytes[i++] << 8)); + SeedCapability = new byte[length]; + Buffer.BlockCopy(bytes, i, SeedCapability, 0, length); i += length; + SimAccess = (byte)bytes[i++]; + TeleportFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + Utils.UIntToBytes(LocationID, bytes, i); i += 4; + Utils.UIntToBytes(SimIP, bytes, i); i += 4; + bytes[i++] = (byte)((SimPort >> 8) % 256); + bytes[i++] = (byte)(SimPort % 256); + Utils.UInt64ToBytes(RegionHandle, bytes, i); i += 8; + bytes[i++] = (byte)(SeedCapability.Length % 256); + bytes[i++] = (byte)((SeedCapability.Length >> 8) % 256); + Buffer.BlockCopy(SeedCapability, 0, bytes, i, SeedCapability.Length); i += SeedCapability.Length; + bytes[i++] = SimAccess; + Utils.UIntToBytes(TeleportFlags, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 10; + length += Info.Length; + return length; + } + } + public InfoBlock Info; + + public TeleportFinishPacket() + { + HasVariableBlocks = false; + Type = PacketType.TeleportFinish; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 69; + Header.Reliable = true; + Info = new InfoBlock(); + } + + public TeleportFinishPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + Info.FromBytes(bytes, ref i); + } + + public TeleportFinishPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + Info.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += Info.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class StartLurePacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class InfoBlock : PacketBlock + { + public byte LureType; + public byte[] Message; + + public override int Length + { + get + { + int length = 2; + if (Message != null) { length += Message.Length; } + return length; + } + } + + public InfoBlock() { } + public InfoBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + LureType = (byte)bytes[i++]; + length = bytes[i++]; + Message = new byte[length]; + Buffer.BlockCopy(bytes, i, Message, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + bytes[i++] = LureType; + bytes[i++] = (byte)Message.Length; + Buffer.BlockCopy(Message, 0, bytes, i, Message.Length); i += Message.Length; + } + + } + + /// + public sealed class TargetDataBlock : PacketBlock + { + public UUID TargetID; + + public override int Length + { + get + { + return 16; + } + } + + public TargetDataBlock() { } + public TargetDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + TargetID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + TargetID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentData.Length; + length += Info.Length; + for (int j = 0; j < TargetData.Length; j++) + length += TargetData[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public InfoBlock Info; + public TargetDataBlock[] TargetData; + + public StartLurePacket() + { + HasVariableBlocks = true; + Type = PacketType.StartLure; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 70; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + Info = new InfoBlock(); + TargetData = null; + } + + public StartLurePacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + Info.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(TargetData == null || TargetData.Length != -1) { + TargetData = new TargetDataBlock[count]; + for(int j = 0; j < count; j++) + { TargetData[j] = new TargetDataBlock(); } + } + for (int j = 0; j < count; j++) + { TargetData[j].FromBytes(bytes, ref i); } + } + + public StartLurePacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + Info.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(TargetData == null || TargetData.Length != count) { + TargetData = new TargetDataBlock[count]; + for(int j = 0; j < count; j++) + { TargetData[j] = new TargetDataBlock(); } + } + for (int j = 0; j < count; j++) + { TargetData[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += Info.Length; + length++; + for (int j = 0; j < TargetData.Length; j++) { length += TargetData[j].Length; } + if (Header.AckList != null && 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); + Info.ToBytes(bytes, ref i); + bytes[i++] = (byte)TargetData.Length; + for (int j = 0; j < TargetData.Length; j++) { TargetData[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + fixedLength += Info.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + Info.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int TargetDataStart = 0; + do + { + int variableLength = 0; + int TargetDataCount = 0; + + i = TargetDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < TargetData.Length) { + int blockLength = TargetData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == TargetDataStart) { + variableLength += blockLength; + ++TargetDataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)TargetDataCount; + for (i = TargetDataStart; i < TargetDataStart + TargetDataCount; i++) { TargetData[i].ToBytes(packet, ref length); } + TargetDataStart += TargetDataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + TargetDataStart < TargetData.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class TeleportLureRequestPacket : Packet + { + /// + public sealed class InfoBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + public UUID LureID; + public uint TeleportFlags; + + public override int Length + { + get + { + return 52; + } + } + + public InfoBlock() { } + public InfoBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + LureID.FromBytes(bytes, i); i += 16; + TeleportFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + LureID.ToBytes(bytes, i); i += 16; + Utils.UIntToBytes(TeleportFlags, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 10; + length += Info.Length; + return length; + } + } + public InfoBlock Info; + + public TeleportLureRequestPacket() + { + HasVariableBlocks = false; + Type = PacketType.TeleportLureRequest; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 71; + Header.Reliable = true; + Info = new InfoBlock(); + } + + public TeleportLureRequestPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + Info.FromBytes(bytes, ref i); + } + + public TeleportLureRequestPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + Info.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += Info.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class TeleportCancelPacket : Packet + { + /// + public sealed class InfoBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public InfoBlock() { } + public InfoBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 10; + length += Info.Length; + return length; + } + } + public InfoBlock Info; + + public TeleportCancelPacket() + { + HasVariableBlocks = false; + Type = PacketType.TeleportCancel; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 72; + Header.Reliable = true; + Info = new InfoBlock(); + } + + public TeleportCancelPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + Info.FromBytes(bytes, ref i); + } + + public TeleportCancelPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + Info.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += Info.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class TeleportStartPacket : Packet + { + /// + public sealed class InfoBlock : PacketBlock + { + public uint TeleportFlags; + + public override int Length + { + get + { + return 4; + } + } + + public InfoBlock() { } + public InfoBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + TeleportFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UIntToBytes(TeleportFlags, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 10; + length += Info.Length; + return length; + } + } + public InfoBlock Info; + + public TeleportStartPacket() + { + HasVariableBlocks = false; + Type = PacketType.TeleportStart; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 73; + Header.Reliable = true; + Info = new InfoBlock(); + } + + public TeleportStartPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + Info.FromBytes(bytes, ref i); + } + + public TeleportStartPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + Info.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += Info.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class TeleportFailedPacket : Packet + { + /// + public sealed class InfoBlock : PacketBlock + { + public UUID AgentID; + public byte[] Reason; + + public override int Length + { + get + { + int length = 17; + if (Reason != null) { length += Reason.Length; } + return length; + } + } + + public InfoBlock() { } + public InfoBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + AgentID.FromBytes(bytes, i); i += 16; + length = bytes[i++]; + Reason = new byte[length]; + Buffer.BlockCopy(bytes, i, Reason, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)Reason.Length; + Buffer.BlockCopy(Reason, 0, bytes, i, Reason.Length); i += Reason.Length; + } + + } + + /// + public sealed class AlertInfoBlock : PacketBlock + { + public byte[] Message; + public byte[] ExtraParams; + + public override int Length + { + get + { + int length = 2; + if (Message != null) { length += Message.Length; } + if (ExtraParams != null) { length += ExtraParams.Length; } + return length; + } + } + + public AlertInfoBlock() { } + public AlertInfoBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + length = bytes[i++]; + Message = new byte[length]; + Buffer.BlockCopy(bytes, i, Message, 0, length); i += length; + length = bytes[i++]; + ExtraParams = new byte[length]; + Buffer.BlockCopy(bytes, i, ExtraParams, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + bytes[i++] = (byte)Message.Length; + Buffer.BlockCopy(Message, 0, bytes, i, Message.Length); i += Message.Length; + bytes[i++] = (byte)ExtraParams.Length; + Buffer.BlockCopy(ExtraParams, 0, bytes, i, ExtraParams.Length); i += ExtraParams.Length; + } + + } + + public override int Length + { + get + { + int length = 11; + length += Info.Length; + for (int j = 0; j < AlertInfo.Length; j++) + length += AlertInfo[j].Length; + return length; + } + } + public InfoBlock Info; + public AlertInfoBlock[] AlertInfo; + + public TeleportFailedPacket() + { + HasVariableBlocks = true; + Type = PacketType.TeleportFailed; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 74; + Header.Reliable = true; + Info = new InfoBlock(); + AlertInfo = null; + } + + public TeleportFailedPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + Info.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(AlertInfo == null || AlertInfo.Length != -1) { + AlertInfo = new AlertInfoBlock[count]; + for(int j = 0; j < count; j++) + { AlertInfo[j] = new AlertInfoBlock(); } + } + for (int j = 0; j < count; j++) + { AlertInfo[j].FromBytes(bytes, ref i); } + } + + public TeleportFailedPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + Info.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(AlertInfo == null || AlertInfo.Length != count) { + AlertInfo = new AlertInfoBlock[count]; + for(int j = 0; j < count; j++) + { AlertInfo[j] = new AlertInfoBlock(); } + } + for (int j = 0; j < count; j++) + { AlertInfo[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += Info.Length; + length++; + for (int j = 0; j < AlertInfo.Length; j++) { length += AlertInfo[j].Length; } + if (Header.AckList != null && 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); + bytes[i++] = (byte)AlertInfo.Length; + for (int j = 0; j < AlertInfo.Length; j++) { AlertInfo[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += Info.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + Info.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int AlertInfoStart = 0; + do + { + int variableLength = 0; + int AlertInfoCount = 0; + + i = AlertInfoStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < AlertInfo.Length) { + int blockLength = AlertInfo[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == AlertInfoStart) { + variableLength += blockLength; + ++AlertInfoCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)AlertInfoCount; + for (i = AlertInfoStart; i < AlertInfoStart + AlertInfoCount; i++) { AlertInfo[i].ToBytes(packet, ref length); } + AlertInfoStart += AlertInfoCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + AlertInfoStart < AlertInfo.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class UndoPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + public UUID GroupID; + + public override int Length + { + get + { + return 48; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + GroupID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + GroupID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class ObjectDataBlock : PacketBlock + { + public UUID ObjectID; + + public override int Length + { + get + { + return 16; + } + } + + public ObjectDataBlock() { } + public ObjectDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + ObjectID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + ObjectID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentData.Length; + for (int j = 0; j < ObjectData.Length; j++) + length += ObjectData[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public ObjectDataBlock[] ObjectData; + + public UndoPacket() + { + HasVariableBlocks = true; + Type = PacketType.Undo; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 75; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + ObjectData = null; + } + + public UndoPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ObjectData == null || ObjectData.Length != -1) { + ObjectData = new ObjectDataBlock[count]; + for(int j = 0; j < count; j++) + { ObjectData[j] = new ObjectDataBlock(); } + } + for (int j = 0; j < count; j++) + { ObjectData[j].FromBytes(bytes, ref i); } + } + + public UndoPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ObjectData == null || ObjectData.Length != count) { + ObjectData = new ObjectDataBlock[count]; + for(int j = 0; j < count; j++) + { ObjectData[j] = new ObjectDataBlock(); } + } + for (int j = 0; j < count; j++) + { ObjectData[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length++; + for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } + if (Header.AckList != null && 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)ObjectData.Length; + for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int ObjectDataStart = 0; + do + { + int variableLength = 0; + int ObjectDataCount = 0; + + i = ObjectDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < ObjectData.Length) { + int blockLength = ObjectData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ObjectDataStart) { + variableLength += blockLength; + ++ObjectDataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)ObjectDataCount; + for (i = ObjectDataStart; i < ObjectDataStart + ObjectDataCount; i++) { ObjectData[i].ToBytes(packet, ref length); } + ObjectDataStart += ObjectDataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + ObjectDataStart < ObjectData.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class RedoPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + public UUID GroupID; + + public override int Length + { + get + { + return 48; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + GroupID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + GroupID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class ObjectDataBlock : PacketBlock + { + public UUID ObjectID; + + public override int Length + { + get + { + return 16; + } + } + + public ObjectDataBlock() { } + public ObjectDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + ObjectID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + ObjectID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentData.Length; + for (int j = 0; j < ObjectData.Length; j++) + length += ObjectData[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public ObjectDataBlock[] ObjectData; + + public RedoPacket() + { + HasVariableBlocks = true; + Type = PacketType.Redo; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 76; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + ObjectData = null; + } + + public RedoPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ObjectData == null || ObjectData.Length != -1) { + ObjectData = new ObjectDataBlock[count]; + for(int j = 0; j < count; j++) + { ObjectData[j] = new ObjectDataBlock(); } + } + for (int j = 0; j < count; j++) + { ObjectData[j].FromBytes(bytes, ref i); } + } + + public RedoPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ObjectData == null || ObjectData.Length != count) { + ObjectData = new ObjectDataBlock[count]; + for(int j = 0; j < count; j++) + { ObjectData[j] = new ObjectDataBlock(); } + } + for (int j = 0; j < count; j++) + { ObjectData[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length++; + for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } + if (Header.AckList != null && 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)ObjectData.Length; + for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int ObjectDataStart = 0; + do + { + int variableLength = 0; + int ObjectDataCount = 0; + + i = ObjectDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < ObjectData.Length) { + int blockLength = ObjectData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ObjectDataStart) { + variableLength += blockLength; + ++ObjectDataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)ObjectDataCount; + for (i = ObjectDataStart; i < ObjectDataStart + ObjectDataCount; i++) { ObjectData[i].ToBytes(packet, ref length); } + ObjectDataStart += ObjectDataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + ObjectDataStart < ObjectData.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class UndoLandPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + return length; + } + } + public AgentDataBlock AgentData; + + public UndoLandPacket() + { + HasVariableBlocks = false; + Type = PacketType.UndoLand; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 77; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + } + + public UndoLandPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + } + + public UndoLandPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class AgentPausePacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + public uint SerialNum; + + public override int Length + { + get + { + return 36; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + SerialNum = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + Utils.UIntToBytes(SerialNum, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + return length; + } + } + public AgentDataBlock AgentData; + + public AgentPausePacket() + { + HasVariableBlocks = false; + Type = PacketType.AgentPause; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 78; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + } + + public AgentPausePacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + } + + public AgentPausePacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class AgentResumePacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + public uint SerialNum; + + public override int Length + { + get + { + return 36; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + SerialNum = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + Utils.UIntToBytes(SerialNum, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + return length; + } + } + public AgentDataBlock AgentData; + + public AgentResumePacket() + { + HasVariableBlocks = false; + Type = PacketType.AgentResume; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 79; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + } + + public AgentResumePacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + } + + public AgentResumePacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class ChatFromViewerPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class ChatDataBlock : PacketBlock + { + public byte[] Message; + public byte Type; + public int Channel; + + public override int Length + { + get + { + int length = 7; + if (Message != null) { length += Message.Length; } + return length; + } + } + + public ChatDataBlock() { } + public ChatDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + length = (bytes[i++] + (bytes[i++] << 8)); + Message = new byte[length]; + Buffer.BlockCopy(bytes, i, Message, 0, length); i += length; + Type = (byte)bytes[i++]; + Channel = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + bytes[i++] = (byte)(Message.Length % 256); + bytes[i++] = (byte)((Message.Length >> 8) % 256); + Buffer.BlockCopy(Message, 0, bytes, i, Message.Length); i += Message.Length; + bytes[i++] = Type; + Utils.IntToBytes(Channel, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += ChatData.Length; + return length; + } + } + public AgentDataBlock AgentData; + public ChatDataBlock ChatData; + + public ChatFromViewerPacket() + { + HasVariableBlocks = false; + Type = PacketType.ChatFromViewer; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 80; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + ChatData = new ChatDataBlock(); + } + + public ChatFromViewerPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + ChatData.FromBytes(bytes, ref i); + } + + public ChatFromViewerPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + ChatData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += ChatData.Length; + if (Header.AckList != null && 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); + ChatData.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class AgentThrottlePacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + public uint CircuitCode; + + public override int Length + { + get + { + return 36; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + CircuitCode = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + Utils.UIntToBytes(CircuitCode, bytes, i); i += 4; + } + + } + + /// + public sealed class ThrottleBlock : PacketBlock + { + public uint GenCounter; + public byte[] Throttles; + + public override int Length + { + get + { + int length = 5; + if (Throttles != null) { length += Throttles.Length; } + return length; + } + } + + public ThrottleBlock() { } + public ThrottleBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + GenCounter = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + length = bytes[i++]; + Throttles = new byte[length]; + Buffer.BlockCopy(bytes, i, Throttles, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UIntToBytes(GenCounter, bytes, i); i += 4; + bytes[i++] = (byte)Throttles.Length; + Buffer.BlockCopy(Throttles, 0, bytes, i, Throttles.Length); i += Throttles.Length; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += Throttle.Length; + return length; + } + } + public AgentDataBlock AgentData; + public ThrottleBlock Throttle; + + public AgentThrottlePacket() + { + HasVariableBlocks = false; + Type = PacketType.AgentThrottle; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 81; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + Throttle = new ThrottleBlock(); + } + + public AgentThrottlePacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + Throttle.FromBytes(bytes, ref i); + } + + public AgentThrottlePacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + Throttle.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += Throttle.Length; + if (Header.AckList != null && 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); + Throttle.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class AgentFOVPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + public uint CircuitCode; + + public override int Length + { + get + { + return 36; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + CircuitCode = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + Utils.UIntToBytes(CircuitCode, bytes, i); i += 4; + } + + } + + /// + public sealed class FOVBlockBlock : PacketBlock + { + public uint GenCounter; + public float VerticalAngle; + + public override int Length + { + get + { + return 8; + } + } + + public FOVBlockBlock() { } + public FOVBlockBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + GenCounter = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + VerticalAngle = Utils.BytesToFloat(bytes, i); i += 4; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UIntToBytes(GenCounter, bytes, i); i += 4; + Utils.FloatToBytes(VerticalAngle, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += FOVBlock.Length; + return length; + } + } + public AgentDataBlock AgentData; + public FOVBlockBlock FOVBlock; + + public AgentFOVPacket() + { + HasVariableBlocks = false; + Type = PacketType.AgentFOV; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 82; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + FOVBlock = new FOVBlockBlock(); + } + + public AgentFOVPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + FOVBlock.FromBytes(bytes, ref i); + } + + public AgentFOVPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + FOVBlock.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += FOVBlock.Length; + if (Header.AckList != null && 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); + FOVBlock.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class AgentHeightWidthPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + public uint CircuitCode; + + public override int Length + { + get + { + return 36; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + CircuitCode = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + Utils.UIntToBytes(CircuitCode, bytes, i); i += 4; + } + + } + + /// + public sealed class HeightWidthBlockBlock : PacketBlock + { + public uint GenCounter; + public ushort Height; + public ushort Width; + + public override int Length + { + get + { + return 8; + } + } + + public HeightWidthBlockBlock() { } + public HeightWidthBlockBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(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(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UIntToBytes(GenCounter, bytes, i); i += 4; + bytes[i++] = (byte)(Height % 256); + bytes[i++] = (byte)((Height >> 8) % 256); + bytes[i++] = (byte)(Width % 256); + bytes[i++] = (byte)((Width >> 8) % 256); + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += HeightWidthBlock.Length; + return length; + } + } + public AgentDataBlock AgentData; + public HeightWidthBlockBlock HeightWidthBlock; + + public AgentHeightWidthPacket() + { + HasVariableBlocks = false; + Type = PacketType.AgentHeightWidth; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 83; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + HeightWidthBlock = new HeightWidthBlockBlock(); + } + + public AgentHeightWidthPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + HeightWidthBlock.FromBytes(bytes, ref i); + } + + public AgentHeightWidthPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + HeightWidthBlock.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += HeightWidthBlock.Length; + if (Header.AckList != null && 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); + HeightWidthBlock.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class AgentSetAppearancePacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + public uint SerialNum; + public Vector3 Size; + + public override int Length + { + get + { + return 48; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + SerialNum = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + Size.FromBytes(bytes, i); i += 12; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + Utils.UIntToBytes(SerialNum, bytes, i); i += 4; + Size.ToBytes(bytes, i); i += 12; + } + + } + + /// + public sealed class WearableDataBlock : PacketBlock + { + public UUID CacheID; + public byte TextureIndex; + + public override int Length + { + get + { + return 17; + } + } + + public WearableDataBlock() { } + public WearableDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + CacheID.FromBytes(bytes, i); i += 16; + TextureIndex = (byte)bytes[i++]; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + CacheID.ToBytes(bytes, i); i += 16; + bytes[i++] = TextureIndex; + } + + } + + /// + public sealed class ObjectDataBlock : PacketBlock + { + public byte[] TextureEntry; + + public override int Length + { + get + { + int length = 2; + if (TextureEntry != null) { length += TextureEntry.Length; } + return length; + } + } + + public ObjectDataBlock() { } + public ObjectDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + length = (bytes[i++] + (bytes[i++] << 8)); + TextureEntry = new byte[length]; + Buffer.BlockCopy(bytes, i, TextureEntry, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + bytes[i++] = (byte)(TextureEntry.Length % 256); + bytes[i++] = (byte)((TextureEntry.Length >> 8) % 256); + Buffer.BlockCopy(TextureEntry, 0, bytes, i, TextureEntry.Length); i += TextureEntry.Length; + } + + } + + /// + public sealed class VisualParamBlock : PacketBlock + { + public byte ParamValue; + + public override int Length + { + get + { + return 1; + } + } + + public VisualParamBlock() { } + public VisualParamBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + ParamValue = (byte)bytes[i++]; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + bytes[i++] = ParamValue; + } + + } + + public override int Length + { + get + { + int length = 12; + length += AgentData.Length; + for (int j = 0; j < WearableData.Length; j++) + length += WearableData[j].Length; + length += ObjectData.Length; + for (int j = 0; j < VisualParam.Length; j++) + length += VisualParam[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public WearableDataBlock[] WearableData; + public ObjectDataBlock ObjectData; + public VisualParamBlock[] VisualParam; + + public AgentSetAppearancePacket() + { + HasVariableBlocks = true; + Type = PacketType.AgentSetAppearance; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 84; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + WearableData = null; + ObjectData = new ObjectDataBlock(); + VisualParam = null; + } + + public AgentSetAppearancePacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(WearableData == null || WearableData.Length != -1) { + WearableData = new WearableDataBlock[count]; + for(int j = 0; j < count; j++) + { WearableData[j] = new WearableDataBlock(); } + } + for (int j = 0; j < count; j++) + { WearableData[j].FromBytes(bytes, ref i); } + ObjectData.FromBytes(bytes, ref i); + count = (int)bytes[i++]; + if(VisualParam == null || VisualParam.Length != -1) { + VisualParam = new VisualParamBlock[count]; + for(int j = 0; j < count; j++) + { VisualParam[j] = new VisualParamBlock(); } + } + for (int j = 0; j < count; j++) + { VisualParam[j].FromBytes(bytes, ref i); } + } + + public AgentSetAppearancePacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(WearableData == null || WearableData.Length != count) { + WearableData = new WearableDataBlock[count]; + for(int j = 0; j < count; j++) + { WearableData[j] = new WearableDataBlock(); } + } + for (int j = 0; j < count; j++) + { WearableData[j].FromBytes(bytes, ref i); } + ObjectData.FromBytes(bytes, ref i); + count = (int)bytes[i++]; + if(VisualParam == null || VisualParam.Length != count) { + VisualParam = new VisualParamBlock[count]; + for(int j = 0; j < count; j++) + { VisualParam[j] = new VisualParamBlock(); } + } + for (int j = 0; j < count; j++) + { VisualParam[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += ObjectData.Length; + length++; + for (int j = 0; j < WearableData.Length; j++) { length += WearableData[j].Length; } + length++; + for (int j = 0; j < VisualParam.Length; j++) { length += VisualParam[j].Length; } + if (Header.AckList != null && 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)WearableData.Length; + for (int j = 0; j < WearableData.Length; j++) { WearableData[j].ToBytes(bytes, ref i); } + ObjectData.ToBytes(bytes, ref i); + bytes[i++] = (byte)VisualParam.Length; + for (int j = 0; j < VisualParam.Length; j++) { VisualParam[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class AgentQuitCopyPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class FuseBlockBlock : PacketBlock + { + public uint ViewerCircuitCode; + + public override int Length + { + get + { + return 4; + } + } + + public FuseBlockBlock() { } + public FuseBlockBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + ViewerCircuitCode = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UIntToBytes(ViewerCircuitCode, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += FuseBlock.Length; + return length; + } + } + public AgentDataBlock AgentData; + public FuseBlockBlock FuseBlock; + + public AgentQuitCopyPacket() + { + HasVariableBlocks = false; + Type = PacketType.AgentQuitCopy; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 85; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + FuseBlock = new FuseBlockBlock(); + } + + public AgentQuitCopyPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + FuseBlock.FromBytes(bytes, ref i); + } + + public AgentQuitCopyPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + FuseBlock.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += FuseBlock.Length; + if (Header.AckList != null && 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); + FuseBlock.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class ImageNotInDatabasePacket : Packet + { + /// + public sealed class ImageIDBlock : PacketBlock + { + public UUID ID; + + public override int Length + { + get + { + return 16; + } + } + + public ImageIDBlock() { } + public ImageIDBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + ID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + ID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 10; + length += ImageID.Length; + return length; + } + } + public ImageIDBlock ImageID; + + public ImageNotInDatabasePacket() + { + HasVariableBlocks = false; + Type = PacketType.ImageNotInDatabase; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 86; + Header.Reliable = true; + ImageID = new ImageIDBlock(); + } + + public ImageNotInDatabasePacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + ImageID.FromBytes(bytes, ref i); + } + + public ImageNotInDatabasePacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + ImageID.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += ImageID.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class RebakeAvatarTexturesPacket : Packet + { + /// + public sealed class TextureDataBlock : PacketBlock + { + public UUID TextureID; + + public override int Length + { + get + { + return 16; + } + } + + public TextureDataBlock() { } + public TextureDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + TextureID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + TextureID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 10; + length += TextureData.Length; + return length; + } + } + public TextureDataBlock TextureData; + + public RebakeAvatarTexturesPacket() + { + HasVariableBlocks = false; + Type = PacketType.RebakeAvatarTextures; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 87; + Header.Reliable = true; + TextureData = new TextureDataBlock(); + } + + public RebakeAvatarTexturesPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + TextureData.FromBytes(bytes, ref i); + } + + public RebakeAvatarTexturesPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + TextureData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += TextureData.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class SetAlwaysRunPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + public bool AlwaysRun; + + public override int Length + { + get + { + return 33; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + AlwaysRun = (bytes[i++] != 0) ? (bool)true : (bool)false; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)((AlwaysRun) ? 1 : 0); + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + return length; + } + } + public AgentDataBlock AgentData; + + public SetAlwaysRunPacket() + { + HasVariableBlocks = false; + Type = PacketType.SetAlwaysRun; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 88; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + } + + public SetAlwaysRunPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + } + + public SetAlwaysRunPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class ObjectDeletePacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + public bool Force; + + public override int Length + { + get + { + return 33; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + Force = (bytes[i++] != 0) ? (bool)true : (bool)false; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)((Force) ? 1 : 0); + } + + } + + /// + public sealed class ObjectDataBlock : PacketBlock + { + public uint ObjectLocalID; + + public override int Length + { + get + { + return 4; + } + } + + public ObjectDataBlock() { } + public ObjectDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + ObjectLocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UIntToBytes(ObjectLocalID, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentData.Length; + for (int j = 0; j < ObjectData.Length; j++) + length += ObjectData[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public ObjectDataBlock[] ObjectData; + + public ObjectDeletePacket() + { + HasVariableBlocks = true; + Type = PacketType.ObjectDelete; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 89; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + ObjectData = null; + } + + public ObjectDeletePacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ObjectData == null || ObjectData.Length != -1) { + ObjectData = new ObjectDataBlock[count]; + for(int j = 0; j < count; j++) + { ObjectData[j] = new ObjectDataBlock(); } + } + for (int j = 0; j < count; j++) + { ObjectData[j].FromBytes(bytes, ref i); } + } + + public ObjectDeletePacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ObjectData == null || ObjectData.Length != count) { + ObjectData = new ObjectDataBlock[count]; + for(int j = 0; j < count; j++) + { ObjectData[j] = new ObjectDataBlock(); } + } + for (int j = 0; j < count; j++) + { ObjectData[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length++; + for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } + if (Header.AckList != null && 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)ObjectData.Length; + for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int ObjectDataStart = 0; + do + { + int variableLength = 0; + int ObjectDataCount = 0; + + i = ObjectDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < ObjectData.Length) { + int blockLength = ObjectData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ObjectDataStart) { + variableLength += blockLength; + ++ObjectDataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)ObjectDataCount; + for (i = ObjectDataStart; i < ObjectDataStart + ObjectDataCount; i++) { ObjectData[i].ToBytes(packet, ref length); } + ObjectDataStart += ObjectDataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + ObjectDataStart < ObjectData.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class ObjectDuplicatePacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + public UUID GroupID; + + public override int Length + { + get + { + return 48; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + GroupID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + GroupID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class SharedDataBlock : PacketBlock + { + public Vector3 Offset; + public uint DuplicateFlags; + + public override int Length + { + get + { + return 16; + } + } + + public SharedDataBlock() { } + public SharedDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + Offset.FromBytes(bytes, i); i += 12; + DuplicateFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Offset.ToBytes(bytes, i); i += 12; + Utils.UIntToBytes(DuplicateFlags, bytes, i); i += 4; + } + + } + + /// + public sealed class ObjectDataBlock : PacketBlock + { + public uint ObjectLocalID; + + public override int Length + { + get + { + return 4; + } + } + + public ObjectDataBlock() { } + public ObjectDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + ObjectLocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UIntToBytes(ObjectLocalID, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentData.Length; + length += SharedData.Length; + for (int j = 0; j < ObjectData.Length; j++) + length += ObjectData[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public SharedDataBlock SharedData; + public ObjectDataBlock[] ObjectData; + + public ObjectDuplicatePacket() + { + HasVariableBlocks = true; + Type = PacketType.ObjectDuplicate; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 90; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + SharedData = new SharedDataBlock(); + ObjectData = null; + } + + public ObjectDuplicatePacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + SharedData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ObjectData == null || ObjectData.Length != -1) { + ObjectData = new ObjectDataBlock[count]; + for(int j = 0; j < count; j++) + { ObjectData[j] = new ObjectDataBlock(); } + } + for (int j = 0; j < count; j++) + { ObjectData[j].FromBytes(bytes, ref i); } + } + + public ObjectDuplicatePacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + SharedData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ObjectData == null || ObjectData.Length != count) { + ObjectData = new ObjectDataBlock[count]; + for(int j = 0; j < count; j++) + { ObjectData[j] = new ObjectDataBlock(); } + } + for (int j = 0; j < count; j++) + { ObjectData[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += SharedData.Length; + length++; + for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } + if (Header.AckList != null && 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); + SharedData.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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + fixedLength += SharedData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + SharedData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int ObjectDataStart = 0; + do + { + int variableLength = 0; + int ObjectDataCount = 0; + + i = ObjectDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < ObjectData.Length) { + int blockLength = ObjectData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ObjectDataStart) { + variableLength += blockLength; + ++ObjectDataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)ObjectDataCount; + for (i = ObjectDataStart; i < ObjectDataStart + ObjectDataCount; i++) { ObjectData[i].ToBytes(packet, ref length); } + ObjectDataStart += ObjectDataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + ObjectDataStart < ObjectData.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class ObjectDuplicateOnRayPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + public UUID GroupID; + public Vector3 RayStart; + public Vector3 RayEnd; + public bool BypassRaycast; + public bool RayEndIsIntersection; + public bool CopyCenters; + public bool CopyRotates; + public UUID RayTargetID; + public uint DuplicateFlags; + + public override int Length + { + get + { + return 96; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + GroupID.FromBytes(bytes, i); i += 16; + RayStart.FromBytes(bytes, i); i += 12; + RayEnd.FromBytes(bytes, i); i += 12; + BypassRaycast = (bytes[i++] != 0) ? (bool)true : (bool)false; + RayEndIsIntersection = (bytes[i++] != 0) ? (bool)true : (bool)false; + CopyCenters = (bytes[i++] != 0) ? (bool)true : (bool)false; + CopyRotates = (bytes[i++] != 0) ? (bool)true : (bool)false; + RayTargetID.FromBytes(bytes, i); i += 16; + DuplicateFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + GroupID.ToBytes(bytes, i); i += 16; + RayStart.ToBytes(bytes, i); i += 12; + RayEnd.ToBytes(bytes, i); i += 12; + bytes[i++] = (byte)((BypassRaycast) ? 1 : 0); + bytes[i++] = (byte)((RayEndIsIntersection) ? 1 : 0); + bytes[i++] = (byte)((CopyCenters) ? 1 : 0); + bytes[i++] = (byte)((CopyRotates) ? 1 : 0); + RayTargetID.ToBytes(bytes, i); i += 16; + Utils.UIntToBytes(DuplicateFlags, bytes, i); i += 4; + } + + } + + /// + public sealed class ObjectDataBlock : PacketBlock + { + public uint ObjectLocalID; + + public override int Length + { + get + { + return 4; + } + } + + public ObjectDataBlock() { } + public ObjectDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + ObjectLocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UIntToBytes(ObjectLocalID, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentData.Length; + for (int j = 0; j < ObjectData.Length; j++) + length += ObjectData[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public ObjectDataBlock[] ObjectData; + + public ObjectDuplicateOnRayPacket() + { + HasVariableBlocks = true; + Type = PacketType.ObjectDuplicateOnRay; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 91; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + ObjectData = null; + } + + public ObjectDuplicateOnRayPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ObjectData == null || ObjectData.Length != -1) { + ObjectData = new ObjectDataBlock[count]; + for(int j = 0; j < count; j++) + { ObjectData[j] = new ObjectDataBlock(); } + } + for (int j = 0; j < count; j++) + { ObjectData[j].FromBytes(bytes, ref i); } + } + + public ObjectDuplicateOnRayPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ObjectData == null || ObjectData.Length != count) { + ObjectData = new ObjectDataBlock[count]; + for(int j = 0; j < count; j++) + { ObjectData[j] = new ObjectDataBlock(); } + } + for (int j = 0; j < count; j++) + { ObjectData[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length++; + for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } + if (Header.AckList != null && 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)ObjectData.Length; + for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int ObjectDataStart = 0; + do + { + int variableLength = 0; + int ObjectDataCount = 0; + + i = ObjectDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < ObjectData.Length) { + int blockLength = ObjectData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ObjectDataStart) { + variableLength += blockLength; + ++ObjectDataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)ObjectDataCount; + for (i = ObjectDataStart; i < ObjectDataStart + ObjectDataCount; i++) { ObjectData[i].ToBytes(packet, ref length); } + ObjectDataStart += ObjectDataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + ObjectDataStart < ObjectData.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class ObjectScalePacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class ObjectDataBlock : PacketBlock + { + public uint ObjectLocalID; + public Vector3 Scale; + + public override int Length + { + get + { + return 16; + } + } + + public ObjectDataBlock() { } + public ObjectDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + ObjectLocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + Scale.FromBytes(bytes, i); i += 12; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UIntToBytes(ObjectLocalID, bytes, i); i += 4; + Scale.ToBytes(bytes, i); i += 12; + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentData.Length; + for (int j = 0; j < ObjectData.Length; j++) + length += ObjectData[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public ObjectDataBlock[] ObjectData; + + public ObjectScalePacket() + { + HasVariableBlocks = true; + Type = PacketType.ObjectScale; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 92; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + ObjectData = null; + } + + public ObjectScalePacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ObjectData == null || ObjectData.Length != -1) { + ObjectData = new ObjectDataBlock[count]; + for(int j = 0; j < count; j++) + { ObjectData[j] = new ObjectDataBlock(); } + } + for (int j = 0; j < count; j++) + { ObjectData[j].FromBytes(bytes, ref i); } + } + + public ObjectScalePacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ObjectData == null || ObjectData.Length != count) { + ObjectData = new ObjectDataBlock[count]; + for(int j = 0; j < count; j++) + { ObjectData[j] = new ObjectDataBlock(); } + } + for (int j = 0; j < count; j++) + { ObjectData[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length++; + for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } + if (Header.AckList != null && 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)ObjectData.Length; + for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int ObjectDataStart = 0; + do + { + int variableLength = 0; + int ObjectDataCount = 0; + + i = ObjectDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < ObjectData.Length) { + int blockLength = ObjectData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ObjectDataStart) { + variableLength += blockLength; + ++ObjectDataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)ObjectDataCount; + for (i = ObjectDataStart; i < ObjectDataStart + ObjectDataCount; i++) { ObjectData[i].ToBytes(packet, ref length); } + ObjectDataStart += ObjectDataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + ObjectDataStart < ObjectData.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class ObjectRotationPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class ObjectDataBlock : PacketBlock + { + public uint ObjectLocalID; + public Quaternion Rotation; + + public override int Length + { + get + { + return 16; + } + } + + public ObjectDataBlock() { } + public ObjectDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + ObjectLocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + Rotation.FromBytes(bytes, i, true); i += 12; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UIntToBytes(ObjectLocalID, bytes, i); i += 4; + Rotation.ToBytes(bytes, i); i += 12; + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentData.Length; + for (int j = 0; j < ObjectData.Length; j++) + length += ObjectData[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public ObjectDataBlock[] ObjectData; + + public ObjectRotationPacket() + { + HasVariableBlocks = true; + Type = PacketType.ObjectRotation; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 93; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + ObjectData = null; + } + + public ObjectRotationPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ObjectData == null || ObjectData.Length != -1) { + ObjectData = new ObjectDataBlock[count]; + for(int j = 0; j < count; j++) + { ObjectData[j] = new ObjectDataBlock(); } + } + for (int j = 0; j < count; j++) + { ObjectData[j].FromBytes(bytes, ref i); } + } + + public ObjectRotationPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ObjectData == null || ObjectData.Length != count) { + ObjectData = new ObjectDataBlock[count]; + for(int j = 0; j < count; j++) + { ObjectData[j] = new ObjectDataBlock(); } + } + for (int j = 0; j < count; j++) + { ObjectData[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length++; + for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } + if (Header.AckList != null && 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)ObjectData.Length; + for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int ObjectDataStart = 0; + do + { + int variableLength = 0; + int ObjectDataCount = 0; + + i = ObjectDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < ObjectData.Length) { + int blockLength = ObjectData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ObjectDataStart) { + variableLength += blockLength; + ++ObjectDataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)ObjectDataCount; + for (i = ObjectDataStart; i < ObjectDataStart + ObjectDataCount; i++) { ObjectData[i].ToBytes(packet, ref length); } + ObjectDataStart += ObjectDataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + ObjectDataStart < ObjectData.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class ObjectFlagUpdatePacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + public uint ObjectLocalID; + public bool UsePhysics; + public bool IsTemporary; + public bool IsPhantom; + public bool CastsShadows; + + public override int Length + { + get + { + return 40; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + ObjectLocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + UsePhysics = (bytes[i++] != 0) ? (bool)true : (bool)false; + IsTemporary = (bytes[i++] != 0) ? (bool)true : (bool)false; + IsPhantom = (bytes[i++] != 0) ? (bool)true : (bool)false; + CastsShadows = (bytes[i++] != 0) ? (bool)true : (bool)false; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + Utils.UIntToBytes(ObjectLocalID, bytes, i); i += 4; + bytes[i++] = (byte)((UsePhysics) ? 1 : 0); + bytes[i++] = (byte)((IsTemporary) ? 1 : 0); + bytes[i++] = (byte)((IsPhantom) ? 1 : 0); + bytes[i++] = (byte)((CastsShadows) ? 1 : 0); + } + + } + + /// + public sealed class ExtraPhysicsBlock : PacketBlock + { + public byte PhysicsShapeType; + public float Density; + public float Friction; + public float Restitution; + public float GravityMultiplier; + + public override int Length + { + get + { + return 17; + } + } + + public ExtraPhysicsBlock() { } + public ExtraPhysicsBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + PhysicsShapeType = (byte)bytes[i++]; + Density = Utils.BytesToFloat(bytes, i); i += 4; + Friction = Utils.BytesToFloat(bytes, i); i += 4; + Restitution = Utils.BytesToFloat(bytes, i); i += 4; + GravityMultiplier = Utils.BytesToFloat(bytes, i); i += 4; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + bytes[i++] = PhysicsShapeType; + Utils.FloatToBytes(Density, bytes, i); i += 4; + Utils.FloatToBytes(Friction, bytes, i); i += 4; + Utils.FloatToBytes(Restitution, bytes, i); i += 4; + Utils.FloatToBytes(GravityMultiplier, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentData.Length; + for (int j = 0; j < ExtraPhysics.Length; j++) + length += ExtraPhysics[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public ExtraPhysicsBlock[] ExtraPhysics; + + public ObjectFlagUpdatePacket() + { + HasVariableBlocks = true; + Type = PacketType.ObjectFlagUpdate; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 94; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + ExtraPhysics = null; + } + + public ObjectFlagUpdatePacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ExtraPhysics == null || ExtraPhysics.Length != -1) { + ExtraPhysics = new ExtraPhysicsBlock[count]; + for(int j = 0; j < count; j++) + { ExtraPhysics[j] = new ExtraPhysicsBlock(); } + } + for (int j = 0; j < count; j++) + { ExtraPhysics[j].FromBytes(bytes, ref i); } + } + + public ObjectFlagUpdatePacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ExtraPhysics == null || ExtraPhysics.Length != count) { + ExtraPhysics = new ExtraPhysicsBlock[count]; + for(int j = 0; j < count; j++) + { ExtraPhysics[j] = new ExtraPhysicsBlock(); } + } + for (int j = 0; j < count; j++) + { ExtraPhysics[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length++; + for (int j = 0; j < ExtraPhysics.Length; j++) { length += ExtraPhysics[j].Length; } + if (Header.AckList != null && 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)ExtraPhysics.Length; + for (int j = 0; j < ExtraPhysics.Length; j++) { ExtraPhysics[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int ExtraPhysicsStart = 0; + do + { + int variableLength = 0; + int ExtraPhysicsCount = 0; + + i = ExtraPhysicsStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < ExtraPhysics.Length) { + int blockLength = ExtraPhysics[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ExtraPhysicsStart) { + variableLength += blockLength; + ++ExtraPhysicsCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)ExtraPhysicsCount; + for (i = ExtraPhysicsStart; i < ExtraPhysicsStart + ExtraPhysicsCount; i++) { ExtraPhysics[i].ToBytes(packet, ref length); } + ExtraPhysicsStart += ExtraPhysicsCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + ExtraPhysicsStart < ExtraPhysics.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class ObjectClickActionPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class ObjectDataBlock : PacketBlock + { + public uint ObjectLocalID; + public byte ClickAction; + + public override int Length + { + get + { + return 5; + } + } + + public ObjectDataBlock() { } + public ObjectDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + ObjectLocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + ClickAction = (byte)bytes[i++]; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UIntToBytes(ObjectLocalID, bytes, i); i += 4; + bytes[i++] = ClickAction; + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentData.Length; + for (int j = 0; j < ObjectData.Length; j++) + length += ObjectData[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public ObjectDataBlock[] ObjectData; + + public ObjectClickActionPacket() + { + HasVariableBlocks = true; + Type = PacketType.ObjectClickAction; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 95; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + ObjectData = null; + } + + public ObjectClickActionPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ObjectData == null || ObjectData.Length != -1) { + ObjectData = new ObjectDataBlock[count]; + for(int j = 0; j < count; j++) + { ObjectData[j] = new ObjectDataBlock(); } + } + for (int j = 0; j < count; j++) + { ObjectData[j].FromBytes(bytes, ref i); } + } + + public ObjectClickActionPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ObjectData == null || ObjectData.Length != count) { + ObjectData = new ObjectDataBlock[count]; + for(int j = 0; j < count; j++) + { ObjectData[j] = new ObjectDataBlock(); } + } + for (int j = 0; j < count; j++) + { ObjectData[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length++; + for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } + if (Header.AckList != null && 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)ObjectData.Length; + for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int ObjectDataStart = 0; + do + { + int variableLength = 0; + int ObjectDataCount = 0; + + i = ObjectDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < ObjectData.Length) { + int blockLength = ObjectData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ObjectDataStart) { + variableLength += blockLength; + ++ObjectDataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)ObjectDataCount; + for (i = ObjectDataStart; i < ObjectDataStart + ObjectDataCount; i++) { ObjectData[i].ToBytes(packet, ref length); } + ObjectDataStart += ObjectDataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + ObjectDataStart < ObjectData.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class ObjectImagePacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class ObjectDataBlock : PacketBlock + { + public uint ObjectLocalID; + public byte[] MediaURL; + public byte[] TextureEntry; + + public override int Length + { + get + { + int length = 7; + if (MediaURL != null) { length += MediaURL.Length; } + if (TextureEntry != null) { length += TextureEntry.Length; } + return length; + } + } + + public ObjectDataBlock() { } + public ObjectDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + ObjectLocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + length = bytes[i++]; + MediaURL = new byte[length]; + Buffer.BlockCopy(bytes, i, MediaURL, 0, length); i += length; + length = (bytes[i++] + (bytes[i++] << 8)); + TextureEntry = new byte[length]; + Buffer.BlockCopy(bytes, i, TextureEntry, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UIntToBytes(ObjectLocalID, bytes, i); i += 4; + bytes[i++] = (byte)MediaURL.Length; + Buffer.BlockCopy(MediaURL, 0, bytes, i, MediaURL.Length); i += MediaURL.Length; + bytes[i++] = (byte)(TextureEntry.Length % 256); + bytes[i++] = (byte)((TextureEntry.Length >> 8) % 256); + Buffer.BlockCopy(TextureEntry, 0, bytes, i, TextureEntry.Length); i += TextureEntry.Length; + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentData.Length; + for (int j = 0; j < ObjectData.Length; j++) + length += ObjectData[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public ObjectDataBlock[] ObjectData; + + public ObjectImagePacket() + { + HasVariableBlocks = true; + Type = PacketType.ObjectImage; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 96; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + ObjectData = null; + } + + public ObjectImagePacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ObjectData == null || ObjectData.Length != -1) { + ObjectData = new ObjectDataBlock[count]; + for(int j = 0; j < count; j++) + { ObjectData[j] = new ObjectDataBlock(); } + } + for (int j = 0; j < count; j++) + { ObjectData[j].FromBytes(bytes, ref i); } + } + + public ObjectImagePacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ObjectData == null || ObjectData.Length != count) { + ObjectData = new ObjectDataBlock[count]; + for(int j = 0; j < count; j++) + { ObjectData[j] = new ObjectDataBlock(); } + } + for (int j = 0; j < count; j++) + { ObjectData[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length++; + for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } + if (Header.AckList != null && 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)ObjectData.Length; + for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int ObjectDataStart = 0; + do + { + int variableLength = 0; + int ObjectDataCount = 0; + + i = ObjectDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < ObjectData.Length) { + int blockLength = ObjectData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ObjectDataStart) { + variableLength += blockLength; + ++ObjectDataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)ObjectDataCount; + for (i = ObjectDataStart; i < ObjectDataStart + ObjectDataCount; i++) { ObjectData[i].ToBytes(packet, ref length); } + ObjectDataStart += ObjectDataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + ObjectDataStart < ObjectData.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class ObjectMaterialPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class ObjectDataBlock : PacketBlock + { + public uint ObjectLocalID; + public byte Material; + + public override int Length + { + get + { + return 5; + } + } + + public ObjectDataBlock() { } + public ObjectDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + ObjectLocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + Material = (byte)bytes[i++]; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UIntToBytes(ObjectLocalID, bytes, i); i += 4; + bytes[i++] = Material; + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentData.Length; + for (int j = 0; j < ObjectData.Length; j++) + length += ObjectData[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public ObjectDataBlock[] ObjectData; + + public ObjectMaterialPacket() + { + HasVariableBlocks = true; + Type = PacketType.ObjectMaterial; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 97; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + ObjectData = null; + } + + public ObjectMaterialPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ObjectData == null || ObjectData.Length != -1) { + ObjectData = new ObjectDataBlock[count]; + for(int j = 0; j < count; j++) + { ObjectData[j] = new ObjectDataBlock(); } + } + for (int j = 0; j < count; j++) + { ObjectData[j].FromBytes(bytes, ref i); } + } + + public ObjectMaterialPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ObjectData == null || ObjectData.Length != count) { + ObjectData = new ObjectDataBlock[count]; + for(int j = 0; j < count; j++) + { ObjectData[j] = new ObjectDataBlock(); } + } + for (int j = 0; j < count; j++) + { ObjectData[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length++; + for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } + if (Header.AckList != null && 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)ObjectData.Length; + for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int ObjectDataStart = 0; + do + { + int variableLength = 0; + int ObjectDataCount = 0; + + i = ObjectDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < ObjectData.Length) { + int blockLength = ObjectData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ObjectDataStart) { + variableLength += blockLength; + ++ObjectDataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)ObjectDataCount; + for (i = ObjectDataStart; i < ObjectDataStart + ObjectDataCount; i++) { ObjectData[i].ToBytes(packet, ref length); } + ObjectDataStart += ObjectDataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + ObjectDataStart < ObjectData.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class ObjectShapePacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class ObjectDataBlock : PacketBlock + { + public uint ObjectLocalID; + public byte PathCurve; + public byte ProfileCurve; + public ushort PathBegin; + public ushort PathEnd; + public byte PathScaleX; + public byte PathScaleY; + public byte PathShearX; + public byte PathShearY; + public sbyte PathTwist; + public sbyte PathTwistBegin; + public sbyte PathRadiusOffset; + public sbyte PathTaperX; + public sbyte PathTaperY; + public byte PathRevolutions; + public sbyte PathSkew; + public ushort ProfileBegin; + public ushort ProfileEnd; + public ushort ProfileHollow; + + public override int Length + { + get + { + return 27; + } + } + + public ObjectDataBlock() { } + public ObjectDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + ObjectLocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + PathCurve = (byte)bytes[i++]; + ProfileCurve = (byte)bytes[i++]; + PathBegin = (ushort)(bytes[i++] + (bytes[i++] << 8)); + PathEnd = (ushort)(bytes[i++] + (bytes[i++] << 8)); + PathScaleX = (byte)bytes[i++]; + PathScaleY = (byte)bytes[i++]; + PathShearX = (byte)bytes[i++]; + PathShearY = (byte)bytes[i++]; + PathTwist = (sbyte)bytes[i++]; + PathTwistBegin = (sbyte)bytes[i++]; + PathRadiusOffset = (sbyte)bytes[i++]; + PathTaperX = (sbyte)bytes[i++]; + PathTaperY = (sbyte)bytes[i++]; + PathRevolutions = (byte)bytes[i++]; + PathSkew = (sbyte)bytes[i++]; + ProfileBegin = (ushort)(bytes[i++] + (bytes[i++] << 8)); + ProfileEnd = (ushort)(bytes[i++] + (bytes[i++] << 8)); + ProfileHollow = (ushort)(bytes[i++] + (bytes[i++] << 8)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UIntToBytes(ObjectLocalID, bytes, i); i += 4; + bytes[i++] = PathCurve; + bytes[i++] = ProfileCurve; + bytes[i++] = (byte)(PathBegin % 256); + bytes[i++] = (byte)((PathBegin >> 8) % 256); + bytes[i++] = (byte)(PathEnd % 256); + bytes[i++] = (byte)((PathEnd >> 8) % 256); + bytes[i++] = PathScaleX; + bytes[i++] = PathScaleY; + bytes[i++] = PathShearX; + bytes[i++] = PathShearY; + bytes[i++] = (byte)PathTwist; + bytes[i++] = (byte)PathTwistBegin; + bytes[i++] = (byte)PathRadiusOffset; + bytes[i++] = (byte)PathTaperX; + bytes[i++] = (byte)PathTaperY; + bytes[i++] = PathRevolutions; + bytes[i++] = (byte)PathSkew; + bytes[i++] = (byte)(ProfileBegin % 256); + bytes[i++] = (byte)((ProfileBegin >> 8) % 256); + bytes[i++] = (byte)(ProfileEnd % 256); + bytes[i++] = (byte)((ProfileEnd >> 8) % 256); + bytes[i++] = (byte)(ProfileHollow % 256); + bytes[i++] = (byte)((ProfileHollow >> 8) % 256); + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentData.Length; + for (int j = 0; j < ObjectData.Length; j++) + length += ObjectData[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public ObjectDataBlock[] ObjectData; + + public ObjectShapePacket() + { + HasVariableBlocks = true; + Type = PacketType.ObjectShape; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 98; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + ObjectData = null; + } + + public ObjectShapePacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ObjectData == null || ObjectData.Length != -1) { + ObjectData = new ObjectDataBlock[count]; + for(int j = 0; j < count; j++) + { ObjectData[j] = new ObjectDataBlock(); } + } + for (int j = 0; j < count; j++) + { ObjectData[j].FromBytes(bytes, ref i); } + } + + public ObjectShapePacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ObjectData == null || ObjectData.Length != count) { + ObjectData = new ObjectDataBlock[count]; + for(int j = 0; j < count; j++) + { ObjectData[j] = new ObjectDataBlock(); } + } + for (int j = 0; j < count; j++) + { ObjectData[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length++; + for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } + if (Header.AckList != null && 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)ObjectData.Length; + for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int ObjectDataStart = 0; + do + { + int variableLength = 0; + int ObjectDataCount = 0; + + i = ObjectDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < ObjectData.Length) { + int blockLength = ObjectData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ObjectDataStart) { + variableLength += blockLength; + ++ObjectDataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)ObjectDataCount; + for (i = ObjectDataStart; i < ObjectDataStart + ObjectDataCount; i++) { ObjectData[i].ToBytes(packet, ref length); } + ObjectDataStart += ObjectDataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + ObjectDataStart < ObjectData.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class ObjectExtraParamsPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class ObjectDataBlock : PacketBlock + { + public uint ObjectLocalID; + public ushort ParamType; + public bool ParamInUse; + public uint ParamSize; + public byte[] ParamData; + + public override int Length + { + get + { + int length = 12; + if (ParamData != null) { length += ParamData.Length; } + return length; + } + } + + public ObjectDataBlock() { } + public ObjectDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + ObjectLocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + ParamType = (ushort)(bytes[i++] + (bytes[i++] << 8)); + ParamInUse = (bytes[i++] != 0) ? (bool)true : (bool)false; + ParamSize = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + length = bytes[i++]; + ParamData = new byte[length]; + Buffer.BlockCopy(bytes, i, ParamData, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UIntToBytes(ObjectLocalID, bytes, i); i += 4; + bytes[i++] = (byte)(ParamType % 256); + bytes[i++] = (byte)((ParamType >> 8) % 256); + bytes[i++] = (byte)((ParamInUse) ? 1 : 0); + Utils.UIntToBytes(ParamSize, bytes, i); i += 4; + bytes[i++] = (byte)ParamData.Length; + Buffer.BlockCopy(ParamData, 0, bytes, i, ParamData.Length); i += ParamData.Length; + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentData.Length; + for (int j = 0; j < ObjectData.Length; j++) + length += ObjectData[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public ObjectDataBlock[] ObjectData; + + public ObjectExtraParamsPacket() + { + HasVariableBlocks = true; + Type = PacketType.ObjectExtraParams; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 99; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + ObjectData = null; + } + + public ObjectExtraParamsPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ObjectData == null || ObjectData.Length != -1) { + ObjectData = new ObjectDataBlock[count]; + for(int j = 0; j < count; j++) + { ObjectData[j] = new ObjectDataBlock(); } + } + for (int j = 0; j < count; j++) + { ObjectData[j].FromBytes(bytes, ref i); } + } + + public ObjectExtraParamsPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ObjectData == null || ObjectData.Length != count) { + ObjectData = new ObjectDataBlock[count]; + for(int j = 0; j < count; j++) + { ObjectData[j] = new ObjectDataBlock(); } + } + for (int j = 0; j < count; j++) + { ObjectData[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length++; + for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } + if (Header.AckList != null && 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)ObjectData.Length; + for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int ObjectDataStart = 0; + do + { + int variableLength = 0; + int ObjectDataCount = 0; + + i = ObjectDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < ObjectData.Length) { + int blockLength = ObjectData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ObjectDataStart) { + variableLength += blockLength; + ++ObjectDataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)ObjectDataCount; + for (i = ObjectDataStart; i < ObjectDataStart + ObjectDataCount; i++) { ObjectData[i].ToBytes(packet, ref length); } + ObjectDataStart += ObjectDataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + ObjectDataStart < ObjectData.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class ObjectOwnerPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class HeaderDataBlock : PacketBlock + { + public bool Override; + public UUID OwnerID; + public UUID GroupID; + + public override int Length + { + get + { + return 33; + } + } + + public HeaderDataBlock() { } + public HeaderDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + Override = (bytes[i++] != 0) ? (bool)true : (bool)false; + OwnerID.FromBytes(bytes, i); i += 16; + GroupID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + bytes[i++] = (byte)((Override) ? 1 : 0); + OwnerID.ToBytes(bytes, i); i += 16; + GroupID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class ObjectDataBlock : PacketBlock + { + public uint ObjectLocalID; + + public override int Length + { + get + { + return 4; + } + } + + public ObjectDataBlock() { } + public ObjectDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + ObjectLocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UIntToBytes(ObjectLocalID, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentData.Length; + length += HeaderData.Length; + for (int j = 0; j < ObjectData.Length; j++) + length += ObjectData[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public HeaderDataBlock HeaderData; + public ObjectDataBlock[] ObjectData; + + public ObjectOwnerPacket() + { + HasVariableBlocks = true; + Type = PacketType.ObjectOwner; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 100; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + HeaderData = new HeaderDataBlock(); + ObjectData = null; + } + + public ObjectOwnerPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + HeaderData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ObjectData == null || ObjectData.Length != -1) { + ObjectData = new ObjectDataBlock[count]; + for(int j = 0; j < count; j++) + { ObjectData[j] = new ObjectDataBlock(); } + } + for (int j = 0; j < count; j++) + { ObjectData[j].FromBytes(bytes, ref i); } + } + + public ObjectOwnerPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + HeaderData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ObjectData == null || ObjectData.Length != count) { + ObjectData = new ObjectDataBlock[count]; + for(int j = 0; j < count; j++) + { ObjectData[j] = new ObjectDataBlock(); } + } + for (int j = 0; j < count; j++) + { ObjectData[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += HeaderData.Length; + length++; + for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } + if (Header.AckList != null && 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); + HeaderData.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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + fixedLength += HeaderData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + HeaderData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int ObjectDataStart = 0; + do + { + int variableLength = 0; + int ObjectDataCount = 0; + + i = ObjectDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < ObjectData.Length) { + int blockLength = ObjectData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ObjectDataStart) { + variableLength += blockLength; + ++ObjectDataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)ObjectDataCount; + for (i = ObjectDataStart; i < ObjectDataStart + ObjectDataCount; i++) { ObjectData[i].ToBytes(packet, ref length); } + ObjectDataStart += ObjectDataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + ObjectDataStart < ObjectData.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class ObjectGroupPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + public UUID GroupID; + + public override int Length + { + get + { + return 48; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + GroupID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + GroupID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class ObjectDataBlock : PacketBlock + { + public uint ObjectLocalID; + + public override int Length + { + get + { + return 4; + } + } + + public ObjectDataBlock() { } + public ObjectDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + ObjectLocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UIntToBytes(ObjectLocalID, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentData.Length; + for (int j = 0; j < ObjectData.Length; j++) + length += ObjectData[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public ObjectDataBlock[] ObjectData; + + public ObjectGroupPacket() + { + HasVariableBlocks = true; + Type = PacketType.ObjectGroup; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 101; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + ObjectData = null; + } + + public ObjectGroupPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ObjectData == null || ObjectData.Length != -1) { + ObjectData = new ObjectDataBlock[count]; + for(int j = 0; j < count; j++) + { ObjectData[j] = new ObjectDataBlock(); } + } + for (int j = 0; j < count; j++) + { ObjectData[j].FromBytes(bytes, ref i); } + } + + public ObjectGroupPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ObjectData == null || ObjectData.Length != count) { + ObjectData = new ObjectDataBlock[count]; + for(int j = 0; j < count; j++) + { ObjectData[j] = new ObjectDataBlock(); } + } + for (int j = 0; j < count; j++) + { ObjectData[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length++; + for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } + if (Header.AckList != null && 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)ObjectData.Length; + for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int ObjectDataStart = 0; + do + { + int variableLength = 0; + int ObjectDataCount = 0; + + i = ObjectDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < ObjectData.Length) { + int blockLength = ObjectData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ObjectDataStart) { + variableLength += blockLength; + ++ObjectDataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)ObjectDataCount; + for (i = ObjectDataStart; i < ObjectDataStart + ObjectDataCount; i++) { ObjectData[i].ToBytes(packet, ref length); } + ObjectDataStart += ObjectDataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + ObjectDataStart < ObjectData.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class ObjectBuyPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + public UUID GroupID; + public UUID CategoryID; + + public override int Length + { + get + { + return 64; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + GroupID.FromBytes(bytes, i); i += 16; + CategoryID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + GroupID.ToBytes(bytes, i); i += 16; + CategoryID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class ObjectDataBlock : PacketBlock + { + public uint ObjectLocalID; + public byte SaleType; + public int SalePrice; + + public override int Length + { + get + { + return 9; + } + } + + public ObjectDataBlock() { } + public ObjectDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + ObjectLocalID = (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(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UIntToBytes(ObjectLocalID, bytes, i); i += 4; + bytes[i++] = SaleType; + Utils.IntToBytes(SalePrice, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentData.Length; + for (int j = 0; j < ObjectData.Length; j++) + length += ObjectData[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public ObjectDataBlock[] ObjectData; + + public ObjectBuyPacket() + { + HasVariableBlocks = true; + Type = PacketType.ObjectBuy; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 102; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + ObjectData = null; + } + + public ObjectBuyPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ObjectData == null || ObjectData.Length != -1) { + ObjectData = new ObjectDataBlock[count]; + for(int j = 0; j < count; j++) + { ObjectData[j] = new ObjectDataBlock(); } + } + for (int j = 0; j < count; j++) + { ObjectData[j].FromBytes(bytes, ref i); } + } + + public ObjectBuyPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ObjectData == null || ObjectData.Length != count) { + ObjectData = new ObjectDataBlock[count]; + for(int j = 0; j < count; j++) + { ObjectData[j] = new ObjectDataBlock(); } + } + for (int j = 0; j < count; j++) + { ObjectData[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length++; + for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } + if (Header.AckList != null && 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)ObjectData.Length; + for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int ObjectDataStart = 0; + do + { + int variableLength = 0; + int ObjectDataCount = 0; + + i = ObjectDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < ObjectData.Length) { + int blockLength = ObjectData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ObjectDataStart) { + variableLength += blockLength; + ++ObjectDataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)ObjectDataCount; + for (i = ObjectDataStart; i < ObjectDataStart + ObjectDataCount; i++) { ObjectData[i].ToBytes(packet, ref length); } + ObjectDataStart += ObjectDataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + ObjectDataStart < ObjectData.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class BuyObjectInventoryPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class DataBlock : PacketBlock + { + public UUID ObjectID; + public UUID ItemID; + public UUID FolderID; + + public override int Length + { + get + { + return 48; + } + } + + public DataBlock() { } + public DataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + ObjectID.FromBytes(bytes, i); i += 16; + ItemID.FromBytes(bytes, i); i += 16; + FolderID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + ObjectID.ToBytes(bytes, i); i += 16; + ItemID.ToBytes(bytes, i); i += 16; + FolderID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += Data.Length; + return length; + } + } + public AgentDataBlock AgentData; + public DataBlock Data; + + public BuyObjectInventoryPacket() + { + HasVariableBlocks = false; + Type = PacketType.BuyObjectInventory; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 103; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + Data = new DataBlock(); + } + + public BuyObjectInventoryPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + Data.FromBytes(bytes, ref i); + } + + public BuyObjectInventoryPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + Data.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += Data.Length; + if (Header.AckList != null && 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); + Data.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class DerezContainerPacket : Packet + { + /// + public sealed class DataBlock : PacketBlock + { + public UUID ObjectID; + public bool Delete; + + public override int Length + { + get + { + return 17; + } + } + + public DataBlock() { } + public DataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + ObjectID.FromBytes(bytes, i); i += 16; + Delete = (bytes[i++] != 0) ? (bool)true : (bool)false; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + ObjectID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)((Delete) ? 1 : 0); + } + + } + + public override int Length + { + get + { + int length = 10; + length += Data.Length; + return length; + } + } + public DataBlock Data; + + public DerezContainerPacket() + { + HasVariableBlocks = false; + Type = PacketType.DerezContainer; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 104; + Header.Reliable = true; + Header.Zerocoded = true; + Data = new DataBlock(); + } + + public DerezContainerPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + Data.FromBytes(bytes, ref i); + } + + public DerezContainerPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + Data.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += Data.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class ObjectPermissionsPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class HeaderDataBlock : PacketBlock + { + public bool Override; + + public override int Length + { + get + { + return 1; + } + } + + public HeaderDataBlock() { } + public HeaderDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + Override = (bytes[i++] != 0) ? (bool)true : (bool)false; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + bytes[i++] = (byte)((Override) ? 1 : 0); + } + + } + + /// + public sealed class ObjectDataBlock : PacketBlock + { + public uint ObjectLocalID; + public byte Field; + public byte Set; + public uint Mask; + + public override int Length + { + get + { + return 10; + } + } + + public ObjectDataBlock() { } + public ObjectDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + ObjectLocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + Field = (byte)bytes[i++]; + Set = (byte)bytes[i++]; + Mask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UIntToBytes(ObjectLocalID, bytes, i); i += 4; + bytes[i++] = Field; + bytes[i++] = Set; + Utils.UIntToBytes(Mask, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentData.Length; + length += HeaderData.Length; + for (int j = 0; j < ObjectData.Length; j++) + length += ObjectData[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public HeaderDataBlock HeaderData; + public ObjectDataBlock[] ObjectData; + + public ObjectPermissionsPacket() + { + HasVariableBlocks = true; + Type = PacketType.ObjectPermissions; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 105; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + HeaderData = new HeaderDataBlock(); + ObjectData = null; + } + + public ObjectPermissionsPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + HeaderData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ObjectData == null || ObjectData.Length != -1) { + ObjectData = new ObjectDataBlock[count]; + for(int j = 0; j < count; j++) + { ObjectData[j] = new ObjectDataBlock(); } + } + for (int j = 0; j < count; j++) + { ObjectData[j].FromBytes(bytes, ref i); } + } + + public ObjectPermissionsPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + HeaderData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ObjectData == null || ObjectData.Length != count) { + ObjectData = new ObjectDataBlock[count]; + for(int j = 0; j < count; j++) + { ObjectData[j] = new ObjectDataBlock(); } + } + for (int j = 0; j < count; j++) + { ObjectData[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += HeaderData.Length; + length++; + for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } + if (Header.AckList != null && 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); + HeaderData.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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + fixedLength += HeaderData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + HeaderData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int ObjectDataStart = 0; + do + { + int variableLength = 0; + int ObjectDataCount = 0; + + i = ObjectDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < ObjectData.Length) { + int blockLength = ObjectData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ObjectDataStart) { + variableLength += blockLength; + ++ObjectDataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)ObjectDataCount; + for (i = ObjectDataStart; i < ObjectDataStart + ObjectDataCount; i++) { ObjectData[i].ToBytes(packet, ref length); } + ObjectDataStart += ObjectDataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + ObjectDataStart < ObjectData.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class ObjectSaleInfoPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class ObjectDataBlock : PacketBlock + { + public uint LocalID; + public byte SaleType; + public int SalePrice; + + public override int Length + { + get + { + return 9; + } + } + + public ObjectDataBlock() { } + public ObjectDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(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(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UIntToBytes(LocalID, bytes, i); i += 4; + bytes[i++] = SaleType; + Utils.IntToBytes(SalePrice, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentData.Length; + for (int j = 0; j < ObjectData.Length; j++) + length += ObjectData[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public ObjectDataBlock[] ObjectData; + + public ObjectSaleInfoPacket() + { + HasVariableBlocks = true; + Type = PacketType.ObjectSaleInfo; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 106; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + ObjectData = null; + } + + public ObjectSaleInfoPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ObjectData == null || ObjectData.Length != -1) { + ObjectData = new ObjectDataBlock[count]; + for(int j = 0; j < count; j++) + { ObjectData[j] = new ObjectDataBlock(); } + } + for (int j = 0; j < count; j++) + { ObjectData[j].FromBytes(bytes, ref i); } + } + + public ObjectSaleInfoPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ObjectData == null || ObjectData.Length != count) { + ObjectData = new ObjectDataBlock[count]; + for(int j = 0; j < count; j++) + { ObjectData[j] = new ObjectDataBlock(); } + } + for (int j = 0; j < count; j++) + { ObjectData[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length++; + for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } + if (Header.AckList != null && 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)ObjectData.Length; + for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int ObjectDataStart = 0; + do + { + int variableLength = 0; + int ObjectDataCount = 0; + + i = ObjectDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < ObjectData.Length) { + int blockLength = ObjectData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ObjectDataStart) { + variableLength += blockLength; + ++ObjectDataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)ObjectDataCount; + for (i = ObjectDataStart; i < ObjectDataStart + ObjectDataCount; i++) { ObjectData[i].ToBytes(packet, ref length); } + ObjectDataStart += ObjectDataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + ObjectDataStart < ObjectData.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class ObjectNamePacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class ObjectDataBlock : PacketBlock + { + public uint LocalID; + public byte[] Name; + + public override int Length + { + get + { + int length = 5; + if (Name != null) { length += Name.Length; } + return length; + } + } + + public ObjectDataBlock() { } + public ObjectDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + LocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + length = bytes[i++]; + Name = new byte[length]; + Buffer.BlockCopy(bytes, i, Name, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UIntToBytes(LocalID, bytes, i); i += 4; + bytes[i++] = (byte)Name.Length; + Buffer.BlockCopy(Name, 0, bytes, i, Name.Length); i += Name.Length; + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentData.Length; + for (int j = 0; j < ObjectData.Length; j++) + length += ObjectData[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public ObjectDataBlock[] ObjectData; + + public ObjectNamePacket() + { + HasVariableBlocks = true; + Type = PacketType.ObjectName; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 107; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + ObjectData = null; + } + + public ObjectNamePacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ObjectData == null || ObjectData.Length != -1) { + ObjectData = new ObjectDataBlock[count]; + for(int j = 0; j < count; j++) + { ObjectData[j] = new ObjectDataBlock(); } + } + for (int j = 0; j < count; j++) + { ObjectData[j].FromBytes(bytes, ref i); } + } + + public ObjectNamePacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ObjectData == null || ObjectData.Length != count) { + ObjectData = new ObjectDataBlock[count]; + for(int j = 0; j < count; j++) + { ObjectData[j] = new ObjectDataBlock(); } + } + for (int j = 0; j < count; j++) + { ObjectData[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length++; + for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } + if (Header.AckList != null && 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)ObjectData.Length; + for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int ObjectDataStart = 0; + do + { + int variableLength = 0; + int ObjectDataCount = 0; + + i = ObjectDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < ObjectData.Length) { + int blockLength = ObjectData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ObjectDataStart) { + variableLength += blockLength; + ++ObjectDataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)ObjectDataCount; + for (i = ObjectDataStart; i < ObjectDataStart + ObjectDataCount; i++) { ObjectData[i].ToBytes(packet, ref length); } + ObjectDataStart += ObjectDataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + ObjectDataStart < ObjectData.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class ObjectDescriptionPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class ObjectDataBlock : PacketBlock + { + public uint LocalID; + public byte[] Description; + + public override int Length + { + get + { + int length = 5; + if (Description != null) { length += Description.Length; } + return length; + } + } + + public ObjectDataBlock() { } + public ObjectDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + LocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + length = bytes[i++]; + Description = new byte[length]; + Buffer.BlockCopy(bytes, i, Description, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UIntToBytes(LocalID, bytes, i); i += 4; + bytes[i++] = (byte)Description.Length; + Buffer.BlockCopy(Description, 0, bytes, i, Description.Length); i += Description.Length; + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentData.Length; + for (int j = 0; j < ObjectData.Length; j++) + length += ObjectData[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public ObjectDataBlock[] ObjectData; + + public ObjectDescriptionPacket() + { + HasVariableBlocks = true; + Type = PacketType.ObjectDescription; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 108; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + ObjectData = null; + } + + public ObjectDescriptionPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ObjectData == null || ObjectData.Length != -1) { + ObjectData = new ObjectDataBlock[count]; + for(int j = 0; j < count; j++) + { ObjectData[j] = new ObjectDataBlock(); } + } + for (int j = 0; j < count; j++) + { ObjectData[j].FromBytes(bytes, ref i); } + } + + public ObjectDescriptionPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ObjectData == null || ObjectData.Length != count) { + ObjectData = new ObjectDataBlock[count]; + for(int j = 0; j < count; j++) + { ObjectData[j] = new ObjectDataBlock(); } + } + for (int j = 0; j < count; j++) + { ObjectData[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length++; + for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } + if (Header.AckList != null && 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)ObjectData.Length; + for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int ObjectDataStart = 0; + do + { + int variableLength = 0; + int ObjectDataCount = 0; + + i = ObjectDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < ObjectData.Length) { + int blockLength = ObjectData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ObjectDataStart) { + variableLength += blockLength; + ++ObjectDataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)ObjectDataCount; + for (i = ObjectDataStart; i < ObjectDataStart + ObjectDataCount; i++) { ObjectData[i].ToBytes(packet, ref length); } + ObjectDataStart += ObjectDataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + ObjectDataStart < ObjectData.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class ObjectCategoryPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class ObjectDataBlock : PacketBlock + { + public uint LocalID; + public uint Category; + + public override int Length + { + get + { + return 8; + } + } + + public ObjectDataBlock() { } + public ObjectDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(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(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UIntToBytes(LocalID, bytes, i); i += 4; + Utils.UIntToBytes(Category, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentData.Length; + for (int j = 0; j < ObjectData.Length; j++) + length += ObjectData[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public ObjectDataBlock[] ObjectData; + + public ObjectCategoryPacket() + { + HasVariableBlocks = true; + Type = PacketType.ObjectCategory; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 109; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + ObjectData = null; + } + + public ObjectCategoryPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ObjectData == null || ObjectData.Length != -1) { + ObjectData = new ObjectDataBlock[count]; + for(int j = 0; j < count; j++) + { ObjectData[j] = new ObjectDataBlock(); } + } + for (int j = 0; j < count; j++) + { ObjectData[j].FromBytes(bytes, ref i); } + } + + public ObjectCategoryPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ObjectData == null || ObjectData.Length != count) { + ObjectData = new ObjectDataBlock[count]; + for(int j = 0; j < count; j++) + { ObjectData[j] = new ObjectDataBlock(); } + } + for (int j = 0; j < count; j++) + { ObjectData[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length++; + for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } + if (Header.AckList != null && 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)ObjectData.Length; + for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int ObjectDataStart = 0; + do + { + int variableLength = 0; + int ObjectDataCount = 0; + + i = ObjectDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < ObjectData.Length) { + int blockLength = ObjectData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ObjectDataStart) { + variableLength += blockLength; + ++ObjectDataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)ObjectDataCount; + for (i = ObjectDataStart; i < ObjectDataStart + ObjectDataCount; i++) { ObjectData[i].ToBytes(packet, ref length); } + ObjectDataStart += ObjectDataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + ObjectDataStart < ObjectData.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class ObjectSelectPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class ObjectDataBlock : PacketBlock + { + public uint ObjectLocalID; + + public override int Length + { + get + { + return 4; + } + } + + public ObjectDataBlock() { } + public ObjectDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + ObjectLocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UIntToBytes(ObjectLocalID, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentData.Length; + for (int j = 0; j < ObjectData.Length; j++) + length += ObjectData[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public ObjectDataBlock[] ObjectData; + + public ObjectSelectPacket() + { + HasVariableBlocks = true; + Type = PacketType.ObjectSelect; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 110; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + ObjectData = null; + } + + public ObjectSelectPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ObjectData == null || ObjectData.Length != -1) { + ObjectData = new ObjectDataBlock[count]; + for(int j = 0; j < count; j++) + { ObjectData[j] = new ObjectDataBlock(); } + } + for (int j = 0; j < count; j++) + { ObjectData[j].FromBytes(bytes, ref i); } + } + + public ObjectSelectPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ObjectData == null || ObjectData.Length != count) { + ObjectData = new ObjectDataBlock[count]; + for(int j = 0; j < count; j++) + { ObjectData[j] = new ObjectDataBlock(); } + } + for (int j = 0; j < count; j++) + { ObjectData[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length++; + for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } + if (Header.AckList != null && 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)ObjectData.Length; + for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int ObjectDataStart = 0; + do + { + int variableLength = 0; + int ObjectDataCount = 0; + + i = ObjectDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < ObjectData.Length) { + int blockLength = ObjectData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ObjectDataStart) { + variableLength += blockLength; + ++ObjectDataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)ObjectDataCount; + for (i = ObjectDataStart; i < ObjectDataStart + ObjectDataCount; i++) { ObjectData[i].ToBytes(packet, ref length); } + ObjectDataStart += ObjectDataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + ObjectDataStart < ObjectData.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class ObjectDeselectPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class ObjectDataBlock : PacketBlock + { + public uint ObjectLocalID; + + public override int Length + { + get + { + return 4; + } + } + + public ObjectDataBlock() { } + public ObjectDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + ObjectLocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UIntToBytes(ObjectLocalID, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentData.Length; + for (int j = 0; j < ObjectData.Length; j++) + length += ObjectData[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public ObjectDataBlock[] ObjectData; + + public ObjectDeselectPacket() + { + HasVariableBlocks = true; + Type = PacketType.ObjectDeselect; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 111; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + ObjectData = null; + } + + public ObjectDeselectPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ObjectData == null || ObjectData.Length != -1) { + ObjectData = new ObjectDataBlock[count]; + for(int j = 0; j < count; j++) + { ObjectData[j] = new ObjectDataBlock(); } + } + for (int j = 0; j < count; j++) + { ObjectData[j].FromBytes(bytes, ref i); } + } + + public ObjectDeselectPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ObjectData == null || ObjectData.Length != count) { + ObjectData = new ObjectDataBlock[count]; + for(int j = 0; j < count; j++) + { ObjectData[j] = new ObjectDataBlock(); } + } + for (int j = 0; j < count; j++) + { ObjectData[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length++; + for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } + if (Header.AckList != null && 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)ObjectData.Length; + for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int ObjectDataStart = 0; + do + { + int variableLength = 0; + int ObjectDataCount = 0; + + i = ObjectDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < ObjectData.Length) { + int blockLength = ObjectData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ObjectDataStart) { + variableLength += blockLength; + ++ObjectDataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)ObjectDataCount; + for (i = ObjectDataStart; i < ObjectDataStart + ObjectDataCount; i++) { ObjectData[i].ToBytes(packet, ref length); } + ObjectDataStart += ObjectDataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + ObjectDataStart < ObjectData.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class ObjectAttachPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + public byte AttachmentPoint; + + public override int Length + { + get + { + return 33; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + AttachmentPoint = (byte)bytes[i++]; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + bytes[i++] = AttachmentPoint; + } + + } + + /// + public sealed class ObjectDataBlock : PacketBlock + { + public uint ObjectLocalID; + public Quaternion Rotation; + + public override int Length + { + get + { + return 16; + } + } + + public ObjectDataBlock() { } + public ObjectDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + ObjectLocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + Rotation.FromBytes(bytes, i, true); i += 12; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UIntToBytes(ObjectLocalID, bytes, i); i += 4; + Rotation.ToBytes(bytes, i); i += 12; + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentData.Length; + for (int j = 0; j < ObjectData.Length; j++) + length += ObjectData[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public ObjectDataBlock[] ObjectData; + + public ObjectAttachPacket() + { + HasVariableBlocks = true; + Type = PacketType.ObjectAttach; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 112; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + ObjectData = null; + } + + public ObjectAttachPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ObjectData == null || ObjectData.Length != -1) { + ObjectData = new ObjectDataBlock[count]; + for(int j = 0; j < count; j++) + { ObjectData[j] = new ObjectDataBlock(); } + } + for (int j = 0; j < count; j++) + { ObjectData[j].FromBytes(bytes, ref i); } + } + + public ObjectAttachPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ObjectData == null || ObjectData.Length != count) { + ObjectData = new ObjectDataBlock[count]; + for(int j = 0; j < count; j++) + { ObjectData[j] = new ObjectDataBlock(); } + } + for (int j = 0; j < count; j++) + { ObjectData[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length++; + for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } + if (Header.AckList != null && 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)ObjectData.Length; + for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int ObjectDataStart = 0; + do + { + int variableLength = 0; + int ObjectDataCount = 0; + + i = ObjectDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < ObjectData.Length) { + int blockLength = ObjectData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ObjectDataStart) { + variableLength += blockLength; + ++ObjectDataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)ObjectDataCount; + for (i = ObjectDataStart; i < ObjectDataStart + ObjectDataCount; i++) { ObjectData[i].ToBytes(packet, ref length); } + ObjectDataStart += ObjectDataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + ObjectDataStart < ObjectData.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class ObjectDetachPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class ObjectDataBlock : PacketBlock + { + public uint ObjectLocalID; + + public override int Length + { + get + { + return 4; + } + } + + public ObjectDataBlock() { } + public ObjectDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + ObjectLocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UIntToBytes(ObjectLocalID, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentData.Length; + for (int j = 0; j < ObjectData.Length; j++) + length += ObjectData[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public ObjectDataBlock[] ObjectData; + + public ObjectDetachPacket() + { + HasVariableBlocks = true; + Type = PacketType.ObjectDetach; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 113; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + ObjectData = null; + } + + public ObjectDetachPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ObjectData == null || ObjectData.Length != -1) { + ObjectData = new ObjectDataBlock[count]; + for(int j = 0; j < count; j++) + { ObjectData[j] = new ObjectDataBlock(); } + } + for (int j = 0; j < count; j++) + { ObjectData[j].FromBytes(bytes, ref i); } + } + + public ObjectDetachPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ObjectData == null || ObjectData.Length != count) { + ObjectData = new ObjectDataBlock[count]; + for(int j = 0; j < count; j++) + { ObjectData[j] = new ObjectDataBlock(); } + } + for (int j = 0; j < count; j++) + { ObjectData[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length++; + for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } + if (Header.AckList != null && 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)ObjectData.Length; + for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int ObjectDataStart = 0; + do + { + int variableLength = 0; + int ObjectDataCount = 0; + + i = ObjectDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < ObjectData.Length) { + int blockLength = ObjectData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ObjectDataStart) { + variableLength += blockLength; + ++ObjectDataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)ObjectDataCount; + for (i = ObjectDataStart; i < ObjectDataStart + ObjectDataCount; i++) { ObjectData[i].ToBytes(packet, ref length); } + ObjectDataStart += ObjectDataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + ObjectDataStart < ObjectData.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class ObjectDropPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class ObjectDataBlock : PacketBlock + { + public uint ObjectLocalID; + + public override int Length + { + get + { + return 4; + } + } + + public ObjectDataBlock() { } + public ObjectDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + ObjectLocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UIntToBytes(ObjectLocalID, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentData.Length; + for (int j = 0; j < ObjectData.Length; j++) + length += ObjectData[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public ObjectDataBlock[] ObjectData; + + public ObjectDropPacket() + { + HasVariableBlocks = true; + Type = PacketType.ObjectDrop; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 114; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + ObjectData = null; + } + + public ObjectDropPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ObjectData == null || ObjectData.Length != -1) { + ObjectData = new ObjectDataBlock[count]; + for(int j = 0; j < count; j++) + { ObjectData[j] = new ObjectDataBlock(); } + } + for (int j = 0; j < count; j++) + { ObjectData[j].FromBytes(bytes, ref i); } + } + + public ObjectDropPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ObjectData == null || ObjectData.Length != count) { + ObjectData = new ObjectDataBlock[count]; + for(int j = 0; j < count; j++) + { ObjectData[j] = new ObjectDataBlock(); } + } + for (int j = 0; j < count; j++) + { ObjectData[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length++; + for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } + if (Header.AckList != null && 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)ObjectData.Length; + for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int ObjectDataStart = 0; + do + { + int variableLength = 0; + int ObjectDataCount = 0; + + i = ObjectDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < ObjectData.Length) { + int blockLength = ObjectData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ObjectDataStart) { + variableLength += blockLength; + ++ObjectDataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)ObjectDataCount; + for (i = ObjectDataStart; i < ObjectDataStart + ObjectDataCount; i++) { ObjectData[i].ToBytes(packet, ref length); } + ObjectDataStart += ObjectDataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + ObjectDataStart < ObjectData.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class ObjectLinkPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class ObjectDataBlock : PacketBlock + { + public uint ObjectLocalID; + + public override int Length + { + get + { + return 4; + } + } + + public ObjectDataBlock() { } + public ObjectDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + ObjectLocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UIntToBytes(ObjectLocalID, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentData.Length; + for (int j = 0; j < ObjectData.Length; j++) + length += ObjectData[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public ObjectDataBlock[] ObjectData; + + public ObjectLinkPacket() + { + HasVariableBlocks = true; + Type = PacketType.ObjectLink; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 115; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + ObjectData = null; + } + + public ObjectLinkPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ObjectData == null || ObjectData.Length != -1) { + ObjectData = new ObjectDataBlock[count]; + for(int j = 0; j < count; j++) + { ObjectData[j] = new ObjectDataBlock(); } + } + for (int j = 0; j < count; j++) + { ObjectData[j].FromBytes(bytes, ref i); } + } + + public ObjectLinkPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ObjectData == null || ObjectData.Length != count) { + ObjectData = new ObjectDataBlock[count]; + for(int j = 0; j < count; j++) + { ObjectData[j] = new ObjectDataBlock(); } + } + for (int j = 0; j < count; j++) + { ObjectData[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length++; + for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } + if (Header.AckList != null && 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)ObjectData.Length; + for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int ObjectDataStart = 0; + do + { + int variableLength = 0; + int ObjectDataCount = 0; + + i = ObjectDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < ObjectData.Length) { + int blockLength = ObjectData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ObjectDataStart) { + variableLength += blockLength; + ++ObjectDataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)ObjectDataCount; + for (i = ObjectDataStart; i < ObjectDataStart + ObjectDataCount; i++) { ObjectData[i].ToBytes(packet, ref length); } + ObjectDataStart += ObjectDataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + ObjectDataStart < ObjectData.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class ObjectDelinkPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class ObjectDataBlock : PacketBlock + { + public uint ObjectLocalID; + + public override int Length + { + get + { + return 4; + } + } + + public ObjectDataBlock() { } + public ObjectDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + ObjectLocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UIntToBytes(ObjectLocalID, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentData.Length; + for (int j = 0; j < ObjectData.Length; j++) + length += ObjectData[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public ObjectDataBlock[] ObjectData; + + public ObjectDelinkPacket() + { + HasVariableBlocks = true; + Type = PacketType.ObjectDelink; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 116; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + ObjectData = null; + } + + public ObjectDelinkPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ObjectData == null || ObjectData.Length != -1) { + ObjectData = new ObjectDataBlock[count]; + for(int j = 0; j < count; j++) + { ObjectData[j] = new ObjectDataBlock(); } + } + for (int j = 0; j < count; j++) + { ObjectData[j].FromBytes(bytes, ref i); } + } + + public ObjectDelinkPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ObjectData == null || ObjectData.Length != count) { + ObjectData = new ObjectDataBlock[count]; + for(int j = 0; j < count; j++) + { ObjectData[j] = new ObjectDataBlock(); } + } + for (int j = 0; j < count; j++) + { ObjectData[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length++; + for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } + if (Header.AckList != null && 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)ObjectData.Length; + for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int ObjectDataStart = 0; + do + { + int variableLength = 0; + int ObjectDataCount = 0; + + i = ObjectDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < ObjectData.Length) { + int blockLength = ObjectData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ObjectDataStart) { + variableLength += blockLength; + ++ObjectDataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)ObjectDataCount; + for (i = ObjectDataStart; i < ObjectDataStart + ObjectDataCount; i++) { ObjectData[i].ToBytes(packet, ref length); } + ObjectDataStart += ObjectDataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + ObjectDataStart < ObjectData.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class ObjectGrabPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class ObjectDataBlock : PacketBlock + { + public uint LocalID; + public Vector3 GrabOffset; + + public override int Length + { + get + { + return 16; + } + } + + public ObjectDataBlock() { } + public ObjectDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + LocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + GrabOffset.FromBytes(bytes, i); i += 12; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UIntToBytes(LocalID, bytes, i); i += 4; + GrabOffset.ToBytes(bytes, i); i += 12; + } + + } + + /// + public sealed class SurfaceInfoBlock : PacketBlock + { + public Vector3 UVCoord; + public Vector3 STCoord; + public int FaceIndex; + public Vector3 Position; + public Vector3 Normal; + public Vector3 Binormal; + + public override int Length + { + get + { + return 64; + } + } + + public SurfaceInfoBlock() { } + public SurfaceInfoBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + UVCoord.FromBytes(bytes, i); i += 12; + STCoord.FromBytes(bytes, i); i += 12; + FaceIndex = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + Position.FromBytes(bytes, i); i += 12; + Normal.FromBytes(bytes, i); i += 12; + Binormal.FromBytes(bytes, i); i += 12; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + UVCoord.ToBytes(bytes, i); i += 12; + STCoord.ToBytes(bytes, i); i += 12; + Utils.IntToBytes(FaceIndex, bytes, i); i += 4; + Position.ToBytes(bytes, i); i += 12; + Normal.ToBytes(bytes, i); i += 12; + Binormal.ToBytes(bytes, i); i += 12; + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentData.Length; + length += ObjectData.Length; + for (int j = 0; j < SurfaceInfo.Length; j++) + length += SurfaceInfo[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public ObjectDataBlock ObjectData; + public SurfaceInfoBlock[] SurfaceInfo; + + public ObjectGrabPacket() + { + HasVariableBlocks = true; + Type = PacketType.ObjectGrab; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 117; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + ObjectData = new ObjectDataBlock(); + SurfaceInfo = null; + } + + public ObjectGrabPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + ObjectData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(SurfaceInfo == null || SurfaceInfo.Length != -1) { + SurfaceInfo = new SurfaceInfoBlock[count]; + for(int j = 0; j < count; j++) + { SurfaceInfo[j] = new SurfaceInfoBlock(); } + } + for (int j = 0; j < count; j++) + { SurfaceInfo[j].FromBytes(bytes, ref i); } + } + + public ObjectGrabPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + ObjectData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(SurfaceInfo == null || SurfaceInfo.Length != count) { + SurfaceInfo = new SurfaceInfoBlock[count]; + for(int j = 0; j < count; j++) + { SurfaceInfo[j] = new SurfaceInfoBlock(); } + } + for (int j = 0; j < count; j++) + { SurfaceInfo[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += ObjectData.Length; + length++; + for (int j = 0; j < SurfaceInfo.Length; j++) { length += SurfaceInfo[j].Length; } + if (Header.AckList != null && 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); + ObjectData.ToBytes(bytes, ref i); + bytes[i++] = (byte)SurfaceInfo.Length; + for (int j = 0; j < SurfaceInfo.Length; j++) { SurfaceInfo[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + fixedLength += ObjectData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + ObjectData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int SurfaceInfoStart = 0; + do + { + int variableLength = 0; + int SurfaceInfoCount = 0; + + i = SurfaceInfoStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < SurfaceInfo.Length) { + int blockLength = SurfaceInfo[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == SurfaceInfoStart) { + variableLength += blockLength; + ++SurfaceInfoCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)SurfaceInfoCount; + for (i = SurfaceInfoStart; i < SurfaceInfoStart + SurfaceInfoCount; i++) { SurfaceInfo[i].ToBytes(packet, ref length); } + SurfaceInfoStart += SurfaceInfoCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + SurfaceInfoStart < SurfaceInfo.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class ObjectGrabUpdatePacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class ObjectDataBlock : PacketBlock + { + public UUID ObjectID; + public Vector3 GrabOffsetInitial; + public Vector3 GrabPosition; + public uint TimeSinceLast; + + public override int Length + { + get + { + return 44; + } + } + + public ObjectDataBlock() { } + public ObjectDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + ObjectID.FromBytes(bytes, i); i += 16; + GrabOffsetInitial.FromBytes(bytes, i); i += 12; + GrabPosition.FromBytes(bytes, i); i += 12; + TimeSinceLast = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + ObjectID.ToBytes(bytes, i); i += 16; + GrabOffsetInitial.ToBytes(bytes, i); i += 12; + GrabPosition.ToBytes(bytes, i); i += 12; + Utils.UIntToBytes(TimeSinceLast, bytes, i); i += 4; + } + + } + + /// + public sealed class SurfaceInfoBlock : PacketBlock + { + public Vector3 UVCoord; + public Vector3 STCoord; + public int FaceIndex; + public Vector3 Position; + public Vector3 Normal; + public Vector3 Binormal; + + public override int Length + { + get + { + return 64; + } + } + + public SurfaceInfoBlock() { } + public SurfaceInfoBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + UVCoord.FromBytes(bytes, i); i += 12; + STCoord.FromBytes(bytes, i); i += 12; + FaceIndex = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + Position.FromBytes(bytes, i); i += 12; + Normal.FromBytes(bytes, i); i += 12; + Binormal.FromBytes(bytes, i); i += 12; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + UVCoord.ToBytes(bytes, i); i += 12; + STCoord.ToBytes(bytes, i); i += 12; + Utils.IntToBytes(FaceIndex, bytes, i); i += 4; + Position.ToBytes(bytes, i); i += 12; + Normal.ToBytes(bytes, i); i += 12; + Binormal.ToBytes(bytes, i); i += 12; + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentData.Length; + length += ObjectData.Length; + for (int j = 0; j < SurfaceInfo.Length; j++) + length += SurfaceInfo[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public ObjectDataBlock ObjectData; + public SurfaceInfoBlock[] SurfaceInfo; + + public ObjectGrabUpdatePacket() + { + HasVariableBlocks = true; + Type = PacketType.ObjectGrabUpdate; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 118; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + ObjectData = new ObjectDataBlock(); + SurfaceInfo = null; + } + + public ObjectGrabUpdatePacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + ObjectData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(SurfaceInfo == null || SurfaceInfo.Length != -1) { + SurfaceInfo = new SurfaceInfoBlock[count]; + for(int j = 0; j < count; j++) + { SurfaceInfo[j] = new SurfaceInfoBlock(); } + } + for (int j = 0; j < count; j++) + { SurfaceInfo[j].FromBytes(bytes, ref i); } + } + + public ObjectGrabUpdatePacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + ObjectData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(SurfaceInfo == null || SurfaceInfo.Length != count) { + SurfaceInfo = new SurfaceInfoBlock[count]; + for(int j = 0; j < count; j++) + { SurfaceInfo[j] = new SurfaceInfoBlock(); } + } + for (int j = 0; j < count; j++) + { SurfaceInfo[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += ObjectData.Length; + length++; + for (int j = 0; j < SurfaceInfo.Length; j++) { length += SurfaceInfo[j].Length; } + if (Header.AckList != null && 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); + ObjectData.ToBytes(bytes, ref i); + bytes[i++] = (byte)SurfaceInfo.Length; + for (int j = 0; j < SurfaceInfo.Length; j++) { SurfaceInfo[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + fixedLength += ObjectData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + ObjectData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int SurfaceInfoStart = 0; + do + { + int variableLength = 0; + int SurfaceInfoCount = 0; + + i = SurfaceInfoStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < SurfaceInfo.Length) { + int blockLength = SurfaceInfo[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == SurfaceInfoStart) { + variableLength += blockLength; + ++SurfaceInfoCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)SurfaceInfoCount; + for (i = SurfaceInfoStart; i < SurfaceInfoStart + SurfaceInfoCount; i++) { SurfaceInfo[i].ToBytes(packet, ref length); } + SurfaceInfoStart += SurfaceInfoCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + SurfaceInfoStart < SurfaceInfo.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class ObjectDeGrabPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class ObjectDataBlock : PacketBlock + { + public uint LocalID; + + public override int Length + { + get + { + return 4; + } + } + + public ObjectDataBlock() { } + public ObjectDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + LocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UIntToBytes(LocalID, bytes, i); i += 4; + } + + } + + /// + public sealed class SurfaceInfoBlock : PacketBlock + { + public Vector3 UVCoord; + public Vector3 STCoord; + public int FaceIndex; + public Vector3 Position; + public Vector3 Normal; + public Vector3 Binormal; + + public override int Length + { + get + { + return 64; + } + } + + public SurfaceInfoBlock() { } + public SurfaceInfoBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + UVCoord.FromBytes(bytes, i); i += 12; + STCoord.FromBytes(bytes, i); i += 12; + FaceIndex = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + Position.FromBytes(bytes, i); i += 12; + Normal.FromBytes(bytes, i); i += 12; + Binormal.FromBytes(bytes, i); i += 12; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + UVCoord.ToBytes(bytes, i); i += 12; + STCoord.ToBytes(bytes, i); i += 12; + Utils.IntToBytes(FaceIndex, bytes, i); i += 4; + Position.ToBytes(bytes, i); i += 12; + Normal.ToBytes(bytes, i); i += 12; + Binormal.ToBytes(bytes, i); i += 12; + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentData.Length; + length += ObjectData.Length; + for (int j = 0; j < SurfaceInfo.Length; j++) + length += SurfaceInfo[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public ObjectDataBlock ObjectData; + public SurfaceInfoBlock[] SurfaceInfo; + + public ObjectDeGrabPacket() + { + HasVariableBlocks = true; + Type = PacketType.ObjectDeGrab; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 119; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + ObjectData = new ObjectDataBlock(); + SurfaceInfo = null; + } + + public ObjectDeGrabPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + ObjectData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(SurfaceInfo == null || SurfaceInfo.Length != -1) { + SurfaceInfo = new SurfaceInfoBlock[count]; + for(int j = 0; j < count; j++) + { SurfaceInfo[j] = new SurfaceInfoBlock(); } + } + for (int j = 0; j < count; j++) + { SurfaceInfo[j].FromBytes(bytes, ref i); } + } + + public ObjectDeGrabPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + ObjectData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(SurfaceInfo == null || SurfaceInfo.Length != count) { + SurfaceInfo = new SurfaceInfoBlock[count]; + for(int j = 0; j < count; j++) + { SurfaceInfo[j] = new SurfaceInfoBlock(); } + } + for (int j = 0; j < count; j++) + { SurfaceInfo[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += ObjectData.Length; + length++; + for (int j = 0; j < SurfaceInfo.Length; j++) { length += SurfaceInfo[j].Length; } + if (Header.AckList != null && 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); + ObjectData.ToBytes(bytes, ref i); + bytes[i++] = (byte)SurfaceInfo.Length; + for (int j = 0; j < SurfaceInfo.Length; j++) { SurfaceInfo[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + fixedLength += ObjectData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + ObjectData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int SurfaceInfoStart = 0; + do + { + int variableLength = 0; + int SurfaceInfoCount = 0; + + i = SurfaceInfoStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < SurfaceInfo.Length) { + int blockLength = SurfaceInfo[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == SurfaceInfoStart) { + variableLength += blockLength; + ++SurfaceInfoCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)SurfaceInfoCount; + for (i = SurfaceInfoStart; i < SurfaceInfoStart + SurfaceInfoCount; i++) { SurfaceInfo[i].ToBytes(packet, ref length); } + SurfaceInfoStart += SurfaceInfoCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + SurfaceInfoStart < SurfaceInfo.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class ObjectSpinStartPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class ObjectDataBlock : PacketBlock + { + public UUID ObjectID; + + public override int Length + { + get + { + return 16; + } + } + + public ObjectDataBlock() { } + public ObjectDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + ObjectID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + ObjectID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += ObjectData.Length; + return length; + } + } + public AgentDataBlock AgentData; + public ObjectDataBlock ObjectData; + + public ObjectSpinStartPacket() + { + HasVariableBlocks = false; + Type = PacketType.ObjectSpinStart; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 120; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + ObjectData = new ObjectDataBlock(); + } + + public ObjectSpinStartPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + ObjectData.FromBytes(bytes, ref i); + } + + public ObjectSpinStartPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + ObjectData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += ObjectData.Length; + if (Header.AckList != null && 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); + ObjectData.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class ObjectSpinUpdatePacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class ObjectDataBlock : PacketBlock + { + public UUID ObjectID; + public Quaternion Rotation; + + public override int Length + { + get + { + return 28; + } + } + + public ObjectDataBlock() { } + public ObjectDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + ObjectID.FromBytes(bytes, i); i += 16; + Rotation.FromBytes(bytes, i, true); i += 12; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + ObjectID.ToBytes(bytes, i); i += 16; + Rotation.ToBytes(bytes, i); i += 12; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += ObjectData.Length; + return length; + } + } + public AgentDataBlock AgentData; + public ObjectDataBlock ObjectData; + + public ObjectSpinUpdatePacket() + { + HasVariableBlocks = false; + Type = PacketType.ObjectSpinUpdate; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 121; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + ObjectData = new ObjectDataBlock(); + } + + public ObjectSpinUpdatePacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + ObjectData.FromBytes(bytes, ref i); + } + + public ObjectSpinUpdatePacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + ObjectData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += ObjectData.Length; + if (Header.AckList != null && 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); + ObjectData.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class ObjectSpinStopPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class ObjectDataBlock : PacketBlock + { + public UUID ObjectID; + + public override int Length + { + get + { + return 16; + } + } + + public ObjectDataBlock() { } + public ObjectDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + ObjectID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + ObjectID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += ObjectData.Length; + return length; + } + } + public AgentDataBlock AgentData; + public ObjectDataBlock ObjectData; + + public ObjectSpinStopPacket() + { + HasVariableBlocks = false; + Type = PacketType.ObjectSpinStop; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 122; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + ObjectData = new ObjectDataBlock(); + } + + public ObjectSpinStopPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + ObjectData.FromBytes(bytes, ref i); + } + + public ObjectSpinStopPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + ObjectData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += ObjectData.Length; + if (Header.AckList != null && 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); + ObjectData.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class ObjectExportSelectedPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID RequestID; + public short VolumeDetail; + + public override int Length + { + get + { + return 34; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + RequestID.FromBytes(bytes, i); i += 16; + VolumeDetail = (short)(bytes[i++] + (bytes[i++] << 8)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + RequestID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)(VolumeDetail % 256); + bytes[i++] = (byte)((VolumeDetail >> 8) % 256); + } + + } + + /// + public sealed class ObjectDataBlock : PacketBlock + { + public UUID ObjectID; + + public override int Length + { + get + { + return 16; + } + } + + public ObjectDataBlock() { } + public ObjectDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + ObjectID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + ObjectID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentData.Length; + for (int j = 0; j < ObjectData.Length; j++) + length += ObjectData[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public ObjectDataBlock[] ObjectData; + + public ObjectExportSelectedPacket() + { + HasVariableBlocks = true; + Type = PacketType.ObjectExportSelected; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 123; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + ObjectData = null; + } + + public ObjectExportSelectedPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ObjectData == null || ObjectData.Length != -1) { + ObjectData = new ObjectDataBlock[count]; + for(int j = 0; j < count; j++) + { ObjectData[j] = new ObjectDataBlock(); } + } + for (int j = 0; j < count; j++) + { ObjectData[j].FromBytes(bytes, ref i); } + } + + public ObjectExportSelectedPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ObjectData == null || ObjectData.Length != count) { + ObjectData = new ObjectDataBlock[count]; + for(int j = 0; j < count; j++) + { ObjectData[j] = new ObjectDataBlock(); } + } + for (int j = 0; j < count; j++) + { ObjectData[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length++; + for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } + if (Header.AckList != null && 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)ObjectData.Length; + for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int ObjectDataStart = 0; + do + { + int variableLength = 0; + int ObjectDataCount = 0; + + i = ObjectDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < ObjectData.Length) { + int blockLength = ObjectData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ObjectDataStart) { + variableLength += blockLength; + ++ObjectDataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)ObjectDataCount; + for (i = ObjectDataStart; i < ObjectDataStart + ObjectDataCount; i++) { ObjectData[i].ToBytes(packet, ref length); } + ObjectDataStart += ObjectDataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + ObjectDataStart < ObjectData.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class ModifyLandPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class ModifyBlockBlock : PacketBlock + { + public byte Action; + public byte BrushSize; + public float Seconds; + public float Height; + + public override int Length + { + get + { + return 10; + } + } + + public ModifyBlockBlock() { } + public ModifyBlockBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + Action = (byte)bytes[i++]; + BrushSize = (byte)bytes[i++]; + Seconds = Utils.BytesToFloat(bytes, i); i += 4; + Height = Utils.BytesToFloat(bytes, i); i += 4; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + bytes[i++] = Action; + bytes[i++] = BrushSize; + Utils.FloatToBytes(Seconds, bytes, i); i += 4; + Utils.FloatToBytes(Height, bytes, i); i += 4; + } + + } + + /// + public sealed class ParcelDataBlock : PacketBlock + { + public int LocalID; + public float West; + public float South; + public float East; + public float North; + + public override int Length + { + get + { + return 20; + } + } + + public ParcelDataBlock() { } + public ParcelDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + LocalID = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + West = Utils.BytesToFloat(bytes, i); i += 4; + South = Utils.BytesToFloat(bytes, i); i += 4; + East = Utils.BytesToFloat(bytes, i); i += 4; + North = Utils.BytesToFloat(bytes, i); i += 4; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.IntToBytes(LocalID, bytes, i); i += 4; + Utils.FloatToBytes(West, bytes, i); i += 4; + Utils.FloatToBytes(South, bytes, i); i += 4; + Utils.FloatToBytes(East, bytes, i); i += 4; + Utils.FloatToBytes(North, bytes, i); i += 4; + } + + } + + /// + public sealed class ModifyBlockExtendedBlock : PacketBlock + { + public float BrushSize; + + public override int Length + { + get + { + return 4; + } + } + + public ModifyBlockExtendedBlock() { } + public ModifyBlockExtendedBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + BrushSize = Utils.BytesToFloat(bytes, i); i += 4; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.FloatToBytes(BrushSize, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 12; + length += AgentData.Length; + length += ModifyBlock.Length; + for (int j = 0; j < ParcelData.Length; j++) + length += ParcelData[j].Length; + for (int j = 0; j < ModifyBlockExtended.Length; j++) + length += ModifyBlockExtended[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public ModifyBlockBlock ModifyBlock; + public ParcelDataBlock[] ParcelData; + public ModifyBlockExtendedBlock[] ModifyBlockExtended; + + public ModifyLandPacket() + { + HasVariableBlocks = true; + Type = PacketType.ModifyLand; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 124; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + ModifyBlock = new ModifyBlockBlock(); + ParcelData = null; + ModifyBlockExtended = null; + } + + public ModifyLandPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + ModifyBlock.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ParcelData == null || ParcelData.Length != -1) { + ParcelData = new ParcelDataBlock[count]; + for(int j = 0; j < count; j++) + { ParcelData[j] = new ParcelDataBlock(); } + } + for (int j = 0; j < count; j++) + { ParcelData[j].FromBytes(bytes, ref i); } + count = (int)bytes[i++]; + if(ModifyBlockExtended == null || ModifyBlockExtended.Length != -1) { + ModifyBlockExtended = new ModifyBlockExtendedBlock[count]; + for(int j = 0; j < count; j++) + { ModifyBlockExtended[j] = new ModifyBlockExtendedBlock(); } + } + for (int j = 0; j < count; j++) + { ModifyBlockExtended[j].FromBytes(bytes, ref i); } + } + + public ModifyLandPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + ModifyBlock.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ParcelData == null || ParcelData.Length != count) { + ParcelData = new ParcelDataBlock[count]; + for(int j = 0; j < count; j++) + { ParcelData[j] = new ParcelDataBlock(); } + } + for (int j = 0; j < count; j++) + { ParcelData[j].FromBytes(bytes, ref i); } + count = (int)bytes[i++]; + if(ModifyBlockExtended == null || ModifyBlockExtended.Length != count) { + ModifyBlockExtended = new ModifyBlockExtendedBlock[count]; + for(int j = 0; j < count; j++) + { ModifyBlockExtended[j] = new ModifyBlockExtendedBlock(); } + } + for (int j = 0; j < count; j++) + { ModifyBlockExtended[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += ModifyBlock.Length; + length++; + for (int j = 0; j < ParcelData.Length; j++) { length += ParcelData[j].Length; } + length++; + for (int j = 0; j < ModifyBlockExtended.Length; j++) { length += ModifyBlockExtended[j].Length; } + if (Header.AckList != null && 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); + ModifyBlock.ToBytes(bytes, ref i); + bytes[i++] = (byte)ParcelData.Length; + for (int j = 0; j < ParcelData.Length; j++) { ParcelData[j].ToBytes(bytes, ref i); } + bytes[i++] = (byte)ModifyBlockExtended.Length; + for (int j = 0; j < ModifyBlockExtended.Length; j++) { ModifyBlockExtended[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + fixedLength += ModifyBlock.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + ModifyBlock.ToBytes(fixedBytes, ref i); + fixedLength += 2; + + int ParcelDataStart = 0; + int ModifyBlockExtendedStart = 0; + do + { + int variableLength = 0; + int ParcelDataCount = 0; + int ModifyBlockExtendedCount = 0; + + i = ParcelDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < ParcelData.Length) { + int blockLength = ParcelData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ParcelDataStart) { + variableLength += blockLength; + ++ParcelDataCount; + } + else { break; } + ++i; + } + + i = ModifyBlockExtendedStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < ModifyBlockExtended.Length) { + int blockLength = ModifyBlockExtended[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ModifyBlockExtendedStart) { + variableLength += blockLength; + ++ModifyBlockExtendedCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)ParcelDataCount; + for (i = ParcelDataStart; i < ParcelDataStart + ParcelDataCount; i++) { ParcelData[i].ToBytes(packet, ref length); } + ParcelDataStart += ParcelDataCount; + + packet[length++] = (byte)ModifyBlockExtendedCount; + for (i = ModifyBlockExtendedStart; i < ModifyBlockExtendedStart + ModifyBlockExtendedCount; i++) { ModifyBlockExtended[i].ToBytes(packet, ref length); } + ModifyBlockExtendedStart += ModifyBlockExtendedCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + ParcelDataStart < ParcelData.Length || + ModifyBlockExtendedStart < ModifyBlockExtended.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class VelocityInterpolateOnPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + return length; + } + } + public AgentDataBlock AgentData; + + public VelocityInterpolateOnPacket() + { + HasVariableBlocks = false; + Type = PacketType.VelocityInterpolateOn; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 125; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + } + + public VelocityInterpolateOnPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + } + + public VelocityInterpolateOnPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class VelocityInterpolateOffPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + return length; + } + } + public AgentDataBlock AgentData; + + public VelocityInterpolateOffPacket() + { + HasVariableBlocks = false; + Type = PacketType.VelocityInterpolateOff; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 126; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + } + + public VelocityInterpolateOffPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + } + + public VelocityInterpolateOffPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class StateSavePacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class DataBlockBlock : PacketBlock + { + public byte[] Filename; + + public override int Length + { + get + { + int length = 1; + if (Filename != null) { length += Filename.Length; } + return length; + } + } + + public DataBlockBlock() { } + public DataBlockBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + length = bytes[i++]; + Filename = new byte[length]; + Buffer.BlockCopy(bytes, i, Filename, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + bytes[i++] = (byte)Filename.Length; + Buffer.BlockCopy(Filename, 0, bytes, i, Filename.Length); i += Filename.Length; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += DataBlock.Length; + return length; + } + } + public AgentDataBlock AgentData; + public DataBlockBlock DataBlock; + + public StateSavePacket() + { + HasVariableBlocks = false; + Type = PacketType.StateSave; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 127; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + DataBlock = new DataBlockBlock(); + } + + public StateSavePacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + DataBlock.FromBytes(bytes, ref i); + } + + public StateSavePacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + DataBlock.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += DataBlock.Length; + if (Header.AckList != null && 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); + DataBlock.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class ReportAutosaveCrashPacket : Packet + { + /// + public sealed class AutosaveDataBlock : PacketBlock + { + public int PID; + public int Status; + + public override int Length + { + get + { + return 8; + } + } + + public AutosaveDataBlock() { } + public AutosaveDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(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(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.IntToBytes(PID, bytes, i); i += 4; + Utils.IntToBytes(Status, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AutosaveData.Length; + return length; + } + } + public AutosaveDataBlock AutosaveData; + + public ReportAutosaveCrashPacket() + { + HasVariableBlocks = false; + Type = PacketType.ReportAutosaveCrash; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 128; + Header.Reliable = true; + AutosaveData = new AutosaveDataBlock(); + } + + public ReportAutosaveCrashPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AutosaveData.FromBytes(bytes, ref i); + } + + public ReportAutosaveCrashPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AutosaveData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AutosaveData.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class SimWideDeletesPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class DataBlockBlock : PacketBlock + { + public UUID TargetID; + public uint Flags; + + public override int Length + { + get + { + return 20; + } + } + + public DataBlockBlock() { } + public DataBlockBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + TargetID.FromBytes(bytes, i); i += 16; + Flags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + TargetID.ToBytes(bytes, i); i += 16; + Utils.UIntToBytes(Flags, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += DataBlock.Length; + return length; + } + } + public AgentDataBlock AgentData; + public DataBlockBlock DataBlock; + + public SimWideDeletesPacket() + { + HasVariableBlocks = false; + Type = PacketType.SimWideDeletes; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 129; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + DataBlock = new DataBlockBlock(); + } + + public SimWideDeletesPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + DataBlock.FromBytes(bytes, ref i); + } + + public SimWideDeletesPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + DataBlock.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += DataBlock.Length; + if (Header.AckList != null && 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); + DataBlock.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class TrackAgentPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class TargetDataBlock : PacketBlock + { + public UUID PreyID; + + public override int Length + { + get + { + return 16; + } + } + + public TargetDataBlock() { } + public TargetDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + PreyID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + PreyID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += TargetData.Length; + return length; + } + } + public AgentDataBlock AgentData; + public TargetDataBlock TargetData; + + public TrackAgentPacket() + { + HasVariableBlocks = false; + Type = PacketType.TrackAgent; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 130; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + TargetData = new TargetDataBlock(); + } + + public TrackAgentPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + TargetData.FromBytes(bytes, ref i); + } + + public TrackAgentPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + TargetData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += TargetData.Length; + if (Header.AckList != null && 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); + TargetData.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class ViewerStatsPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + public uint IP; + public uint StartTime; + public float RunTime; + public float SimFPS; + public float FPS; + public byte AgentsInView; + public float Ping; + public double MetersTraveled; + public int RegionsVisited; + public uint SysRAM; + public byte[] SysOS; + public byte[] SysCPU; + public byte[] SysGPU; + + public override int Length + { + get + { + int length = 76; + if (SysOS != null) { length += SysOS.Length; } + if (SysCPU != null) { length += SysCPU.Length; } + if (SysGPU != null) { length += SysGPU.Length; } + return length; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + IP = (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)); + RunTime = Utils.BytesToFloat(bytes, i); i += 4; + SimFPS = Utils.BytesToFloat(bytes, i); i += 4; + FPS = Utils.BytesToFloat(bytes, i); i += 4; + AgentsInView = (byte)bytes[i++]; + Ping = Utils.BytesToFloat(bytes, i); i += 4; + MetersTraveled = Utils.BytesToDouble(bytes, i); i += 8; + RegionsVisited = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + SysRAM = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + length = bytes[i++]; + SysOS = new byte[length]; + Buffer.BlockCopy(bytes, i, SysOS, 0, length); i += length; + length = bytes[i++]; + SysCPU = new byte[length]; + Buffer.BlockCopy(bytes, i, SysCPU, 0, length); i += length; + length = bytes[i++]; + SysGPU = new byte[length]; + Buffer.BlockCopy(bytes, i, SysGPU, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + Utils.UIntToBytes(IP, bytes, i); i += 4; + Utils.UIntToBytes(StartTime, bytes, i); i += 4; + Utils.FloatToBytes(RunTime, bytes, i); i += 4; + Utils.FloatToBytes(SimFPS, bytes, i); i += 4; + Utils.FloatToBytes(FPS, bytes, i); i += 4; + bytes[i++] = AgentsInView; + Utils.FloatToBytes(Ping, bytes, i); i += 4; + Utils.DoubleToBytes(MetersTraveled, bytes, i); i += 8; + Utils.IntToBytes(RegionsVisited, bytes, i); i += 4; + Utils.UIntToBytes(SysRAM, bytes, i); i += 4; + bytes[i++] = (byte)SysOS.Length; + Buffer.BlockCopy(SysOS, 0, bytes, i, SysOS.Length); i += SysOS.Length; + bytes[i++] = (byte)SysCPU.Length; + Buffer.BlockCopy(SysCPU, 0, bytes, i, SysCPU.Length); i += SysCPU.Length; + bytes[i++] = (byte)SysGPU.Length; + Buffer.BlockCopy(SysGPU, 0, bytes, i, SysGPU.Length); i += SysGPU.Length; + } + + } + + /// + public sealed class DownloadTotalsBlock : PacketBlock + { + public uint World; + public uint Objects; + public uint Textures; + + public override int Length + { + get + { + return 12; + } + } + + public DownloadTotalsBlock() { } + public DownloadTotalsBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + World = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + 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)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UIntToBytes(World, bytes, i); i += 4; + Utils.UIntToBytes(Objects, bytes, i); i += 4; + Utils.UIntToBytes(Textures, bytes, i); i += 4; + } + + } + + /// + public sealed class NetStatsBlock : PacketBlock + { + public uint Bytes; + public uint Packets; + public uint Compressed; + public uint Savings; + + public override int Length + { + get + { + return 16; + } + } + + public NetStatsBlock() { } + public NetStatsBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + Bytes = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + Packets = (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)); + Savings = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UIntToBytes(Bytes, bytes, i); i += 4; + Utils.UIntToBytes(Packets, bytes, i); i += 4; + Utils.UIntToBytes(Compressed, bytes, i); i += 4; + Utils.UIntToBytes(Savings, bytes, i); i += 4; + } + + } + + /// + public sealed class FailStatsBlock : PacketBlock + { + public uint SendPacket; + public uint Dropped; + public uint Resent; + public uint FailedResends; + public uint OffCircuit; + public uint Invalid; + + public override int Length + { + get + { + return 24; + } + } + + public FailStatsBlock() { } + public FailStatsBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + 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)); + Resent = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + FailedResends = (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)); + Invalid = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UIntToBytes(SendPacket, bytes, i); i += 4; + Utils.UIntToBytes(Dropped, bytes, i); i += 4; + Utils.UIntToBytes(Resent, bytes, i); i += 4; + Utils.UIntToBytes(FailedResends, bytes, i); i += 4; + Utils.UIntToBytes(OffCircuit, bytes, i); i += 4; + Utils.UIntToBytes(Invalid, bytes, i); i += 4; + } + + } + + /// + public sealed class MiscStatsBlock : PacketBlock + { + public uint Type; + public double Value; + + public override int Length + { + get + { + return 12; + } + } + + public MiscStatsBlock() { } + public MiscStatsBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + Type = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + Value = Utils.BytesToDouble(bytes, i); i += 8; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UIntToBytes(Type, bytes, i); i += 4; + Utils.DoubleToBytes(Value, bytes, i); i += 8; + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentData.Length; + length += DownloadTotals.Length; + for (int j = 0; j < 2; j++) + length += NetStats[j].Length; + length += FailStats.Length; + for (int j = 0; j < MiscStats.Length; j++) + length += MiscStats[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public DownloadTotalsBlock DownloadTotals; + public NetStatsBlock[] NetStats; + public FailStatsBlock FailStats; + public MiscStatsBlock[] MiscStats; + + public ViewerStatsPacket() + { + HasVariableBlocks = true; + Type = PacketType.ViewerStats; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 131; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + DownloadTotals = new DownloadTotalsBlock(); + NetStats = new NetStatsBlock[2]; + FailStats = new FailStatsBlock(); + MiscStats = null; + } + + public ViewerStatsPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + DownloadTotals.FromBytes(bytes, ref i); + if(NetStats == null || NetStats.Length != 2) { + NetStats = new NetStatsBlock[2]; + for(int j = 0; j < 2; j++) + { NetStats[j] = new NetStatsBlock(); } + } + for (int j = 0; j < 2; j++) + { NetStats[j].FromBytes(bytes, ref i); } + FailStats.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(MiscStats == null || MiscStats.Length != -1) { + MiscStats = new MiscStatsBlock[count]; + for(int j = 0; j < count; j++) + { MiscStats[j] = new MiscStatsBlock(); } + } + for (int j = 0; j < count; j++) + { MiscStats[j].FromBytes(bytes, ref i); } + } + + public ViewerStatsPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + DownloadTotals.FromBytes(bytes, ref i); + if(NetStats == null || NetStats.Length != 2) { + NetStats = new NetStatsBlock[2]; + for(int j = 0; j < 2; j++) + { NetStats[j] = new NetStatsBlock(); } + } + for (int j = 0; j < 2; j++) + { NetStats[j].FromBytes(bytes, ref i); } + FailStats.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(MiscStats == null || MiscStats.Length != count) { + MiscStats = new MiscStatsBlock[count]; + for(int j = 0; j < count; j++) + { MiscStats[j] = new MiscStatsBlock(); } + } + for (int j = 0; j < count; j++) + { MiscStats[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += DownloadTotals.Length; + length += FailStats.Length; + for (int j = 0; j < 2; j++) { length += NetStats[j].Length; } + length++; + for (int j = 0; j < MiscStats.Length; j++) { length += MiscStats[j].Length; } + if (Header.AckList != null && 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); + DownloadTotals.ToBytes(bytes, ref i); + for (int j = 0; j < 2; j++) { NetStats[j].ToBytes(bytes, ref i); } + FailStats.ToBytes(bytes, ref i); + bytes[i++] = (byte)MiscStats.Length; + for (int j = 0; j < MiscStats.Length; j++) { MiscStats[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + fixedLength += DownloadTotals.Length; + for (int j = 0; j < 2; j++) { fixedLength += NetStats[j].Length; } + fixedLength += FailStats.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + DownloadTotals.ToBytes(fixedBytes, ref i); + for (int j = 0; j < 2; j++) { NetStats[j].ToBytes(fixedBytes, ref i); } + FailStats.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int MiscStatsStart = 0; + do + { + int variableLength = 0; + int MiscStatsCount = 0; + + i = MiscStatsStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < MiscStats.Length) { + int blockLength = MiscStats[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == MiscStatsStart) { + variableLength += blockLength; + ++MiscStatsCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)MiscStatsCount; + for (i = MiscStatsStart; i < MiscStatsStart + MiscStatsCount; i++) { MiscStats[i].ToBytes(packet, ref length); } + MiscStatsStart += MiscStatsCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + MiscStatsStart < MiscStats.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class ScriptAnswerYesPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class DataBlock : PacketBlock + { + public UUID TaskID; + public UUID ItemID; + public int Questions; + + public override int Length + { + get + { + return 36; + } + } + + public DataBlock() { } + public DataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + TaskID.FromBytes(bytes, i); i += 16; + ItemID.FromBytes(bytes, i); i += 16; + Questions = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + TaskID.ToBytes(bytes, i); i += 16; + ItemID.ToBytes(bytes, i); i += 16; + Utils.IntToBytes(Questions, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += Data.Length; + return length; + } + } + public AgentDataBlock AgentData; + public DataBlock Data; + + public ScriptAnswerYesPacket() + { + HasVariableBlocks = false; + Type = PacketType.ScriptAnswerYes; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 132; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + Data = new DataBlock(); + } + + public ScriptAnswerYesPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + Data.FromBytes(bytes, ref i); + } + + public ScriptAnswerYesPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + Data.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += Data.Length; + if (Header.AckList != null && 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); + Data.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class UserReportPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class ReportDataBlock : PacketBlock + { + public byte ReportType; + public byte Category; + public Vector3 Position; + public byte CheckFlags; + public UUID ScreenshotID; + public UUID ObjectID; + public UUID AbuserID; + public byte[] AbuseRegionName; + public UUID AbuseRegionID; + public byte[] Summary; + public byte[] Details; + public byte[] VersionString; + + public override int Length + { + get + { + int length = 84; + if (AbuseRegionName != null) { length += AbuseRegionName.Length; } + if (Summary != null) { length += Summary.Length; } + if (Details != null) { length += Details.Length; } + if (VersionString != null) { length += VersionString.Length; } + return length; + } + } + + public ReportDataBlock() { } + public ReportDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + ReportType = (byte)bytes[i++]; + Category = (byte)bytes[i++]; + Position.FromBytes(bytes, i); i += 12; + CheckFlags = (byte)bytes[i++]; + ScreenshotID.FromBytes(bytes, i); i += 16; + ObjectID.FromBytes(bytes, i); i += 16; + AbuserID.FromBytes(bytes, i); i += 16; + length = bytes[i++]; + AbuseRegionName = new byte[length]; + Buffer.BlockCopy(bytes, i, AbuseRegionName, 0, length); i += length; + AbuseRegionID.FromBytes(bytes, i); i += 16; + length = bytes[i++]; + Summary = new byte[length]; + Buffer.BlockCopy(bytes, i, Summary, 0, length); i += length; + length = (bytes[i++] + (bytes[i++] << 8)); + Details = new byte[length]; + Buffer.BlockCopy(bytes, i, Details, 0, length); i += length; + length = bytes[i++]; + VersionString = new byte[length]; + Buffer.BlockCopy(bytes, i, VersionString, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + bytes[i++] = ReportType; + bytes[i++] = Category; + Position.ToBytes(bytes, i); i += 12; + bytes[i++] = CheckFlags; + ScreenshotID.ToBytes(bytes, i); i += 16; + ObjectID.ToBytes(bytes, i); i += 16; + AbuserID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)AbuseRegionName.Length; + Buffer.BlockCopy(AbuseRegionName, 0, bytes, i, AbuseRegionName.Length); i += AbuseRegionName.Length; + AbuseRegionID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)Summary.Length; + Buffer.BlockCopy(Summary, 0, bytes, i, Summary.Length); i += Summary.Length; + bytes[i++] = (byte)(Details.Length % 256); + bytes[i++] = (byte)((Details.Length >> 8) % 256); + Buffer.BlockCopy(Details, 0, bytes, i, Details.Length); i += Details.Length; + bytes[i++] = (byte)VersionString.Length; + Buffer.BlockCopy(VersionString, 0, bytes, i, VersionString.Length); i += VersionString.Length; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += ReportData.Length; + return length; + } + } + public AgentDataBlock AgentData; + public ReportDataBlock ReportData; + + public UserReportPacket() + { + HasVariableBlocks = false; + Type = PacketType.UserReport; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 133; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + ReportData = new ReportDataBlock(); + } + + public UserReportPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + ReportData.FromBytes(bytes, ref i); + } + + public UserReportPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + ReportData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += ReportData.Length; + if (Header.AckList != null && 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); + ReportData.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class AlertMessagePacket : Packet + { + /// + public sealed class AlertDataBlock : PacketBlock + { + public byte[] Message; + + public override int Length + { + get + { + int length = 1; + if (Message != null) { length += Message.Length; } + return length; + } + } + + public AlertDataBlock() { } + public AlertDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + length = bytes[i++]; + Message = new byte[length]; + Buffer.BlockCopy(bytes, i, Message, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + bytes[i++] = (byte)Message.Length; + Buffer.BlockCopy(Message, 0, bytes, i, Message.Length); i += Message.Length; + } + + } + + /// + public sealed class AlertInfoBlock : PacketBlock + { + public byte[] Message; + public byte[] ExtraParams; + + public override int Length + { + get + { + int length = 2; + if (Message != null) { length += Message.Length; } + if (ExtraParams != null) { length += ExtraParams.Length; } + return length; + } + } + + public AlertInfoBlock() { } + public AlertInfoBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + length = bytes[i++]; + Message = new byte[length]; + Buffer.BlockCopy(bytes, i, Message, 0, length); i += length; + length = bytes[i++]; + ExtraParams = new byte[length]; + Buffer.BlockCopy(bytes, i, ExtraParams, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + bytes[i++] = (byte)Message.Length; + Buffer.BlockCopy(Message, 0, bytes, i, Message.Length); i += Message.Length; + bytes[i++] = (byte)ExtraParams.Length; + Buffer.BlockCopy(ExtraParams, 0, bytes, i, ExtraParams.Length); i += ExtraParams.Length; + } + + } + + /// + public sealed class AgentInfoBlock : PacketBlock + { + public UUID AgentID; + + public override int Length + { + get + { + return 16; + } + } + + public AgentInfoBlock() { } + public AgentInfoBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 12; + length += AlertData.Length; + for (int j = 0; j < AlertInfo.Length; j++) + length += AlertInfo[j].Length; + for (int j = 0; j < AgentInfo.Length; j++) + length += AgentInfo[j].Length; + return length; + } + } + public AlertDataBlock AlertData; + public AlertInfoBlock[] AlertInfo; + public AgentInfoBlock[] AgentInfo; + + public AlertMessagePacket() + { + HasVariableBlocks = true; + Type = PacketType.AlertMessage; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 134; + Header.Reliable = true; + AlertData = new AlertDataBlock(); + AlertInfo = null; + AgentInfo = null; + } + + public AlertMessagePacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AlertData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(AlertInfo == null || AlertInfo.Length != -1) { + AlertInfo = new AlertInfoBlock[count]; + for(int j = 0; j < count; j++) + { AlertInfo[j] = new AlertInfoBlock(); } + } + for (int j = 0; j < count; j++) + { AlertInfo[j].FromBytes(bytes, ref i); } + count = (int)bytes[i++]; + if(AgentInfo == null || AgentInfo.Length != -1) { + AgentInfo = new AgentInfoBlock[count]; + for(int j = 0; j < count; j++) + { AgentInfo[j] = new AgentInfoBlock(); } + } + for (int j = 0; j < count; j++) + { AgentInfo[j].FromBytes(bytes, ref i); } + } + + public AlertMessagePacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AlertData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(AlertInfo == null || AlertInfo.Length != count) { + AlertInfo = new AlertInfoBlock[count]; + for(int j = 0; j < count; j++) + { AlertInfo[j] = new AlertInfoBlock(); } + } + for (int j = 0; j < count; j++) + { AlertInfo[j].FromBytes(bytes, ref i); } + count = (int)bytes[i++]; + if(AgentInfo == null || AgentInfo.Length != count) { + AgentInfo = new AgentInfoBlock[count]; + for(int j = 0; j < count; j++) + { AgentInfo[j] = new AgentInfoBlock(); } + } + for (int j = 0; j < count; j++) + { AgentInfo[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AlertData.Length; + length++; + for (int j = 0; j < AlertInfo.Length; j++) { length += AlertInfo[j].Length; } + length++; + for (int j = 0; j < AgentInfo.Length; j++) { length += AgentInfo[j].Length; } + if (Header.AckList != null && 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); + bytes[i++] = (byte)AlertInfo.Length; + for (int j = 0; j < AlertInfo.Length; j++) { AlertInfo[j].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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AlertData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AlertData.ToBytes(fixedBytes, ref i); + fixedLength += 2; + + int AlertInfoStart = 0; + int AgentInfoStart = 0; + do + { + int variableLength = 0; + int AlertInfoCount = 0; + int AgentInfoCount = 0; + + i = AlertInfoStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < AlertInfo.Length) { + int blockLength = AlertInfo[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == AlertInfoStart) { + variableLength += blockLength; + ++AlertInfoCount; + } + else { break; } + ++i; + } + + i = AgentInfoStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < AgentInfo.Length) { + int blockLength = AgentInfo[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == AgentInfoStart) { + variableLength += blockLength; + ++AgentInfoCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)AlertInfoCount; + for (i = AlertInfoStart; i < AlertInfoStart + AlertInfoCount; i++) { AlertInfo[i].ToBytes(packet, ref length); } + AlertInfoStart += AlertInfoCount; + + packet[length++] = (byte)AgentInfoCount; + for (i = AgentInfoStart; i < AgentInfoStart + AgentInfoCount; i++) { AgentInfo[i].ToBytes(packet, ref length); } + AgentInfoStart += AgentInfoCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + AlertInfoStart < AlertInfo.Length || + AgentInfoStart < AgentInfo.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class AgentAlertMessagePacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + + public override int Length + { + get + { + return 16; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class AlertDataBlock : PacketBlock + { + public bool Modal; + public byte[] Message; + + public override int Length + { + get + { + int length = 2; + if (Message != null) { length += Message.Length; } + return length; + } + } + + public AlertDataBlock() { } + public AlertDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + Modal = (bytes[i++] != 0) ? (bool)true : (bool)false; + length = bytes[i++]; + Message = new byte[length]; + Buffer.BlockCopy(bytes, i, Message, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + bytes[i++] = (byte)((Modal) ? 1 : 0); + bytes[i++] = (byte)Message.Length; + Buffer.BlockCopy(Message, 0, bytes, i, Message.Length); i += Message.Length; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += AlertData.Length; + return length; + } + } + public AgentDataBlock AgentData; + public AlertDataBlock AlertData; + + public AgentAlertMessagePacket() + { + HasVariableBlocks = false; + Type = PacketType.AgentAlertMessage; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 135; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + AlertData = new AlertDataBlock(); + } + + public AgentAlertMessagePacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + AlertData.FromBytes(bytes, ref i); + } + + public AgentAlertMessagePacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + AlertData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += AlertData.Length; + if (Header.AckList != null && 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); + AlertData.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class MeanCollisionAlertPacket : Packet + { + /// + public sealed class MeanCollisionBlock : PacketBlock + { + public UUID Victim; + public UUID Perp; + public uint Time; + public float Mag; + public byte Type; + + public override int Length + { + get + { + return 41; + } + } + + public MeanCollisionBlock() { } + public MeanCollisionBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + Victim.FromBytes(bytes, i); i += 16; + Perp.FromBytes(bytes, i); i += 16; + Time = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + Mag = Utils.BytesToFloat(bytes, i); i += 4; + Type = (byte)bytes[i++]; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Victim.ToBytes(bytes, i); i += 16; + Perp.ToBytes(bytes, i); i += 16; + Utils.UIntToBytes(Time, bytes, i); i += 4; + Utils.FloatToBytes(Mag, bytes, i); i += 4; + bytes[i++] = Type; + } + + } + + public override int Length + { + get + { + int length = 11; + for (int j = 0; j < MeanCollision.Length; j++) + length += MeanCollision[j].Length; + return length; + } + } + public MeanCollisionBlock[] MeanCollision; + + public MeanCollisionAlertPacket() + { + HasVariableBlocks = true; + Type = PacketType.MeanCollisionAlert; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 136; + Header.Reliable = true; + Header.Zerocoded = true; + MeanCollision = null; + } + + public MeanCollisionAlertPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + int count = (int)bytes[i++]; + if(MeanCollision == null || MeanCollision.Length != -1) { + MeanCollision = new MeanCollisionBlock[count]; + for(int j = 0; j < count; j++) + { MeanCollision[j] = new MeanCollisionBlock(); } + } + for (int j = 0; j < count; j++) + { MeanCollision[j].FromBytes(bytes, ref i); } + } + + public MeanCollisionAlertPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + int count = (int)bytes[i++]; + if(MeanCollision == null || MeanCollision.Length != count) { + MeanCollision = new MeanCollisionBlock[count]; + for(int j = 0; j < count; j++) + { MeanCollision[j] = new MeanCollisionBlock(); } + } + for (int j = 0; j < count; j++) + { MeanCollision[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length++; + for (int j = 0; j < MeanCollision.Length; j++) { length += MeanCollision[j].Length; } + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int MeanCollisionStart = 0; + do + { + int variableLength = 0; + int MeanCollisionCount = 0; + + i = MeanCollisionStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < MeanCollision.Length) { + int blockLength = MeanCollision[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == MeanCollisionStart) { + variableLength += blockLength; + ++MeanCollisionCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)MeanCollisionCount; + for (i = MeanCollisionStart; i < MeanCollisionStart + MeanCollisionCount; i++) { MeanCollision[i].ToBytes(packet, ref length); } + MeanCollisionStart += MeanCollisionCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + MeanCollisionStart < MeanCollision.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class ViewerFrozenMessagePacket : Packet + { + /// + public sealed class FrozenDataBlock : PacketBlock + { + public bool Data; + + public override int Length + { + get + { + return 1; + } + } + + public FrozenDataBlock() { } + public FrozenDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + Data = (bytes[i++] != 0) ? (bool)true : (bool)false; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + bytes[i++] = (byte)((Data) ? 1 : 0); + } + + } + + public override int Length + { + get + { + int length = 10; + length += FrozenData.Length; + return length; + } + } + public FrozenDataBlock FrozenData; + + public ViewerFrozenMessagePacket() + { + HasVariableBlocks = false; + Type = PacketType.ViewerFrozenMessage; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 137; + Header.Reliable = true; + FrozenData = new FrozenDataBlock(); + } + + public ViewerFrozenMessagePacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + FrozenData.FromBytes(bytes, ref i); + } + + public ViewerFrozenMessagePacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + FrozenData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += FrozenData.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class HealthMessagePacket : Packet + { + /// + public sealed class HealthDataBlock : PacketBlock + { + public float Health; + + public override int Length + { + get + { + return 4; + } + } + + public HealthDataBlock() { } + public HealthDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + Health = Utils.BytesToFloat(bytes, i); i += 4; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.FloatToBytes(Health, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 10; + length += HealthData.Length; + return length; + } + } + public HealthDataBlock HealthData; + + public HealthMessagePacket() + { + HasVariableBlocks = false; + Type = PacketType.HealthMessage; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 138; + Header.Reliable = true; + Header.Zerocoded = true; + HealthData = new HealthDataBlock(); + } + + public HealthMessagePacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + HealthData.FromBytes(bytes, ref i); + } + + public HealthMessagePacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + HealthData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += HealthData.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class ChatFromSimulatorPacket : Packet + { + /// + public sealed class ChatDataBlock : PacketBlock + { + public byte[] FromName; + public UUID SourceID; + public UUID OwnerID; + public byte SourceType; + public byte ChatType; + public byte Audible; + public Vector3 Position; + public byte[] Message; + + public override int Length + { + get + { + int length = 50; + if (FromName != null) { length += FromName.Length; } + if (Message != null) { length += Message.Length; } + return length; + } + } + + public ChatDataBlock() { } + public ChatDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + length = bytes[i++]; + FromName = new byte[length]; + Buffer.BlockCopy(bytes, i, FromName, 0, length); i += length; + SourceID.FromBytes(bytes, i); i += 16; + OwnerID.FromBytes(bytes, i); i += 16; + SourceType = (byte)bytes[i++]; + ChatType = (byte)bytes[i++]; + Audible = (byte)bytes[i++]; + Position.FromBytes(bytes, i); i += 12; + length = (bytes[i++] + (bytes[i++] << 8)); + Message = new byte[length]; + Buffer.BlockCopy(bytes, i, Message, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + bytes[i++] = (byte)FromName.Length; + Buffer.BlockCopy(FromName, 0, bytes, i, FromName.Length); i += FromName.Length; + SourceID.ToBytes(bytes, i); i += 16; + OwnerID.ToBytes(bytes, i); i += 16; + bytes[i++] = SourceType; + bytes[i++] = ChatType; + bytes[i++] = Audible; + Position.ToBytes(bytes, i); i += 12; + bytes[i++] = (byte)(Message.Length % 256); + bytes[i++] = (byte)((Message.Length >> 8) % 256); + Buffer.BlockCopy(Message, 0, bytes, i, Message.Length); i += Message.Length; + } + + } + + public override int Length + { + get + { + int length = 10; + length += ChatData.Length; + return length; + } + } + public ChatDataBlock ChatData; + + public ChatFromSimulatorPacket() + { + HasVariableBlocks = false; + Type = PacketType.ChatFromSimulator; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 139; + Header.Reliable = true; + ChatData = new ChatDataBlock(); + } + + public ChatFromSimulatorPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + ChatData.FromBytes(bytes, ref i); + } + + public ChatFromSimulatorPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + ChatData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += ChatData.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class SimStatsPacket : Packet + { + /// + public sealed class RegionBlock : PacketBlock + { + public uint RegionX; + public uint RegionY; + public uint RegionFlags; + public uint ObjectCapacity; + + public override int Length + { + get + { + return 16; + } + } + + public RegionBlock() { } + public RegionBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(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(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UIntToBytes(RegionX, bytes, i); i += 4; + Utils.UIntToBytes(RegionY, bytes, i); i += 4; + Utils.UIntToBytes(RegionFlags, bytes, i); i += 4; + Utils.UIntToBytes(ObjectCapacity, bytes, i); i += 4; + } + + } + + /// + public sealed class StatBlock : PacketBlock + { + public uint StatID; + public float StatValue; + + public override int Length + { + get + { + return 8; + } + } + + public StatBlock() { } + public StatBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + StatID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + StatValue = Utils.BytesToFloat(bytes, i); i += 4; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UIntToBytes(StatID, bytes, i); i += 4; + Utils.FloatToBytes(StatValue, bytes, i); i += 4; + } + + } + + /// + public sealed class PidStatBlock : PacketBlock + { + public int PID; + + public override int Length + { + get + { + return 4; + } + } + + public PidStatBlock() { } + public PidStatBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + PID = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.IntToBytes(PID, bytes, i); i += 4; + } + + } + + /// + public sealed class RegionInfoBlock : PacketBlock + { + public ulong RegionFlagsExtended; + + public override int Length + { + get + { + return 8; + } + } + + public RegionInfoBlock() { } + public RegionInfoBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + RegionFlagsExtended = (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(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UInt64ToBytes(RegionFlagsExtended, bytes, i); i += 8; + } + + } + + public override int Length + { + get + { + int length = 12; + length += Region.Length; + for (int j = 0; j < Stat.Length; j++) + length += Stat[j].Length; + length += PidStat.Length; + for (int j = 0; j < RegionInfo.Length; j++) + length += RegionInfo[j].Length; + return length; + } + } + public RegionBlock Region; + public StatBlock[] Stat; + public PidStatBlock PidStat; + public RegionInfoBlock[] RegionInfo; + + public SimStatsPacket() + { + HasVariableBlocks = true; + Type = PacketType.SimStats; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 140; + Header.Reliable = true; + Region = new RegionBlock(); + Stat = null; + PidStat = new PidStatBlock(); + RegionInfo = null; + } + + public SimStatsPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + Region.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(Stat == null || Stat.Length != -1) { + Stat = new StatBlock[count]; + for(int j = 0; j < count; j++) + { Stat[j] = new StatBlock(); } + } + for (int j = 0; j < count; j++) + { Stat[j].FromBytes(bytes, ref i); } + PidStat.FromBytes(bytes, ref i); + count = (int)bytes[i++]; + if(RegionInfo == null || RegionInfo.Length != -1) { + RegionInfo = new RegionInfoBlock[count]; + for(int j = 0; j < count; j++) + { RegionInfo[j] = new RegionInfoBlock(); } + } + for (int j = 0; j < count; j++) + { RegionInfo[j].FromBytes(bytes, ref i); } + } + + public SimStatsPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + Region.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(Stat == null || Stat.Length != count) { + Stat = new StatBlock[count]; + for(int j = 0; j < count; j++) + { Stat[j] = new StatBlock(); } + } + for (int j = 0; j < count; j++) + { Stat[j].FromBytes(bytes, ref i); } + PidStat.FromBytes(bytes, ref i); + count = (int)bytes[i++]; + if(RegionInfo == null || RegionInfo.Length != count) { + RegionInfo = new RegionInfoBlock[count]; + for(int j = 0; j < count; j++) + { RegionInfo[j] = new RegionInfoBlock(); } + } + for (int j = 0; j < count; j++) + { RegionInfo[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += Region.Length; + length += PidStat.Length; + length++; + for (int j = 0; j < Stat.Length; j++) { length += Stat[j].Length; } + length++; + for (int j = 0; j < RegionInfo.Length; j++) { length += RegionInfo[j].Length; } + if (Header.AckList != null && Header.AckList.Length > 0) { length += Header.AckList.Length * 4 + 1; } + byte[] bytes = new byte[length]; + int i = 0; + Header.ToBytes(bytes, ref i); + Region.ToBytes(bytes, ref i); + bytes[i++] = (byte)Stat.Length; + for (int j = 0; j < Stat.Length; j++) { Stat[j].ToBytes(bytes, ref i); } + PidStat.ToBytes(bytes, ref i); + bytes[i++] = (byte)RegionInfo.Length; + for (int j = 0; j < RegionInfo.Length; j++) { RegionInfo[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class RequestRegionInfoPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + return length; + } + } + public AgentDataBlock AgentData; + + public RequestRegionInfoPacket() + { + HasVariableBlocks = false; + Type = PacketType.RequestRegionInfo; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 141; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + } + + public RequestRegionInfoPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + } + + public RequestRegionInfoPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class RegionInfoPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class RegionInfoBlock : PacketBlock + { + public byte[] SimName; + public uint EstateID; + public uint ParentEstateID; + public uint RegionFlags; + public byte SimAccess; + public byte MaxAgents; + public float BillableFactor; + public float ObjectBonusFactor; + public float WaterHeight; + public float TerrainRaiseLimit; + public float TerrainLowerLimit; + public int PricePerMeter; + public int RedirectGridX; + public int RedirectGridY; + public bool UseEstateSun; + public float SunHour; + + public override int Length + { + get + { + int length = 52; + if (SimName != null) { length += SimName.Length; } + return length; + } + } + + public RegionInfoBlock() { } + public RegionInfoBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + length = bytes[i++]; + SimName = new byte[length]; + Buffer.BlockCopy(bytes, i, SimName, 0, length); i += length; + EstateID = (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)); + RegionFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + SimAccess = (byte)bytes[i++]; + MaxAgents = (byte)bytes[i++]; + BillableFactor = Utils.BytesToFloat(bytes, i); i += 4; + ObjectBonusFactor = Utils.BytesToFloat(bytes, i); i += 4; + WaterHeight = Utils.BytesToFloat(bytes, i); i += 4; + TerrainRaiseLimit = Utils.BytesToFloat(bytes, i); i += 4; + TerrainLowerLimit = Utils.BytesToFloat(bytes, i); i += 4; + PricePerMeter = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + 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)); + UseEstateSun = (bytes[i++] != 0) ? (bool)true : (bool)false; + SunHour = Utils.BytesToFloat(bytes, i); i += 4; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + bytes[i++] = (byte)SimName.Length; + Buffer.BlockCopy(SimName, 0, bytes, i, SimName.Length); i += SimName.Length; + Utils.UIntToBytes(EstateID, bytes, i); i += 4; + Utils.UIntToBytes(ParentEstateID, bytes, i); i += 4; + Utils.UIntToBytes(RegionFlags, bytes, i); i += 4; + bytes[i++] = SimAccess; + bytes[i++] = MaxAgents; + Utils.FloatToBytes(BillableFactor, bytes, i); i += 4; + Utils.FloatToBytes(ObjectBonusFactor, bytes, i); i += 4; + Utils.FloatToBytes(WaterHeight, bytes, i); i += 4; + Utils.FloatToBytes(TerrainRaiseLimit, bytes, i); i += 4; + Utils.FloatToBytes(TerrainLowerLimit, bytes, i); i += 4; + Utils.IntToBytes(PricePerMeter, bytes, i); i += 4; + Utils.IntToBytes(RedirectGridX, bytes, i); i += 4; + Utils.IntToBytes(RedirectGridY, bytes, i); i += 4; + bytes[i++] = (byte)((UseEstateSun) ? 1 : 0); + Utils.FloatToBytes(SunHour, bytes, i); i += 4; + } + + } + + /// + public sealed class RegionInfo2Block : PacketBlock + { + public byte[] ProductSKU; + public byte[] ProductName; + public uint MaxAgents32; + public uint HardMaxAgents; + public uint HardMaxObjects; + + public override int Length + { + get + { + int length = 14; + if (ProductSKU != null) { length += ProductSKU.Length; } + if (ProductName != null) { length += ProductName.Length; } + return length; + } + } + + public RegionInfo2Block() { } + public RegionInfo2Block(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + length = bytes[i++]; + ProductSKU = new byte[length]; + Buffer.BlockCopy(bytes, i, ProductSKU, 0, length); i += length; + length = bytes[i++]; + ProductName = new byte[length]; + Buffer.BlockCopy(bytes, i, ProductName, 0, length); i += length; + MaxAgents32 = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + HardMaxAgents = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + HardMaxObjects = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + bytes[i++] = (byte)ProductSKU.Length; + Buffer.BlockCopy(ProductSKU, 0, bytes, i, ProductSKU.Length); i += ProductSKU.Length; + bytes[i++] = (byte)ProductName.Length; + Buffer.BlockCopy(ProductName, 0, bytes, i, ProductName.Length); i += ProductName.Length; + Utils.UIntToBytes(MaxAgents32, bytes, i); i += 4; + Utils.UIntToBytes(HardMaxAgents, bytes, i); i += 4; + Utils.UIntToBytes(HardMaxObjects, bytes, i); i += 4; + } + + } + + /// + public sealed class RegionInfo3Block : PacketBlock + { + public ulong RegionFlagsExtended; + + public override int Length + { + get + { + return 8; + } + } + + public RegionInfo3Block() { } + public RegionInfo3Block(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + RegionFlagsExtended = (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(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UInt64ToBytes(RegionFlagsExtended, bytes, i); i += 8; + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentData.Length; + length += RegionInfo.Length; + length += RegionInfo2.Length; + for (int j = 0; j < RegionInfo3.Length; j++) + length += RegionInfo3[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public RegionInfoBlock RegionInfo; + public RegionInfo2Block RegionInfo2; + public RegionInfo3Block[] RegionInfo3; + + public RegionInfoPacket() + { + HasVariableBlocks = true; + Type = PacketType.RegionInfo; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 142; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + RegionInfo = new RegionInfoBlock(); + RegionInfo2 = new RegionInfo2Block(); + RegionInfo3 = null; + } + + public RegionInfoPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + RegionInfo.FromBytes(bytes, ref i); + RegionInfo2.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(RegionInfo3 == null || RegionInfo3.Length != -1) { + RegionInfo3 = new RegionInfo3Block[count]; + for(int j = 0; j < count; j++) + { RegionInfo3[j] = new RegionInfo3Block(); } + } + for (int j = 0; j < count; j++) + { RegionInfo3[j].FromBytes(bytes, ref i); } + } + + public RegionInfoPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + RegionInfo.FromBytes(bytes, ref i); + RegionInfo2.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(RegionInfo3 == null || RegionInfo3.Length != count) { + RegionInfo3 = new RegionInfo3Block[count]; + for(int j = 0; j < count; j++) + { RegionInfo3[j] = new RegionInfo3Block(); } + } + for (int j = 0; j < count; j++) + { RegionInfo3[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += RegionInfo.Length; + length += RegionInfo2.Length; + length++; + for (int j = 0; j < RegionInfo3.Length; j++) { length += RegionInfo3[j].Length; } + if (Header.AckList != null && 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); + RegionInfo.ToBytes(bytes, ref i); + RegionInfo2.ToBytes(bytes, ref i); + bytes[i++] = (byte)RegionInfo3.Length; + for (int j = 0; j < RegionInfo3.Length; j++) { RegionInfo3[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + fixedLength += RegionInfo.Length; + fixedLength += RegionInfo2.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + RegionInfo.ToBytes(fixedBytes, ref i); + RegionInfo2.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int RegionInfo3Start = 0; + do + { + int variableLength = 0; + int RegionInfo3Count = 0; + + i = RegionInfo3Start; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < RegionInfo3.Length) { + int blockLength = RegionInfo3[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == RegionInfo3Start) { + variableLength += blockLength; + ++RegionInfo3Count; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)RegionInfo3Count; + for (i = RegionInfo3Start; i < RegionInfo3Start + RegionInfo3Count; i++) { RegionInfo3[i].ToBytes(packet, ref length); } + RegionInfo3Start += RegionInfo3Count; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + RegionInfo3Start < RegionInfo3.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class GodUpdateRegionInfoPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class RegionInfoBlock : PacketBlock + { + public byte[] SimName; + public uint EstateID; + public uint ParentEstateID; + public uint RegionFlags; + public float BillableFactor; + public int PricePerMeter; + public int RedirectGridX; + public int RedirectGridY; + + public override int Length + { + get + { + int length = 29; + if (SimName != null) { length += SimName.Length; } + return length; + } + } + + public RegionInfoBlock() { } + public RegionInfoBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + length = bytes[i++]; + SimName = new byte[length]; + Buffer.BlockCopy(bytes, i, SimName, 0, length); i += length; + EstateID = (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)); + RegionFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + BillableFactor = Utils.BytesToFloat(bytes, i); i += 4; + PricePerMeter = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + 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)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + bytes[i++] = (byte)SimName.Length; + Buffer.BlockCopy(SimName, 0, bytes, i, SimName.Length); i += SimName.Length; + Utils.UIntToBytes(EstateID, bytes, i); i += 4; + Utils.UIntToBytes(ParentEstateID, bytes, i); i += 4; + Utils.UIntToBytes(RegionFlags, bytes, i); i += 4; + Utils.FloatToBytes(BillableFactor, bytes, i); i += 4; + Utils.IntToBytes(PricePerMeter, bytes, i); i += 4; + Utils.IntToBytes(RedirectGridX, bytes, i); i += 4; + Utils.IntToBytes(RedirectGridY, bytes, i); i += 4; + } + + } + + /// + public sealed class RegionInfo2Block : PacketBlock + { + public ulong RegionFlagsExtended; + + public override int Length + { + get + { + return 8; + } + } + + public RegionInfo2Block() { } + public RegionInfo2Block(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + RegionFlagsExtended = (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(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UInt64ToBytes(RegionFlagsExtended, bytes, i); i += 8; + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentData.Length; + length += RegionInfo.Length; + for (int j = 0; j < RegionInfo2.Length; j++) + length += RegionInfo2[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public RegionInfoBlock RegionInfo; + public RegionInfo2Block[] RegionInfo2; + + public GodUpdateRegionInfoPacket() + { + HasVariableBlocks = true; + Type = PacketType.GodUpdateRegionInfo; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 143; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + RegionInfo = new RegionInfoBlock(); + RegionInfo2 = null; + } + + public GodUpdateRegionInfoPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + RegionInfo.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(RegionInfo2 == null || RegionInfo2.Length != -1) { + RegionInfo2 = new RegionInfo2Block[count]; + for(int j = 0; j < count; j++) + { RegionInfo2[j] = new RegionInfo2Block(); } + } + for (int j = 0; j < count; j++) + { RegionInfo2[j].FromBytes(bytes, ref i); } + } + + public GodUpdateRegionInfoPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + RegionInfo.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(RegionInfo2 == null || RegionInfo2.Length != count) { + RegionInfo2 = new RegionInfo2Block[count]; + for(int j = 0; j < count; j++) + { RegionInfo2[j] = new RegionInfo2Block(); } + } + for (int j = 0; j < count; j++) + { RegionInfo2[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += RegionInfo.Length; + length++; + for (int j = 0; j < RegionInfo2.Length; j++) { length += RegionInfo2[j].Length; } + if (Header.AckList != null && 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); + RegionInfo.ToBytes(bytes, ref i); + bytes[i++] = (byte)RegionInfo2.Length; + for (int j = 0; j < RegionInfo2.Length; j++) { RegionInfo2[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + fixedLength += RegionInfo.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + RegionInfo.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int RegionInfo2Start = 0; + do + { + int variableLength = 0; + int RegionInfo2Count = 0; + + i = RegionInfo2Start; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < RegionInfo2.Length) { + int blockLength = RegionInfo2[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == RegionInfo2Start) { + variableLength += blockLength; + ++RegionInfo2Count; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)RegionInfo2Count; + for (i = RegionInfo2Start; i < RegionInfo2Start + RegionInfo2Count; i++) { RegionInfo2[i].ToBytes(packet, ref length); } + RegionInfo2Start += RegionInfo2Count; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + RegionInfo2Start < RegionInfo2.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class RegionHandshakePacket : Packet + { + /// + public sealed class RegionInfoBlock : PacketBlock + { + public uint RegionFlags; + public byte SimAccess; + public byte[] SimName; + public UUID SimOwner; + public bool IsEstateManager; + public float WaterHeight; + public float BillableFactor; + public UUID CacheID; + public UUID TerrainBase0; + public UUID TerrainBase1; + public UUID TerrainBase2; + public UUID TerrainBase3; + public UUID TerrainDetail0; + public UUID TerrainDetail1; + public UUID TerrainDetail2; + public UUID TerrainDetail3; + public float TerrainStartHeight00; + public float TerrainStartHeight01; + public float TerrainStartHeight10; + public float TerrainStartHeight11; + public float TerrainHeightRange00; + public float TerrainHeightRange01; + public float TerrainHeightRange10; + public float TerrainHeightRange11; + + public override int Length + { + get + { + int length = 207; + if (SimName != null) { length += SimName.Length; } + return length; + } + } + + public RegionInfoBlock() { } + public RegionInfoBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + RegionFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + SimAccess = (byte)bytes[i++]; + length = bytes[i++]; + SimName = new byte[length]; + Buffer.BlockCopy(bytes, i, SimName, 0, length); i += length; + SimOwner.FromBytes(bytes, i); i += 16; + IsEstateManager = (bytes[i++] != 0) ? (bool)true : (bool)false; + WaterHeight = Utils.BytesToFloat(bytes, i); i += 4; + BillableFactor = Utils.BytesToFloat(bytes, i); i += 4; + CacheID.FromBytes(bytes, i); i += 16; + TerrainBase0.FromBytes(bytes, i); i += 16; + TerrainBase1.FromBytes(bytes, i); i += 16; + TerrainBase2.FromBytes(bytes, i); i += 16; + TerrainBase3.FromBytes(bytes, i); i += 16; + TerrainDetail0.FromBytes(bytes, i); i += 16; + TerrainDetail1.FromBytes(bytes, i); i += 16; + TerrainDetail2.FromBytes(bytes, i); i += 16; + TerrainDetail3.FromBytes(bytes, i); i += 16; + TerrainStartHeight00 = Utils.BytesToFloat(bytes, i); i += 4; + TerrainStartHeight01 = Utils.BytesToFloat(bytes, i); i += 4; + TerrainStartHeight10 = Utils.BytesToFloat(bytes, i); i += 4; + TerrainStartHeight11 = Utils.BytesToFloat(bytes, i); i += 4; + TerrainHeightRange00 = Utils.BytesToFloat(bytes, i); i += 4; + TerrainHeightRange01 = Utils.BytesToFloat(bytes, i); i += 4; + TerrainHeightRange10 = Utils.BytesToFloat(bytes, i); i += 4; + TerrainHeightRange11 = Utils.BytesToFloat(bytes, i); i += 4; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UIntToBytes(RegionFlags, bytes, i); i += 4; + bytes[i++] = SimAccess; + bytes[i++] = (byte)SimName.Length; + Buffer.BlockCopy(SimName, 0, bytes, i, SimName.Length); i += SimName.Length; + SimOwner.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)((IsEstateManager) ? 1 : 0); + Utils.FloatToBytes(WaterHeight, bytes, i); i += 4; + Utils.FloatToBytes(BillableFactor, bytes, i); i += 4; + CacheID.ToBytes(bytes, i); i += 16; + TerrainBase0.ToBytes(bytes, i); i += 16; + TerrainBase1.ToBytes(bytes, i); i += 16; + TerrainBase2.ToBytes(bytes, i); i += 16; + TerrainBase3.ToBytes(bytes, i); i += 16; + TerrainDetail0.ToBytes(bytes, i); i += 16; + TerrainDetail1.ToBytes(bytes, i); i += 16; + TerrainDetail2.ToBytes(bytes, i); i += 16; + TerrainDetail3.ToBytes(bytes, i); i += 16; + Utils.FloatToBytes(TerrainStartHeight00, bytes, i); i += 4; + Utils.FloatToBytes(TerrainStartHeight01, bytes, i); i += 4; + Utils.FloatToBytes(TerrainStartHeight10, bytes, i); i += 4; + Utils.FloatToBytes(TerrainStartHeight11, bytes, i); i += 4; + Utils.FloatToBytes(TerrainHeightRange00, bytes, i); i += 4; + Utils.FloatToBytes(TerrainHeightRange01, bytes, i); i += 4; + Utils.FloatToBytes(TerrainHeightRange10, bytes, i); i += 4; + Utils.FloatToBytes(TerrainHeightRange11, bytes, i); i += 4; + } + + } + + /// + public sealed class RegionInfo2Block : PacketBlock + { + public UUID RegionID; + + public override int Length + { + get + { + return 16; + } + } + + public RegionInfo2Block() { } + public RegionInfo2Block(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + RegionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + RegionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class RegionInfo3Block : PacketBlock + { + public int CPUClassID; + public int CPURatio; + public byte[] ColoName; + public byte[] ProductSKU; + public byte[] ProductName; + + public override int Length + { + get + { + int length = 11; + if (ColoName != null) { length += ColoName.Length; } + if (ProductSKU != null) { length += ProductSKU.Length; } + if (ProductName != null) { length += ProductName.Length; } + return length; + } + } + + public RegionInfo3Block() { } + public RegionInfo3Block(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + CPUClassID = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + CPURatio = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + length = bytes[i++]; + ColoName = new byte[length]; + Buffer.BlockCopy(bytes, i, ColoName, 0, length); i += length; + length = bytes[i++]; + ProductSKU = new byte[length]; + Buffer.BlockCopy(bytes, i, ProductSKU, 0, length); i += length; + length = bytes[i++]; + ProductName = new byte[length]; + Buffer.BlockCopy(bytes, i, ProductName, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.IntToBytes(CPUClassID, bytes, i); i += 4; + Utils.IntToBytes(CPURatio, bytes, i); i += 4; + bytes[i++] = (byte)ColoName.Length; + Buffer.BlockCopy(ColoName, 0, bytes, i, ColoName.Length); i += ColoName.Length; + bytes[i++] = (byte)ProductSKU.Length; + Buffer.BlockCopy(ProductSKU, 0, bytes, i, ProductSKU.Length); i += ProductSKU.Length; + bytes[i++] = (byte)ProductName.Length; + Buffer.BlockCopy(ProductName, 0, bytes, i, ProductName.Length); i += ProductName.Length; + } + + } + + /// + public sealed class RegionInfo4Block : PacketBlock + { + public ulong RegionFlagsExtended; + public ulong RegionProtocols; + + public override int Length + { + get + { + return 16; + } + } + + public RegionInfo4Block() { } + public RegionInfo4Block(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + RegionFlagsExtended = (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)); + RegionProtocols = (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(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UInt64ToBytes(RegionFlagsExtended, bytes, i); i += 8; + Utils.UInt64ToBytes(RegionProtocols, bytes, i); i += 8; + } + + } + + public override int Length + { + get + { + int length = 11; + length += RegionInfo.Length; + length += RegionInfo2.Length; + length += RegionInfo3.Length; + for (int j = 0; j < RegionInfo4.Length; j++) + length += RegionInfo4[j].Length; + return length; + } + } + public RegionInfoBlock RegionInfo; + public RegionInfo2Block RegionInfo2; + public RegionInfo3Block RegionInfo3; + public RegionInfo4Block[] RegionInfo4; + + public RegionHandshakePacket() + { + HasVariableBlocks = true; + Type = PacketType.RegionHandshake; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 148; + Header.Reliable = true; + Header.Zerocoded = true; + RegionInfo = new RegionInfoBlock(); + RegionInfo2 = new RegionInfo2Block(); + RegionInfo3 = new RegionInfo3Block(); + RegionInfo4 = null; + } + + public RegionHandshakePacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + RegionInfo.FromBytes(bytes, ref i); + RegionInfo2.FromBytes(bytes, ref i); + RegionInfo3.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(RegionInfo4 == null || RegionInfo4.Length != -1) { + RegionInfo4 = new RegionInfo4Block[count]; + for(int j = 0; j < count; j++) + { RegionInfo4[j] = new RegionInfo4Block(); } + } + for (int j = 0; j < count; j++) + { RegionInfo4[j].FromBytes(bytes, ref i); } + } + + public RegionHandshakePacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + RegionInfo.FromBytes(bytes, ref i); + RegionInfo2.FromBytes(bytes, ref i); + RegionInfo3.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(RegionInfo4 == null || RegionInfo4.Length != count) { + RegionInfo4 = new RegionInfo4Block[count]; + for(int j = 0; j < count; j++) + { RegionInfo4[j] = new RegionInfo4Block(); } + } + for (int j = 0; j < count; j++) + { RegionInfo4[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += RegionInfo.Length; + length += RegionInfo2.Length; + length += RegionInfo3.Length; + length++; + for (int j = 0; j < RegionInfo4.Length; j++) { length += RegionInfo4[j].Length; } + if (Header.AckList != null && 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); + RegionInfo2.ToBytes(bytes, ref i); + RegionInfo3.ToBytes(bytes, ref i); + bytes[i++] = (byte)RegionInfo4.Length; + for (int j = 0; j < RegionInfo4.Length; j++) { RegionInfo4[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += RegionInfo.Length; + fixedLength += RegionInfo2.Length; + fixedLength += RegionInfo3.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + RegionInfo.ToBytes(fixedBytes, ref i); + RegionInfo2.ToBytes(fixedBytes, ref i); + RegionInfo3.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int RegionInfo4Start = 0; + do + { + int variableLength = 0; + int RegionInfo4Count = 0; + + i = RegionInfo4Start; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < RegionInfo4.Length) { + int blockLength = RegionInfo4[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == RegionInfo4Start) { + variableLength += blockLength; + ++RegionInfo4Count; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)RegionInfo4Count; + for (i = RegionInfo4Start; i < RegionInfo4Start + RegionInfo4Count; i++) { RegionInfo4[i].ToBytes(packet, ref length); } + RegionInfo4Start += RegionInfo4Count; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + RegionInfo4Start < RegionInfo4.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class RegionHandshakeReplyPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class RegionInfoBlock : PacketBlock + { + public uint Flags; + + public override int Length + { + get + { + return 4; + } + } + + public RegionInfoBlock() { } + public RegionInfoBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + Flags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UIntToBytes(Flags, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += RegionInfo.Length; + return length; + } + } + public AgentDataBlock AgentData; + public RegionInfoBlock RegionInfo; + + public RegionHandshakeReplyPacket() + { + HasVariableBlocks = false; + Type = PacketType.RegionHandshakeReply; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 149; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + RegionInfo = new RegionInfoBlock(); + } + + public RegionHandshakeReplyPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + RegionInfo.FromBytes(bytes, ref i); + } + + public RegionHandshakeReplyPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + RegionInfo.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += RegionInfo.Length; + if (Header.AckList != null && 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); + RegionInfo.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class SimulatorViewerTimeMessagePacket : Packet + { + /// + public sealed class TimeInfoBlock : PacketBlock + { + public ulong UsecSinceStart; + public uint SecPerDay; + public uint SecPerYear; + public Vector3 SunDirection; + public float SunPhase; + public Vector3 SunAngVelocity; + + public override int Length + { + get + { + return 44; + } + } + + public TimeInfoBlock() { } + public TimeInfoBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + 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)); + SecPerDay = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + SecPerYear = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + SunDirection.FromBytes(bytes, i); i += 12; + SunPhase = Utils.BytesToFloat(bytes, i); i += 4; + SunAngVelocity.FromBytes(bytes, i); i += 12; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UInt64ToBytes(UsecSinceStart, bytes, i); i += 8; + Utils.UIntToBytes(SecPerDay, bytes, i); i += 4; + Utils.UIntToBytes(SecPerYear, bytes, i); i += 4; + SunDirection.ToBytes(bytes, i); i += 12; + Utils.FloatToBytes(SunPhase, bytes, i); i += 4; + SunAngVelocity.ToBytes(bytes, i); i += 12; + } + + } + + public override int Length + { + get + { + int length = 10; + length += TimeInfo.Length; + return length; + } + } + public TimeInfoBlock TimeInfo; + + public SimulatorViewerTimeMessagePacket() + { + HasVariableBlocks = false; + Type = PacketType.SimulatorViewerTimeMessage; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 150; + Header.Reliable = true; + TimeInfo = new TimeInfoBlock(); + } + + public SimulatorViewerTimeMessagePacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + TimeInfo.FromBytes(bytes, ref i); + } + + public SimulatorViewerTimeMessagePacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + TimeInfo.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += TimeInfo.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class EnableSimulatorPacket : Packet + { + /// + public sealed class SimulatorInfoBlock : PacketBlock + { + public ulong Handle; + public uint IP; + public ushort Port; + + public override int Length + { + get + { + return 14; + } + } + + public SimulatorInfoBlock() { } + public SimulatorInfoBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + 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)); + 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(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UInt64ToBytes(Handle, bytes, i); i += 8; + Utils.UIntToBytes(IP, bytes, i); i += 4; + bytes[i++] = (byte)((Port >> 8) % 256); + bytes[i++] = (byte)(Port % 256); + } + + } + + public override int Length + { + get + { + int length = 10; + length += SimulatorInfo.Length; + return length; + } + } + public SimulatorInfoBlock SimulatorInfo; + + public EnableSimulatorPacket() + { + HasVariableBlocks = false; + Type = PacketType.EnableSimulator; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 151; + Header.Reliable = true; + SimulatorInfo = new SimulatorInfoBlock(); + } + + public EnableSimulatorPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + SimulatorInfo.FromBytes(bytes, ref i); + } + + public EnableSimulatorPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + SimulatorInfo.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += SimulatorInfo.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class DisableSimulatorPacket : Packet + { + public override int Length + { + get + { + int length = 10; + return length; + } + } + + public DisableSimulatorPacket() + { + HasVariableBlocks = false; + Type = PacketType.DisableSimulator; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 152; + Header.Reliable = true; + } + + public DisableSimulatorPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + } + + public DisableSimulatorPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + } + + public override byte[] ToBytes() + { + int length = 10; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class TransferRequestPacket : Packet + { + /// + public sealed class TransferInfoBlock : PacketBlock + { + public UUID TransferID; + public int ChannelType; + public int SourceType; + public float Priority; + public byte[] Params; + + public override int Length + { + get + { + int length = 30; + if (Params != null) { length += Params.Length; } + return length; + } + } + + public TransferInfoBlock() { } + public TransferInfoBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + TransferID.FromBytes(bytes, i); i += 16; + 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)); + Priority = Utils.BytesToFloat(bytes, i); i += 4; + length = (bytes[i++] + (bytes[i++] << 8)); + Params = new byte[length]; + Buffer.BlockCopy(bytes, i, Params, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + TransferID.ToBytes(bytes, i); i += 16; + Utils.IntToBytes(ChannelType, bytes, i); i += 4; + Utils.IntToBytes(SourceType, bytes, i); i += 4; + Utils.FloatToBytes(Priority, bytes, i); i += 4; + bytes[i++] = (byte)(Params.Length % 256); + bytes[i++] = (byte)((Params.Length >> 8) % 256); + Buffer.BlockCopy(Params, 0, bytes, i, Params.Length); i += Params.Length; + } + + } + + public override int Length + { + get + { + int length = 10; + length += TransferInfo.Length; + return length; + } + } + public TransferInfoBlock TransferInfo; + + public TransferRequestPacket() + { + HasVariableBlocks = false; + Type = PacketType.TransferRequest; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 153; + Header.Reliable = true; + Header.Zerocoded = true; + TransferInfo = new TransferInfoBlock(); + } + + public TransferRequestPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + TransferInfo.FromBytes(bytes, ref i); + } + + public TransferRequestPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + TransferInfo.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += TransferInfo.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class TransferInfoPacket : Packet + { + /// + public sealed class TransferInfoBlock : PacketBlock + { + public UUID TransferID; + public int ChannelType; + public int TargetType; + public int Status; + public int Size; + public byte[] Params; + + public override int Length + { + get + { + int length = 34; + if (Params != null) { length += Params.Length; } + return length; + } + } + + public TransferInfoBlock() { } + public TransferInfoBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + TransferID.FromBytes(bytes, i); i += 16; + 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)); + Size = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + length = (bytes[i++] + (bytes[i++] << 8)); + Params = new byte[length]; + Buffer.BlockCopy(bytes, i, Params, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + TransferID.ToBytes(bytes, i); i += 16; + Utils.IntToBytes(ChannelType, bytes, i); i += 4; + Utils.IntToBytes(TargetType, bytes, i); i += 4; + Utils.IntToBytes(Status, bytes, i); i += 4; + Utils.IntToBytes(Size, bytes, i); i += 4; + bytes[i++] = (byte)(Params.Length % 256); + bytes[i++] = (byte)((Params.Length >> 8) % 256); + Buffer.BlockCopy(Params, 0, bytes, i, Params.Length); i += Params.Length; + } + + } + + public override int Length + { + get + { + int length = 10; + length += TransferInfo.Length; + return length; + } + } + public TransferInfoBlock TransferInfo; + + public TransferInfoPacket() + { + HasVariableBlocks = false; + Type = PacketType.TransferInfo; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 154; + Header.Reliable = true; + Header.Zerocoded = true; + TransferInfo = new TransferInfoBlock(); + } + + public TransferInfoPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + TransferInfo.FromBytes(bytes, ref i); + } + + public TransferInfoPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + TransferInfo.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += TransferInfo.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class TransferAbortPacket : Packet + { + /// + public sealed class TransferInfoBlock : PacketBlock + { + public UUID TransferID; + public int ChannelType; + + public override int Length + { + get + { + return 20; + } + } + + public TransferInfoBlock() { } + public TransferInfoBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + TransferID.FromBytes(bytes, i); i += 16; + ChannelType = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + TransferID.ToBytes(bytes, i); i += 16; + Utils.IntToBytes(ChannelType, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 10; + length += TransferInfo.Length; + return length; + } + } + public TransferInfoBlock TransferInfo; + + public TransferAbortPacket() + { + HasVariableBlocks = false; + Type = PacketType.TransferAbort; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 155; + Header.Reliable = true; + Header.Zerocoded = true; + TransferInfo = new TransferInfoBlock(); + } + + public TransferAbortPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + TransferInfo.FromBytes(bytes, ref i); + } + + public TransferAbortPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + TransferInfo.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += TransferInfo.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class RequestXferPacket : Packet + { + /// + public sealed class XferIDBlock : PacketBlock + { + public ulong ID; + public byte[] Filename; + public byte FilePath; + public bool DeleteOnCompletion; + public bool UseBigPackets; + public UUID VFileID; + public short VFileType; + + public override int Length + { + get + { + int length = 30; + if (Filename != null) { length += Filename.Length; } + return length; + } + } + + public XferIDBlock() { } + public XferIDBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(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)); + length = bytes[i++]; + Filename = new byte[length]; + Buffer.BlockCopy(bytes, i, Filename, 0, length); i += length; + FilePath = (byte)bytes[i++]; + DeleteOnCompletion = (bytes[i++] != 0) ? (bool)true : (bool)false; + UseBigPackets = (bytes[i++] != 0) ? (bool)true : (bool)false; + VFileID.FromBytes(bytes, i); i += 16; + VFileType = (short)(bytes[i++] + (bytes[i++] << 8)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UInt64ToBytes(ID, bytes, i); i += 8; + bytes[i++] = (byte)Filename.Length; + Buffer.BlockCopy(Filename, 0, bytes, i, Filename.Length); i += Filename.Length; + bytes[i++] = FilePath; + bytes[i++] = (byte)((DeleteOnCompletion) ? 1 : 0); + bytes[i++] = (byte)((UseBigPackets) ? 1 : 0); + VFileID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)(VFileType % 256); + bytes[i++] = (byte)((VFileType >> 8) % 256); + } + + } + + public override int Length + { + get + { + int length = 10; + length += XferID.Length; + return length; + } + } + public XferIDBlock XferID; + + public RequestXferPacket() + { + HasVariableBlocks = false; + Type = PacketType.RequestXfer; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 156; + Header.Reliable = true; + Header.Zerocoded = true; + XferID = new XferIDBlock(); + } + + public RequestXferPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + XferID.FromBytes(bytes, ref i); + } + + public RequestXferPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + XferID.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += XferID.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class AbortXferPacket : Packet + { + /// + public sealed class XferIDBlock : PacketBlock + { + public ulong ID; + public int Result; + + public override int Length + { + get + { + return 12; + } + } + + public XferIDBlock() { } + public XferIDBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(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(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UInt64ToBytes(ID, bytes, i); i += 8; + Utils.IntToBytes(Result, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 10; + length += XferID.Length; + return length; + } + } + public XferIDBlock XferID; + + public AbortXferPacket() + { + HasVariableBlocks = false; + Type = PacketType.AbortXfer; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 157; + Header.Reliable = true; + XferID = new XferIDBlock(); + } + + public AbortXferPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + XferID.FromBytes(bytes, ref i); + } + + public AbortXferPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + XferID.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += XferID.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class AvatarAppearancePacket : Packet + { + /// + public sealed class SenderBlock : PacketBlock + { + public UUID ID; + public bool IsTrial; + + public override int Length + { + get + { + return 17; + } + } + + public SenderBlock() { } + public SenderBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + ID.FromBytes(bytes, i); i += 16; + IsTrial = (bytes[i++] != 0) ? (bool)true : (bool)false; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + ID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)((IsTrial) ? 1 : 0); + } + + } + + /// + public sealed class ObjectDataBlock : PacketBlock + { + public byte[] TextureEntry; + + public override int Length + { + get + { + int length = 2; + if (TextureEntry != null) { length += TextureEntry.Length; } + return length; + } + } + + public ObjectDataBlock() { } + public ObjectDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + length = (bytes[i++] + (bytes[i++] << 8)); + TextureEntry = new byte[length]; + Buffer.BlockCopy(bytes, i, TextureEntry, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + bytes[i++] = (byte)(TextureEntry.Length % 256); + bytes[i++] = (byte)((TextureEntry.Length >> 8) % 256); + Buffer.BlockCopy(TextureEntry, 0, bytes, i, TextureEntry.Length); i += TextureEntry.Length; + } + + } + + /// + public sealed class VisualParamBlock : PacketBlock + { + public byte ParamValue; + + public override int Length + { + get + { + return 1; + } + } + + public VisualParamBlock() { } + public VisualParamBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + ParamValue = (byte)bytes[i++]; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + bytes[i++] = ParamValue; + } + + } + + /// + public sealed class AppearanceDataBlock : PacketBlock + { + public byte AppearanceVersion; + public int CofVersion; + public uint Flags; + + public override int Length + { + get + { + return 9; + } + } + + public AppearanceDataBlock() { } + public AppearanceDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AppearanceVersion = (byte)bytes[i++]; + CofVersion = (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(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + bytes[i++] = AppearanceVersion; + Utils.IntToBytes(CofVersion, bytes, i); i += 4; + Utils.UIntToBytes(Flags, bytes, i); i += 4; + } + + } + + /// + public sealed class AppearanceHoverBlock : PacketBlock + { + public Vector3 HoverHeight; + + public override int Length + { + get + { + return 12; + } + } + + public AppearanceHoverBlock() { } + public AppearanceHoverBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + HoverHeight.FromBytes(bytes, i); i += 12; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + HoverHeight.ToBytes(bytes, i); i += 12; + } + + } + + public override int Length + { + get + { + int length = 13; + length += Sender.Length; + length += ObjectData.Length; + for (int j = 0; j < VisualParam.Length; j++) + length += VisualParam[j].Length; + for (int j = 0; j < AppearanceData.Length; j++) + length += AppearanceData[j].Length; + for (int j = 0; j < AppearanceHover.Length; j++) + length += AppearanceHover[j].Length; + return length; + } + } + public SenderBlock Sender; + public ObjectDataBlock ObjectData; + public VisualParamBlock[] VisualParam; + public AppearanceDataBlock[] AppearanceData; + public AppearanceHoverBlock[] AppearanceHover; + + public AvatarAppearancePacket() + { + HasVariableBlocks = true; + Type = PacketType.AvatarAppearance; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 158; + Header.Reliable = true; + Header.Zerocoded = true; + Sender = new SenderBlock(); + ObjectData = new ObjectDataBlock(); + VisualParam = null; + AppearanceData = null; + AppearanceHover = null; + } + + public AvatarAppearancePacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + Sender.FromBytes(bytes, ref i); + ObjectData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(VisualParam == null || VisualParam.Length != -1) { + VisualParam = new VisualParamBlock[count]; + for(int j = 0; j < count; j++) + { VisualParam[j] = new VisualParamBlock(); } + } + for (int j = 0; j < count; j++) + { VisualParam[j].FromBytes(bytes, ref i); } + count = (int)bytes[i++]; + if(AppearanceData == null || AppearanceData.Length != -1) { + AppearanceData = new AppearanceDataBlock[count]; + for(int j = 0; j < count; j++) + { AppearanceData[j] = new AppearanceDataBlock(); } + } + for (int j = 0; j < count; j++) + { AppearanceData[j].FromBytes(bytes, ref i); } + count = (int)bytes[i++]; + if(AppearanceHover == null || AppearanceHover.Length != -1) { + AppearanceHover = new AppearanceHoverBlock[count]; + for(int j = 0; j < count; j++) + { AppearanceHover[j] = new AppearanceHoverBlock(); } + } + for (int j = 0; j < count; j++) + { AppearanceHover[j].FromBytes(bytes, ref i); } + } + + public AvatarAppearancePacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + Sender.FromBytes(bytes, ref i); + ObjectData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(VisualParam == null || VisualParam.Length != count) { + VisualParam = new VisualParamBlock[count]; + for(int j = 0; j < count; j++) + { VisualParam[j] = new VisualParamBlock(); } + } + for (int j = 0; j < count; j++) + { VisualParam[j].FromBytes(bytes, ref i); } + count = (int)bytes[i++]; + if(AppearanceData == null || AppearanceData.Length != count) { + AppearanceData = new AppearanceDataBlock[count]; + for(int j = 0; j < count; j++) + { AppearanceData[j] = new AppearanceDataBlock(); } + } + for (int j = 0; j < count; j++) + { AppearanceData[j].FromBytes(bytes, ref i); } + count = (int)bytes[i++]; + if(AppearanceHover == null || AppearanceHover.Length != count) { + AppearanceHover = new AppearanceHoverBlock[count]; + for(int j = 0; j < count; j++) + { AppearanceHover[j] = new AppearanceHoverBlock(); } + } + for (int j = 0; j < count; j++) + { AppearanceHover[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += Sender.Length; + length += ObjectData.Length; + length++; + for (int j = 0; j < VisualParam.Length; j++) { length += VisualParam[j].Length; } + length++; + for (int j = 0; j < AppearanceData.Length; j++) { length += AppearanceData[j].Length; } + length++; + for (int j = 0; j < AppearanceHover.Length; j++) { length += AppearanceHover[j].Length; } + if (Header.AckList != null && 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); + ObjectData.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)AppearanceData.Length; + for (int j = 0; j < AppearanceData.Length; j++) { AppearanceData[j].ToBytes(bytes, ref i); } + bytes[i++] = (byte)AppearanceHover.Length; + for (int j = 0; j < AppearanceHover.Length; j++) { AppearanceHover[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += Sender.Length; + fixedLength += ObjectData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + Sender.ToBytes(fixedBytes, ref i); + ObjectData.ToBytes(fixedBytes, ref i); + fixedLength += 3; + + int VisualParamStart = 0; + int AppearanceDataStart = 0; + int AppearanceHoverStart = 0; + do + { + int variableLength = 0; + int VisualParamCount = 0; + int AppearanceDataCount = 0; + int AppearanceHoverCount = 0; + + i = VisualParamStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < VisualParam.Length) { + int blockLength = VisualParam[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == VisualParamStart) { + variableLength += blockLength; + ++VisualParamCount; + } + else { break; } + ++i; + } + + i = AppearanceDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < AppearanceData.Length) { + int blockLength = AppearanceData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == AppearanceDataStart) { + variableLength += blockLength; + ++AppearanceDataCount; + } + else { break; } + ++i; + } + + i = AppearanceHoverStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < AppearanceHover.Length) { + int blockLength = AppearanceHover[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == AppearanceHoverStart) { + variableLength += blockLength; + ++AppearanceHoverCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)VisualParamCount; + for (i = VisualParamStart; i < VisualParamStart + VisualParamCount; i++) { VisualParam[i].ToBytes(packet, ref length); } + VisualParamStart += VisualParamCount; + + packet[length++] = (byte)AppearanceDataCount; + for (i = AppearanceDataStart; i < AppearanceDataStart + AppearanceDataCount; i++) { AppearanceData[i].ToBytes(packet, ref length); } + AppearanceDataStart += AppearanceDataCount; + + packet[length++] = (byte)AppearanceHoverCount; + for (i = AppearanceHoverStart; i < AppearanceHoverStart + AppearanceHoverCount; i++) { AppearanceHover[i].ToBytes(packet, ref length); } + AppearanceHoverStart += AppearanceHoverCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + VisualParamStart < VisualParam.Length || + AppearanceDataStart < AppearanceData.Length || + AppearanceHoverStart < AppearanceHover.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class SetFollowCamPropertiesPacket : Packet + { + /// + public sealed class ObjectDataBlock : PacketBlock + { + public UUID ObjectID; + + public override int Length + { + get + { + return 16; + } + } + + public ObjectDataBlock() { } + public ObjectDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + ObjectID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + ObjectID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class CameraPropertyBlock : PacketBlock + { + public int Type; + public float Value; + + public override int Length + { + get + { + return 8; + } + } + + public CameraPropertyBlock() { } + public CameraPropertyBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + Type = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + Value = Utils.BytesToFloat(bytes, i); i += 4; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.IntToBytes(Type, bytes, i); i += 4; + Utils.FloatToBytes(Value, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 11; + length += ObjectData.Length; + for (int j = 0; j < CameraProperty.Length; j++) + length += CameraProperty[j].Length; + return length; + } + } + public ObjectDataBlock ObjectData; + public CameraPropertyBlock[] CameraProperty; + + public SetFollowCamPropertiesPacket() + { + HasVariableBlocks = true; + Type = PacketType.SetFollowCamProperties; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 159; + Header.Reliable = true; + ObjectData = new ObjectDataBlock(); + CameraProperty = null; + } + + public SetFollowCamPropertiesPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + ObjectData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(CameraProperty == null || CameraProperty.Length != -1) { + CameraProperty = new CameraPropertyBlock[count]; + for(int j = 0; j < count; j++) + { CameraProperty[j] = new CameraPropertyBlock(); } + } + for (int j = 0; j < count; j++) + { CameraProperty[j].FromBytes(bytes, ref i); } + } + + public SetFollowCamPropertiesPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + ObjectData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(CameraProperty == null || CameraProperty.Length != count) { + CameraProperty = new CameraPropertyBlock[count]; + for(int j = 0; j < count; j++) + { CameraProperty[j] = new CameraPropertyBlock(); } + } + for (int j = 0; j < count; j++) + { CameraProperty[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += ObjectData.Length; + length++; + for (int j = 0; j < CameraProperty.Length; j++) { length += CameraProperty[j].Length; } + if (Header.AckList != null && 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)CameraProperty.Length; + for (int j = 0; j < CameraProperty.Length; j++) { CameraProperty[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += ObjectData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + ObjectData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int CameraPropertyStart = 0; + do + { + int variableLength = 0; + int CameraPropertyCount = 0; + + i = CameraPropertyStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < CameraProperty.Length) { + int blockLength = CameraProperty[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == CameraPropertyStart) { + variableLength += blockLength; + ++CameraPropertyCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)CameraPropertyCount; + for (i = CameraPropertyStart; i < CameraPropertyStart + CameraPropertyCount; i++) { CameraProperty[i].ToBytes(packet, ref length); } + CameraPropertyStart += CameraPropertyCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + CameraPropertyStart < CameraProperty.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class ClearFollowCamPropertiesPacket : Packet + { + /// + public sealed class ObjectDataBlock : PacketBlock + { + public UUID ObjectID; + + public override int Length + { + get + { + return 16; + } + } + + public ObjectDataBlock() { } + public ObjectDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + ObjectID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + ObjectID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 10; + length += ObjectData.Length; + return length; + } + } + public ObjectDataBlock ObjectData; + + public ClearFollowCamPropertiesPacket() + { + HasVariableBlocks = false; + Type = PacketType.ClearFollowCamProperties; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 160; + Header.Reliable = true; + ObjectData = new ObjectDataBlock(); + } + + public ClearFollowCamPropertiesPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + ObjectData.FromBytes(bytes, ref i); + } + + public ClearFollowCamPropertiesPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + ObjectData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += ObjectData.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class RequestPayPricePacket : Packet + { + /// + public sealed class ObjectDataBlock : PacketBlock + { + public UUID ObjectID; + + public override int Length + { + get + { + return 16; + } + } + + public ObjectDataBlock() { } + public ObjectDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + ObjectID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + ObjectID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 10; + length += ObjectData.Length; + return length; + } + } + public ObjectDataBlock ObjectData; + + public RequestPayPricePacket() + { + HasVariableBlocks = false; + Type = PacketType.RequestPayPrice; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 161; + Header.Reliable = true; + ObjectData = new ObjectDataBlock(); + } + + public RequestPayPricePacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + ObjectData.FromBytes(bytes, ref i); + } + + public RequestPayPricePacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + ObjectData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += ObjectData.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class PayPriceReplyPacket : Packet + { + /// + public sealed class ObjectDataBlock : PacketBlock + { + public UUID ObjectID; + public int DefaultPayPrice; + + public override int Length + { + get + { + return 20; + } + } + + public ObjectDataBlock() { } + public ObjectDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + ObjectID.FromBytes(bytes, i); i += 16; + DefaultPayPrice = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + ObjectID.ToBytes(bytes, i); i += 16; + Utils.IntToBytes(DefaultPayPrice, bytes, i); i += 4; + } + + } + + /// + public sealed class ButtonDataBlock : PacketBlock + { + public int PayButton; + + public override int Length + { + get + { + return 4; + } + } + + public ButtonDataBlock() { } + public ButtonDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + PayButton = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.IntToBytes(PayButton, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 11; + length += ObjectData.Length; + for (int j = 0; j < ButtonData.Length; j++) + length += ButtonData[j].Length; + return length; + } + } + public ObjectDataBlock ObjectData; + public ButtonDataBlock[] ButtonData; + + public PayPriceReplyPacket() + { + HasVariableBlocks = true; + Type = PacketType.PayPriceReply; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 162; + Header.Reliable = true; + ObjectData = new ObjectDataBlock(); + ButtonData = null; + } + + public PayPriceReplyPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + ObjectData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ButtonData == null || ButtonData.Length != -1) { + ButtonData = new ButtonDataBlock[count]; + for(int j = 0; j < count; j++) + { ButtonData[j] = new ButtonDataBlock(); } + } + for (int j = 0; j < count; j++) + { ButtonData[j].FromBytes(bytes, ref i); } + } + + public PayPriceReplyPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + ObjectData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ButtonData == null || ButtonData.Length != count) { + ButtonData = new ButtonDataBlock[count]; + for(int j = 0; j < count; j++) + { ButtonData[j] = new ButtonDataBlock(); } + } + for (int j = 0; j < count; j++) + { ButtonData[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += ObjectData.Length; + length++; + for (int j = 0; j < ButtonData.Length; j++) { length += ButtonData[j].Length; } + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += ObjectData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + ObjectData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int ButtonDataStart = 0; + do + { + int variableLength = 0; + int ButtonDataCount = 0; + + i = ButtonDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < ButtonData.Length) { + int blockLength = ButtonData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ButtonDataStart) { + variableLength += blockLength; + ++ButtonDataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)ButtonDataCount; + for (i = ButtonDataStart; i < ButtonDataStart + ButtonDataCount; i++) { ButtonData[i].ToBytes(packet, ref length); } + ButtonDataStart += ButtonDataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + ButtonDataStart < ButtonData.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class KickUserPacket : Packet + { + /// + public sealed class TargetBlockBlock : PacketBlock + { + public uint TargetIP; + public ushort TargetPort; + + public override int Length + { + get + { + return 6; + } + } + + public TargetBlockBlock() { } + public TargetBlockBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(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(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UIntToBytes(TargetIP, bytes, i); i += 4; + bytes[i++] = (byte)((TargetPort >> 8) % 256); + bytes[i++] = (byte)(TargetPort % 256); + } + + } + + /// + public sealed class UserInfoBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + public byte[] Reason; + + public override int Length + { + get + { + int length = 34; + if (Reason != null) { length += Reason.Length; } + return length; + } + } + + public UserInfoBlock() { } + public UserInfoBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + length = (bytes[i++] + (bytes[i++] << 8)); + Reason = new byte[length]; + Buffer.BlockCopy(bytes, i, Reason, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)(Reason.Length % 256); + bytes[i++] = (byte)((Reason.Length >> 8) % 256); + Buffer.BlockCopy(Reason, 0, bytes, i, Reason.Length); i += Reason.Length; + } + + } + + public override int Length + { + get + { + int length = 10; + length += TargetBlock.Length; + length += UserInfo.Length; + return length; + } + } + public TargetBlockBlock TargetBlock; + public UserInfoBlock UserInfo; + + public KickUserPacket() + { + HasVariableBlocks = false; + Type = PacketType.KickUser; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 163; + Header.Reliable = true; + TargetBlock = new TargetBlockBlock(); + UserInfo = new UserInfoBlock(); + } + + public KickUserPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + TargetBlock.FromBytes(bytes, ref i); + UserInfo.FromBytes(bytes, ref i); + } + + public KickUserPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + TargetBlock.FromBytes(bytes, ref i); + UserInfo.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += TargetBlock.Length; + length += UserInfo.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class GodKickUserPacket : Packet + { + /// + public sealed class UserInfoBlock : PacketBlock + { + public UUID GodID; + public UUID GodSessionID; + public UUID AgentID; + public uint KickFlags; + public byte[] Reason; + + public override int Length + { + get + { + int length = 54; + if (Reason != null) { length += Reason.Length; } + return length; + } + } + + public UserInfoBlock() { } + public UserInfoBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + GodID.FromBytes(bytes, i); i += 16; + GodSessionID.FromBytes(bytes, i); i += 16; + AgentID.FromBytes(bytes, i); i += 16; + KickFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + length = (bytes[i++] + (bytes[i++] << 8)); + Reason = new byte[length]; + Buffer.BlockCopy(bytes, i, Reason, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + GodID.ToBytes(bytes, i); i += 16; + GodSessionID.ToBytes(bytes, i); i += 16; + AgentID.ToBytes(bytes, i); i += 16; + Utils.UIntToBytes(KickFlags, bytes, i); i += 4; + bytes[i++] = (byte)(Reason.Length % 256); + bytes[i++] = (byte)((Reason.Length >> 8) % 256); + Buffer.BlockCopy(Reason, 0, bytes, i, Reason.Length); i += Reason.Length; + } + + } + + public override int Length + { + get + { + int length = 10; + length += UserInfo.Length; + return length; + } + } + public UserInfoBlock UserInfo; + + public GodKickUserPacket() + { + HasVariableBlocks = false; + Type = PacketType.GodKickUser; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 165; + Header.Reliable = true; + UserInfo = new UserInfoBlock(); + } + + public GodKickUserPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + UserInfo.FromBytes(bytes, ref i); + } + + public GodKickUserPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + UserInfo.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += UserInfo.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class EjectUserPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class DataBlock : PacketBlock + { + public UUID TargetID; + public uint Flags; + + public override int Length + { + get + { + return 20; + } + } + + public DataBlock() { } + public DataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + TargetID.FromBytes(bytes, i); i += 16; + Flags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + TargetID.ToBytes(bytes, i); i += 16; + Utils.UIntToBytes(Flags, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += Data.Length; + return length; + } + } + public AgentDataBlock AgentData; + public DataBlock Data; + + public EjectUserPacket() + { + HasVariableBlocks = false; + Type = PacketType.EjectUser; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 167; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + Data = new DataBlock(); + } + + public EjectUserPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + Data.FromBytes(bytes, ref i); + } + + public EjectUserPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + Data.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += Data.Length; + if (Header.AckList != null && 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); + Data.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class FreezeUserPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class DataBlock : PacketBlock + { + public UUID TargetID; + public uint Flags; + + public override int Length + { + get + { + return 20; + } + } + + public DataBlock() { } + public DataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + TargetID.FromBytes(bytes, i); i += 16; + Flags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + TargetID.ToBytes(bytes, i); i += 16; + Utils.UIntToBytes(Flags, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += Data.Length; + return length; + } + } + public AgentDataBlock AgentData; + public DataBlock Data; + + public FreezeUserPacket() + { + HasVariableBlocks = false; + Type = PacketType.FreezeUser; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 168; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + Data = new DataBlock(); + } + + public FreezeUserPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + Data.FromBytes(bytes, ref i); + } + + public FreezeUserPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + Data.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += Data.Length; + if (Header.AckList != null && 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); + Data.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class AvatarPropertiesRequestPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + public UUID AvatarID; + + public override int Length + { + get + { + return 48; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + AvatarID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + AvatarID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + return length; + } + } + public AgentDataBlock AgentData; + + public AvatarPropertiesRequestPacket() + { + HasVariableBlocks = false; + Type = PacketType.AvatarPropertiesRequest; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 169; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + } + + public AvatarPropertiesRequestPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + } + + public AvatarPropertiesRequestPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class AvatarPropertiesReplyPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID AvatarID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + AvatarID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + AvatarID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class PropertiesDataBlock : PacketBlock + { + public UUID ImageID; + public UUID FLImageID; + public UUID PartnerID; + public byte[] AboutText; + public byte[] FLAboutText; + public byte[] BornOn; + public byte[] ProfileURL; + public byte[] CharterMember; + public uint Flags; + + public override int Length + { + get + { + int length = 58; + if (AboutText != null) { length += AboutText.Length; } + if (FLAboutText != null) { length += FLAboutText.Length; } + if (BornOn != null) { length += BornOn.Length; } + if (ProfileURL != null) { length += ProfileURL.Length; } + if (CharterMember != null) { length += CharterMember.Length; } + return length; + } + } + + public PropertiesDataBlock() { } + public PropertiesDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + ImageID.FromBytes(bytes, i); i += 16; + FLImageID.FromBytes(bytes, i); i += 16; + PartnerID.FromBytes(bytes, i); i += 16; + length = (bytes[i++] + (bytes[i++] << 8)); + AboutText = new byte[length]; + Buffer.BlockCopy(bytes, i, AboutText, 0, length); i += length; + length = bytes[i++]; + FLAboutText = new byte[length]; + Buffer.BlockCopy(bytes, i, FLAboutText, 0, length); i += length; + length = bytes[i++]; + BornOn = new byte[length]; + Buffer.BlockCopy(bytes, i, BornOn, 0, length); i += length; + length = bytes[i++]; + ProfileURL = new byte[length]; + Buffer.BlockCopy(bytes, i, ProfileURL, 0, length); i += length; + length = bytes[i++]; + CharterMember = new byte[length]; + Buffer.BlockCopy(bytes, i, CharterMember, 0, length); i += length; + Flags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + ImageID.ToBytes(bytes, i); i += 16; + FLImageID.ToBytes(bytes, i); i += 16; + PartnerID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)(AboutText.Length % 256); + bytes[i++] = (byte)((AboutText.Length >> 8) % 256); + Buffer.BlockCopy(AboutText, 0, bytes, i, AboutText.Length); i += AboutText.Length; + bytes[i++] = (byte)FLAboutText.Length; + Buffer.BlockCopy(FLAboutText, 0, bytes, i, FLAboutText.Length); i += FLAboutText.Length; + bytes[i++] = (byte)BornOn.Length; + Buffer.BlockCopy(BornOn, 0, bytes, i, BornOn.Length); i += BornOn.Length; + bytes[i++] = (byte)ProfileURL.Length; + Buffer.BlockCopy(ProfileURL, 0, bytes, i, ProfileURL.Length); i += ProfileURL.Length; + bytes[i++] = (byte)CharterMember.Length; + Buffer.BlockCopy(CharterMember, 0, bytes, i, CharterMember.Length); i += CharterMember.Length; + Utils.UIntToBytes(Flags, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += PropertiesData.Length; + return length; + } + } + public AgentDataBlock AgentData; + public PropertiesDataBlock PropertiesData; + + public AvatarPropertiesReplyPacket() + { + HasVariableBlocks = false; + Type = PacketType.AvatarPropertiesReply; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 171; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + PropertiesData = new PropertiesDataBlock(); + } + + public AvatarPropertiesReplyPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + PropertiesData.FromBytes(bytes, ref i); + } + + public AvatarPropertiesReplyPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + PropertiesData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += PropertiesData.Length; + if (Header.AckList != null && 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); + PropertiesData.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class AvatarInterestsReplyPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID AvatarID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + AvatarID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + AvatarID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class PropertiesDataBlock : PacketBlock + { + public uint WantToMask; + public byte[] WantToText; + public uint SkillsMask; + public byte[] SkillsText; + public byte[] LanguagesText; + + public override int Length + { + get + { + int length = 11; + if (WantToText != null) { length += WantToText.Length; } + if (SkillsText != null) { length += SkillsText.Length; } + if (LanguagesText != null) { length += LanguagesText.Length; } + return length; + } + } + + public PropertiesDataBlock() { } + public PropertiesDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + WantToMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + length = bytes[i++]; + WantToText = new byte[length]; + Buffer.BlockCopy(bytes, i, WantToText, 0, length); i += length; + SkillsMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + length = bytes[i++]; + SkillsText = new byte[length]; + Buffer.BlockCopy(bytes, i, SkillsText, 0, length); i += length; + length = bytes[i++]; + LanguagesText = new byte[length]; + Buffer.BlockCopy(bytes, i, LanguagesText, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UIntToBytes(WantToMask, bytes, i); i += 4; + bytes[i++] = (byte)WantToText.Length; + Buffer.BlockCopy(WantToText, 0, bytes, i, WantToText.Length); i += WantToText.Length; + Utils.UIntToBytes(SkillsMask, bytes, i); i += 4; + bytes[i++] = (byte)SkillsText.Length; + Buffer.BlockCopy(SkillsText, 0, bytes, i, SkillsText.Length); i += SkillsText.Length; + bytes[i++] = (byte)LanguagesText.Length; + Buffer.BlockCopy(LanguagesText, 0, bytes, i, LanguagesText.Length); i += LanguagesText.Length; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += PropertiesData.Length; + return length; + } + } + public AgentDataBlock AgentData; + public PropertiesDataBlock PropertiesData; + + public AvatarInterestsReplyPacket() + { + HasVariableBlocks = false; + Type = PacketType.AvatarInterestsReply; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 172; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + PropertiesData = new PropertiesDataBlock(); + } + + public AvatarInterestsReplyPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + PropertiesData.FromBytes(bytes, ref i); + } + + public AvatarInterestsReplyPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + PropertiesData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += PropertiesData.Length; + if (Header.AckList != null && 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); + PropertiesData.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class AvatarGroupsReplyPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID AvatarID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + AvatarID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + AvatarID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class GroupDataBlock : PacketBlock + { + public ulong GroupPowers; + public bool AcceptNotices; + public byte[] GroupTitle; + public UUID GroupID; + public byte[] GroupName; + public UUID GroupInsigniaID; + + public override int Length + { + get + { + int length = 43; + if (GroupTitle != null) { length += GroupTitle.Length; } + if (GroupName != null) { length += GroupName.Length; } + return length; + } + } + + public GroupDataBlock() { } + public GroupDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(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)); + AcceptNotices = (bytes[i++] != 0) ? (bool)true : (bool)false; + length = bytes[i++]; + GroupTitle = new byte[length]; + Buffer.BlockCopy(bytes, i, GroupTitle, 0, length); i += length; + GroupID.FromBytes(bytes, i); i += 16; + length = bytes[i++]; + GroupName = new byte[length]; + Buffer.BlockCopy(bytes, i, GroupName, 0, length); i += length; + GroupInsigniaID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UInt64ToBytes(GroupPowers, bytes, i); i += 8; + bytes[i++] = (byte)((AcceptNotices) ? 1 : 0); + bytes[i++] = (byte)GroupTitle.Length; + Buffer.BlockCopy(GroupTitle, 0, bytes, i, GroupTitle.Length); i += GroupTitle.Length; + GroupID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)GroupName.Length; + Buffer.BlockCopy(GroupName, 0, bytes, i, GroupName.Length); i += GroupName.Length; + GroupInsigniaID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class NewGroupDataBlock : PacketBlock + { + public bool ListInProfile; + + public override int Length + { + get + { + return 1; + } + } + + public NewGroupDataBlock() { } + public NewGroupDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + ListInProfile = (bytes[i++] != 0) ? (bool)true : (bool)false; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + bytes[i++] = (byte)((ListInProfile) ? 1 : 0); + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentData.Length; + for (int j = 0; j < GroupData.Length; j++) + length += GroupData[j].Length; + length += NewGroupData.Length; + return length; + } + } + public AgentDataBlock AgentData; + public GroupDataBlock[] GroupData; + public NewGroupDataBlock NewGroupData; + + public AvatarGroupsReplyPacket() + { + HasVariableBlocks = true; + Type = PacketType.AvatarGroupsReply; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 173; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + GroupData = null; + NewGroupData = new NewGroupDataBlock(); + } + + public AvatarGroupsReplyPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(GroupData == null || GroupData.Length != -1) { + GroupData = new GroupDataBlock[count]; + for(int j = 0; j < count; j++) + { GroupData[j] = new GroupDataBlock(); } + } + for (int j = 0; j < count; j++) + { GroupData[j].FromBytes(bytes, ref i); } + NewGroupData.FromBytes(bytes, ref i); + } + + public AvatarGroupsReplyPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(GroupData == null || GroupData.Length != count) { + GroupData = new GroupDataBlock[count]; + for(int j = 0; j < count; j++) + { GroupData[j] = new GroupDataBlock(); } + } + for (int j = 0; j < count; j++) + { GroupData[j].FromBytes(bytes, ref i); } + NewGroupData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += NewGroupData.Length; + length++; + for (int j = 0; j < GroupData.Length; j++) { length += GroupData[j].Length; } + if (Header.AckList != null && 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); } + NewGroupData.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class AvatarPropertiesUpdatePacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class PropertiesDataBlock : PacketBlock + { + public UUID ImageID; + public UUID FLImageID; + public byte[] AboutText; + public byte[] FLAboutText; + public bool AllowPublish; + public bool MaturePublish; + public byte[] ProfileURL; + + public override int Length + { + get + { + int length = 38; + if (AboutText != null) { length += AboutText.Length; } + if (FLAboutText != null) { length += FLAboutText.Length; } + if (ProfileURL != null) { length += ProfileURL.Length; } + return length; + } + } + + public PropertiesDataBlock() { } + public PropertiesDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + ImageID.FromBytes(bytes, i); i += 16; + FLImageID.FromBytes(bytes, i); i += 16; + length = (bytes[i++] + (bytes[i++] << 8)); + AboutText = new byte[length]; + Buffer.BlockCopy(bytes, i, AboutText, 0, length); i += length; + length = bytes[i++]; + FLAboutText = new byte[length]; + Buffer.BlockCopy(bytes, i, FLAboutText, 0, length); i += length; + AllowPublish = (bytes[i++] != 0) ? (bool)true : (bool)false; + MaturePublish = (bytes[i++] != 0) ? (bool)true : (bool)false; + length = bytes[i++]; + ProfileURL = new byte[length]; + Buffer.BlockCopy(bytes, i, ProfileURL, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + ImageID.ToBytes(bytes, i); i += 16; + FLImageID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)(AboutText.Length % 256); + bytes[i++] = (byte)((AboutText.Length >> 8) % 256); + Buffer.BlockCopy(AboutText, 0, bytes, i, AboutText.Length); i += AboutText.Length; + bytes[i++] = (byte)FLAboutText.Length; + Buffer.BlockCopy(FLAboutText, 0, bytes, i, FLAboutText.Length); i += FLAboutText.Length; + bytes[i++] = (byte)((AllowPublish) ? 1 : 0); + bytes[i++] = (byte)((MaturePublish) ? 1 : 0); + bytes[i++] = (byte)ProfileURL.Length; + Buffer.BlockCopy(ProfileURL, 0, bytes, i, ProfileURL.Length); i += ProfileURL.Length; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += PropertiesData.Length; + return length; + } + } + public AgentDataBlock AgentData; + public PropertiesDataBlock PropertiesData; + + public AvatarPropertiesUpdatePacket() + { + HasVariableBlocks = false; + Type = PacketType.AvatarPropertiesUpdate; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 174; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + PropertiesData = new PropertiesDataBlock(); + } + + public AvatarPropertiesUpdatePacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + PropertiesData.FromBytes(bytes, ref i); + } + + public AvatarPropertiesUpdatePacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + PropertiesData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += PropertiesData.Length; + if (Header.AckList != null && 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); + PropertiesData.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class AvatarInterestsUpdatePacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class PropertiesDataBlock : PacketBlock + { + public uint WantToMask; + public byte[] WantToText; + public uint SkillsMask; + public byte[] SkillsText; + public byte[] LanguagesText; + + public override int Length + { + get + { + int length = 11; + if (WantToText != null) { length += WantToText.Length; } + if (SkillsText != null) { length += SkillsText.Length; } + if (LanguagesText != null) { length += LanguagesText.Length; } + return length; + } + } + + public PropertiesDataBlock() { } + public PropertiesDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + WantToMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + length = bytes[i++]; + WantToText = new byte[length]; + Buffer.BlockCopy(bytes, i, WantToText, 0, length); i += length; + SkillsMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + length = bytes[i++]; + SkillsText = new byte[length]; + Buffer.BlockCopy(bytes, i, SkillsText, 0, length); i += length; + length = bytes[i++]; + LanguagesText = new byte[length]; + Buffer.BlockCopy(bytes, i, LanguagesText, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UIntToBytes(WantToMask, bytes, i); i += 4; + bytes[i++] = (byte)WantToText.Length; + Buffer.BlockCopy(WantToText, 0, bytes, i, WantToText.Length); i += WantToText.Length; + Utils.UIntToBytes(SkillsMask, bytes, i); i += 4; + bytes[i++] = (byte)SkillsText.Length; + Buffer.BlockCopy(SkillsText, 0, bytes, i, SkillsText.Length); i += SkillsText.Length; + bytes[i++] = (byte)LanguagesText.Length; + Buffer.BlockCopy(LanguagesText, 0, bytes, i, LanguagesText.Length); i += LanguagesText.Length; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += PropertiesData.Length; + return length; + } + } + public AgentDataBlock AgentData; + public PropertiesDataBlock PropertiesData; + + public AvatarInterestsUpdatePacket() + { + HasVariableBlocks = false; + Type = PacketType.AvatarInterestsUpdate; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 175; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + PropertiesData = new PropertiesDataBlock(); + } + + public AvatarInterestsUpdatePacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + PropertiesData.FromBytes(bytes, ref i); + } + + public AvatarInterestsUpdatePacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + PropertiesData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += PropertiesData.Length; + if (Header.AckList != null && 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); + PropertiesData.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class AvatarNotesReplyPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + + public override int Length + { + get + { + return 16; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class DataBlock : PacketBlock + { + public UUID TargetID; + public byte[] Notes; + + public override int Length + { + get + { + int length = 18; + if (Notes != null) { length += Notes.Length; } + return length; + } + } + + public DataBlock() { } + public DataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + TargetID.FromBytes(bytes, i); i += 16; + length = (bytes[i++] + (bytes[i++] << 8)); + Notes = new byte[length]; + Buffer.BlockCopy(bytes, i, Notes, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + TargetID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)(Notes.Length % 256); + bytes[i++] = (byte)((Notes.Length >> 8) % 256); + Buffer.BlockCopy(Notes, 0, bytes, i, Notes.Length); i += Notes.Length; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += Data.Length; + return length; + } + } + public AgentDataBlock AgentData; + public DataBlock Data; + + public AvatarNotesReplyPacket() + { + HasVariableBlocks = false; + Type = PacketType.AvatarNotesReply; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 176; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + Data = new DataBlock(); + } + + public AvatarNotesReplyPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + Data.FromBytes(bytes, ref i); + } + + public AvatarNotesReplyPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + Data.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += Data.Length; + if (Header.AckList != null && 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); + Data.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class AvatarNotesUpdatePacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class DataBlock : PacketBlock + { + public UUID TargetID; + public byte[] Notes; + + public override int Length + { + get + { + int length = 18; + if (Notes != null) { length += Notes.Length; } + return length; + } + } + + public DataBlock() { } + public DataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + TargetID.FromBytes(bytes, i); i += 16; + length = (bytes[i++] + (bytes[i++] << 8)); + Notes = new byte[length]; + Buffer.BlockCopy(bytes, i, Notes, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + TargetID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)(Notes.Length % 256); + bytes[i++] = (byte)((Notes.Length >> 8) % 256); + Buffer.BlockCopy(Notes, 0, bytes, i, Notes.Length); i += Notes.Length; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += Data.Length; + return length; + } + } + public AgentDataBlock AgentData; + public DataBlock Data; + + public AvatarNotesUpdatePacket() + { + HasVariableBlocks = false; + Type = PacketType.AvatarNotesUpdate; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 177; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + Data = new DataBlock(); + } + + public AvatarNotesUpdatePacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + Data.FromBytes(bytes, ref i); + } + + public AvatarNotesUpdatePacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + Data.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += Data.Length; + if (Header.AckList != null && 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); + Data.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class AvatarPicksReplyPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID TargetID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + TargetID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + TargetID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class DataBlock : PacketBlock + { + public UUID PickID; + public byte[] PickName; + + public override int Length + { + get + { + int length = 17; + if (PickName != null) { length += PickName.Length; } + return length; + } + } + + public DataBlock() { } + public DataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + PickID.FromBytes(bytes, i); i += 16; + length = bytes[i++]; + PickName = new byte[length]; + Buffer.BlockCopy(bytes, i, PickName, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + PickID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)PickName.Length; + Buffer.BlockCopy(PickName, 0, bytes, i, PickName.Length); i += PickName.Length; + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentData.Length; + for (int j = 0; j < Data.Length; j++) + length += Data[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public DataBlock[] Data; + + public AvatarPicksReplyPacket() + { + HasVariableBlocks = true; + Type = PacketType.AvatarPicksReply; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 178; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + Data = null; + } + + public AvatarPicksReplyPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(Data == null || Data.Length != -1) { + Data = new DataBlock[count]; + for(int j = 0; j < count; j++) + { Data[j] = new DataBlock(); } + } + for (int j = 0; j < count; j++) + { Data[j].FromBytes(bytes, ref i); } + } + + public AvatarPicksReplyPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(Data == null || Data.Length != count) { + Data = new DataBlock[count]; + for(int j = 0; j < count; j++) + { Data[j] = new DataBlock(); } + } + for (int j = 0; j < count; j++) + { Data[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length++; + for (int j = 0; j < Data.Length; j++) { length += Data[j].Length; } + if (Header.AckList != null && 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)Data.Length; + for (int j = 0; j < Data.Length; j++) { Data[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int DataStart = 0; + do + { + int variableLength = 0; + int DataCount = 0; + + i = DataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < Data.Length) { + int blockLength = Data[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == DataStart) { + variableLength += blockLength; + ++DataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)DataCount; + for (i = DataStart; i < DataStart + DataCount; i++) { Data[i].ToBytes(packet, ref length); } + DataStart += DataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + DataStart < Data.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class EventInfoRequestPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class EventDataBlock : PacketBlock + { + public uint EventID; + + public override int Length + { + get + { + return 4; + } + } + + public EventDataBlock() { } + public EventDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + EventID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UIntToBytes(EventID, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += EventData.Length; + return length; + } + } + public AgentDataBlock AgentData; + public EventDataBlock EventData; + + public EventInfoRequestPacket() + { + HasVariableBlocks = false; + Type = PacketType.EventInfoRequest; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 179; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + EventData = new EventDataBlock(); + } + + public EventInfoRequestPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + EventData.FromBytes(bytes, ref i); + } + + public EventInfoRequestPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + EventData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += EventData.Length; + if (Header.AckList != null && 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); + EventData.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class EventInfoReplyPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + + public override int Length + { + get + { + return 16; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class EventDataBlock : PacketBlock + { + public uint EventID; + public byte[] Creator; + public byte[] Name; + public byte[] Category; + public byte[] Desc; + public byte[] Date; + public uint DateUTC; + public uint Duration; + public uint Cover; + public uint Amount; + public byte[] SimName; + public Vector3d GlobalPos; + public uint EventFlags; + + public override int Length + { + get + { + int length = 55; + if (Creator != null) { length += Creator.Length; } + if (Name != null) { length += Name.Length; } + if (Category != null) { length += Category.Length; } + if (Desc != null) { length += Desc.Length; } + if (Date != null) { length += Date.Length; } + if (SimName != null) { length += SimName.Length; } + return length; + } + } + + public EventDataBlock() { } + public EventDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + EventID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + length = bytes[i++]; + Creator = new byte[length]; + Buffer.BlockCopy(bytes, i, Creator, 0, length); i += length; + length = bytes[i++]; + Name = new byte[length]; + Buffer.BlockCopy(bytes, i, Name, 0, length); i += length; + length = bytes[i++]; + Category = new byte[length]; + Buffer.BlockCopy(bytes, i, Category, 0, length); i += length; + length = (bytes[i++] + (bytes[i++] << 8)); + Desc = new byte[length]; + Buffer.BlockCopy(bytes, i, Desc, 0, length); i += length; + length = bytes[i++]; + Date = new byte[length]; + Buffer.BlockCopy(bytes, i, Date, 0, length); i += length; + DateUTC = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + Duration = (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)); + Amount = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + length = bytes[i++]; + SimName = new byte[length]; + Buffer.BlockCopy(bytes, i, SimName, 0, length); i += length; + GlobalPos.FromBytes(bytes, i); i += 24; + EventFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UIntToBytes(EventID, bytes, i); i += 4; + bytes[i++] = (byte)Creator.Length; + Buffer.BlockCopy(Creator, 0, bytes, i, Creator.Length); i += Creator.Length; + bytes[i++] = (byte)Name.Length; + Buffer.BlockCopy(Name, 0, bytes, i, Name.Length); i += Name.Length; + bytes[i++] = (byte)Category.Length; + Buffer.BlockCopy(Category, 0, bytes, i, Category.Length); i += Category.Length; + bytes[i++] = (byte)(Desc.Length % 256); + bytes[i++] = (byte)((Desc.Length >> 8) % 256); + Buffer.BlockCopy(Desc, 0, bytes, i, Desc.Length); i += Desc.Length; + bytes[i++] = (byte)Date.Length; + Buffer.BlockCopy(Date, 0, bytes, i, Date.Length); i += Date.Length; + Utils.UIntToBytes(DateUTC, bytes, i); i += 4; + Utils.UIntToBytes(Duration, bytes, i); i += 4; + Utils.UIntToBytes(Cover, bytes, i); i += 4; + Utils.UIntToBytes(Amount, bytes, i); i += 4; + bytes[i++] = (byte)SimName.Length; + Buffer.BlockCopy(SimName, 0, bytes, i, SimName.Length); i += SimName.Length; + GlobalPos.ToBytes(bytes, i); i += 24; + Utils.UIntToBytes(EventFlags, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += EventData.Length; + return length; + } + } + public AgentDataBlock AgentData; + public EventDataBlock EventData; + + public EventInfoReplyPacket() + { + HasVariableBlocks = false; + Type = PacketType.EventInfoReply; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 180; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + EventData = new EventDataBlock(); + } + + public EventInfoReplyPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + EventData.FromBytes(bytes, ref i); + } + + public EventInfoReplyPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + EventData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += EventData.Length; + if (Header.AckList != null && 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); + EventData.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class EventNotificationAddRequestPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class EventDataBlock : PacketBlock + { + public uint EventID; + + public override int Length + { + get + { + return 4; + } + } + + public EventDataBlock() { } + public EventDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + EventID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UIntToBytes(EventID, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += EventData.Length; + return length; + } + } + public AgentDataBlock AgentData; + public EventDataBlock EventData; + + public EventNotificationAddRequestPacket() + { + HasVariableBlocks = false; + Type = PacketType.EventNotificationAddRequest; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 181; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + EventData = new EventDataBlock(); + } + + public EventNotificationAddRequestPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + EventData.FromBytes(bytes, ref i); + } + + public EventNotificationAddRequestPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + EventData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += EventData.Length; + if (Header.AckList != null && 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); + EventData.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class EventNotificationRemoveRequestPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class EventDataBlock : PacketBlock + { + public uint EventID; + + public override int Length + { + get + { + return 4; + } + } + + public EventDataBlock() { } + public EventDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + EventID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UIntToBytes(EventID, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += EventData.Length; + return length; + } + } + public AgentDataBlock AgentData; + public EventDataBlock EventData; + + public EventNotificationRemoveRequestPacket() + { + HasVariableBlocks = false; + Type = PacketType.EventNotificationRemoveRequest; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 182; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + EventData = new EventDataBlock(); + } + + public EventNotificationRemoveRequestPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + EventData.FromBytes(bytes, ref i); + } + + public EventNotificationRemoveRequestPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + EventData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += EventData.Length; + if (Header.AckList != null && 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); + EventData.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class EventGodDeletePacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class EventDataBlock : PacketBlock + { + public uint EventID; + + public override int Length + { + get + { + return 4; + } + } + + public EventDataBlock() { } + public EventDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + EventID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UIntToBytes(EventID, bytes, i); i += 4; + } + + } + + /// + public sealed class QueryDataBlock : PacketBlock + { + public UUID QueryID; + public byte[] QueryText; + public uint QueryFlags; + public int QueryStart; + + public override int Length + { + get + { + int length = 25; + if (QueryText != null) { length += QueryText.Length; } + return length; + } + } + + public QueryDataBlock() { } + public QueryDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + QueryID.FromBytes(bytes, i); i += 16; + length = bytes[i++]; + QueryText = new byte[length]; + Buffer.BlockCopy(bytes, i, QueryText, 0, length); i += length; + 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)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + QueryID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)QueryText.Length; + Buffer.BlockCopy(QueryText, 0, bytes, i, QueryText.Length); i += QueryText.Length; + Utils.UIntToBytes(QueryFlags, bytes, i); i += 4; + Utils.IntToBytes(QueryStart, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += EventData.Length; + length += QueryData.Length; + return length; + } + } + public AgentDataBlock AgentData; + public EventDataBlock EventData; + public QueryDataBlock QueryData; + + public EventGodDeletePacket() + { + HasVariableBlocks = false; + Type = PacketType.EventGodDelete; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 183; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + EventData = new EventDataBlock(); + QueryData = new QueryDataBlock(); + } + + public EventGodDeletePacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + EventData.FromBytes(bytes, ref i); + QueryData.FromBytes(bytes, ref i); + } + + public EventGodDeletePacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + EventData.FromBytes(bytes, ref i); + QueryData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += EventData.Length; + length += QueryData.Length; + if (Header.AckList != null && 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); + EventData.ToBytes(bytes, ref i); + QueryData.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class PickInfoReplyPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + + public override int Length + { + get + { + return 16; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class DataBlock : PacketBlock + { + public UUID PickID; + public UUID CreatorID; + public bool TopPick; + public UUID ParcelID; + public byte[] Name; + public byte[] Desc; + public UUID SnapshotID; + public byte[] User; + public byte[] OriginalName; + public byte[] SimName; + public Vector3d PosGlobal; + public int SortOrder; + public bool Enabled; + + public override int Length + { + get + { + int length = 100; + if (Name != null) { length += Name.Length; } + if (Desc != null) { length += Desc.Length; } + if (User != null) { length += User.Length; } + if (OriginalName != null) { length += OriginalName.Length; } + if (SimName != null) { length += SimName.Length; } + return length; + } + } + + public DataBlock() { } + public DataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + PickID.FromBytes(bytes, i); i += 16; + CreatorID.FromBytes(bytes, i); i += 16; + TopPick = (bytes[i++] != 0) ? (bool)true : (bool)false; + ParcelID.FromBytes(bytes, i); i += 16; + length = bytes[i++]; + Name = new byte[length]; + Buffer.BlockCopy(bytes, i, Name, 0, length); i += length; + length = (bytes[i++] + (bytes[i++] << 8)); + Desc = new byte[length]; + Buffer.BlockCopy(bytes, i, Desc, 0, length); i += length; + SnapshotID.FromBytes(bytes, i); i += 16; + length = bytes[i++]; + User = new byte[length]; + Buffer.BlockCopy(bytes, i, User, 0, length); i += length; + length = bytes[i++]; + OriginalName = new byte[length]; + Buffer.BlockCopy(bytes, i, OriginalName, 0, length); i += length; + length = bytes[i++]; + SimName = new byte[length]; + Buffer.BlockCopy(bytes, i, SimName, 0, length); i += length; + PosGlobal.FromBytes(bytes, i); i += 24; + SortOrder = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + Enabled = (bytes[i++] != 0) ? (bool)true : (bool)false; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + PickID.ToBytes(bytes, i); i += 16; + CreatorID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)((TopPick) ? 1 : 0); + ParcelID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)Name.Length; + Buffer.BlockCopy(Name, 0, bytes, i, Name.Length); i += Name.Length; + bytes[i++] = (byte)(Desc.Length % 256); + bytes[i++] = (byte)((Desc.Length >> 8) % 256); + Buffer.BlockCopy(Desc, 0, bytes, i, Desc.Length); i += Desc.Length; + SnapshotID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)User.Length; + Buffer.BlockCopy(User, 0, bytes, i, User.Length); i += User.Length; + bytes[i++] = (byte)OriginalName.Length; + Buffer.BlockCopy(OriginalName, 0, bytes, i, OriginalName.Length); i += OriginalName.Length; + bytes[i++] = (byte)SimName.Length; + Buffer.BlockCopy(SimName, 0, bytes, i, SimName.Length); i += SimName.Length; + PosGlobal.ToBytes(bytes, i); i += 24; + Utils.IntToBytes(SortOrder, bytes, i); i += 4; + bytes[i++] = (byte)((Enabled) ? 1 : 0); + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += Data.Length; + return length; + } + } + public AgentDataBlock AgentData; + public DataBlock Data; + + public PickInfoReplyPacket() + { + HasVariableBlocks = false; + Type = PacketType.PickInfoReply; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 184; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + Data = new DataBlock(); + } + + public PickInfoReplyPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + Data.FromBytes(bytes, ref i); + } + + public PickInfoReplyPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + Data.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += Data.Length; + if (Header.AckList != null && 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); + Data.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class PickInfoUpdatePacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class DataBlock : PacketBlock + { + public UUID PickID; + public UUID CreatorID; + public bool TopPick; + public UUID ParcelID; + public byte[] Name; + public byte[] Desc; + public UUID SnapshotID; + public Vector3d PosGlobal; + public int SortOrder; + public bool Enabled; + + public override int Length + { + get + { + int length = 97; + if (Name != null) { length += Name.Length; } + if (Desc != null) { length += Desc.Length; } + return length; + } + } + + public DataBlock() { } + public DataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + PickID.FromBytes(bytes, i); i += 16; + CreatorID.FromBytes(bytes, i); i += 16; + TopPick = (bytes[i++] != 0) ? (bool)true : (bool)false; + ParcelID.FromBytes(bytes, i); i += 16; + length = bytes[i++]; + Name = new byte[length]; + Buffer.BlockCopy(bytes, i, Name, 0, length); i += length; + length = (bytes[i++] + (bytes[i++] << 8)); + Desc = new byte[length]; + Buffer.BlockCopy(bytes, i, Desc, 0, length); i += length; + SnapshotID.FromBytes(bytes, i); i += 16; + PosGlobal.FromBytes(bytes, i); i += 24; + SortOrder = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + Enabled = (bytes[i++] != 0) ? (bool)true : (bool)false; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + PickID.ToBytes(bytes, i); i += 16; + CreatorID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)((TopPick) ? 1 : 0); + ParcelID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)Name.Length; + Buffer.BlockCopy(Name, 0, bytes, i, Name.Length); i += Name.Length; + bytes[i++] = (byte)(Desc.Length % 256); + bytes[i++] = (byte)((Desc.Length >> 8) % 256); + Buffer.BlockCopy(Desc, 0, bytes, i, Desc.Length); i += Desc.Length; + SnapshotID.ToBytes(bytes, i); i += 16; + PosGlobal.ToBytes(bytes, i); i += 24; + Utils.IntToBytes(SortOrder, bytes, i); i += 4; + bytes[i++] = (byte)((Enabled) ? 1 : 0); + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += Data.Length; + return length; + } + } + public AgentDataBlock AgentData; + public DataBlock Data; + + public PickInfoUpdatePacket() + { + HasVariableBlocks = false; + Type = PacketType.PickInfoUpdate; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 185; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + Data = new DataBlock(); + } + + public PickInfoUpdatePacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + Data.FromBytes(bytes, ref i); + } + + public PickInfoUpdatePacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + Data.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += Data.Length; + if (Header.AckList != null && 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); + Data.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class PickDeletePacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class DataBlock : PacketBlock + { + public UUID PickID; + + public override int Length + { + get + { + return 16; + } + } + + public DataBlock() { } + public DataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + PickID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + PickID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += Data.Length; + return length; + } + } + public AgentDataBlock AgentData; + public DataBlock Data; + + public PickDeletePacket() + { + HasVariableBlocks = false; + Type = PacketType.PickDelete; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 186; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + Data = new DataBlock(); + } + + public PickDeletePacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + Data.FromBytes(bytes, ref i); + } + + public PickDeletePacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + Data.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += Data.Length; + if (Header.AckList != null && 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); + Data.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class PickGodDeletePacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class DataBlock : PacketBlock + { + public UUID PickID; + public UUID QueryID; + + public override int Length + { + get + { + return 32; + } + } + + public DataBlock() { } + public DataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + PickID.FromBytes(bytes, i); i += 16; + QueryID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + PickID.ToBytes(bytes, i); i += 16; + QueryID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += Data.Length; + return length; + } + } + public AgentDataBlock AgentData; + public DataBlock Data; + + public PickGodDeletePacket() + { + HasVariableBlocks = false; + Type = PacketType.PickGodDelete; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 187; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + Data = new DataBlock(); + } + + public PickGodDeletePacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + Data.FromBytes(bytes, ref i); + } + + public PickGodDeletePacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + Data.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += Data.Length; + if (Header.AckList != null && 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); + Data.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class ScriptQuestionPacket : Packet + { + /// + public sealed class DataBlock : PacketBlock + { + public UUID TaskID; + public UUID ItemID; + public byte[] ObjectName; + public byte[] ObjectOwner; + public int Questions; + + public override int Length + { + get + { + int length = 38; + if (ObjectName != null) { length += ObjectName.Length; } + if (ObjectOwner != null) { length += ObjectOwner.Length; } + return length; + } + } + + public DataBlock() { } + public DataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + TaskID.FromBytes(bytes, i); i += 16; + ItemID.FromBytes(bytes, i); i += 16; + length = bytes[i++]; + ObjectName = new byte[length]; + Buffer.BlockCopy(bytes, i, ObjectName, 0, length); i += length; + length = bytes[i++]; + ObjectOwner = new byte[length]; + Buffer.BlockCopy(bytes, i, ObjectOwner, 0, length); i += length; + Questions = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + TaskID.ToBytes(bytes, i); i += 16; + ItemID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)ObjectName.Length; + Buffer.BlockCopy(ObjectName, 0, bytes, i, ObjectName.Length); i += ObjectName.Length; + bytes[i++] = (byte)ObjectOwner.Length; + Buffer.BlockCopy(ObjectOwner, 0, bytes, i, ObjectOwner.Length); i += ObjectOwner.Length; + Utils.IntToBytes(Questions, bytes, i); i += 4; + } + + } + + /// + public sealed class ExperienceBlock : PacketBlock + { + public UUID ExperienceID; + + public override int Length + { + get + { + return 16; + } + } + + public ExperienceBlock() { } + public ExperienceBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + ExperienceID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + ExperienceID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 10; + length += Data.Length; + length += Experience.Length; + return length; + } + } + public DataBlock Data; + public ExperienceBlock Experience; + + public ScriptQuestionPacket() + { + HasVariableBlocks = false; + Type = PacketType.ScriptQuestion; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 188; + Header.Reliable = true; + Data = new DataBlock(); + Experience = new ExperienceBlock(); + } + + public ScriptQuestionPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + Data.FromBytes(bytes, ref i); + Experience.FromBytes(bytes, ref i); + } + + public ScriptQuestionPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + Data.FromBytes(bytes, ref i); + Experience.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += Data.Length; + length += Experience.Length; + if (Header.AckList != null && 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); + Experience.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class ScriptControlChangePacket : Packet + { + /// + public sealed class DataBlock : PacketBlock + { + public bool TakeControls; + public uint Controls; + public bool PassToAgent; + + public override int Length + { + get + { + return 6; + } + } + + public DataBlock() { } + public DataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + TakeControls = (bytes[i++] != 0) ? (bool)true : (bool)false; + Controls = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + PassToAgent = (bytes[i++] != 0) ? (bool)true : (bool)false; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + bytes[i++] = (byte)((TakeControls) ? 1 : 0); + Utils.UIntToBytes(Controls, bytes, i); i += 4; + bytes[i++] = (byte)((PassToAgent) ? 1 : 0); + } + + } + + public override int Length + { + get + { + int length = 11; + for (int j = 0; j < Data.Length; j++) + length += Data[j].Length; + return length; + } + } + public DataBlock[] Data; + + public ScriptControlChangePacket() + { + HasVariableBlocks = true; + Type = PacketType.ScriptControlChange; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 189; + Header.Reliable = true; + Data = null; + } + + public ScriptControlChangePacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + int count = (int)bytes[i++]; + if(Data == null || Data.Length != -1) { + Data = new DataBlock[count]; + for(int j = 0; j < count; j++) + { Data[j] = new DataBlock(); } + } + for (int j = 0; j < count; j++) + { Data[j].FromBytes(bytes, ref i); } + } + + public ScriptControlChangePacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + int count = (int)bytes[i++]; + if(Data == null || Data.Length != count) { + Data = new DataBlock[count]; + for(int j = 0; j < count; j++) + { Data[j] = new DataBlock(); } + } + for (int j = 0; j < count; j++) + { Data[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length++; + for (int j = 0; j < Data.Length; j++) { length += Data[j].Length; } + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int DataStart = 0; + do + { + int variableLength = 0; + int DataCount = 0; + + i = DataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < Data.Length) { + int blockLength = Data[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == DataStart) { + variableLength += blockLength; + ++DataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)DataCount; + for (i = DataStart; i < DataStart + DataCount; i++) { Data[i].ToBytes(packet, ref length); } + DataStart += DataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + DataStart < Data.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class ScriptDialogPacket : Packet + { + /// + public sealed class DataBlock : PacketBlock + { + public UUID ObjectID; + public byte[] FirstName; + public byte[] LastName; + public byte[] ObjectName; + public byte[] Message; + public int ChatChannel; + public UUID ImageID; + + public override int Length + { + get + { + int length = 41; + if (FirstName != null) { length += FirstName.Length; } + if (LastName != null) { length += LastName.Length; } + if (ObjectName != null) { length += ObjectName.Length; } + if (Message != null) { length += Message.Length; } + return length; + } + } + + public DataBlock() { } + public DataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + ObjectID.FromBytes(bytes, i); i += 16; + length = bytes[i++]; + FirstName = new byte[length]; + Buffer.BlockCopy(bytes, i, FirstName, 0, length); i += length; + length = bytes[i++]; + LastName = new byte[length]; + Buffer.BlockCopy(bytes, i, LastName, 0, length); i += length; + length = bytes[i++]; + ObjectName = new byte[length]; + Buffer.BlockCopy(bytes, i, ObjectName, 0, length); i += length; + length = (bytes[i++] + (bytes[i++] << 8)); + Message = new byte[length]; + Buffer.BlockCopy(bytes, i, Message, 0, length); i += length; + ChatChannel = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + ImageID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + ObjectID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)FirstName.Length; + Buffer.BlockCopy(FirstName, 0, bytes, i, FirstName.Length); i += FirstName.Length; + bytes[i++] = (byte)LastName.Length; + Buffer.BlockCopy(LastName, 0, bytes, i, LastName.Length); i += LastName.Length; + bytes[i++] = (byte)ObjectName.Length; + Buffer.BlockCopy(ObjectName, 0, bytes, i, ObjectName.Length); i += ObjectName.Length; + bytes[i++] = (byte)(Message.Length % 256); + bytes[i++] = (byte)((Message.Length >> 8) % 256); + Buffer.BlockCopy(Message, 0, bytes, i, Message.Length); i += Message.Length; + Utils.IntToBytes(ChatChannel, bytes, i); i += 4; + ImageID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class ButtonsBlock : PacketBlock + { + public byte[] ButtonLabel; + + public override int Length + { + get + { + int length = 1; + if (ButtonLabel != null) { length += ButtonLabel.Length; } + return length; + } + } + + public ButtonsBlock() { } + public ButtonsBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + length = bytes[i++]; + ButtonLabel = new byte[length]; + Buffer.BlockCopy(bytes, i, ButtonLabel, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + bytes[i++] = (byte)ButtonLabel.Length; + Buffer.BlockCopy(ButtonLabel, 0, bytes, i, ButtonLabel.Length); i += ButtonLabel.Length; + } + + } + + /// + public sealed class OwnerDataBlock : PacketBlock + { + public UUID OwnerID; + + public override int Length + { + get + { + return 16; + } + } + + public OwnerDataBlock() { } + public OwnerDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + OwnerID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + OwnerID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 12; + length += Data.Length; + for (int j = 0; j < Buttons.Length; j++) + length += Buttons[j].Length; + for (int j = 0; j < OwnerData.Length; j++) + length += OwnerData[j].Length; + return length; + } + } + public DataBlock Data; + public ButtonsBlock[] Buttons; + public OwnerDataBlock[] OwnerData; + + public ScriptDialogPacket() + { + HasVariableBlocks = true; + Type = PacketType.ScriptDialog; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 190; + Header.Reliable = true; + Header.Zerocoded = true; + Data = new DataBlock(); + Buttons = null; + OwnerData = null; + } + + public ScriptDialogPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + Data.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(Buttons == null || Buttons.Length != -1) { + Buttons = new ButtonsBlock[count]; + for(int j = 0; j < count; j++) + { Buttons[j] = new ButtonsBlock(); } + } + for (int j = 0; j < count; j++) + { Buttons[j].FromBytes(bytes, ref i); } + count = (int)bytes[i++]; + if(OwnerData == null || OwnerData.Length != -1) { + OwnerData = new OwnerDataBlock[count]; + for(int j = 0; j < count; j++) + { OwnerData[j] = new OwnerDataBlock(); } + } + for (int j = 0; j < count; j++) + { OwnerData[j].FromBytes(bytes, ref i); } + } + + public ScriptDialogPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + Data.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(Buttons == null || Buttons.Length != count) { + Buttons = new ButtonsBlock[count]; + for(int j = 0; j < count; j++) + { Buttons[j] = new ButtonsBlock(); } + } + for (int j = 0; j < count; j++) + { Buttons[j].FromBytes(bytes, ref i); } + count = (int)bytes[i++]; + if(OwnerData == null || OwnerData.Length != count) { + OwnerData = new OwnerDataBlock[count]; + for(int j = 0; j < count; j++) + { OwnerData[j] = new OwnerDataBlock(); } + } + for (int j = 0; j < count; j++) + { OwnerData[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += Data.Length; + length++; + for (int j = 0; j < Buttons.Length; j++) { length += Buttons[j].Length; } + length++; + for (int j = 0; j < OwnerData.Length; j++) { length += OwnerData[j].Length; } + if (Header.AckList != null && 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); } + bytes[i++] = (byte)OwnerData.Length; + for (int j = 0; j < OwnerData.Length; j++) { OwnerData[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += Data.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + Data.ToBytes(fixedBytes, ref i); + fixedLength += 2; + + int ButtonsStart = 0; + int OwnerDataStart = 0; + do + { + int variableLength = 0; + int ButtonsCount = 0; + int OwnerDataCount = 0; + + i = ButtonsStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < Buttons.Length) { + int blockLength = Buttons[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ButtonsStart) { + variableLength += blockLength; + ++ButtonsCount; + } + else { break; } + ++i; + } + + i = OwnerDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < OwnerData.Length) { + int blockLength = OwnerData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == OwnerDataStart) { + variableLength += blockLength; + ++OwnerDataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)ButtonsCount; + for (i = ButtonsStart; i < ButtonsStart + ButtonsCount; i++) { Buttons[i].ToBytes(packet, ref length); } + ButtonsStart += ButtonsCount; + + packet[length++] = (byte)OwnerDataCount; + for (i = OwnerDataStart; i < OwnerDataStart + OwnerDataCount; i++) { OwnerData[i].ToBytes(packet, ref length); } + OwnerDataStart += OwnerDataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + ButtonsStart < Buttons.Length || + OwnerDataStart < OwnerData.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class ScriptDialogReplyPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class DataBlock : PacketBlock + { + public UUID ObjectID; + public int ChatChannel; + public int ButtonIndex; + public byte[] ButtonLabel; + + public override int Length + { + get + { + int length = 25; + if (ButtonLabel != null) { length += ButtonLabel.Length; } + return length; + } + } + + public DataBlock() { } + public DataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + ObjectID.FromBytes(bytes, i); i += 16; + ChatChannel = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + ButtonIndex = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + length = bytes[i++]; + ButtonLabel = new byte[length]; + Buffer.BlockCopy(bytes, i, ButtonLabel, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + ObjectID.ToBytes(bytes, i); i += 16; + Utils.IntToBytes(ChatChannel, bytes, i); i += 4; + Utils.IntToBytes(ButtonIndex, bytes, i); i += 4; + bytes[i++] = (byte)ButtonLabel.Length; + Buffer.BlockCopy(ButtonLabel, 0, bytes, i, ButtonLabel.Length); i += ButtonLabel.Length; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += Data.Length; + return length; + } + } + public AgentDataBlock AgentData; + public DataBlock Data; + + public ScriptDialogReplyPacket() + { + HasVariableBlocks = false; + Type = PacketType.ScriptDialogReply; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 191; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + Data = new DataBlock(); + } + + public ScriptDialogReplyPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + Data.FromBytes(bytes, ref i); + } + + public ScriptDialogReplyPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + Data.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += Data.Length; + if (Header.AckList != null && 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); + Data.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class ForceScriptControlReleasePacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + return length; + } + } + public AgentDataBlock AgentData; + + public ForceScriptControlReleasePacket() + { + HasVariableBlocks = false; + Type = PacketType.ForceScriptControlRelease; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 192; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + } + + public ForceScriptControlReleasePacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + } + + public ForceScriptControlReleasePacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class RevokePermissionsPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class DataBlock : PacketBlock + { + public UUID ObjectID; + public uint ObjectPermissions; + + public override int Length + { + get + { + return 20; + } + } + + public DataBlock() { } + public DataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + ObjectID.FromBytes(bytes, i); i += 16; + ObjectPermissions = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + ObjectID.ToBytes(bytes, i); i += 16; + Utils.UIntToBytes(ObjectPermissions, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += Data.Length; + return length; + } + } + public AgentDataBlock AgentData; + public DataBlock Data; + + public RevokePermissionsPacket() + { + HasVariableBlocks = false; + Type = PacketType.RevokePermissions; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 193; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + Data = new DataBlock(); + } + + public RevokePermissionsPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + Data.FromBytes(bytes, ref i); + } + + public RevokePermissionsPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + Data.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += Data.Length; + if (Header.AckList != null && 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); + Data.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class LoadURLPacket : Packet + { + /// + public sealed class DataBlock : PacketBlock + { + public byte[] ObjectName; + public UUID ObjectID; + public UUID OwnerID; + public bool OwnerIsGroup; + public byte[] Message; + public byte[] URL; + + public override int Length + { + get + { + int length = 36; + if (ObjectName != null) { length += ObjectName.Length; } + if (Message != null) { length += Message.Length; } + if (URL != null) { length += URL.Length; } + return length; + } + } + + public DataBlock() { } + public DataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + length = bytes[i++]; + ObjectName = new byte[length]; + Buffer.BlockCopy(bytes, i, ObjectName, 0, length); i += length; + ObjectID.FromBytes(bytes, i); i += 16; + OwnerID.FromBytes(bytes, i); i += 16; + OwnerIsGroup = (bytes[i++] != 0) ? (bool)true : (bool)false; + length = bytes[i++]; + Message = new byte[length]; + Buffer.BlockCopy(bytes, i, Message, 0, length); i += length; + length = bytes[i++]; + URL = new byte[length]; + Buffer.BlockCopy(bytes, i, URL, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + bytes[i++] = (byte)ObjectName.Length; + Buffer.BlockCopy(ObjectName, 0, bytes, i, ObjectName.Length); i += ObjectName.Length; + ObjectID.ToBytes(bytes, i); i += 16; + OwnerID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)((OwnerIsGroup) ? 1 : 0); + bytes[i++] = (byte)Message.Length; + Buffer.BlockCopy(Message, 0, bytes, i, Message.Length); i += Message.Length; + bytes[i++] = (byte)URL.Length; + Buffer.BlockCopy(URL, 0, bytes, i, URL.Length); i += URL.Length; + } + + } + + public override int Length + { + get + { + int length = 10; + length += Data.Length; + return length; + } + } + public DataBlock Data; + + public LoadURLPacket() + { + HasVariableBlocks = false; + Type = PacketType.LoadURL; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 194; + Header.Reliable = true; + Data = new DataBlock(); + } + + public LoadURLPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + Data.FromBytes(bytes, ref i); + } + + public LoadURLPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + Data.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += Data.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class ScriptTeleportRequestPacket : Packet + { + /// + public sealed class DataBlock : PacketBlock + { + public byte[] ObjectName; + public byte[] SimName; + public Vector3 SimPosition; + public Vector3 LookAt; + + public override int Length + { + get + { + int length = 26; + if (ObjectName != null) { length += ObjectName.Length; } + if (SimName != null) { length += SimName.Length; } + return length; + } + } + + public DataBlock() { } + public DataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + length = bytes[i++]; + ObjectName = new byte[length]; + Buffer.BlockCopy(bytes, i, ObjectName, 0, length); i += length; + length = bytes[i++]; + SimName = new byte[length]; + Buffer.BlockCopy(bytes, i, SimName, 0, length); i += length; + SimPosition.FromBytes(bytes, i); i += 12; + LookAt.FromBytes(bytes, i); i += 12; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + bytes[i++] = (byte)ObjectName.Length; + Buffer.BlockCopy(ObjectName, 0, bytes, i, ObjectName.Length); i += ObjectName.Length; + bytes[i++] = (byte)SimName.Length; + Buffer.BlockCopy(SimName, 0, bytes, i, SimName.Length); i += SimName.Length; + SimPosition.ToBytes(bytes, i); i += 12; + LookAt.ToBytes(bytes, i); i += 12; + } + + } + + public override int Length + { + get + { + int length = 10; + length += Data.Length; + return length; + } + } + public DataBlock Data; + + public ScriptTeleportRequestPacket() + { + HasVariableBlocks = false; + Type = PacketType.ScriptTeleportRequest; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 195; + Header.Reliable = true; + Data = new DataBlock(); + } + + public ScriptTeleportRequestPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + Data.FromBytes(bytes, ref i); + } + + public ScriptTeleportRequestPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + Data.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += Data.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class ParcelOverlayPacket : Packet + { + /// + public sealed class ParcelDataBlock : PacketBlock + { + public int SequenceID; + public byte[] Data; + + public override int Length + { + get + { + int length = 6; + if (Data != null) { length += Data.Length; } + return length; + } + } + + public ParcelDataBlock() { } + public ParcelDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + SequenceID = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + length = (bytes[i++] + (bytes[i++] << 8)); + Data = new byte[length]; + Buffer.BlockCopy(bytes, i, Data, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.IntToBytes(SequenceID, bytes, i); i += 4; + bytes[i++] = (byte)(Data.Length % 256); + bytes[i++] = (byte)((Data.Length >> 8) % 256); + Buffer.BlockCopy(Data, 0, bytes, i, Data.Length); i += Data.Length; + } + + } + + public override int Length + { + get + { + int length = 10; + length += ParcelData.Length; + return length; + } + } + public ParcelDataBlock ParcelData; + + public ParcelOverlayPacket() + { + HasVariableBlocks = false; + Type = PacketType.ParcelOverlay; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 196; + Header.Reliable = true; + Header.Zerocoded = true; + ParcelData = new ParcelDataBlock(); + } + + public ParcelOverlayPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + ParcelData.FromBytes(bytes, ref i); + } + + public ParcelOverlayPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + ParcelData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += ParcelData.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class ParcelPropertiesRequestByIDPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class ParcelDataBlock : PacketBlock + { + public int SequenceID; + public int LocalID; + + public override int Length + { + get + { + return 8; + } + } + + public ParcelDataBlock() { } + public ParcelDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + SequenceID = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + LocalID = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.IntToBytes(SequenceID, bytes, i); i += 4; + Utils.IntToBytes(LocalID, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += ParcelData.Length; + return length; + } + } + public AgentDataBlock AgentData; + public ParcelDataBlock ParcelData; + + public ParcelPropertiesRequestByIDPacket() + { + HasVariableBlocks = false; + Type = PacketType.ParcelPropertiesRequestByID; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 197; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + ParcelData = new ParcelDataBlock(); + } + + public ParcelPropertiesRequestByIDPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + ParcelData.FromBytes(bytes, ref i); + } + + public ParcelPropertiesRequestByIDPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + ParcelData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += ParcelData.Length; + if (Header.AckList != null && 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); + ParcelData.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class ParcelPropertiesUpdatePacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class ParcelDataBlock : PacketBlock + { + public int LocalID; + public uint Flags; + public uint ParcelFlags; + public int SalePrice; + public byte[] Name; + public byte[] Desc; + public byte[] MusicURL; + public byte[] MediaURL; + public UUID MediaID; + public byte MediaAutoScale; + public UUID GroupID; + public int PassPrice; + public float PassHours; + public byte Category; + public UUID AuthBuyerID; + public UUID SnapshotID; + public Vector3 UserLocation; + public Vector3 UserLookAt; + public byte LandingType; + + public override int Length + { + get + { + int length = 119; + if (Name != null) { length += Name.Length; } + if (Desc != null) { length += Desc.Length; } + if (MusicURL != null) { length += MusicURL.Length; } + if (MediaURL != null) { length += MediaURL.Length; } + return length; + } + } + + public ParcelDataBlock() { } + public ParcelDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + LocalID = (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)); + ParcelFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + SalePrice = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + length = bytes[i++]; + Name = new byte[length]; + Buffer.BlockCopy(bytes, i, Name, 0, length); i += length; + length = bytes[i++]; + Desc = new byte[length]; + Buffer.BlockCopy(bytes, i, Desc, 0, length); i += length; + length = bytes[i++]; + MusicURL = new byte[length]; + Buffer.BlockCopy(bytes, i, MusicURL, 0, length); i += length; + length = bytes[i++]; + MediaURL = new byte[length]; + Buffer.BlockCopy(bytes, i, MediaURL, 0, length); i += length; + MediaID.FromBytes(bytes, i); i += 16; + MediaAutoScale = (byte)bytes[i++]; + GroupID.FromBytes(bytes, i); i += 16; + PassPrice = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + PassHours = Utils.BytesToFloat(bytes, i); i += 4; + Category = (byte)bytes[i++]; + AuthBuyerID.FromBytes(bytes, i); i += 16; + SnapshotID.FromBytes(bytes, i); i += 16; + UserLocation.FromBytes(bytes, i); i += 12; + UserLookAt.FromBytes(bytes, i); i += 12; + LandingType = (byte)bytes[i++]; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.IntToBytes(LocalID, bytes, i); i += 4; + Utils.UIntToBytes(Flags, bytes, i); i += 4; + Utils.UIntToBytes(ParcelFlags, bytes, i); i += 4; + Utils.IntToBytes(SalePrice, bytes, i); i += 4; + bytes[i++] = (byte)Name.Length; + Buffer.BlockCopy(Name, 0, bytes, i, Name.Length); i += Name.Length; + bytes[i++] = (byte)Desc.Length; + Buffer.BlockCopy(Desc, 0, bytes, i, Desc.Length); i += Desc.Length; + bytes[i++] = (byte)MusicURL.Length; + Buffer.BlockCopy(MusicURL, 0, bytes, i, MusicURL.Length); i += MusicURL.Length; + bytes[i++] = (byte)MediaURL.Length; + Buffer.BlockCopy(MediaURL, 0, bytes, i, MediaURL.Length); i += MediaURL.Length; + MediaID.ToBytes(bytes, i); i += 16; + bytes[i++] = MediaAutoScale; + GroupID.ToBytes(bytes, i); i += 16; + Utils.IntToBytes(PassPrice, bytes, i); i += 4; + Utils.FloatToBytes(PassHours, bytes, i); i += 4; + bytes[i++] = Category; + AuthBuyerID.ToBytes(bytes, i); i += 16; + SnapshotID.ToBytes(bytes, i); i += 16; + UserLocation.ToBytes(bytes, i); i += 12; + UserLookAt.ToBytes(bytes, i); i += 12; + bytes[i++] = LandingType; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += ParcelData.Length; + return length; + } + } + public AgentDataBlock AgentData; + public ParcelDataBlock ParcelData; + + public ParcelPropertiesUpdatePacket() + { + HasVariableBlocks = false; + Type = PacketType.ParcelPropertiesUpdate; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 198; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + ParcelData = new ParcelDataBlock(); + } + + public ParcelPropertiesUpdatePacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + ParcelData.FromBytes(bytes, ref i); + } + + public ParcelPropertiesUpdatePacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + ParcelData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += ParcelData.Length; + if (Header.AckList != null && 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); + ParcelData.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class ParcelReturnObjectsPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class ParcelDataBlock : PacketBlock + { + public int LocalID; + public uint ReturnType; + + public override int Length + { + get + { + return 8; + } + } + + public ParcelDataBlock() { } + public ParcelDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(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(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.IntToBytes(LocalID, bytes, i); i += 4; + Utils.UIntToBytes(ReturnType, bytes, i); i += 4; + } + + } + + /// + public sealed class TaskIDsBlock : PacketBlock + { + public UUID TaskID; + + public override int Length + { + get + { + return 16; + } + } + + public TaskIDsBlock() { } + public TaskIDsBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + TaskID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + TaskID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class OwnerIDsBlock : PacketBlock + { + public UUID OwnerID; + + public override int Length + { + get + { + return 16; + } + } + + public OwnerIDsBlock() { } + public OwnerIDsBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + OwnerID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + OwnerID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 12; + length += AgentData.Length; + length += ParcelData.Length; + for (int j = 0; j < TaskIDs.Length; j++) + length += TaskIDs[j].Length; + for (int j = 0; j < OwnerIDs.Length; j++) + length += OwnerIDs[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public ParcelDataBlock ParcelData; + public TaskIDsBlock[] TaskIDs; + public OwnerIDsBlock[] OwnerIDs; + + public ParcelReturnObjectsPacket() + { + HasVariableBlocks = true; + Type = PacketType.ParcelReturnObjects; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 199; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + ParcelData = new ParcelDataBlock(); + TaskIDs = null; + OwnerIDs = null; + } + + public ParcelReturnObjectsPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + ParcelData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(TaskIDs == null || TaskIDs.Length != -1) { + TaskIDs = new TaskIDsBlock[count]; + for(int j = 0; j < count; j++) + { TaskIDs[j] = new TaskIDsBlock(); } + } + for (int j = 0; j < count; j++) + { TaskIDs[j].FromBytes(bytes, ref i); } + count = (int)bytes[i++]; + if(OwnerIDs == null || OwnerIDs.Length != -1) { + OwnerIDs = new OwnerIDsBlock[count]; + for(int j = 0; j < count; j++) + { OwnerIDs[j] = new OwnerIDsBlock(); } + } + for (int j = 0; j < count; j++) + { OwnerIDs[j].FromBytes(bytes, ref i); } + } + + public ParcelReturnObjectsPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + ParcelData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(TaskIDs == null || TaskIDs.Length != count) { + TaskIDs = new TaskIDsBlock[count]; + for(int j = 0; j < count; j++) + { TaskIDs[j] = new TaskIDsBlock(); } + } + for (int j = 0; j < count; j++) + { TaskIDs[j].FromBytes(bytes, ref i); } + count = (int)bytes[i++]; + if(OwnerIDs == null || OwnerIDs.Length != count) { + OwnerIDs = new OwnerIDsBlock[count]; + for(int j = 0; j < count; j++) + { OwnerIDs[j] = new OwnerIDsBlock(); } + } + for (int j = 0; j < count; j++) + { OwnerIDs[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += ParcelData.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 != null && 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); + ParcelData.ToBytes(bytes, ref i); + bytes[i++] = (byte)TaskIDs.Length; + for (int j = 0; j < TaskIDs.Length; j++) { TaskIDs[j].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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + fixedLength += ParcelData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + ParcelData.ToBytes(fixedBytes, ref i); + fixedLength += 2; + + int TaskIDsStart = 0; + int OwnerIDsStart = 0; + do + { + int variableLength = 0; + int TaskIDsCount = 0; + int OwnerIDsCount = 0; + + i = TaskIDsStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < TaskIDs.Length) { + int blockLength = TaskIDs[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == TaskIDsStart) { + variableLength += blockLength; + ++TaskIDsCount; + } + else { break; } + ++i; + } + + i = OwnerIDsStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < OwnerIDs.Length) { + int blockLength = OwnerIDs[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == OwnerIDsStart) { + variableLength += blockLength; + ++OwnerIDsCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)TaskIDsCount; + for (i = TaskIDsStart; i < TaskIDsStart + TaskIDsCount; i++) { TaskIDs[i].ToBytes(packet, ref length); } + TaskIDsStart += TaskIDsCount; + + packet[length++] = (byte)OwnerIDsCount; + for (i = OwnerIDsStart; i < OwnerIDsStart + OwnerIDsCount; i++) { OwnerIDs[i].ToBytes(packet, ref length); } + OwnerIDsStart += OwnerIDsCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + TaskIDsStart < TaskIDs.Length || + OwnerIDsStart < OwnerIDs.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class ParcelSetOtherCleanTimePacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class ParcelDataBlock : PacketBlock + { + public int LocalID; + public int OtherCleanTime; + + public override int Length + { + get + { + return 8; + } + } + + public ParcelDataBlock() { } + public ParcelDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(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(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.IntToBytes(LocalID, bytes, i); i += 4; + Utils.IntToBytes(OtherCleanTime, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += ParcelData.Length; + return length; + } + } + public AgentDataBlock AgentData; + public ParcelDataBlock ParcelData; + + public ParcelSetOtherCleanTimePacket() + { + HasVariableBlocks = false; + Type = PacketType.ParcelSetOtherCleanTime; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 200; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + ParcelData = new ParcelDataBlock(); + } + + public ParcelSetOtherCleanTimePacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + ParcelData.FromBytes(bytes, ref i); + } + + public ParcelSetOtherCleanTimePacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + ParcelData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += ParcelData.Length; + if (Header.AckList != null && 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); + ParcelData.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class ParcelDisableObjectsPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class ParcelDataBlock : PacketBlock + { + public int LocalID; + public uint ReturnType; + + public override int Length + { + get + { + return 8; + } + } + + public ParcelDataBlock() { } + public ParcelDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(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(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.IntToBytes(LocalID, bytes, i); i += 4; + Utils.UIntToBytes(ReturnType, bytes, i); i += 4; + } + + } + + /// + public sealed class TaskIDsBlock : PacketBlock + { + public UUID TaskID; + + public override int Length + { + get + { + return 16; + } + } + + public TaskIDsBlock() { } + public TaskIDsBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + TaskID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + TaskID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class OwnerIDsBlock : PacketBlock + { + public UUID OwnerID; + + public override int Length + { + get + { + return 16; + } + } + + public OwnerIDsBlock() { } + public OwnerIDsBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + OwnerID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + OwnerID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 12; + length += AgentData.Length; + length += ParcelData.Length; + for (int j = 0; j < TaskIDs.Length; j++) + length += TaskIDs[j].Length; + for (int j = 0; j < OwnerIDs.Length; j++) + length += OwnerIDs[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public ParcelDataBlock ParcelData; + public TaskIDsBlock[] TaskIDs; + public OwnerIDsBlock[] OwnerIDs; + + public ParcelDisableObjectsPacket() + { + HasVariableBlocks = true; + Type = PacketType.ParcelDisableObjects; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 201; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + ParcelData = new ParcelDataBlock(); + TaskIDs = null; + OwnerIDs = null; + } + + public ParcelDisableObjectsPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + ParcelData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(TaskIDs == null || TaskIDs.Length != -1) { + TaskIDs = new TaskIDsBlock[count]; + for(int j = 0; j < count; j++) + { TaskIDs[j] = new TaskIDsBlock(); } + } + for (int j = 0; j < count; j++) + { TaskIDs[j].FromBytes(bytes, ref i); } + count = (int)bytes[i++]; + if(OwnerIDs == null || OwnerIDs.Length != -1) { + OwnerIDs = new OwnerIDsBlock[count]; + for(int j = 0; j < count; j++) + { OwnerIDs[j] = new OwnerIDsBlock(); } + } + for (int j = 0; j < count; j++) + { OwnerIDs[j].FromBytes(bytes, ref i); } + } + + public ParcelDisableObjectsPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + ParcelData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(TaskIDs == null || TaskIDs.Length != count) { + TaskIDs = new TaskIDsBlock[count]; + for(int j = 0; j < count; j++) + { TaskIDs[j] = new TaskIDsBlock(); } + } + for (int j = 0; j < count; j++) + { TaskIDs[j].FromBytes(bytes, ref i); } + count = (int)bytes[i++]; + if(OwnerIDs == null || OwnerIDs.Length != count) { + OwnerIDs = new OwnerIDsBlock[count]; + for(int j = 0; j < count; j++) + { OwnerIDs[j] = new OwnerIDsBlock(); } + } + for (int j = 0; j < count; j++) + { OwnerIDs[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += ParcelData.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 != null && 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); + ParcelData.ToBytes(bytes, ref i); + bytes[i++] = (byte)TaskIDs.Length; + for (int j = 0; j < TaskIDs.Length; j++) { TaskIDs[j].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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + fixedLength += ParcelData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + ParcelData.ToBytes(fixedBytes, ref i); + fixedLength += 2; + + int TaskIDsStart = 0; + int OwnerIDsStart = 0; + do + { + int variableLength = 0; + int TaskIDsCount = 0; + int OwnerIDsCount = 0; + + i = TaskIDsStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < TaskIDs.Length) { + int blockLength = TaskIDs[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == TaskIDsStart) { + variableLength += blockLength; + ++TaskIDsCount; + } + else { break; } + ++i; + } + + i = OwnerIDsStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < OwnerIDs.Length) { + int blockLength = OwnerIDs[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == OwnerIDsStart) { + variableLength += blockLength; + ++OwnerIDsCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)TaskIDsCount; + for (i = TaskIDsStart; i < TaskIDsStart + TaskIDsCount; i++) { TaskIDs[i].ToBytes(packet, ref length); } + TaskIDsStart += TaskIDsCount; + + packet[length++] = (byte)OwnerIDsCount; + for (i = OwnerIDsStart; i < OwnerIDsStart + OwnerIDsCount; i++) { OwnerIDs[i].ToBytes(packet, ref length); } + OwnerIDsStart += OwnerIDsCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + TaskIDsStart < TaskIDs.Length || + OwnerIDsStart < OwnerIDs.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class ParcelSelectObjectsPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class ParcelDataBlock : PacketBlock + { + public int LocalID; + public uint ReturnType; + + public override int Length + { + get + { + return 8; + } + } + + public ParcelDataBlock() { } + public ParcelDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(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(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.IntToBytes(LocalID, bytes, i); i += 4; + Utils.UIntToBytes(ReturnType, bytes, i); i += 4; + } + + } + + /// + public sealed class ReturnIDsBlock : PacketBlock + { + public UUID ReturnID; + + public override int Length + { + get + { + return 16; + } + } + + public ReturnIDsBlock() { } + public ReturnIDsBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + ReturnID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + ReturnID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentData.Length; + length += ParcelData.Length; + for (int j = 0; j < ReturnIDs.Length; j++) + length += ReturnIDs[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public ParcelDataBlock ParcelData; + public ReturnIDsBlock[] ReturnIDs; + + public ParcelSelectObjectsPacket() + { + HasVariableBlocks = true; + Type = PacketType.ParcelSelectObjects; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 202; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + ParcelData = new ParcelDataBlock(); + ReturnIDs = null; + } + + public ParcelSelectObjectsPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + ParcelData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ReturnIDs == null || ReturnIDs.Length != -1) { + ReturnIDs = new ReturnIDsBlock[count]; + for(int j = 0; j < count; j++) + { ReturnIDs[j] = new ReturnIDsBlock(); } + } + for (int j = 0; j < count; j++) + { ReturnIDs[j].FromBytes(bytes, ref i); } + } + + public ParcelSelectObjectsPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + ParcelData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ReturnIDs == null || ReturnIDs.Length != count) { + ReturnIDs = new ReturnIDsBlock[count]; + for(int j = 0; j < count; j++) + { ReturnIDs[j] = new ReturnIDsBlock(); } + } + for (int j = 0; j < count; j++) + { ReturnIDs[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += ParcelData.Length; + length++; + for (int j = 0; j < ReturnIDs.Length; j++) { length += ReturnIDs[j].Length; } + if (Header.AckList != null && 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); + ParcelData.ToBytes(bytes, ref i); + bytes[i++] = (byte)ReturnIDs.Length; + for (int j = 0; j < ReturnIDs.Length; j++) { ReturnIDs[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + fixedLength += ParcelData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + ParcelData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int ReturnIDsStart = 0; + do + { + int variableLength = 0; + int ReturnIDsCount = 0; + + i = ReturnIDsStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < ReturnIDs.Length) { + int blockLength = ReturnIDs[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ReturnIDsStart) { + variableLength += blockLength; + ++ReturnIDsCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)ReturnIDsCount; + for (i = ReturnIDsStart; i < ReturnIDsStart + ReturnIDsCount; i++) { ReturnIDs[i].ToBytes(packet, ref length); } + ReturnIDsStart += ReturnIDsCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + ReturnIDsStart < ReturnIDs.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class EstateCovenantRequestPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + return length; + } + } + public AgentDataBlock AgentData; + + public EstateCovenantRequestPacket() + { + HasVariableBlocks = false; + Type = PacketType.EstateCovenantRequest; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 203; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + } + + public EstateCovenantRequestPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + } + + public EstateCovenantRequestPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class EstateCovenantReplyPacket : Packet + { + /// + public sealed class DataBlock : PacketBlock + { + public UUID CovenantID; + public uint CovenantTimestamp; + public byte[] EstateName; + public UUID EstateOwnerID; + + public override int Length + { + get + { + int length = 37; + if (EstateName != null) { length += EstateName.Length; } + return length; + } + } + + public DataBlock() { } + public DataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + CovenantID.FromBytes(bytes, i); i += 16; + CovenantTimestamp = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + length = bytes[i++]; + EstateName = new byte[length]; + Buffer.BlockCopy(bytes, i, EstateName, 0, length); i += length; + EstateOwnerID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + CovenantID.ToBytes(bytes, i); i += 16; + Utils.UIntToBytes(CovenantTimestamp, bytes, i); i += 4; + bytes[i++] = (byte)EstateName.Length; + Buffer.BlockCopy(EstateName, 0, bytes, i, EstateName.Length); i += EstateName.Length; + EstateOwnerID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 10; + length += Data.Length; + return length; + } + } + public DataBlock Data; + + public EstateCovenantReplyPacket() + { + HasVariableBlocks = false; + Type = PacketType.EstateCovenantReply; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 204; + Header.Reliable = true; + Data = new DataBlock(); + } + + public EstateCovenantReplyPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + Data.FromBytes(bytes, ref i); + } + + public EstateCovenantReplyPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + Data.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += Data.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class ForceObjectSelectPacket : Packet + { + /// + public sealed class HeaderBlock : PacketBlock + { + public bool ResetList; + + public override int Length + { + get + { + return 1; + } + } + + public HeaderBlock() { } + public HeaderBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + ResetList = (bytes[i++] != 0) ? (bool)true : (bool)false; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + bytes[i++] = (byte)((ResetList) ? 1 : 0); + } + + } + + /// + public sealed class DataBlock : PacketBlock + { + public uint LocalID; + + public override int Length + { + get + { + return 4; + } + } + + public DataBlock() { } + public DataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + LocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UIntToBytes(LocalID, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 11; + length += _Header.Length; + for (int j = 0; j < Data.Length; j++) + length += Data[j].Length; + return length; + } + } + public HeaderBlock _Header; + public DataBlock[] Data; + + public ForceObjectSelectPacket() + { + HasVariableBlocks = true; + Type = PacketType.ForceObjectSelect; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 205; + Header.Reliable = true; + _Header = new HeaderBlock(); + Data = null; + } + + public ForceObjectSelectPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + _Header.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(Data == null || Data.Length != -1) { + Data = new DataBlock[count]; + for(int j = 0; j < count; j++) + { Data[j] = new DataBlock(); } + } + for (int j = 0; j < count; j++) + { Data[j].FromBytes(bytes, ref i); } + } + + public ForceObjectSelectPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + _Header.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(Data == null || Data.Length != count) { + Data = new DataBlock[count]; + for(int j = 0; j < count; j++) + { Data[j] = new DataBlock(); } + } + for (int j = 0; j < count; j++) + { Data[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += _Header.Length; + length++; + for (int j = 0; j < Data.Length; j++) { length += Data[j].Length; } + if (Header.AckList != null && Header.AckList.Length > 0) { length += Header.AckList.Length * 4 + 1; } + byte[] bytes = new byte[length]; + int i = 0; + Header.ToBytes(bytes, ref i); + _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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += _Header.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + _Header.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int DataStart = 0; + do + { + int variableLength = 0; + int DataCount = 0; + + i = DataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < Data.Length) { + int blockLength = Data[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == DataStart) { + variableLength += blockLength; + ++DataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)DataCount; + for (i = DataStart; i < DataStart + DataCount; i++) { Data[i].ToBytes(packet, ref length); } + DataStart += DataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + DataStart < Data.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class ParcelBuyPassPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class ParcelDataBlock : PacketBlock + { + public int LocalID; + + public override int Length + { + get + { + return 4; + } + } + + public ParcelDataBlock() { } + public ParcelDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + LocalID = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.IntToBytes(LocalID, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += ParcelData.Length; + return length; + } + } + public AgentDataBlock AgentData; + public ParcelDataBlock ParcelData; + + public ParcelBuyPassPacket() + { + HasVariableBlocks = false; + Type = PacketType.ParcelBuyPass; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 206; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + ParcelData = new ParcelDataBlock(); + } + + public ParcelBuyPassPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + ParcelData.FromBytes(bytes, ref i); + } + + public ParcelBuyPassPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + ParcelData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += ParcelData.Length; + if (Header.AckList != null && 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); + ParcelData.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class ParcelDeedToGroupPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class DataBlock : PacketBlock + { + public UUID GroupID; + public int LocalID; + + public override int Length + { + get + { + return 20; + } + } + + public DataBlock() { } + public DataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + GroupID.FromBytes(bytes, i); i += 16; + LocalID = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + GroupID.ToBytes(bytes, i); i += 16; + Utils.IntToBytes(LocalID, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += Data.Length; + return length; + } + } + public AgentDataBlock AgentData; + public DataBlock Data; + + public ParcelDeedToGroupPacket() + { + HasVariableBlocks = false; + Type = PacketType.ParcelDeedToGroup; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 207; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + Data = new DataBlock(); + } + + public ParcelDeedToGroupPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + Data.FromBytes(bytes, ref i); + } + + public ParcelDeedToGroupPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + Data.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += Data.Length; + if (Header.AckList != null && 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); + Data.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class ParcelReclaimPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class DataBlock : PacketBlock + { + public int LocalID; + + public override int Length + { + get + { + return 4; + } + } + + public DataBlock() { } + public DataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + LocalID = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.IntToBytes(LocalID, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += Data.Length; + return length; + } + } + public AgentDataBlock AgentData; + public DataBlock Data; + + public ParcelReclaimPacket() + { + HasVariableBlocks = false; + Type = PacketType.ParcelReclaim; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 208; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + Data = new DataBlock(); + } + + public ParcelReclaimPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + Data.FromBytes(bytes, ref i); + } + + public ParcelReclaimPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + Data.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += Data.Length; + if (Header.AckList != null && 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); + Data.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class ParcelClaimPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class DataBlock : PacketBlock + { + public UUID GroupID; + public bool IsGroupOwned; + public bool Final; + + public override int Length + { + get + { + return 18; + } + } + + public DataBlock() { } + public DataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + GroupID.FromBytes(bytes, i); i += 16; + IsGroupOwned = (bytes[i++] != 0) ? (bool)true : (bool)false; + Final = (bytes[i++] != 0) ? (bool)true : (bool)false; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + GroupID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)((IsGroupOwned) ? 1 : 0); + bytes[i++] = (byte)((Final) ? 1 : 0); + } + + } + + /// + public sealed class ParcelDataBlock : PacketBlock + { + public float West; + public float South; + public float East; + public float North; + + public override int Length + { + get + { + return 16; + } + } + + public ParcelDataBlock() { } + public ParcelDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + West = Utils.BytesToFloat(bytes, i); i += 4; + South = Utils.BytesToFloat(bytes, i); i += 4; + East = Utils.BytesToFloat(bytes, i); i += 4; + North = Utils.BytesToFloat(bytes, i); i += 4; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.FloatToBytes(West, bytes, i); i += 4; + Utils.FloatToBytes(South, bytes, i); i += 4; + Utils.FloatToBytes(East, bytes, i); i += 4; + Utils.FloatToBytes(North, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentData.Length; + length += Data.Length; + for (int j = 0; j < ParcelData.Length; j++) + length += ParcelData[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public DataBlock Data; + public ParcelDataBlock[] ParcelData; + + public ParcelClaimPacket() + { + HasVariableBlocks = true; + Type = PacketType.ParcelClaim; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 209; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + Data = new DataBlock(); + ParcelData = null; + } + + public ParcelClaimPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + Data.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ParcelData == null || ParcelData.Length != -1) { + ParcelData = new ParcelDataBlock[count]; + for(int j = 0; j < count; j++) + { ParcelData[j] = new ParcelDataBlock(); } + } + for (int j = 0; j < count; j++) + { ParcelData[j].FromBytes(bytes, ref i); } + } + + public ParcelClaimPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + Data.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ParcelData == null || ParcelData.Length != count) { + ParcelData = new ParcelDataBlock[count]; + for(int j = 0; j < count; j++) + { ParcelData[j] = new ParcelDataBlock(); } + } + for (int j = 0; j < count; j++) + { ParcelData[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += Data.Length; + length++; + for (int j = 0; j < ParcelData.Length; j++) { length += ParcelData[j].Length; } + if (Header.AckList != null && 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); + Data.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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + fixedLength += Data.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + Data.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int ParcelDataStart = 0; + do + { + int variableLength = 0; + int ParcelDataCount = 0; + + i = ParcelDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < ParcelData.Length) { + int blockLength = ParcelData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ParcelDataStart) { + variableLength += blockLength; + ++ParcelDataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)ParcelDataCount; + for (i = ParcelDataStart; i < ParcelDataStart + ParcelDataCount; i++) { ParcelData[i].ToBytes(packet, ref length); } + ParcelDataStart += ParcelDataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + ParcelDataStart < ParcelData.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class ParcelJoinPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class ParcelDataBlock : PacketBlock + { + public float West; + public float South; + public float East; + public float North; + + public override int Length + { + get + { + return 16; + } + } + + public ParcelDataBlock() { } + public ParcelDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + West = Utils.BytesToFloat(bytes, i); i += 4; + South = Utils.BytesToFloat(bytes, i); i += 4; + East = Utils.BytesToFloat(bytes, i); i += 4; + North = Utils.BytesToFloat(bytes, i); i += 4; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.FloatToBytes(West, bytes, i); i += 4; + Utils.FloatToBytes(South, bytes, i); i += 4; + Utils.FloatToBytes(East, bytes, i); i += 4; + Utils.FloatToBytes(North, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += ParcelData.Length; + return length; + } + } + public AgentDataBlock AgentData; + public ParcelDataBlock ParcelData; + + public ParcelJoinPacket() + { + HasVariableBlocks = false; + Type = PacketType.ParcelJoin; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 210; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + ParcelData = new ParcelDataBlock(); + } + + public ParcelJoinPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + ParcelData.FromBytes(bytes, ref i); + } + + public ParcelJoinPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + ParcelData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += ParcelData.Length; + if (Header.AckList != null && 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); + ParcelData.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class ParcelDividePacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class ParcelDataBlock : PacketBlock + { + public float West; + public float South; + public float East; + public float North; + + public override int Length + { + get + { + return 16; + } + } + + public ParcelDataBlock() { } + public ParcelDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + West = Utils.BytesToFloat(bytes, i); i += 4; + South = Utils.BytesToFloat(bytes, i); i += 4; + East = Utils.BytesToFloat(bytes, i); i += 4; + North = Utils.BytesToFloat(bytes, i); i += 4; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.FloatToBytes(West, bytes, i); i += 4; + Utils.FloatToBytes(South, bytes, i); i += 4; + Utils.FloatToBytes(East, bytes, i); i += 4; + Utils.FloatToBytes(North, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += ParcelData.Length; + return length; + } + } + public AgentDataBlock AgentData; + public ParcelDataBlock ParcelData; + + public ParcelDividePacket() + { + HasVariableBlocks = false; + Type = PacketType.ParcelDivide; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 211; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + ParcelData = new ParcelDataBlock(); + } + + public ParcelDividePacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + ParcelData.FromBytes(bytes, ref i); + } + + public ParcelDividePacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + ParcelData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += ParcelData.Length; + if (Header.AckList != null && 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); + ParcelData.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class ParcelReleasePacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class DataBlock : PacketBlock + { + public int LocalID; + + public override int Length + { + get + { + return 4; + } + } + + public DataBlock() { } + public DataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + LocalID = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.IntToBytes(LocalID, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += Data.Length; + return length; + } + } + public AgentDataBlock AgentData; + public DataBlock Data; + + public ParcelReleasePacket() + { + HasVariableBlocks = false; + Type = PacketType.ParcelRelease; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 212; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + Data = new DataBlock(); + } + + public ParcelReleasePacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + Data.FromBytes(bytes, ref i); + } + + public ParcelReleasePacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + Data.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += Data.Length; + if (Header.AckList != null && 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); + Data.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class ParcelBuyPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class DataBlock : PacketBlock + { + public UUID GroupID; + public bool IsGroupOwned; + public bool RemoveContribution; + public int LocalID; + public bool Final; + + public override int Length + { + get + { + return 23; + } + } + + public DataBlock() { } + public DataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + GroupID.FromBytes(bytes, i); i += 16; + IsGroupOwned = (bytes[i++] != 0) ? (bool)true : (bool)false; + RemoveContribution = (bytes[i++] != 0) ? (bool)true : (bool)false; + LocalID = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + Final = (bytes[i++] != 0) ? (bool)true : (bool)false; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + GroupID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)((IsGroupOwned) ? 1 : 0); + bytes[i++] = (byte)((RemoveContribution) ? 1 : 0); + Utils.IntToBytes(LocalID, bytes, i); i += 4; + bytes[i++] = (byte)((Final) ? 1 : 0); + } + + } + + /// + public sealed class ParcelDataBlock : PacketBlock + { + public int Price; + public int Area; + + public override int Length + { + get + { + return 8; + } + } + + public ParcelDataBlock() { } + public ParcelDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + Price = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + Area = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.IntToBytes(Price, bytes, i); i += 4; + Utils.IntToBytes(Area, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += Data.Length; + length += ParcelData.Length; + return length; + } + } + public AgentDataBlock AgentData; + public DataBlock Data; + public ParcelDataBlock ParcelData; + + public ParcelBuyPacket() + { + HasVariableBlocks = false; + Type = PacketType.ParcelBuy; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 213; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + Data = new DataBlock(); + ParcelData = new ParcelDataBlock(); + } + + public ParcelBuyPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + Data.FromBytes(bytes, ref i); + ParcelData.FromBytes(bytes, ref i); + } + + public ParcelBuyPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + Data.FromBytes(bytes, ref i); + ParcelData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += Data.Length; + length += ParcelData.Length; + if (Header.AckList != null && 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); + Data.ToBytes(bytes, ref i); + ParcelData.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class ParcelGodForceOwnerPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class DataBlock : PacketBlock + { + public UUID OwnerID; + public int LocalID; + + public override int Length + { + get + { + return 20; + } + } + + public DataBlock() { } + public DataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + OwnerID.FromBytes(bytes, i); i += 16; + LocalID = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + OwnerID.ToBytes(bytes, i); i += 16; + Utils.IntToBytes(LocalID, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += Data.Length; + return length; + } + } + public AgentDataBlock AgentData; + public DataBlock Data; + + public ParcelGodForceOwnerPacket() + { + HasVariableBlocks = false; + Type = PacketType.ParcelGodForceOwner; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 214; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + Data = new DataBlock(); + } + + public ParcelGodForceOwnerPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + Data.FromBytes(bytes, ref i); + } + + public ParcelGodForceOwnerPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + Data.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += Data.Length; + if (Header.AckList != null && 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); + Data.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class ParcelAccessListRequestPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class DataBlock : PacketBlock + { + public int SequenceID; + public uint Flags; + public int LocalID; + + public override int Length + { + get + { + return 12; + } + } + + public DataBlock() { } + public DataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + 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)); + LocalID = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.IntToBytes(SequenceID, bytes, i); i += 4; + Utils.UIntToBytes(Flags, bytes, i); i += 4; + Utils.IntToBytes(LocalID, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += Data.Length; + return length; + } + } + public AgentDataBlock AgentData; + public DataBlock Data; + + public ParcelAccessListRequestPacket() + { + HasVariableBlocks = false; + Type = PacketType.ParcelAccessListRequest; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 215; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + Data = new DataBlock(); + } + + public ParcelAccessListRequestPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + Data.FromBytes(bytes, ref i); + } + + public ParcelAccessListRequestPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + Data.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += Data.Length; + if (Header.AckList != null && 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); + Data.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class ParcelAccessListReplyPacket : Packet + { + /// + public sealed class DataBlock : PacketBlock + { + public UUID AgentID; + public int SequenceID; + public uint Flags; + public int LocalID; + + public override int Length + { + get + { + return 28; + } + } + + public DataBlock() { } + public DataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + 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)); + LocalID = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + Utils.IntToBytes(SequenceID, bytes, i); i += 4; + Utils.UIntToBytes(Flags, bytes, i); i += 4; + Utils.IntToBytes(LocalID, bytes, i); i += 4; + } + + } + + /// + public sealed class ListBlock : PacketBlock + { + public UUID ID; + public int Time; + public uint Flags; + + public override int Length + { + get + { + return 24; + } + } + + public ListBlock() { } + public ListBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + ID.FromBytes(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(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + ID.ToBytes(bytes, i); i += 16; + Utils.IntToBytes(Time, bytes, i); i += 4; + Utils.UIntToBytes(Flags, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 11; + length += Data.Length; + for (int j = 0; j < List.Length; j++) + length += List[j].Length; + return length; + } + } + public DataBlock Data; + public ListBlock[] List; + + public ParcelAccessListReplyPacket() + { + HasVariableBlocks = true; + Type = PacketType.ParcelAccessListReply; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 216; + Header.Reliable = true; + Header.Zerocoded = true; + Data = new DataBlock(); + List = null; + } + + public ParcelAccessListReplyPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + Data.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(List == null || List.Length != -1) { + List = new ListBlock[count]; + for(int j = 0; j < count; j++) + { List[j] = new ListBlock(); } + } + for (int j = 0; j < count; j++) + { List[j].FromBytes(bytes, ref i); } + } + + public ParcelAccessListReplyPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + Data.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(List == null || List.Length != count) { + List = new ListBlock[count]; + for(int j = 0; j < count; j++) + { List[j] = new ListBlock(); } + } + for (int j = 0; j < count; j++) + { List[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += Data.Length; + length++; + for (int j = 0; j < List.Length; j++) { length += List[j].Length; } + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += Data.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + Data.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int ListStart = 0; + do + { + int variableLength = 0; + int ListCount = 0; + + i = ListStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < List.Length) { + int blockLength = List[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ListStart) { + variableLength += blockLength; + ++ListCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)ListCount; + for (i = ListStart; i < ListStart + ListCount; i++) { List[i].ToBytes(packet, ref length); } + ListStart += ListCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + ListStart < List.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class ParcelAccessListUpdatePacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class DataBlock : PacketBlock + { + public uint Flags; + public int LocalID; + public UUID TransactionID; + public int SequenceID; + public int Sections; + + public override int Length + { + get + { + return 32; + } + } + + public DataBlock() { } + public DataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + Flags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + LocalID = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + TransactionID.FromBytes(bytes, i); i += 16; + SequenceID = (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)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UIntToBytes(Flags, bytes, i); i += 4; + Utils.IntToBytes(LocalID, bytes, i); i += 4; + TransactionID.ToBytes(bytes, i); i += 16; + Utils.IntToBytes(SequenceID, bytes, i); i += 4; + Utils.IntToBytes(Sections, bytes, i); i += 4; + } + + } + + /// + public sealed class ListBlock : PacketBlock + { + public UUID ID; + public int Time; + public uint Flags; + + public override int Length + { + get + { + return 24; + } + } + + public ListBlock() { } + public ListBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + ID.FromBytes(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(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + ID.ToBytes(bytes, i); i += 16; + Utils.IntToBytes(Time, bytes, i); i += 4; + Utils.UIntToBytes(Flags, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentData.Length; + length += Data.Length; + for (int j = 0; j < List.Length; j++) + length += List[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public DataBlock Data; + public ListBlock[] List; + + public ParcelAccessListUpdatePacket() + { + HasVariableBlocks = true; + Type = PacketType.ParcelAccessListUpdate; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 217; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + Data = new DataBlock(); + List = null; + } + + public ParcelAccessListUpdatePacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + Data.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(List == null || List.Length != -1) { + List = new ListBlock[count]; + for(int j = 0; j < count; j++) + { List[j] = new ListBlock(); } + } + for (int j = 0; j < count; j++) + { List[j].FromBytes(bytes, ref i); } + } + + public ParcelAccessListUpdatePacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + Data.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(List == null || List.Length != count) { + List = new ListBlock[count]; + for(int j = 0; j < count; j++) + { List[j] = new ListBlock(); } + } + for (int j = 0; j < count; j++) + { List[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += Data.Length; + length++; + for (int j = 0; j < List.Length; j++) { length += List[j].Length; } + if (Header.AckList != null && 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); + 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + fixedLength += Data.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + Data.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int ListStart = 0; + do + { + int variableLength = 0; + int ListCount = 0; + + i = ListStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < List.Length) { + int blockLength = List[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ListStart) { + variableLength += blockLength; + ++ListCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)ListCount; + for (i = ListStart; i < ListStart + ListCount; i++) { List[i].ToBytes(packet, ref length); } + ListStart += ListCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + ListStart < List.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class ParcelDwellRequestPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class DataBlock : PacketBlock + { + public int LocalID; + public UUID ParcelID; + + public override int Length + { + get + { + return 20; + } + } + + public DataBlock() { } + public DataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + LocalID = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + ParcelID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.IntToBytes(LocalID, bytes, i); i += 4; + ParcelID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += Data.Length; + return length; + } + } + public AgentDataBlock AgentData; + public DataBlock Data; + + public ParcelDwellRequestPacket() + { + HasVariableBlocks = false; + Type = PacketType.ParcelDwellRequest; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 218; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + Data = new DataBlock(); + } + + public ParcelDwellRequestPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + Data.FromBytes(bytes, ref i); + } + + public ParcelDwellRequestPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + Data.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += Data.Length; + if (Header.AckList != null && 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); + Data.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class ParcelDwellReplyPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + + public override int Length + { + get + { + return 16; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class DataBlock : PacketBlock + { + public int LocalID; + public UUID ParcelID; + public float Dwell; + + public override int Length + { + get + { + return 24; + } + } + + public DataBlock() { } + public DataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + LocalID = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + ParcelID.FromBytes(bytes, i); i += 16; + Dwell = Utils.BytesToFloat(bytes, i); i += 4; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.IntToBytes(LocalID, bytes, i); i += 4; + ParcelID.ToBytes(bytes, i); i += 16; + Utils.FloatToBytes(Dwell, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += Data.Length; + return length; + } + } + public AgentDataBlock AgentData; + public DataBlock Data; + + public ParcelDwellReplyPacket() + { + HasVariableBlocks = false; + Type = PacketType.ParcelDwellReply; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 219; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + Data = new DataBlock(); + } + + public ParcelDwellReplyPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + Data.FromBytes(bytes, ref i); + } + + public ParcelDwellReplyPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + Data.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += Data.Length; + if (Header.AckList != null && 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); + Data.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class ParcelGodMarkAsContentPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class ParcelDataBlock : PacketBlock + { + public int LocalID; + + public override int Length + { + get + { + return 4; + } + } + + public ParcelDataBlock() { } + public ParcelDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + LocalID = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.IntToBytes(LocalID, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += ParcelData.Length; + return length; + } + } + public AgentDataBlock AgentData; + public ParcelDataBlock ParcelData; + + public ParcelGodMarkAsContentPacket() + { + HasVariableBlocks = false; + Type = PacketType.ParcelGodMarkAsContent; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 227; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + ParcelData = new ParcelDataBlock(); + } + + public ParcelGodMarkAsContentPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + ParcelData.FromBytes(bytes, ref i); + } + + public ParcelGodMarkAsContentPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + ParcelData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += ParcelData.Length; + if (Header.AckList != null && 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); + ParcelData.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class ViewerStartAuctionPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class ParcelDataBlock : PacketBlock + { + public int LocalID; + public UUID SnapshotID; + + public override int Length + { + get + { + return 20; + } + } + + public ParcelDataBlock() { } + public ParcelDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + LocalID = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + SnapshotID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.IntToBytes(LocalID, bytes, i); i += 4; + SnapshotID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += ParcelData.Length; + return length; + } + } + public AgentDataBlock AgentData; + public ParcelDataBlock ParcelData; + + public ViewerStartAuctionPacket() + { + HasVariableBlocks = false; + Type = PacketType.ViewerStartAuction; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 228; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + ParcelData = new ParcelDataBlock(); + } + + public ViewerStartAuctionPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + ParcelData.FromBytes(bytes, ref i); + } + + public ViewerStartAuctionPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + ParcelData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += ParcelData.Length; + if (Header.AckList != null && 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); + ParcelData.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class UUIDNameRequestPacket : Packet + { + /// + public sealed class UUIDNameBlockBlock : PacketBlock + { + public UUID ID; + + public override int Length + { + get + { + return 16; + } + } + + public UUIDNameBlockBlock() { } + public UUIDNameBlockBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + ID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + ID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 11; + for (int j = 0; j < UUIDNameBlock.Length; j++) + length += UUIDNameBlock[j].Length; + return length; + } + } + public UUIDNameBlockBlock[] UUIDNameBlock; + + public UUIDNameRequestPacket() + { + HasVariableBlocks = true; + Type = PacketType.UUIDNameRequest; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 235; + Header.Reliable = true; + UUIDNameBlock = null; + } + + public UUIDNameRequestPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + int count = (int)bytes[i++]; + if(UUIDNameBlock == null || UUIDNameBlock.Length != -1) { + UUIDNameBlock = new UUIDNameBlockBlock[count]; + for(int j = 0; j < count; j++) + { UUIDNameBlock[j] = new UUIDNameBlockBlock(); } + } + for (int j = 0; j < count; j++) + { UUIDNameBlock[j].FromBytes(bytes, ref i); } + } + + public UUIDNameRequestPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + int count = (int)bytes[i++]; + if(UUIDNameBlock == null || UUIDNameBlock.Length != count) { + UUIDNameBlock = new UUIDNameBlockBlock[count]; + for(int j = 0; j < count; j++) + { UUIDNameBlock[j] = new UUIDNameBlockBlock(); } + } + for (int j = 0; j < count; j++) + { UUIDNameBlock[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length++; + for (int j = 0; j < UUIDNameBlock.Length; j++) { length += UUIDNameBlock[j].Length; } + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int UUIDNameBlockStart = 0; + do + { + int variableLength = 0; + int UUIDNameBlockCount = 0; + + i = UUIDNameBlockStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < UUIDNameBlock.Length) { + int blockLength = UUIDNameBlock[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == UUIDNameBlockStart) { + variableLength += blockLength; + ++UUIDNameBlockCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)UUIDNameBlockCount; + for (i = UUIDNameBlockStart; i < UUIDNameBlockStart + UUIDNameBlockCount; i++) { UUIDNameBlock[i].ToBytes(packet, ref length); } + UUIDNameBlockStart += UUIDNameBlockCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + UUIDNameBlockStart < UUIDNameBlock.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class UUIDNameReplyPacket : Packet + { + /// + public sealed class UUIDNameBlockBlock : PacketBlock + { + public UUID ID; + public byte[] FirstName; + public byte[] LastName; + + public override int Length + { + get + { + int length = 18; + if (FirstName != null) { length += FirstName.Length; } + if (LastName != null) { length += LastName.Length; } + return length; + } + } + + public UUIDNameBlockBlock() { } + public UUIDNameBlockBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + ID.FromBytes(bytes, i); i += 16; + length = bytes[i++]; + FirstName = new byte[length]; + Buffer.BlockCopy(bytes, i, FirstName, 0, length); i += length; + length = bytes[i++]; + LastName = new byte[length]; + Buffer.BlockCopy(bytes, i, LastName, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + ID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)FirstName.Length; + Buffer.BlockCopy(FirstName, 0, bytes, i, FirstName.Length); i += FirstName.Length; + bytes[i++] = (byte)LastName.Length; + Buffer.BlockCopy(LastName, 0, bytes, i, LastName.Length); i += LastName.Length; + } + + } + + public override int Length + { + get + { + int length = 11; + for (int j = 0; j < UUIDNameBlock.Length; j++) + length += UUIDNameBlock[j].Length; + return length; + } + } + public UUIDNameBlockBlock[] UUIDNameBlock; + + public UUIDNameReplyPacket() + { + HasVariableBlocks = true; + Type = PacketType.UUIDNameReply; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 236; + Header.Reliable = true; + UUIDNameBlock = null; + } + + public UUIDNameReplyPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + int count = (int)bytes[i++]; + if(UUIDNameBlock == null || UUIDNameBlock.Length != -1) { + UUIDNameBlock = new UUIDNameBlockBlock[count]; + for(int j = 0; j < count; j++) + { UUIDNameBlock[j] = new UUIDNameBlockBlock(); } + } + for (int j = 0; j < count; j++) + { UUIDNameBlock[j].FromBytes(bytes, ref i); } + } + + public UUIDNameReplyPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + int count = (int)bytes[i++]; + if(UUIDNameBlock == null || UUIDNameBlock.Length != count) { + UUIDNameBlock = new UUIDNameBlockBlock[count]; + for(int j = 0; j < count; j++) + { UUIDNameBlock[j] = new UUIDNameBlockBlock(); } + } + for (int j = 0; j < count; j++) + { UUIDNameBlock[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length++; + for (int j = 0; j < UUIDNameBlock.Length; j++) { length += UUIDNameBlock[j].Length; } + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int UUIDNameBlockStart = 0; + do + { + int variableLength = 0; + int UUIDNameBlockCount = 0; + + i = UUIDNameBlockStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < UUIDNameBlock.Length) { + int blockLength = UUIDNameBlock[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == UUIDNameBlockStart) { + variableLength += blockLength; + ++UUIDNameBlockCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)UUIDNameBlockCount; + for (i = UUIDNameBlockStart; i < UUIDNameBlockStart + UUIDNameBlockCount; i++) { UUIDNameBlock[i].ToBytes(packet, ref length); } + UUIDNameBlockStart += UUIDNameBlockCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + UUIDNameBlockStart < UUIDNameBlock.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class UUIDGroupNameRequestPacket : Packet + { + /// + public sealed class UUIDNameBlockBlock : PacketBlock + { + public UUID ID; + + public override int Length + { + get + { + return 16; + } + } + + public UUIDNameBlockBlock() { } + public UUIDNameBlockBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + ID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + ID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 11; + for (int j = 0; j < UUIDNameBlock.Length; j++) + length += UUIDNameBlock[j].Length; + return length; + } + } + public UUIDNameBlockBlock[] UUIDNameBlock; + + public UUIDGroupNameRequestPacket() + { + HasVariableBlocks = true; + Type = PacketType.UUIDGroupNameRequest; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 237; + Header.Reliable = true; + UUIDNameBlock = null; + } + + public UUIDGroupNameRequestPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + int count = (int)bytes[i++]; + if(UUIDNameBlock == null || UUIDNameBlock.Length != -1) { + UUIDNameBlock = new UUIDNameBlockBlock[count]; + for(int j = 0; j < count; j++) + { UUIDNameBlock[j] = new UUIDNameBlockBlock(); } + } + for (int j = 0; j < count; j++) + { UUIDNameBlock[j].FromBytes(bytes, ref i); } + } + + public UUIDGroupNameRequestPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + int count = (int)bytes[i++]; + if(UUIDNameBlock == null || UUIDNameBlock.Length != count) { + UUIDNameBlock = new UUIDNameBlockBlock[count]; + for(int j = 0; j < count; j++) + { UUIDNameBlock[j] = new UUIDNameBlockBlock(); } + } + for (int j = 0; j < count; j++) + { UUIDNameBlock[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length++; + for (int j = 0; j < UUIDNameBlock.Length; j++) { length += UUIDNameBlock[j].Length; } + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int UUIDNameBlockStart = 0; + do + { + int variableLength = 0; + int UUIDNameBlockCount = 0; + + i = UUIDNameBlockStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < UUIDNameBlock.Length) { + int blockLength = UUIDNameBlock[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == UUIDNameBlockStart) { + variableLength += blockLength; + ++UUIDNameBlockCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)UUIDNameBlockCount; + for (i = UUIDNameBlockStart; i < UUIDNameBlockStart + UUIDNameBlockCount; i++) { UUIDNameBlock[i].ToBytes(packet, ref length); } + UUIDNameBlockStart += UUIDNameBlockCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + UUIDNameBlockStart < UUIDNameBlock.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class UUIDGroupNameReplyPacket : Packet + { + /// + public sealed class UUIDNameBlockBlock : PacketBlock + { + public UUID ID; + public byte[] GroupName; + + public override int Length + { + get + { + int length = 17; + if (GroupName != null) { length += GroupName.Length; } + return length; + } + } + + public UUIDNameBlockBlock() { } + public UUIDNameBlockBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + ID.FromBytes(bytes, i); i += 16; + length = bytes[i++]; + GroupName = new byte[length]; + Buffer.BlockCopy(bytes, i, GroupName, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + ID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)GroupName.Length; + Buffer.BlockCopy(GroupName, 0, bytes, i, GroupName.Length); i += GroupName.Length; + } + + } + + public override int Length + { + get + { + int length = 11; + for (int j = 0; j < UUIDNameBlock.Length; j++) + length += UUIDNameBlock[j].Length; + return length; + } + } + public UUIDNameBlockBlock[] UUIDNameBlock; + + public UUIDGroupNameReplyPacket() + { + HasVariableBlocks = true; + Type = PacketType.UUIDGroupNameReply; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 238; + Header.Reliable = true; + UUIDNameBlock = null; + } + + public UUIDGroupNameReplyPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + int count = (int)bytes[i++]; + if(UUIDNameBlock == null || UUIDNameBlock.Length != -1) { + UUIDNameBlock = new UUIDNameBlockBlock[count]; + for(int j = 0; j < count; j++) + { UUIDNameBlock[j] = new UUIDNameBlockBlock(); } + } + for (int j = 0; j < count; j++) + { UUIDNameBlock[j].FromBytes(bytes, ref i); } + } + + public UUIDGroupNameReplyPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + int count = (int)bytes[i++]; + if(UUIDNameBlock == null || UUIDNameBlock.Length != count) { + UUIDNameBlock = new UUIDNameBlockBlock[count]; + for(int j = 0; j < count; j++) + { UUIDNameBlock[j] = new UUIDNameBlockBlock(); } + } + for (int j = 0; j < count; j++) + { UUIDNameBlock[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length++; + for (int j = 0; j < UUIDNameBlock.Length; j++) { length += UUIDNameBlock[j].Length; } + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int UUIDNameBlockStart = 0; + do + { + int variableLength = 0; + int UUIDNameBlockCount = 0; + + i = UUIDNameBlockStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < UUIDNameBlock.Length) { + int blockLength = UUIDNameBlock[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == UUIDNameBlockStart) { + variableLength += blockLength; + ++UUIDNameBlockCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)UUIDNameBlockCount; + for (i = UUIDNameBlockStart; i < UUIDNameBlockStart + UUIDNameBlockCount; i++) { UUIDNameBlock[i].ToBytes(packet, ref length); } + UUIDNameBlockStart += UUIDNameBlockCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + UUIDNameBlockStart < UUIDNameBlock.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class ChildAgentDyingPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + return length; + } + } + public AgentDataBlock AgentData; + + public ChildAgentDyingPacket() + { + HasVariableBlocks = false; + Type = PacketType.ChildAgentDying; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 240; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + } + + public ChildAgentDyingPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + } + + public ChildAgentDyingPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class ChildAgentUnknownPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + return length; + } + } + public AgentDataBlock AgentData; + + public ChildAgentUnknownPacket() + { + HasVariableBlocks = false; + Type = PacketType.ChildAgentUnknown; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 241; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + } + + public ChildAgentUnknownPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + } + + public ChildAgentUnknownPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class GetScriptRunningPacket : Packet + { + /// + public sealed class ScriptBlock : PacketBlock + { + public UUID ObjectID; + public UUID ItemID; + + public override int Length + { + get + { + return 32; + } + } + + public ScriptBlock() { } + public ScriptBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + ObjectID.FromBytes(bytes, i); i += 16; + ItemID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + ObjectID.ToBytes(bytes, i); i += 16; + ItemID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 10; + length += Script.Length; + return length; + } + } + public ScriptBlock Script; + + public GetScriptRunningPacket() + { + HasVariableBlocks = false; + Type = PacketType.GetScriptRunning; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 243; + Header.Reliable = true; + Script = new ScriptBlock(); + } + + public GetScriptRunningPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + Script.FromBytes(bytes, ref i); + } + + public GetScriptRunningPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + Script.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += Script.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class ScriptRunningReplyPacket : Packet + { + /// + public sealed class ScriptBlock : PacketBlock + { + public UUID ObjectID; + public UUID ItemID; + public bool Running; + + public override int Length + { + get + { + return 33; + } + } + + public ScriptBlock() { } + public ScriptBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + ObjectID.FromBytes(bytes, i); i += 16; + ItemID.FromBytes(bytes, i); i += 16; + Running = (bytes[i++] != 0) ? (bool)true : (bool)false; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + ObjectID.ToBytes(bytes, i); i += 16; + ItemID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)((Running) ? 1 : 0); + } + + } + + public override int Length + { + get + { + int length = 10; + length += Script.Length; + return length; + } + } + public ScriptBlock Script; + + public ScriptRunningReplyPacket() + { + HasVariableBlocks = false; + Type = PacketType.ScriptRunningReply; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 244; + Header.Reliable = true; + Script = new ScriptBlock(); + } + + public ScriptRunningReplyPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + Script.FromBytes(bytes, ref i); + } + + public ScriptRunningReplyPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + Script.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += Script.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class SetScriptRunningPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class ScriptBlock : PacketBlock + { + public UUID ObjectID; + public UUID ItemID; + public bool Running; + + public override int Length + { + get + { + return 33; + } + } + + public ScriptBlock() { } + public ScriptBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + ObjectID.FromBytes(bytes, i); i += 16; + ItemID.FromBytes(bytes, i); i += 16; + Running = (bytes[i++] != 0) ? (bool)true : (bool)false; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + ObjectID.ToBytes(bytes, i); i += 16; + ItemID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)((Running) ? 1 : 0); + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += Script.Length; + return length; + } + } + public AgentDataBlock AgentData; + public ScriptBlock Script; + + public SetScriptRunningPacket() + { + HasVariableBlocks = false; + Type = PacketType.SetScriptRunning; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 245; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + Script = new ScriptBlock(); + } + + public SetScriptRunningPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + Script.FromBytes(bytes, ref i); + } + + public SetScriptRunningPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + Script.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += Script.Length; + if (Header.AckList != null && 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); + Script.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class ScriptResetPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class ScriptBlock : PacketBlock + { + public UUID ObjectID; + public UUID ItemID; + + public override int Length + { + get + { + return 32; + } + } + + public ScriptBlock() { } + public ScriptBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + ObjectID.FromBytes(bytes, i); i += 16; + ItemID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + ObjectID.ToBytes(bytes, i); i += 16; + ItemID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += Script.Length; + return length; + } + } + public AgentDataBlock AgentData; + public ScriptBlock Script; + + public ScriptResetPacket() + { + HasVariableBlocks = false; + Type = PacketType.ScriptReset; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 246; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + Script = new ScriptBlock(); + } + + public ScriptResetPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + Script.FromBytes(bytes, ref i); + } + + public ScriptResetPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + Script.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += Script.Length; + if (Header.AckList != null && 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); + Script.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class ScriptSensorRequestPacket : Packet + { + /// + public sealed class RequesterBlock : PacketBlock + { + public UUID SourceID; + public UUID RequestID; + public UUID SearchID; + public Vector3 SearchPos; + public Quaternion SearchDir; + public byte[] SearchName; + public int Type; + public float Range; + public float Arc; + public ulong RegionHandle; + public byte SearchRegions; + + public override int Length + { + get + { + int length = 94; + if (SearchName != null) { length += SearchName.Length; } + return length; + } + } + + public RequesterBlock() { } + public RequesterBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + SourceID.FromBytes(bytes, i); i += 16; + RequestID.FromBytes(bytes, i); i += 16; + SearchID.FromBytes(bytes, i); i += 16; + SearchPos.FromBytes(bytes, i); i += 12; + SearchDir.FromBytes(bytes, i, true); i += 12; + length = bytes[i++]; + SearchName = new byte[length]; + Buffer.BlockCopy(bytes, i, SearchName, 0, length); i += length; + Type = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + Range = Utils.BytesToFloat(bytes, i); i += 4; + Arc = Utils.BytesToFloat(bytes, i); i += 4; + 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)); + SearchRegions = (byte)bytes[i++]; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + SourceID.ToBytes(bytes, i); i += 16; + RequestID.ToBytes(bytes, i); i += 16; + SearchID.ToBytes(bytes, i); i += 16; + SearchPos.ToBytes(bytes, i); i += 12; + SearchDir.ToBytes(bytes, i); i += 12; + bytes[i++] = (byte)SearchName.Length; + Buffer.BlockCopy(SearchName, 0, bytes, i, SearchName.Length); i += SearchName.Length; + Utils.IntToBytes(Type, bytes, i); i += 4; + Utils.FloatToBytes(Range, bytes, i); i += 4; + Utils.FloatToBytes(Arc, bytes, i); i += 4; + Utils.UInt64ToBytes(RegionHandle, bytes, i); i += 8; + bytes[i++] = SearchRegions; + } + + } + + public override int Length + { + get + { + int length = 10; + length += Requester.Length; + return length; + } + } + public RequesterBlock Requester; + + public ScriptSensorRequestPacket() + { + HasVariableBlocks = false; + Type = PacketType.ScriptSensorRequest; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 247; + Header.Reliable = true; + Header.Zerocoded = true; + Requester = new RequesterBlock(); + } + + public ScriptSensorRequestPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + Requester.FromBytes(bytes, ref i); + } + + public ScriptSensorRequestPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + Requester.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += Requester.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class ScriptSensorReplyPacket : Packet + { + /// + public sealed class RequesterBlock : PacketBlock + { + public UUID SourceID; + + public override int Length + { + get + { + return 16; + } + } + + public RequesterBlock() { } + public RequesterBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + SourceID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + SourceID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class SensedDataBlock : PacketBlock + { + public UUID ObjectID; + public UUID OwnerID; + public UUID GroupID; + public Vector3 Position; + public Vector3 Velocity; + public Quaternion Rotation; + public byte[] Name; + public int Type; + public float Range; + + public override int Length + { + get + { + int length = 93; + if (Name != null) { length += Name.Length; } + return length; + } + } + + public SensedDataBlock() { } + public SensedDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + ObjectID.FromBytes(bytes, i); i += 16; + OwnerID.FromBytes(bytes, i); i += 16; + GroupID.FromBytes(bytes, i); i += 16; + Position.FromBytes(bytes, i); i += 12; + Velocity.FromBytes(bytes, i); i += 12; + Rotation.FromBytes(bytes, i, true); i += 12; + length = bytes[i++]; + Name = new byte[length]; + Buffer.BlockCopy(bytes, i, Name, 0, length); i += length; + Type = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + Range = Utils.BytesToFloat(bytes, i); i += 4; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + ObjectID.ToBytes(bytes, i); i += 16; + OwnerID.ToBytes(bytes, i); i += 16; + GroupID.ToBytes(bytes, i); i += 16; + Position.ToBytes(bytes, i); i += 12; + Velocity.ToBytes(bytes, i); i += 12; + Rotation.ToBytes(bytes, i); i += 12; + bytes[i++] = (byte)Name.Length; + Buffer.BlockCopy(Name, 0, bytes, i, Name.Length); i += Name.Length; + Utils.IntToBytes(Type, bytes, i); i += 4; + Utils.FloatToBytes(Range, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 11; + length += Requester.Length; + for (int j = 0; j < SensedData.Length; j++) + length += SensedData[j].Length; + return length; + } + } + public RequesterBlock Requester; + public SensedDataBlock[] SensedData; + + public ScriptSensorReplyPacket() + { + HasVariableBlocks = true; + Type = PacketType.ScriptSensorReply; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 248; + Header.Reliable = true; + Header.Zerocoded = true; + Requester = new RequesterBlock(); + SensedData = null; + } + + public ScriptSensorReplyPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + Requester.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(SensedData == null || SensedData.Length != -1) { + SensedData = new SensedDataBlock[count]; + for(int j = 0; j < count; j++) + { SensedData[j] = new SensedDataBlock(); } + } + for (int j = 0; j < count; j++) + { SensedData[j].FromBytes(bytes, ref i); } + } + + public ScriptSensorReplyPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + Requester.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(SensedData == null || SensedData.Length != count) { + SensedData = new SensedDataBlock[count]; + for(int j = 0; j < count; j++) + { SensedData[j] = new SensedDataBlock(); } + } + for (int j = 0; j < count; j++) + { SensedData[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += Requester.Length; + length++; + for (int j = 0; j < SensedData.Length; j++) { length += SensedData[j].Length; } + if (Header.AckList != null && 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); + bytes[i++] = (byte)SensedData.Length; + for (int j = 0; j < SensedData.Length; j++) { SensedData[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += Requester.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + Requester.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int SensedDataStart = 0; + do + { + int variableLength = 0; + int SensedDataCount = 0; + + i = SensedDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < SensedData.Length) { + int blockLength = SensedData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == SensedDataStart) { + variableLength += blockLength; + ++SensedDataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)SensedDataCount; + for (i = SensedDataStart; i < SensedDataStart + SensedDataCount; i++) { SensedData[i].ToBytes(packet, ref length); } + SensedDataStart += SensedDataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + SensedDataStart < SensedData.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class CompleteAgentMovementPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + public uint CircuitCode; + + public override int Length + { + get + { + return 36; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + CircuitCode = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + Utils.UIntToBytes(CircuitCode, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + return length; + } + } + public AgentDataBlock AgentData; + + public CompleteAgentMovementPacket() + { + HasVariableBlocks = false; + Type = PacketType.CompleteAgentMovement; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 249; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + } + + public CompleteAgentMovementPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + } + + public CompleteAgentMovementPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class AgentMovementCompletePacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class DataBlock : PacketBlock + { + public Vector3 Position; + public Vector3 LookAt; + public ulong RegionHandle; + public uint Timestamp; + + public override int Length + { + get + { + return 36; + } + } + + public DataBlock() { } + public DataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + Position.FromBytes(bytes, i); i += 12; + LookAt.FromBytes(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)); + Timestamp = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Position.ToBytes(bytes, i); i += 12; + LookAt.ToBytes(bytes, i); i += 12; + Utils.UInt64ToBytes(RegionHandle, bytes, i); i += 8; + Utils.UIntToBytes(Timestamp, bytes, i); i += 4; + } + + } + + /// + public sealed class SimDataBlock : PacketBlock + { + public byte[] ChannelVersion; + + public override int Length + { + get + { + int length = 2; + if (ChannelVersion != null) { length += ChannelVersion.Length; } + return length; + } + } + + public SimDataBlock() { } + public SimDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + length = (bytes[i++] + (bytes[i++] << 8)); + ChannelVersion = new byte[length]; + Buffer.BlockCopy(bytes, i, ChannelVersion, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + bytes[i++] = (byte)(ChannelVersion.Length % 256); + bytes[i++] = (byte)((ChannelVersion.Length >> 8) % 256); + Buffer.BlockCopy(ChannelVersion, 0, bytes, i, ChannelVersion.Length); i += ChannelVersion.Length; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += Data.Length; + length += SimData.Length; + return length; + } + } + public AgentDataBlock AgentData; + public DataBlock Data; + public SimDataBlock SimData; + + public AgentMovementCompletePacket() + { + HasVariableBlocks = false; + Type = PacketType.AgentMovementComplete; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 250; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + Data = new DataBlock(); + SimData = new SimDataBlock(); + } + + public AgentMovementCompletePacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + Data.FromBytes(bytes, ref i); + SimData.FromBytes(bytes, ref i); + } + + public AgentMovementCompletePacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + Data.FromBytes(bytes, ref i); + SimData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += Data.Length; + length += SimData.Length; + if (Header.AckList != null && 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); + Data.ToBytes(bytes, ref i); + SimData.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class LogoutRequestPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + return length; + } + } + public AgentDataBlock AgentData; + + public LogoutRequestPacket() + { + HasVariableBlocks = false; + Type = PacketType.LogoutRequest; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 252; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + } + + public LogoutRequestPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + } + + public LogoutRequestPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class LogoutReplyPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class InventoryDataBlock : PacketBlock + { + public UUID ItemID; + + public override int Length + { + get + { + return 16; + } + } + + public InventoryDataBlock() { } + public InventoryDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + ItemID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + ItemID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentData.Length; + for (int j = 0; j < InventoryData.Length; j++) + length += InventoryData[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public InventoryDataBlock[] InventoryData; + + public LogoutReplyPacket() + { + HasVariableBlocks = true; + Type = PacketType.LogoutReply; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 253; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + InventoryData = null; + } + + public LogoutReplyPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(InventoryData == null || InventoryData.Length != -1) { + InventoryData = new InventoryDataBlock[count]; + for(int j = 0; j < count; j++) + { InventoryData[j] = new InventoryDataBlock(); } + } + for (int j = 0; j < count; j++) + { InventoryData[j].FromBytes(bytes, ref i); } + } + + public LogoutReplyPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(InventoryData == null || InventoryData.Length != count) { + InventoryData = new InventoryDataBlock[count]; + for(int j = 0; j < count; j++) + { InventoryData[j] = new InventoryDataBlock(); } + } + for (int j = 0; j < count; j++) + { InventoryData[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length++; + for (int j = 0; j < InventoryData.Length; j++) { length += InventoryData[j].Length; } + if (Header.AckList != null && 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)InventoryData.Length; + for (int j = 0; j < InventoryData.Length; j++) { InventoryData[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int InventoryDataStart = 0; + do + { + int variableLength = 0; + int InventoryDataCount = 0; + + i = InventoryDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < InventoryData.Length) { + int blockLength = InventoryData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == InventoryDataStart) { + variableLength += blockLength; + ++InventoryDataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)InventoryDataCount; + for (i = InventoryDataStart; i < InventoryDataStart + InventoryDataCount; i++) { InventoryData[i].ToBytes(packet, ref length); } + InventoryDataStart += InventoryDataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + InventoryDataStart < InventoryData.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class ImprovedInstantMessagePacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class MessageBlockBlock : PacketBlock + { + public bool FromGroup; + public UUID ToAgentID; + public uint ParentEstateID; + public UUID RegionID; + public Vector3 Position; + public byte Offline; + public byte Dialog; + public UUID ID; + public uint Timestamp; + public byte[] FromAgentName; + public byte[] Message; + public byte[] BinaryBucket; + + public override int Length + { + get + { + int length = 76; + if (FromAgentName != null) { length += FromAgentName.Length; } + if (Message != null) { length += Message.Length; } + if (BinaryBucket != null) { length += BinaryBucket.Length; } + return length; + } + } + + public MessageBlockBlock() { } + public MessageBlockBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + FromGroup = (bytes[i++] != 0) ? (bool)true : (bool)false; + ToAgentID.FromBytes(bytes, i); i += 16; + ParentEstateID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + RegionID.FromBytes(bytes, i); i += 16; + Position.FromBytes(bytes, i); i += 12; + Offline = (byte)bytes[i++]; + Dialog = (byte)bytes[i++]; + ID.FromBytes(bytes, i); i += 16; + Timestamp = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + length = bytes[i++]; + FromAgentName = new byte[length]; + Buffer.BlockCopy(bytes, i, FromAgentName, 0, length); i += length; + length = (bytes[i++] + (bytes[i++] << 8)); + Message = new byte[length]; + Buffer.BlockCopy(bytes, i, Message, 0, length); i += length; + length = (bytes[i++] + (bytes[i++] << 8)); + BinaryBucket = new byte[length]; + Buffer.BlockCopy(bytes, i, BinaryBucket, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + bytes[i++] = (byte)((FromGroup) ? 1 : 0); + ToAgentID.ToBytes(bytes, i); i += 16; + Utils.UIntToBytes(ParentEstateID, bytes, i); i += 4; + RegionID.ToBytes(bytes, i); i += 16; + Position.ToBytes(bytes, i); i += 12; + bytes[i++] = Offline; + bytes[i++] = Dialog; + ID.ToBytes(bytes, i); i += 16; + Utils.UIntToBytes(Timestamp, bytes, i); i += 4; + bytes[i++] = (byte)FromAgentName.Length; + Buffer.BlockCopy(FromAgentName, 0, bytes, i, FromAgentName.Length); i += FromAgentName.Length; + bytes[i++] = (byte)(Message.Length % 256); + bytes[i++] = (byte)((Message.Length >> 8) % 256); + Buffer.BlockCopy(Message, 0, bytes, i, Message.Length); i += Message.Length; + bytes[i++] = (byte)(BinaryBucket.Length % 256); + bytes[i++] = (byte)((BinaryBucket.Length >> 8) % 256); + Buffer.BlockCopy(BinaryBucket, 0, bytes, i, BinaryBucket.Length); i += BinaryBucket.Length; + } + + } + + /// + public sealed class EstateBlockBlock : PacketBlock + { + public uint EstateID; + + public override int Length + { + get + { + return 4; + } + } + + public EstateBlockBlock() { } + public EstateBlockBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + EstateID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UIntToBytes(EstateID, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += MessageBlock.Length; + length += EstateBlock.Length; + return length; + } + } + public AgentDataBlock AgentData; + public MessageBlockBlock MessageBlock; + public EstateBlockBlock EstateBlock; + + public ImprovedInstantMessagePacket() + { + HasVariableBlocks = false; + Type = PacketType.ImprovedInstantMessage; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 254; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + MessageBlock = new MessageBlockBlock(); + EstateBlock = new EstateBlockBlock(); + } + + public ImprovedInstantMessagePacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + MessageBlock.FromBytes(bytes, ref i); + EstateBlock.FromBytes(bytes, ref i); + } + + public ImprovedInstantMessagePacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + MessageBlock.FromBytes(bytes, ref i); + EstateBlock.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += MessageBlock.Length; + length += EstateBlock.Length; + if (Header.AckList != null && 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); + MessageBlock.ToBytes(bytes, ref i); + EstateBlock.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class RetrieveInstantMessagesPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + return length; + } + } + public AgentDataBlock AgentData; + + public RetrieveInstantMessagesPacket() + { + HasVariableBlocks = false; + Type = PacketType.RetrieveInstantMessages; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 255; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + } + + public RetrieveInstantMessagesPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + } + + public RetrieveInstantMessagesPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class FindAgentPacket : Packet + { + /// + public sealed class AgentBlockBlock : PacketBlock + { + public UUID Hunter; + public UUID Prey; + public uint SpaceIP; + + public override int Length + { + get + { + return 36; + } + } + + public AgentBlockBlock() { } + public AgentBlockBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + Hunter.FromBytes(bytes, i); i += 16; + Prey.FromBytes(bytes, i); i += 16; + SpaceIP = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Hunter.ToBytes(bytes, i); i += 16; + Prey.ToBytes(bytes, i); i += 16; + Utils.UIntToBytes(SpaceIP, bytes, i); i += 4; + } + + } + + /// + public sealed class LocationBlockBlock : PacketBlock + { + public double GlobalX; + public double GlobalY; + + public override int Length + { + get + { + return 16; + } + } + + public LocationBlockBlock() { } + public LocationBlockBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + GlobalX = Utils.BytesToDouble(bytes, i); i += 8; + GlobalY = Utils.BytesToDouble(bytes, i); i += 8; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.DoubleToBytes(GlobalX, bytes, i); i += 8; + Utils.DoubleToBytes(GlobalY, bytes, i); i += 8; + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentBlock.Length; + for (int j = 0; j < LocationBlock.Length; j++) + length += LocationBlock[j].Length; + return length; + } + } + public AgentBlockBlock AgentBlock; + public LocationBlockBlock[] LocationBlock; + + public FindAgentPacket() + { + HasVariableBlocks = true; + Type = PacketType.FindAgent; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 256; + Header.Reliable = true; + AgentBlock = new AgentBlockBlock(); + LocationBlock = null; + } + + public FindAgentPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentBlock.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(LocationBlock == null || LocationBlock.Length != -1) { + LocationBlock = new LocationBlockBlock[count]; + for(int j = 0; j < count; j++) + { LocationBlock[j] = new LocationBlockBlock(); } + } + for (int j = 0; j < count; j++) + { LocationBlock[j].FromBytes(bytes, ref i); } + } + + public FindAgentPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentBlock.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(LocationBlock == null || LocationBlock.Length != count) { + LocationBlock = new LocationBlockBlock[count]; + for(int j = 0; j < count; j++) + { LocationBlock[j] = new LocationBlockBlock(); } + } + for (int j = 0; j < count; j++) + { LocationBlock[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentBlock.Length; + length++; + for (int j = 0; j < LocationBlock.Length; j++) { length += LocationBlock[j].Length; } + if (Header.AckList != null && 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); + bytes[i++] = (byte)LocationBlock.Length; + for (int j = 0; j < LocationBlock.Length; j++) { LocationBlock[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentBlock.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentBlock.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int LocationBlockStart = 0; + do + { + int variableLength = 0; + int LocationBlockCount = 0; + + i = LocationBlockStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < LocationBlock.Length) { + int blockLength = LocationBlock[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == LocationBlockStart) { + variableLength += blockLength; + ++LocationBlockCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)LocationBlockCount; + for (i = LocationBlockStart; i < LocationBlockStart + LocationBlockCount; i++) { LocationBlock[i].ToBytes(packet, ref length); } + LocationBlockStart += LocationBlockCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + LocationBlockStart < LocationBlock.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class RequestGodlikePowersPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class RequestBlockBlock : PacketBlock + { + public bool Godlike; + public UUID Token; + + public override int Length + { + get + { + return 17; + } + } + + public RequestBlockBlock() { } + public RequestBlockBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + Godlike = (bytes[i++] != 0) ? (bool)true : (bool)false; + Token.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + bytes[i++] = (byte)((Godlike) ? 1 : 0); + Token.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += RequestBlock.Length; + return length; + } + } + public AgentDataBlock AgentData; + public RequestBlockBlock RequestBlock; + + public RequestGodlikePowersPacket() + { + HasVariableBlocks = false; + Type = PacketType.RequestGodlikePowers; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 257; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + RequestBlock = new RequestBlockBlock(); + } + + public RequestGodlikePowersPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + RequestBlock.FromBytes(bytes, ref i); + } + + public RequestGodlikePowersPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + RequestBlock.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += RequestBlock.Length; + if (Header.AckList != null && 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); + RequestBlock.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class GrantGodlikePowersPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class GrantDataBlock : PacketBlock + { + public byte GodLevel; + public UUID Token; + + public override int Length + { + get + { + return 17; + } + } + + public GrantDataBlock() { } + public GrantDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + GodLevel = (byte)bytes[i++]; + Token.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + bytes[i++] = GodLevel; + Token.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += GrantData.Length; + return length; + } + } + public AgentDataBlock AgentData; + public GrantDataBlock GrantData; + + public GrantGodlikePowersPacket() + { + HasVariableBlocks = false; + Type = PacketType.GrantGodlikePowers; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 258; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + GrantData = new GrantDataBlock(); + } + + public GrantGodlikePowersPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + GrantData.FromBytes(bytes, ref i); + } + + public GrantGodlikePowersPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + GrantData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += GrantData.Length; + if (Header.AckList != null && 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); + GrantData.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class GodlikeMessagePacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + public UUID TransactionID; + + public override int Length + { + get + { + return 48; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + TransactionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + TransactionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class MethodDataBlock : PacketBlock + { + public byte[] Method; + public UUID Invoice; + + public override int Length + { + get + { + int length = 17; + if (Method != null) { length += Method.Length; } + return length; + } + } + + public MethodDataBlock() { } + public MethodDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + length = bytes[i++]; + Method = new byte[length]; + Buffer.BlockCopy(bytes, i, Method, 0, length); i += length; + Invoice.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + bytes[i++] = (byte)Method.Length; + Buffer.BlockCopy(Method, 0, bytes, i, Method.Length); i += Method.Length; + Invoice.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class ParamListBlock : PacketBlock + { + public byte[] Parameter; + + public override int Length + { + get + { + int length = 1; + if (Parameter != null) { length += Parameter.Length; } + return length; + } + } + + public ParamListBlock() { } + public ParamListBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + length = bytes[i++]; + Parameter = new byte[length]; + Buffer.BlockCopy(bytes, i, Parameter, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + bytes[i++] = (byte)Parameter.Length; + Buffer.BlockCopy(Parameter, 0, bytes, i, Parameter.Length); i += Parameter.Length; + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentData.Length; + length += MethodData.Length; + for (int j = 0; j < ParamList.Length; j++) + length += ParamList[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public MethodDataBlock MethodData; + public ParamListBlock[] ParamList; + + public GodlikeMessagePacket() + { + HasVariableBlocks = true; + Type = PacketType.GodlikeMessage; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 259; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + MethodData = new MethodDataBlock(); + ParamList = null; + } + + public GodlikeMessagePacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + MethodData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ParamList == null || ParamList.Length != -1) { + ParamList = new ParamListBlock[count]; + for(int j = 0; j < count; j++) + { ParamList[j] = new ParamListBlock(); } + } + for (int j = 0; j < count; j++) + { ParamList[j].FromBytes(bytes, ref i); } + } + + public GodlikeMessagePacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + MethodData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ParamList == null || ParamList.Length != count) { + ParamList = new ParamListBlock[count]; + for(int j = 0; j < count; j++) + { ParamList[j] = new ParamListBlock(); } + } + for (int j = 0; j < count; j++) + { ParamList[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += MethodData.Length; + length++; + for (int j = 0; j < ParamList.Length; j++) { length += ParamList[j].Length; } + if (Header.AckList != null && 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); + 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + fixedLength += MethodData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + MethodData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int ParamListStart = 0; + do + { + int variableLength = 0; + int ParamListCount = 0; + + i = ParamListStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < ParamList.Length) { + int blockLength = ParamList[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ParamListStart) { + variableLength += blockLength; + ++ParamListCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)ParamListCount; + for (i = ParamListStart; i < ParamListStart + ParamListCount; i++) { ParamList[i].ToBytes(packet, ref length); } + ParamListStart += ParamListCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + ParamListStart < ParamList.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class EstateOwnerMessagePacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + public UUID TransactionID; + + public override int Length + { + get + { + return 48; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + TransactionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + TransactionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class MethodDataBlock : PacketBlock + { + public byte[] Method; + public UUID Invoice; + + public override int Length + { + get + { + int length = 17; + if (Method != null) { length += Method.Length; } + return length; + } + } + + public MethodDataBlock() { } + public MethodDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + length = bytes[i++]; + Method = new byte[length]; + Buffer.BlockCopy(bytes, i, Method, 0, length); i += length; + Invoice.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + bytes[i++] = (byte)Method.Length; + Buffer.BlockCopy(Method, 0, bytes, i, Method.Length); i += Method.Length; + Invoice.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class ParamListBlock : PacketBlock + { + public byte[] Parameter; + + public override int Length + { + get + { + int length = 1; + if (Parameter != null) { length += Parameter.Length; } + return length; + } + } + + public ParamListBlock() { } + public ParamListBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + length = bytes[i++]; + Parameter = new byte[length]; + Buffer.BlockCopy(bytes, i, Parameter, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + bytes[i++] = (byte)Parameter.Length; + Buffer.BlockCopy(Parameter, 0, bytes, i, Parameter.Length); i += Parameter.Length; + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentData.Length; + length += MethodData.Length; + for (int j = 0; j < ParamList.Length; j++) + length += ParamList[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public MethodDataBlock MethodData; + public ParamListBlock[] ParamList; + + public EstateOwnerMessagePacket() + { + HasVariableBlocks = true; + Type = PacketType.EstateOwnerMessage; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 260; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + MethodData = new MethodDataBlock(); + ParamList = null; + } + + public EstateOwnerMessagePacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + MethodData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ParamList == null || ParamList.Length != -1) { + ParamList = new ParamListBlock[count]; + for(int j = 0; j < count; j++) + { ParamList[j] = new ParamListBlock(); } + } + for (int j = 0; j < count; j++) + { ParamList[j].FromBytes(bytes, ref i); } + } + + public EstateOwnerMessagePacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + MethodData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ParamList == null || ParamList.Length != count) { + ParamList = new ParamListBlock[count]; + for(int j = 0; j < count; j++) + { ParamList[j] = new ParamListBlock(); } + } + for (int j = 0; j < count; j++) + { ParamList[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += MethodData.Length; + length++; + for (int j = 0; j < ParamList.Length; j++) { length += ParamList[j].Length; } + if (Header.AckList != null && 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); + 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + fixedLength += MethodData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + MethodData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int ParamListStart = 0; + do + { + int variableLength = 0; + int ParamListCount = 0; + + i = ParamListStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < ParamList.Length) { + int blockLength = ParamList[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ParamListStart) { + variableLength += blockLength; + ++ParamListCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)ParamListCount; + for (i = ParamListStart; i < ParamListStart + ParamListCount; i++) { ParamList[i].ToBytes(packet, ref length); } + ParamListStart += ParamListCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + ParamListStart < ParamList.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class GenericMessagePacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + public UUID TransactionID; + + public override int Length + { + get + { + return 48; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + TransactionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + TransactionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class MethodDataBlock : PacketBlock + { + public byte[] Method; + public UUID Invoice; + + public override int Length + { + get + { + int length = 17; + if (Method != null) { length += Method.Length; } + return length; + } + } + + public MethodDataBlock() { } + public MethodDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + length = bytes[i++]; + Method = new byte[length]; + Buffer.BlockCopy(bytes, i, Method, 0, length); i += length; + Invoice.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + bytes[i++] = (byte)Method.Length; + Buffer.BlockCopy(Method, 0, bytes, i, Method.Length); i += Method.Length; + Invoice.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class ParamListBlock : PacketBlock + { + public byte[] Parameter; + + public override int Length + { + get + { + int length = 1; + if (Parameter != null) { length += Parameter.Length; } + return length; + } + } + + public ParamListBlock() { } + public ParamListBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + length = bytes[i++]; + Parameter = new byte[length]; + Buffer.BlockCopy(bytes, i, Parameter, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + bytes[i++] = (byte)Parameter.Length; + Buffer.BlockCopy(Parameter, 0, bytes, i, Parameter.Length); i += Parameter.Length; + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentData.Length; + length += MethodData.Length; + for (int j = 0; j < ParamList.Length; j++) + length += ParamList[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public MethodDataBlock MethodData; + public ParamListBlock[] ParamList; + + public GenericMessagePacket() + { + HasVariableBlocks = true; + Type = PacketType.GenericMessage; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 261; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + MethodData = new MethodDataBlock(); + ParamList = null; + } + + public GenericMessagePacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + MethodData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ParamList == null || ParamList.Length != -1) { + ParamList = new ParamListBlock[count]; + for(int j = 0; j < count; j++) + { ParamList[j] = new ParamListBlock(); } + } + for (int j = 0; j < count; j++) + { ParamList[j].FromBytes(bytes, ref i); } + } + + public GenericMessagePacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + MethodData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ParamList == null || ParamList.Length != count) { + ParamList = new ParamListBlock[count]; + for(int j = 0; j < count; j++) + { ParamList[j] = new ParamListBlock(); } + } + for (int j = 0; j < count; j++) + { ParamList[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += MethodData.Length; + length++; + for (int j = 0; j < ParamList.Length; j++) { length += ParamList[j].Length; } + if (Header.AckList != null && 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); + 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + fixedLength += MethodData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + MethodData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int ParamListStart = 0; + do + { + int variableLength = 0; + int ParamListCount = 0; + + i = ParamListStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < ParamList.Length) { + int blockLength = ParamList[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ParamListStart) { + variableLength += blockLength; + ++ParamListCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)ParamListCount; + for (i = ParamListStart; i < ParamListStart + ParamListCount; i++) { ParamList[i].ToBytes(packet, ref length); } + ParamListStart += ParamListCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + ParamListStart < ParamList.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class MuteListRequestPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class MuteDataBlock : PacketBlock + { + public uint MuteCRC; + + public override int Length + { + get + { + return 4; + } + } + + public MuteDataBlock() { } + public MuteDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + MuteCRC = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UIntToBytes(MuteCRC, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += MuteData.Length; + return length; + } + } + public AgentDataBlock AgentData; + public MuteDataBlock MuteData; + + public MuteListRequestPacket() + { + HasVariableBlocks = false; + Type = PacketType.MuteListRequest; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 262; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + MuteData = new MuteDataBlock(); + } + + public MuteListRequestPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + MuteData.FromBytes(bytes, ref i); + } + + public MuteListRequestPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + MuteData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += MuteData.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class UpdateMuteListEntryPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class MuteDataBlock : PacketBlock + { + public UUID MuteID; + public byte[] MuteName; + public int MuteType; + public uint MuteFlags; + + public override int Length + { + get + { + int length = 25; + if (MuteName != null) { length += MuteName.Length; } + return length; + } + } + + public MuteDataBlock() { } + public MuteDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + MuteID.FromBytes(bytes, i); i += 16; + length = bytes[i++]; + MuteName = new byte[length]; + Buffer.BlockCopy(bytes, i, MuteName, 0, length); i += length; + MuteType = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + MuteFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + MuteID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)MuteName.Length; + Buffer.BlockCopy(MuteName, 0, bytes, i, MuteName.Length); i += MuteName.Length; + Utils.IntToBytes(MuteType, bytes, i); i += 4; + Utils.UIntToBytes(MuteFlags, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += MuteData.Length; + return length; + } + } + public AgentDataBlock AgentData; + public MuteDataBlock MuteData; + + public UpdateMuteListEntryPacket() + { + HasVariableBlocks = false; + Type = PacketType.UpdateMuteListEntry; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 263; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + MuteData = new MuteDataBlock(); + } + + public UpdateMuteListEntryPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + MuteData.FromBytes(bytes, ref i); + } + + public UpdateMuteListEntryPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + MuteData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += MuteData.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class RemoveMuteListEntryPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class MuteDataBlock : PacketBlock + { + public UUID MuteID; + public byte[] MuteName; + + public override int Length + { + get + { + int length = 17; + if (MuteName != null) { length += MuteName.Length; } + return length; + } + } + + public MuteDataBlock() { } + public MuteDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + MuteID.FromBytes(bytes, i); i += 16; + length = bytes[i++]; + MuteName = new byte[length]; + Buffer.BlockCopy(bytes, i, MuteName, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + MuteID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)MuteName.Length; + Buffer.BlockCopy(MuteName, 0, bytes, i, MuteName.Length); i += MuteName.Length; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += MuteData.Length; + return length; + } + } + public AgentDataBlock AgentData; + public MuteDataBlock MuteData; + + public RemoveMuteListEntryPacket() + { + HasVariableBlocks = false; + Type = PacketType.RemoveMuteListEntry; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 264; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + MuteData = new MuteDataBlock(); + } + + public RemoveMuteListEntryPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + MuteData.FromBytes(bytes, ref i); + } + + public RemoveMuteListEntryPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + MuteData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += MuteData.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class CopyInventoryFromNotecardPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class NotecardDataBlock : PacketBlock + { + public UUID NotecardItemID; + public UUID ObjectID; + + public override int Length + { + get + { + return 32; + } + } + + public NotecardDataBlock() { } + public NotecardDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + NotecardItemID.FromBytes(bytes, i); i += 16; + ObjectID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + NotecardItemID.ToBytes(bytes, i); i += 16; + ObjectID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class InventoryDataBlock : PacketBlock + { + public UUID ItemID; + public UUID FolderID; + + public override int Length + { + get + { + return 32; + } + } + + public InventoryDataBlock() { } + public InventoryDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + ItemID.FromBytes(bytes, i); i += 16; + FolderID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + ItemID.ToBytes(bytes, i); i += 16; + FolderID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentData.Length; + length += NotecardData.Length; + for (int j = 0; j < InventoryData.Length; j++) + length += InventoryData[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public NotecardDataBlock NotecardData; + public InventoryDataBlock[] InventoryData; + + public CopyInventoryFromNotecardPacket() + { + HasVariableBlocks = true; + Type = PacketType.CopyInventoryFromNotecard; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 265; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + NotecardData = new NotecardDataBlock(); + InventoryData = null; + } + + public CopyInventoryFromNotecardPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + NotecardData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(InventoryData == null || InventoryData.Length != -1) { + InventoryData = new InventoryDataBlock[count]; + for(int j = 0; j < count; j++) + { InventoryData[j] = new InventoryDataBlock(); } + } + for (int j = 0; j < count; j++) + { InventoryData[j].FromBytes(bytes, ref i); } + } + + public CopyInventoryFromNotecardPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + NotecardData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(InventoryData == null || InventoryData.Length != count) { + InventoryData = new InventoryDataBlock[count]; + for(int j = 0; j < count; j++) + { InventoryData[j] = new InventoryDataBlock(); } + } + for (int j = 0; j < count; j++) + { InventoryData[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += NotecardData.Length; + length++; + for (int j = 0; j < InventoryData.Length; j++) { length += InventoryData[j].Length; } + if (Header.AckList != null && 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); + NotecardData.ToBytes(bytes, ref i); + bytes[i++] = (byte)InventoryData.Length; + for (int j = 0; j < InventoryData.Length; j++) { InventoryData[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + fixedLength += NotecardData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + NotecardData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int InventoryDataStart = 0; + do + { + int variableLength = 0; + int InventoryDataCount = 0; + + i = InventoryDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < InventoryData.Length) { + int blockLength = InventoryData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == InventoryDataStart) { + variableLength += blockLength; + ++InventoryDataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)InventoryDataCount; + for (i = InventoryDataStart; i < InventoryDataStart + InventoryDataCount; i++) { InventoryData[i].ToBytes(packet, ref length); } + InventoryDataStart += InventoryDataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + InventoryDataStart < InventoryData.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class UpdateInventoryItemPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + public UUID TransactionID; + + public override int Length + { + get + { + return 48; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + TransactionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + TransactionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class InventoryDataBlock : PacketBlock + { + public UUID ItemID; + public UUID FolderID; + public uint CallbackID; + public UUID CreatorID; + public UUID OwnerID; + public UUID GroupID; + public uint BaseMask; + public uint OwnerMask; + public uint GroupMask; + public uint EveryoneMask; + public uint NextOwnerMask; + public bool GroupOwned; + public UUID TransactionID; + public sbyte Type; + public sbyte InvType; + public uint Flags; + public byte SaleType; + public int SalePrice; + public byte[] Name; + public byte[] Description; + public int CreationDate; + public uint CRC; + + public override int Length + { + get + { + int length = 142; + if (Name != null) { length += Name.Length; } + if (Description != null) { length += Description.Length; } + return length; + } + } + + public InventoryDataBlock() { } + public InventoryDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + ItemID.FromBytes(bytes, i); i += 16; + FolderID.FromBytes(bytes, i); i += 16; + CallbackID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + CreatorID.FromBytes(bytes, i); i += 16; + OwnerID.FromBytes(bytes, i); i += 16; + GroupID.FromBytes(bytes, i); i += 16; + BaseMask = (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)); + GroupMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + 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)); + GroupOwned = (bytes[i++] != 0) ? (bool)true : (bool)false; + TransactionID.FromBytes(bytes, i); i += 16; + Type = (sbyte)bytes[i++]; + InvType = (sbyte)bytes[i++]; + Flags = (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)); + length = bytes[i++]; + Name = new byte[length]; + Buffer.BlockCopy(bytes, i, Name, 0, length); i += length; + length = bytes[i++]; + Description = new byte[length]; + Buffer.BlockCopy(bytes, i, Description, 0, length); i += length; + CreationDate = (int)(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(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + ItemID.ToBytes(bytes, i); i += 16; + FolderID.ToBytes(bytes, i); i += 16; + Utils.UIntToBytes(CallbackID, bytes, i); i += 4; + CreatorID.ToBytes(bytes, i); i += 16; + OwnerID.ToBytes(bytes, i); i += 16; + GroupID.ToBytes(bytes, i); i += 16; + Utils.UIntToBytes(BaseMask, bytes, i); i += 4; + Utils.UIntToBytes(OwnerMask, bytes, i); i += 4; + Utils.UIntToBytes(GroupMask, bytes, i); i += 4; + Utils.UIntToBytes(EveryoneMask, bytes, i); i += 4; + Utils.UIntToBytes(NextOwnerMask, bytes, i); i += 4; + bytes[i++] = (byte)((GroupOwned) ? 1 : 0); + TransactionID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)Type; + bytes[i++] = (byte)InvType; + Utils.UIntToBytes(Flags, bytes, i); i += 4; + bytes[i++] = SaleType; + Utils.IntToBytes(SalePrice, bytes, i); i += 4; + bytes[i++] = (byte)Name.Length; + Buffer.BlockCopy(Name, 0, bytes, i, Name.Length); i += Name.Length; + bytes[i++] = (byte)Description.Length; + Buffer.BlockCopy(Description, 0, bytes, i, Description.Length); i += Description.Length; + Utils.IntToBytes(CreationDate, bytes, i); i += 4; + Utils.UIntToBytes(CRC, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentData.Length; + for (int j = 0; j < InventoryData.Length; j++) + length += InventoryData[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public InventoryDataBlock[] InventoryData; + + public UpdateInventoryItemPacket() + { + HasVariableBlocks = true; + Type = PacketType.UpdateInventoryItem; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 266; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + InventoryData = null; + } + + public UpdateInventoryItemPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(InventoryData == null || InventoryData.Length != -1) { + InventoryData = new InventoryDataBlock[count]; + for(int j = 0; j < count; j++) + { InventoryData[j] = new InventoryDataBlock(); } + } + for (int j = 0; j < count; j++) + { InventoryData[j].FromBytes(bytes, ref i); } + } + + public UpdateInventoryItemPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(InventoryData == null || InventoryData.Length != count) { + InventoryData = new InventoryDataBlock[count]; + for(int j = 0; j < count; j++) + { InventoryData[j] = new InventoryDataBlock(); } + } + for (int j = 0; j < count; j++) + { InventoryData[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length++; + for (int j = 0; j < InventoryData.Length; j++) { length += InventoryData[j].Length; } + if (Header.AckList != null && 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)InventoryData.Length; + for (int j = 0; j < InventoryData.Length; j++) { InventoryData[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int InventoryDataStart = 0; + do + { + int variableLength = 0; + int InventoryDataCount = 0; + + i = InventoryDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < InventoryData.Length) { + int blockLength = InventoryData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == InventoryDataStart) { + variableLength += blockLength; + ++InventoryDataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)InventoryDataCount; + for (i = InventoryDataStart; i < InventoryDataStart + InventoryDataCount; i++) { InventoryData[i].ToBytes(packet, ref length); } + InventoryDataStart += InventoryDataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + InventoryDataStart < InventoryData.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class UpdateCreateInventoryItemPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public bool SimApproved; + public UUID TransactionID; + + public override int Length + { + get + { + return 33; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SimApproved = (bytes[i++] != 0) ? (bool)true : (bool)false; + TransactionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)((SimApproved) ? 1 : 0); + TransactionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class InventoryDataBlock : PacketBlock + { + public UUID ItemID; + public UUID FolderID; + public uint CallbackID; + public UUID CreatorID; + public UUID OwnerID; + public UUID GroupID; + public uint BaseMask; + public uint OwnerMask; + public uint GroupMask; + public uint EveryoneMask; + public uint NextOwnerMask; + public bool GroupOwned; + public UUID AssetID; + public sbyte Type; + public sbyte InvType; + public uint Flags; + public byte SaleType; + public int SalePrice; + public byte[] Name; + public byte[] Description; + public int CreationDate; + public uint CRC; + + public override int Length + { + get + { + int length = 142; + if (Name != null) { length += Name.Length; } + if (Description != null) { length += Description.Length; } + return length; + } + } + + public InventoryDataBlock() { } + public InventoryDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + ItemID.FromBytes(bytes, i); i += 16; + FolderID.FromBytes(bytes, i); i += 16; + CallbackID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + CreatorID.FromBytes(bytes, i); i += 16; + OwnerID.FromBytes(bytes, i); i += 16; + GroupID.FromBytes(bytes, i); i += 16; + BaseMask = (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)); + GroupMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + 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)); + GroupOwned = (bytes[i++] != 0) ? (bool)true : (bool)false; + AssetID.FromBytes(bytes, i); i += 16; + Type = (sbyte)bytes[i++]; + InvType = (sbyte)bytes[i++]; + Flags = (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)); + length = bytes[i++]; + Name = new byte[length]; + Buffer.BlockCopy(bytes, i, Name, 0, length); i += length; + length = bytes[i++]; + Description = new byte[length]; + Buffer.BlockCopy(bytes, i, Description, 0, length); i += length; + CreationDate = (int)(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(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + ItemID.ToBytes(bytes, i); i += 16; + FolderID.ToBytes(bytes, i); i += 16; + Utils.UIntToBytes(CallbackID, bytes, i); i += 4; + CreatorID.ToBytes(bytes, i); i += 16; + OwnerID.ToBytes(bytes, i); i += 16; + GroupID.ToBytes(bytes, i); i += 16; + Utils.UIntToBytes(BaseMask, bytes, i); i += 4; + Utils.UIntToBytes(OwnerMask, bytes, i); i += 4; + Utils.UIntToBytes(GroupMask, bytes, i); i += 4; + Utils.UIntToBytes(EveryoneMask, bytes, i); i += 4; + Utils.UIntToBytes(NextOwnerMask, bytes, i); i += 4; + bytes[i++] = (byte)((GroupOwned) ? 1 : 0); + AssetID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)Type; + bytes[i++] = (byte)InvType; + Utils.UIntToBytes(Flags, bytes, i); i += 4; + bytes[i++] = SaleType; + Utils.IntToBytes(SalePrice, bytes, i); i += 4; + bytes[i++] = (byte)Name.Length; + Buffer.BlockCopy(Name, 0, bytes, i, Name.Length); i += Name.Length; + bytes[i++] = (byte)Description.Length; + Buffer.BlockCopy(Description, 0, bytes, i, Description.Length); i += Description.Length; + Utils.IntToBytes(CreationDate, bytes, i); i += 4; + Utils.UIntToBytes(CRC, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentData.Length; + for (int j = 0; j < InventoryData.Length; j++) + length += InventoryData[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public InventoryDataBlock[] InventoryData; + + public UpdateCreateInventoryItemPacket() + { + HasVariableBlocks = true; + Type = PacketType.UpdateCreateInventoryItem; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 267; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + InventoryData = null; + } + + public UpdateCreateInventoryItemPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(InventoryData == null || InventoryData.Length != -1) { + InventoryData = new InventoryDataBlock[count]; + for(int j = 0; j < count; j++) + { InventoryData[j] = new InventoryDataBlock(); } + } + for (int j = 0; j < count; j++) + { InventoryData[j].FromBytes(bytes, ref i); } + } + + public UpdateCreateInventoryItemPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(InventoryData == null || InventoryData.Length != count) { + InventoryData = new InventoryDataBlock[count]; + for(int j = 0; j < count; j++) + { InventoryData[j] = new InventoryDataBlock(); } + } + for (int j = 0; j < count; j++) + { InventoryData[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length++; + for (int j = 0; j < InventoryData.Length; j++) { length += InventoryData[j].Length; } + if (Header.AckList != null && 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)InventoryData.Length; + for (int j = 0; j < InventoryData.Length; j++) { InventoryData[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int InventoryDataStart = 0; + do + { + int variableLength = 0; + int InventoryDataCount = 0; + + i = InventoryDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < InventoryData.Length) { + int blockLength = InventoryData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == InventoryDataStart) { + variableLength += blockLength; + ++InventoryDataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)InventoryDataCount; + for (i = InventoryDataStart; i < InventoryDataStart + InventoryDataCount; i++) { InventoryData[i].ToBytes(packet, ref length); } + InventoryDataStart += InventoryDataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + InventoryDataStart < InventoryData.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class MoveInventoryItemPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + public bool Stamp; + + public override int Length + { + get + { + return 33; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + Stamp = (bytes[i++] != 0) ? (bool)true : (bool)false; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)((Stamp) ? 1 : 0); + } + + } + + /// + public sealed class InventoryDataBlock : PacketBlock + { + public UUID ItemID; + public UUID FolderID; + public byte[] NewName; + + public override int Length + { + get + { + int length = 33; + if (NewName != null) { length += NewName.Length; } + return length; + } + } + + public InventoryDataBlock() { } + public InventoryDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + ItemID.FromBytes(bytes, i); i += 16; + FolderID.FromBytes(bytes, i); i += 16; + length = bytes[i++]; + NewName = new byte[length]; + Buffer.BlockCopy(bytes, i, NewName, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + ItemID.ToBytes(bytes, i); i += 16; + FolderID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)NewName.Length; + Buffer.BlockCopy(NewName, 0, bytes, i, NewName.Length); i += NewName.Length; + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentData.Length; + for (int j = 0; j < InventoryData.Length; j++) + length += InventoryData[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public InventoryDataBlock[] InventoryData; + + public MoveInventoryItemPacket() + { + HasVariableBlocks = true; + Type = PacketType.MoveInventoryItem; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 268; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + InventoryData = null; + } + + public MoveInventoryItemPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(InventoryData == null || InventoryData.Length != -1) { + InventoryData = new InventoryDataBlock[count]; + for(int j = 0; j < count; j++) + { InventoryData[j] = new InventoryDataBlock(); } + } + for (int j = 0; j < count; j++) + { InventoryData[j].FromBytes(bytes, ref i); } + } + + public MoveInventoryItemPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(InventoryData == null || InventoryData.Length != count) { + InventoryData = new InventoryDataBlock[count]; + for(int j = 0; j < count; j++) + { InventoryData[j] = new InventoryDataBlock(); } + } + for (int j = 0; j < count; j++) + { InventoryData[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length++; + for (int j = 0; j < InventoryData.Length; j++) { length += InventoryData[j].Length; } + if (Header.AckList != null && 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)InventoryData.Length; + for (int j = 0; j < InventoryData.Length; j++) { InventoryData[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int InventoryDataStart = 0; + do + { + int variableLength = 0; + int InventoryDataCount = 0; + + i = InventoryDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < InventoryData.Length) { + int blockLength = InventoryData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == InventoryDataStart) { + variableLength += blockLength; + ++InventoryDataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)InventoryDataCount; + for (i = InventoryDataStart; i < InventoryDataStart + InventoryDataCount; i++) { InventoryData[i].ToBytes(packet, ref length); } + InventoryDataStart += InventoryDataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + InventoryDataStart < InventoryData.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class CopyInventoryItemPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class InventoryDataBlock : PacketBlock + { + public uint CallbackID; + public UUID OldAgentID; + public UUID OldItemID; + public UUID NewFolderID; + public byte[] NewName; + + public override int Length + { + get + { + int length = 53; + if (NewName != null) { length += NewName.Length; } + return length; + } + } + + public InventoryDataBlock() { } + public InventoryDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + CallbackID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + OldAgentID.FromBytes(bytes, i); i += 16; + OldItemID.FromBytes(bytes, i); i += 16; + NewFolderID.FromBytes(bytes, i); i += 16; + length = bytes[i++]; + NewName = new byte[length]; + Buffer.BlockCopy(bytes, i, NewName, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UIntToBytes(CallbackID, bytes, i); i += 4; + OldAgentID.ToBytes(bytes, i); i += 16; + OldItemID.ToBytes(bytes, i); i += 16; + NewFolderID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)NewName.Length; + Buffer.BlockCopy(NewName, 0, bytes, i, NewName.Length); i += NewName.Length; + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentData.Length; + for (int j = 0; j < InventoryData.Length; j++) + length += InventoryData[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public InventoryDataBlock[] InventoryData; + + public CopyInventoryItemPacket() + { + HasVariableBlocks = true; + Type = PacketType.CopyInventoryItem; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 269; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + InventoryData = null; + } + + public CopyInventoryItemPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(InventoryData == null || InventoryData.Length != -1) { + InventoryData = new InventoryDataBlock[count]; + for(int j = 0; j < count; j++) + { InventoryData[j] = new InventoryDataBlock(); } + } + for (int j = 0; j < count; j++) + { InventoryData[j].FromBytes(bytes, ref i); } + } + + public CopyInventoryItemPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(InventoryData == null || InventoryData.Length != count) { + InventoryData = new InventoryDataBlock[count]; + for(int j = 0; j < count; j++) + { InventoryData[j] = new InventoryDataBlock(); } + } + for (int j = 0; j < count; j++) + { InventoryData[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length++; + for (int j = 0; j < InventoryData.Length; j++) { length += InventoryData[j].Length; } + if (Header.AckList != null && 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)InventoryData.Length; + for (int j = 0; j < InventoryData.Length; j++) { InventoryData[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int InventoryDataStart = 0; + do + { + int variableLength = 0; + int InventoryDataCount = 0; + + i = InventoryDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < InventoryData.Length) { + int blockLength = InventoryData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == InventoryDataStart) { + variableLength += blockLength; + ++InventoryDataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)InventoryDataCount; + for (i = InventoryDataStart; i < InventoryDataStart + InventoryDataCount; i++) { InventoryData[i].ToBytes(packet, ref length); } + InventoryDataStart += InventoryDataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + InventoryDataStart < InventoryData.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class RemoveInventoryItemPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class InventoryDataBlock : PacketBlock + { + public UUID ItemID; + + public override int Length + { + get + { + return 16; + } + } + + public InventoryDataBlock() { } + public InventoryDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + ItemID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + ItemID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentData.Length; + for (int j = 0; j < InventoryData.Length; j++) + length += InventoryData[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public InventoryDataBlock[] InventoryData; + + public RemoveInventoryItemPacket() + { + HasVariableBlocks = true; + Type = PacketType.RemoveInventoryItem; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 270; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + InventoryData = null; + } + + public RemoveInventoryItemPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(InventoryData == null || InventoryData.Length != -1) { + InventoryData = new InventoryDataBlock[count]; + for(int j = 0; j < count; j++) + { InventoryData[j] = new InventoryDataBlock(); } + } + for (int j = 0; j < count; j++) + { InventoryData[j].FromBytes(bytes, ref i); } + } + + public RemoveInventoryItemPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(InventoryData == null || InventoryData.Length != count) { + InventoryData = new InventoryDataBlock[count]; + for(int j = 0; j < count; j++) + { InventoryData[j] = new InventoryDataBlock(); } + } + for (int j = 0; j < count; j++) + { InventoryData[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length++; + for (int j = 0; j < InventoryData.Length; j++) { length += InventoryData[j].Length; } + if (Header.AckList != null && 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)InventoryData.Length; + for (int j = 0; j < InventoryData.Length; j++) { InventoryData[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int InventoryDataStart = 0; + do + { + int variableLength = 0; + int InventoryDataCount = 0; + + i = InventoryDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < InventoryData.Length) { + int blockLength = InventoryData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == InventoryDataStart) { + variableLength += blockLength; + ++InventoryDataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)InventoryDataCount; + for (i = InventoryDataStart; i < InventoryDataStart + InventoryDataCount; i++) { InventoryData[i].ToBytes(packet, ref length); } + InventoryDataStart += InventoryDataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + InventoryDataStart < InventoryData.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class ChangeInventoryItemFlagsPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class InventoryDataBlock : PacketBlock + { + public UUID ItemID; + public uint Flags; + + public override int Length + { + get + { + return 20; + } + } + + public InventoryDataBlock() { } + public InventoryDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + ItemID.FromBytes(bytes, i); i += 16; + Flags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + ItemID.ToBytes(bytes, i); i += 16; + Utils.UIntToBytes(Flags, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentData.Length; + for (int j = 0; j < InventoryData.Length; j++) + length += InventoryData[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public InventoryDataBlock[] InventoryData; + + public ChangeInventoryItemFlagsPacket() + { + HasVariableBlocks = true; + Type = PacketType.ChangeInventoryItemFlags; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 271; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + InventoryData = null; + } + + public ChangeInventoryItemFlagsPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(InventoryData == null || InventoryData.Length != -1) { + InventoryData = new InventoryDataBlock[count]; + for(int j = 0; j < count; j++) + { InventoryData[j] = new InventoryDataBlock(); } + } + for (int j = 0; j < count; j++) + { InventoryData[j].FromBytes(bytes, ref i); } + } + + public ChangeInventoryItemFlagsPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(InventoryData == null || InventoryData.Length != count) { + InventoryData = new InventoryDataBlock[count]; + for(int j = 0; j < count; j++) + { InventoryData[j] = new InventoryDataBlock(); } + } + for (int j = 0; j < count; j++) + { InventoryData[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length++; + for (int j = 0; j < InventoryData.Length; j++) { length += InventoryData[j].Length; } + if (Header.AckList != null && 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)InventoryData.Length; + for (int j = 0; j < InventoryData.Length; j++) { InventoryData[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int InventoryDataStart = 0; + do + { + int variableLength = 0; + int InventoryDataCount = 0; + + i = InventoryDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < InventoryData.Length) { + int blockLength = InventoryData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == InventoryDataStart) { + variableLength += blockLength; + ++InventoryDataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)InventoryDataCount; + for (i = InventoryDataStart; i < InventoryDataStart + InventoryDataCount; i++) { InventoryData[i].ToBytes(packet, ref length); } + InventoryDataStart += InventoryDataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + InventoryDataStart < InventoryData.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class SaveAssetIntoInventoryPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + + public override int Length + { + get + { + return 16; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class InventoryDataBlock : PacketBlock + { + public UUID ItemID; + public UUID NewAssetID; + + public override int Length + { + get + { + return 32; + } + } + + public InventoryDataBlock() { } + public InventoryDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + ItemID.FromBytes(bytes, i); i += 16; + NewAssetID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + ItemID.ToBytes(bytes, i); i += 16; + NewAssetID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += InventoryData.Length; + return length; + } + } + public AgentDataBlock AgentData; + public InventoryDataBlock InventoryData; + + public SaveAssetIntoInventoryPacket() + { + HasVariableBlocks = false; + Type = PacketType.SaveAssetIntoInventory; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 272; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + InventoryData = new InventoryDataBlock(); + } + + public SaveAssetIntoInventoryPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + InventoryData.FromBytes(bytes, ref i); + } + + public SaveAssetIntoInventoryPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + InventoryData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += InventoryData.Length; + if (Header.AckList != null && 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); + InventoryData.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class CreateInventoryFolderPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class FolderDataBlock : PacketBlock + { + public UUID FolderID; + public UUID ParentID; + public sbyte Type; + public byte[] Name; + + public override int Length + { + get + { + int length = 34; + if (Name != null) { length += Name.Length; } + return length; + } + } + + public FolderDataBlock() { } + public FolderDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + FolderID.FromBytes(bytes, i); i += 16; + ParentID.FromBytes(bytes, i); i += 16; + Type = (sbyte)bytes[i++]; + length = bytes[i++]; + Name = new byte[length]; + Buffer.BlockCopy(bytes, i, Name, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + FolderID.ToBytes(bytes, i); i += 16; + ParentID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)Type; + bytes[i++] = (byte)Name.Length; + Buffer.BlockCopy(Name, 0, bytes, i, Name.Length); i += Name.Length; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += FolderData.Length; + return length; + } + } + public AgentDataBlock AgentData; + public FolderDataBlock FolderData; + + public CreateInventoryFolderPacket() + { + HasVariableBlocks = false; + Type = PacketType.CreateInventoryFolder; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 273; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + FolderData = new FolderDataBlock(); + } + + public CreateInventoryFolderPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + FolderData.FromBytes(bytes, ref i); + } + + public CreateInventoryFolderPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + FolderData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += FolderData.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class UpdateInventoryFolderPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class FolderDataBlock : PacketBlock + { + public UUID FolderID; + public UUID ParentID; + public sbyte Type; + public byte[] Name; + + public override int Length + { + get + { + int length = 34; + if (Name != null) { length += Name.Length; } + return length; + } + } + + public FolderDataBlock() { } + public FolderDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + FolderID.FromBytes(bytes, i); i += 16; + ParentID.FromBytes(bytes, i); i += 16; + Type = (sbyte)bytes[i++]; + length = bytes[i++]; + Name = new byte[length]; + Buffer.BlockCopy(bytes, i, Name, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + FolderID.ToBytes(bytes, i); i += 16; + ParentID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)Type; + bytes[i++] = (byte)Name.Length; + Buffer.BlockCopy(Name, 0, bytes, i, Name.Length); i += Name.Length; + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentData.Length; + for (int j = 0; j < FolderData.Length; j++) + length += FolderData[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public FolderDataBlock[] FolderData; + + public UpdateInventoryFolderPacket() + { + HasVariableBlocks = true; + Type = PacketType.UpdateInventoryFolder; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 274; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + FolderData = null; + } + + public UpdateInventoryFolderPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(FolderData == null || FolderData.Length != -1) { + FolderData = new FolderDataBlock[count]; + for(int j = 0; j < count; j++) + { FolderData[j] = new FolderDataBlock(); } + } + for (int j = 0; j < count; j++) + { FolderData[j].FromBytes(bytes, ref i); } + } + + public UpdateInventoryFolderPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(FolderData == null || FolderData.Length != count) { + FolderData = new FolderDataBlock[count]; + for(int j = 0; j < count; j++) + { FolderData[j] = new FolderDataBlock(); } + } + for (int j = 0; j < count; j++) + { FolderData[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length++; + for (int j = 0; j < FolderData.Length; j++) { length += FolderData[j].Length; } + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int FolderDataStart = 0; + do + { + int variableLength = 0; + int FolderDataCount = 0; + + i = FolderDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < FolderData.Length) { + int blockLength = FolderData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == FolderDataStart) { + variableLength += blockLength; + ++FolderDataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)FolderDataCount; + for (i = FolderDataStart; i < FolderDataStart + FolderDataCount; i++) { FolderData[i].ToBytes(packet, ref length); } + FolderDataStart += FolderDataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + FolderDataStart < FolderData.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class MoveInventoryFolderPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + public bool Stamp; + + public override int Length + { + get + { + return 33; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + Stamp = (bytes[i++] != 0) ? (bool)true : (bool)false; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)((Stamp) ? 1 : 0); + } + + } + + /// + public sealed class InventoryDataBlock : PacketBlock + { + public UUID FolderID; + public UUID ParentID; + + public override int Length + { + get + { + return 32; + } + } + + public InventoryDataBlock() { } + public InventoryDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + FolderID.FromBytes(bytes, i); i += 16; + ParentID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + FolderID.ToBytes(bytes, i); i += 16; + ParentID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentData.Length; + for (int j = 0; j < InventoryData.Length; j++) + length += InventoryData[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public InventoryDataBlock[] InventoryData; + + public MoveInventoryFolderPacket() + { + HasVariableBlocks = true; + Type = PacketType.MoveInventoryFolder; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 275; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + InventoryData = null; + } + + public MoveInventoryFolderPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(InventoryData == null || InventoryData.Length != -1) { + InventoryData = new InventoryDataBlock[count]; + for(int j = 0; j < count; j++) + { InventoryData[j] = new InventoryDataBlock(); } + } + for (int j = 0; j < count; j++) + { InventoryData[j].FromBytes(bytes, ref i); } + } + + public MoveInventoryFolderPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(InventoryData == null || InventoryData.Length != count) { + InventoryData = new InventoryDataBlock[count]; + for(int j = 0; j < count; j++) + { InventoryData[j] = new InventoryDataBlock(); } + } + for (int j = 0; j < count; j++) + { InventoryData[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length++; + for (int j = 0; j < InventoryData.Length; j++) { length += InventoryData[j].Length; } + if (Header.AckList != null && 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)InventoryData.Length; + for (int j = 0; j < InventoryData.Length; j++) { InventoryData[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int InventoryDataStart = 0; + do + { + int variableLength = 0; + int InventoryDataCount = 0; + + i = InventoryDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < InventoryData.Length) { + int blockLength = InventoryData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == InventoryDataStart) { + variableLength += blockLength; + ++InventoryDataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)InventoryDataCount; + for (i = InventoryDataStart; i < InventoryDataStart + InventoryDataCount; i++) { InventoryData[i].ToBytes(packet, ref length); } + InventoryDataStart += InventoryDataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + InventoryDataStart < InventoryData.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class RemoveInventoryFolderPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class FolderDataBlock : PacketBlock + { + public UUID FolderID; + + public override int Length + { + get + { + return 16; + } + } + + public FolderDataBlock() { } + public FolderDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + FolderID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + FolderID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentData.Length; + for (int j = 0; j < FolderData.Length; j++) + length += FolderData[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public FolderDataBlock[] FolderData; + + public RemoveInventoryFolderPacket() + { + HasVariableBlocks = true; + Type = PacketType.RemoveInventoryFolder; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 276; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + FolderData = null; + } + + public RemoveInventoryFolderPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(FolderData == null || FolderData.Length != -1) { + FolderData = new FolderDataBlock[count]; + for(int j = 0; j < count; j++) + { FolderData[j] = new FolderDataBlock(); } + } + for (int j = 0; j < count; j++) + { FolderData[j].FromBytes(bytes, ref i); } + } + + public RemoveInventoryFolderPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(FolderData == null || FolderData.Length != count) { + FolderData = new FolderDataBlock[count]; + for(int j = 0; j < count; j++) + { FolderData[j] = new FolderDataBlock(); } + } + for (int j = 0; j < count; j++) + { FolderData[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length++; + for (int j = 0; j < FolderData.Length; j++) { length += FolderData[j].Length; } + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int FolderDataStart = 0; + do + { + int variableLength = 0; + int FolderDataCount = 0; + + i = FolderDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < FolderData.Length) { + int blockLength = FolderData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == FolderDataStart) { + variableLength += blockLength; + ++FolderDataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)FolderDataCount; + for (i = FolderDataStart; i < FolderDataStart + FolderDataCount; i++) { FolderData[i].ToBytes(packet, ref length); } + FolderDataStart += FolderDataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + FolderDataStart < FolderData.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class FetchInventoryDescendentsPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class InventoryDataBlock : PacketBlock + { + public UUID FolderID; + public UUID OwnerID; + public int SortOrder; + public bool FetchFolders; + public bool FetchItems; + + public override int Length + { + get + { + return 38; + } + } + + public InventoryDataBlock() { } + public InventoryDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + FolderID.FromBytes(bytes, i); i += 16; + OwnerID.FromBytes(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(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + FolderID.ToBytes(bytes, i); i += 16; + OwnerID.ToBytes(bytes, i); i += 16; + Utils.IntToBytes(SortOrder, bytes, i); i += 4; + bytes[i++] = (byte)((FetchFolders) ? 1 : 0); + bytes[i++] = (byte)((FetchItems) ? 1 : 0); + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += InventoryData.Length; + return length; + } + } + public AgentDataBlock AgentData; + public InventoryDataBlock InventoryData; + + public FetchInventoryDescendentsPacket() + { + HasVariableBlocks = false; + Type = PacketType.FetchInventoryDescendents; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 277; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + InventoryData = new InventoryDataBlock(); + } + + public FetchInventoryDescendentsPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + InventoryData.FromBytes(bytes, ref i); + } + + public FetchInventoryDescendentsPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + InventoryData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += InventoryData.Length; + if (Header.AckList != null && 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); + InventoryData.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class InventoryDescendentsPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID FolderID; + public UUID OwnerID; + public int Version; + public int Descendents; + + public override int Length + { + get + { + return 56; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + FolderID.FromBytes(bytes, i); i += 16; + OwnerID.FromBytes(bytes, i); i += 16; + Version = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + Descendents = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + FolderID.ToBytes(bytes, i); i += 16; + OwnerID.ToBytes(bytes, i); i += 16; + Utils.IntToBytes(Version, bytes, i); i += 4; + Utils.IntToBytes(Descendents, bytes, i); i += 4; + } + + } + + /// + public sealed class FolderDataBlock : PacketBlock + { + public UUID FolderID; + public UUID ParentID; + public sbyte Type; + public byte[] Name; + + public override int Length + { + get + { + int length = 34; + if (Name != null) { length += Name.Length; } + return length; + } + } + + public FolderDataBlock() { } + public FolderDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + FolderID.FromBytes(bytes, i); i += 16; + ParentID.FromBytes(bytes, i); i += 16; + Type = (sbyte)bytes[i++]; + length = bytes[i++]; + Name = new byte[length]; + Buffer.BlockCopy(bytes, i, Name, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + FolderID.ToBytes(bytes, i); i += 16; + ParentID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)Type; + bytes[i++] = (byte)Name.Length; + Buffer.BlockCopy(Name, 0, bytes, i, Name.Length); i += Name.Length; + } + + } + + /// + public sealed class ItemDataBlock : PacketBlock + { + public UUID ItemID; + public UUID FolderID; + public UUID CreatorID; + public UUID OwnerID; + public UUID GroupID; + public uint BaseMask; + public uint OwnerMask; + public uint GroupMask; + public uint EveryoneMask; + public uint NextOwnerMask; + public bool GroupOwned; + public UUID AssetID; + public sbyte Type; + public sbyte InvType; + public uint Flags; + public byte SaleType; + public int SalePrice; + public byte[] Name; + public byte[] Description; + public int CreationDate; + public uint CRC; + + public override int Length + { + get + { + int length = 138; + if (Name != null) { length += Name.Length; } + if (Description != null) { length += Description.Length; } + return length; + } + } + + public ItemDataBlock() { } + public ItemDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + ItemID.FromBytes(bytes, i); i += 16; + FolderID.FromBytes(bytes, i); i += 16; + CreatorID.FromBytes(bytes, i); i += 16; + OwnerID.FromBytes(bytes, i); i += 16; + GroupID.FromBytes(bytes, i); i += 16; + BaseMask = (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)); + GroupMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + 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)); + GroupOwned = (bytes[i++] != 0) ? (bool)true : (bool)false; + AssetID.FromBytes(bytes, i); i += 16; + Type = (sbyte)bytes[i++]; + InvType = (sbyte)bytes[i++]; + Flags = (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)); + length = bytes[i++]; + Name = new byte[length]; + Buffer.BlockCopy(bytes, i, Name, 0, length); i += length; + length = bytes[i++]; + Description = new byte[length]; + Buffer.BlockCopy(bytes, i, Description, 0, length); i += length; + CreationDate = (int)(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(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + ItemID.ToBytes(bytes, i); i += 16; + FolderID.ToBytes(bytes, i); i += 16; + CreatorID.ToBytes(bytes, i); i += 16; + OwnerID.ToBytes(bytes, i); i += 16; + GroupID.ToBytes(bytes, i); i += 16; + Utils.UIntToBytes(BaseMask, bytes, i); i += 4; + Utils.UIntToBytes(OwnerMask, bytes, i); i += 4; + Utils.UIntToBytes(GroupMask, bytes, i); i += 4; + Utils.UIntToBytes(EveryoneMask, bytes, i); i += 4; + Utils.UIntToBytes(NextOwnerMask, bytes, i); i += 4; + bytes[i++] = (byte)((GroupOwned) ? 1 : 0); + AssetID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)Type; + bytes[i++] = (byte)InvType; + Utils.UIntToBytes(Flags, bytes, i); i += 4; + bytes[i++] = SaleType; + Utils.IntToBytes(SalePrice, bytes, i); i += 4; + bytes[i++] = (byte)Name.Length; + Buffer.BlockCopy(Name, 0, bytes, i, Name.Length); i += Name.Length; + bytes[i++] = (byte)Description.Length; + Buffer.BlockCopy(Description, 0, bytes, i, Description.Length); i += Description.Length; + Utils.IntToBytes(CreationDate, bytes, i); i += 4; + Utils.UIntToBytes(CRC, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 12; + length += AgentData.Length; + for (int j = 0; j < FolderData.Length; j++) + length += FolderData[j].Length; + for (int j = 0; j < ItemData.Length; j++) + length += ItemData[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public FolderDataBlock[] FolderData; + public ItemDataBlock[] ItemData; + + public InventoryDescendentsPacket() + { + HasVariableBlocks = true; + Type = PacketType.InventoryDescendents; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 278; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + FolderData = null; + ItemData = null; + } + + public InventoryDescendentsPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(FolderData == null || FolderData.Length != -1) { + FolderData = new FolderDataBlock[count]; + for(int j = 0; j < count; j++) + { FolderData[j] = new FolderDataBlock(); } + } + for (int j = 0; j < count; j++) + { FolderData[j].FromBytes(bytes, ref i); } + count = (int)bytes[i++]; + if(ItemData == null || ItemData.Length != -1) { + ItemData = new ItemDataBlock[count]; + for(int j = 0; j < count; j++) + { ItemData[j] = new ItemDataBlock(); } + } + for (int j = 0; j < count; j++) + { ItemData[j].FromBytes(bytes, ref i); } + } + + public InventoryDescendentsPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(FolderData == null || FolderData.Length != count) { + FolderData = new FolderDataBlock[count]; + for(int j = 0; j < count; j++) + { FolderData[j] = new FolderDataBlock(); } + } + for (int j = 0; j < count; j++) + { FolderData[j].FromBytes(bytes, ref i); } + count = (int)bytes[i++]; + if(ItemData == null || ItemData.Length != count) { + ItemData = new ItemDataBlock[count]; + for(int j = 0; j < count; j++) + { ItemData[j] = new ItemDataBlock(); } + } + for (int j = 0; j < count; j++) + { ItemData[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length++; + for (int j = 0; j < FolderData.Length; j++) { length += FolderData[j].Length; } + length++; + for (int j = 0; j < ItemData.Length; j++) { length += ItemData[j].Length; } + if (Header.AckList != null && 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); } + bytes[i++] = (byte)ItemData.Length; + for (int j = 0; j < ItemData.Length; j++) { ItemData[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + fixedLength += 2; + + int FolderDataStart = 0; + int ItemDataStart = 0; + do + { + int variableLength = 0; + int FolderDataCount = 0; + int ItemDataCount = 0; + + i = FolderDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < FolderData.Length) { + int blockLength = FolderData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == FolderDataStart) { + variableLength += blockLength; + ++FolderDataCount; + } + else { break; } + ++i; + } + + i = ItemDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < ItemData.Length) { + int blockLength = ItemData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ItemDataStart) { + variableLength += blockLength; + ++ItemDataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)FolderDataCount; + for (i = FolderDataStart; i < FolderDataStart + FolderDataCount; i++) { FolderData[i].ToBytes(packet, ref length); } + FolderDataStart += FolderDataCount; + + packet[length++] = (byte)ItemDataCount; + for (i = ItemDataStart; i < ItemDataStart + ItemDataCount; i++) { ItemData[i].ToBytes(packet, ref length); } + ItemDataStart += ItemDataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + FolderDataStart < FolderData.Length || + ItemDataStart < ItemData.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class FetchInventoryPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class InventoryDataBlock : PacketBlock + { + public UUID OwnerID; + public UUID ItemID; + + public override int Length + { + get + { + return 32; + } + } + + public InventoryDataBlock() { } + public InventoryDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + OwnerID.FromBytes(bytes, i); i += 16; + ItemID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + OwnerID.ToBytes(bytes, i); i += 16; + ItemID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentData.Length; + for (int j = 0; j < InventoryData.Length; j++) + length += InventoryData[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public InventoryDataBlock[] InventoryData; + + public FetchInventoryPacket() + { + HasVariableBlocks = true; + Type = PacketType.FetchInventory; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 279; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + InventoryData = null; + } + + public FetchInventoryPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(InventoryData == null || InventoryData.Length != -1) { + InventoryData = new InventoryDataBlock[count]; + for(int j = 0; j < count; j++) + { InventoryData[j] = new InventoryDataBlock(); } + } + for (int j = 0; j < count; j++) + { InventoryData[j].FromBytes(bytes, ref i); } + } + + public FetchInventoryPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(InventoryData == null || InventoryData.Length != count) { + InventoryData = new InventoryDataBlock[count]; + for(int j = 0; j < count; j++) + { InventoryData[j] = new InventoryDataBlock(); } + } + for (int j = 0; j < count; j++) + { InventoryData[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length++; + for (int j = 0; j < InventoryData.Length; j++) { length += InventoryData[j].Length; } + if (Header.AckList != null && 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)InventoryData.Length; + for (int j = 0; j < InventoryData.Length; j++) { InventoryData[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int InventoryDataStart = 0; + do + { + int variableLength = 0; + int InventoryDataCount = 0; + + i = InventoryDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < InventoryData.Length) { + int blockLength = InventoryData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == InventoryDataStart) { + variableLength += blockLength; + ++InventoryDataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)InventoryDataCount; + for (i = InventoryDataStart; i < InventoryDataStart + InventoryDataCount; i++) { InventoryData[i].ToBytes(packet, ref length); } + InventoryDataStart += InventoryDataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + InventoryDataStart < InventoryData.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class FetchInventoryReplyPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + + public override int Length + { + get + { + return 16; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class InventoryDataBlock : PacketBlock + { + public UUID ItemID; + public UUID FolderID; + public UUID CreatorID; + public UUID OwnerID; + public UUID GroupID; + public uint BaseMask; + public uint OwnerMask; + public uint GroupMask; + public uint EveryoneMask; + public uint NextOwnerMask; + public bool GroupOwned; + public UUID AssetID; + public sbyte Type; + public sbyte InvType; + public uint Flags; + public byte SaleType; + public int SalePrice; + public byte[] Name; + public byte[] Description; + public int CreationDate; + public uint CRC; + + public override int Length + { + get + { + int length = 138; + if (Name != null) { length += Name.Length; } + if (Description != null) { length += Description.Length; } + return length; + } + } + + public InventoryDataBlock() { } + public InventoryDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + ItemID.FromBytes(bytes, i); i += 16; + FolderID.FromBytes(bytes, i); i += 16; + CreatorID.FromBytes(bytes, i); i += 16; + OwnerID.FromBytes(bytes, i); i += 16; + GroupID.FromBytes(bytes, i); i += 16; + BaseMask = (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)); + GroupMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + 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)); + GroupOwned = (bytes[i++] != 0) ? (bool)true : (bool)false; + AssetID.FromBytes(bytes, i); i += 16; + Type = (sbyte)bytes[i++]; + InvType = (sbyte)bytes[i++]; + Flags = (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)); + length = bytes[i++]; + Name = new byte[length]; + Buffer.BlockCopy(bytes, i, Name, 0, length); i += length; + length = bytes[i++]; + Description = new byte[length]; + Buffer.BlockCopy(bytes, i, Description, 0, length); i += length; + CreationDate = (int)(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(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + ItemID.ToBytes(bytes, i); i += 16; + FolderID.ToBytes(bytes, i); i += 16; + CreatorID.ToBytes(bytes, i); i += 16; + OwnerID.ToBytes(bytes, i); i += 16; + GroupID.ToBytes(bytes, i); i += 16; + Utils.UIntToBytes(BaseMask, bytes, i); i += 4; + Utils.UIntToBytes(OwnerMask, bytes, i); i += 4; + Utils.UIntToBytes(GroupMask, bytes, i); i += 4; + Utils.UIntToBytes(EveryoneMask, bytes, i); i += 4; + Utils.UIntToBytes(NextOwnerMask, bytes, i); i += 4; + bytes[i++] = (byte)((GroupOwned) ? 1 : 0); + AssetID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)Type; + bytes[i++] = (byte)InvType; + Utils.UIntToBytes(Flags, bytes, i); i += 4; + bytes[i++] = SaleType; + Utils.IntToBytes(SalePrice, bytes, i); i += 4; + bytes[i++] = (byte)Name.Length; + Buffer.BlockCopy(Name, 0, bytes, i, Name.Length); i += Name.Length; + bytes[i++] = (byte)Description.Length; + Buffer.BlockCopy(Description, 0, bytes, i, Description.Length); i += Description.Length; + Utils.IntToBytes(CreationDate, bytes, i); i += 4; + Utils.UIntToBytes(CRC, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentData.Length; + for (int j = 0; j < InventoryData.Length; j++) + length += InventoryData[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public InventoryDataBlock[] InventoryData; + + public FetchInventoryReplyPacket() + { + HasVariableBlocks = true; + Type = PacketType.FetchInventoryReply; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 280; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + InventoryData = null; + } + + public FetchInventoryReplyPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(InventoryData == null || InventoryData.Length != -1) { + InventoryData = new InventoryDataBlock[count]; + for(int j = 0; j < count; j++) + { InventoryData[j] = new InventoryDataBlock(); } + } + for (int j = 0; j < count; j++) + { InventoryData[j].FromBytes(bytes, ref i); } + } + + public FetchInventoryReplyPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(InventoryData == null || InventoryData.Length != count) { + InventoryData = new InventoryDataBlock[count]; + for(int j = 0; j < count; j++) + { InventoryData[j] = new InventoryDataBlock(); } + } + for (int j = 0; j < count; j++) + { InventoryData[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length++; + for (int j = 0; j < InventoryData.Length; j++) { length += InventoryData[j].Length; } + if (Header.AckList != null && 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)InventoryData.Length; + for (int j = 0; j < InventoryData.Length; j++) { InventoryData[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int InventoryDataStart = 0; + do + { + int variableLength = 0; + int InventoryDataCount = 0; + + i = InventoryDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < InventoryData.Length) { + int blockLength = InventoryData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == InventoryDataStart) { + variableLength += blockLength; + ++InventoryDataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)InventoryDataCount; + for (i = InventoryDataStart; i < InventoryDataStart + InventoryDataCount; i++) { InventoryData[i].ToBytes(packet, ref length); } + InventoryDataStart += InventoryDataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + InventoryDataStart < InventoryData.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class BulkUpdateInventoryPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID TransactionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + TransactionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + TransactionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class FolderDataBlock : PacketBlock + { + public UUID FolderID; + public UUID ParentID; + public sbyte Type; + public byte[] Name; + + public override int Length + { + get + { + int length = 34; + if (Name != null) { length += Name.Length; } + return length; + } + } + + public FolderDataBlock() { } + public FolderDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + FolderID.FromBytes(bytes, i); i += 16; + ParentID.FromBytes(bytes, i); i += 16; + Type = (sbyte)bytes[i++]; + length = bytes[i++]; + Name = new byte[length]; + Buffer.BlockCopy(bytes, i, Name, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + FolderID.ToBytes(bytes, i); i += 16; + ParentID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)Type; + bytes[i++] = (byte)Name.Length; + Buffer.BlockCopy(Name, 0, bytes, i, Name.Length); i += Name.Length; + } + + } + + /// + public sealed class ItemDataBlock : PacketBlock + { + public UUID ItemID; + public uint CallbackID; + public UUID FolderID; + public UUID CreatorID; + public UUID OwnerID; + public UUID GroupID; + public uint BaseMask; + public uint OwnerMask; + public uint GroupMask; + public uint EveryoneMask; + public uint NextOwnerMask; + public bool GroupOwned; + public UUID AssetID; + public sbyte Type; + public sbyte InvType; + public uint Flags; + public byte SaleType; + public int SalePrice; + public byte[] Name; + public byte[] Description; + public int CreationDate; + public uint CRC; + + public override int Length + { + get + { + int length = 142; + if (Name != null) { length += Name.Length; } + if (Description != null) { length += Description.Length; } + return length; + } + } + + public ItemDataBlock() { } + public ItemDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + ItemID.FromBytes(bytes, i); i += 16; + CallbackID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + FolderID.FromBytes(bytes, i); i += 16; + CreatorID.FromBytes(bytes, i); i += 16; + OwnerID.FromBytes(bytes, i); i += 16; + GroupID.FromBytes(bytes, i); i += 16; + BaseMask = (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)); + GroupMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + 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)); + GroupOwned = (bytes[i++] != 0) ? (bool)true : (bool)false; + AssetID.FromBytes(bytes, i); i += 16; + Type = (sbyte)bytes[i++]; + InvType = (sbyte)bytes[i++]; + Flags = (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)); + length = bytes[i++]; + Name = new byte[length]; + Buffer.BlockCopy(bytes, i, Name, 0, length); i += length; + length = bytes[i++]; + Description = new byte[length]; + Buffer.BlockCopy(bytes, i, Description, 0, length); i += length; + CreationDate = (int)(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(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + ItemID.ToBytes(bytes, i); i += 16; + Utils.UIntToBytes(CallbackID, bytes, i); i += 4; + FolderID.ToBytes(bytes, i); i += 16; + CreatorID.ToBytes(bytes, i); i += 16; + OwnerID.ToBytes(bytes, i); i += 16; + GroupID.ToBytes(bytes, i); i += 16; + Utils.UIntToBytes(BaseMask, bytes, i); i += 4; + Utils.UIntToBytes(OwnerMask, bytes, i); i += 4; + Utils.UIntToBytes(GroupMask, bytes, i); i += 4; + Utils.UIntToBytes(EveryoneMask, bytes, i); i += 4; + Utils.UIntToBytes(NextOwnerMask, bytes, i); i += 4; + bytes[i++] = (byte)((GroupOwned) ? 1 : 0); + AssetID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)Type; + bytes[i++] = (byte)InvType; + Utils.UIntToBytes(Flags, bytes, i); i += 4; + bytes[i++] = SaleType; + Utils.IntToBytes(SalePrice, bytes, i); i += 4; + bytes[i++] = (byte)Name.Length; + Buffer.BlockCopy(Name, 0, bytes, i, Name.Length); i += Name.Length; + bytes[i++] = (byte)Description.Length; + Buffer.BlockCopy(Description, 0, bytes, i, Description.Length); i += Description.Length; + Utils.IntToBytes(CreationDate, bytes, i); i += 4; + Utils.UIntToBytes(CRC, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 12; + length += AgentData.Length; + for (int j = 0; j < FolderData.Length; j++) + length += FolderData[j].Length; + for (int j = 0; j < ItemData.Length; j++) + length += ItemData[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public FolderDataBlock[] FolderData; + public ItemDataBlock[] ItemData; + + public BulkUpdateInventoryPacket() + { + HasVariableBlocks = true; + Type = PacketType.BulkUpdateInventory; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 281; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + FolderData = null; + ItemData = null; + } + + public BulkUpdateInventoryPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(FolderData == null || FolderData.Length != -1) { + FolderData = new FolderDataBlock[count]; + for(int j = 0; j < count; j++) + { FolderData[j] = new FolderDataBlock(); } + } + for (int j = 0; j < count; j++) + { FolderData[j].FromBytes(bytes, ref i); } + count = (int)bytes[i++]; + if(ItemData == null || ItemData.Length != -1) { + ItemData = new ItemDataBlock[count]; + for(int j = 0; j < count; j++) + { ItemData[j] = new ItemDataBlock(); } + } + for (int j = 0; j < count; j++) + { ItemData[j].FromBytes(bytes, ref i); } + } + + public BulkUpdateInventoryPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(FolderData == null || FolderData.Length != count) { + FolderData = new FolderDataBlock[count]; + for(int j = 0; j < count; j++) + { FolderData[j] = new FolderDataBlock(); } + } + for (int j = 0; j < count; j++) + { FolderData[j].FromBytes(bytes, ref i); } + count = (int)bytes[i++]; + if(ItemData == null || ItemData.Length != count) { + ItemData = new ItemDataBlock[count]; + for(int j = 0; j < count; j++) + { ItemData[j] = new ItemDataBlock(); } + } + for (int j = 0; j < count; j++) + { ItemData[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length++; + for (int j = 0; j < FolderData.Length; j++) { length += FolderData[j].Length; } + length++; + for (int j = 0; j < ItemData.Length; j++) { length += ItemData[j].Length; } + if (Header.AckList != null && 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); } + bytes[i++] = (byte)ItemData.Length; + for (int j = 0; j < ItemData.Length; j++) { ItemData[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + fixedLength += 2; + + int FolderDataStart = 0; + int ItemDataStart = 0; + do + { + int variableLength = 0; + int FolderDataCount = 0; + int ItemDataCount = 0; + + i = FolderDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < FolderData.Length) { + int blockLength = FolderData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == FolderDataStart) { + variableLength += blockLength; + ++FolderDataCount; + } + else { break; } + ++i; + } + + i = ItemDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < ItemData.Length) { + int blockLength = ItemData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ItemDataStart) { + variableLength += blockLength; + ++ItemDataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)FolderDataCount; + for (i = FolderDataStart; i < FolderDataStart + FolderDataCount; i++) { FolderData[i].ToBytes(packet, ref length); } + FolderDataStart += FolderDataCount; + + packet[length++] = (byte)ItemDataCount; + for (i = ItemDataStart; i < ItemDataStart + ItemDataCount; i++) { ItemData[i].ToBytes(packet, ref length); } + ItemDataStart += ItemDataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + FolderDataStart < FolderData.Length || + ItemDataStart < ItemData.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class RemoveInventoryObjectsPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class FolderDataBlock : PacketBlock + { + public UUID FolderID; + + public override int Length + { + get + { + return 16; + } + } + + public FolderDataBlock() { } + public FolderDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + FolderID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + FolderID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class ItemDataBlock : PacketBlock + { + public UUID ItemID; + + public override int Length + { + get + { + return 16; + } + } + + public ItemDataBlock() { } + public ItemDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + ItemID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + ItemID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 12; + length += AgentData.Length; + for (int j = 0; j < FolderData.Length; j++) + length += FolderData[j].Length; + for (int j = 0; j < ItemData.Length; j++) + length += ItemData[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public FolderDataBlock[] FolderData; + public ItemDataBlock[] ItemData; + + public RemoveInventoryObjectsPacket() + { + HasVariableBlocks = true; + Type = PacketType.RemoveInventoryObjects; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 284; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + FolderData = null; + ItemData = null; + } + + public RemoveInventoryObjectsPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(FolderData == null || FolderData.Length != -1) { + FolderData = new FolderDataBlock[count]; + for(int j = 0; j < count; j++) + { FolderData[j] = new FolderDataBlock(); } + } + for (int j = 0; j < count; j++) + { FolderData[j].FromBytes(bytes, ref i); } + count = (int)bytes[i++]; + if(ItemData == null || ItemData.Length != -1) { + ItemData = new ItemDataBlock[count]; + for(int j = 0; j < count; j++) + { ItemData[j] = new ItemDataBlock(); } + } + for (int j = 0; j < count; j++) + { ItemData[j].FromBytes(bytes, ref i); } + } + + public RemoveInventoryObjectsPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(FolderData == null || FolderData.Length != count) { + FolderData = new FolderDataBlock[count]; + for(int j = 0; j < count; j++) + { FolderData[j] = new FolderDataBlock(); } + } + for (int j = 0; j < count; j++) + { FolderData[j].FromBytes(bytes, ref i); } + count = (int)bytes[i++]; + if(ItemData == null || ItemData.Length != count) { + ItemData = new ItemDataBlock[count]; + for(int j = 0; j < count; j++) + { ItemData[j] = new ItemDataBlock(); } + } + for (int j = 0; j < count; j++) + { ItemData[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length++; + for (int j = 0; j < FolderData.Length; j++) { length += FolderData[j].Length; } + length++; + for (int j = 0; j < ItemData.Length; j++) { length += ItemData[j].Length; } + if (Header.AckList != null && 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); } + bytes[i++] = (byte)ItemData.Length; + for (int j = 0; j < ItemData.Length; j++) { ItemData[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + fixedLength += 2; + + int FolderDataStart = 0; + int ItemDataStart = 0; + do + { + int variableLength = 0; + int FolderDataCount = 0; + int ItemDataCount = 0; + + i = FolderDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < FolderData.Length) { + int blockLength = FolderData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == FolderDataStart) { + variableLength += blockLength; + ++FolderDataCount; + } + else { break; } + ++i; + } + + i = ItemDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < ItemData.Length) { + int blockLength = ItemData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ItemDataStart) { + variableLength += blockLength; + ++ItemDataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)FolderDataCount; + for (i = FolderDataStart; i < FolderDataStart + FolderDataCount; i++) { FolderData[i].ToBytes(packet, ref length); } + FolderDataStart += FolderDataCount; + + packet[length++] = (byte)ItemDataCount; + for (i = ItemDataStart; i < ItemDataStart + ItemDataCount; i++) { ItemData[i].ToBytes(packet, ref length); } + ItemDataStart += ItemDataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + FolderDataStart < FolderData.Length || + ItemDataStart < ItemData.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class PurgeInventoryDescendentsPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class InventoryDataBlock : PacketBlock + { + public UUID FolderID; + + public override int Length + { + get + { + return 16; + } + } + + public InventoryDataBlock() { } + public InventoryDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + FolderID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + FolderID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += InventoryData.Length; + return length; + } + } + public AgentDataBlock AgentData; + public InventoryDataBlock InventoryData; + + public PurgeInventoryDescendentsPacket() + { + HasVariableBlocks = false; + Type = PacketType.PurgeInventoryDescendents; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 285; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + InventoryData = new InventoryDataBlock(); + } + + public PurgeInventoryDescendentsPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + InventoryData.FromBytes(bytes, ref i); + } + + public PurgeInventoryDescendentsPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + InventoryData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += InventoryData.Length; + if (Header.AckList != null && 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); + InventoryData.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class UpdateTaskInventoryPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class UpdateDataBlock : PacketBlock + { + public uint LocalID; + public byte Key; + + public override int Length + { + get + { + return 5; + } + } + + public UpdateDataBlock() { } + public UpdateDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + LocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + Key = (byte)bytes[i++]; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UIntToBytes(LocalID, bytes, i); i += 4; + bytes[i++] = Key; + } + + } + + /// + public sealed class InventoryDataBlock : PacketBlock + { + public UUID ItemID; + public UUID FolderID; + public UUID CreatorID; + public UUID OwnerID; + public UUID GroupID; + public uint BaseMask; + public uint OwnerMask; + public uint GroupMask; + public uint EveryoneMask; + public uint NextOwnerMask; + public bool GroupOwned; + public UUID TransactionID; + public sbyte Type; + public sbyte InvType; + public uint Flags; + public byte SaleType; + public int SalePrice; + public byte[] Name; + public byte[] Description; + public int CreationDate; + public uint CRC; + + public override int Length + { + get + { + int length = 138; + if (Name != null) { length += Name.Length; } + if (Description != null) { length += Description.Length; } + return length; + } + } + + public InventoryDataBlock() { } + public InventoryDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + ItemID.FromBytes(bytes, i); i += 16; + FolderID.FromBytes(bytes, i); i += 16; + CreatorID.FromBytes(bytes, i); i += 16; + OwnerID.FromBytes(bytes, i); i += 16; + GroupID.FromBytes(bytes, i); i += 16; + BaseMask = (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)); + GroupMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + 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)); + GroupOwned = (bytes[i++] != 0) ? (bool)true : (bool)false; + TransactionID.FromBytes(bytes, i); i += 16; + Type = (sbyte)bytes[i++]; + InvType = (sbyte)bytes[i++]; + Flags = (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)); + length = bytes[i++]; + Name = new byte[length]; + Buffer.BlockCopy(bytes, i, Name, 0, length); i += length; + length = bytes[i++]; + Description = new byte[length]; + Buffer.BlockCopy(bytes, i, Description, 0, length); i += length; + CreationDate = (int)(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(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + ItemID.ToBytes(bytes, i); i += 16; + FolderID.ToBytes(bytes, i); i += 16; + CreatorID.ToBytes(bytes, i); i += 16; + OwnerID.ToBytes(bytes, i); i += 16; + GroupID.ToBytes(bytes, i); i += 16; + Utils.UIntToBytes(BaseMask, bytes, i); i += 4; + Utils.UIntToBytes(OwnerMask, bytes, i); i += 4; + Utils.UIntToBytes(GroupMask, bytes, i); i += 4; + Utils.UIntToBytes(EveryoneMask, bytes, i); i += 4; + Utils.UIntToBytes(NextOwnerMask, bytes, i); i += 4; + bytes[i++] = (byte)((GroupOwned) ? 1 : 0); + TransactionID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)Type; + bytes[i++] = (byte)InvType; + Utils.UIntToBytes(Flags, bytes, i); i += 4; + bytes[i++] = SaleType; + Utils.IntToBytes(SalePrice, bytes, i); i += 4; + bytes[i++] = (byte)Name.Length; + Buffer.BlockCopy(Name, 0, bytes, i, Name.Length); i += Name.Length; + bytes[i++] = (byte)Description.Length; + Buffer.BlockCopy(Description, 0, bytes, i, Description.Length); i += Description.Length; + Utils.IntToBytes(CreationDate, bytes, i); i += 4; + Utils.UIntToBytes(CRC, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += UpdateData.Length; + length += InventoryData.Length; + return length; + } + } + public AgentDataBlock AgentData; + public UpdateDataBlock UpdateData; + public InventoryDataBlock InventoryData; + + public UpdateTaskInventoryPacket() + { + HasVariableBlocks = false; + Type = PacketType.UpdateTaskInventory; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 286; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + UpdateData = new UpdateDataBlock(); + InventoryData = new InventoryDataBlock(); + } + + public UpdateTaskInventoryPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + UpdateData.FromBytes(bytes, ref i); + InventoryData.FromBytes(bytes, ref i); + } + + public UpdateTaskInventoryPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + UpdateData.FromBytes(bytes, ref i); + InventoryData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += UpdateData.Length; + length += InventoryData.Length; + if (Header.AckList != null && 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); + UpdateData.ToBytes(bytes, ref i); + InventoryData.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class RemoveTaskInventoryPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class InventoryDataBlock : PacketBlock + { + public uint LocalID; + public UUID ItemID; + + public override int Length + { + get + { + return 20; + } + } + + public InventoryDataBlock() { } + public InventoryDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + LocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + ItemID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UIntToBytes(LocalID, bytes, i); i += 4; + ItemID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += InventoryData.Length; + return length; + } + } + public AgentDataBlock AgentData; + public InventoryDataBlock InventoryData; + + public RemoveTaskInventoryPacket() + { + HasVariableBlocks = false; + Type = PacketType.RemoveTaskInventory; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 287; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + InventoryData = new InventoryDataBlock(); + } + + public RemoveTaskInventoryPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + InventoryData.FromBytes(bytes, ref i); + } + + public RemoveTaskInventoryPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + InventoryData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += InventoryData.Length; + if (Header.AckList != null && 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); + InventoryData.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class MoveTaskInventoryPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + public UUID FolderID; + + public override int Length + { + get + { + return 48; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + FolderID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + FolderID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class InventoryDataBlock : PacketBlock + { + public uint LocalID; + public UUID ItemID; + + public override int Length + { + get + { + return 20; + } + } + + public InventoryDataBlock() { } + public InventoryDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + LocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + ItemID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UIntToBytes(LocalID, bytes, i); i += 4; + ItemID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += InventoryData.Length; + return length; + } + } + public AgentDataBlock AgentData; + public InventoryDataBlock InventoryData; + + public MoveTaskInventoryPacket() + { + HasVariableBlocks = false; + Type = PacketType.MoveTaskInventory; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 288; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + InventoryData = new InventoryDataBlock(); + } + + public MoveTaskInventoryPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + InventoryData.FromBytes(bytes, ref i); + } + + public MoveTaskInventoryPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + InventoryData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += InventoryData.Length; + if (Header.AckList != null && 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); + InventoryData.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class RequestTaskInventoryPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class InventoryDataBlock : PacketBlock + { + public uint LocalID; + + public override int Length + { + get + { + return 4; + } + } + + public InventoryDataBlock() { } + public InventoryDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + LocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UIntToBytes(LocalID, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += InventoryData.Length; + return length; + } + } + public AgentDataBlock AgentData; + public InventoryDataBlock InventoryData; + + public RequestTaskInventoryPacket() + { + HasVariableBlocks = false; + Type = PacketType.RequestTaskInventory; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 289; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + InventoryData = new InventoryDataBlock(); + } + + public RequestTaskInventoryPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + InventoryData.FromBytes(bytes, ref i); + } + + public RequestTaskInventoryPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + InventoryData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += InventoryData.Length; + if (Header.AckList != null && 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); + InventoryData.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class ReplyTaskInventoryPacket : Packet + { + /// + public sealed class InventoryDataBlock : PacketBlock + { + public UUID TaskID; + public short Serial; + public byte[] Filename; + + public override int Length + { + get + { + int length = 19; + if (Filename != null) { length += Filename.Length; } + return length; + } + } + + public InventoryDataBlock() { } + public InventoryDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + TaskID.FromBytes(bytes, i); i += 16; + Serial = (short)(bytes[i++] + (bytes[i++] << 8)); + length = bytes[i++]; + Filename = new byte[length]; + Buffer.BlockCopy(bytes, i, Filename, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + TaskID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)(Serial % 256); + bytes[i++] = (byte)((Serial >> 8) % 256); + bytes[i++] = (byte)Filename.Length; + Buffer.BlockCopy(Filename, 0, bytes, i, Filename.Length); i += Filename.Length; + } + + } + + public override int Length + { + get + { + int length = 10; + length += InventoryData.Length; + return length; + } + } + public InventoryDataBlock InventoryData; + + public ReplyTaskInventoryPacket() + { + HasVariableBlocks = false; + Type = PacketType.ReplyTaskInventory; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 290; + Header.Reliable = true; + Header.Zerocoded = true; + InventoryData = new InventoryDataBlock(); + } + + public ReplyTaskInventoryPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + InventoryData.FromBytes(bytes, ref i); + } + + public ReplyTaskInventoryPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + InventoryData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += InventoryData.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class DeRezObjectPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class AgentBlockBlock : PacketBlock + { + public UUID GroupID; + public byte Destination; + public UUID DestinationID; + public UUID TransactionID; + public byte PacketCount; + public byte PacketNumber; + + public override int Length + { + get + { + return 51; + } + } + + public AgentBlockBlock() { } + public AgentBlockBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + GroupID.FromBytes(bytes, i); i += 16; + Destination = (byte)bytes[i++]; + DestinationID.FromBytes(bytes, i); i += 16; + TransactionID.FromBytes(bytes, i); i += 16; + PacketCount = (byte)bytes[i++]; + PacketNumber = (byte)bytes[i++]; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + GroupID.ToBytes(bytes, i); i += 16; + bytes[i++] = Destination; + DestinationID.ToBytes(bytes, i); i += 16; + TransactionID.ToBytes(bytes, i); i += 16; + bytes[i++] = PacketCount; + bytes[i++] = PacketNumber; + } + + } + + /// + public sealed class ObjectDataBlock : PacketBlock + { + public uint ObjectLocalID; + + public override int Length + { + get + { + return 4; + } + } + + public ObjectDataBlock() { } + public ObjectDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + ObjectLocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UIntToBytes(ObjectLocalID, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentData.Length; + length += AgentBlock.Length; + for (int j = 0; j < ObjectData.Length; j++) + length += ObjectData[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public AgentBlockBlock AgentBlock; + public ObjectDataBlock[] ObjectData; + + public DeRezObjectPacket() + { + HasVariableBlocks = true; + Type = PacketType.DeRezObject; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 291; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + AgentBlock = new AgentBlockBlock(); + ObjectData = null; + } + + public DeRezObjectPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + AgentBlock.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ObjectData == null || ObjectData.Length != -1) { + ObjectData = new ObjectDataBlock[count]; + for(int j = 0; j < count; j++) + { ObjectData[j] = new ObjectDataBlock(); } + } + for (int j = 0; j < count; j++) + { ObjectData[j].FromBytes(bytes, ref i); } + } + + public DeRezObjectPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + AgentBlock.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ObjectData == null || ObjectData.Length != count) { + ObjectData = new ObjectDataBlock[count]; + for(int j = 0; j < count; j++) + { ObjectData[j] = new ObjectDataBlock(); } + } + for (int j = 0; j < count; j++) + { ObjectData[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += AgentBlock.Length; + length++; + for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } + if (Header.AckList != null && 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); + AgentBlock.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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + fixedLength += AgentBlock.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + AgentBlock.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int ObjectDataStart = 0; + do + { + int variableLength = 0; + int ObjectDataCount = 0; + + i = ObjectDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < ObjectData.Length) { + int blockLength = ObjectData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ObjectDataStart) { + variableLength += blockLength; + ++ObjectDataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)ObjectDataCount; + for (i = ObjectDataStart; i < ObjectDataStart + ObjectDataCount; i++) { ObjectData[i].ToBytes(packet, ref length); } + ObjectDataStart += ObjectDataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + ObjectDataStart < ObjectData.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class DeRezAckPacket : Packet + { + /// + public sealed class TransactionDataBlock : PacketBlock + { + public UUID TransactionID; + public bool Success; + + public override int Length + { + get + { + return 17; + } + } + + public TransactionDataBlock() { } + public TransactionDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + TransactionID.FromBytes(bytes, i); i += 16; + Success = (bytes[i++] != 0) ? (bool)true : (bool)false; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + TransactionID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)((Success) ? 1 : 0); + } + + } + + public override int Length + { + get + { + int length = 10; + length += TransactionData.Length; + return length; + } + } + public TransactionDataBlock TransactionData; + + public DeRezAckPacket() + { + HasVariableBlocks = false; + Type = PacketType.DeRezAck; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 292; + Header.Reliable = true; + TransactionData = new TransactionDataBlock(); + } + + public DeRezAckPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + TransactionData.FromBytes(bytes, ref i); + } + + public DeRezAckPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + TransactionData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += TransactionData.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class RezObjectPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + public UUID GroupID; + + public override int Length + { + get + { + return 48; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + GroupID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + GroupID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class RezDataBlock : PacketBlock + { + public UUID FromTaskID; + public byte BypassRaycast; + public Vector3 RayStart; + public Vector3 RayEnd; + public UUID RayTargetID; + public bool RayEndIsIntersection; + public bool RezSelected; + public bool RemoveItem; + public uint ItemFlags; + public uint GroupMask; + public uint EveryoneMask; + public uint NextOwnerMask; + + public override int Length + { + get + { + return 76; + } + } + + public RezDataBlock() { } + public RezDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + FromTaskID.FromBytes(bytes, i); i += 16; + BypassRaycast = (byte)bytes[i++]; + RayStart.FromBytes(bytes, i); i += 12; + RayEnd.FromBytes(bytes, i); i += 12; + RayTargetID.FromBytes(bytes, i); i += 16; + RayEndIsIntersection = (bytes[i++] != 0) ? (bool)true : (bool)false; + RezSelected = (bytes[i++] != 0) ? (bool)true : (bool)false; + RemoveItem = (bytes[i++] != 0) ? (bool)true : (bool)false; + ItemFlags = (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)); + 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)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + FromTaskID.ToBytes(bytes, i); i += 16; + bytes[i++] = BypassRaycast; + RayStart.ToBytes(bytes, i); i += 12; + RayEnd.ToBytes(bytes, i); i += 12; + RayTargetID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)((RayEndIsIntersection) ? 1 : 0); + bytes[i++] = (byte)((RezSelected) ? 1 : 0); + bytes[i++] = (byte)((RemoveItem) ? 1 : 0); + Utils.UIntToBytes(ItemFlags, bytes, i); i += 4; + Utils.UIntToBytes(GroupMask, bytes, i); i += 4; + Utils.UIntToBytes(EveryoneMask, bytes, i); i += 4; + Utils.UIntToBytes(NextOwnerMask, bytes, i); i += 4; + } + + } + + /// + public sealed class InventoryDataBlock : PacketBlock + { + public UUID ItemID; + public UUID FolderID; + public UUID CreatorID; + public UUID OwnerID; + public UUID GroupID; + public uint BaseMask; + public uint OwnerMask; + public uint GroupMask; + public uint EveryoneMask; + public uint NextOwnerMask; + public bool GroupOwned; + public UUID TransactionID; + public sbyte Type; + public sbyte InvType; + public uint Flags; + public byte SaleType; + public int SalePrice; + public byte[] Name; + public byte[] Description; + public int CreationDate; + public uint CRC; + + public override int Length + { + get + { + int length = 138; + if (Name != null) { length += Name.Length; } + if (Description != null) { length += Description.Length; } + return length; + } + } + + public InventoryDataBlock() { } + public InventoryDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + ItemID.FromBytes(bytes, i); i += 16; + FolderID.FromBytes(bytes, i); i += 16; + CreatorID.FromBytes(bytes, i); i += 16; + OwnerID.FromBytes(bytes, i); i += 16; + GroupID.FromBytes(bytes, i); i += 16; + BaseMask = (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)); + GroupMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + 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)); + GroupOwned = (bytes[i++] != 0) ? (bool)true : (bool)false; + TransactionID.FromBytes(bytes, i); i += 16; + Type = (sbyte)bytes[i++]; + InvType = (sbyte)bytes[i++]; + Flags = (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)); + length = bytes[i++]; + Name = new byte[length]; + Buffer.BlockCopy(bytes, i, Name, 0, length); i += length; + length = bytes[i++]; + Description = new byte[length]; + Buffer.BlockCopy(bytes, i, Description, 0, length); i += length; + CreationDate = (int)(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(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + ItemID.ToBytes(bytes, i); i += 16; + FolderID.ToBytes(bytes, i); i += 16; + CreatorID.ToBytes(bytes, i); i += 16; + OwnerID.ToBytes(bytes, i); i += 16; + GroupID.ToBytes(bytes, i); i += 16; + Utils.UIntToBytes(BaseMask, bytes, i); i += 4; + Utils.UIntToBytes(OwnerMask, bytes, i); i += 4; + Utils.UIntToBytes(GroupMask, bytes, i); i += 4; + Utils.UIntToBytes(EveryoneMask, bytes, i); i += 4; + Utils.UIntToBytes(NextOwnerMask, bytes, i); i += 4; + bytes[i++] = (byte)((GroupOwned) ? 1 : 0); + TransactionID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)Type; + bytes[i++] = (byte)InvType; + Utils.UIntToBytes(Flags, bytes, i); i += 4; + bytes[i++] = SaleType; + Utils.IntToBytes(SalePrice, bytes, i); i += 4; + bytes[i++] = (byte)Name.Length; + Buffer.BlockCopy(Name, 0, bytes, i, Name.Length); i += Name.Length; + bytes[i++] = (byte)Description.Length; + Buffer.BlockCopy(Description, 0, bytes, i, Description.Length); i += Description.Length; + Utils.IntToBytes(CreationDate, bytes, i); i += 4; + Utils.UIntToBytes(CRC, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += RezData.Length; + length += InventoryData.Length; + return length; + } + } + public AgentDataBlock AgentData; + public RezDataBlock RezData; + public InventoryDataBlock InventoryData; + + public RezObjectPacket() + { + HasVariableBlocks = false; + Type = PacketType.RezObject; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 293; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + RezData = new RezDataBlock(); + InventoryData = new InventoryDataBlock(); + } + + public RezObjectPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + RezData.FromBytes(bytes, ref i); + InventoryData.FromBytes(bytes, ref i); + } + + public RezObjectPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + RezData.FromBytes(bytes, ref i); + InventoryData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += RezData.Length; + length += InventoryData.Length; + if (Header.AckList != null && 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); + RezData.ToBytes(bytes, ref i); + InventoryData.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class RezObjectFromNotecardPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + public UUID GroupID; + + public override int Length + { + get + { + return 48; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + GroupID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + GroupID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class RezDataBlock : PacketBlock + { + public UUID FromTaskID; + public byte BypassRaycast; + public Vector3 RayStart; + public Vector3 RayEnd; + public UUID RayTargetID; + public bool RayEndIsIntersection; + public bool RezSelected; + public bool RemoveItem; + public uint ItemFlags; + public uint GroupMask; + public uint EveryoneMask; + public uint NextOwnerMask; + + public override int Length + { + get + { + return 76; + } + } + + public RezDataBlock() { } + public RezDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + FromTaskID.FromBytes(bytes, i); i += 16; + BypassRaycast = (byte)bytes[i++]; + RayStart.FromBytes(bytes, i); i += 12; + RayEnd.FromBytes(bytes, i); i += 12; + RayTargetID.FromBytes(bytes, i); i += 16; + RayEndIsIntersection = (bytes[i++] != 0) ? (bool)true : (bool)false; + RezSelected = (bytes[i++] != 0) ? (bool)true : (bool)false; + RemoveItem = (bytes[i++] != 0) ? (bool)true : (bool)false; + ItemFlags = (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)); + 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)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + FromTaskID.ToBytes(bytes, i); i += 16; + bytes[i++] = BypassRaycast; + RayStart.ToBytes(bytes, i); i += 12; + RayEnd.ToBytes(bytes, i); i += 12; + RayTargetID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)((RayEndIsIntersection) ? 1 : 0); + bytes[i++] = (byte)((RezSelected) ? 1 : 0); + bytes[i++] = (byte)((RemoveItem) ? 1 : 0); + Utils.UIntToBytes(ItemFlags, bytes, i); i += 4; + Utils.UIntToBytes(GroupMask, bytes, i); i += 4; + Utils.UIntToBytes(EveryoneMask, bytes, i); i += 4; + Utils.UIntToBytes(NextOwnerMask, bytes, i); i += 4; + } + + } + + /// + public sealed class NotecardDataBlock : PacketBlock + { + public UUID NotecardItemID; + public UUID ObjectID; + + public override int Length + { + get + { + return 32; + } + } + + public NotecardDataBlock() { } + public NotecardDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + NotecardItemID.FromBytes(bytes, i); i += 16; + ObjectID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + NotecardItemID.ToBytes(bytes, i); i += 16; + ObjectID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class InventoryDataBlock : PacketBlock + { + public UUID ItemID; + + public override int Length + { + get + { + return 16; + } + } + + public InventoryDataBlock() { } + public InventoryDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + ItemID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + ItemID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentData.Length; + length += RezData.Length; + length += NotecardData.Length; + for (int j = 0; j < InventoryData.Length; j++) + length += InventoryData[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public RezDataBlock RezData; + public NotecardDataBlock NotecardData; + public InventoryDataBlock[] InventoryData; + + public RezObjectFromNotecardPacket() + { + HasVariableBlocks = true; + Type = PacketType.RezObjectFromNotecard; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 294; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + RezData = new RezDataBlock(); + NotecardData = new NotecardDataBlock(); + InventoryData = null; + } + + public RezObjectFromNotecardPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + RezData.FromBytes(bytes, ref i); + NotecardData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(InventoryData == null || InventoryData.Length != -1) { + InventoryData = new InventoryDataBlock[count]; + for(int j = 0; j < count; j++) + { InventoryData[j] = new InventoryDataBlock(); } + } + for (int j = 0; j < count; j++) + { InventoryData[j].FromBytes(bytes, ref i); } + } + + public RezObjectFromNotecardPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + RezData.FromBytes(bytes, ref i); + NotecardData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(InventoryData == null || InventoryData.Length != count) { + InventoryData = new InventoryDataBlock[count]; + for(int j = 0; j < count; j++) + { InventoryData[j] = new InventoryDataBlock(); } + } + for (int j = 0; j < count; j++) + { InventoryData[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += RezData.Length; + length += NotecardData.Length; + length++; + for (int j = 0; j < InventoryData.Length; j++) { length += InventoryData[j].Length; } + if (Header.AckList != null && 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); + RezData.ToBytes(bytes, ref i); + NotecardData.ToBytes(bytes, ref i); + bytes[i++] = (byte)InventoryData.Length; + for (int j = 0; j < InventoryData.Length; j++) { InventoryData[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + fixedLength += RezData.Length; + fixedLength += NotecardData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + RezData.ToBytes(fixedBytes, ref i); + NotecardData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int InventoryDataStart = 0; + do + { + int variableLength = 0; + int InventoryDataCount = 0; + + i = InventoryDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < InventoryData.Length) { + int blockLength = InventoryData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == InventoryDataStart) { + variableLength += blockLength; + ++InventoryDataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)InventoryDataCount; + for (i = InventoryDataStart; i < InventoryDataStart + InventoryDataCount; i++) { InventoryData[i].ToBytes(packet, ref length); } + InventoryDataStart += InventoryDataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + InventoryDataStart < InventoryData.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class AcceptFriendshipPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class TransactionBlockBlock : PacketBlock + { + public UUID TransactionID; + + public override int Length + { + get + { + return 16; + } + } + + public TransactionBlockBlock() { } + public TransactionBlockBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + TransactionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + TransactionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class FolderDataBlock : PacketBlock + { + public UUID FolderID; + + public override int Length + { + get + { + return 16; + } + } + + public FolderDataBlock() { } + public FolderDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + FolderID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + FolderID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentData.Length; + length += TransactionBlock.Length; + for (int j = 0; j < FolderData.Length; j++) + length += FolderData[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public TransactionBlockBlock TransactionBlock; + public FolderDataBlock[] FolderData; + + public AcceptFriendshipPacket() + { + HasVariableBlocks = true; + Type = PacketType.AcceptFriendship; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 297; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + TransactionBlock = new TransactionBlockBlock(); + FolderData = null; + } + + public AcceptFriendshipPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + TransactionBlock.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(FolderData == null || FolderData.Length != -1) { + FolderData = new FolderDataBlock[count]; + for(int j = 0; j < count; j++) + { FolderData[j] = new FolderDataBlock(); } + } + for (int j = 0; j < count; j++) + { FolderData[j].FromBytes(bytes, ref i); } + } + + public AcceptFriendshipPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + TransactionBlock.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(FolderData == null || FolderData.Length != count) { + FolderData = new FolderDataBlock[count]; + for(int j = 0; j < count; j++) + { FolderData[j] = new FolderDataBlock(); } + } + for (int j = 0; j < count; j++) + { FolderData[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += TransactionBlock.Length; + length++; + for (int j = 0; j < FolderData.Length; j++) { length += FolderData[j].Length; } + if (Header.AckList != null && 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); + TransactionBlock.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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + fixedLength += TransactionBlock.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + TransactionBlock.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int FolderDataStart = 0; + do + { + int variableLength = 0; + int FolderDataCount = 0; + + i = FolderDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < FolderData.Length) { + int blockLength = FolderData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == FolderDataStart) { + variableLength += blockLength; + ++FolderDataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)FolderDataCount; + for (i = FolderDataStart; i < FolderDataStart + FolderDataCount; i++) { FolderData[i].ToBytes(packet, ref length); } + FolderDataStart += FolderDataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + FolderDataStart < FolderData.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class DeclineFriendshipPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class TransactionBlockBlock : PacketBlock + { + public UUID TransactionID; + + public override int Length + { + get + { + return 16; + } + } + + public TransactionBlockBlock() { } + public TransactionBlockBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + TransactionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + TransactionID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += TransactionBlock.Length; + return length; + } + } + public AgentDataBlock AgentData; + public TransactionBlockBlock TransactionBlock; + + public DeclineFriendshipPacket() + { + HasVariableBlocks = false; + Type = PacketType.DeclineFriendship; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 298; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + TransactionBlock = new TransactionBlockBlock(); + } + + public DeclineFriendshipPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + TransactionBlock.FromBytes(bytes, ref i); + } + + public DeclineFriendshipPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + TransactionBlock.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += TransactionBlock.Length; + if (Header.AckList != null && 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); + TransactionBlock.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class TerminateFriendshipPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class ExBlockBlock : PacketBlock + { + public UUID OtherID; + + public override int Length + { + get + { + return 16; + } + } + + public ExBlockBlock() { } + public ExBlockBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + OtherID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + OtherID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += ExBlock.Length; + return length; + } + } + public AgentDataBlock AgentData; + public ExBlockBlock ExBlock; + + public TerminateFriendshipPacket() + { + HasVariableBlocks = false; + Type = PacketType.TerminateFriendship; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 300; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + ExBlock = new ExBlockBlock(); + } + + public TerminateFriendshipPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + ExBlock.FromBytes(bytes, ref i); + } + + public TerminateFriendshipPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + ExBlock.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += ExBlock.Length; + if (Header.AckList != null && 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); + ExBlock.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class OfferCallingCardPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class AgentBlockBlock : PacketBlock + { + public UUID DestID; + public UUID TransactionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentBlockBlock() { } + public AgentBlockBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + DestID.FromBytes(bytes, i); i += 16; + TransactionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + DestID.ToBytes(bytes, i); i += 16; + TransactionID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += AgentBlock.Length; + return length; + } + } + public AgentDataBlock AgentData; + public AgentBlockBlock AgentBlock; + + public OfferCallingCardPacket() + { + HasVariableBlocks = false; + Type = PacketType.OfferCallingCard; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 301; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + AgentBlock = new AgentBlockBlock(); + } + + public OfferCallingCardPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + AgentBlock.FromBytes(bytes, ref i); + } + + public OfferCallingCardPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + AgentBlock.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += AgentBlock.Length; + if (Header.AckList != null && 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); + AgentBlock.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class AcceptCallingCardPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class TransactionBlockBlock : PacketBlock + { + public UUID TransactionID; + + public override int Length + { + get + { + return 16; + } + } + + public TransactionBlockBlock() { } + public TransactionBlockBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + TransactionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + TransactionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class FolderDataBlock : PacketBlock + { + public UUID FolderID; + + public override int Length + { + get + { + return 16; + } + } + + public FolderDataBlock() { } + public FolderDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + FolderID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + FolderID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentData.Length; + length += TransactionBlock.Length; + for (int j = 0; j < FolderData.Length; j++) + length += FolderData[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public TransactionBlockBlock TransactionBlock; + public FolderDataBlock[] FolderData; + + public AcceptCallingCardPacket() + { + HasVariableBlocks = true; + Type = PacketType.AcceptCallingCard; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 302; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + TransactionBlock = new TransactionBlockBlock(); + FolderData = null; + } + + public AcceptCallingCardPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + TransactionBlock.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(FolderData == null || FolderData.Length != -1) { + FolderData = new FolderDataBlock[count]; + for(int j = 0; j < count; j++) + { FolderData[j] = new FolderDataBlock(); } + } + for (int j = 0; j < count; j++) + { FolderData[j].FromBytes(bytes, ref i); } + } + + public AcceptCallingCardPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + TransactionBlock.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(FolderData == null || FolderData.Length != count) { + FolderData = new FolderDataBlock[count]; + for(int j = 0; j < count; j++) + { FolderData[j] = new FolderDataBlock(); } + } + for (int j = 0; j < count; j++) + { FolderData[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += TransactionBlock.Length; + length++; + for (int j = 0; j < FolderData.Length; j++) { length += FolderData[j].Length; } + if (Header.AckList != null && 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); + TransactionBlock.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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + fixedLength += TransactionBlock.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + TransactionBlock.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int FolderDataStart = 0; + do + { + int variableLength = 0; + int FolderDataCount = 0; + + i = FolderDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < FolderData.Length) { + int blockLength = FolderData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == FolderDataStart) { + variableLength += blockLength; + ++FolderDataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)FolderDataCount; + for (i = FolderDataStart; i < FolderDataStart + FolderDataCount; i++) { FolderData[i].ToBytes(packet, ref length); } + FolderDataStart += FolderDataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + FolderDataStart < FolderData.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class DeclineCallingCardPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class TransactionBlockBlock : PacketBlock + { + public UUID TransactionID; + + public override int Length + { + get + { + return 16; + } + } + + public TransactionBlockBlock() { } + public TransactionBlockBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + TransactionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + TransactionID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += TransactionBlock.Length; + return length; + } + } + public AgentDataBlock AgentData; + public TransactionBlockBlock TransactionBlock; + + public DeclineCallingCardPacket() + { + HasVariableBlocks = false; + Type = PacketType.DeclineCallingCard; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 303; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + TransactionBlock = new TransactionBlockBlock(); + } + + public DeclineCallingCardPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + TransactionBlock.FromBytes(bytes, ref i); + } + + public DeclineCallingCardPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + TransactionBlock.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += TransactionBlock.Length; + if (Header.AckList != null && 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); + TransactionBlock.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class RezScriptPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + public UUID GroupID; + + public override int Length + { + get + { + return 48; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + GroupID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + GroupID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class UpdateBlockBlock : PacketBlock + { + public uint ObjectLocalID; + public bool Enabled; + + public override int Length + { + get + { + return 5; + } + } + + public UpdateBlockBlock() { } + public UpdateBlockBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + ObjectLocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + Enabled = (bytes[i++] != 0) ? (bool)true : (bool)false; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UIntToBytes(ObjectLocalID, bytes, i); i += 4; + bytes[i++] = (byte)((Enabled) ? 1 : 0); + } + + } + + /// + public sealed class InventoryBlockBlock : PacketBlock + { + public UUID ItemID; + public UUID FolderID; + public UUID CreatorID; + public UUID OwnerID; + public UUID GroupID; + public uint BaseMask; + public uint OwnerMask; + public uint GroupMask; + public uint EveryoneMask; + public uint NextOwnerMask; + public bool GroupOwned; + public UUID TransactionID; + public sbyte Type; + public sbyte InvType; + public uint Flags; + public byte SaleType; + public int SalePrice; + public byte[] Name; + public byte[] Description; + public int CreationDate; + public uint CRC; + + public override int Length + { + get + { + int length = 138; + if (Name != null) { length += Name.Length; } + if (Description != null) { length += Description.Length; } + return length; + } + } + + public InventoryBlockBlock() { } + public InventoryBlockBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + ItemID.FromBytes(bytes, i); i += 16; + FolderID.FromBytes(bytes, i); i += 16; + CreatorID.FromBytes(bytes, i); i += 16; + OwnerID.FromBytes(bytes, i); i += 16; + GroupID.FromBytes(bytes, i); i += 16; + BaseMask = (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)); + GroupMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + 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)); + GroupOwned = (bytes[i++] != 0) ? (bool)true : (bool)false; + TransactionID.FromBytes(bytes, i); i += 16; + Type = (sbyte)bytes[i++]; + InvType = (sbyte)bytes[i++]; + Flags = (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)); + length = bytes[i++]; + Name = new byte[length]; + Buffer.BlockCopy(bytes, i, Name, 0, length); i += length; + length = bytes[i++]; + Description = new byte[length]; + Buffer.BlockCopy(bytes, i, Description, 0, length); i += length; + CreationDate = (int)(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(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + ItemID.ToBytes(bytes, i); i += 16; + FolderID.ToBytes(bytes, i); i += 16; + CreatorID.ToBytes(bytes, i); i += 16; + OwnerID.ToBytes(bytes, i); i += 16; + GroupID.ToBytes(bytes, i); i += 16; + Utils.UIntToBytes(BaseMask, bytes, i); i += 4; + Utils.UIntToBytes(OwnerMask, bytes, i); i += 4; + Utils.UIntToBytes(GroupMask, bytes, i); i += 4; + Utils.UIntToBytes(EveryoneMask, bytes, i); i += 4; + Utils.UIntToBytes(NextOwnerMask, bytes, i); i += 4; + bytes[i++] = (byte)((GroupOwned) ? 1 : 0); + TransactionID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)Type; + bytes[i++] = (byte)InvType; + Utils.UIntToBytes(Flags, bytes, i); i += 4; + bytes[i++] = SaleType; + Utils.IntToBytes(SalePrice, bytes, i); i += 4; + bytes[i++] = (byte)Name.Length; + Buffer.BlockCopy(Name, 0, bytes, i, Name.Length); i += Name.Length; + bytes[i++] = (byte)Description.Length; + Buffer.BlockCopy(Description, 0, bytes, i, Description.Length); i += Description.Length; + Utils.IntToBytes(CreationDate, bytes, i); i += 4; + Utils.UIntToBytes(CRC, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += UpdateBlock.Length; + length += InventoryBlock.Length; + return length; + } + } + public AgentDataBlock AgentData; + public UpdateBlockBlock UpdateBlock; + public InventoryBlockBlock InventoryBlock; + + public RezScriptPacket() + { + HasVariableBlocks = false; + Type = PacketType.RezScript; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 304; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + UpdateBlock = new UpdateBlockBlock(); + InventoryBlock = new InventoryBlockBlock(); + } + + public RezScriptPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + UpdateBlock.FromBytes(bytes, ref i); + InventoryBlock.FromBytes(bytes, ref i); + } + + public RezScriptPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + UpdateBlock.FromBytes(bytes, ref i); + InventoryBlock.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += UpdateBlock.Length; + length += InventoryBlock.Length; + if (Header.AckList != null && 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); + UpdateBlock.ToBytes(bytes, ref i); + InventoryBlock.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class CreateInventoryItemPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class InventoryBlockBlock : PacketBlock + { + public uint CallbackID; + public UUID FolderID; + public UUID TransactionID; + public uint NextOwnerMask; + public sbyte Type; + public sbyte InvType; + public byte WearableType; + public byte[] Name; + public byte[] Description; + + public override int Length + { + get + { + int length = 45; + if (Name != null) { length += Name.Length; } + if (Description != null) { length += Description.Length; } + return length; + } + } + + public InventoryBlockBlock() { } + public InventoryBlockBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + CallbackID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + FolderID.FromBytes(bytes, i); i += 16; + TransactionID.FromBytes(bytes, i); i += 16; + NextOwnerMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + Type = (sbyte)bytes[i++]; + InvType = (sbyte)bytes[i++]; + WearableType = (byte)bytes[i++]; + length = bytes[i++]; + Name = new byte[length]; + Buffer.BlockCopy(bytes, i, Name, 0, length); i += length; + length = bytes[i++]; + Description = new byte[length]; + Buffer.BlockCopy(bytes, i, Description, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UIntToBytes(CallbackID, bytes, i); i += 4; + FolderID.ToBytes(bytes, i); i += 16; + TransactionID.ToBytes(bytes, i); i += 16; + Utils.UIntToBytes(NextOwnerMask, bytes, i); i += 4; + bytes[i++] = (byte)Type; + bytes[i++] = (byte)InvType; + bytes[i++] = WearableType; + bytes[i++] = (byte)Name.Length; + Buffer.BlockCopy(Name, 0, bytes, i, Name.Length); i += Name.Length; + bytes[i++] = (byte)Description.Length; + Buffer.BlockCopy(Description, 0, bytes, i, Description.Length); i += Description.Length; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += InventoryBlock.Length; + return length; + } + } + public AgentDataBlock AgentData; + public InventoryBlockBlock InventoryBlock; + + public CreateInventoryItemPacket() + { + HasVariableBlocks = false; + Type = PacketType.CreateInventoryItem; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 305; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + InventoryBlock = new InventoryBlockBlock(); + } + + public CreateInventoryItemPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + InventoryBlock.FromBytes(bytes, ref i); + } + + public CreateInventoryItemPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + InventoryBlock.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += InventoryBlock.Length; + if (Header.AckList != null && 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); + InventoryBlock.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class CreateLandmarkForEventPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class EventDataBlock : PacketBlock + { + public uint EventID; + + public override int Length + { + get + { + return 4; + } + } + + public EventDataBlock() { } + public EventDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + EventID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UIntToBytes(EventID, bytes, i); i += 4; + } + + } + + /// + public sealed class InventoryBlockBlock : PacketBlock + { + public UUID FolderID; + public byte[] Name; + + public override int Length + { + get + { + int length = 17; + if (Name != null) { length += Name.Length; } + return length; + } + } + + public InventoryBlockBlock() { } + public InventoryBlockBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + FolderID.FromBytes(bytes, i); i += 16; + length = bytes[i++]; + Name = new byte[length]; + Buffer.BlockCopy(bytes, i, Name, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + FolderID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)Name.Length; + Buffer.BlockCopy(Name, 0, bytes, i, Name.Length); i += Name.Length; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += EventData.Length; + length += InventoryBlock.Length; + return length; + } + } + public AgentDataBlock AgentData; + public EventDataBlock EventData; + public InventoryBlockBlock InventoryBlock; + + public CreateLandmarkForEventPacket() + { + HasVariableBlocks = false; + Type = PacketType.CreateLandmarkForEvent; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 306; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + EventData = new EventDataBlock(); + InventoryBlock = new InventoryBlockBlock(); + } + + public CreateLandmarkForEventPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + EventData.FromBytes(bytes, ref i); + InventoryBlock.FromBytes(bytes, ref i); + } + + public CreateLandmarkForEventPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + EventData.FromBytes(bytes, ref i); + InventoryBlock.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += EventData.Length; + length += InventoryBlock.Length; + if (Header.AckList != null && 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); + EventData.ToBytes(bytes, ref i); + InventoryBlock.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class RegionHandleRequestPacket : Packet + { + /// + public sealed class RequestBlockBlock : PacketBlock + { + public UUID RegionID; + + public override int Length + { + get + { + return 16; + } + } + + public RequestBlockBlock() { } + public RequestBlockBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + RegionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + RegionID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 10; + length += RequestBlock.Length; + return length; + } + } + public RequestBlockBlock RequestBlock; + + public RegionHandleRequestPacket() + { + HasVariableBlocks = false; + Type = PacketType.RegionHandleRequest; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 309; + Header.Reliable = true; + RequestBlock = new RequestBlockBlock(); + } + + public RegionHandleRequestPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + RequestBlock.FromBytes(bytes, ref i); + } + + public RegionHandleRequestPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + RequestBlock.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += RequestBlock.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class RegionIDAndHandleReplyPacket : Packet + { + /// + public sealed class ReplyBlockBlock : PacketBlock + { + public UUID RegionID; + public ulong RegionHandle; + + public override int Length + { + get + { + return 24; + } + } + + public ReplyBlockBlock() { } + public ReplyBlockBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + RegionID.FromBytes(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(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + RegionID.ToBytes(bytes, i); i += 16; + Utils.UInt64ToBytes(RegionHandle, bytes, i); i += 8; + } + + } + + public override int Length + { + get + { + int length = 10; + length += ReplyBlock.Length; + return length; + } + } + public ReplyBlockBlock ReplyBlock; + + public RegionIDAndHandleReplyPacket() + { + HasVariableBlocks = false; + Type = PacketType.RegionIDAndHandleReply; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 310; + Header.Reliable = true; + ReplyBlock = new ReplyBlockBlock(); + } + + public RegionIDAndHandleReplyPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + ReplyBlock.FromBytes(bytes, ref i); + } + + public RegionIDAndHandleReplyPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + ReplyBlock.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += ReplyBlock.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class MoneyTransferRequestPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class MoneyDataBlock : PacketBlock + { + public UUID SourceID; + public UUID DestID; + public byte Flags; + public int Amount; + public byte AggregatePermNextOwner; + public byte AggregatePermInventory; + public int TransactionType; + public byte[] Description; + + public override int Length + { + get + { + int length = 44; + if (Description != null) { length += Description.Length; } + return length; + } + } + + public MoneyDataBlock() { } + public MoneyDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + SourceID.FromBytes(bytes, i); i += 16; + DestID.FromBytes(bytes, i); i += 16; + Flags = (byte)bytes[i++]; + Amount = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + AggregatePermNextOwner = (byte)bytes[i++]; + AggregatePermInventory = (byte)bytes[i++]; + TransactionType = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + length = bytes[i++]; + Description = new byte[length]; + Buffer.BlockCopy(bytes, i, Description, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + SourceID.ToBytes(bytes, i); i += 16; + DestID.ToBytes(bytes, i); i += 16; + bytes[i++] = Flags; + Utils.IntToBytes(Amount, bytes, i); i += 4; + bytes[i++] = AggregatePermNextOwner; + bytes[i++] = AggregatePermInventory; + Utils.IntToBytes(TransactionType, bytes, i); i += 4; + bytes[i++] = (byte)Description.Length; + Buffer.BlockCopy(Description, 0, bytes, i, Description.Length); i += Description.Length; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += MoneyData.Length; + return length; + } + } + public AgentDataBlock AgentData; + public MoneyDataBlock MoneyData; + + public MoneyTransferRequestPacket() + { + HasVariableBlocks = false; + Type = PacketType.MoneyTransferRequest; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 311; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + MoneyData = new MoneyDataBlock(); + } + + public MoneyTransferRequestPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + MoneyData.FromBytes(bytes, ref i); + } + + public MoneyTransferRequestPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + MoneyData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += MoneyData.Length; + if (Header.AckList != null && 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); + MoneyData.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class MoneyBalanceRequestPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class MoneyDataBlock : PacketBlock + { + public UUID TransactionID; + + public override int Length + { + get + { + return 16; + } + } + + public MoneyDataBlock() { } + public MoneyDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + TransactionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + TransactionID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += MoneyData.Length; + return length; + } + } + public AgentDataBlock AgentData; + public MoneyDataBlock MoneyData; + + public MoneyBalanceRequestPacket() + { + HasVariableBlocks = false; + Type = PacketType.MoneyBalanceRequest; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 313; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + MoneyData = new MoneyDataBlock(); + } + + public MoneyBalanceRequestPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + MoneyData.FromBytes(bytes, ref i); + } + + public MoneyBalanceRequestPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + MoneyData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += MoneyData.Length; + if (Header.AckList != null && 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); + MoneyData.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class MoneyBalanceReplyPacket : Packet + { + /// + public sealed class MoneyDataBlock : PacketBlock + { + public UUID AgentID; + public UUID TransactionID; + public bool TransactionSuccess; + public int MoneyBalance; + public int SquareMetersCredit; + public int SquareMetersCommitted; + public byte[] Description; + + public override int Length + { + get + { + int length = 46; + if (Description != null) { length += Description.Length; } + return length; + } + } + + public MoneyDataBlock() { } + public MoneyDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + AgentID.FromBytes(bytes, i); i += 16; + TransactionID.FromBytes(bytes, i); i += 16; + TransactionSuccess = (bytes[i++] != 0) ? (bool)true : (bool)false; + 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)); + SquareMetersCommitted = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + length = bytes[i++]; + Description = new byte[length]; + Buffer.BlockCopy(bytes, i, Description, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + TransactionID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)((TransactionSuccess) ? 1 : 0); + Utils.IntToBytes(MoneyBalance, bytes, i); i += 4; + Utils.IntToBytes(SquareMetersCredit, bytes, i); i += 4; + Utils.IntToBytes(SquareMetersCommitted, bytes, i); i += 4; + bytes[i++] = (byte)Description.Length; + Buffer.BlockCopy(Description, 0, bytes, i, Description.Length); i += Description.Length; + } + + } + + /// + public sealed class TransactionInfoBlock : PacketBlock + { + public int TransactionType; + public UUID SourceID; + public bool IsSourceGroup; + public UUID DestID; + public bool IsDestGroup; + public int Amount; + public byte[] ItemDescription; + + public override int Length + { + get + { + int length = 43; + if (ItemDescription != null) { length += ItemDescription.Length; } + return length; + } + } + + public TransactionInfoBlock() { } + public TransactionInfoBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + TransactionType = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + SourceID.FromBytes(bytes, i); i += 16; + IsSourceGroup = (bytes[i++] != 0) ? (bool)true : (bool)false; + DestID.FromBytes(bytes, i); i += 16; + IsDestGroup = (bytes[i++] != 0) ? (bool)true : (bool)false; + Amount = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + length = bytes[i++]; + ItemDescription = new byte[length]; + Buffer.BlockCopy(bytes, i, ItemDescription, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.IntToBytes(TransactionType, bytes, i); i += 4; + SourceID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)((IsSourceGroup) ? 1 : 0); + DestID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)((IsDestGroup) ? 1 : 0); + Utils.IntToBytes(Amount, bytes, i); i += 4; + bytes[i++] = (byte)ItemDescription.Length; + Buffer.BlockCopy(ItemDescription, 0, bytes, i, ItemDescription.Length); i += ItemDescription.Length; + } + + } + + public override int Length + { + get + { + int length = 10; + length += MoneyData.Length; + length += TransactionInfo.Length; + return length; + } + } + public MoneyDataBlock MoneyData; + public TransactionInfoBlock TransactionInfo; + + public MoneyBalanceReplyPacket() + { + HasVariableBlocks = false; + Type = PacketType.MoneyBalanceReply; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 314; + Header.Reliable = true; + Header.Zerocoded = true; + MoneyData = new MoneyDataBlock(); + TransactionInfo = new TransactionInfoBlock(); + } + + public MoneyBalanceReplyPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + MoneyData.FromBytes(bytes, ref i); + TransactionInfo.FromBytes(bytes, ref i); + } + + public MoneyBalanceReplyPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + MoneyData.FromBytes(bytes, ref i); + TransactionInfo.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += MoneyData.Length; + length += TransactionInfo.Length; + if (Header.AckList != null && 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); + TransactionInfo.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class RoutedMoneyBalanceReplyPacket : Packet + { + /// + public sealed class TargetBlockBlock : PacketBlock + { + public uint TargetIP; + public ushort TargetPort; + + public override int Length + { + get + { + return 6; + } + } + + public TargetBlockBlock() { } + public TargetBlockBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(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(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UIntToBytes(TargetIP, bytes, i); i += 4; + bytes[i++] = (byte)((TargetPort >> 8) % 256); + bytes[i++] = (byte)(TargetPort % 256); + } + + } + + /// + public sealed class MoneyDataBlock : PacketBlock + { + public UUID AgentID; + public UUID TransactionID; + public bool TransactionSuccess; + public int MoneyBalance; + public int SquareMetersCredit; + public int SquareMetersCommitted; + public byte[] Description; + + public override int Length + { + get + { + int length = 46; + if (Description != null) { length += Description.Length; } + return length; + } + } + + public MoneyDataBlock() { } + public MoneyDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + AgentID.FromBytes(bytes, i); i += 16; + TransactionID.FromBytes(bytes, i); i += 16; + TransactionSuccess = (bytes[i++] != 0) ? (bool)true : (bool)false; + 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)); + SquareMetersCommitted = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + length = bytes[i++]; + Description = new byte[length]; + Buffer.BlockCopy(bytes, i, Description, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + TransactionID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)((TransactionSuccess) ? 1 : 0); + Utils.IntToBytes(MoneyBalance, bytes, i); i += 4; + Utils.IntToBytes(SquareMetersCredit, bytes, i); i += 4; + Utils.IntToBytes(SquareMetersCommitted, bytes, i); i += 4; + bytes[i++] = (byte)Description.Length; + Buffer.BlockCopy(Description, 0, bytes, i, Description.Length); i += Description.Length; + } + + } + + /// + public sealed class TransactionInfoBlock : PacketBlock + { + public int TransactionType; + public UUID SourceID; + public bool IsSourceGroup; + public UUID DestID; + public bool IsDestGroup; + public int Amount; + public byte[] ItemDescription; + + public override int Length + { + get + { + int length = 43; + if (ItemDescription != null) { length += ItemDescription.Length; } + return length; + } + } + + public TransactionInfoBlock() { } + public TransactionInfoBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + TransactionType = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + SourceID.FromBytes(bytes, i); i += 16; + IsSourceGroup = (bytes[i++] != 0) ? (bool)true : (bool)false; + DestID.FromBytes(bytes, i); i += 16; + IsDestGroup = (bytes[i++] != 0) ? (bool)true : (bool)false; + Amount = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + length = bytes[i++]; + ItemDescription = new byte[length]; + Buffer.BlockCopy(bytes, i, ItemDescription, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.IntToBytes(TransactionType, bytes, i); i += 4; + SourceID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)((IsSourceGroup) ? 1 : 0); + DestID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)((IsDestGroup) ? 1 : 0); + Utils.IntToBytes(Amount, bytes, i); i += 4; + bytes[i++] = (byte)ItemDescription.Length; + Buffer.BlockCopy(ItemDescription, 0, bytes, i, ItemDescription.Length); i += ItemDescription.Length; + } + + } + + public override int Length + { + get + { + int length = 10; + length += TargetBlock.Length; + length += MoneyData.Length; + length += TransactionInfo.Length; + return length; + } + } + public TargetBlockBlock TargetBlock; + public MoneyDataBlock MoneyData; + public TransactionInfoBlock TransactionInfo; + + public RoutedMoneyBalanceReplyPacket() + { + HasVariableBlocks = false; + Type = PacketType.RoutedMoneyBalanceReply; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 315; + Header.Reliable = true; + Header.Zerocoded = true; + TargetBlock = new TargetBlockBlock(); + MoneyData = new MoneyDataBlock(); + TransactionInfo = new TransactionInfoBlock(); + } + + public RoutedMoneyBalanceReplyPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + TargetBlock.FromBytes(bytes, ref i); + MoneyData.FromBytes(bytes, ref i); + TransactionInfo.FromBytes(bytes, ref i); + } + + public RoutedMoneyBalanceReplyPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + TargetBlock.FromBytes(bytes, ref i); + MoneyData.FromBytes(bytes, ref i); + TransactionInfo.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += TargetBlock.Length; + length += MoneyData.Length; + length += TransactionInfo.Length; + if (Header.AckList != null && 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); + TransactionInfo.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class ActivateGesturesPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + public uint Flags; + + public override int Length + { + get + { + return 36; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + Flags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + Utils.UIntToBytes(Flags, bytes, i); i += 4; + } + + } + + /// + public sealed class DataBlock : PacketBlock + { + public UUID ItemID; + public UUID AssetID; + public uint GestureFlags; + + public override int Length + { + get + { + return 36; + } + } + + public DataBlock() { } + public DataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + ItemID.FromBytes(bytes, i); i += 16; + AssetID.FromBytes(bytes, i); i += 16; + GestureFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + ItemID.ToBytes(bytes, i); i += 16; + AssetID.ToBytes(bytes, i); i += 16; + Utils.UIntToBytes(GestureFlags, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentData.Length; + for (int j = 0; j < Data.Length; j++) + length += Data[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public DataBlock[] Data; + + public ActivateGesturesPacket() + { + HasVariableBlocks = true; + Type = PacketType.ActivateGestures; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 316; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + Data = null; + } + + public ActivateGesturesPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(Data == null || Data.Length != -1) { + Data = new DataBlock[count]; + for(int j = 0; j < count; j++) + { Data[j] = new DataBlock(); } + } + for (int j = 0; j < count; j++) + { Data[j].FromBytes(bytes, ref i); } + } + + public ActivateGesturesPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(Data == null || Data.Length != count) { + Data = new DataBlock[count]; + for(int j = 0; j < count; j++) + { Data[j] = new DataBlock(); } + } + for (int j = 0; j < count; j++) + { Data[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length++; + for (int j = 0; j < Data.Length; j++) { length += Data[j].Length; } + if (Header.AckList != null && 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)Data.Length; + for (int j = 0; j < Data.Length; j++) { Data[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int DataStart = 0; + do + { + int variableLength = 0; + int DataCount = 0; + + i = DataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < Data.Length) { + int blockLength = Data[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == DataStart) { + variableLength += blockLength; + ++DataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)DataCount; + for (i = DataStart; i < DataStart + DataCount; i++) { Data[i].ToBytes(packet, ref length); } + DataStart += DataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + DataStart < Data.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class DeactivateGesturesPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + public uint Flags; + + public override int Length + { + get + { + return 36; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + Flags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + Utils.UIntToBytes(Flags, bytes, i); i += 4; + } + + } + + /// + public sealed class DataBlock : PacketBlock + { + public UUID ItemID; + public uint GestureFlags; + + public override int Length + { + get + { + return 20; + } + } + + public DataBlock() { } + public DataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + ItemID.FromBytes(bytes, i); i += 16; + GestureFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + ItemID.ToBytes(bytes, i); i += 16; + Utils.UIntToBytes(GestureFlags, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentData.Length; + for (int j = 0; j < Data.Length; j++) + length += Data[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public DataBlock[] Data; + + public DeactivateGesturesPacket() + { + HasVariableBlocks = true; + Type = PacketType.DeactivateGestures; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 317; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + Data = null; + } + + public DeactivateGesturesPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(Data == null || Data.Length != -1) { + Data = new DataBlock[count]; + for(int j = 0; j < count; j++) + { Data[j] = new DataBlock(); } + } + for (int j = 0; j < count; j++) + { Data[j].FromBytes(bytes, ref i); } + } + + public DeactivateGesturesPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(Data == null || Data.Length != count) { + Data = new DataBlock[count]; + for(int j = 0; j < count; j++) + { Data[j] = new DataBlock(); } + } + for (int j = 0; j < count; j++) + { Data[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length++; + for (int j = 0; j < Data.Length; j++) { length += Data[j].Length; } + if (Header.AckList != null && 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)Data.Length; + for (int j = 0; j < Data.Length; j++) { Data[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int DataStart = 0; + do + { + int variableLength = 0; + int DataCount = 0; + + i = DataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < Data.Length) { + int blockLength = Data[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == DataStart) { + variableLength += blockLength; + ++DataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)DataCount; + for (i = DataStart; i < DataStart + DataCount; i++) { Data[i].ToBytes(packet, ref length); } + DataStart += DataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + DataStart < Data.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class MuteListUpdatePacket : Packet + { + /// + public sealed class MuteDataBlock : PacketBlock + { + public UUID AgentID; + public byte[] Filename; + + public override int Length + { + get + { + int length = 17; + if (Filename != null) { length += Filename.Length; } + return length; + } + } + + public MuteDataBlock() { } + public MuteDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + AgentID.FromBytes(bytes, i); i += 16; + length = bytes[i++]; + Filename = new byte[length]; + Buffer.BlockCopy(bytes, i, Filename, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)Filename.Length; + Buffer.BlockCopy(Filename, 0, bytes, i, Filename.Length); i += Filename.Length; + } + + } + + public override int Length + { + get + { + int length = 10; + length += MuteData.Length; + return length; + } + } + public MuteDataBlock MuteData; + + public MuteListUpdatePacket() + { + HasVariableBlocks = false; + Type = PacketType.MuteListUpdate; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 318; + Header.Reliable = true; + MuteData = new MuteDataBlock(); + } + + public MuteListUpdatePacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + MuteData.FromBytes(bytes, ref i); + } + + public MuteListUpdatePacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + MuteData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += MuteData.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class UseCachedMuteListPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + + public override int Length + { + get + { + return 16; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + return length; + } + } + public AgentDataBlock AgentData; + + public UseCachedMuteListPacket() + { + HasVariableBlocks = false; + Type = PacketType.UseCachedMuteList; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 319; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + } + + public UseCachedMuteListPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + } + + public UseCachedMuteListPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class GrantUserRightsPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class RightsBlock : PacketBlock + { + public UUID AgentRelated; + public int RelatedRights; + + public override int Length + { + get + { + return 20; + } + } + + public RightsBlock() { } + public RightsBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentRelated.FromBytes(bytes, i); i += 16; + RelatedRights = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentRelated.ToBytes(bytes, i); i += 16; + Utils.IntToBytes(RelatedRights, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentData.Length; + for (int j = 0; j < Rights.Length; j++) + length += Rights[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public RightsBlock[] Rights; + + public GrantUserRightsPacket() + { + HasVariableBlocks = true; + Type = PacketType.GrantUserRights; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 320; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + Rights = null; + } + + public GrantUserRightsPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(Rights == null || Rights.Length != -1) { + Rights = new RightsBlock[count]; + for(int j = 0; j < count; j++) + { Rights[j] = new RightsBlock(); } + } + for (int j = 0; j < count; j++) + { Rights[j].FromBytes(bytes, ref i); } + } + + public GrantUserRightsPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(Rights == null || Rights.Length != count) { + Rights = new RightsBlock[count]; + for(int j = 0; j < count; j++) + { Rights[j] = new RightsBlock(); } + } + for (int j = 0; j < count; j++) + { Rights[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length++; + for (int j = 0; j < Rights.Length; j++) { length += Rights[j].Length; } + if (Header.AckList != null && 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)Rights.Length; + for (int j = 0; j < Rights.Length; j++) { Rights[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int RightsStart = 0; + do + { + int variableLength = 0; + int RightsCount = 0; + + i = RightsStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < Rights.Length) { + int blockLength = Rights[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == RightsStart) { + variableLength += blockLength; + ++RightsCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)RightsCount; + for (i = RightsStart; i < RightsStart + RightsCount; i++) { Rights[i].ToBytes(packet, ref length); } + RightsStart += RightsCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + RightsStart < Rights.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class ChangeUserRightsPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + + public override int Length + { + get + { + return 16; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class RightsBlock : PacketBlock + { + public UUID AgentRelated; + public int RelatedRights; + + public override int Length + { + get + { + return 20; + } + } + + public RightsBlock() { } + public RightsBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentRelated.FromBytes(bytes, i); i += 16; + RelatedRights = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentRelated.ToBytes(bytes, i); i += 16; + Utils.IntToBytes(RelatedRights, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentData.Length; + for (int j = 0; j < Rights.Length; j++) + length += Rights[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public RightsBlock[] Rights; + + public ChangeUserRightsPacket() + { + HasVariableBlocks = true; + Type = PacketType.ChangeUserRights; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 321; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + Rights = null; + } + + public ChangeUserRightsPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(Rights == null || Rights.Length != -1) { + Rights = new RightsBlock[count]; + for(int j = 0; j < count; j++) + { Rights[j] = new RightsBlock(); } + } + for (int j = 0; j < count; j++) + { Rights[j].FromBytes(bytes, ref i); } + } + + public ChangeUserRightsPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(Rights == null || Rights.Length != count) { + Rights = new RightsBlock[count]; + for(int j = 0; j < count; j++) + { Rights[j] = new RightsBlock(); } + } + for (int j = 0; j < count; j++) + { Rights[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length++; + for (int j = 0; j < Rights.Length; j++) { length += Rights[j].Length; } + if (Header.AckList != null && 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)Rights.Length; + for (int j = 0; j < Rights.Length; j++) { Rights[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int RightsStart = 0; + do + { + int variableLength = 0; + int RightsCount = 0; + + i = RightsStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < Rights.Length) { + int blockLength = Rights[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == RightsStart) { + variableLength += blockLength; + ++RightsCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)RightsCount; + for (i = RightsStart; i < RightsStart + RightsCount; i++) { Rights[i].ToBytes(packet, ref length); } + RightsStart += RightsCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + RightsStart < Rights.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class OnlineNotificationPacket : Packet + { + /// + public sealed class AgentBlockBlock : PacketBlock + { + public UUID AgentID; + + public override int Length + { + get + { + return 16; + } + } + + public AgentBlockBlock() { } + public AgentBlockBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 11; + for (int j = 0; j < AgentBlock.Length; j++) + length += AgentBlock[j].Length; + return length; + } + } + public AgentBlockBlock[] AgentBlock; + + public OnlineNotificationPacket() + { + HasVariableBlocks = true; + Type = PacketType.OnlineNotification; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 322; + Header.Reliable = true; + AgentBlock = null; + } + + public OnlineNotificationPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + int count = (int)bytes[i++]; + if(AgentBlock == null || AgentBlock.Length != -1) { + AgentBlock = new AgentBlockBlock[count]; + for(int j = 0; j < count; j++) + { AgentBlock[j] = new AgentBlockBlock(); } + } + for (int j = 0; j < count; j++) + { AgentBlock[j].FromBytes(bytes, ref i); } + } + + public OnlineNotificationPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + int count = (int)bytes[i++]; + if(AgentBlock == null || AgentBlock.Length != count) { + AgentBlock = new AgentBlockBlock[count]; + for(int j = 0; j < count; j++) + { AgentBlock[j] = new AgentBlockBlock(); } + } + for (int j = 0; j < count; j++) + { AgentBlock[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length++; + for (int j = 0; j < AgentBlock.Length; j++) { length += AgentBlock[j].Length; } + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int AgentBlockStart = 0; + do + { + int variableLength = 0; + int AgentBlockCount = 0; + + i = AgentBlockStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < AgentBlock.Length) { + int blockLength = AgentBlock[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == AgentBlockStart) { + variableLength += blockLength; + ++AgentBlockCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)AgentBlockCount; + for (i = AgentBlockStart; i < AgentBlockStart + AgentBlockCount; i++) { AgentBlock[i].ToBytes(packet, ref length); } + AgentBlockStart += AgentBlockCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + AgentBlockStart < AgentBlock.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class OfflineNotificationPacket : Packet + { + /// + public sealed class AgentBlockBlock : PacketBlock + { + public UUID AgentID; + + public override int Length + { + get + { + return 16; + } + } + + public AgentBlockBlock() { } + public AgentBlockBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 11; + for (int j = 0; j < AgentBlock.Length; j++) + length += AgentBlock[j].Length; + return length; + } + } + public AgentBlockBlock[] AgentBlock; + + public OfflineNotificationPacket() + { + HasVariableBlocks = true; + Type = PacketType.OfflineNotification; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 323; + Header.Reliable = true; + AgentBlock = null; + } + + public OfflineNotificationPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + int count = (int)bytes[i++]; + if(AgentBlock == null || AgentBlock.Length != -1) { + AgentBlock = new AgentBlockBlock[count]; + for(int j = 0; j < count; j++) + { AgentBlock[j] = new AgentBlockBlock(); } + } + for (int j = 0; j < count; j++) + { AgentBlock[j].FromBytes(bytes, ref i); } + } + + public OfflineNotificationPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + int count = (int)bytes[i++]; + if(AgentBlock == null || AgentBlock.Length != count) { + AgentBlock = new AgentBlockBlock[count]; + for(int j = 0; j < count; j++) + { AgentBlock[j] = new AgentBlockBlock(); } + } + for (int j = 0; j < count; j++) + { AgentBlock[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length++; + for (int j = 0; j < AgentBlock.Length; j++) { length += AgentBlock[j].Length; } + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int AgentBlockStart = 0; + do + { + int variableLength = 0; + int AgentBlockCount = 0; + + i = AgentBlockStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < AgentBlock.Length) { + int blockLength = AgentBlock[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == AgentBlockStart) { + variableLength += blockLength; + ++AgentBlockCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)AgentBlockCount; + for (i = AgentBlockStart; i < AgentBlockStart + AgentBlockCount; i++) { AgentBlock[i].ToBytes(packet, ref length); } + AgentBlockStart += AgentBlockCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + AgentBlockStart < AgentBlock.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class SetStartLocationRequestPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class StartLocationDataBlock : PacketBlock + { + public byte[] SimName; + public uint LocationID; + public Vector3 LocationPos; + public Vector3 LocationLookAt; + + public override int Length + { + get + { + int length = 29; + if (SimName != null) { length += SimName.Length; } + return length; + } + } + + public StartLocationDataBlock() { } + public StartLocationDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + length = bytes[i++]; + SimName = new byte[length]; + Buffer.BlockCopy(bytes, i, SimName, 0, length); i += length; + LocationID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + LocationPos.FromBytes(bytes, i); i += 12; + LocationLookAt.FromBytes(bytes, i); i += 12; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + bytes[i++] = (byte)SimName.Length; + Buffer.BlockCopy(SimName, 0, bytes, i, SimName.Length); i += SimName.Length; + Utils.UIntToBytes(LocationID, bytes, i); i += 4; + LocationPos.ToBytes(bytes, i); i += 12; + LocationLookAt.ToBytes(bytes, i); i += 12; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += StartLocationData.Length; + return length; + } + } + public AgentDataBlock AgentData; + public StartLocationDataBlock StartLocationData; + + public SetStartLocationRequestPacket() + { + HasVariableBlocks = false; + Type = PacketType.SetStartLocationRequest; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 324; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + StartLocationData = new StartLocationDataBlock(); + } + + public SetStartLocationRequestPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + StartLocationData.FromBytes(bytes, ref i); + } + + public SetStartLocationRequestPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + StartLocationData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += StartLocationData.Length; + if (Header.AckList != null && 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); + StartLocationData.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class AssetUploadRequestPacket : Packet + { + /// + public sealed class AssetBlockBlock : PacketBlock + { + public UUID TransactionID; + public sbyte Type; + public bool Tempfile; + public bool StoreLocal; + public byte[] AssetData; + + public override int Length + { + get + { + int length = 21; + if (AssetData != null) { length += AssetData.Length; } + return length; + } + } + + public AssetBlockBlock() { } + public AssetBlockBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + TransactionID.FromBytes(bytes, i); i += 16; + Type = (sbyte)bytes[i++]; + Tempfile = (bytes[i++] != 0) ? (bool)true : (bool)false; + StoreLocal = (bytes[i++] != 0) ? (bool)true : (bool)false; + length = (bytes[i++] + (bytes[i++] << 8)); + AssetData = new byte[length]; + Buffer.BlockCopy(bytes, i, AssetData, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + TransactionID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)Type; + bytes[i++] = (byte)((Tempfile) ? 1 : 0); + bytes[i++] = (byte)((StoreLocal) ? 1 : 0); + bytes[i++] = (byte)(AssetData.Length % 256); + bytes[i++] = (byte)((AssetData.Length >> 8) % 256); + Buffer.BlockCopy(AssetData, 0, bytes, i, AssetData.Length); i += AssetData.Length; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AssetBlock.Length; + return length; + } + } + public AssetBlockBlock AssetBlock; + + public AssetUploadRequestPacket() + { + HasVariableBlocks = false; + Type = PacketType.AssetUploadRequest; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 333; + Header.Reliable = true; + AssetBlock = new AssetBlockBlock(); + } + + public AssetUploadRequestPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AssetBlock.FromBytes(bytes, ref i); + } + + public AssetUploadRequestPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AssetBlock.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AssetBlock.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class AssetUploadCompletePacket : Packet + { + /// + public sealed class AssetBlockBlock : PacketBlock + { + public UUID UUID; + public sbyte Type; + public bool Success; + + public override int Length + { + get + { + return 18; + } + } + + public AssetBlockBlock() { } + public AssetBlockBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + UUID.FromBytes(bytes, i); i += 16; + Type = (sbyte)bytes[i++]; + Success = (bytes[i++] != 0) ? (bool)true : (bool)false; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + UUID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)Type; + bytes[i++] = (byte)((Success) ? 1 : 0); + } + + } + + public override int Length + { + get + { + int length = 10; + length += AssetBlock.Length; + return length; + } + } + public AssetBlockBlock AssetBlock; + + public AssetUploadCompletePacket() + { + HasVariableBlocks = false; + Type = PacketType.AssetUploadComplete; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 334; + Header.Reliable = true; + AssetBlock = new AssetBlockBlock(); + } + + public AssetUploadCompletePacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AssetBlock.FromBytes(bytes, ref i); + } + + public AssetUploadCompletePacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AssetBlock.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AssetBlock.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class CreateGroupRequestPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class GroupDataBlock : PacketBlock + { + public byte[] Name; + public byte[] Charter; + public bool ShowInList; + public UUID InsigniaID; + public int MembershipFee; + public bool OpenEnrollment; + public bool AllowPublish; + public bool MaturePublish; + + public override int Length + { + get + { + int length = 27; + if (Name != null) { length += Name.Length; } + if (Charter != null) { length += Charter.Length; } + return length; + } + } + + public GroupDataBlock() { } + public GroupDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + length = bytes[i++]; + Name = new byte[length]; + Buffer.BlockCopy(bytes, i, Name, 0, length); i += length; + length = (bytes[i++] + (bytes[i++] << 8)); + Charter = new byte[length]; + Buffer.BlockCopy(bytes, i, Charter, 0, length); i += length; + ShowInList = (bytes[i++] != 0) ? (bool)true : (bool)false; + InsigniaID.FromBytes(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; + AllowPublish = (bytes[i++] != 0) ? (bool)true : (bool)false; + MaturePublish = (bytes[i++] != 0) ? (bool)true : (bool)false; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + bytes[i++] = (byte)Name.Length; + Buffer.BlockCopy(Name, 0, bytes, i, Name.Length); i += Name.Length; + bytes[i++] = (byte)(Charter.Length % 256); + bytes[i++] = (byte)((Charter.Length >> 8) % 256); + Buffer.BlockCopy(Charter, 0, bytes, i, Charter.Length); i += Charter.Length; + bytes[i++] = (byte)((ShowInList) ? 1 : 0); + InsigniaID.ToBytes(bytes, i); i += 16; + Utils.IntToBytes(MembershipFee, bytes, i); i += 4; + bytes[i++] = (byte)((OpenEnrollment) ? 1 : 0); + bytes[i++] = (byte)((AllowPublish) ? 1 : 0); + bytes[i++] = (byte)((MaturePublish) ? 1 : 0); + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += GroupData.Length; + return length; + } + } + public AgentDataBlock AgentData; + public GroupDataBlock GroupData; + + public CreateGroupRequestPacket() + { + HasVariableBlocks = false; + Type = PacketType.CreateGroupRequest; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 339; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + GroupData = new GroupDataBlock(); + } + + public CreateGroupRequestPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + GroupData.FromBytes(bytes, ref i); + } + + public CreateGroupRequestPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + GroupData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += GroupData.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class CreateGroupReplyPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + + public override int Length + { + get + { + return 16; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class ReplyDataBlock : PacketBlock + { + public UUID GroupID; + public bool Success; + public byte[] Message; + + public override int Length + { + get + { + int length = 18; + if (Message != null) { length += Message.Length; } + return length; + } + } + + public ReplyDataBlock() { } + public ReplyDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + GroupID.FromBytes(bytes, i); i += 16; + Success = (bytes[i++] != 0) ? (bool)true : (bool)false; + length = bytes[i++]; + Message = new byte[length]; + Buffer.BlockCopy(bytes, i, Message, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + GroupID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)((Success) ? 1 : 0); + bytes[i++] = (byte)Message.Length; + Buffer.BlockCopy(Message, 0, bytes, i, Message.Length); i += Message.Length; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += ReplyData.Length; + return length; + } + } + public AgentDataBlock AgentData; + public ReplyDataBlock ReplyData; + + public CreateGroupReplyPacket() + { + HasVariableBlocks = false; + Type = PacketType.CreateGroupReply; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 340; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + ReplyData = new ReplyDataBlock(); + } + + public CreateGroupReplyPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + ReplyData.FromBytes(bytes, ref i); + } + + public CreateGroupReplyPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + ReplyData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += ReplyData.Length; + if (Header.AckList != null && 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); + ReplyData.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class UpdateGroupInfoPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class GroupDataBlock : PacketBlock + { + public UUID GroupID; + public byte[] Charter; + public bool ShowInList; + public UUID InsigniaID; + public int MembershipFee; + public bool OpenEnrollment; + public bool AllowPublish; + public bool MaturePublish; + + public override int Length + { + get + { + int length = 42; + if (Charter != null) { length += Charter.Length; } + return length; + } + } + + public GroupDataBlock() { } + public GroupDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + GroupID.FromBytes(bytes, i); i += 16; + length = (bytes[i++] + (bytes[i++] << 8)); + Charter = new byte[length]; + Buffer.BlockCopy(bytes, i, Charter, 0, length); i += length; + ShowInList = (bytes[i++] != 0) ? (bool)true : (bool)false; + InsigniaID.FromBytes(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; + AllowPublish = (bytes[i++] != 0) ? (bool)true : (bool)false; + MaturePublish = (bytes[i++] != 0) ? (bool)true : (bool)false; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + GroupID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)(Charter.Length % 256); + bytes[i++] = (byte)((Charter.Length >> 8) % 256); + Buffer.BlockCopy(Charter, 0, bytes, i, Charter.Length); i += Charter.Length; + bytes[i++] = (byte)((ShowInList) ? 1 : 0); + InsigniaID.ToBytes(bytes, i); i += 16; + Utils.IntToBytes(MembershipFee, bytes, i); i += 4; + bytes[i++] = (byte)((OpenEnrollment) ? 1 : 0); + bytes[i++] = (byte)((AllowPublish) ? 1 : 0); + bytes[i++] = (byte)((MaturePublish) ? 1 : 0); + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += GroupData.Length; + return length; + } + } + public AgentDataBlock AgentData; + public GroupDataBlock GroupData; + + public UpdateGroupInfoPacket() + { + HasVariableBlocks = false; + Type = PacketType.UpdateGroupInfo; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 341; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + GroupData = new GroupDataBlock(); + } + + public UpdateGroupInfoPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + GroupData.FromBytes(bytes, ref i); + } + + public UpdateGroupInfoPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + GroupData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += GroupData.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class GroupRoleChangesPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + public UUID GroupID; + + public override int Length + { + get + { + return 48; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + GroupID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + GroupID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class RoleChangeBlock : PacketBlock + { + public UUID RoleID; + public UUID MemberID; + public uint Change; + + public override int Length + { + get + { + return 36; + } + } + + public RoleChangeBlock() { } + public RoleChangeBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + RoleID.FromBytes(bytes, i); i += 16; + MemberID.FromBytes(bytes, i); i += 16; + Change = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + RoleID.ToBytes(bytes, i); i += 16; + MemberID.ToBytes(bytes, i); i += 16; + Utils.UIntToBytes(Change, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentData.Length; + for (int j = 0; j < RoleChange.Length; j++) + length += RoleChange[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public RoleChangeBlock[] RoleChange; + + public GroupRoleChangesPacket() + { + HasVariableBlocks = true; + Type = PacketType.GroupRoleChanges; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 342; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + RoleChange = null; + } + + public GroupRoleChangesPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(RoleChange == null || RoleChange.Length != -1) { + RoleChange = new RoleChangeBlock[count]; + for(int j = 0; j < count; j++) + { RoleChange[j] = new RoleChangeBlock(); } + } + for (int j = 0; j < count; j++) + { RoleChange[j].FromBytes(bytes, ref i); } + } + + public GroupRoleChangesPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(RoleChange == null || RoleChange.Length != count) { + RoleChange = new RoleChangeBlock[count]; + for(int j = 0; j < count; j++) + { RoleChange[j] = new RoleChangeBlock(); } + } + for (int j = 0; j < count; j++) + { RoleChange[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length++; + for (int j = 0; j < RoleChange.Length; j++) { length += RoleChange[j].Length; } + if (Header.AckList != null && 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)RoleChange.Length; + for (int j = 0; j < RoleChange.Length; j++) { RoleChange[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int RoleChangeStart = 0; + do + { + int variableLength = 0; + int RoleChangeCount = 0; + + i = RoleChangeStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < RoleChange.Length) { + int blockLength = RoleChange[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == RoleChangeStart) { + variableLength += blockLength; + ++RoleChangeCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)RoleChangeCount; + for (i = RoleChangeStart; i < RoleChangeStart + RoleChangeCount; i++) { RoleChange[i].ToBytes(packet, ref length); } + RoleChangeStart += RoleChangeCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + RoleChangeStart < RoleChange.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class JoinGroupRequestPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class GroupDataBlock : PacketBlock + { + public UUID GroupID; + + public override int Length + { + get + { + return 16; + } + } + + public GroupDataBlock() { } + public GroupDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + GroupID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + GroupID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += GroupData.Length; + return length; + } + } + public AgentDataBlock AgentData; + public GroupDataBlock GroupData; + + public JoinGroupRequestPacket() + { + HasVariableBlocks = false; + Type = PacketType.JoinGroupRequest; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 343; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + GroupData = new GroupDataBlock(); + } + + public JoinGroupRequestPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + GroupData.FromBytes(bytes, ref i); + } + + public JoinGroupRequestPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + GroupData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += GroupData.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class JoinGroupReplyPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + + public override int Length + { + get + { + return 16; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class GroupDataBlock : PacketBlock + { + public UUID GroupID; + public bool Success; + + public override int Length + { + get + { + return 17; + } + } + + public GroupDataBlock() { } + public GroupDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + GroupID.FromBytes(bytes, i); i += 16; + Success = (bytes[i++] != 0) ? (bool)true : (bool)false; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + GroupID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)((Success) ? 1 : 0); + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += GroupData.Length; + return length; + } + } + public AgentDataBlock AgentData; + public GroupDataBlock GroupData; + + public JoinGroupReplyPacket() + { + HasVariableBlocks = false; + Type = PacketType.JoinGroupReply; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 344; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + GroupData = new GroupDataBlock(); + } + + public JoinGroupReplyPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + GroupData.FromBytes(bytes, ref i); + } + + public JoinGroupReplyPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + GroupData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += GroupData.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class EjectGroupMemberRequestPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class GroupDataBlock : PacketBlock + { + public UUID GroupID; + + public override int Length + { + get + { + return 16; + } + } + + public GroupDataBlock() { } + public GroupDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + GroupID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + GroupID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class EjectDataBlock : PacketBlock + { + public UUID EjecteeID; + + public override int Length + { + get + { + return 16; + } + } + + public EjectDataBlock() { } + public EjectDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + EjecteeID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + EjecteeID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentData.Length; + length += GroupData.Length; + for (int j = 0; j < EjectData.Length; j++) + length += EjectData[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public GroupDataBlock GroupData; + public EjectDataBlock[] EjectData; + + public EjectGroupMemberRequestPacket() + { + HasVariableBlocks = true; + Type = PacketType.EjectGroupMemberRequest; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 345; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + GroupData = new GroupDataBlock(); + EjectData = null; + } + + public EjectGroupMemberRequestPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + GroupData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(EjectData == null || EjectData.Length != -1) { + EjectData = new EjectDataBlock[count]; + for(int j = 0; j < count; j++) + { EjectData[j] = new EjectDataBlock(); } + } + for (int j = 0; j < count; j++) + { EjectData[j].FromBytes(bytes, ref i); } + } + + public EjectGroupMemberRequestPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + GroupData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(EjectData == null || EjectData.Length != count) { + EjectData = new EjectDataBlock[count]; + for(int j = 0; j < count; j++) + { EjectData[j] = new EjectDataBlock(); } + } + for (int j = 0; j < count; j++) + { EjectData[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += GroupData.Length; + length++; + for (int j = 0; j < EjectData.Length; j++) { length += EjectData[j].Length; } + if (Header.AckList != null && 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); + bytes[i++] = (byte)EjectData.Length; + for (int j = 0; j < EjectData.Length; j++) { EjectData[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + fixedLength += GroupData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + GroupData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int EjectDataStart = 0; + do + { + int variableLength = 0; + int EjectDataCount = 0; + + i = EjectDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < EjectData.Length) { + int blockLength = EjectData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == EjectDataStart) { + variableLength += blockLength; + ++EjectDataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)EjectDataCount; + for (i = EjectDataStart; i < EjectDataStart + EjectDataCount; i++) { EjectData[i].ToBytes(packet, ref length); } + EjectDataStart += EjectDataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + EjectDataStart < EjectData.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class EjectGroupMemberReplyPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + + public override int Length + { + get + { + return 16; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class GroupDataBlock : PacketBlock + { + public UUID GroupID; + + public override int Length + { + get + { + return 16; + } + } + + public GroupDataBlock() { } + public GroupDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + GroupID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + GroupID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class EjectDataBlock : PacketBlock + { + public bool Success; + + public override int Length + { + get + { + return 1; + } + } + + public EjectDataBlock() { } + public EjectDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + Success = (bytes[i++] != 0) ? (bool)true : (bool)false; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + bytes[i++] = (byte)((Success) ? 1 : 0); + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += GroupData.Length; + length += EjectData.Length; + return length; + } + } + public AgentDataBlock AgentData; + public GroupDataBlock GroupData; + public EjectDataBlock EjectData; + + public EjectGroupMemberReplyPacket() + { + HasVariableBlocks = false; + Type = PacketType.EjectGroupMemberReply; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 346; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + GroupData = new GroupDataBlock(); + EjectData = new EjectDataBlock(); + } + + public EjectGroupMemberReplyPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + GroupData.FromBytes(bytes, ref i); + EjectData.FromBytes(bytes, ref i); + } + + public EjectGroupMemberReplyPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + GroupData.FromBytes(bytes, ref i); + EjectData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += GroupData.Length; + length += EjectData.Length; + if (Header.AckList != null && 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); + EjectData.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class LeaveGroupRequestPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class GroupDataBlock : PacketBlock + { + public UUID GroupID; + + public override int Length + { + get + { + return 16; + } + } + + public GroupDataBlock() { } + public GroupDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + GroupID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + GroupID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += GroupData.Length; + return length; + } + } + public AgentDataBlock AgentData; + public GroupDataBlock GroupData; + + public LeaveGroupRequestPacket() + { + HasVariableBlocks = false; + Type = PacketType.LeaveGroupRequest; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 347; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + GroupData = new GroupDataBlock(); + } + + public LeaveGroupRequestPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + GroupData.FromBytes(bytes, ref i); + } + + public LeaveGroupRequestPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + GroupData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += GroupData.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class LeaveGroupReplyPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + + public override int Length + { + get + { + return 16; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class GroupDataBlock : PacketBlock + { + public UUID GroupID; + public bool Success; + + public override int Length + { + get + { + return 17; + } + } + + public GroupDataBlock() { } + public GroupDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + GroupID.FromBytes(bytes, i); i += 16; + Success = (bytes[i++] != 0) ? (bool)true : (bool)false; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + GroupID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)((Success) ? 1 : 0); + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += GroupData.Length; + return length; + } + } + public AgentDataBlock AgentData; + public GroupDataBlock GroupData; + + public LeaveGroupReplyPacket() + { + HasVariableBlocks = false; + Type = PacketType.LeaveGroupReply; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 348; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + GroupData = new GroupDataBlock(); + } + + public LeaveGroupReplyPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + GroupData.FromBytes(bytes, ref i); + } + + public LeaveGroupReplyPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + GroupData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += GroupData.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class InviteGroupRequestPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class GroupDataBlock : PacketBlock + { + public UUID GroupID; + + public override int Length + { + get + { + return 16; + } + } + + public GroupDataBlock() { } + public GroupDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + GroupID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + GroupID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class InviteDataBlock : PacketBlock + { + public UUID InviteeID; + public UUID RoleID; + + public override int Length + { + get + { + return 32; + } + } + + public InviteDataBlock() { } + public InviteDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + InviteeID.FromBytes(bytes, i); i += 16; + RoleID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + InviteeID.ToBytes(bytes, i); i += 16; + RoleID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentData.Length; + length += GroupData.Length; + for (int j = 0; j < InviteData.Length; j++) + length += InviteData[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public GroupDataBlock GroupData; + public InviteDataBlock[] InviteData; + + public InviteGroupRequestPacket() + { + HasVariableBlocks = true; + Type = PacketType.InviteGroupRequest; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 349; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + GroupData = new GroupDataBlock(); + InviteData = null; + } + + public InviteGroupRequestPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + GroupData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(InviteData == null || InviteData.Length != -1) { + InviteData = new InviteDataBlock[count]; + for(int j = 0; j < count; j++) + { InviteData[j] = new InviteDataBlock(); } + } + for (int j = 0; j < count; j++) + { InviteData[j].FromBytes(bytes, ref i); } + } + + public InviteGroupRequestPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + GroupData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(InviteData == null || InviteData.Length != count) { + InviteData = new InviteDataBlock[count]; + for(int j = 0; j < count; j++) + { InviteData[j] = new InviteDataBlock(); } + } + for (int j = 0; j < count; j++) + { InviteData[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += GroupData.Length; + length++; + for (int j = 0; j < InviteData.Length; j++) { length += InviteData[j].Length; } + if (Header.AckList != null && 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); + bytes[i++] = (byte)InviteData.Length; + for (int j = 0; j < InviteData.Length; j++) { InviteData[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + fixedLength += GroupData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + GroupData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int InviteDataStart = 0; + do + { + int variableLength = 0; + int InviteDataCount = 0; + + i = InviteDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < InviteData.Length) { + int blockLength = InviteData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == InviteDataStart) { + variableLength += blockLength; + ++InviteDataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)InviteDataCount; + for (i = InviteDataStart; i < InviteDataStart + InviteDataCount; i++) { InviteData[i].ToBytes(packet, ref length); } + InviteDataStart += InviteDataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + InviteDataStart < InviteData.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class GroupProfileRequestPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class GroupDataBlock : PacketBlock + { + public UUID GroupID; + + public override int Length + { + get + { + return 16; + } + } + + public GroupDataBlock() { } + public GroupDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + GroupID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + GroupID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += GroupData.Length; + return length; + } + } + public AgentDataBlock AgentData; + public GroupDataBlock GroupData; + + public GroupProfileRequestPacket() + { + HasVariableBlocks = false; + Type = PacketType.GroupProfileRequest; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 351; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + GroupData = new GroupDataBlock(); + } + + public GroupProfileRequestPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + GroupData.FromBytes(bytes, ref i); + } + + public GroupProfileRequestPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + GroupData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += GroupData.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class GroupProfileReplyPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + + public override int Length + { + get + { + return 16; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class GroupDataBlock : PacketBlock + { + public UUID GroupID; + public byte[] Name; + public byte[] Charter; + public bool ShowInList; + public byte[] MemberTitle; + public ulong PowersMask; + public UUID InsigniaID; + public UUID FounderID; + public int MembershipFee; + public bool OpenEnrollment; + public int Money; + public int GroupMembershipCount; + public int GroupRolesCount; + public bool AllowPublish; + public bool MaturePublish; + public UUID OwnerRole; + + public override int Length + { + get + { + int length = 96; + if (Name != null) { length += Name.Length; } + if (Charter != null) { length += Charter.Length; } + if (MemberTitle != null) { length += MemberTitle.Length; } + return length; + } + } + + public GroupDataBlock() { } + public GroupDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + GroupID.FromBytes(bytes, i); i += 16; + length = bytes[i++]; + Name = new byte[length]; + Buffer.BlockCopy(bytes, i, Name, 0, length); i += length; + length = (bytes[i++] + (bytes[i++] << 8)); + Charter = new byte[length]; + Buffer.BlockCopy(bytes, i, Charter, 0, length); i += length; + ShowInList = (bytes[i++] != 0) ? (bool)true : (bool)false; + length = bytes[i++]; + MemberTitle = new byte[length]; + Buffer.BlockCopy(bytes, i, MemberTitle, 0, length); i += length; + 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)); + InsigniaID.FromBytes(bytes, i); i += 16; + FounderID.FromBytes(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; + Money = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + GroupMembershipCount = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + GroupRolesCount = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + AllowPublish = (bytes[i++] != 0) ? (bool)true : (bool)false; + MaturePublish = (bytes[i++] != 0) ? (bool)true : (bool)false; + OwnerRole.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + GroupID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)Name.Length; + Buffer.BlockCopy(Name, 0, bytes, i, Name.Length); i += Name.Length; + bytes[i++] = (byte)(Charter.Length % 256); + bytes[i++] = (byte)((Charter.Length >> 8) % 256); + Buffer.BlockCopy(Charter, 0, bytes, i, Charter.Length); i += Charter.Length; + bytes[i++] = (byte)((ShowInList) ? 1 : 0); + bytes[i++] = (byte)MemberTitle.Length; + Buffer.BlockCopy(MemberTitle, 0, bytes, i, MemberTitle.Length); i += MemberTitle.Length; + Utils.UInt64ToBytes(PowersMask, bytes, i); i += 8; + InsigniaID.ToBytes(bytes, i); i += 16; + FounderID.ToBytes(bytes, i); i += 16; + Utils.IntToBytes(MembershipFee, bytes, i); i += 4; + bytes[i++] = (byte)((OpenEnrollment) ? 1 : 0); + Utils.IntToBytes(Money, bytes, i); i += 4; + Utils.IntToBytes(GroupMembershipCount, bytes, i); i += 4; + Utils.IntToBytes(GroupRolesCount, bytes, i); i += 4; + bytes[i++] = (byte)((AllowPublish) ? 1 : 0); + bytes[i++] = (byte)((MaturePublish) ? 1 : 0); + OwnerRole.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += GroupData.Length; + return length; + } + } + public AgentDataBlock AgentData; + public GroupDataBlock GroupData; + + public GroupProfileReplyPacket() + { + HasVariableBlocks = false; + Type = PacketType.GroupProfileReply; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 352; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + GroupData = new GroupDataBlock(); + } + + public GroupProfileReplyPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + GroupData.FromBytes(bytes, ref i); + } + + public GroupProfileReplyPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + GroupData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += GroupData.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class GroupAccountSummaryRequestPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + public UUID GroupID; + + public override int Length + { + get + { + return 48; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + GroupID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + GroupID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class MoneyDataBlock : PacketBlock + { + public UUID RequestID; + public int IntervalDays; + public int CurrentInterval; + + public override int Length + { + get + { + return 24; + } + } + + public MoneyDataBlock() { } + public MoneyDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + RequestID.FromBytes(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(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + RequestID.ToBytes(bytes, i); i += 16; + Utils.IntToBytes(IntervalDays, bytes, i); i += 4; + Utils.IntToBytes(CurrentInterval, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += MoneyData.Length; + return length; + } + } + public AgentDataBlock AgentData; + public MoneyDataBlock MoneyData; + + public GroupAccountSummaryRequestPacket() + { + HasVariableBlocks = false; + Type = PacketType.GroupAccountSummaryRequest; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 353; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + MoneyData = new MoneyDataBlock(); + } + + public GroupAccountSummaryRequestPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + MoneyData.FromBytes(bytes, ref i); + } + + public GroupAccountSummaryRequestPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + MoneyData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += MoneyData.Length; + if (Header.AckList != null && 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); + MoneyData.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class GroupAccountSummaryReplyPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID GroupID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + GroupID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + GroupID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class MoneyDataBlock : PacketBlock + { + public UUID RequestID; + public int IntervalDays; + public int CurrentInterval; + public byte[] StartDate; + public int Balance; + public int TotalCredits; + public int TotalDebits; + public int ObjectTaxCurrent; + public int LightTaxCurrent; + public int LandTaxCurrent; + public int GroupTaxCurrent; + public int ParcelDirFeeCurrent; + public int ObjectTaxEstimate; + public int LightTaxEstimate; + public int LandTaxEstimate; + public int GroupTaxEstimate; + public int ParcelDirFeeEstimate; + public int NonExemptMembers; + public byte[] LastTaxDate; + public byte[] TaxDate; + + public override int Length + { + get + { + int length = 83; + if (StartDate != null) { length += StartDate.Length; } + if (LastTaxDate != null) { length += LastTaxDate.Length; } + if (TaxDate != null) { length += TaxDate.Length; } + return length; + } + } + + public MoneyDataBlock() { } + public MoneyDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + RequestID.FromBytes(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)); + length = bytes[i++]; + StartDate = new byte[length]; + Buffer.BlockCopy(bytes, i, StartDate, 0, length); i += length; + Balance = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + TotalCredits = (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)); + 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)); + ParcelDirFeeCurrent = (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)); + ParcelDirFeeEstimate = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + NonExemptMembers = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + length = bytes[i++]; + LastTaxDate = new byte[length]; + Buffer.BlockCopy(bytes, i, LastTaxDate, 0, length); i += length; + length = bytes[i++]; + TaxDate = new byte[length]; + Buffer.BlockCopy(bytes, i, TaxDate, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + RequestID.ToBytes(bytes, i); i += 16; + Utils.IntToBytes(IntervalDays, bytes, i); i += 4; + Utils.IntToBytes(CurrentInterval, bytes, i); i += 4; + bytes[i++] = (byte)StartDate.Length; + Buffer.BlockCopy(StartDate, 0, bytes, i, StartDate.Length); i += StartDate.Length; + Utils.IntToBytes(Balance, bytes, i); i += 4; + Utils.IntToBytes(TotalCredits, bytes, i); i += 4; + Utils.IntToBytes(TotalDebits, bytes, i); i += 4; + Utils.IntToBytes(ObjectTaxCurrent, bytes, i); i += 4; + Utils.IntToBytes(LightTaxCurrent, bytes, i); i += 4; + Utils.IntToBytes(LandTaxCurrent, bytes, i); i += 4; + Utils.IntToBytes(GroupTaxCurrent, bytes, i); i += 4; + Utils.IntToBytes(ParcelDirFeeCurrent, bytes, i); i += 4; + Utils.IntToBytes(ObjectTaxEstimate, bytes, i); i += 4; + Utils.IntToBytes(LightTaxEstimate, bytes, i); i += 4; + Utils.IntToBytes(LandTaxEstimate, bytes, i); i += 4; + Utils.IntToBytes(GroupTaxEstimate, bytes, i); i += 4; + Utils.IntToBytes(ParcelDirFeeEstimate, bytes, i); i += 4; + Utils.IntToBytes(NonExemptMembers, bytes, i); i += 4; + bytes[i++] = (byte)LastTaxDate.Length; + Buffer.BlockCopy(LastTaxDate, 0, bytes, i, LastTaxDate.Length); i += LastTaxDate.Length; + bytes[i++] = (byte)TaxDate.Length; + Buffer.BlockCopy(TaxDate, 0, bytes, i, TaxDate.Length); i += TaxDate.Length; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += MoneyData.Length; + return length; + } + } + public AgentDataBlock AgentData; + public MoneyDataBlock MoneyData; + + public GroupAccountSummaryReplyPacket() + { + HasVariableBlocks = false; + Type = PacketType.GroupAccountSummaryReply; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 354; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + MoneyData = new MoneyDataBlock(); + } + + public GroupAccountSummaryReplyPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + MoneyData.FromBytes(bytes, ref i); + } + + public GroupAccountSummaryReplyPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + MoneyData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += MoneyData.Length; + if (Header.AckList != null && 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); + MoneyData.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class GroupAccountDetailsRequestPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + public UUID GroupID; + + public override int Length + { + get + { + return 48; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + GroupID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + GroupID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class MoneyDataBlock : PacketBlock + { + public UUID RequestID; + public int IntervalDays; + public int CurrentInterval; + + public override int Length + { + get + { + return 24; + } + } + + public MoneyDataBlock() { } + public MoneyDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + RequestID.FromBytes(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(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + RequestID.ToBytes(bytes, i); i += 16; + Utils.IntToBytes(IntervalDays, bytes, i); i += 4; + Utils.IntToBytes(CurrentInterval, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += MoneyData.Length; + return length; + } + } + public AgentDataBlock AgentData; + public MoneyDataBlock MoneyData; + + public GroupAccountDetailsRequestPacket() + { + HasVariableBlocks = false; + Type = PacketType.GroupAccountDetailsRequest; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 355; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + MoneyData = new MoneyDataBlock(); + } + + public GroupAccountDetailsRequestPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + MoneyData.FromBytes(bytes, ref i); + } + + public GroupAccountDetailsRequestPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + MoneyData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += MoneyData.Length; + if (Header.AckList != null && 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); + MoneyData.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class GroupAccountDetailsReplyPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID GroupID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + GroupID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + GroupID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class MoneyDataBlock : PacketBlock + { + public UUID RequestID; + public int IntervalDays; + public int CurrentInterval; + public byte[] StartDate; + + public override int Length + { + get + { + int length = 25; + if (StartDate != null) { length += StartDate.Length; } + return length; + } + } + + public MoneyDataBlock() { } + public MoneyDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + RequestID.FromBytes(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)); + length = bytes[i++]; + StartDate = new byte[length]; + Buffer.BlockCopy(bytes, i, StartDate, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + RequestID.ToBytes(bytes, i); i += 16; + Utils.IntToBytes(IntervalDays, bytes, i); i += 4; + Utils.IntToBytes(CurrentInterval, bytes, i); i += 4; + bytes[i++] = (byte)StartDate.Length; + Buffer.BlockCopy(StartDate, 0, bytes, i, StartDate.Length); i += StartDate.Length; + } + + } + + /// + public sealed class HistoryDataBlock : PacketBlock + { + public byte[] Description; + public int Amount; + + public override int Length + { + get + { + int length = 5; + if (Description != null) { length += Description.Length; } + return length; + } + } + + public HistoryDataBlock() { } + public HistoryDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + length = bytes[i++]; + Description = new byte[length]; + Buffer.BlockCopy(bytes, i, Description, 0, length); i += length; + Amount = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + bytes[i++] = (byte)Description.Length; + Buffer.BlockCopy(Description, 0, bytes, i, Description.Length); i += Description.Length; + Utils.IntToBytes(Amount, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentData.Length; + length += MoneyData.Length; + for (int j = 0; j < HistoryData.Length; j++) + length += HistoryData[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public MoneyDataBlock MoneyData; + public HistoryDataBlock[] HistoryData; + + public GroupAccountDetailsReplyPacket() + { + HasVariableBlocks = true; + Type = PacketType.GroupAccountDetailsReply; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 356; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + MoneyData = new MoneyDataBlock(); + HistoryData = null; + } + + public GroupAccountDetailsReplyPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + MoneyData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(HistoryData == null || HistoryData.Length != -1) { + HistoryData = new HistoryDataBlock[count]; + for(int j = 0; j < count; j++) + { HistoryData[j] = new HistoryDataBlock(); } + } + for (int j = 0; j < count; j++) + { HistoryData[j].FromBytes(bytes, ref i); } + } + + public GroupAccountDetailsReplyPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + MoneyData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(HistoryData == null || HistoryData.Length != count) { + HistoryData = new HistoryDataBlock[count]; + for(int j = 0; j < count; j++) + { HistoryData[j] = new HistoryDataBlock(); } + } + for (int j = 0; j < count; j++) + { HistoryData[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += MoneyData.Length; + length++; + for (int j = 0; j < HistoryData.Length; j++) { length += HistoryData[j].Length; } + if (Header.AckList != null && 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); + MoneyData.ToBytes(bytes, ref i); + bytes[i++] = (byte)HistoryData.Length; + for (int j = 0; j < HistoryData.Length; j++) { HistoryData[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + fixedLength += MoneyData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + MoneyData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int HistoryDataStart = 0; + do + { + int variableLength = 0; + int HistoryDataCount = 0; + + i = HistoryDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < HistoryData.Length) { + int blockLength = HistoryData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == HistoryDataStart) { + variableLength += blockLength; + ++HistoryDataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)HistoryDataCount; + for (i = HistoryDataStart; i < HistoryDataStart + HistoryDataCount; i++) { HistoryData[i].ToBytes(packet, ref length); } + HistoryDataStart += HistoryDataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + HistoryDataStart < HistoryData.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class GroupAccountTransactionsRequestPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + public UUID GroupID; + + public override int Length + { + get + { + return 48; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + GroupID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + GroupID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class MoneyDataBlock : PacketBlock + { + public UUID RequestID; + public int IntervalDays; + public int CurrentInterval; + + public override int Length + { + get + { + return 24; + } + } + + public MoneyDataBlock() { } + public MoneyDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + RequestID.FromBytes(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(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + RequestID.ToBytes(bytes, i); i += 16; + Utils.IntToBytes(IntervalDays, bytes, i); i += 4; + Utils.IntToBytes(CurrentInterval, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += MoneyData.Length; + return length; + } + } + public AgentDataBlock AgentData; + public MoneyDataBlock MoneyData; + + public GroupAccountTransactionsRequestPacket() + { + HasVariableBlocks = false; + Type = PacketType.GroupAccountTransactionsRequest; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 357; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + MoneyData = new MoneyDataBlock(); + } + + public GroupAccountTransactionsRequestPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + MoneyData.FromBytes(bytes, ref i); + } + + public GroupAccountTransactionsRequestPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + MoneyData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += MoneyData.Length; + if (Header.AckList != null && 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); + MoneyData.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class GroupAccountTransactionsReplyPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID GroupID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + GroupID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + GroupID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class MoneyDataBlock : PacketBlock + { + public UUID RequestID; + public int IntervalDays; + public int CurrentInterval; + public byte[] StartDate; + + public override int Length + { + get + { + int length = 25; + if (StartDate != null) { length += StartDate.Length; } + return length; + } + } + + public MoneyDataBlock() { } + public MoneyDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + RequestID.FromBytes(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)); + length = bytes[i++]; + StartDate = new byte[length]; + Buffer.BlockCopy(bytes, i, StartDate, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + RequestID.ToBytes(bytes, i); i += 16; + Utils.IntToBytes(IntervalDays, bytes, i); i += 4; + Utils.IntToBytes(CurrentInterval, bytes, i); i += 4; + bytes[i++] = (byte)StartDate.Length; + Buffer.BlockCopy(StartDate, 0, bytes, i, StartDate.Length); i += StartDate.Length; + } + + } + + /// + public sealed class HistoryDataBlock : PacketBlock + { + public byte[] Time; + public byte[] User; + public int Type; + public byte[] Item; + public int Amount; + + public override int Length + { + get + { + int length = 11; + if (Time != null) { length += Time.Length; } + if (User != null) { length += User.Length; } + if (Item != null) { length += Item.Length; } + return length; + } + } + + public HistoryDataBlock() { } + public HistoryDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + length = bytes[i++]; + Time = new byte[length]; + Buffer.BlockCopy(bytes, i, Time, 0, length); i += length; + length = bytes[i++]; + User = new byte[length]; + Buffer.BlockCopy(bytes, i, User, 0, length); i += length; + Type = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + length = bytes[i++]; + Item = new byte[length]; + Buffer.BlockCopy(bytes, i, Item, 0, length); i += length; + Amount = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + bytes[i++] = (byte)Time.Length; + Buffer.BlockCopy(Time, 0, bytes, i, Time.Length); i += Time.Length; + bytes[i++] = (byte)User.Length; + Buffer.BlockCopy(User, 0, bytes, i, User.Length); i += User.Length; + Utils.IntToBytes(Type, bytes, i); i += 4; + bytes[i++] = (byte)Item.Length; + Buffer.BlockCopy(Item, 0, bytes, i, Item.Length); i += Item.Length; + Utils.IntToBytes(Amount, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentData.Length; + length += MoneyData.Length; + for (int j = 0; j < HistoryData.Length; j++) + length += HistoryData[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public MoneyDataBlock MoneyData; + public HistoryDataBlock[] HistoryData; + + public GroupAccountTransactionsReplyPacket() + { + HasVariableBlocks = true; + Type = PacketType.GroupAccountTransactionsReply; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 358; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + MoneyData = new MoneyDataBlock(); + HistoryData = null; + } + + public GroupAccountTransactionsReplyPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + MoneyData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(HistoryData == null || HistoryData.Length != -1) { + HistoryData = new HistoryDataBlock[count]; + for(int j = 0; j < count; j++) + { HistoryData[j] = new HistoryDataBlock(); } + } + for (int j = 0; j < count; j++) + { HistoryData[j].FromBytes(bytes, ref i); } + } + + public GroupAccountTransactionsReplyPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + MoneyData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(HistoryData == null || HistoryData.Length != count) { + HistoryData = new HistoryDataBlock[count]; + for(int j = 0; j < count; j++) + { HistoryData[j] = new HistoryDataBlock(); } + } + for (int j = 0; j < count; j++) + { HistoryData[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += MoneyData.Length; + length++; + for (int j = 0; j < HistoryData.Length; j++) { length += HistoryData[j].Length; } + if (Header.AckList != null && 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); + MoneyData.ToBytes(bytes, ref i); + bytes[i++] = (byte)HistoryData.Length; + for (int j = 0; j < HistoryData.Length; j++) { HistoryData[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + fixedLength += MoneyData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + MoneyData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int HistoryDataStart = 0; + do + { + int variableLength = 0; + int HistoryDataCount = 0; + + i = HistoryDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < HistoryData.Length) { + int blockLength = HistoryData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == HistoryDataStart) { + variableLength += blockLength; + ++HistoryDataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)HistoryDataCount; + for (i = HistoryDataStart; i < HistoryDataStart + HistoryDataCount; i++) { HistoryData[i].ToBytes(packet, ref length); } + HistoryDataStart += HistoryDataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + HistoryDataStart < HistoryData.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class GroupActiveProposalsRequestPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class GroupDataBlock : PacketBlock + { + public UUID GroupID; + + public override int Length + { + get + { + return 16; + } + } + + public GroupDataBlock() { } + public GroupDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + GroupID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + GroupID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class TransactionDataBlock : PacketBlock + { + public UUID TransactionID; + + public override int Length + { + get + { + return 16; + } + } + + public TransactionDataBlock() { } + public TransactionDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + TransactionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + TransactionID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += GroupData.Length; + length += TransactionData.Length; + return length; + } + } + public AgentDataBlock AgentData; + public GroupDataBlock GroupData; + public TransactionDataBlock TransactionData; + + public GroupActiveProposalsRequestPacket() + { + HasVariableBlocks = false; + Type = PacketType.GroupActiveProposalsRequest; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 359; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + GroupData = new GroupDataBlock(); + TransactionData = new TransactionDataBlock(); + } + + public GroupActiveProposalsRequestPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + GroupData.FromBytes(bytes, ref i); + TransactionData.FromBytes(bytes, ref i); + } + + public GroupActiveProposalsRequestPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + GroupData.FromBytes(bytes, ref i); + TransactionData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += GroupData.Length; + length += TransactionData.Length; + if (Header.AckList != null && 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); + TransactionData.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class GroupActiveProposalItemReplyPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID GroupID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + GroupID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + GroupID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class TransactionDataBlock : PacketBlock + { + public UUID TransactionID; + public uint TotalNumItems; + + public override int Length + { + get + { + return 20; + } + } + + public TransactionDataBlock() { } + public TransactionDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + TransactionID.FromBytes(bytes, i); i += 16; + TotalNumItems = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + TransactionID.ToBytes(bytes, i); i += 16; + Utils.UIntToBytes(TotalNumItems, bytes, i); i += 4; + } + + } + + /// + public sealed class ProposalDataBlock : PacketBlock + { + public UUID VoteID; + public UUID VoteInitiator; + public byte[] TerseDateID; + public byte[] StartDateTime; + public byte[] EndDateTime; + public bool AlreadyVoted; + public byte[] VoteCast; + public float Majority; + public int Quorum; + public byte[] ProposalText; + + public override int Length + { + get + { + int length = 46; + if (TerseDateID != null) { length += TerseDateID.Length; } + if (StartDateTime != null) { length += StartDateTime.Length; } + if (EndDateTime != null) { length += EndDateTime.Length; } + if (VoteCast != null) { length += VoteCast.Length; } + if (ProposalText != null) { length += ProposalText.Length; } + return length; + } + } + + public ProposalDataBlock() { } + public ProposalDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + VoteID.FromBytes(bytes, i); i += 16; + VoteInitiator.FromBytes(bytes, i); i += 16; + length = bytes[i++]; + TerseDateID = new byte[length]; + Buffer.BlockCopy(bytes, i, TerseDateID, 0, length); i += length; + length = bytes[i++]; + StartDateTime = new byte[length]; + Buffer.BlockCopy(bytes, i, StartDateTime, 0, length); i += length; + length = bytes[i++]; + EndDateTime = new byte[length]; + Buffer.BlockCopy(bytes, i, EndDateTime, 0, length); i += length; + AlreadyVoted = (bytes[i++] != 0) ? (bool)true : (bool)false; + length = bytes[i++]; + VoteCast = new byte[length]; + Buffer.BlockCopy(bytes, i, VoteCast, 0, length); i += length; + Majority = Utils.BytesToFloat(bytes, i); i += 4; + Quorum = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + length = bytes[i++]; + ProposalText = new byte[length]; + Buffer.BlockCopy(bytes, i, ProposalText, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + VoteID.ToBytes(bytes, i); i += 16; + VoteInitiator.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)TerseDateID.Length; + Buffer.BlockCopy(TerseDateID, 0, bytes, i, TerseDateID.Length); i += TerseDateID.Length; + bytes[i++] = (byte)StartDateTime.Length; + Buffer.BlockCopy(StartDateTime, 0, bytes, i, StartDateTime.Length); i += StartDateTime.Length; + bytes[i++] = (byte)EndDateTime.Length; + Buffer.BlockCopy(EndDateTime, 0, bytes, i, EndDateTime.Length); i += EndDateTime.Length; + bytes[i++] = (byte)((AlreadyVoted) ? 1 : 0); + bytes[i++] = (byte)VoteCast.Length; + Buffer.BlockCopy(VoteCast, 0, bytes, i, VoteCast.Length); i += VoteCast.Length; + Utils.FloatToBytes(Majority, bytes, i); i += 4; + Utils.IntToBytes(Quorum, bytes, i); i += 4; + bytes[i++] = (byte)ProposalText.Length; + Buffer.BlockCopy(ProposalText, 0, bytes, i, ProposalText.Length); i += ProposalText.Length; + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentData.Length; + length += TransactionData.Length; + for (int j = 0; j < ProposalData.Length; j++) + length += ProposalData[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public TransactionDataBlock TransactionData; + public ProposalDataBlock[] ProposalData; + + public GroupActiveProposalItemReplyPacket() + { + HasVariableBlocks = true; + Type = PacketType.GroupActiveProposalItemReply; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 360; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + TransactionData = new TransactionDataBlock(); + ProposalData = null; + } + + public GroupActiveProposalItemReplyPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + TransactionData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ProposalData == null || ProposalData.Length != -1) { + ProposalData = new ProposalDataBlock[count]; + for(int j = 0; j < count; j++) + { ProposalData[j] = new ProposalDataBlock(); } + } + for (int j = 0; j < count; j++) + { ProposalData[j].FromBytes(bytes, ref i); } + } + + public GroupActiveProposalItemReplyPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + TransactionData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ProposalData == null || ProposalData.Length != count) { + ProposalData = new ProposalDataBlock[count]; + for(int j = 0; j < count; j++) + { ProposalData[j] = new ProposalDataBlock(); } + } + for (int j = 0; j < count; j++) + { ProposalData[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += TransactionData.Length; + length++; + for (int j = 0; j < ProposalData.Length; j++) { length += ProposalData[j].Length; } + if (Header.AckList != null && 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); + bytes[i++] = (byte)ProposalData.Length; + for (int j = 0; j < ProposalData.Length; j++) { ProposalData[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + fixedLength += TransactionData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + TransactionData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int ProposalDataStart = 0; + do + { + int variableLength = 0; + int ProposalDataCount = 0; + + i = ProposalDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < ProposalData.Length) { + int blockLength = ProposalData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ProposalDataStart) { + variableLength += blockLength; + ++ProposalDataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)ProposalDataCount; + for (i = ProposalDataStart; i < ProposalDataStart + ProposalDataCount; i++) { ProposalData[i].ToBytes(packet, ref length); } + ProposalDataStart += ProposalDataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + ProposalDataStart < ProposalData.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class GroupVoteHistoryRequestPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class GroupDataBlock : PacketBlock + { + public UUID GroupID; + + public override int Length + { + get + { + return 16; + } + } + + public GroupDataBlock() { } + public GroupDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + GroupID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + GroupID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class TransactionDataBlock : PacketBlock + { + public UUID TransactionID; + + public override int Length + { + get + { + return 16; + } + } + + public TransactionDataBlock() { } + public TransactionDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + TransactionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + TransactionID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += GroupData.Length; + length += TransactionData.Length; + return length; + } + } + public AgentDataBlock AgentData; + public GroupDataBlock GroupData; + public TransactionDataBlock TransactionData; + + public GroupVoteHistoryRequestPacket() + { + HasVariableBlocks = false; + Type = PacketType.GroupVoteHistoryRequest; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 361; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + GroupData = new GroupDataBlock(); + TransactionData = new TransactionDataBlock(); + } + + public GroupVoteHistoryRequestPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + GroupData.FromBytes(bytes, ref i); + TransactionData.FromBytes(bytes, ref i); + } + + public GroupVoteHistoryRequestPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + GroupData.FromBytes(bytes, ref i); + TransactionData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += GroupData.Length; + length += TransactionData.Length; + if (Header.AckList != null && 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); + TransactionData.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class GroupVoteHistoryItemReplyPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID GroupID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + GroupID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + GroupID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class TransactionDataBlock : PacketBlock + { + public UUID TransactionID; + public uint TotalNumItems; + + public override int Length + { + get + { + return 20; + } + } + + public TransactionDataBlock() { } + public TransactionDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + TransactionID.FromBytes(bytes, i); i += 16; + TotalNumItems = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + TransactionID.ToBytes(bytes, i); i += 16; + Utils.UIntToBytes(TotalNumItems, bytes, i); i += 4; + } + + } + + /// + public sealed class HistoryItemDataBlock : PacketBlock + { + public UUID VoteID; + public byte[] TerseDateID; + public byte[] StartDateTime; + public byte[] EndDateTime; + public UUID VoteInitiator; + public byte[] VoteType; + public byte[] VoteResult; + public float Majority; + public int Quorum; + public byte[] ProposalText; + + public override int Length + { + get + { + int length = 47; + if (TerseDateID != null) { length += TerseDateID.Length; } + if (StartDateTime != null) { length += StartDateTime.Length; } + if (EndDateTime != null) { length += EndDateTime.Length; } + if (VoteType != null) { length += VoteType.Length; } + if (VoteResult != null) { length += VoteResult.Length; } + if (ProposalText != null) { length += ProposalText.Length; } + return length; + } + } + + public HistoryItemDataBlock() { } + public HistoryItemDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + VoteID.FromBytes(bytes, i); i += 16; + length = bytes[i++]; + TerseDateID = new byte[length]; + Buffer.BlockCopy(bytes, i, TerseDateID, 0, length); i += length; + length = bytes[i++]; + StartDateTime = new byte[length]; + Buffer.BlockCopy(bytes, i, StartDateTime, 0, length); i += length; + length = bytes[i++]; + EndDateTime = new byte[length]; + Buffer.BlockCopy(bytes, i, EndDateTime, 0, length); i += length; + VoteInitiator.FromBytes(bytes, i); i += 16; + length = bytes[i++]; + VoteType = new byte[length]; + Buffer.BlockCopy(bytes, i, VoteType, 0, length); i += length; + length = bytes[i++]; + VoteResult = new byte[length]; + Buffer.BlockCopy(bytes, i, VoteResult, 0, length); i += length; + Majority = Utils.BytesToFloat(bytes, i); i += 4; + Quorum = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + length = (bytes[i++] + (bytes[i++] << 8)); + ProposalText = new byte[length]; + Buffer.BlockCopy(bytes, i, ProposalText, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + VoteID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)TerseDateID.Length; + Buffer.BlockCopy(TerseDateID, 0, bytes, i, TerseDateID.Length); i += TerseDateID.Length; + bytes[i++] = (byte)StartDateTime.Length; + Buffer.BlockCopy(StartDateTime, 0, bytes, i, StartDateTime.Length); i += StartDateTime.Length; + bytes[i++] = (byte)EndDateTime.Length; + Buffer.BlockCopy(EndDateTime, 0, bytes, i, EndDateTime.Length); i += EndDateTime.Length; + VoteInitiator.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)VoteType.Length; + Buffer.BlockCopy(VoteType, 0, bytes, i, VoteType.Length); i += VoteType.Length; + bytes[i++] = (byte)VoteResult.Length; + Buffer.BlockCopy(VoteResult, 0, bytes, i, VoteResult.Length); i += VoteResult.Length; + Utils.FloatToBytes(Majority, bytes, i); i += 4; + Utils.IntToBytes(Quorum, bytes, i); i += 4; + bytes[i++] = (byte)(ProposalText.Length % 256); + bytes[i++] = (byte)((ProposalText.Length >> 8) % 256); + Buffer.BlockCopy(ProposalText, 0, bytes, i, ProposalText.Length); i += ProposalText.Length; + } + + } + + /// + public sealed class VoteItemBlock : PacketBlock + { + public UUID CandidateID; + public byte[] VoteCast; + public int NumVotes; + + public override int Length + { + get + { + int length = 21; + if (VoteCast != null) { length += VoteCast.Length; } + return length; + } + } + + public VoteItemBlock() { } + public VoteItemBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + CandidateID.FromBytes(bytes, i); i += 16; + length = bytes[i++]; + VoteCast = new byte[length]; + Buffer.BlockCopy(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(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + CandidateID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)VoteCast.Length; + Buffer.BlockCopy(VoteCast, 0, bytes, i, VoteCast.Length); i += VoteCast.Length; + Utils.IntToBytes(NumVotes, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentData.Length; + length += TransactionData.Length; + length += HistoryItemData.Length; + for (int j = 0; j < VoteItem.Length; j++) + length += VoteItem[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public TransactionDataBlock TransactionData; + public HistoryItemDataBlock HistoryItemData; + public VoteItemBlock[] VoteItem; + + public GroupVoteHistoryItemReplyPacket() + { + HasVariableBlocks = true; + Type = PacketType.GroupVoteHistoryItemReply; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 362; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + TransactionData = new TransactionDataBlock(); + HistoryItemData = new HistoryItemDataBlock(); + VoteItem = null; + } + + public GroupVoteHistoryItemReplyPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + TransactionData.FromBytes(bytes, ref i); + HistoryItemData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(VoteItem == null || VoteItem.Length != -1) { + VoteItem = new VoteItemBlock[count]; + for(int j = 0; j < count; j++) + { VoteItem[j] = new VoteItemBlock(); } + } + for (int j = 0; j < count; j++) + { VoteItem[j].FromBytes(bytes, ref i); } + } + + public GroupVoteHistoryItemReplyPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + TransactionData.FromBytes(bytes, ref i); + HistoryItemData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(VoteItem == null || VoteItem.Length != count) { + VoteItem = new VoteItemBlock[count]; + for(int j = 0; j < count; j++) + { VoteItem[j] = new VoteItemBlock(); } + } + for (int j = 0; j < count; j++) + { VoteItem[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += TransactionData.Length; + length += HistoryItemData.Length; + length++; + for (int j = 0; j < VoteItem.Length; j++) { length += VoteItem[j].Length; } + if (Header.AckList != null && 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); + HistoryItemData.ToBytes(bytes, ref i); + bytes[i++] = (byte)VoteItem.Length; + for (int j = 0; j < VoteItem.Length; j++) { VoteItem[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + fixedLength += TransactionData.Length; + fixedLength += HistoryItemData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + TransactionData.ToBytes(fixedBytes, ref i); + HistoryItemData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int VoteItemStart = 0; + do + { + int variableLength = 0; + int VoteItemCount = 0; + + i = VoteItemStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < VoteItem.Length) { + int blockLength = VoteItem[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == VoteItemStart) { + variableLength += blockLength; + ++VoteItemCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)VoteItemCount; + for (i = VoteItemStart; i < VoteItemStart + VoteItemCount; i++) { VoteItem[i].ToBytes(packet, ref length); } + VoteItemStart += VoteItemCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + VoteItemStart < VoteItem.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class StartGroupProposalPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class ProposalDataBlock : PacketBlock + { + public UUID GroupID; + public int Quorum; + public float Majority; + public int Duration; + public byte[] ProposalText; + + public override int Length + { + get + { + int length = 29; + if (ProposalText != null) { length += ProposalText.Length; } + return length; + } + } + + public ProposalDataBlock() { } + public ProposalDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + GroupID.FromBytes(bytes, i); i += 16; + Quorum = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + Majority = Utils.BytesToFloat(bytes, i); i += 4; + Duration = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + length = bytes[i++]; + ProposalText = new byte[length]; + Buffer.BlockCopy(bytes, i, ProposalText, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + GroupID.ToBytes(bytes, i); i += 16; + Utils.IntToBytes(Quorum, bytes, i); i += 4; + Utils.FloatToBytes(Majority, bytes, i); i += 4; + Utils.IntToBytes(Duration, bytes, i); i += 4; + bytes[i++] = (byte)ProposalText.Length; + Buffer.BlockCopy(ProposalText, 0, bytes, i, ProposalText.Length); i += ProposalText.Length; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += ProposalData.Length; + return length; + } + } + public AgentDataBlock AgentData; + public ProposalDataBlock ProposalData; + + public StartGroupProposalPacket() + { + HasVariableBlocks = false; + Type = PacketType.StartGroupProposal; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 363; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + ProposalData = new ProposalDataBlock(); + } + + public StartGroupProposalPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + ProposalData.FromBytes(bytes, ref i); + } + + public StartGroupProposalPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + ProposalData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += ProposalData.Length; + if (Header.AckList != null && 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); + ProposalData.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class GroupProposalBallotPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class ProposalDataBlock : PacketBlock + { + public UUID ProposalID; + public UUID GroupID; + public byte[] VoteCast; + + public override int Length + { + get + { + int length = 33; + if (VoteCast != null) { length += VoteCast.Length; } + return length; + } + } + + public ProposalDataBlock() { } + public ProposalDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + ProposalID.FromBytes(bytes, i); i += 16; + GroupID.FromBytes(bytes, i); i += 16; + length = bytes[i++]; + VoteCast = new byte[length]; + Buffer.BlockCopy(bytes, i, VoteCast, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + ProposalID.ToBytes(bytes, i); i += 16; + GroupID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)VoteCast.Length; + Buffer.BlockCopy(VoteCast, 0, bytes, i, VoteCast.Length); i += VoteCast.Length; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += ProposalData.Length; + return length; + } + } + public AgentDataBlock AgentData; + public ProposalDataBlock ProposalData; + + public GroupProposalBallotPacket() + { + HasVariableBlocks = false; + Type = PacketType.GroupProposalBallot; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 364; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + ProposalData = new ProposalDataBlock(); + } + + public GroupProposalBallotPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + ProposalData.FromBytes(bytes, ref i); + } + + public GroupProposalBallotPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + ProposalData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += ProposalData.Length; + if (Header.AckList != null && 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); + ProposalData.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class GroupMembersRequestPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class GroupDataBlock : PacketBlock + { + public UUID GroupID; + public UUID RequestID; + + public override int Length + { + get + { + return 32; + } + } + + public GroupDataBlock() { } + public GroupDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + GroupID.FromBytes(bytes, i); i += 16; + RequestID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + GroupID.ToBytes(bytes, i); i += 16; + RequestID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += GroupData.Length; + return length; + } + } + public AgentDataBlock AgentData; + public GroupDataBlock GroupData; + + public GroupMembersRequestPacket() + { + HasVariableBlocks = false; + Type = PacketType.GroupMembersRequest; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 366; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + GroupData = new GroupDataBlock(); + } + + public GroupMembersRequestPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + GroupData.FromBytes(bytes, ref i); + } + + public GroupMembersRequestPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + GroupData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += GroupData.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class GroupMembersReplyPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + + public override int Length + { + get + { + return 16; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class GroupDataBlock : PacketBlock + { + public UUID GroupID; + public UUID RequestID; + public int MemberCount; + + public override int Length + { + get + { + return 36; + } + } + + public GroupDataBlock() { } + public GroupDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + GroupID.FromBytes(bytes, i); i += 16; + RequestID.FromBytes(bytes, i); i += 16; + MemberCount = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + GroupID.ToBytes(bytes, i); i += 16; + RequestID.ToBytes(bytes, i); i += 16; + Utils.IntToBytes(MemberCount, bytes, i); i += 4; + } + + } + + /// + public sealed class MemberDataBlock : PacketBlock + { + public UUID AgentID; + public int Contribution; + public byte[] OnlineStatus; + public ulong AgentPowers; + public byte[] Title; + public bool IsOwner; + + public override int Length + { + get + { + int length = 31; + if (OnlineStatus != null) { length += OnlineStatus.Length; } + if (Title != null) { length += Title.Length; } + return length; + } + } + + public MemberDataBlock() { } + public MemberDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + AgentID.FromBytes(bytes, i); i += 16; + Contribution = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + length = bytes[i++]; + OnlineStatus = new byte[length]; + Buffer.BlockCopy(bytes, i, OnlineStatus, 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)); + length = bytes[i++]; + Title = new byte[length]; + Buffer.BlockCopy(bytes, i, Title, 0, length); i += length; + IsOwner = (bytes[i++] != 0) ? (bool)true : (bool)false; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + Utils.IntToBytes(Contribution, bytes, i); i += 4; + bytes[i++] = (byte)OnlineStatus.Length; + Buffer.BlockCopy(OnlineStatus, 0, bytes, i, OnlineStatus.Length); i += OnlineStatus.Length; + Utils.UInt64ToBytes(AgentPowers, bytes, i); i += 8; + bytes[i++] = (byte)Title.Length; + Buffer.BlockCopy(Title, 0, bytes, i, Title.Length); i += Title.Length; + bytes[i++] = (byte)((IsOwner) ? 1 : 0); + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentData.Length; + length += GroupData.Length; + for (int j = 0; j < MemberData.Length; j++) + length += MemberData[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public GroupDataBlock GroupData; + public MemberDataBlock[] MemberData; + + public GroupMembersReplyPacket() + { + HasVariableBlocks = true; + Type = PacketType.GroupMembersReply; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 367; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + GroupData = new GroupDataBlock(); + MemberData = null; + } + + public GroupMembersReplyPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + GroupData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(MemberData == null || MemberData.Length != -1) { + MemberData = new MemberDataBlock[count]; + for(int j = 0; j < count; j++) + { MemberData[j] = new MemberDataBlock(); } + } + for (int j = 0; j < count; j++) + { MemberData[j].FromBytes(bytes, ref i); } + } + + public GroupMembersReplyPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + GroupData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(MemberData == null || MemberData.Length != count) { + MemberData = new MemberDataBlock[count]; + for(int j = 0; j < count; j++) + { MemberData[j] = new MemberDataBlock(); } + } + for (int j = 0; j < count; j++) + { MemberData[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += GroupData.Length; + length++; + for (int j = 0; j < MemberData.Length; j++) { length += MemberData[j].Length; } + if (Header.AckList != null && 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); + bytes[i++] = (byte)MemberData.Length; + for (int j = 0; j < MemberData.Length; j++) { MemberData[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + fixedLength += GroupData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + GroupData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int MemberDataStart = 0; + do + { + int variableLength = 0; + int MemberDataCount = 0; + + i = MemberDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < MemberData.Length) { + int blockLength = MemberData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == MemberDataStart) { + variableLength += blockLength; + ++MemberDataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)MemberDataCount; + for (i = MemberDataStart; i < MemberDataStart + MemberDataCount; i++) { MemberData[i].ToBytes(packet, ref length); } + MemberDataStart += MemberDataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + MemberDataStart < MemberData.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class ActivateGroupPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + public UUID GroupID; + + public override int Length + { + get + { + return 48; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + GroupID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + GroupID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + return length; + } + } + public AgentDataBlock AgentData; + + public ActivateGroupPacket() + { + HasVariableBlocks = false; + Type = PacketType.ActivateGroup; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 368; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + } + + public ActivateGroupPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + } + + public ActivateGroupPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class SetGroupContributionPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class DataBlock : PacketBlock + { + public UUID GroupID; + public int Contribution; + + public override int Length + { + get + { + return 20; + } + } + + public DataBlock() { } + public DataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + GroupID.FromBytes(bytes, i); i += 16; + Contribution = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + GroupID.ToBytes(bytes, i); i += 16; + Utils.IntToBytes(Contribution, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += Data.Length; + return length; + } + } + public AgentDataBlock AgentData; + public DataBlock Data; + + public SetGroupContributionPacket() + { + HasVariableBlocks = false; + Type = PacketType.SetGroupContribution; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 369; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + Data = new DataBlock(); + } + + public SetGroupContributionPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + Data.FromBytes(bytes, ref i); + } + + public SetGroupContributionPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + Data.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += Data.Length; + if (Header.AckList != null && 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); + Data.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class SetGroupAcceptNoticesPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class DataBlock : PacketBlock + { + public UUID GroupID; + public bool AcceptNotices; + + public override int Length + { + get + { + return 17; + } + } + + public DataBlock() { } + public DataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + GroupID.FromBytes(bytes, i); i += 16; + AcceptNotices = (bytes[i++] != 0) ? (bool)true : (bool)false; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + GroupID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)((AcceptNotices) ? 1 : 0); + } + + } + + /// + public sealed class NewDataBlock : PacketBlock + { + public bool ListInProfile; + + public override int Length + { + get + { + return 1; + } + } + + public NewDataBlock() { } + public NewDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + ListInProfile = (bytes[i++] != 0) ? (bool)true : (bool)false; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + bytes[i++] = (byte)((ListInProfile) ? 1 : 0); + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += Data.Length; + length += NewData.Length; + return length; + } + } + public AgentDataBlock AgentData; + public DataBlock Data; + public NewDataBlock NewData; + + public SetGroupAcceptNoticesPacket() + { + HasVariableBlocks = false; + Type = PacketType.SetGroupAcceptNotices; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 370; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + Data = new DataBlock(); + NewData = new NewDataBlock(); + } + + public SetGroupAcceptNoticesPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + Data.FromBytes(bytes, ref i); + NewData.FromBytes(bytes, ref i); + } + + public SetGroupAcceptNoticesPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + Data.FromBytes(bytes, ref i); + NewData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += Data.Length; + length += NewData.Length; + if (Header.AckList != null && 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); + Data.ToBytes(bytes, ref i); + NewData.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class GroupRoleDataRequestPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class GroupDataBlock : PacketBlock + { + public UUID GroupID; + public UUID RequestID; + + public override int Length + { + get + { + return 32; + } + } + + public GroupDataBlock() { } + public GroupDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + GroupID.FromBytes(bytes, i); i += 16; + RequestID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + GroupID.ToBytes(bytes, i); i += 16; + RequestID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += GroupData.Length; + return length; + } + } + public AgentDataBlock AgentData; + public GroupDataBlock GroupData; + + public GroupRoleDataRequestPacket() + { + HasVariableBlocks = false; + Type = PacketType.GroupRoleDataRequest; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 371; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + GroupData = new GroupDataBlock(); + } + + public GroupRoleDataRequestPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + GroupData.FromBytes(bytes, ref i); + } + + public GroupRoleDataRequestPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + GroupData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += GroupData.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class GroupRoleDataReplyPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + + public override int Length + { + get + { + return 16; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class GroupDataBlock : PacketBlock + { + public UUID GroupID; + public UUID RequestID; + public int RoleCount; + + public override int Length + { + get + { + return 36; + } + } + + public GroupDataBlock() { } + public GroupDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + GroupID.FromBytes(bytes, i); i += 16; + RequestID.FromBytes(bytes, i); i += 16; + RoleCount = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + GroupID.ToBytes(bytes, i); i += 16; + RequestID.ToBytes(bytes, i); i += 16; + Utils.IntToBytes(RoleCount, bytes, i); i += 4; + } + + } + + /// + public sealed class RoleDataBlock : PacketBlock + { + public UUID RoleID; + public byte[] Name; + public byte[] Title; + public byte[] Description; + public ulong Powers; + public uint Members; + + public override int Length + { + get + { + int length = 31; + if (Name != null) { length += Name.Length; } + if (Title != null) { length += Title.Length; } + if (Description != null) { length += Description.Length; } + return length; + } + } + + public RoleDataBlock() { } + public RoleDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + RoleID.FromBytes(bytes, i); i += 16; + length = bytes[i++]; + Name = new byte[length]; + Buffer.BlockCopy(bytes, i, Name, 0, length); i += length; + length = bytes[i++]; + Title = new byte[length]; + Buffer.BlockCopy(bytes, i, Title, 0, length); i += length; + length = bytes[i++]; + Description = new byte[length]; + Buffer.BlockCopy(bytes, i, Description, 0, length); i += length; + 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)); + Members = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + RoleID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)Name.Length; + Buffer.BlockCopy(Name, 0, bytes, i, Name.Length); i += Name.Length; + bytes[i++] = (byte)Title.Length; + Buffer.BlockCopy(Title, 0, bytes, i, Title.Length); i += Title.Length; + bytes[i++] = (byte)Description.Length; + Buffer.BlockCopy(Description, 0, bytes, i, Description.Length); i += Description.Length; + Utils.UInt64ToBytes(Powers, bytes, i); i += 8; + Utils.UIntToBytes(Members, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentData.Length; + length += GroupData.Length; + for (int j = 0; j < RoleData.Length; j++) + length += RoleData[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public GroupDataBlock GroupData; + public RoleDataBlock[] RoleData; + + public GroupRoleDataReplyPacket() + { + HasVariableBlocks = true; + Type = PacketType.GroupRoleDataReply; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 372; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + GroupData = new GroupDataBlock(); + RoleData = null; + } + + public GroupRoleDataReplyPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + GroupData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(RoleData == null || RoleData.Length != -1) { + RoleData = new RoleDataBlock[count]; + for(int j = 0; j < count; j++) + { RoleData[j] = new RoleDataBlock(); } + } + for (int j = 0; j < count; j++) + { RoleData[j].FromBytes(bytes, ref i); } + } + + public GroupRoleDataReplyPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + GroupData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(RoleData == null || RoleData.Length != count) { + RoleData = new RoleDataBlock[count]; + for(int j = 0; j < count; j++) + { RoleData[j] = new RoleDataBlock(); } + } + for (int j = 0; j < count; j++) + { RoleData[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += GroupData.Length; + length++; + for (int j = 0; j < RoleData.Length; j++) { length += RoleData[j].Length; } + if (Header.AckList != null && 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); + bytes[i++] = (byte)RoleData.Length; + for (int j = 0; j < RoleData.Length; j++) { RoleData[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + fixedLength += GroupData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + GroupData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int RoleDataStart = 0; + do + { + int variableLength = 0; + int RoleDataCount = 0; + + i = RoleDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < RoleData.Length) { + int blockLength = RoleData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == RoleDataStart) { + variableLength += blockLength; + ++RoleDataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)RoleDataCount; + for (i = RoleDataStart; i < RoleDataStart + RoleDataCount; i++) { RoleData[i].ToBytes(packet, ref length); } + RoleDataStart += RoleDataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + RoleDataStart < RoleData.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class GroupRoleMembersRequestPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class GroupDataBlock : PacketBlock + { + public UUID GroupID; + public UUID RequestID; + + public override int Length + { + get + { + return 32; + } + } + + public GroupDataBlock() { } + public GroupDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + GroupID.FromBytes(bytes, i); i += 16; + RequestID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + GroupID.ToBytes(bytes, i); i += 16; + RequestID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += GroupData.Length; + return length; + } + } + public AgentDataBlock AgentData; + public GroupDataBlock GroupData; + + public GroupRoleMembersRequestPacket() + { + HasVariableBlocks = false; + Type = PacketType.GroupRoleMembersRequest; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 373; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + GroupData = new GroupDataBlock(); + } + + public GroupRoleMembersRequestPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + GroupData.FromBytes(bytes, ref i); + } + + public GroupRoleMembersRequestPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + GroupData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += GroupData.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class GroupRoleMembersReplyPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID GroupID; + public UUID RequestID; + public uint TotalPairs; + + public override int Length + { + get + { + return 52; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + GroupID.FromBytes(bytes, i); i += 16; + RequestID.FromBytes(bytes, i); i += 16; + TotalPairs = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + GroupID.ToBytes(bytes, i); i += 16; + RequestID.ToBytes(bytes, i); i += 16; + Utils.UIntToBytes(TotalPairs, bytes, i); i += 4; + } + + } + + /// + public sealed class MemberDataBlock : PacketBlock + { + public UUID RoleID; + public UUID MemberID; + + public override int Length + { + get + { + return 32; + } + } + + public MemberDataBlock() { } + public MemberDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + RoleID.FromBytes(bytes, i); i += 16; + MemberID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + RoleID.ToBytes(bytes, i); i += 16; + MemberID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentData.Length; + for (int j = 0; j < MemberData.Length; j++) + length += MemberData[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public MemberDataBlock[] MemberData; + + public GroupRoleMembersReplyPacket() + { + HasVariableBlocks = true; + Type = PacketType.GroupRoleMembersReply; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 374; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + MemberData = null; + } + + public GroupRoleMembersReplyPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(MemberData == null || MemberData.Length != -1) { + MemberData = new MemberDataBlock[count]; + for(int j = 0; j < count; j++) + { MemberData[j] = new MemberDataBlock(); } + } + for (int j = 0; j < count; j++) + { MemberData[j].FromBytes(bytes, ref i); } + } + + public GroupRoleMembersReplyPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(MemberData == null || MemberData.Length != count) { + MemberData = new MemberDataBlock[count]; + for(int j = 0; j < count; j++) + { MemberData[j] = new MemberDataBlock(); } + } + for (int j = 0; j < count; j++) + { MemberData[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length++; + for (int j = 0; j < MemberData.Length; j++) { length += MemberData[j].Length; } + if (Header.AckList != null && 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)MemberData.Length; + for (int j = 0; j < MemberData.Length; j++) { MemberData[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int MemberDataStart = 0; + do + { + int variableLength = 0; + int MemberDataCount = 0; + + i = MemberDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < MemberData.Length) { + int blockLength = MemberData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == MemberDataStart) { + variableLength += blockLength; + ++MemberDataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)MemberDataCount; + for (i = MemberDataStart; i < MemberDataStart + MemberDataCount; i++) { MemberData[i].ToBytes(packet, ref length); } + MemberDataStart += MemberDataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + MemberDataStart < MemberData.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class GroupTitlesRequestPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + public UUID GroupID; + public UUID RequestID; + + public override int Length + { + get + { + return 64; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + GroupID.FromBytes(bytes, i); i += 16; + RequestID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + GroupID.ToBytes(bytes, i); i += 16; + RequestID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + return length; + } + } + public AgentDataBlock AgentData; + + public GroupTitlesRequestPacket() + { + HasVariableBlocks = false; + Type = PacketType.GroupTitlesRequest; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 375; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + } + + public GroupTitlesRequestPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + } + + public GroupTitlesRequestPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class GroupTitlesReplyPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID GroupID; + public UUID RequestID; + + public override int Length + { + get + { + return 48; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + GroupID.FromBytes(bytes, i); i += 16; + RequestID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + GroupID.ToBytes(bytes, i); i += 16; + RequestID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class GroupDataBlock : PacketBlock + { + public byte[] Title; + public UUID RoleID; + public bool Selected; + + public override int Length + { + get + { + int length = 18; + if (Title != null) { length += Title.Length; } + return length; + } + } + + public GroupDataBlock() { } + public GroupDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + length = bytes[i++]; + Title = new byte[length]; + Buffer.BlockCopy(bytes, i, Title, 0, length); i += length; + RoleID.FromBytes(bytes, i); i += 16; + Selected = (bytes[i++] != 0) ? (bool)true : (bool)false; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + bytes[i++] = (byte)Title.Length; + Buffer.BlockCopy(Title, 0, bytes, i, Title.Length); i += Title.Length; + RoleID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)((Selected) ? 1 : 0); + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentData.Length; + for (int j = 0; j < GroupData.Length; j++) + length += GroupData[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public GroupDataBlock[] GroupData; + + public GroupTitlesReplyPacket() + { + HasVariableBlocks = true; + Type = PacketType.GroupTitlesReply; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 376; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + GroupData = null; + } + + public GroupTitlesReplyPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(GroupData == null || GroupData.Length != -1) { + GroupData = new GroupDataBlock[count]; + for(int j = 0; j < count; j++) + { GroupData[j] = new GroupDataBlock(); } + } + for (int j = 0; j < count; j++) + { GroupData[j].FromBytes(bytes, ref i); } + } + + public GroupTitlesReplyPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(GroupData == null || GroupData.Length != count) { + GroupData = new GroupDataBlock[count]; + for(int j = 0; j < count; j++) + { GroupData[j] = new GroupDataBlock(); } + } + for (int j = 0; j < count; j++) + { GroupData[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length++; + for (int j = 0; j < GroupData.Length; j++) { length += GroupData[j].Length; } + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int GroupDataStart = 0; + do + { + int variableLength = 0; + int GroupDataCount = 0; + + i = GroupDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < GroupData.Length) { + int blockLength = GroupData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == GroupDataStart) { + variableLength += blockLength; + ++GroupDataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)GroupDataCount; + for (i = GroupDataStart; i < GroupDataStart + GroupDataCount; i++) { GroupData[i].ToBytes(packet, ref length); } + GroupDataStart += GroupDataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + GroupDataStart < GroupData.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class GroupTitleUpdatePacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + public UUID GroupID; + public UUID TitleRoleID; + + public override int Length + { + get + { + return 64; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + GroupID.FromBytes(bytes, i); i += 16; + TitleRoleID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + GroupID.ToBytes(bytes, i); i += 16; + TitleRoleID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + return length; + } + } + public AgentDataBlock AgentData; + + public GroupTitleUpdatePacket() + { + HasVariableBlocks = false; + Type = PacketType.GroupTitleUpdate; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 377; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + } + + public GroupTitleUpdatePacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + } + + public GroupTitleUpdatePacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class GroupRoleUpdatePacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + public UUID GroupID; + + public override int Length + { + get + { + return 48; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + GroupID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + GroupID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class RoleDataBlock : PacketBlock + { + public UUID RoleID; + public byte[] Name; + public byte[] Description; + public byte[] Title; + public ulong Powers; + public byte UpdateType; + + public override int Length + { + get + { + int length = 28; + if (Name != null) { length += Name.Length; } + if (Description != null) { length += Description.Length; } + if (Title != null) { length += Title.Length; } + return length; + } + } + + public RoleDataBlock() { } + public RoleDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + RoleID.FromBytes(bytes, i); i += 16; + length = bytes[i++]; + Name = new byte[length]; + Buffer.BlockCopy(bytes, i, Name, 0, length); i += length; + length = bytes[i++]; + Description = new byte[length]; + Buffer.BlockCopy(bytes, i, Description, 0, length); i += length; + length = bytes[i++]; + Title = new byte[length]; + Buffer.BlockCopy(bytes, i, Title, 0, length); i += length; + 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)); + UpdateType = (byte)bytes[i++]; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + RoleID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)Name.Length; + Buffer.BlockCopy(Name, 0, bytes, i, Name.Length); i += Name.Length; + bytes[i++] = (byte)Description.Length; + Buffer.BlockCopy(Description, 0, bytes, i, Description.Length); i += Description.Length; + bytes[i++] = (byte)Title.Length; + Buffer.BlockCopy(Title, 0, bytes, i, Title.Length); i += Title.Length; + Utils.UInt64ToBytes(Powers, bytes, i); i += 8; + bytes[i++] = UpdateType; + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentData.Length; + for (int j = 0; j < RoleData.Length; j++) + length += RoleData[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public RoleDataBlock[] RoleData; + + public GroupRoleUpdatePacket() + { + HasVariableBlocks = true; + Type = PacketType.GroupRoleUpdate; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 378; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + RoleData = null; + } + + public GroupRoleUpdatePacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(RoleData == null || RoleData.Length != -1) { + RoleData = new RoleDataBlock[count]; + for(int j = 0; j < count; j++) + { RoleData[j] = new RoleDataBlock(); } + } + for (int j = 0; j < count; j++) + { RoleData[j].FromBytes(bytes, ref i); } + } + + public GroupRoleUpdatePacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(RoleData == null || RoleData.Length != count) { + RoleData = new RoleDataBlock[count]; + for(int j = 0; j < count; j++) + { RoleData[j] = new RoleDataBlock(); } + } + for (int j = 0; j < count; j++) + { RoleData[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length++; + for (int j = 0; j < RoleData.Length; j++) { length += RoleData[j].Length; } + if (Header.AckList != null && 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)RoleData.Length; + for (int j = 0; j < RoleData.Length; j++) { RoleData[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int RoleDataStart = 0; + do + { + int variableLength = 0; + int RoleDataCount = 0; + + i = RoleDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < RoleData.Length) { + int blockLength = RoleData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == RoleDataStart) { + variableLength += blockLength; + ++RoleDataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)RoleDataCount; + for (i = RoleDataStart; i < RoleDataStart + RoleDataCount; i++) { RoleData[i].ToBytes(packet, ref length); } + RoleDataStart += RoleDataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + RoleDataStart < RoleData.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class LiveHelpGroupRequestPacket : Packet + { + /// + public sealed class RequestDataBlock : PacketBlock + { + public UUID RequestID; + public UUID AgentID; + + public override int Length + { + get + { + return 32; + } + } + + public RequestDataBlock() { } + public RequestDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + RequestID.FromBytes(bytes, i); i += 16; + AgentID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + RequestID.ToBytes(bytes, i); i += 16; + AgentID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 10; + length += RequestData.Length; + return length; + } + } + public RequestDataBlock RequestData; + + public LiveHelpGroupRequestPacket() + { + HasVariableBlocks = false; + Type = PacketType.LiveHelpGroupRequest; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 379; + Header.Reliable = true; + RequestData = new RequestDataBlock(); + } + + public LiveHelpGroupRequestPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + RequestData.FromBytes(bytes, ref i); + } + + public LiveHelpGroupRequestPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + RequestData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += RequestData.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class LiveHelpGroupReplyPacket : Packet + { + /// + public sealed class ReplyDataBlock : PacketBlock + { + public UUID RequestID; + public UUID GroupID; + public byte[] Selection; + + public override int Length + { + get + { + int length = 33; + if (Selection != null) { length += Selection.Length; } + return length; + } + } + + public ReplyDataBlock() { } + public ReplyDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + RequestID.FromBytes(bytes, i); i += 16; + GroupID.FromBytes(bytes, i); i += 16; + length = bytes[i++]; + Selection = new byte[length]; + Buffer.BlockCopy(bytes, i, Selection, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + RequestID.ToBytes(bytes, i); i += 16; + GroupID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)Selection.Length; + Buffer.BlockCopy(Selection, 0, bytes, i, Selection.Length); i += Selection.Length; + } + + } + + public override int Length + { + get + { + int length = 10; + length += ReplyData.Length; + return length; + } + } + public ReplyDataBlock ReplyData; + + public LiveHelpGroupReplyPacket() + { + HasVariableBlocks = false; + Type = PacketType.LiveHelpGroupReply; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 380; + Header.Reliable = true; + ReplyData = new ReplyDataBlock(); + } + + public LiveHelpGroupReplyPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + ReplyData.FromBytes(bytes, ref i); + } + + public LiveHelpGroupReplyPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + ReplyData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += ReplyData.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class AgentWearablesRequestPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + return length; + } + } + public AgentDataBlock AgentData; + + public AgentWearablesRequestPacket() + { + HasVariableBlocks = false; + Type = PacketType.AgentWearablesRequest; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 381; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + } + + public AgentWearablesRequestPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + } + + public AgentWearablesRequestPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class AgentWearablesUpdatePacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + public uint SerialNum; + + public override int Length + { + get + { + return 36; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + SerialNum = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + Utils.UIntToBytes(SerialNum, bytes, i); i += 4; + } + + } + + /// + public sealed class WearableDataBlock : PacketBlock + { + public UUID ItemID; + public UUID AssetID; + public byte WearableType; + + public override int Length + { + get + { + return 33; + } + } + + public WearableDataBlock() { } + public WearableDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + ItemID.FromBytes(bytes, i); i += 16; + AssetID.FromBytes(bytes, i); i += 16; + WearableType = (byte)bytes[i++]; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + ItemID.ToBytes(bytes, i); i += 16; + AssetID.ToBytes(bytes, i); i += 16; + bytes[i++] = WearableType; + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentData.Length; + for (int j = 0; j < WearableData.Length; j++) + length += WearableData[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public WearableDataBlock[] WearableData; + + public AgentWearablesUpdatePacket() + { + HasVariableBlocks = true; + Type = PacketType.AgentWearablesUpdate; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 382; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + WearableData = null; + } + + public AgentWearablesUpdatePacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(WearableData == null || WearableData.Length != -1) { + WearableData = new WearableDataBlock[count]; + for(int j = 0; j < count; j++) + { WearableData[j] = new WearableDataBlock(); } + } + for (int j = 0; j < count; j++) + { WearableData[j].FromBytes(bytes, ref i); } + } + + public AgentWearablesUpdatePacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(WearableData == null || WearableData.Length != count) { + WearableData = new WearableDataBlock[count]; + for(int j = 0; j < count; j++) + { WearableData[j] = new WearableDataBlock(); } + } + for (int j = 0; j < count; j++) + { WearableData[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length++; + for (int j = 0; j < WearableData.Length; j++) { length += WearableData[j].Length; } + if (Header.AckList != null && 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)WearableData.Length; + for (int j = 0; j < WearableData.Length; j++) { WearableData[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int WearableDataStart = 0; + do + { + int variableLength = 0; + int WearableDataCount = 0; + + i = WearableDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < WearableData.Length) { + int blockLength = WearableData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == WearableDataStart) { + variableLength += blockLength; + ++WearableDataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)WearableDataCount; + for (i = WearableDataStart; i < WearableDataStart + WearableDataCount; i++) { WearableData[i].ToBytes(packet, ref length); } + WearableDataStart += WearableDataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + WearableDataStart < WearableData.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class AgentIsNowWearingPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class WearableDataBlock : PacketBlock + { + public UUID ItemID; + public byte WearableType; + + public override int Length + { + get + { + return 17; + } + } + + public WearableDataBlock() { } + public WearableDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + ItemID.FromBytes(bytes, i); i += 16; + WearableType = (byte)bytes[i++]; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + ItemID.ToBytes(bytes, i); i += 16; + bytes[i++] = WearableType; + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentData.Length; + for (int j = 0; j < WearableData.Length; j++) + length += WearableData[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public WearableDataBlock[] WearableData; + + public AgentIsNowWearingPacket() + { + HasVariableBlocks = true; + Type = PacketType.AgentIsNowWearing; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 383; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + WearableData = null; + } + + public AgentIsNowWearingPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(WearableData == null || WearableData.Length != -1) { + WearableData = new WearableDataBlock[count]; + for(int j = 0; j < count; j++) + { WearableData[j] = new WearableDataBlock(); } + } + for (int j = 0; j < count; j++) + { WearableData[j].FromBytes(bytes, ref i); } + } + + public AgentIsNowWearingPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(WearableData == null || WearableData.Length != count) { + WearableData = new WearableDataBlock[count]; + for(int j = 0; j < count; j++) + { WearableData[j] = new WearableDataBlock(); } + } + for (int j = 0; j < count; j++) + { WearableData[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length++; + for (int j = 0; j < WearableData.Length; j++) { length += WearableData[j].Length; } + if (Header.AckList != null && 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)WearableData.Length; + for (int j = 0; j < WearableData.Length; j++) { WearableData[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int WearableDataStart = 0; + do + { + int variableLength = 0; + int WearableDataCount = 0; + + i = WearableDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < WearableData.Length) { + int blockLength = WearableData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == WearableDataStart) { + variableLength += blockLength; + ++WearableDataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)WearableDataCount; + for (i = WearableDataStart; i < WearableDataStart + WearableDataCount; i++) { WearableData[i].ToBytes(packet, ref length); } + WearableDataStart += WearableDataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + WearableDataStart < WearableData.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class AgentCachedTexturePacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + public int SerialNum; + + public override int Length + { + get + { + return 36; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + SerialNum = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + Utils.IntToBytes(SerialNum, bytes, i); i += 4; + } + + } + + /// + public sealed class WearableDataBlock : PacketBlock + { + public UUID ID; + public byte TextureIndex; + + public override int Length + { + get + { + return 17; + } + } + + public WearableDataBlock() { } + public WearableDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + ID.FromBytes(bytes, i); i += 16; + TextureIndex = (byte)bytes[i++]; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + ID.ToBytes(bytes, i); i += 16; + bytes[i++] = TextureIndex; + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentData.Length; + for (int j = 0; j < WearableData.Length; j++) + length += WearableData[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public WearableDataBlock[] WearableData; + + public AgentCachedTexturePacket() + { + HasVariableBlocks = true; + Type = PacketType.AgentCachedTexture; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 384; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + WearableData = null; + } + + public AgentCachedTexturePacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(WearableData == null || WearableData.Length != -1) { + WearableData = new WearableDataBlock[count]; + for(int j = 0; j < count; j++) + { WearableData[j] = new WearableDataBlock(); } + } + for (int j = 0; j < count; j++) + { WearableData[j].FromBytes(bytes, ref i); } + } + + public AgentCachedTexturePacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(WearableData == null || WearableData.Length != count) { + WearableData = new WearableDataBlock[count]; + for(int j = 0; j < count; j++) + { WearableData[j] = new WearableDataBlock(); } + } + for (int j = 0; j < count; j++) + { WearableData[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length++; + for (int j = 0; j < WearableData.Length; j++) { length += WearableData[j].Length; } + if (Header.AckList != null && 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)WearableData.Length; + for (int j = 0; j < WearableData.Length; j++) { WearableData[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int WearableDataStart = 0; + do + { + int variableLength = 0; + int WearableDataCount = 0; + + i = WearableDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < WearableData.Length) { + int blockLength = WearableData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == WearableDataStart) { + variableLength += blockLength; + ++WearableDataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)WearableDataCount; + for (i = WearableDataStart; i < WearableDataStart + WearableDataCount; i++) { WearableData[i].ToBytes(packet, ref length); } + WearableDataStart += WearableDataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + WearableDataStart < WearableData.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class AgentCachedTextureResponsePacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + public int SerialNum; + + public override int Length + { + get + { + return 36; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + SerialNum = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + Utils.IntToBytes(SerialNum, bytes, i); i += 4; + } + + } + + /// + public sealed class WearableDataBlock : PacketBlock + { + public UUID TextureID; + public byte TextureIndex; + public byte[] HostName; + + public override int Length + { + get + { + int length = 18; + if (HostName != null) { length += HostName.Length; } + return length; + } + } + + public WearableDataBlock() { } + public WearableDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + TextureID.FromBytes(bytes, i); i += 16; + TextureIndex = (byte)bytes[i++]; + length = bytes[i++]; + HostName = new byte[length]; + Buffer.BlockCopy(bytes, i, HostName, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + TextureID.ToBytes(bytes, i); i += 16; + bytes[i++] = TextureIndex; + bytes[i++] = (byte)HostName.Length; + Buffer.BlockCopy(HostName, 0, bytes, i, HostName.Length); i += HostName.Length; + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentData.Length; + for (int j = 0; j < WearableData.Length; j++) + length += WearableData[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public WearableDataBlock[] WearableData; + + public AgentCachedTextureResponsePacket() + { + HasVariableBlocks = true; + Type = PacketType.AgentCachedTextureResponse; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 385; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + WearableData = null; + } + + public AgentCachedTextureResponsePacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(WearableData == null || WearableData.Length != -1) { + WearableData = new WearableDataBlock[count]; + for(int j = 0; j < count; j++) + { WearableData[j] = new WearableDataBlock(); } + } + for (int j = 0; j < count; j++) + { WearableData[j].FromBytes(bytes, ref i); } + } + + public AgentCachedTextureResponsePacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(WearableData == null || WearableData.Length != count) { + WearableData = new WearableDataBlock[count]; + for(int j = 0; j < count; j++) + { WearableData[j] = new WearableDataBlock(); } + } + for (int j = 0; j < count; j++) + { WearableData[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length++; + for (int j = 0; j < WearableData.Length; j++) { length += WearableData[j].Length; } + if (Header.AckList != null && 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)WearableData.Length; + for (int j = 0; j < WearableData.Length; j++) { WearableData[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int WearableDataStart = 0; + do + { + int variableLength = 0; + int WearableDataCount = 0; + + i = WearableDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < WearableData.Length) { + int blockLength = WearableData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == WearableDataStart) { + variableLength += blockLength; + ++WearableDataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)WearableDataCount; + for (i = WearableDataStart; i < WearableDataStart + WearableDataCount; i++) { WearableData[i].ToBytes(packet, ref length); } + WearableDataStart += WearableDataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + WearableDataStart < WearableData.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class AgentDataUpdateRequestPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + return length; + } + } + public AgentDataBlock AgentData; + + public AgentDataUpdateRequestPacket() + { + HasVariableBlocks = false; + Type = PacketType.AgentDataUpdateRequest; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 386; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + } + + public AgentDataUpdateRequestPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + } + + public AgentDataUpdateRequestPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class AgentDataUpdatePacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public byte[] FirstName; + public byte[] LastName; + public byte[] GroupTitle; + public UUID ActiveGroupID; + public ulong GroupPowers; + public byte[] GroupName; + + public override int Length + { + get + { + int length = 44; + if (FirstName != null) { length += FirstName.Length; } + if (LastName != null) { length += LastName.Length; } + if (GroupTitle != null) { length += GroupTitle.Length; } + if (GroupName != null) { length += GroupName.Length; } + return length; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + AgentID.FromBytes(bytes, i); i += 16; + length = bytes[i++]; + FirstName = new byte[length]; + Buffer.BlockCopy(bytes, i, FirstName, 0, length); i += length; + length = bytes[i++]; + LastName = new byte[length]; + Buffer.BlockCopy(bytes, i, LastName, 0, length); i += length; + length = bytes[i++]; + GroupTitle = new byte[length]; + Buffer.BlockCopy(bytes, i, GroupTitle, 0, length); i += length; + ActiveGroupID.FromBytes(bytes, i); i += 16; + 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)); + length = bytes[i++]; + GroupName = new byte[length]; + Buffer.BlockCopy(bytes, i, GroupName, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)FirstName.Length; + Buffer.BlockCopy(FirstName, 0, bytes, i, FirstName.Length); i += FirstName.Length; + bytes[i++] = (byte)LastName.Length; + Buffer.BlockCopy(LastName, 0, bytes, i, LastName.Length); i += LastName.Length; + bytes[i++] = (byte)GroupTitle.Length; + Buffer.BlockCopy(GroupTitle, 0, bytes, i, GroupTitle.Length); i += GroupTitle.Length; + ActiveGroupID.ToBytes(bytes, i); i += 16; + Utils.UInt64ToBytes(GroupPowers, bytes, i); i += 8; + bytes[i++] = (byte)GroupName.Length; + Buffer.BlockCopy(GroupName, 0, bytes, i, GroupName.Length); i += GroupName.Length; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + return length; + } + } + public AgentDataBlock AgentData; + + public AgentDataUpdatePacket() + { + HasVariableBlocks = false; + Type = PacketType.AgentDataUpdate; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 387; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + } + + public AgentDataUpdatePacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + } + + public AgentDataUpdatePacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class GroupDataUpdatePacket : Packet + { + /// + public sealed class AgentGroupDataBlock : PacketBlock + { + public UUID AgentID; + public UUID GroupID; + public ulong AgentPowers; + public byte[] GroupTitle; + + public override int Length + { + get + { + int length = 41; + if (GroupTitle != null) { length += GroupTitle.Length; } + return length; + } + } + + public AgentGroupDataBlock() { } + public AgentGroupDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + AgentID.FromBytes(bytes, i); i += 16; + GroupID.FromBytes(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)); + length = bytes[i++]; + GroupTitle = new byte[length]; + Buffer.BlockCopy(bytes, i, GroupTitle, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + GroupID.ToBytes(bytes, i); i += 16; + Utils.UInt64ToBytes(AgentPowers, bytes, i); i += 8; + bytes[i++] = (byte)GroupTitle.Length; + Buffer.BlockCopy(GroupTitle, 0, bytes, i, GroupTitle.Length); i += GroupTitle.Length; + } + + } + + public override int Length + { + get + { + int length = 11; + for (int j = 0; j < AgentGroupData.Length; j++) + length += AgentGroupData[j].Length; + return length; + } + } + public AgentGroupDataBlock[] AgentGroupData; + + public GroupDataUpdatePacket() + { + HasVariableBlocks = true; + Type = PacketType.GroupDataUpdate; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 388; + Header.Reliable = true; + Header.Zerocoded = true; + AgentGroupData = null; + } + + public GroupDataUpdatePacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + int count = (int)bytes[i++]; + if(AgentGroupData == null || AgentGroupData.Length != -1) { + AgentGroupData = new AgentGroupDataBlock[count]; + for(int j = 0; j < count; j++) + { AgentGroupData[j] = new AgentGroupDataBlock(); } + } + for (int j = 0; j < count; j++) + { AgentGroupData[j].FromBytes(bytes, ref i); } + } + + public GroupDataUpdatePacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + int count = (int)bytes[i++]; + if(AgentGroupData == null || AgentGroupData.Length != count) { + AgentGroupData = new AgentGroupDataBlock[count]; + for(int j = 0; j < count; j++) + { AgentGroupData[j] = new AgentGroupDataBlock(); } + } + for (int j = 0; j < count; j++) + { AgentGroupData[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length++; + for (int j = 0; j < AgentGroupData.Length; j++) { length += AgentGroupData[j].Length; } + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int AgentGroupDataStart = 0; + do + { + int variableLength = 0; + int AgentGroupDataCount = 0; + + i = AgentGroupDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < AgentGroupData.Length) { + int blockLength = AgentGroupData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == AgentGroupDataStart) { + variableLength += blockLength; + ++AgentGroupDataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)AgentGroupDataCount; + for (i = AgentGroupDataStart; i < AgentGroupDataStart + AgentGroupDataCount; i++) { AgentGroupData[i].ToBytes(packet, ref length); } + AgentGroupDataStart += AgentGroupDataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + AgentGroupDataStart < AgentGroupData.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class AgentGroupDataUpdatePacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + + public override int Length + { + get + { + return 16; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class GroupDataBlock : PacketBlock + { + public UUID GroupID; + public ulong GroupPowers; + public bool AcceptNotices; + public UUID GroupInsigniaID; + public int Contribution; + public byte[] GroupName; + + public override int Length + { + get + { + int length = 46; + if (GroupName != null) { length += GroupName.Length; } + return length; + } + } + + public GroupDataBlock() { } + public GroupDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + GroupID.FromBytes(bytes, i); i += 16; + 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)); + AcceptNotices = (bytes[i++] != 0) ? (bool)true : (bool)false; + GroupInsigniaID.FromBytes(bytes, i); i += 16; + Contribution = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + length = bytes[i++]; + GroupName = new byte[length]; + Buffer.BlockCopy(bytes, i, GroupName, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + GroupID.ToBytes(bytes, i); i += 16; + Utils.UInt64ToBytes(GroupPowers, bytes, i); i += 8; + bytes[i++] = (byte)((AcceptNotices) ? 1 : 0); + GroupInsigniaID.ToBytes(bytes, i); i += 16; + Utils.IntToBytes(Contribution, bytes, i); i += 4; + bytes[i++] = (byte)GroupName.Length; + Buffer.BlockCopy(GroupName, 0, bytes, i, GroupName.Length); i += GroupName.Length; + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentData.Length; + for (int j = 0; j < GroupData.Length; j++) + length += GroupData[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public GroupDataBlock[] GroupData; + + public AgentGroupDataUpdatePacket() + { + HasVariableBlocks = true; + Type = PacketType.AgentGroupDataUpdate; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 389; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + GroupData = null; + } + + public AgentGroupDataUpdatePacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(GroupData == null || GroupData.Length != -1) { + GroupData = new GroupDataBlock[count]; + for(int j = 0; j < count; j++) + { GroupData[j] = new GroupDataBlock(); } + } + for (int j = 0; j < count; j++) + { GroupData[j].FromBytes(bytes, ref i); } + } + + public AgentGroupDataUpdatePacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(GroupData == null || GroupData.Length != count) { + GroupData = new GroupDataBlock[count]; + for(int j = 0; j < count; j++) + { GroupData[j] = new GroupDataBlock(); } + } + for (int j = 0; j < count; j++) + { GroupData[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length++; + for (int j = 0; j < GroupData.Length; j++) { length += GroupData[j].Length; } + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int GroupDataStart = 0; + do + { + int variableLength = 0; + int GroupDataCount = 0; + + i = GroupDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < GroupData.Length) { + int blockLength = GroupData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == GroupDataStart) { + variableLength += blockLength; + ++GroupDataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)GroupDataCount; + for (i = GroupDataStart; i < GroupDataStart + GroupDataCount; i++) { GroupData[i].ToBytes(packet, ref length); } + GroupDataStart += GroupDataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + GroupDataStart < GroupData.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class AgentDropGroupPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID GroupID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + GroupID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + GroupID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + return length; + } + } + public AgentDataBlock AgentData; + + public AgentDropGroupPacket() + { + HasVariableBlocks = false; + Type = PacketType.AgentDropGroup; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 390; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + } + + public AgentDropGroupPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + } + + public AgentDropGroupPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class RezSingleAttachmentFromInvPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class ObjectDataBlock : PacketBlock + { + public UUID ItemID; + public UUID OwnerID; + public byte AttachmentPt; + public uint ItemFlags; + public uint GroupMask; + public uint EveryoneMask; + public uint NextOwnerMask; + public byte[] Name; + public byte[] Description; + + public override int Length + { + get + { + int length = 51; + if (Name != null) { length += Name.Length; } + if (Description != null) { length += Description.Length; } + return length; + } + } + + public ObjectDataBlock() { } + public ObjectDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + ItemID.FromBytes(bytes, i); i += 16; + OwnerID.FromBytes(bytes, i); i += 16; + AttachmentPt = (byte)bytes[i++]; + ItemFlags = (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)); + 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)); + length = bytes[i++]; + Name = new byte[length]; + Buffer.BlockCopy(bytes, i, Name, 0, length); i += length; + length = bytes[i++]; + Description = new byte[length]; + Buffer.BlockCopy(bytes, i, Description, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + ItemID.ToBytes(bytes, i); i += 16; + OwnerID.ToBytes(bytes, i); i += 16; + bytes[i++] = AttachmentPt; + Utils.UIntToBytes(ItemFlags, bytes, i); i += 4; + Utils.UIntToBytes(GroupMask, bytes, i); i += 4; + Utils.UIntToBytes(EveryoneMask, bytes, i); i += 4; + Utils.UIntToBytes(NextOwnerMask, bytes, i); i += 4; + bytes[i++] = (byte)Name.Length; + Buffer.BlockCopy(Name, 0, bytes, i, Name.Length); i += Name.Length; + bytes[i++] = (byte)Description.Length; + Buffer.BlockCopy(Description, 0, bytes, i, Description.Length); i += Description.Length; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += ObjectData.Length; + return length; + } + } + public AgentDataBlock AgentData; + public ObjectDataBlock ObjectData; + + public RezSingleAttachmentFromInvPacket() + { + HasVariableBlocks = false; + Type = PacketType.RezSingleAttachmentFromInv; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 395; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + ObjectData = new ObjectDataBlock(); + } + + public RezSingleAttachmentFromInvPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + ObjectData.FromBytes(bytes, ref i); + } + + public RezSingleAttachmentFromInvPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + ObjectData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += ObjectData.Length; + if (Header.AckList != null && 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); + ObjectData.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class RezMultipleAttachmentsFromInvPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class HeaderDataBlock : PacketBlock + { + public UUID CompoundMsgID; + public byte TotalObjects; + public bool FirstDetachAll; + + public override int Length + { + get + { + return 18; + } + } + + public HeaderDataBlock() { } + public HeaderDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + CompoundMsgID.FromBytes(bytes, i); i += 16; + TotalObjects = (byte)bytes[i++]; + FirstDetachAll = (bytes[i++] != 0) ? (bool)true : (bool)false; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + CompoundMsgID.ToBytes(bytes, i); i += 16; + bytes[i++] = TotalObjects; + bytes[i++] = (byte)((FirstDetachAll) ? 1 : 0); + } + + } + + /// + public sealed class ObjectDataBlock : PacketBlock + { + public UUID ItemID; + public UUID OwnerID; + public byte AttachmentPt; + public uint ItemFlags; + public uint GroupMask; + public uint EveryoneMask; + public uint NextOwnerMask; + public byte[] Name; + public byte[] Description; + + public override int Length + { + get + { + int length = 51; + if (Name != null) { length += Name.Length; } + if (Description != null) { length += Description.Length; } + return length; + } + } + + public ObjectDataBlock() { } + public ObjectDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + ItemID.FromBytes(bytes, i); i += 16; + OwnerID.FromBytes(bytes, i); i += 16; + AttachmentPt = (byte)bytes[i++]; + ItemFlags = (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)); + 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)); + length = bytes[i++]; + Name = new byte[length]; + Buffer.BlockCopy(bytes, i, Name, 0, length); i += length; + length = bytes[i++]; + Description = new byte[length]; + Buffer.BlockCopy(bytes, i, Description, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + ItemID.ToBytes(bytes, i); i += 16; + OwnerID.ToBytes(bytes, i); i += 16; + bytes[i++] = AttachmentPt; + Utils.UIntToBytes(ItemFlags, bytes, i); i += 4; + Utils.UIntToBytes(GroupMask, bytes, i); i += 4; + Utils.UIntToBytes(EveryoneMask, bytes, i); i += 4; + Utils.UIntToBytes(NextOwnerMask, bytes, i); i += 4; + bytes[i++] = (byte)Name.Length; + Buffer.BlockCopy(Name, 0, bytes, i, Name.Length); i += Name.Length; + bytes[i++] = (byte)Description.Length; + Buffer.BlockCopy(Description, 0, bytes, i, Description.Length); i += Description.Length; + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentData.Length; + length += HeaderData.Length; + for (int j = 0; j < ObjectData.Length; j++) + length += ObjectData[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public HeaderDataBlock HeaderData; + public ObjectDataBlock[] ObjectData; + + public RezMultipleAttachmentsFromInvPacket() + { + HasVariableBlocks = true; + Type = PacketType.RezMultipleAttachmentsFromInv; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 396; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + HeaderData = new HeaderDataBlock(); + ObjectData = null; + } + + public RezMultipleAttachmentsFromInvPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + HeaderData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ObjectData == null || ObjectData.Length != -1) { + ObjectData = new ObjectDataBlock[count]; + for(int j = 0; j < count; j++) + { ObjectData[j] = new ObjectDataBlock(); } + } + for (int j = 0; j < count; j++) + { ObjectData[j].FromBytes(bytes, ref i); } + } + + public RezMultipleAttachmentsFromInvPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + HeaderData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ObjectData == null || ObjectData.Length != count) { + ObjectData = new ObjectDataBlock[count]; + for(int j = 0; j < count; j++) + { ObjectData[j] = new ObjectDataBlock(); } + } + for (int j = 0; j < count; j++) + { ObjectData[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += HeaderData.Length; + length++; + for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } + if (Header.AckList != null && 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); + HeaderData.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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + fixedLength += HeaderData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + HeaderData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int ObjectDataStart = 0; + do + { + int variableLength = 0; + int ObjectDataCount = 0; + + i = ObjectDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < ObjectData.Length) { + int blockLength = ObjectData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ObjectDataStart) { + variableLength += blockLength; + ++ObjectDataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)ObjectDataCount; + for (i = ObjectDataStart; i < ObjectDataStart + ObjectDataCount; i++) { ObjectData[i].ToBytes(packet, ref length); } + ObjectDataStart += ObjectDataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + ObjectDataStart < ObjectData.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class DetachAttachmentIntoInvPacket : Packet + { + /// + public sealed class ObjectDataBlock : PacketBlock + { + public UUID AgentID; + public UUID ItemID; + + public override int Length + { + get + { + return 32; + } + } + + public ObjectDataBlock() { } + public ObjectDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + ItemID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + ItemID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 10; + length += ObjectData.Length; + return length; + } + } + public ObjectDataBlock ObjectData; + + public DetachAttachmentIntoInvPacket() + { + HasVariableBlocks = false; + Type = PacketType.DetachAttachmentIntoInv; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 397; + Header.Reliable = true; + ObjectData = new ObjectDataBlock(); + } + + public DetachAttachmentIntoInvPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + ObjectData.FromBytes(bytes, ref i); + } + + public DetachAttachmentIntoInvPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + ObjectData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += ObjectData.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class CreateNewOutfitAttachmentsPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class HeaderDataBlock : PacketBlock + { + public UUID NewFolderID; + + public override int Length + { + get + { + return 16; + } + } + + public HeaderDataBlock() { } + public HeaderDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + NewFolderID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + NewFolderID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class ObjectDataBlock : PacketBlock + { + public UUID OldItemID; + public UUID OldFolderID; + + public override int Length + { + get + { + return 32; + } + } + + public ObjectDataBlock() { } + public ObjectDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + OldItemID.FromBytes(bytes, i); i += 16; + OldFolderID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + OldItemID.ToBytes(bytes, i); i += 16; + OldFolderID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentData.Length; + length += HeaderData.Length; + for (int j = 0; j < ObjectData.Length; j++) + length += ObjectData[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public HeaderDataBlock HeaderData; + public ObjectDataBlock[] ObjectData; + + public CreateNewOutfitAttachmentsPacket() + { + HasVariableBlocks = true; + Type = PacketType.CreateNewOutfitAttachments; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 398; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + HeaderData = new HeaderDataBlock(); + ObjectData = null; + } + + public CreateNewOutfitAttachmentsPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + HeaderData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ObjectData == null || ObjectData.Length != -1) { + ObjectData = new ObjectDataBlock[count]; + for(int j = 0; j < count; j++) + { ObjectData[j] = new ObjectDataBlock(); } + } + for (int j = 0; j < count; j++) + { ObjectData[j].FromBytes(bytes, ref i); } + } + + public CreateNewOutfitAttachmentsPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + HeaderData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ObjectData == null || ObjectData.Length != count) { + ObjectData = new ObjectDataBlock[count]; + for(int j = 0; j < count; j++) + { ObjectData[j] = new ObjectDataBlock(); } + } + for (int j = 0; j < count; j++) + { ObjectData[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += HeaderData.Length; + length++; + for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } + if (Header.AckList != null && 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); + HeaderData.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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + fixedLength += HeaderData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + HeaderData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int ObjectDataStart = 0; + do + { + int variableLength = 0; + int ObjectDataCount = 0; + + i = ObjectDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < ObjectData.Length) { + int blockLength = ObjectData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ObjectDataStart) { + variableLength += blockLength; + ++ObjectDataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)ObjectDataCount; + for (i = ObjectDataStart; i < ObjectDataStart + ObjectDataCount; i++) { ObjectData[i].ToBytes(packet, ref length); } + ObjectDataStart += ObjectDataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + ObjectDataStart < ObjectData.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class UserInfoRequestPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + return length; + } + } + public AgentDataBlock AgentData; + + public UserInfoRequestPacket() + { + HasVariableBlocks = false; + Type = PacketType.UserInfoRequest; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 399; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + } + + public UserInfoRequestPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + } + + public UserInfoRequestPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class UserInfoReplyPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + + public override int Length + { + get + { + return 16; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class UserDataBlock : PacketBlock + { + public bool IMViaEMail; + public byte[] DirectoryVisibility; + public byte[] EMail; + + public override int Length + { + get + { + int length = 4; + if (DirectoryVisibility != null) { length += DirectoryVisibility.Length; } + if (EMail != null) { length += EMail.Length; } + return length; + } + } + + public UserDataBlock() { } + public UserDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + IMViaEMail = (bytes[i++] != 0) ? (bool)true : (bool)false; + length = bytes[i++]; + DirectoryVisibility = new byte[length]; + Buffer.BlockCopy(bytes, i, DirectoryVisibility, 0, length); i += length; + length = (bytes[i++] + (bytes[i++] << 8)); + EMail = new byte[length]; + Buffer.BlockCopy(bytes, i, EMail, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + bytes[i++] = (byte)((IMViaEMail) ? 1 : 0); + bytes[i++] = (byte)DirectoryVisibility.Length; + Buffer.BlockCopy(DirectoryVisibility, 0, bytes, i, DirectoryVisibility.Length); i += DirectoryVisibility.Length; + bytes[i++] = (byte)(EMail.Length % 256); + bytes[i++] = (byte)((EMail.Length >> 8) % 256); + Buffer.BlockCopy(EMail, 0, bytes, i, EMail.Length); i += EMail.Length; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += UserData.Length; + return length; + } + } + public AgentDataBlock AgentData; + public UserDataBlock UserData; + + public UserInfoReplyPacket() + { + HasVariableBlocks = false; + Type = PacketType.UserInfoReply; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 400; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + UserData = new UserDataBlock(); + } + + public UserInfoReplyPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + UserData.FromBytes(bytes, ref i); + } + + public UserInfoReplyPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + UserData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += UserData.Length; + if (Header.AckList != null && 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); + UserData.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class UpdateUserInfoPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class UserDataBlock : PacketBlock + { + public bool IMViaEMail; + public byte[] DirectoryVisibility; + + public override int Length + { + get + { + int length = 2; + if (DirectoryVisibility != null) { length += DirectoryVisibility.Length; } + return length; + } + } + + public UserDataBlock() { } + public UserDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + IMViaEMail = (bytes[i++] != 0) ? (bool)true : (bool)false; + length = bytes[i++]; + DirectoryVisibility = new byte[length]; + Buffer.BlockCopy(bytes, i, DirectoryVisibility, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + bytes[i++] = (byte)((IMViaEMail) ? 1 : 0); + bytes[i++] = (byte)DirectoryVisibility.Length; + Buffer.BlockCopy(DirectoryVisibility, 0, bytes, i, DirectoryVisibility.Length); i += DirectoryVisibility.Length; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += UserData.Length; + return length; + } + } + public AgentDataBlock AgentData; + public UserDataBlock UserData; + + public UpdateUserInfoPacket() + { + HasVariableBlocks = false; + Type = PacketType.UpdateUserInfo; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 401; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + UserData = new UserDataBlock(); + } + + public UpdateUserInfoPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + UserData.FromBytes(bytes, ref i); + } + + public UpdateUserInfoPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + UserData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += UserData.Length; + if (Header.AckList != null && 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); + UserData.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class InitiateDownloadPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + + public override int Length + { + get + { + return 16; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class FileDataBlock : PacketBlock + { + public byte[] SimFilename; + public byte[] ViewerFilename; + + public override int Length + { + get + { + int length = 2; + if (SimFilename != null) { length += SimFilename.Length; } + if (ViewerFilename != null) { length += ViewerFilename.Length; } + return length; + } + } + + public FileDataBlock() { } + public FileDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + length = bytes[i++]; + SimFilename = new byte[length]; + Buffer.BlockCopy(bytes, i, SimFilename, 0, length); i += length; + length = bytes[i++]; + ViewerFilename = new byte[length]; + Buffer.BlockCopy(bytes, i, ViewerFilename, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + bytes[i++] = (byte)SimFilename.Length; + Buffer.BlockCopy(SimFilename, 0, bytes, i, SimFilename.Length); i += SimFilename.Length; + bytes[i++] = (byte)ViewerFilename.Length; + Buffer.BlockCopy(ViewerFilename, 0, bytes, i, ViewerFilename.Length); i += ViewerFilename.Length; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += FileData.Length; + return length; + } + } + public AgentDataBlock AgentData; + public FileDataBlock FileData; + + public InitiateDownloadPacket() + { + HasVariableBlocks = false; + Type = PacketType.InitiateDownload; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 403; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + FileData = new FileDataBlock(); + } + + public InitiateDownloadPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + FileData.FromBytes(bytes, ref i); + } + + public InitiateDownloadPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + FileData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += FileData.Length; + if (Header.AckList != null && 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); + FileData.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class MapLayerRequestPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + public uint Flags; + public uint EstateID; + public bool Godlike; + + public override int Length + { + get + { + return 41; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + 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)); + Godlike = (bytes[i++] != 0) ? (bool)true : (bool)false; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + Utils.UIntToBytes(Flags, bytes, i); i += 4; + Utils.UIntToBytes(EstateID, bytes, i); i += 4; + bytes[i++] = (byte)((Godlike) ? 1 : 0); + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + return length; + } + } + public AgentDataBlock AgentData; + + public MapLayerRequestPacket() + { + HasVariableBlocks = false; + Type = PacketType.MapLayerRequest; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 405; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + } + + public MapLayerRequestPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + } + + public MapLayerRequestPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class MapLayerReplyPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public uint Flags; + + public override int Length + { + get + { + return 20; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + Flags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + Utils.UIntToBytes(Flags, bytes, i); i += 4; + } + + } + + /// + public sealed class LayerDataBlock : PacketBlock + { + public uint Left; + public uint Right; + public uint Top; + public uint Bottom; + public UUID ImageID; + + public override int Length + { + get + { + return 32; + } + } + + public LayerDataBlock() { } + public LayerDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + Left = (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)); + Top = (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)); + ImageID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UIntToBytes(Left, bytes, i); i += 4; + Utils.UIntToBytes(Right, bytes, i); i += 4; + Utils.UIntToBytes(Top, bytes, i); i += 4; + Utils.UIntToBytes(Bottom, bytes, i); i += 4; + ImageID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentData.Length; + for (int j = 0; j < LayerData.Length; j++) + length += LayerData[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public LayerDataBlock[] LayerData; + + public MapLayerReplyPacket() + { + HasVariableBlocks = true; + Type = PacketType.MapLayerReply; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 406; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + LayerData = null; + } + + public MapLayerReplyPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(LayerData == null || LayerData.Length != -1) { + LayerData = new LayerDataBlock[count]; + for(int j = 0; j < count; j++) + { LayerData[j] = new LayerDataBlock(); } + } + for (int j = 0; j < count; j++) + { LayerData[j].FromBytes(bytes, ref i); } + } + + public MapLayerReplyPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(LayerData == null || LayerData.Length != count) { + LayerData = new LayerDataBlock[count]; + for(int j = 0; j < count; j++) + { LayerData[j] = new LayerDataBlock(); } + } + for (int j = 0; j < count; j++) + { LayerData[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length++; + for (int j = 0; j < LayerData.Length; j++) { length += LayerData[j].Length; } + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int LayerDataStart = 0; + do + { + int variableLength = 0; + int LayerDataCount = 0; + + i = LayerDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < LayerData.Length) { + int blockLength = LayerData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == LayerDataStart) { + variableLength += blockLength; + ++LayerDataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)LayerDataCount; + for (i = LayerDataStart; i < LayerDataStart + LayerDataCount; i++) { LayerData[i].ToBytes(packet, ref length); } + LayerDataStart += LayerDataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + LayerDataStart < LayerData.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class MapBlockRequestPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + public uint Flags; + public uint EstateID; + public bool Godlike; + + public override int Length + { + get + { + return 41; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + 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)); + Godlike = (bytes[i++] != 0) ? (bool)true : (bool)false; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + Utils.UIntToBytes(Flags, bytes, i); i += 4; + Utils.UIntToBytes(EstateID, bytes, i); i += 4; + bytes[i++] = (byte)((Godlike) ? 1 : 0); + } + + } + + /// + public sealed class PositionDataBlock : PacketBlock + { + public ushort MinX; + public ushort MaxX; + public ushort MinY; + public ushort MaxY; + + public override int Length + { + get + { + return 8; + } + } + + public PositionDataBlock() { } + public PositionDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + MinX = (ushort)(bytes[i++] + (bytes[i++] << 8)); + MaxX = (ushort)(bytes[i++] + (bytes[i++] << 8)); + MinY = (ushort)(bytes[i++] + (bytes[i++] << 8)); + MaxY = (ushort)(bytes[i++] + (bytes[i++] << 8)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + bytes[i++] = (byte)(MinX % 256); + bytes[i++] = (byte)((MinX >> 8) % 256); + bytes[i++] = (byte)(MaxX % 256); + bytes[i++] = (byte)((MaxX >> 8) % 256); + bytes[i++] = (byte)(MinY % 256); + bytes[i++] = (byte)((MinY >> 8) % 256); + bytes[i++] = (byte)(MaxY % 256); + bytes[i++] = (byte)((MaxY >> 8) % 256); + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += PositionData.Length; + return length; + } + } + public AgentDataBlock AgentData; + public PositionDataBlock PositionData; + + public MapBlockRequestPacket() + { + HasVariableBlocks = false; + Type = PacketType.MapBlockRequest; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 407; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + PositionData = new PositionDataBlock(); + } + + public MapBlockRequestPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + PositionData.FromBytes(bytes, ref i); + } + + public MapBlockRequestPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + PositionData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += PositionData.Length; + if (Header.AckList != null && 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); + PositionData.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class MapNameRequestPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + public uint Flags; + public uint EstateID; + public bool Godlike; + + public override int Length + { + get + { + return 41; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + 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)); + Godlike = (bytes[i++] != 0) ? (bool)true : (bool)false; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + Utils.UIntToBytes(Flags, bytes, i); i += 4; + Utils.UIntToBytes(EstateID, bytes, i); i += 4; + bytes[i++] = (byte)((Godlike) ? 1 : 0); + } + + } + + /// + public sealed class NameDataBlock : PacketBlock + { + public byte[] Name; + + public override int Length + { + get + { + int length = 1; + if (Name != null) { length += Name.Length; } + return length; + } + } + + public NameDataBlock() { } + public NameDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + length = bytes[i++]; + Name = new byte[length]; + Buffer.BlockCopy(bytes, i, Name, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + bytes[i++] = (byte)Name.Length; + Buffer.BlockCopy(Name, 0, bytes, i, Name.Length); i += Name.Length; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += NameData.Length; + return length; + } + } + public AgentDataBlock AgentData; + public NameDataBlock NameData; + + public MapNameRequestPacket() + { + HasVariableBlocks = false; + Type = PacketType.MapNameRequest; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 408; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + NameData = new NameDataBlock(); + } + + public MapNameRequestPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + NameData.FromBytes(bytes, ref i); + } + + public MapNameRequestPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + NameData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += NameData.Length; + if (Header.AckList != null && 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); + NameData.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class MapBlockReplyPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public uint Flags; + + public override int Length + { + get + { + return 20; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + Flags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + Utils.UIntToBytes(Flags, bytes, i); i += 4; + } + + } + + /// + public sealed class DataBlock : PacketBlock + { + public ushort X; + public ushort Y; + public byte[] Name; + public byte Access; + public uint RegionFlags; + public byte WaterHeight; + public byte Agents; + public UUID MapImageID; + + public override int Length + { + get + { + int length = 28; + if (Name != null) { length += Name.Length; } + return length; + } + } + + public DataBlock() { } + public DataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + X = (ushort)(bytes[i++] + (bytes[i++] << 8)); + Y = (ushort)(bytes[i++] + (bytes[i++] << 8)); + length = bytes[i++]; + Name = new byte[length]; + Buffer.BlockCopy(bytes, i, Name, 0, length); i += length; + Access = (byte)bytes[i++]; + RegionFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + WaterHeight = (byte)bytes[i++]; + Agents = (byte)bytes[i++]; + MapImageID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override 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)Name.Length; + Buffer.BlockCopy(Name, 0, bytes, i, Name.Length); i += Name.Length; + bytes[i++] = Access; + Utils.UIntToBytes(RegionFlags, bytes, i); i += 4; + bytes[i++] = WaterHeight; + bytes[i++] = Agents; + MapImageID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class SizeBlock : PacketBlock + { + public ushort SizeX; + public ushort SizeY; + + public override int Length + { + get + { + return 4; + } + } + + public SizeBlock() { } + public SizeBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + SizeX = (ushort)(bytes[i++] + (bytes[i++] << 8)); + SizeY = (ushort)(bytes[i++] + (bytes[i++] << 8)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + bytes[i++] = (byte)(SizeX % 256); + bytes[i++] = (byte)((SizeX >> 8) % 256); + bytes[i++] = (byte)(SizeY % 256); + bytes[i++] = (byte)((SizeY >> 8) % 256); + } + + } + + public override int Length + { + get + { + int length = 12; + length += AgentData.Length; + for (int j = 0; j < Data.Length; j++) + length += Data[j].Length; + for (int j = 0; j < Size.Length; j++) + length += Size[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public DataBlock[] Data; + public SizeBlock[] Size; + + public MapBlockReplyPacket() + { + HasVariableBlocks = true; + Type = PacketType.MapBlockReply; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 409; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + Data = null; + Size = null; + } + + public MapBlockReplyPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(Data == null || Data.Length != -1) { + Data = new DataBlock[count]; + for(int j = 0; j < count; j++) + { Data[j] = new DataBlock(); } + } + for (int j = 0; j < count; j++) + { Data[j].FromBytes(bytes, ref i); } + count = (int)bytes[i++]; + if(Size == null || Size.Length != -1) { + Size = new SizeBlock[count]; + for(int j = 0; j < count; j++) + { Size[j] = new SizeBlock(); } + } + for (int j = 0; j < count; j++) + { Size[j].FromBytes(bytes, ref i); } + } + + public MapBlockReplyPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(Data == null || Data.Length != count) { + Data = new DataBlock[count]; + for(int j = 0; j < count; j++) + { Data[j] = new DataBlock(); } + } + for (int j = 0; j < count; j++) + { Data[j].FromBytes(bytes, ref i); } + count = (int)bytes[i++]; + if(Size == null || Size.Length != count) { + Size = new SizeBlock[count]; + for(int j = 0; j < count; j++) + { Size[j] = new SizeBlock(); } + } + for (int j = 0; j < count; j++) + { Size[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length++; + for (int j = 0; j < Data.Length; j++) { length += Data[j].Length; } + length++; + for (int j = 0; j < Size.Length; j++) { length += Size[j].Length; } + if (Header.AckList != null && 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)Data.Length; + for (int j = 0; j < Data.Length; j++) { Data[j].ToBytes(bytes, ref i); } + bytes[i++] = (byte)Size.Length; + for (int j = 0; j < Size.Length; j++) { Size[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + fixedLength += 2; + + int DataStart = 0; + int SizeStart = 0; + do + { + int variableLength = 0; + int DataCount = 0; + int SizeCount = 0; + + i = DataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < Data.Length) { + int blockLength = Data[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == DataStart) { + variableLength += blockLength; + ++DataCount; + } + else { break; } + ++i; + } + + i = SizeStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < Size.Length) { + int blockLength = Size[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == SizeStart) { + variableLength += blockLength; + ++SizeCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)DataCount; + for (i = DataStart; i < DataStart + DataCount; i++) { Data[i].ToBytes(packet, ref length); } + DataStart += DataCount; + + packet[length++] = (byte)SizeCount; + for (i = SizeStart; i < SizeStart + SizeCount; i++) { Size[i].ToBytes(packet, ref length); } + SizeStart += SizeCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + DataStart < Data.Length || + SizeStart < Size.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class MapItemRequestPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + public uint Flags; + public uint EstateID; + public bool Godlike; + + public override int Length + { + get + { + return 41; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + 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)); + Godlike = (bytes[i++] != 0) ? (bool)true : (bool)false; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + Utils.UIntToBytes(Flags, bytes, i); i += 4; + Utils.UIntToBytes(EstateID, bytes, i); i += 4; + bytes[i++] = (byte)((Godlike) ? 1 : 0); + } + + } + + /// + public sealed class RequestDataBlock : PacketBlock + { + public uint ItemType; + public ulong RegionHandle; + + public override int Length + { + get + { + return 12; + } + } + + public RequestDataBlock() { } + public RequestDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + ItemType = (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)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UIntToBytes(ItemType, bytes, i); i += 4; + Utils.UInt64ToBytes(RegionHandle, bytes, i); i += 8; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += RequestData.Length; + return length; + } + } + public AgentDataBlock AgentData; + public RequestDataBlock RequestData; + + public MapItemRequestPacket() + { + HasVariableBlocks = false; + Type = PacketType.MapItemRequest; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 410; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + RequestData = new RequestDataBlock(); + } + + public MapItemRequestPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + RequestData.FromBytes(bytes, ref i); + } + + public MapItemRequestPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + RequestData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += RequestData.Length; + if (Header.AckList != null && 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); + RequestData.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class MapItemReplyPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public uint Flags; + + public override int Length + { + get + { + return 20; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + Flags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + Utils.UIntToBytes(Flags, bytes, i); i += 4; + } + + } + + /// + public sealed class RequestDataBlock : PacketBlock + { + public uint ItemType; + + public override int Length + { + get + { + return 4; + } + } + + public RequestDataBlock() { } + public RequestDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + ItemType = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UIntToBytes(ItemType, bytes, i); i += 4; + } + + } + + /// + public sealed class DataBlock : PacketBlock + { + public uint X; + public uint Y; + public UUID ID; + public int Extra; + public int Extra2; + public byte[] Name; + + public override int Length + { + get + { + int length = 33; + if (Name != null) { length += Name.Length; } + return length; + } + } + + public DataBlock() { } + public DataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(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.FromBytes(bytes, i); i += 16; + Extra = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + Extra2 = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + length = bytes[i++]; + Name = new byte[length]; + Buffer.BlockCopy(bytes, i, Name, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UIntToBytes(X, bytes, i); i += 4; + Utils.UIntToBytes(Y, bytes, i); i += 4; + ID.ToBytes(bytes, i); i += 16; + Utils.IntToBytes(Extra, bytes, i); i += 4; + Utils.IntToBytes(Extra2, bytes, i); i += 4; + bytes[i++] = (byte)Name.Length; + Buffer.BlockCopy(Name, 0, bytes, i, Name.Length); i += Name.Length; + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentData.Length; + length += RequestData.Length; + for (int j = 0; j < Data.Length; j++) + length += Data[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public RequestDataBlock RequestData; + public DataBlock[] Data; + + public MapItemReplyPacket() + { + HasVariableBlocks = true; + Type = PacketType.MapItemReply; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 411; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + RequestData = new RequestDataBlock(); + Data = null; + } + + public MapItemReplyPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + RequestData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(Data == null || Data.Length != -1) { + Data = new DataBlock[count]; + for(int j = 0; j < count; j++) + { Data[j] = new DataBlock(); } + } + for (int j = 0; j < count; j++) + { Data[j].FromBytes(bytes, ref i); } + } + + public MapItemReplyPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + RequestData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(Data == null || Data.Length != count) { + Data = new DataBlock[count]; + for(int j = 0; j < count; j++) + { Data[j] = new DataBlock(); } + } + for (int j = 0; j < count; j++) + { Data[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += RequestData.Length; + length++; + for (int j = 0; j < Data.Length; j++) { length += Data[j].Length; } + if (Header.AckList != null && 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); + RequestData.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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + fixedLength += RequestData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + RequestData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int DataStart = 0; + do + { + int variableLength = 0; + int DataCount = 0; + + i = DataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < Data.Length) { + int blockLength = Data[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == DataStart) { + variableLength += blockLength; + ++DataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)DataCount; + for (i = DataStart; i < DataStart + DataCount; i++) { Data[i].ToBytes(packet, ref length); } + DataStart += DataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + DataStart < Data.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class SendPostcardPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + public UUID AssetID; + public Vector3d PosGlobal; + public byte[] To; + public byte[] From; + public byte[] Name; + public byte[] Subject; + public byte[] Msg; + public bool AllowPublish; + public bool MaturePublish; + + public override int Length + { + get + { + int length = 80; + if (To != null) { length += To.Length; } + if (From != null) { length += From.Length; } + if (Name != null) { length += Name.Length; } + if (Subject != null) { length += Subject.Length; } + if (Msg != null) { length += Msg.Length; } + return length; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + AssetID.FromBytes(bytes, i); i += 16; + PosGlobal.FromBytes(bytes, i); i += 24; + length = bytes[i++]; + To = new byte[length]; + Buffer.BlockCopy(bytes, i, To, 0, length); i += length; + length = bytes[i++]; + From = new byte[length]; + Buffer.BlockCopy(bytes, i, From, 0, length); i += length; + length = bytes[i++]; + Name = new byte[length]; + Buffer.BlockCopy(bytes, i, Name, 0, length); i += length; + length = bytes[i++]; + Subject = new byte[length]; + Buffer.BlockCopy(bytes, i, Subject, 0, length); i += length; + length = (bytes[i++] + (bytes[i++] << 8)); + Msg = new byte[length]; + Buffer.BlockCopy(bytes, i, Msg, 0, length); i += length; + AllowPublish = (bytes[i++] != 0) ? (bool)true : (bool)false; + MaturePublish = (bytes[i++] != 0) ? (bool)true : (bool)false; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + AssetID.ToBytes(bytes, i); i += 16; + PosGlobal.ToBytes(bytes, i); i += 24; + bytes[i++] = (byte)To.Length; + Buffer.BlockCopy(To, 0, bytes, i, To.Length); i += To.Length; + bytes[i++] = (byte)From.Length; + Buffer.BlockCopy(From, 0, bytes, i, From.Length); i += From.Length; + bytes[i++] = (byte)Name.Length; + Buffer.BlockCopy(Name, 0, bytes, i, Name.Length); i += Name.Length; + bytes[i++] = (byte)Subject.Length; + Buffer.BlockCopy(Subject, 0, bytes, i, Subject.Length); i += Subject.Length; + bytes[i++] = (byte)(Msg.Length % 256); + bytes[i++] = (byte)((Msg.Length >> 8) % 256); + Buffer.BlockCopy(Msg, 0, bytes, i, Msg.Length); i += Msg.Length; + bytes[i++] = (byte)((AllowPublish) ? 1 : 0); + bytes[i++] = (byte)((MaturePublish) ? 1 : 0); + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + return length; + } + } + public AgentDataBlock AgentData; + + public SendPostcardPacket() + { + HasVariableBlocks = false; + Type = PacketType.SendPostcard; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 412; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + } + + public SendPostcardPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + } + + public SendPostcardPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class ParcelMediaCommandMessagePacket : Packet + { + /// + public sealed class CommandBlockBlock : PacketBlock + { + public uint Flags; + public uint Command; + public float Time; + + public override int Length + { + get + { + return 12; + } + } + + public CommandBlockBlock() { } + public CommandBlockBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + Flags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + Command = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + Time = Utils.BytesToFloat(bytes, i); i += 4; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UIntToBytes(Flags, bytes, i); i += 4; + Utils.UIntToBytes(Command, bytes, i); i += 4; + Utils.FloatToBytes(Time, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 10; + length += CommandBlock.Length; + return length; + } + } + public CommandBlockBlock CommandBlock; + + public ParcelMediaCommandMessagePacket() + { + HasVariableBlocks = false; + Type = PacketType.ParcelMediaCommandMessage; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 419; + Header.Reliable = true; + CommandBlock = new CommandBlockBlock(); + } + + public ParcelMediaCommandMessagePacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + CommandBlock.FromBytes(bytes, ref i); + } + + public ParcelMediaCommandMessagePacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + CommandBlock.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += CommandBlock.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class ParcelMediaUpdatePacket : Packet + { + /// + public sealed class DataBlockBlock : PacketBlock + { + public byte[] MediaURL; + public UUID MediaID; + public byte MediaAutoScale; + + public override int Length + { + get + { + int length = 18; + if (MediaURL != null) { length += MediaURL.Length; } + return length; + } + } + + public DataBlockBlock() { } + public DataBlockBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + length = bytes[i++]; + MediaURL = new byte[length]; + Buffer.BlockCopy(bytes, i, MediaURL, 0, length); i += length; + MediaID.FromBytes(bytes, i); i += 16; + MediaAutoScale = (byte)bytes[i++]; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + bytes[i++] = (byte)MediaURL.Length; + Buffer.BlockCopy(MediaURL, 0, bytes, i, MediaURL.Length); i += MediaURL.Length; + MediaID.ToBytes(bytes, i); i += 16; + bytes[i++] = MediaAutoScale; + } + + } + + /// + public sealed class DataBlockExtendedBlock : PacketBlock + { + public byte[] MediaType; + public byte[] MediaDesc; + public int MediaWidth; + public int MediaHeight; + public byte MediaLoop; + + public override int Length + { + get + { + int length = 11; + if (MediaType != null) { length += MediaType.Length; } + if (MediaDesc != null) { length += MediaDesc.Length; } + return length; + } + } + + public DataBlockExtendedBlock() { } + public DataBlockExtendedBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + length = bytes[i++]; + MediaType = new byte[length]; + Buffer.BlockCopy(bytes, i, MediaType, 0, length); i += length; + length = bytes[i++]; + MediaDesc = new byte[length]; + Buffer.BlockCopy(bytes, i, MediaDesc, 0, length); i += length; + MediaWidth = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + MediaHeight = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + MediaLoop = (byte)bytes[i++]; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + bytes[i++] = (byte)MediaType.Length; + Buffer.BlockCopy(MediaType, 0, bytes, i, MediaType.Length); i += MediaType.Length; + bytes[i++] = (byte)MediaDesc.Length; + Buffer.BlockCopy(MediaDesc, 0, bytes, i, MediaDesc.Length); i += MediaDesc.Length; + Utils.IntToBytes(MediaWidth, bytes, i); i += 4; + Utils.IntToBytes(MediaHeight, bytes, i); i += 4; + bytes[i++] = MediaLoop; + } + + } + + public override int Length + { + get + { + int length = 10; + length += DataBlock.Length; + length += DataBlockExtended.Length; + return length; + } + } + public DataBlockBlock DataBlock; + public DataBlockExtendedBlock DataBlockExtended; + + public ParcelMediaUpdatePacket() + { + HasVariableBlocks = false; + Type = PacketType.ParcelMediaUpdate; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 420; + Header.Reliable = true; + DataBlock = new DataBlockBlock(); + DataBlockExtended = new DataBlockExtendedBlock(); + } + + public ParcelMediaUpdatePacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + DataBlock.FromBytes(bytes, ref i); + DataBlockExtended.FromBytes(bytes, ref i); + } + + public ParcelMediaUpdatePacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + DataBlock.FromBytes(bytes, ref i); + DataBlockExtended.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += DataBlock.Length; + length += DataBlockExtended.Length; + if (Header.AckList != null && 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); + DataBlockExtended.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class LandStatRequestPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class RequestDataBlock : PacketBlock + { + public uint ReportType; + public uint RequestFlags; + public byte[] Filter; + public int ParcelLocalID; + + public override int Length + { + get + { + int length = 13; + if (Filter != null) { length += Filter.Length; } + return length; + } + } + + public RequestDataBlock() { } + public RequestDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + ReportType = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + RequestFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + length = bytes[i++]; + Filter = new byte[length]; + Buffer.BlockCopy(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(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UIntToBytes(ReportType, bytes, i); i += 4; + Utils.UIntToBytes(RequestFlags, bytes, i); i += 4; + bytes[i++] = (byte)Filter.Length; + Buffer.BlockCopy(Filter, 0, bytes, i, Filter.Length); i += Filter.Length; + Utils.IntToBytes(ParcelLocalID, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += RequestData.Length; + return length; + } + } + public AgentDataBlock AgentData; + public RequestDataBlock RequestData; + + public LandStatRequestPacket() + { + HasVariableBlocks = false; + Type = PacketType.LandStatRequest; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 421; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + RequestData = new RequestDataBlock(); + } + + public LandStatRequestPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + RequestData.FromBytes(bytes, ref i); + } + + public LandStatRequestPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + RequestData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += RequestData.Length; + if (Header.AckList != null && 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); + RequestData.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class LandStatReplyPacket : Packet + { + /// + public sealed class RequestDataBlock : PacketBlock + { + public uint ReportType; + public uint RequestFlags; + public uint TotalObjectCount; + + public override int Length + { + get + { + return 12; + } + } + + public RequestDataBlock() { } + public RequestDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + ReportType = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + RequestFlags = (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(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UIntToBytes(ReportType, bytes, i); i += 4; + Utils.UIntToBytes(RequestFlags, bytes, i); i += 4; + Utils.UIntToBytes(TotalObjectCount, bytes, i); i += 4; + } + + } + + /// + public sealed class ReportDataBlock : PacketBlock + { + public uint TaskLocalID; + public UUID TaskID; + public float LocationX; + public float LocationY; + public float LocationZ; + public float Score; + public byte[] TaskName; + public byte[] OwnerName; + + public override int Length + { + get + { + int length = 38; + if (TaskName != null) { length += TaskName.Length; } + if (OwnerName != null) { length += OwnerName.Length; } + return length; + } + } + + public ReportDataBlock() { } + public ReportDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + TaskLocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + TaskID.FromBytes(bytes, i); i += 16; + LocationX = Utils.BytesToFloat(bytes, i); i += 4; + LocationY = Utils.BytesToFloat(bytes, i); i += 4; + LocationZ = Utils.BytesToFloat(bytes, i); i += 4; + Score = Utils.BytesToFloat(bytes, i); i += 4; + length = bytes[i++]; + TaskName = new byte[length]; + Buffer.BlockCopy(bytes, i, TaskName, 0, length); i += length; + length = bytes[i++]; + OwnerName = new byte[length]; + Buffer.BlockCopy(bytes, i, OwnerName, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UIntToBytes(TaskLocalID, bytes, i); i += 4; + TaskID.ToBytes(bytes, i); i += 16; + Utils.FloatToBytes(LocationX, bytes, i); i += 4; + Utils.FloatToBytes(LocationY, bytes, i); i += 4; + Utils.FloatToBytes(LocationZ, bytes, i); i += 4; + Utils.FloatToBytes(Score, bytes, i); i += 4; + bytes[i++] = (byte)TaskName.Length; + Buffer.BlockCopy(TaskName, 0, bytes, i, TaskName.Length); i += TaskName.Length; + bytes[i++] = (byte)OwnerName.Length; + Buffer.BlockCopy(OwnerName, 0, bytes, i, OwnerName.Length); i += OwnerName.Length; + } + + } + + public override int Length + { + get + { + int length = 11; + length += RequestData.Length; + for (int j = 0; j < ReportData.Length; j++) + length += ReportData[j].Length; + return length; + } + } + public RequestDataBlock RequestData; + public ReportDataBlock[] ReportData; + + public LandStatReplyPacket() + { + HasVariableBlocks = true; + Type = PacketType.LandStatReply; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 422; + Header.Reliable = true; + RequestData = new RequestDataBlock(); + ReportData = null; + } + + public LandStatReplyPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + RequestData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ReportData == null || ReportData.Length != -1) { + ReportData = new ReportDataBlock[count]; + for(int j = 0; j < count; j++) + { ReportData[j] = new ReportDataBlock(); } + } + for (int j = 0; j < count; j++) + { ReportData[j].FromBytes(bytes, ref i); } + } + + public LandStatReplyPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + RequestData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ReportData == null || ReportData.Length != count) { + ReportData = new ReportDataBlock[count]; + for(int j = 0; j < count; j++) + { ReportData[j] = new ReportDataBlock(); } + } + for (int j = 0; j < count; j++) + { ReportData[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += RequestData.Length; + length++; + for (int j = 0; j < ReportData.Length; j++) { length += ReportData[j].Length; } + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += RequestData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + RequestData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int ReportDataStart = 0; + do + { + int variableLength = 0; + int ReportDataCount = 0; + + i = ReportDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < ReportData.Length) { + int blockLength = ReportData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ReportDataStart) { + variableLength += blockLength; + ++ReportDataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)ReportDataCount; + for (i = ReportDataStart; i < ReportDataStart + ReportDataCount; i++) { ReportData[i].ToBytes(packet, ref length); } + ReportDataStart += ReportDataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + ReportDataStart < ReportData.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class ErrorPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + + public override int Length + { + get + { + return 16; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class DataBlock : PacketBlock + { + public int Code; + public byte[] Token; + public UUID ID; + public byte[] System; + public byte[] Message; + public byte[] Data; + + public override int Length + { + get + { + int length = 26; + if (Token != null) { length += Token.Length; } + if (System != null) { length += System.Length; } + if (Message != null) { length += Message.Length; } + if (Data != null) { length += Data.Length; } + return length; + } + } + + public DataBlock() { } + public DataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + Code = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + length = bytes[i++]; + Token = new byte[length]; + Buffer.BlockCopy(bytes, i, Token, 0, length); i += length; + ID.FromBytes(bytes, i); i += 16; + length = bytes[i++]; + System = new byte[length]; + Buffer.BlockCopy(bytes, i, System, 0, length); i += length; + length = (bytes[i++] + (bytes[i++] << 8)); + Message = new byte[length]; + Buffer.BlockCopy(bytes, i, Message, 0, length); i += length; + length = (bytes[i++] + (bytes[i++] << 8)); + Data = new byte[length]; + Buffer.BlockCopy(bytes, i, Data, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.IntToBytes(Code, bytes, i); i += 4; + bytes[i++] = (byte)Token.Length; + Buffer.BlockCopy(Token, 0, bytes, i, Token.Length); i += Token.Length; + ID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)System.Length; + Buffer.BlockCopy(System, 0, bytes, i, System.Length); i += System.Length; + bytes[i++] = (byte)(Message.Length % 256); + bytes[i++] = (byte)((Message.Length >> 8) % 256); + Buffer.BlockCopy(Message, 0, bytes, i, Message.Length); i += Message.Length; + bytes[i++] = (byte)(Data.Length % 256); + bytes[i++] = (byte)((Data.Length >> 8) % 256); + Buffer.BlockCopy(Data, 0, bytes, i, Data.Length); i += Data.Length; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += Data.Length; + return length; + } + } + public AgentDataBlock AgentData; + public DataBlock Data; + + public ErrorPacket() + { + HasVariableBlocks = false; + Type = PacketType.Error; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 423; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + Data = new DataBlock(); + } + + public ErrorPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + Data.FromBytes(bytes, ref i); + } + + public ErrorPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + Data.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += Data.Length; + if (Header.AckList != null && 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); + Data.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class ObjectIncludeInSearchPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class ObjectDataBlock : PacketBlock + { + public uint ObjectLocalID; + public bool IncludeInSearch; + + public override int Length + { + get + { + return 5; + } + } + + public ObjectDataBlock() { } + public ObjectDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + ObjectLocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + IncludeInSearch = (bytes[i++] != 0) ? (bool)true : (bool)false; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UIntToBytes(ObjectLocalID, bytes, i); i += 4; + bytes[i++] = (byte)((IncludeInSearch) ? 1 : 0); + } + + } + + public override int Length + { + get + { + int length = 11; + length += AgentData.Length; + for (int j = 0; j < ObjectData.Length; j++) + length += ObjectData[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public ObjectDataBlock[] ObjectData; + + public ObjectIncludeInSearchPacket() + { + HasVariableBlocks = true; + Type = PacketType.ObjectIncludeInSearch; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 424; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + ObjectData = null; + } + + public ObjectIncludeInSearchPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ObjectData == null || ObjectData.Length != -1) { + ObjectData = new ObjectDataBlock[count]; + for(int j = 0; j < count; j++) + { ObjectData[j] = new ObjectDataBlock(); } + } + for (int j = 0; j < count; j++) + { ObjectData[j].FromBytes(bytes, ref i); } + } + + public ObjectIncludeInSearchPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ObjectData == null || ObjectData.Length != count) { + ObjectData = new ObjectDataBlock[count]; + for(int j = 0; j < count; j++) + { ObjectData[j] = new ObjectDataBlock(); } + } + for (int j = 0; j < count; j++) + { ObjectData[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length++; + for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } + if (Header.AckList != null && 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)ObjectData.Length; + for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int ObjectDataStart = 0; + do + { + int variableLength = 0; + int ObjectDataCount = 0; + + i = ObjectDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < ObjectData.Length) { + int blockLength = ObjectData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ObjectDataStart) { + variableLength += blockLength; + ++ObjectDataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)ObjectDataCount; + for (i = ObjectDataStart; i < ObjectDataStart + ObjectDataCount; i++) { ObjectData[i].ToBytes(packet, ref length); } + ObjectDataStart += ObjectDataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + ObjectDataStart < ObjectData.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class RezRestoreToWorldPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class InventoryDataBlock : PacketBlock + { + public UUID ItemID; + public UUID FolderID; + public UUID CreatorID; + public UUID OwnerID; + public UUID GroupID; + public uint BaseMask; + public uint OwnerMask; + public uint GroupMask; + public uint EveryoneMask; + public uint NextOwnerMask; + public bool GroupOwned; + public UUID TransactionID; + public sbyte Type; + public sbyte InvType; + public uint Flags; + public byte SaleType; + public int SalePrice; + public byte[] Name; + public byte[] Description; + public int CreationDate; + public uint CRC; + + public override int Length + { + get + { + int length = 138; + if (Name != null) { length += Name.Length; } + if (Description != null) { length += Description.Length; } + return length; + } + } + + public InventoryDataBlock() { } + public InventoryDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + ItemID.FromBytes(bytes, i); i += 16; + FolderID.FromBytes(bytes, i); i += 16; + CreatorID.FromBytes(bytes, i); i += 16; + OwnerID.FromBytes(bytes, i); i += 16; + GroupID.FromBytes(bytes, i); i += 16; + BaseMask = (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)); + GroupMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + 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)); + GroupOwned = (bytes[i++] != 0) ? (bool)true : (bool)false; + TransactionID.FromBytes(bytes, i); i += 16; + Type = (sbyte)bytes[i++]; + InvType = (sbyte)bytes[i++]; + Flags = (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)); + length = bytes[i++]; + Name = new byte[length]; + Buffer.BlockCopy(bytes, i, Name, 0, length); i += length; + length = bytes[i++]; + Description = new byte[length]; + Buffer.BlockCopy(bytes, i, Description, 0, length); i += length; + CreationDate = (int)(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(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + ItemID.ToBytes(bytes, i); i += 16; + FolderID.ToBytes(bytes, i); i += 16; + CreatorID.ToBytes(bytes, i); i += 16; + OwnerID.ToBytes(bytes, i); i += 16; + GroupID.ToBytes(bytes, i); i += 16; + Utils.UIntToBytes(BaseMask, bytes, i); i += 4; + Utils.UIntToBytes(OwnerMask, bytes, i); i += 4; + Utils.UIntToBytes(GroupMask, bytes, i); i += 4; + Utils.UIntToBytes(EveryoneMask, bytes, i); i += 4; + Utils.UIntToBytes(NextOwnerMask, bytes, i); i += 4; + bytes[i++] = (byte)((GroupOwned) ? 1 : 0); + TransactionID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)Type; + bytes[i++] = (byte)InvType; + Utils.UIntToBytes(Flags, bytes, i); i += 4; + bytes[i++] = SaleType; + Utils.IntToBytes(SalePrice, bytes, i); i += 4; + bytes[i++] = (byte)Name.Length; + Buffer.BlockCopy(Name, 0, bytes, i, Name.Length); i += Name.Length; + bytes[i++] = (byte)Description.Length; + Buffer.BlockCopy(Description, 0, bytes, i, Description.Length); i += Description.Length; + Utils.IntToBytes(CreationDate, bytes, i); i += 4; + Utils.UIntToBytes(CRC, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += InventoryData.Length; + return length; + } + } + public AgentDataBlock AgentData; + public InventoryDataBlock InventoryData; + + public RezRestoreToWorldPacket() + { + HasVariableBlocks = false; + Type = PacketType.RezRestoreToWorld; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 425; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + InventoryData = new InventoryDataBlock(); + } + + public RezRestoreToWorldPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + InventoryData.FromBytes(bytes, ref i); + } + + public RezRestoreToWorldPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + InventoryData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += InventoryData.Length; + if (Header.AckList != null && 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); + InventoryData.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class LinkInventoryItemPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class InventoryBlockBlock : PacketBlock + { + public uint CallbackID; + public UUID FolderID; + public UUID TransactionID; + public UUID OldItemID; + public sbyte Type; + public sbyte InvType; + public byte[] Name; + public byte[] Description; + + public override int Length + { + get + { + int length = 56; + if (Name != null) { length += Name.Length; } + if (Description != null) { length += Description.Length; } + return length; + } + } + + public InventoryBlockBlock() { } + public InventoryBlockBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + CallbackID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + FolderID.FromBytes(bytes, i); i += 16; + TransactionID.FromBytes(bytes, i); i += 16; + OldItemID.FromBytes(bytes, i); i += 16; + Type = (sbyte)bytes[i++]; + InvType = (sbyte)bytes[i++]; + length = bytes[i++]; + Name = new byte[length]; + Buffer.BlockCopy(bytes, i, Name, 0, length); i += length; + length = bytes[i++]; + Description = new byte[length]; + Buffer.BlockCopy(bytes, i, Description, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UIntToBytes(CallbackID, bytes, i); i += 4; + FolderID.ToBytes(bytes, i); i += 16; + TransactionID.ToBytes(bytes, i); i += 16; + OldItemID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)Type; + bytes[i++] = (byte)InvType; + bytes[i++] = (byte)Name.Length; + Buffer.BlockCopy(Name, 0, bytes, i, Name.Length); i += Name.Length; + bytes[i++] = (byte)Description.Length; + Buffer.BlockCopy(Description, 0, bytes, i, Description.Length); i += Description.Length; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += InventoryBlock.Length; + return length; + } + } + public AgentDataBlock AgentData; + public InventoryBlockBlock InventoryBlock; + + public LinkInventoryItemPacket() + { + HasVariableBlocks = false; + Type = PacketType.LinkInventoryItem; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 426; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + InventoryBlock = new InventoryBlockBlock(); + } + + public LinkInventoryItemPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + InventoryBlock.FromBytes(bytes, ref i); + } + + public LinkInventoryItemPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + InventoryBlock.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += InventoryBlock.Length; + if (Header.AckList != null && 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); + InventoryBlock.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class RetrieveIMsExtendedPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + public bool IsPremium; + + public override int Length + { + get + { + return 33; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + IsPremium = (bytes[i++] != 0) ? (bool)true : (bool)false; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)((IsPremium) ? 1 : 0); + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + return length; + } + } + public AgentDataBlock AgentData; + + public RetrieveIMsExtendedPacket() + { + HasVariableBlocks = false; + Type = PacketType.RetrieveIMsExtended; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 427; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + } + + public RetrieveIMsExtendedPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + } + + public RetrieveIMsExtendedPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class JoinGroupRequestExtendedPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + public int GroupLimit; + + public override int Length + { + get + { + return 36; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + GroupLimit = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + Utils.IntToBytes(GroupLimit, bytes, i); i += 4; + } + + } + + /// + public sealed class GroupDataBlock : PacketBlock + { + public UUID GroupID; + + public override int Length + { + get + { + return 16; + } + } + + public GroupDataBlock() { } + public GroupDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + GroupID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + GroupID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += GroupData.Length; + return length; + } + } + public AgentDataBlock AgentData; + public GroupDataBlock GroupData; + + public JoinGroupRequestExtendedPacket() + { + HasVariableBlocks = false; + Type = PacketType.JoinGroupRequestExtended; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 428; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + GroupData = new GroupDataBlock(); + } + + public JoinGroupRequestExtendedPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + GroupData.FromBytes(bytes, ref i); + } + + public JoinGroupRequestExtendedPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + GroupData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += GroupData.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class CreateGroupRequestExtendedPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + public int GroupLimit; + + public override int Length + { + get + { + return 36; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + GroupLimit = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + Utils.IntToBytes(GroupLimit, bytes, i); i += 4; + } + + } + + /// + public sealed class GroupDataBlock : PacketBlock + { + public byte[] Name; + public byte[] Charter; + public bool ShowInList; + public UUID InsigniaID; + public int MembershipFee; + public bool OpenEnrollment; + public bool AllowPublish; + public bool MaturePublish; + + public override int Length + { + get + { + int length = 27; + if (Name != null) { length += Name.Length; } + if (Charter != null) { length += Charter.Length; } + return length; + } + } + + public GroupDataBlock() { } + public GroupDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + length = bytes[i++]; + Name = new byte[length]; + Buffer.BlockCopy(bytes, i, Name, 0, length); i += length; + length = (bytes[i++] + (bytes[i++] << 8)); + Charter = new byte[length]; + Buffer.BlockCopy(bytes, i, Charter, 0, length); i += length; + ShowInList = (bytes[i++] != 0) ? (bool)true : (bool)false; + InsigniaID.FromBytes(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; + AllowPublish = (bytes[i++] != 0) ? (bool)true : (bool)false; + MaturePublish = (bytes[i++] != 0) ? (bool)true : (bool)false; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + bytes[i++] = (byte)Name.Length; + Buffer.BlockCopy(Name, 0, bytes, i, Name.Length); i += Name.Length; + bytes[i++] = (byte)(Charter.Length % 256); + bytes[i++] = (byte)((Charter.Length >> 8) % 256); + Buffer.BlockCopy(Charter, 0, bytes, i, Charter.Length); i += Charter.Length; + bytes[i++] = (byte)((ShowInList) ? 1 : 0); + InsigniaID.ToBytes(bytes, i); i += 16; + Utils.IntToBytes(MembershipFee, bytes, i); i += 4; + bytes[i++] = (byte)((OpenEnrollment) ? 1 : 0); + bytes[i++] = (byte)((AllowPublish) ? 1 : 0); + bytes[i++] = (byte)((MaturePublish) ? 1 : 0); + } + + } + + public override int Length + { + get + { + int length = 10; + length += AgentData.Length; + length += GroupData.Length; + return length; + } + } + public AgentDataBlock AgentData; + public GroupDataBlock GroupData; + + public CreateGroupRequestExtendedPacket() + { + HasVariableBlocks = false; + Type = PacketType.CreateGroupRequestExtended; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 429; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + GroupData = new GroupDataBlock(); + } + + public CreateGroupRequestExtendedPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + GroupData.FromBytes(bytes, ref i); + } + + public CreateGroupRequestExtendedPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + GroupData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += AgentData.Length; + length += GroupData.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class PacketAckPacket : Packet + { + public override bool UsesBufferPooling + { + get + { + return true; + } + } + + /// + public sealed class PacketsBlock : PacketBlock + { + public uint ID; + + public override int Length + { + get + { + return 4; + } + } + + public PacketsBlock() { } + public PacketsBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + ID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UIntToBytes(ID, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 11; + for (int j = 0; j < Packets.Length; j++) + length += Packets[j].Length; + return length; + } + } + public PacketsBlock[] Packets; + + public PacketAckPacket() + { + HasVariableBlocks = true; + Type = PacketType.PacketAck; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 65531; + Header.Reliable = true; + Packets = null; + } + + public PacketAckPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + int count = (int)bytes[i++]; + if(Packets == null || Packets.Length != -1) { + Packets = new PacketsBlock[count]; + for(int j = 0; j < count; j++) + { Packets[j] = new PacketsBlock(); } + } + for (int j = 0; j < count; j++) + { Packets[j].FromBytes(bytes, ref i); } + } + + public PacketAckPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + int count = (int)bytes[i++]; + if(Packets == null || Packets.Length != count) { + Packets = new PacketsBlock[count]; + for(int j = 0; j < count; j++) + { Packets[j] = new PacketsBlock(); } + } + for (int j = 0; j < count; j++) + { Packets[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 10; + length++; + for (int j = 0; j < Packets.Length; j++) { length += Packets[j].Length; } + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int PacketsStart = 0; + do + { + int variableLength = 0; + int PacketsCount = 0; + + i = PacketsStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < Packets.Length) { + int blockLength = Packets[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == PacketsStart) { + variableLength += blockLength; + ++PacketsCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)PacketsCount; + for (i = PacketsStart; i < PacketsStart + PacketsCount; i++) { Packets[i].ToBytes(packet, ref length); } + PacketsStart += PacketsCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + PacketsStart < Packets.Length); + + return packets.ToArray(); + } + + public override byte[] ToBytes(Interfaces.IByteBufferPool pool, ref int size) + { + int length = 10; + length++; + for (int j = 0; j < Packets.Length; j++) { length += Packets[j].Length; } + if (Header.AckList != null && Header.AckList.Length > 0) { length += Header.AckList.Length * 4 + 1; } + byte[] bytes = pool.LeaseBytes(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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + + size = length; + return bytes; + } + + public override byte[][] ToBytesMultiple(Interfaces.IByteBufferPool pool, out int[] sizes) + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + System.Collections.Generic.List retSizes = new System.Collections.Generic.List(); + + int i = 0; + int fixedLength = 10; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) + { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int PacketsStart = 0; + do + { + int variableLength = 0; + int PacketsCount = 0; + + i = PacketsStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < Packets.Length) + { + int blockLength = Packets[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU) + { + variableLength += blockLength; + ++PacketsCount; + } + else { break; } + ++i; + } + + int packetSize = fixedLength + variableLength + acksLength; + byte[] packet = pool.LeaseBytes(packetSize); + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)PacketsCount; + for (i = PacketsStart; i < PacketsStart + PacketsCount; i++) { Packets[i].ToBytes(packet, ref length); } + PacketsStart += PacketsCount; + + if (acksLength > 0) + { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + retSizes.Add(packetSize); + packets.Add(packet); + } while ( + PacketsStart < Packets.Length); + + sizes = retSizes.ToArray(); + return packets.ToArray(); + } + + } + + /// + public sealed class OpenCircuitPacket : Packet + { + /// + public sealed class CircuitInfoBlock : PacketBlock + { + public uint IP; + public ushort Port; + + public override int Length + { + get + { + return 6; + } + } + + public CircuitInfoBlock() { } + public CircuitInfoBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(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(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UIntToBytes(IP, bytes, i); i += 4; + bytes[i++] = (byte)((Port >> 8) % 256); + bytes[i++] = (byte)(Port % 256); + } + + } + + public override int Length + { + get + { + int length = 10; + length += CircuitInfo.Length; + return length; + } + } + public CircuitInfoBlock CircuitInfo; + + public OpenCircuitPacket() + { + HasVariableBlocks = false; + Type = PacketType.OpenCircuit; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 65532; + Header.Reliable = true; + CircuitInfo = new CircuitInfoBlock(); + } + + public OpenCircuitPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + CircuitInfo.FromBytes(bytes, ref i); + } + + public OpenCircuitPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + CircuitInfo.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 10; + length += CircuitInfo.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class CloseCircuitPacket : Packet + { + public override int Length + { + get + { + int length = 10; + return length; + } + } + + public CloseCircuitPacket() + { + HasVariableBlocks = false; + Type = PacketType.CloseCircuit; + Header = new Header(); + Header.Frequency = PacketFrequency.Low; + Header.ID = 65533; + Header.Reliable = true; + } + + public CloseCircuitPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + } + + public CloseCircuitPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + } + + public override byte[] ToBytes() + { + int length = 10; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class ObjectAddPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + public UUID GroupID; + + public override int Length + { + get + { + return 48; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + GroupID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + GroupID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class ObjectDataBlock : PacketBlock + { + public byte PCode; + public byte Material; + public uint AddFlags; + public byte PathCurve; + public byte ProfileCurve; + public ushort PathBegin; + public ushort PathEnd; + public byte PathScaleX; + public byte PathScaleY; + public byte PathShearX; + public byte PathShearY; + public sbyte PathTwist; + public sbyte PathTwistBegin; + public sbyte PathRadiusOffset; + public sbyte PathTaperX; + public sbyte PathTaperY; + public byte PathRevolutions; + public sbyte PathSkew; + public ushort ProfileBegin; + public ushort ProfileEnd; + public ushort ProfileHollow; + public byte BypassRaycast; + public Vector3 RayStart; + public Vector3 RayEnd; + public UUID RayTargetID; + public byte RayEndIsIntersection; + public Vector3 Scale; + public Quaternion Rotation; + public byte State; + + public override int Length + { + get + { + return 96; + } + } + + public ObjectDataBlock() { } + public ObjectDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + PCode = (byte)bytes[i++]; + Material = (byte)bytes[i++]; + AddFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + PathCurve = (byte)bytes[i++]; + ProfileCurve = (byte)bytes[i++]; + PathBegin = (ushort)(bytes[i++] + (bytes[i++] << 8)); + PathEnd = (ushort)(bytes[i++] + (bytes[i++] << 8)); + PathScaleX = (byte)bytes[i++]; + PathScaleY = (byte)bytes[i++]; + PathShearX = (byte)bytes[i++]; + PathShearY = (byte)bytes[i++]; + PathTwist = (sbyte)bytes[i++]; + PathTwistBegin = (sbyte)bytes[i++]; + PathRadiusOffset = (sbyte)bytes[i++]; + PathTaperX = (sbyte)bytes[i++]; + PathTaperY = (sbyte)bytes[i++]; + PathRevolutions = (byte)bytes[i++]; + PathSkew = (sbyte)bytes[i++]; + ProfileBegin = (ushort)(bytes[i++] + (bytes[i++] << 8)); + ProfileEnd = (ushort)(bytes[i++] + (bytes[i++] << 8)); + ProfileHollow = (ushort)(bytes[i++] + (bytes[i++] << 8)); + BypassRaycast = (byte)bytes[i++]; + RayStart.FromBytes(bytes, i); i += 12; + RayEnd.FromBytes(bytes, i); i += 12; + RayTargetID.FromBytes(bytes, i); i += 16; + RayEndIsIntersection = (byte)bytes[i++]; + Scale.FromBytes(bytes, i); i += 12; + Rotation.FromBytes(bytes, i, true); i += 12; + State = (byte)bytes[i++]; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + bytes[i++] = PCode; + bytes[i++] = Material; + Utils.UIntToBytes(AddFlags, bytes, i); i += 4; + bytes[i++] = PathCurve; + bytes[i++] = ProfileCurve; + bytes[i++] = (byte)(PathBegin % 256); + bytes[i++] = (byte)((PathBegin >> 8) % 256); + bytes[i++] = (byte)(PathEnd % 256); + bytes[i++] = (byte)((PathEnd >> 8) % 256); + bytes[i++] = PathScaleX; + bytes[i++] = PathScaleY; + bytes[i++] = PathShearX; + bytes[i++] = PathShearY; + bytes[i++] = (byte)PathTwist; + bytes[i++] = (byte)PathTwistBegin; + bytes[i++] = (byte)PathRadiusOffset; + bytes[i++] = (byte)PathTaperX; + bytes[i++] = (byte)PathTaperY; + bytes[i++] = PathRevolutions; + bytes[i++] = (byte)PathSkew; + bytes[i++] = (byte)(ProfileBegin % 256); + bytes[i++] = (byte)((ProfileBegin >> 8) % 256); + bytes[i++] = (byte)(ProfileEnd % 256); + bytes[i++] = (byte)((ProfileEnd >> 8) % 256); + bytes[i++] = (byte)(ProfileHollow % 256); + bytes[i++] = (byte)((ProfileHollow >> 8) % 256); + bytes[i++] = BypassRaycast; + RayStart.ToBytes(bytes, i); i += 12; + RayEnd.ToBytes(bytes, i); i += 12; + RayTargetID.ToBytes(bytes, i); i += 16; + bytes[i++] = RayEndIsIntersection; + Scale.ToBytes(bytes, i); i += 12; + Rotation.ToBytes(bytes, i); i += 12; + bytes[i++] = State; + } + + } + + public override int Length + { + get + { + int length = 8; + length += AgentData.Length; + length += ObjectData.Length; + return length; + } + } + public AgentDataBlock AgentData; + public ObjectDataBlock ObjectData; + + public ObjectAddPacket() + { + HasVariableBlocks = false; + Type = PacketType.ObjectAdd; + Header = new Header(); + Header.Frequency = PacketFrequency.Medium; + Header.ID = 1; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + ObjectData = new ObjectDataBlock(); + } + + public ObjectAddPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + ObjectData.FromBytes(bytes, ref i); + } + + public ObjectAddPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + ObjectData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 8; + length += AgentData.Length; + length += ObjectData.Length; + if (Header.AckList != null && 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); + ObjectData.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class MultipleObjectUpdatePacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class ObjectDataBlock : PacketBlock + { + public uint ObjectLocalID; + public byte Type; + public byte[] Data; + + public override int Length + { + get + { + int length = 6; + if (Data != null) { length += Data.Length; } + return length; + } + } + + public ObjectDataBlock() { } + public ObjectDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + ObjectLocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + Type = (byte)bytes[i++]; + length = bytes[i++]; + Data = new byte[length]; + Buffer.BlockCopy(bytes, i, Data, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UIntToBytes(ObjectLocalID, bytes, i); i += 4; + bytes[i++] = Type; + bytes[i++] = (byte)Data.Length; + Buffer.BlockCopy(Data, 0, bytes, i, Data.Length); i += Data.Length; + } + + } + + public override int Length + { + get + { + int length = 9; + length += AgentData.Length; + for (int j = 0; j < ObjectData.Length; j++) + length += ObjectData[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public ObjectDataBlock[] ObjectData; + + public MultipleObjectUpdatePacket() + { + HasVariableBlocks = true; + Type = PacketType.MultipleObjectUpdate; + Header = new Header(); + Header.Frequency = PacketFrequency.Medium; + Header.ID = 2; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + ObjectData = null; + } + + public MultipleObjectUpdatePacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ObjectData == null || ObjectData.Length != -1) { + ObjectData = new ObjectDataBlock[count]; + for(int j = 0; j < count; j++) + { ObjectData[j] = new ObjectDataBlock(); } + } + for (int j = 0; j < count; j++) + { ObjectData[j].FromBytes(bytes, ref i); } + } + + public MultipleObjectUpdatePacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ObjectData == null || ObjectData.Length != count) { + ObjectData = new ObjectDataBlock[count]; + for(int j = 0; j < count; j++) + { ObjectData[j] = new ObjectDataBlock(); } + } + for (int j = 0; j < count; j++) + { ObjectData[j].FromBytes(bytes, ref i); } + } + + 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 != null && 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)ObjectData.Length; + for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 8; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int ObjectDataStart = 0; + do + { + int variableLength = 0; + int ObjectDataCount = 0; + + i = ObjectDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < ObjectData.Length) { + int blockLength = ObjectData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ObjectDataStart) { + variableLength += blockLength; + ++ObjectDataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)ObjectDataCount; + for (i = ObjectDataStart; i < ObjectDataStart + ObjectDataCount; i++) { ObjectData[i].ToBytes(packet, ref length); } + ObjectDataStart += ObjectDataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + ObjectDataStart < ObjectData.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class RequestMultipleObjectsPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class ObjectDataBlock : PacketBlock + { + public byte CacheMissType; + public uint ID; + + public override int Length + { + get + { + return 5; + } + } + + public ObjectDataBlock() { } + public ObjectDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + CacheMissType = (byte)bytes[i++]; + ID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + bytes[i++] = CacheMissType; + Utils.UIntToBytes(ID, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 9; + length += AgentData.Length; + for (int j = 0; j < ObjectData.Length; j++) + length += ObjectData[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public ObjectDataBlock[] ObjectData; + + public RequestMultipleObjectsPacket() + { + HasVariableBlocks = true; + Type = PacketType.RequestMultipleObjects; + Header = new Header(); + Header.Frequency = PacketFrequency.Medium; + Header.ID = 3; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + ObjectData = null; + } + + public RequestMultipleObjectsPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ObjectData == null || ObjectData.Length != -1) { + ObjectData = new ObjectDataBlock[count]; + for(int j = 0; j < count; j++) + { ObjectData[j] = new ObjectDataBlock(); } + } + for (int j = 0; j < count; j++) + { ObjectData[j].FromBytes(bytes, ref i); } + } + + public RequestMultipleObjectsPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ObjectData == null || ObjectData.Length != count) { + ObjectData = new ObjectDataBlock[count]; + for(int j = 0; j < count; j++) + { ObjectData[j] = new ObjectDataBlock(); } + } + for (int j = 0; j < count; j++) + { ObjectData[j].FromBytes(bytes, ref i); } + } + + 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 != null && 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)ObjectData.Length; + for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 8; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int ObjectDataStart = 0; + do + { + int variableLength = 0; + int ObjectDataCount = 0; + + i = ObjectDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < ObjectData.Length) { + int blockLength = ObjectData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ObjectDataStart) { + variableLength += blockLength; + ++ObjectDataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)ObjectDataCount; + for (i = ObjectDataStart; i < ObjectDataStart + ObjectDataCount; i++) { ObjectData[i].ToBytes(packet, ref length); } + ObjectDataStart += ObjectDataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + ObjectDataStart < ObjectData.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class ObjectPositionPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class ObjectDataBlock : PacketBlock + { + public uint ObjectLocalID; + public Vector3 Position; + + public override int Length + { + get + { + return 16; + } + } + + public ObjectDataBlock() { } + public ObjectDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + ObjectLocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + Position.FromBytes(bytes, i); i += 12; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UIntToBytes(ObjectLocalID, bytes, i); i += 4; + Position.ToBytes(bytes, i); i += 12; + } + + } + + public override int Length + { + get + { + int length = 9; + length += AgentData.Length; + for (int j = 0; j < ObjectData.Length; j++) + length += ObjectData[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public ObjectDataBlock[] ObjectData; + + public ObjectPositionPacket() + { + HasVariableBlocks = true; + Type = PacketType.ObjectPosition; + Header = new Header(); + Header.Frequency = PacketFrequency.Medium; + Header.ID = 4; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + ObjectData = null; + } + + public ObjectPositionPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ObjectData == null || ObjectData.Length != -1) { + ObjectData = new ObjectDataBlock[count]; + for(int j = 0; j < count; j++) + { ObjectData[j] = new ObjectDataBlock(); } + } + for (int j = 0; j < count; j++) + { ObjectData[j].FromBytes(bytes, ref i); } + } + + public ObjectPositionPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ObjectData == null || ObjectData.Length != count) { + ObjectData = new ObjectDataBlock[count]; + for(int j = 0; j < count; j++) + { ObjectData[j] = new ObjectDataBlock(); } + } + for (int j = 0; j < count; j++) + { ObjectData[j].FromBytes(bytes, ref i); } + } + + 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 != null && 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)ObjectData.Length; + for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 8; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int ObjectDataStart = 0; + do + { + int variableLength = 0; + int ObjectDataCount = 0; + + i = ObjectDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < ObjectData.Length) { + int blockLength = ObjectData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ObjectDataStart) { + variableLength += blockLength; + ++ObjectDataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)ObjectDataCount; + for (i = ObjectDataStart; i < ObjectDataStart + ObjectDataCount; i++) { ObjectData[i].ToBytes(packet, ref length); } + ObjectDataStart += ObjectDataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + ObjectDataStart < ObjectData.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class RequestObjectPropertiesFamilyPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class ObjectDataBlock : PacketBlock + { + public uint RequestFlags; + public UUID ObjectID; + + public override int Length + { + get + { + return 20; + } + } + + public ObjectDataBlock() { } + public ObjectDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + RequestFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + ObjectID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UIntToBytes(RequestFlags, bytes, i); i += 4; + ObjectID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 8; + length += AgentData.Length; + length += ObjectData.Length; + return length; + } + } + public AgentDataBlock AgentData; + public ObjectDataBlock ObjectData; + + public RequestObjectPropertiesFamilyPacket() + { + HasVariableBlocks = false; + Type = PacketType.RequestObjectPropertiesFamily; + Header = new Header(); + Header.Frequency = PacketFrequency.Medium; + Header.ID = 5; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + ObjectData = new ObjectDataBlock(); + } + + public RequestObjectPropertiesFamilyPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + ObjectData.FromBytes(bytes, ref i); + } + + public RequestObjectPropertiesFamilyPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + ObjectData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 8; + length += AgentData.Length; + length += ObjectData.Length; + if (Header.AckList != null && 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); + ObjectData.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class CoarseLocationUpdatePacket : Packet + { + /// + public sealed class LocationBlock : PacketBlock + { + public byte X; + public byte Y; + public byte Z; + + public override int Length + { + get + { + return 3; + } + } + + public LocationBlock() { } + public LocationBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + X = (byte)bytes[i++]; + Y = (byte)bytes[i++]; + Z = (byte)bytes[i++]; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + bytes[i++] = X; + bytes[i++] = Y; + bytes[i++] = Z; + } + + } + + /// + public sealed class IndexBlock : PacketBlock + { + public short You; + public short Prey; + + public override int Length + { + get + { + return 4; + } + } + + public IndexBlock() { } + public IndexBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(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(); + } + } + + public override 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); + } + + } + + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + + public override int Length + { + get + { + return 16; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 10; + for (int j = 0; j < Location.Length; j++) + length += Location[j].Length; + length += Index.Length; + for (int j = 0; j < AgentData.Length; j++) + length += AgentData[j].Length; + return length; + } + } + public LocationBlock[] Location; + public IndexBlock Index; + public AgentDataBlock[] AgentData; + + public CoarseLocationUpdatePacket() + { + HasVariableBlocks = true; + Type = PacketType.CoarseLocationUpdate; + Header = new Header(); + Header.Frequency = PacketFrequency.Medium; + Header.ID = 6; + Header.Reliable = true; + Location = null; + Index = new IndexBlock(); + AgentData = null; + } + + public CoarseLocationUpdatePacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + int count = (int)bytes[i++]; + if(Location == null || Location.Length != -1) { + Location = new LocationBlock[count]; + for(int j = 0; j < count; j++) + { Location[j] = new LocationBlock(); } + } + for (int j = 0; j < count; j++) + { Location[j].FromBytes(bytes, ref i); } + Index.FromBytes(bytes, ref i); + count = (int)bytes[i++]; + if(AgentData == null || AgentData.Length != -1) { + AgentData = new AgentDataBlock[count]; + for(int j = 0; j < count; j++) + { AgentData[j] = new AgentDataBlock(); } + } + for (int j = 0; j < count; j++) + { AgentData[j].FromBytes(bytes, ref i); } + } + + public CoarseLocationUpdatePacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + int count = (int)bytes[i++]; + if(Location == null || Location.Length != count) { + Location = new LocationBlock[count]; + for(int j = 0; j < count; j++) + { Location[j] = new LocationBlock(); } + } + for (int j = 0; j < count; j++) + { Location[j].FromBytes(bytes, ref i); } + Index.FromBytes(bytes, ref i); + count = (int)bytes[i++]; + if(AgentData == null || AgentData.Length != count) { + AgentData = new AgentDataBlock[count]; + for(int j = 0; j < count; j++) + { AgentData[j] = new AgentDataBlock(); } + } + for (int j = 0; j < count; j++) + { AgentData[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 8; + length += Index.Length; + length++; + for (int j = 0; j < Location.Length; j++) { length += Location[j].Length; } + length++; + for (int j = 0; j < AgentData.Length; j++) { length += AgentData[j].Length; } + if (Header.AckList != null && 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); + bytes[i++] = (byte)AgentData.Length; + for (int j = 0; j < AgentData.Length; j++) { AgentData[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class CrossedRegionPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class RegionDataBlock : PacketBlock + { + public uint SimIP; + public ushort SimPort; + public ulong RegionHandle; + public byte[] SeedCapability; + + public override int Length + { + get + { + int length = 16; + if (SeedCapability != null) { length += SeedCapability.Length; } + return length; + } + } + + public RegionDataBlock() { } + public RegionDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + SimIP = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + 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)); + length = (bytes[i++] + (bytes[i++] << 8)); + SeedCapability = new byte[length]; + Buffer.BlockCopy(bytes, i, SeedCapability, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UIntToBytes(SimIP, bytes, i); i += 4; + bytes[i++] = (byte)((SimPort >> 8) % 256); + bytes[i++] = (byte)(SimPort % 256); + Utils.UInt64ToBytes(RegionHandle, bytes, i); i += 8; + bytes[i++] = (byte)(SeedCapability.Length % 256); + bytes[i++] = (byte)((SeedCapability.Length >> 8) % 256); + Buffer.BlockCopy(SeedCapability, 0, bytes, i, SeedCapability.Length); i += SeedCapability.Length; + } + + } + + /// + public sealed class InfoBlock : PacketBlock + { + public Vector3 Position; + public Vector3 LookAt; + + public override int Length + { + get + { + return 24; + } + } + + public InfoBlock() { } + public InfoBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + Position.FromBytes(bytes, i); i += 12; + LookAt.FromBytes(bytes, i); i += 12; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Position.ToBytes(bytes, i); i += 12; + LookAt.ToBytes(bytes, i); i += 12; + } + + } + + public override int Length + { + get + { + int length = 8; + length += AgentData.Length; + length += RegionData.Length; + length += Info.Length; + return length; + } + } + public AgentDataBlock AgentData; + public RegionDataBlock RegionData; + public InfoBlock Info; + + public CrossedRegionPacket() + { + HasVariableBlocks = false; + Type = PacketType.CrossedRegion; + Header = new Header(); + Header.Frequency = PacketFrequency.Medium; + Header.ID = 7; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + RegionData = new RegionDataBlock(); + Info = new InfoBlock(); + } + + public CrossedRegionPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + RegionData.FromBytes(bytes, ref i); + Info.FromBytes(bytes, ref i); + } + + public CrossedRegionPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + RegionData.FromBytes(bytes, ref i); + Info.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 8; + length += AgentData.Length; + length += RegionData.Length; + length += Info.Length; + if (Header.AckList != null && 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); + RegionData.ToBytes(bytes, ref i); + Info.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class ConfirmEnableSimulatorPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 8; + length += AgentData.Length; + return length; + } + } + public AgentDataBlock AgentData; + + public ConfirmEnableSimulatorPacket() + { + HasVariableBlocks = false; + Type = PacketType.ConfirmEnableSimulator; + Header = new Header(); + Header.Frequency = PacketFrequency.Medium; + Header.ID = 8; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + } + + public ConfirmEnableSimulatorPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + } + + public ConfirmEnableSimulatorPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 8; + length += AgentData.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class ObjectPropertiesPacket : Packet + { + /// + public sealed class ObjectDataBlock : PacketBlock + { + public UUID ObjectID; + public UUID CreatorID; + public UUID OwnerID; + public UUID GroupID; + public ulong CreationDate; + public uint BaseMask; + public uint OwnerMask; + public uint GroupMask; + public uint EveryoneMask; + public uint NextOwnerMask; + public int OwnershipCost; + public byte SaleType; + public int SalePrice; + public byte AggregatePerms; + public byte AggregatePermTextures; + public byte AggregatePermTexturesOwner; + public uint Category; + public short InventorySerial; + public UUID ItemID; + public UUID FolderID; + public UUID FromTaskID; + public UUID LastOwnerID; + public byte[] Name; + public byte[] Description; + public byte[] TouchName; + public byte[] SitName; + public byte[] TextureID; + + public override int Length + { + get + { + int length = 179; + if (Name != null) { length += Name.Length; } + if (Description != null) { length += Description.Length; } + if (TouchName != null) { length += TouchName.Length; } + if (SitName != null) { length += SitName.Length; } + if (TextureID != null) { length += TextureID.Length; } + return length; + } + } + + public ObjectDataBlock() { } + public ObjectDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + ObjectID.FromBytes(bytes, i); i += 16; + CreatorID.FromBytes(bytes, i); i += 16; + OwnerID.FromBytes(bytes, i); i += 16; + GroupID.FromBytes(bytes, i); i += 16; + CreationDate = (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)); + BaseMask = (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)); + GroupMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + 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)); + OwnershipCost = (int)(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)); + AggregatePerms = (byte)bytes[i++]; + AggregatePermTextures = (byte)bytes[i++]; + AggregatePermTexturesOwner = (byte)bytes[i++]; + Category = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + InventorySerial = (short)(bytes[i++] + (bytes[i++] << 8)); + ItemID.FromBytes(bytes, i); i += 16; + FolderID.FromBytes(bytes, i); i += 16; + FromTaskID.FromBytes(bytes, i); i += 16; + LastOwnerID.FromBytes(bytes, i); i += 16; + length = bytes[i++]; + Name = new byte[length]; + Buffer.BlockCopy(bytes, i, Name, 0, length); i += length; + length = bytes[i++]; + Description = new byte[length]; + Buffer.BlockCopy(bytes, i, Description, 0, length); i += length; + length = bytes[i++]; + TouchName = new byte[length]; + Buffer.BlockCopy(bytes, i, TouchName, 0, length); i += length; + length = bytes[i++]; + SitName = new byte[length]; + Buffer.BlockCopy(bytes, i, SitName, 0, length); i += length; + length = bytes[i++]; + TextureID = new byte[length]; + Buffer.BlockCopy(bytes, i, TextureID, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + ObjectID.ToBytes(bytes, i); i += 16; + CreatorID.ToBytes(bytes, i); i += 16; + OwnerID.ToBytes(bytes, i); i += 16; + GroupID.ToBytes(bytes, i); i += 16; + Utils.UInt64ToBytes(CreationDate, bytes, i); i += 8; + Utils.UIntToBytes(BaseMask, bytes, i); i += 4; + Utils.UIntToBytes(OwnerMask, bytes, i); i += 4; + Utils.UIntToBytes(GroupMask, bytes, i); i += 4; + Utils.UIntToBytes(EveryoneMask, bytes, i); i += 4; + Utils.UIntToBytes(NextOwnerMask, bytes, i); i += 4; + Utils.IntToBytes(OwnershipCost, bytes, i); i += 4; + bytes[i++] = SaleType; + Utils.IntToBytes(SalePrice, bytes, i); i += 4; + bytes[i++] = AggregatePerms; + bytes[i++] = AggregatePermTextures; + bytes[i++] = AggregatePermTexturesOwner; + Utils.UIntToBytes(Category, bytes, i); i += 4; + bytes[i++] = (byte)(InventorySerial % 256); + bytes[i++] = (byte)((InventorySerial >> 8) % 256); + ItemID.ToBytes(bytes, i); i += 16; + FolderID.ToBytes(bytes, i); i += 16; + FromTaskID.ToBytes(bytes, i); i += 16; + LastOwnerID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)Name.Length; + Buffer.BlockCopy(Name, 0, bytes, i, Name.Length); i += Name.Length; + bytes[i++] = (byte)Description.Length; + Buffer.BlockCopy(Description, 0, bytes, i, Description.Length); i += Description.Length; + bytes[i++] = (byte)TouchName.Length; + Buffer.BlockCopy(TouchName, 0, bytes, i, TouchName.Length); i += TouchName.Length; + bytes[i++] = (byte)SitName.Length; + Buffer.BlockCopy(SitName, 0, bytes, i, SitName.Length); i += SitName.Length; + bytes[i++] = (byte)TextureID.Length; + Buffer.BlockCopy(TextureID, 0, bytes, i, TextureID.Length); i += TextureID.Length; + } + + } + + public override int Length + { + get + { + int length = 9; + for (int j = 0; j < ObjectData.Length; j++) + length += ObjectData[j].Length; + return length; + } + } + public ObjectDataBlock[] ObjectData; + + public ObjectPropertiesPacket() + { + HasVariableBlocks = true; + Type = PacketType.ObjectProperties; + Header = new Header(); + Header.Frequency = PacketFrequency.Medium; + Header.ID = 9; + Header.Reliable = true; + Header.Zerocoded = true; + ObjectData = null; + } + + public ObjectPropertiesPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + int count = (int)bytes[i++]; + if(ObjectData == null || ObjectData.Length != -1) { + ObjectData = new ObjectDataBlock[count]; + for(int j = 0; j < count; j++) + { ObjectData[j] = new ObjectDataBlock(); } + } + for (int j = 0; j < count; j++) + { ObjectData[j].FromBytes(bytes, ref i); } + } + + public ObjectPropertiesPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + int count = (int)bytes[i++]; + if(ObjectData == null || ObjectData.Length != count) { + ObjectData = new ObjectDataBlock[count]; + for(int j = 0; j < count; j++) + { ObjectData[j] = new ObjectDataBlock(); } + } + for (int j = 0; j < count; j++) + { ObjectData[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 8; + length++; + for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 8; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int ObjectDataStart = 0; + do + { + int variableLength = 0; + int ObjectDataCount = 0; + + i = ObjectDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < ObjectData.Length) { + int blockLength = ObjectData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ObjectDataStart) { + variableLength += blockLength; + ++ObjectDataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)ObjectDataCount; + for (i = ObjectDataStart; i < ObjectDataStart + ObjectDataCount; i++) { ObjectData[i].ToBytes(packet, ref length); } + ObjectDataStart += ObjectDataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + ObjectDataStart < ObjectData.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class ObjectPropertiesFamilyPacket : Packet + { + /// + public sealed class ObjectDataBlock : PacketBlock + { + public uint RequestFlags; + public UUID ObjectID; + public UUID OwnerID; + public UUID GroupID; + public uint BaseMask; + public uint OwnerMask; + public uint GroupMask; + public uint EveryoneMask; + public uint NextOwnerMask; + public int OwnershipCost; + public byte SaleType; + public int SalePrice; + public uint Category; + public UUID LastOwnerID; + public byte[] Name; + public byte[] Description; + + public override int Length + { + get + { + int length = 103; + if (Name != null) { length += Name.Length; } + if (Description != null) { length += Description.Length; } + return length; + } + } + + public ObjectDataBlock() { } + public ObjectDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + RequestFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + ObjectID.FromBytes(bytes, i); i += 16; + OwnerID.FromBytes(bytes, i); i += 16; + GroupID.FromBytes(bytes, i); i += 16; + BaseMask = (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)); + GroupMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + 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)); + OwnershipCost = (int)(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)); + Category = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + LastOwnerID.FromBytes(bytes, i); i += 16; + length = bytes[i++]; + Name = new byte[length]; + Buffer.BlockCopy(bytes, i, Name, 0, length); i += length; + length = bytes[i++]; + Description = new byte[length]; + Buffer.BlockCopy(bytes, i, Description, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UIntToBytes(RequestFlags, bytes, i); i += 4; + ObjectID.ToBytes(bytes, i); i += 16; + OwnerID.ToBytes(bytes, i); i += 16; + GroupID.ToBytes(bytes, i); i += 16; + Utils.UIntToBytes(BaseMask, bytes, i); i += 4; + Utils.UIntToBytes(OwnerMask, bytes, i); i += 4; + Utils.UIntToBytes(GroupMask, bytes, i); i += 4; + Utils.UIntToBytes(EveryoneMask, bytes, i); i += 4; + Utils.UIntToBytes(NextOwnerMask, bytes, i); i += 4; + Utils.IntToBytes(OwnershipCost, bytes, i); i += 4; + bytes[i++] = SaleType; + Utils.IntToBytes(SalePrice, bytes, i); i += 4; + Utils.UIntToBytes(Category, bytes, i); i += 4; + LastOwnerID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)Name.Length; + Buffer.BlockCopy(Name, 0, bytes, i, Name.Length); i += Name.Length; + bytes[i++] = (byte)Description.Length; + Buffer.BlockCopy(Description, 0, bytes, i, Description.Length); i += Description.Length; + } + + } + + public override int Length + { + get + { + int length = 8; + length += ObjectData.Length; + return length; + } + } + public ObjectDataBlock ObjectData; + + public ObjectPropertiesFamilyPacket() + { + HasVariableBlocks = false; + Type = PacketType.ObjectPropertiesFamily; + Header = new Header(); + Header.Frequency = PacketFrequency.Medium; + Header.ID = 10; + Header.Reliable = true; + Header.Zerocoded = true; + ObjectData = new ObjectDataBlock(); + } + + public ObjectPropertiesFamilyPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + ObjectData.FromBytes(bytes, ref i); + } + + public ObjectPropertiesFamilyPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + ObjectData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 8; + length += ObjectData.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class ParcelPropertiesRequestPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class ParcelDataBlock : PacketBlock + { + public int SequenceID; + public float West; + public float South; + public float East; + public float North; + public bool SnapSelection; + + public override int Length + { + get + { + return 21; + } + } + + public ParcelDataBlock() { } + public ParcelDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + SequenceID = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + West = Utils.BytesToFloat(bytes, i); i += 4; + South = Utils.BytesToFloat(bytes, i); i += 4; + East = Utils.BytesToFloat(bytes, i); i += 4; + North = Utils.BytesToFloat(bytes, i); i += 4; + SnapSelection = (bytes[i++] != 0) ? (bool)true : (bool)false; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.IntToBytes(SequenceID, bytes, i); i += 4; + Utils.FloatToBytes(West, bytes, i); i += 4; + Utils.FloatToBytes(South, bytes, i); i += 4; + Utils.FloatToBytes(East, bytes, i); i += 4; + Utils.FloatToBytes(North, bytes, i); i += 4; + bytes[i++] = (byte)((SnapSelection) ? 1 : 0); + } + + } + + public override int Length + { + get + { + int length = 8; + length += AgentData.Length; + length += ParcelData.Length; + return length; + } + } + public AgentDataBlock AgentData; + public ParcelDataBlock ParcelData; + + public ParcelPropertiesRequestPacket() + { + HasVariableBlocks = false; + Type = PacketType.ParcelPropertiesRequest; + Header = new Header(); + Header.Frequency = PacketFrequency.Medium; + Header.ID = 11; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + ParcelData = new ParcelDataBlock(); + } + + public ParcelPropertiesRequestPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + ParcelData.FromBytes(bytes, ref i); + } + + public ParcelPropertiesRequestPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + ParcelData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 8; + length += AgentData.Length; + length += ParcelData.Length; + if (Header.AckList != null && 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); + ParcelData.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class AttachedSoundPacket : Packet + { + /// + public sealed class DataBlockBlock : PacketBlock + { + public UUID SoundID; + public UUID ObjectID; + public UUID OwnerID; + public float Gain; + public byte Flags; + + public override int Length + { + get + { + return 53; + } + } + + public DataBlockBlock() { } + public DataBlockBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + SoundID.FromBytes(bytes, i); i += 16; + ObjectID.FromBytes(bytes, i); i += 16; + OwnerID.FromBytes(bytes, i); i += 16; + Gain = Utils.BytesToFloat(bytes, i); i += 4; + Flags = (byte)bytes[i++]; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + SoundID.ToBytes(bytes, i); i += 16; + ObjectID.ToBytes(bytes, i); i += 16; + OwnerID.ToBytes(bytes, i); i += 16; + Utils.FloatToBytes(Gain, bytes, i); i += 4; + bytes[i++] = Flags; + } + + } + + public override int Length + { + get + { + int length = 8; + length += DataBlock.Length; + return length; + } + } + public DataBlockBlock DataBlock; + + public AttachedSoundPacket() + { + HasVariableBlocks = false; + Type = PacketType.AttachedSound; + Header = new Header(); + Header.Frequency = PacketFrequency.Medium; + Header.ID = 13; + Header.Reliable = true; + DataBlock = new DataBlockBlock(); + } + + public AttachedSoundPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + DataBlock.FromBytes(bytes, ref i); + } + + public AttachedSoundPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + DataBlock.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 8; + length += DataBlock.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class AttachedSoundGainChangePacket : Packet + { + /// + public sealed class DataBlockBlock : PacketBlock + { + public UUID ObjectID; + public float Gain; + + public override int Length + { + get + { + return 20; + } + } + + public DataBlockBlock() { } + public DataBlockBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + ObjectID.FromBytes(bytes, i); i += 16; + Gain = Utils.BytesToFloat(bytes, i); i += 4; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + ObjectID.ToBytes(bytes, i); i += 16; + Utils.FloatToBytes(Gain, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 8; + length += DataBlock.Length; + return length; + } + } + public DataBlockBlock DataBlock; + + public AttachedSoundGainChangePacket() + { + HasVariableBlocks = false; + Type = PacketType.AttachedSoundGainChange; + Header = new Header(); + Header.Frequency = PacketFrequency.Medium; + Header.ID = 14; + Header.Reliable = true; + DataBlock = new DataBlockBlock(); + } + + public AttachedSoundGainChangePacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + DataBlock.FromBytes(bytes, ref i); + } + + public AttachedSoundGainChangePacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + DataBlock.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 8; + length += DataBlock.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + } + + /// + public sealed class PreloadSoundPacket : Packet + { + /// + public sealed class DataBlockBlock : PacketBlock + { + public UUID ObjectID; + public UUID OwnerID; + public UUID SoundID; + + public override int Length + { + get + { + return 48; + } + } + + public DataBlockBlock() { } + public DataBlockBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + ObjectID.FromBytes(bytes, i); i += 16; + OwnerID.FromBytes(bytes, i); i += 16; + SoundID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + ObjectID.ToBytes(bytes, i); i += 16; + OwnerID.ToBytes(bytes, i); i += 16; + SoundID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 9; + for (int j = 0; j < DataBlock.Length; j++) + length += DataBlock[j].Length; + return length; + } + } + public DataBlockBlock[] DataBlock; + + public PreloadSoundPacket() + { + HasVariableBlocks = true; + Type = PacketType.PreloadSound; + Header = new Header(); + Header.Frequency = PacketFrequency.Medium; + Header.ID = 15; + Header.Reliable = true; + DataBlock = null; + } + + public PreloadSoundPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + int count = (int)bytes[i++]; + if(DataBlock == null || DataBlock.Length != -1) { + DataBlock = new DataBlockBlock[count]; + for(int j = 0; j < count; j++) + { DataBlock[j] = new DataBlockBlock(); } + } + for (int j = 0; j < count; j++) + { DataBlock[j].FromBytes(bytes, ref i); } + } + + public PreloadSoundPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + int count = (int)bytes[i++]; + if(DataBlock == null || DataBlock.Length != count) { + DataBlock = new DataBlockBlock[count]; + for(int j = 0; j < count; j++) + { DataBlock[j] = new DataBlockBlock(); } + } + for (int j = 0; j < count; j++) + { DataBlock[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 8; + length++; + for (int j = 0; j < DataBlock.Length; j++) { length += DataBlock[j].Length; } + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 8; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int DataBlockStart = 0; + do + { + int variableLength = 0; + int DataBlockCount = 0; + + i = DataBlockStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < DataBlock.Length) { + int blockLength = DataBlock[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == DataBlockStart) { + variableLength += blockLength; + ++DataBlockCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)DataBlockCount; + for (i = DataBlockStart; i < DataBlockStart + DataBlockCount; i++) { DataBlock[i].ToBytes(packet, ref length); } + DataBlockStart += DataBlockCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + DataBlockStart < DataBlock.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class ViewerEffectPacket : Packet + { + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class EffectBlock : PacketBlock + { + public UUID ID; + public UUID AgentID; + public byte Type; + public float Duration; + public byte[] Color; + public byte[] TypeData; + + public override int Length + { + get + { + int length = 42; + if (TypeData != null) { length += TypeData.Length; } + return length; + } + } + + public EffectBlock() { } + public EffectBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + ID.FromBytes(bytes, i); i += 16; + AgentID.FromBytes(bytes, i); i += 16; + Type = (byte)bytes[i++]; + Duration = Utils.BytesToFloat(bytes, i); i += 4; + Color = new byte[4]; + Buffer.BlockCopy(bytes, i, Color, 0, 4); i += 4; + length = bytes[i++]; + TypeData = new byte[length]; + Buffer.BlockCopy(bytes, i, TypeData, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + ID.ToBytes(bytes, i); i += 16; + AgentID.ToBytes(bytes, i); i += 16; + bytes[i++] = Type; + Utils.FloatToBytes(Duration, bytes, i); i += 4; + Buffer.BlockCopy(Color, 0, bytes, i, 4);i += 4; + bytes[i++] = (byte)TypeData.Length; + Buffer.BlockCopy(TypeData, 0, bytes, i, TypeData.Length); i += TypeData.Length; + } + + } + + public override int Length + { + get + { + int length = 9; + length += AgentData.Length; + for (int j = 0; j < Effect.Length; j++) + length += Effect[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public EffectBlock[] Effect; + + public ViewerEffectPacket() + { + HasVariableBlocks = true; + Type = PacketType.ViewerEffect; + Header = new Header(); + Header.Frequency = PacketFrequency.Medium; + Header.ID = 17; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + Effect = null; + } + + public ViewerEffectPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(Effect == null || Effect.Length != -1) { + Effect = new EffectBlock[count]; + for(int j = 0; j < count; j++) + { Effect[j] = new EffectBlock(); } + } + for (int j = 0; j < count; j++) + { Effect[j].FromBytes(bytes, ref i); } + } + + public ViewerEffectPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(Effect == null || Effect.Length != count) { + Effect = new EffectBlock[count]; + for(int j = 0; j < count; j++) + { Effect[j] = new EffectBlock(); } + } + for (int j = 0; j < count; j++) + { Effect[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 8; + length += AgentData.Length; + length++; + for (int j = 0; j < Effect.Length; j++) { length += Effect[j].Length; } + if (Header.AckList != null && 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)Effect.Length; + for (int j = 0; j < Effect.Length; j++) { Effect[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 8; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int EffectStart = 0; + do + { + int variableLength = 0; + int EffectCount = 0; + + i = EffectStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < Effect.Length) { + int blockLength = Effect[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == EffectStart) { + variableLength += blockLength; + ++EffectCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)EffectCount; + for (i = EffectStart; i < EffectStart + EffectCount; i++) { Effect[i].ToBytes(packet, ref length); } + EffectStart += EffectCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + EffectStart < Effect.Length); + + return packets.ToArray(); + } + } + + /// + public sealed class StartPingCheckPacket : Packet + { + public override bool UsesBufferPooling + { + get + { + return true; + } + } + + /// + public sealed class PingIDBlock : PacketBlock + { + public byte PingID; + public uint OldestUnacked; + + public override int Length + { + get + { + return 5; + } + } + + public PingIDBlock() { } + public PingIDBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(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(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + bytes[i++] = PingID; + Utils.UIntToBytes(OldestUnacked, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 7; + length += PingID.Length; + return length; + } + } + public PingIDBlock PingID; + + public StartPingCheckPacket() + { + HasVariableBlocks = false; + Type = PacketType.StartPingCheck; + Header = new Header(); + Header.Frequency = PacketFrequency.High; + Header.ID = 1; + Header.Reliable = true; + PingID = new PingIDBlock(); + } + + public StartPingCheckPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + PingID.FromBytes(bytes, ref i); + } + + public StartPingCheckPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + PingID.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 7; + length += PingID.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + + public override byte[] ToBytes(Interfaces.IByteBufferPool pool, ref int size) + { + int length = 7; + length += PingID.Length; + if (Header.AckList != null && Header.AckList.Length > 0) { length += Header.AckList.Length * 4 + 1; } + byte[] bytes = pool.LeaseBytes(length); + int i = 0; + Header.ToBytes(bytes, ref i); + PingID.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + + size = length; + return bytes; + } + + public override byte[][] ToBytesMultiple(Interfaces.IByteBufferPool pool, out int[] sizes) + { + sizes = new int[1]; + return new byte[][] { this.ToBytes(pool, ref sizes[0]) }; + } + } + + /// + public sealed class CompletePingCheckPacket : Packet + { + public override bool UsesBufferPooling + { + get + { + return true; + } + } + + /// + public sealed class PingIDBlock : PacketBlock + { + public byte PingID; + + public override int Length + { + get + { + return 1; + } + } + + public PingIDBlock() { } + public PingIDBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + PingID = (byte)bytes[i++]; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + bytes[i++] = PingID; + } + + } + + public override int Length + { + get + { + int length = 7; + length += PingID.Length; + return length; + } + } + public PingIDBlock PingID; + + public CompletePingCheckPacket() + { + HasVariableBlocks = false; + Type = PacketType.CompletePingCheck; + Header = new Header(); + Header.Frequency = PacketFrequency.High; + Header.ID = 2; + Header.Reliable = true; + PingID = new PingIDBlock(); + } + + public CompletePingCheckPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + PingID.FromBytes(bytes, ref i); + } + + public CompletePingCheckPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + PingID.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 7; + length += PingID.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + + public override byte[] ToBytes(Interfaces.IByteBufferPool pool, ref int size) + { + int length = 7; + length += PingID.Length; + if (Header.AckList != null && Header.AckList.Length > 0) { length += Header.AckList.Length * 4 + 1; } + byte[] bytes = pool.LeaseBytes(length); + int i = 0; + Header.ToBytes(bytes, ref i); + PingID.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + + size = length; + return bytes; + } + + public override byte[][] ToBytesMultiple(Interfaces.IByteBufferPool pool, out int[] sizes) + { + sizes = new int[1]; + return new byte[][] { this.ToBytes(pool, ref sizes[0]) }; + } + } + + /// + public sealed class AgentUpdatePacket : Packet + { + public override bool UsesBufferPooling + { + get + { + return true; + } + } + + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + public Quaternion BodyRotation; + public Quaternion HeadRotation; + public byte State; + public Vector3 CameraCenter; + public Vector3 CameraAtAxis; + public Vector3 CameraLeftAxis; + public Vector3 CameraUpAxis; + public float Far; + public uint ControlFlags; + public byte Flags; + + public override int Length + { + get + { + return 114; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + BodyRotation.FromBytes(bytes, i, true); i += 12; + HeadRotation.FromBytes(bytes, i, true); i += 12; + State = (byte)bytes[i++]; + CameraCenter.FromBytes(bytes, i); i += 12; + CameraAtAxis.FromBytes(bytes, i); i += 12; + CameraLeftAxis.FromBytes(bytes, i); i += 12; + CameraUpAxis.FromBytes(bytes, i); i += 12; + Far = Utils.BytesToFloat(bytes, i); i += 4; + ControlFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + Flags = (byte)bytes[i++]; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + BodyRotation.ToBytes(bytes, i); i += 12; + HeadRotation.ToBytes(bytes, i); i += 12; + bytes[i++] = State; + CameraCenter.ToBytes(bytes, i); i += 12; + CameraAtAxis.ToBytes(bytes, i); i += 12; + CameraLeftAxis.ToBytes(bytes, i); i += 12; + CameraUpAxis.ToBytes(bytes, i); i += 12; + Utils.FloatToBytes(Far, bytes, i); i += 4; + Utils.UIntToBytes(ControlFlags, bytes, i); i += 4; + bytes[i++] = Flags; + } + + } + + public override int Length + { + get + { + int length = 7; + length += AgentData.Length; + return length; + } + } + public AgentDataBlock AgentData; + + public AgentUpdatePacket() + { + HasVariableBlocks = false; + Type = PacketType.AgentUpdate; + Header = new Header(); + Header.Frequency = PacketFrequency.High; + Header.ID = 4; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + } + + public AgentUpdatePacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + } + + public AgentUpdatePacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 7; + length += AgentData.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + + public override byte[] ToBytes(Interfaces.IByteBufferPool pool, ref int size) + { + int length = 7; + length += AgentData.Length; + if (Header.AckList != null && Header.AckList.Length > 0) { length += Header.AckList.Length * 4 + 1; } + byte[] bytes = pool.LeaseBytes(length); + int i = 0; + Header.ToBytes(bytes, ref i); + AgentData.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + + size = length; + return bytes; + } + + public override byte[][] ToBytesMultiple(Interfaces.IByteBufferPool pool, out int[] sizes) + { + sizes = new int[1]; + return new byte[][] { this.ToBytes(pool, ref sizes[0]) }; + } + } + + /// + public sealed class AgentAnimationPacket : Packet + { + public override bool UsesBufferPooling + { + get + { + return true; + } + } + + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class AnimationListBlock : PacketBlock + { + public UUID AnimID; + public bool StartAnim; + + public override int Length + { + get + { + return 17; + } + } + + public AnimationListBlock() { } + public AnimationListBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AnimID.FromBytes(bytes, i); i += 16; + StartAnim = (bytes[i++] != 0) ? (bool)true : (bool)false; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AnimID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)((StartAnim) ? 1 : 0); + } + + } + + /// + public sealed class PhysicalAvatarEventListBlock : PacketBlock + { + public byte[] TypeData; + + public override int Length + { + get + { + int length = 1; + if (TypeData != null) { length += TypeData.Length; } + return length; + } + } + + public PhysicalAvatarEventListBlock() { } + public PhysicalAvatarEventListBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + length = bytes[i++]; + TypeData = new byte[length]; + Buffer.BlockCopy(bytes, i, TypeData, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + bytes[i++] = (byte)TypeData.Length; + Buffer.BlockCopy(TypeData, 0, bytes, i, TypeData.Length); i += TypeData.Length; + } + + } + + public override int Length + { + get + { + int length = 9; + length += AgentData.Length; + for (int j = 0; j < AnimationList.Length; j++) + length += AnimationList[j].Length; + for (int j = 0; j < PhysicalAvatarEventList.Length; j++) + length += PhysicalAvatarEventList[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public AnimationListBlock[] AnimationList; + public PhysicalAvatarEventListBlock[] PhysicalAvatarEventList; + + public AgentAnimationPacket() + { + HasVariableBlocks = true; + Type = PacketType.AgentAnimation; + Header = new Header(); + Header.Frequency = PacketFrequency.High; + Header.ID = 5; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + AnimationList = null; + PhysicalAvatarEventList = null; + } + + public AgentAnimationPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(AnimationList == null || AnimationList.Length != -1) { + AnimationList = new AnimationListBlock[count]; + for(int j = 0; j < count; j++) + { AnimationList[j] = new AnimationListBlock(); } + } + for (int j = 0; j < count; j++) + { AnimationList[j].FromBytes(bytes, ref i); } + count = (int)bytes[i++]; + if(PhysicalAvatarEventList == null || PhysicalAvatarEventList.Length != -1) { + PhysicalAvatarEventList = new PhysicalAvatarEventListBlock[count]; + for(int j = 0; j < count; j++) + { PhysicalAvatarEventList[j] = new PhysicalAvatarEventListBlock(); } + } + for (int j = 0; j < count; j++) + { PhysicalAvatarEventList[j].FromBytes(bytes, ref i); } + } + + public AgentAnimationPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(AnimationList == null || AnimationList.Length != count) { + AnimationList = new AnimationListBlock[count]; + for(int j = 0; j < count; j++) + { AnimationList[j] = new AnimationListBlock(); } + } + for (int j = 0; j < count; j++) + { AnimationList[j].FromBytes(bytes, ref i); } + count = (int)bytes[i++]; + if(PhysicalAvatarEventList == null || PhysicalAvatarEventList.Length != count) { + PhysicalAvatarEventList = new PhysicalAvatarEventListBlock[count]; + for(int j = 0; j < count; j++) + { PhysicalAvatarEventList[j] = new PhysicalAvatarEventListBlock(); } + } + for (int j = 0; j < count; j++) + { PhysicalAvatarEventList[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 7; + length += AgentData.Length; + length++; + for (int j = 0; j < AnimationList.Length; j++) { length += AnimationList[j].Length; } + length++; + for (int j = 0; j < PhysicalAvatarEventList.Length; j++) { length += PhysicalAvatarEventList[j].Length; } + if (Header.AckList != null && 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)AnimationList.Length; + for (int j = 0; j < AnimationList.Length; j++) { AnimationList[j].ToBytes(bytes, ref i); } + bytes[i++] = (byte)PhysicalAvatarEventList.Length; + for (int j = 0; j < PhysicalAvatarEventList.Length; j++) { PhysicalAvatarEventList[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 7; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + fixedLength += 2; + + int AnimationListStart = 0; + int PhysicalAvatarEventListStart = 0; + do + { + int variableLength = 0; + int AnimationListCount = 0; + int PhysicalAvatarEventListCount = 0; + + i = AnimationListStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < AnimationList.Length) { + int blockLength = AnimationList[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == AnimationListStart) { + variableLength += blockLength; + ++AnimationListCount; + } + else { break; } + ++i; + } + + i = PhysicalAvatarEventListStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < PhysicalAvatarEventList.Length) { + int blockLength = PhysicalAvatarEventList[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == PhysicalAvatarEventListStart) { + variableLength += blockLength; + ++PhysicalAvatarEventListCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)AnimationListCount; + for (i = AnimationListStart; i < AnimationListStart + AnimationListCount; i++) { AnimationList[i].ToBytes(packet, ref length); } + AnimationListStart += AnimationListCount; + + packet[length++] = (byte)PhysicalAvatarEventListCount; + for (i = PhysicalAvatarEventListStart; i < PhysicalAvatarEventListStart + PhysicalAvatarEventListCount; i++) { PhysicalAvatarEventList[i].ToBytes(packet, ref length); } + PhysicalAvatarEventListStart += PhysicalAvatarEventListCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + AnimationListStart < AnimationList.Length || + PhysicalAvatarEventListStart < PhysicalAvatarEventList.Length); + + return packets.ToArray(); + } + + public override byte[] ToBytes(Interfaces.IByteBufferPool pool, ref int size) + { + int length = 7; + length += AgentData.Length; + length++; + for (int j = 0; j < AnimationList.Length; j++) { length += AnimationList[j].Length; } + length++; + for (int j = 0; j < PhysicalAvatarEventList.Length; j++) { length += PhysicalAvatarEventList[j].Length; } + if (Header.AckList != null && Header.AckList.Length > 0) { length += Header.AckList.Length * 4 + 1; } + byte[] bytes = pool.LeaseBytes(length); + int i = 0; + Header.ToBytes(bytes, ref i); + AgentData.ToBytes(bytes, ref i); + bytes[i++] = (byte)AnimationList.Length; + for (int j = 0; j < AnimationList.Length; j++) { AnimationList[j].ToBytes(bytes, ref i); } + bytes[i++] = (byte)PhysicalAvatarEventList.Length; + for (int j = 0; j < PhysicalAvatarEventList.Length; j++) { PhysicalAvatarEventList[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + + size = length; + return bytes; + } + + public override byte[][] ToBytesMultiple(Interfaces.IByteBufferPool pool, out int[] sizes) + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + System.Collections.Generic.List retSizes = new System.Collections.Generic.List(); + + int i = 0; + int fixedLength = 7; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) + { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + fixedLength += 2; + + int AnimationListStart = 0; + int PhysicalAvatarEventListStart = 0; + do + { + int variableLength = 0; + int AnimationListCount = 0; + int PhysicalAvatarEventListCount = 0; + + i = AnimationListStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < AnimationList.Length) + { + int blockLength = AnimationList[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU) + { + variableLength += blockLength; + ++AnimationListCount; + } + else { break; } + ++i; + } + + i = PhysicalAvatarEventListStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < PhysicalAvatarEventList.Length) + { + int blockLength = PhysicalAvatarEventList[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU) + { + variableLength += blockLength; + ++PhysicalAvatarEventListCount; + } + else { break; } + ++i; + } + + byte[] packet = pool.LeaseBytes(fixedLength + variableLength + acksLength); + int packetSize = fixedLength + variableLength + acksLength; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)AnimationListCount; + for (i = AnimationListStart; i < AnimationListStart + AnimationListCount; i++) { AnimationList[i].ToBytes(packet, ref length); } + AnimationListStart += AnimationListCount; + + packet[length++] = (byte)PhysicalAvatarEventListCount; + for (i = PhysicalAvatarEventListStart; i < PhysicalAvatarEventListStart + PhysicalAvatarEventListCount; i++) { PhysicalAvatarEventList[i].ToBytes(packet, ref length); } + PhysicalAvatarEventListStart += PhysicalAvatarEventListCount; + + if (acksLength > 0) + { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + retSizes.Add(packetSize); + } while ( + AnimationListStart < AnimationList.Length || + PhysicalAvatarEventListStart < PhysicalAvatarEventList.Length); + + sizes = retSizes.ToArray(); + return packets.ToArray(); + } + } + + /// + public sealed class AgentRequestSitPacket : Packet + { + public override bool UsesBufferPooling + { + get + { + return true; + } + } + + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class TargetObjectBlock : PacketBlock + { + public UUID TargetID; + public Vector3 Offset; + + public override int Length + { + get + { + return 28; + } + } + + public TargetObjectBlock() { } + public TargetObjectBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + TargetID.FromBytes(bytes, i); i += 16; + Offset.FromBytes(bytes, i); i += 12; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + TargetID.ToBytes(bytes, i); i += 16; + Offset.ToBytes(bytes, i); i += 12; + } + + } + + public override int Length + { + get + { + int length = 7; + length += AgentData.Length; + length += TargetObject.Length; + return length; + } + } + public AgentDataBlock AgentData; + public TargetObjectBlock TargetObject; + + public AgentRequestSitPacket() + { + HasVariableBlocks = false; + Type = PacketType.AgentRequestSit; + Header = new Header(); + Header.Frequency = PacketFrequency.High; + Header.ID = 6; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + TargetObject = new TargetObjectBlock(); + } + + public AgentRequestSitPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + TargetObject.FromBytes(bytes, ref i); + } + + public AgentRequestSitPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + TargetObject.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 7; + length += AgentData.Length; + length += TargetObject.Length; + if (Header.AckList != null && 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); + TargetObject.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + + public override byte[] ToBytes(Interfaces.IByteBufferPool pool, ref int size) + { + int length = 7; + length += AgentData.Length; + length += TargetObject.Length; + if (Header.AckList != null && Header.AckList.Length > 0) { length += Header.AckList.Length * 4 + 1; } + byte[] bytes = pool.LeaseBytes(length); + int i = 0; + Header.ToBytes(bytes, ref i); + AgentData.ToBytes(bytes, ref i); + TargetObject.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + + size = length; + return bytes; + } + + public override byte[][] ToBytesMultiple(Interfaces.IByteBufferPool pool, out int[] sizes) + { + sizes = new int[1]; + return new byte[][] { this.ToBytes(pool, ref sizes[0]) }; + } + } + + /// + public sealed class AgentSitPacket : Packet + { + public override bool UsesBufferPooling + { + get + { + return true; + } + } + + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 7; + length += AgentData.Length; + return length; + } + } + public AgentDataBlock AgentData; + + public AgentSitPacket() + { + HasVariableBlocks = false; + Type = PacketType.AgentSit; + Header = new Header(); + Header.Frequency = PacketFrequency.High; + Header.ID = 7; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + } + + public AgentSitPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + } + + public AgentSitPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 7; + length += AgentData.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + + public override byte[] ToBytes(Interfaces.IByteBufferPool pool, ref int size) + { + int length = 7; + length += AgentData.Length; + if (Header.AckList != null && Header.AckList.Length > 0) { length += Header.AckList.Length * 4 + 1; } + byte[] bytes = pool.LeaseBytes(length); + int i = 0; + Header.ToBytes(bytes, ref i); + AgentData.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + + size = length; + return bytes; + } + + public override byte[][] ToBytesMultiple(Interfaces.IByteBufferPool pool, out int[] sizes) + { + sizes = new int[1]; + return new byte[][] { this.ToBytes(pool, ref sizes[0]) }; + } + } + + /// + public sealed class RequestImagePacket : Packet + { + public override bool UsesBufferPooling + { + get + { + return true; + } + } + + /// + public sealed class AgentDataBlock : PacketBlock + { + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 32; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class RequestImageBlock : PacketBlock + { + public UUID Image; + public sbyte DiscardLevel; + public float DownloadPriority; + public uint Packet; + public byte Type; + + public override int Length + { + get + { + return 26; + } + } + + public RequestImageBlock() { } + public RequestImageBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + Image.FromBytes(bytes, i); i += 16; + DiscardLevel = (sbyte)bytes[i++]; + DownloadPriority = Utils.BytesToFloat(bytes, i); i += 4; + Packet = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + Type = (byte)bytes[i++]; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Image.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)DiscardLevel; + Utils.FloatToBytes(DownloadPriority, bytes, i); i += 4; + Utils.UIntToBytes(Packet, bytes, i); i += 4; + bytes[i++] = Type; + } + + } + + public override int Length + { + get + { + int length = 8; + length += AgentData.Length; + for (int j = 0; j < RequestImage.Length; j++) + length += RequestImage[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public RequestImageBlock[] RequestImage; + + public RequestImagePacket() + { + HasVariableBlocks = true; + Type = PacketType.RequestImage; + Header = new Header(); + Header.Frequency = PacketFrequency.High; + Header.ID = 8; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + RequestImage = null; + } + + public RequestImagePacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(RequestImage == null || RequestImage.Length != -1) { + RequestImage = new RequestImageBlock[count]; + for(int j = 0; j < count; j++) + { RequestImage[j] = new RequestImageBlock(); } + } + for (int j = 0; j < count; j++) + { RequestImage[j].FromBytes(bytes, ref i); } + } + + public RequestImagePacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(RequestImage == null || RequestImage.Length != count) { + RequestImage = new RequestImageBlock[count]; + for(int j = 0; j < count; j++) + { RequestImage[j] = new RequestImageBlock(); } + } + for (int j = 0; j < count; j++) + { RequestImage[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 7; + length += AgentData.Length; + length++; + for (int j = 0; j < RequestImage.Length; j++) { length += RequestImage[j].Length; } + if (Header.AckList != null && 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)RequestImage.Length; + for (int j = 0; j < RequestImage.Length; j++) { RequestImage[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 7; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int RequestImageStart = 0; + do + { + int variableLength = 0; + int RequestImageCount = 0; + + i = RequestImageStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < RequestImage.Length) { + int blockLength = RequestImage[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == RequestImageStart) { + variableLength += blockLength; + ++RequestImageCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)RequestImageCount; + for (i = RequestImageStart; i < RequestImageStart + RequestImageCount; i++) { RequestImage[i].ToBytes(packet, ref length); } + RequestImageStart += RequestImageCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + RequestImageStart < RequestImage.Length); + + return packets.ToArray(); + } + + public override byte[] ToBytes(Interfaces.IByteBufferPool pool, ref int size) + { + int length = 7; + length += AgentData.Length; + length++; + for (int j = 0; j < RequestImage.Length; j++) { length += RequestImage[j].Length; } + if (Header.AckList != null && Header.AckList.Length > 0) { length += Header.AckList.Length * 4 + 1; } + byte[] bytes = pool.LeaseBytes(length); + int i = 0; + Header.ToBytes(bytes, ref i); + AgentData.ToBytes(bytes, ref i); + bytes[i++] = (byte)RequestImage.Length; + for (int j = 0; j < RequestImage.Length; j++) { RequestImage[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + + size = length; + return bytes; + } + + public override byte[][] ToBytesMultiple(Interfaces.IByteBufferPool pool, out int[] sizes) + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + System.Collections.Generic.List retSizes = new System.Collections.Generic.List(); + + int i = 0; + int fixedLength = 7; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) + { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int RequestImageStart = 0; + do + { + int variableLength = 0; + int RequestImageCount = 0; + + i = RequestImageStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < RequestImage.Length) + { + int blockLength = RequestImage[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU) + { + variableLength += blockLength; + ++RequestImageCount; + } + else { break; } + ++i; + } + + byte[] packet = pool.LeaseBytes(fixedLength + variableLength + acksLength); + int packetSize = fixedLength + variableLength + acksLength; + + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)RequestImageCount; + for (i = RequestImageStart; i < RequestImageStart + RequestImageCount; i++) { RequestImage[i].ToBytes(packet, ref length); } + RequestImageStart += RequestImageCount; + + if (acksLength > 0) + { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + retSizes.Add(packetSize); + packets.Add(packet); + } while ( + RequestImageStart < RequestImage.Length); + + sizes = retSizes.ToArray(); + return packets.ToArray(); + } + } + + /// + public sealed class ImageDataPacket : Packet + { + public override bool UsesBufferPooling + { + get + { + return true; + } + } + + /// + public sealed class ImageIDBlock : PacketBlock + { + public UUID ID; + public byte Codec; + public uint Size; + public ushort Packets; + + public override int Length + { + get + { + return 23; + } + } + + public ImageIDBlock() { } + public ImageIDBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + ID.FromBytes(bytes, i); i += 16; + Codec = (byte)bytes[i++]; + Size = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + Packets = (ushort)(bytes[i++] + (bytes[i++] << 8)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + ID.ToBytes(bytes, i); i += 16; + bytes[i++] = Codec; + Utils.UIntToBytes(Size, bytes, i); i += 4; + bytes[i++] = (byte)(Packets % 256); + bytes[i++] = (byte)((Packets >> 8) % 256); + } + + } + + /// + public sealed class ImageDataBlock : PacketBlock + { + public byte[] Data; + + public override int Length + { + get + { + int length = 2; + if (Data != null) { length += Data.Length; } + return length; + } + } + + public ImageDataBlock() { } + public ImageDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + length = (bytes[i++] + (bytes[i++] << 8)); + Data = new byte[length]; + Buffer.BlockCopy(bytes, i, Data, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + bytes[i++] = (byte)(Data.Length % 256); + bytes[i++] = (byte)((Data.Length >> 8) % 256); + Buffer.BlockCopy(Data, 0, bytes, i, Data.Length); i += Data.Length; + } + + } + + public override int Length + { + get + { + int length = 7; + length += ImageID.Length; + length += ImageData.Length; + return length; + } + } + public ImageIDBlock ImageID; + public ImageDataBlock ImageData; + + public ImageDataPacket() + { + HasVariableBlocks = false; + Type = PacketType.ImageData; + Header = new Header(); + Header.Frequency = PacketFrequency.High; + Header.ID = 9; + Header.Reliable = true; + ImageID = new ImageIDBlock(); + ImageData = new ImageDataBlock(); + } + + public ImageDataPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + ImageID.FromBytes(bytes, ref i); + ImageData.FromBytes(bytes, ref i); + } + + public ImageDataPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + ImageID.FromBytes(bytes, ref i); + ImageData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 7; + length += ImageID.Length; + length += ImageData.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + + public override byte[] ToBytes(Interfaces.IByteBufferPool pool, ref int size) + { + int length = 7; + length += ImageID.Length; + length += ImageData.Length; + if (Header.AckList != null && Header.AckList.Length > 0) { length += Header.AckList.Length * 4 + 1; } + byte[] bytes = pool.LeaseBytes(length); + int i = 0; + Header.ToBytes(bytes, ref i); + ImageID.ToBytes(bytes, ref i); + ImageData.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + + size = length; + return bytes; + } + + public override byte[][] ToBytesMultiple(Interfaces.IByteBufferPool pool, out int[] sizes) + { + sizes = new int[1]; + return new byte[][] { this.ToBytes(pool, ref sizes[0]) }; + } + + } + + /// + public sealed class ImagePacketPacket : Packet + { + public override bool UsesBufferPooling + { + get + { + return true; + } + } + + /// + public sealed class ImageIDBlock : PacketBlock + { + public UUID ID; + public ushort Packet; + + public override int Length + { + get + { + return 18; + } + } + + public ImageIDBlock() { } + public ImageIDBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + ID.FromBytes(bytes, i); i += 16; + Packet = (ushort)(bytes[i++] + (bytes[i++] << 8)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + ID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)(Packet % 256); + bytes[i++] = (byte)((Packet >> 8) % 256); + } + + } + + /// + public sealed class ImageDataBlock : PacketBlock + { + public byte[] Data; + + public override int Length + { + get + { + int length = 2; + if (Data != null) { length += Data.Length; } + return length; + } + } + + public ImageDataBlock() { } + public ImageDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + length = (bytes[i++] + (bytes[i++] << 8)); + Data = new byte[length]; + Buffer.BlockCopy(bytes, i, Data, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + bytes[i++] = (byte)(Data.Length % 256); + bytes[i++] = (byte)((Data.Length >> 8) % 256); + Buffer.BlockCopy(Data, 0, bytes, i, Data.Length); i += Data.Length; + } + + } + + public override int Length + { + get + { + int length = 7; + length += ImageID.Length; + length += ImageData.Length; + return length; + } + } + public ImageIDBlock ImageID; + public ImageDataBlock ImageData; + + public ImagePacketPacket() + { + HasVariableBlocks = false; + Type = PacketType.ImagePacket; + Header = new Header(); + Header.Frequency = PacketFrequency.High; + Header.ID = 10; + Header.Reliable = true; + ImageID = new ImageIDBlock(); + ImageData = new ImageDataBlock(); + } + + public ImagePacketPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + ImageID.FromBytes(bytes, ref i); + ImageData.FromBytes(bytes, ref i); + } + + public ImagePacketPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + ImageID.FromBytes(bytes, ref i); + ImageData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 7; + length += ImageID.Length; + length += ImageData.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + + public override byte[] ToBytes(Interfaces.IByteBufferPool pool, ref int size) + { + int length = 7; + length += ImageID.Length; + length += ImageData.Length; + if (Header.AckList != null && Header.AckList.Length > 0) { length += Header.AckList.Length * 4 + 1; } + byte[] bytes = pool.LeaseBytes(length); + int i = 0; + Header.ToBytes(bytes, ref i); + ImageID.ToBytes(bytes, ref i); + ImageData.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + + size = length; + return bytes; + } + + public override byte[][] ToBytesMultiple(Interfaces.IByteBufferPool pool, out int[] sizes) + { + sizes = new int[1]; + return new byte[][] { this.ToBytes(pool, ref sizes[0]) }; + } + } + + /// + public sealed class LayerDataPacket : Packet + { + public override bool UsesBufferPooling + { + get + { + return true; + } + } + + /// + public sealed class LayerIDBlock : PacketBlock + { + public byte Type; + + public override int Length + { + get + { + return 1; + } + } + + public LayerIDBlock() { } + public LayerIDBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + Type = (byte)bytes[i++]; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + bytes[i++] = Type; + } + + } + + /// + public sealed class LayerDataBlock : PacketBlock + { + public byte[] Data; + + public override int Length + { + get + { + int length = 2; + if (Data != null) { length += Data.Length; } + return length; + } + } + + public LayerDataBlock() { } + public LayerDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + length = (bytes[i++] + (bytes[i++] << 8)); + Data = new byte[length]; + Buffer.BlockCopy(bytes, i, Data, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + bytes[i++] = (byte)(Data.Length % 256); + bytes[i++] = (byte)((Data.Length >> 8) % 256); + Buffer.BlockCopy(Data, 0, bytes, i, Data.Length); i += Data.Length; + } + + } + + public override int Length + { + get + { + int length = 7; + length += LayerID.Length; + length += LayerData.Length; + return length; + } + } + public LayerIDBlock LayerID; + public LayerDataBlock LayerData; + + public LayerDataPacket() + { + HasVariableBlocks = false; + Type = PacketType.LayerData; + Header = new Header(); + Header.Frequency = PacketFrequency.High; + Header.ID = 11; + Header.Reliable = true; + LayerID = new LayerIDBlock(); + LayerData = new LayerDataBlock(); + } + + public LayerDataPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + LayerID.FromBytes(bytes, ref i); + LayerData.FromBytes(bytes, ref i); + } + + public LayerDataPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + LayerID.FromBytes(bytes, ref i); + LayerData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 7; + length += LayerID.Length; + length += LayerData.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + + public override byte[] ToBytes(Interfaces.IByteBufferPool pool, ref int size) + { + int length = 7; + length += LayerID.Length; + length += LayerData.Length; + if (Header.AckList != null && Header.AckList.Length > 0) { length += Header.AckList.Length * 4 + 1; } + byte[] bytes = pool.LeaseBytes(length); + int i = 0; + Header.ToBytes(bytes, ref i); + LayerID.ToBytes(bytes, ref i); + LayerData.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + + size = length; + return bytes; + } + + public override byte[][] ToBytesMultiple(Interfaces.IByteBufferPool pool, out int[] sizes) + { + sizes = new int[1]; + return new byte[][] { this.ToBytes(pool, ref sizes[0]) }; + } + } + + /// + public sealed class ObjectUpdatePacket : Packet + { + public override bool UsesBufferPooling + { + get + { + return true; + } + } + + /// + public sealed class RegionDataBlock : PacketBlock + { + public ulong RegionHandle; + public ushort TimeDilation; + + public override int Length + { + get + { + return 10; + } + } + + public RegionDataBlock() { } + public RegionDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(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)); + TimeDilation = (ushort)(bytes[i++] + (bytes[i++] << 8)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UInt64ToBytes(RegionHandle, bytes, i); i += 8; + bytes[i++] = (byte)(TimeDilation % 256); + bytes[i++] = (byte)((TimeDilation >> 8) % 256); + } + + } + + /// + public sealed class ObjectDataBlock : PacketBlock + { + public uint ID; + public byte State; + public UUID FullID; + public uint CRC; + public byte PCode; + public byte Material; + public byte ClickAction; + public Vector3 Scale; + public byte[] ObjectData; + public uint ParentID; + public uint UpdateFlags; + public byte PathCurve; + public byte ProfileCurve; + public ushort PathBegin; + public ushort PathEnd; + public byte PathScaleX; + public byte PathScaleY; + public byte PathShearX; + public byte PathShearY; + public sbyte PathTwist; + public sbyte PathTwistBegin; + public sbyte PathRadiusOffset; + public sbyte PathTaperX; + public sbyte PathTaperY; + public byte PathRevolutions; + public sbyte PathSkew; + public ushort ProfileBegin; + public ushort ProfileEnd; + public ushort ProfileHollow; + public byte[] TextureEntry; + public byte[] TextureAnim; + public byte[] NameValue; + public byte[] Data; + public byte[] Text; + public byte[] TextColor; + public byte[] MediaURL; + public byte[] PSBlock; + public byte[] ExtraParams; + public UUID Sound; + public UUID OwnerID; + public float Gain; + public byte Flags; + public float Radius; + public byte JointType; + public Vector3 JointPivot; + public Vector3 JointAxisOrAnchor; + + public override int Length + { + get + { + int length = 153; + if (ObjectData != null) { length += (byte)ObjectData.Length; } + if (TextureEntry != null) { length += Math.Min(TextureEntry.Length, 65535); } + if (TextureAnim != null) { length += (byte)TextureAnim.Length; } + if (NameValue != null) { length += Math.Min(NameValue.Length, 65535); } + if (Data != null) { length += Math.Min(Data.Length, 65535); } + if (Text != null) { length += (byte)Text.Length; } + if (MediaURL != null) { length += (byte)MediaURL.Length; } + if (PSBlock != null) { length += (byte)PSBlock.Length; } + if (ExtraParams != null) { length += (byte)ExtraParams.Length; } + return length; + } + } + + public ObjectDataBlock() { } + public ObjectDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + ID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + State = (byte)bytes[i++]; + FullID.FromBytes(bytes, i); i += 16; + CRC = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + PCode = (byte)bytes[i++]; + Material = (byte)bytes[i++]; + ClickAction = (byte)bytes[i++]; + Scale.FromBytes(bytes, i); i += 12; + length = bytes[i++]; + ObjectData = new byte[length]; + Buffer.BlockCopy(bytes, i, ObjectData, 0, length); i += length; + ParentID = (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)); + PathCurve = (byte)bytes[i++]; + ProfileCurve = (byte)bytes[i++]; + PathBegin = (ushort)(bytes[i++] + (bytes[i++] << 8)); + PathEnd = (ushort)(bytes[i++] + (bytes[i++] << 8)); + PathScaleX = (byte)bytes[i++]; + PathScaleY = (byte)bytes[i++]; + PathShearX = (byte)bytes[i++]; + PathShearY = (byte)bytes[i++]; + PathTwist = (sbyte)bytes[i++]; + PathTwistBegin = (sbyte)bytes[i++]; + PathRadiusOffset = (sbyte)bytes[i++]; + PathTaperX = (sbyte)bytes[i++]; + PathTaperY = (sbyte)bytes[i++]; + PathRevolutions = (byte)bytes[i++]; + PathSkew = (sbyte)bytes[i++]; + ProfileBegin = (ushort)(bytes[i++] + (bytes[i++] << 8)); + ProfileEnd = (ushort)(bytes[i++] + (bytes[i++] << 8)); + ProfileHollow = (ushort)(bytes[i++] + (bytes[i++] << 8)); + length = (bytes[i++] + (bytes[i++] << 8)); + TextureEntry = new byte[length]; + Buffer.BlockCopy(bytes, i, TextureEntry, 0, length); i += length; + length = bytes[i++]; + TextureAnim = new byte[length]; + Buffer.BlockCopy(bytes, i, TextureAnim, 0, length); i += length; + length = (bytes[i++] + (bytes[i++] << 8)); + NameValue = new byte[length]; + Buffer.BlockCopy(bytes, i, NameValue, 0, length); i += length; + length = (bytes[i++] + (bytes[i++] << 8)); + Data = new byte[length]; + Buffer.BlockCopy(bytes, i, Data, 0, length); i += length; + length = bytes[i++]; + Text = new byte[length]; + Buffer.BlockCopy(bytes, i, Text, 0, length); i += length; + TextColor = new byte[4]; + Buffer.BlockCopy(bytes, i, TextColor, 0, 4); i += 4; + length = bytes[i++]; + MediaURL = new byte[length]; + Buffer.BlockCopy(bytes, i, MediaURL, 0, length); i += length; + length = bytes[i++]; + PSBlock = new byte[length]; + Buffer.BlockCopy(bytes, i, PSBlock, 0, length); i += length; + length = bytes[i++]; + ExtraParams = new byte[length]; + Buffer.BlockCopy(bytes, i, ExtraParams, 0, length); i += length; + Sound.FromBytes(bytes, i); i += 16; + OwnerID.FromBytes(bytes, i); i += 16; + Gain = Utils.BytesToFloat(bytes, i); i += 4; + Flags = (byte)bytes[i++]; + Radius = Utils.BytesToFloat(bytes, i); i += 4; + JointType = (byte)bytes[i++]; + JointPivot.FromBytes(bytes, i); i += 12; + JointAxisOrAnchor.FromBytes(bytes, i); i += 12; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UIntToBytes(ID, bytes, i); i += 4; + bytes[i++] = State; + FullID.ToBytes(bytes, i); i += 16; + Utils.UIntToBytes(CRC, bytes, i); i += 4; + bytes[i++] = PCode; + bytes[i++] = Material; + bytes[i++] = ClickAction; + Scale.ToBytes(bytes, i); i += 12; + bytes[i++] = (byte)ObjectData.Length; + Buffer.BlockCopy(ObjectData, 0, bytes, i, (byte)ObjectData.Length); i += (byte)ObjectData.Length; + Utils.UIntToBytes(ParentID, bytes, i); i += 4; + Utils.UIntToBytes(UpdateFlags, bytes, i); i += 4; + bytes[i++] = PathCurve; + bytes[i++] = ProfileCurve; + bytes[i++] = (byte)(PathBegin % 256); + bytes[i++] = (byte)((PathBegin >> 8) % 256); + bytes[i++] = (byte)(PathEnd % 256); + bytes[i++] = (byte)((PathEnd >> 8) % 256); + bytes[i++] = PathScaleX; + bytes[i++] = PathScaleY; + bytes[i++] = PathShearX; + bytes[i++] = PathShearY; + bytes[i++] = (byte)PathTwist; + bytes[i++] = (byte)PathTwistBegin; + bytes[i++] = (byte)PathRadiusOffset; + bytes[i++] = (byte)PathTaperX; + bytes[i++] = (byte)PathTaperY; + bytes[i++] = PathRevolutions; + bytes[i++] = (byte)PathSkew; + bytes[i++] = (byte)(ProfileBegin % 256); + bytes[i++] = (byte)((ProfileBegin >> 8) % 256); + bytes[i++] = (byte)(ProfileEnd % 256); + bytes[i++] = (byte)((ProfileEnd >> 8) % 256); + bytes[i++] = (byte)(ProfileHollow % 256); + bytes[i++] = (byte)((ProfileHollow >> 8) % 256); + + int truncTextureEntryLen = Math.Min(TextureEntry.Length, 65535); + bytes[i++] = (byte)(truncTextureEntryLen % 256); + bytes[i++] = (byte)((truncTextureEntryLen >> 8) % 256); + Buffer.BlockCopy(TextureEntry, 0, bytes, i, truncTextureEntryLen); i += truncTextureEntryLen; + + byte truncTextureAnimLen = (byte)TextureAnim.Length; + bytes[i++] = truncTextureAnimLen; + Buffer.BlockCopy(TextureAnim, 0, bytes, i, truncTextureAnimLen); i += truncTextureAnimLen; + + int truncNameValueLen = Math.Min(NameValue.Length, 65535); + bytes[i++] = (byte)(truncNameValueLen % 256); + bytes[i++] = (byte)((truncNameValueLen >> 8) % 256); + Buffer.BlockCopy(NameValue, 0, bytes, i, truncNameValueLen); i += truncNameValueLen; + + int truncDataLen = Math.Min(Data.Length, 65535); + bytes[i++] = (byte)(truncDataLen % 256); + bytes[i++] = (byte)((truncDataLen >> 8) % 256); + Buffer.BlockCopy(Data, 0, bytes, i, truncDataLen); i += truncDataLen; + + byte truncTextLen = (byte)Text.Length; + bytes[i++] = truncTextLen; + Buffer.BlockCopy(Text, 0, bytes, i, truncTextLen); i += truncTextLen; + + Buffer.BlockCopy(TextColor, 0, bytes, i, 4);i += 4; + + byte truncMediaUrlLen = (byte)MediaURL.Length; + bytes[i++] = truncMediaUrlLen; + Buffer.BlockCopy(MediaURL, 0, bytes, i, truncMediaUrlLen); i += truncMediaUrlLen; + + byte truncPsBlockLen = (byte)PSBlock.Length; + bytes[i++] = truncPsBlockLen; + Buffer.BlockCopy(PSBlock, 0, bytes, i, truncPsBlockLen); i += truncPsBlockLen; + + byte truncExtraParamsLen = (byte)ExtraParams.Length; + bytes[i++] = truncExtraParamsLen; + Buffer.BlockCopy(ExtraParams, 0, bytes, i, truncExtraParamsLen); i += truncExtraParamsLen; + + Sound.ToBytes(bytes, i); i += 16; + OwnerID.ToBytes(bytes, i); i += 16; + Utils.FloatToBytes(Gain, bytes, i); i += 4; + bytes[i++] = Flags; + Utils.FloatToBytes(Radius, bytes, i); i += 4; + bytes[i++] = JointType; + JointPivot.ToBytes(bytes, i); i += 12; + JointAxisOrAnchor.ToBytes(bytes, i); i += 12; + } + + } + + public override int Length + { + get + { + int length = 8; + length += RegionData.Length; + for (int j = 0; j < ObjectData.Length; j++) + length += ObjectData[j].Length; + return length; + } + } + public RegionDataBlock RegionData; + public ObjectDataBlock[] ObjectData; + + public ObjectUpdatePacket() + { + HasVariableBlocks = true; + Type = PacketType.ObjectUpdate; + Header = new Header(); + Header.Frequency = PacketFrequency.High; + Header.ID = 12; + Header.Reliable = true; + Header.Zerocoded = true; + RegionData = new RegionDataBlock(); + ObjectData = null; + } + + public ObjectUpdatePacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + RegionData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ObjectData == null || ObjectData.Length != -1) { + ObjectData = new ObjectDataBlock[count]; + for(int j = 0; j < count; j++) + { ObjectData[j] = new ObjectDataBlock(); } + } + for (int j = 0; j < count; j++) + { ObjectData[j].FromBytes(bytes, ref i); } + } + + public ObjectUpdatePacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + RegionData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ObjectData == null || ObjectData.Length != count) { + ObjectData = new ObjectDataBlock[count]; + for(int j = 0; j < count; j++) + { ObjectData[j] = new ObjectDataBlock(); } + } + for (int j = 0; j < count; j++) + { ObjectData[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 7; + length += RegionData.Length; + length++; + for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } + if (Header.AckList != null && 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)ObjectData.Length; + for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 7; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += RegionData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + RegionData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int ObjectDataStart = 0; + do + { + int variableLength = 0; + int ObjectDataCount = 0; + + i = ObjectDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < ObjectData.Length) { + int blockLength = ObjectData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ObjectDataStart) { + variableLength += blockLength; + ++ObjectDataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)ObjectDataCount; + for (i = ObjectDataStart; i < ObjectDataStart + ObjectDataCount; i++) { ObjectData[i].ToBytes(packet, ref length); } + ObjectDataStart += ObjectDataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + ObjectDataStart < ObjectData.Length); + + return packets.ToArray(); + } + + public override byte[] ToBytes(Interfaces.IByteBufferPool pool, ref int size) + { + int length = 7; + length += RegionData.Length; + length++; + for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } + if (Header.AckList != null && Header.AckList.Length > 0) { length += Header.AckList.Length * 4 + 1; } + byte[] bytes = pool.LeaseBytes(length); + int i = 0; + Header.ToBytes(bytes, ref i); + RegionData.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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + + size = length; + return bytes; + } + + public override byte[][] ToBytesMultiple(Interfaces.IByteBufferPool pool, out int[] sizes) + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + System.Collections.Generic.List retSizes = new System.Collections.Generic.List(); + + int i = 0; + int fixedLength = 7; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) + { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += RegionData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + RegionData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int ObjectDataStart = 0; + do + { + int variableLength = 0; + int ObjectDataCount = 0; + + i = ObjectDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < ObjectData.Length) + { + int blockLength = ObjectData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ObjectDataStart) + { + variableLength += blockLength; + ++ObjectDataCount; + } + else { break; } + ++i; + } + + int packetSize = fixedLength + variableLength + acksLength; + byte[] packet = pool.LeaseBytes(packetSize); + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)ObjectDataCount; + for (i = ObjectDataStart; i < ObjectDataStart + ObjectDataCount; i++) { ObjectData[i].ToBytes(packet, ref length); } + ObjectDataStart += ObjectDataCount; + + if (acksLength > 0) + { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + retSizes.Add(packetSize); + packets.Add(packet); + } while ( + ObjectDataStart < ObjectData.Length); + + sizes = retSizes.ToArray(); + return packets.ToArray(); + } + } + + /// + public sealed class ObjectUpdateCompressedPacket : Packet + { + public override bool UsesBufferPooling + { + get + { + return true; + } + } + + /// + public sealed class RegionDataBlock : PacketBlock + { + public ulong RegionHandle; + public ushort TimeDilation; + + public override int Length + { + get + { + return 10; + } + } + + public RegionDataBlock() { } + public RegionDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(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)); + TimeDilation = (ushort)(bytes[i++] + (bytes[i++] << 8)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UInt64ToBytes(RegionHandle, bytes, i); i += 8; + bytes[i++] = (byte)(TimeDilation % 256); + bytes[i++] = (byte)((TimeDilation >> 8) % 256); + } + + } + + /// + public sealed class ObjectDataBlock : PacketBlock + { + public uint UpdateFlags; + public byte[] Data; + + public override int Length + { + get + { + int length = 6; + if (Data != null) { length += Data.Length; } + return length; + } + } + + public ObjectDataBlock() { } + public ObjectDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + UpdateFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + length = (bytes[i++] + (bytes[i++] << 8)); + Data = new byte[length]; + Buffer.BlockCopy(bytes, i, Data, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UIntToBytes(UpdateFlags, bytes, i); i += 4; + bytes[i++] = (byte)(Data.Length % 256); + bytes[i++] = (byte)((Data.Length >> 8) % 256); + Buffer.BlockCopy(Data, 0, bytes, i, Data.Length); i += Data.Length; + } + + } + + public override int Length + { + get + { + int length = 8; + length += RegionData.Length; + for (int j = 0; j < ObjectData.Length; j++) + length += ObjectData[j].Length; + return length; + } + } + public RegionDataBlock RegionData; + public ObjectDataBlock[] ObjectData; + + public ObjectUpdateCompressedPacket() + { + HasVariableBlocks = true; + Type = PacketType.ObjectUpdateCompressed; + Header = new Header(); + Header.Frequency = PacketFrequency.High; + Header.ID = 13; + Header.Reliable = true; + RegionData = new RegionDataBlock(); + ObjectData = null; + } + + public ObjectUpdateCompressedPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + RegionData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ObjectData == null || ObjectData.Length != -1) { + ObjectData = new ObjectDataBlock[count]; + for(int j = 0; j < count; j++) + { ObjectData[j] = new ObjectDataBlock(); } + } + for (int j = 0; j < count; j++) + { ObjectData[j].FromBytes(bytes, ref i); } + } + + public ObjectUpdateCompressedPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + RegionData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ObjectData == null || ObjectData.Length != count) { + ObjectData = new ObjectDataBlock[count]; + for(int j = 0; j < count; j++) + { ObjectData[j] = new ObjectDataBlock(); } + } + for (int j = 0; j < count; j++) + { ObjectData[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 7; + length += RegionData.Length; + length++; + for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } + if (Header.AckList != null && 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)ObjectData.Length; + for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 7; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += RegionData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + RegionData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int ObjectDataStart = 0; + do + { + int variableLength = 0; + int ObjectDataCount = 0; + + i = ObjectDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < ObjectData.Length) { + int blockLength = ObjectData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ObjectDataStart) { + variableLength += blockLength; + ++ObjectDataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)ObjectDataCount; + for (i = ObjectDataStart; i < ObjectDataStart + ObjectDataCount; i++) { ObjectData[i].ToBytes(packet, ref length); } + ObjectDataStart += ObjectDataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + ObjectDataStart < ObjectData.Length); + + return packets.ToArray(); + } + + public override byte[] ToBytes(Interfaces.IByteBufferPool pool, ref int size) + { + int length = 7; + length += RegionData.Length; + length++; + for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } + if (Header.AckList != null && Header.AckList.Length > 0) { length += Header.AckList.Length * 4 + 1; } + byte[] bytes = pool.LeaseBytes(length); + int i = 0; + Header.ToBytes(bytes, ref i); + RegionData.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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + + size = length; + return bytes; + } + + public override byte[][] ToBytesMultiple(Interfaces.IByteBufferPool pool, out int[] sizes) + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + System.Collections.Generic.List retSizes = new System.Collections.Generic.List(); + + int i = 0; + int fixedLength = 7; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) + { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += RegionData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + RegionData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int ObjectDataStart = 0; + do + { + int variableLength = 0; + int ObjectDataCount = 0; + + i = ObjectDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < ObjectData.Length) + { + int blockLength = ObjectData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU) + { + variableLength += blockLength; + ++ObjectDataCount; + } + else { break; } + ++i; + } + + int packetSize = fixedLength + variableLength + acksLength; + byte[] packet = pool.LeaseBytes(packetSize); + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)ObjectDataCount; + for (i = ObjectDataStart; i < ObjectDataStart + ObjectDataCount; i++) { ObjectData[i].ToBytes(packet, ref length); } + ObjectDataStart += ObjectDataCount; + + if (acksLength > 0) + { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + retSizes.Add(packetSize); + packets.Add(packet); + } while ( + ObjectDataStart < ObjectData.Length); + + sizes = retSizes.ToArray(); + return packets.ToArray(); + } + } + + /// + public sealed class ObjectUpdateCachedPacket : Packet + { + public override bool UsesBufferPooling + { + get + { + return true; + } + } + + /// + public sealed class RegionDataBlock : PacketBlock + { + public ulong RegionHandle; + public ushort TimeDilation; + + public override int Length + { + get + { + return 10; + } + } + + public RegionDataBlock() { } + public RegionDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(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)); + TimeDilation = (ushort)(bytes[i++] + (bytes[i++] << 8)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UInt64ToBytes(RegionHandle, bytes, i); i += 8; + bytes[i++] = (byte)(TimeDilation % 256); + bytes[i++] = (byte)((TimeDilation >> 8) % 256); + } + + } + + /// + public sealed class ObjectDataBlock : PacketBlock + { + public uint ID; + public uint CRC; + public uint UpdateFlags; + + public override int Length + { + get + { + return 12; + } + } + + public ObjectDataBlock() { } + public ObjectDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + ID = (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)); + UpdateFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UIntToBytes(ID, bytes, i); i += 4; + Utils.UIntToBytes(CRC, bytes, i); i += 4; + Utils.UIntToBytes(UpdateFlags, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 8; + length += RegionData.Length; + for (int j = 0; j < ObjectData.Length; j++) + length += ObjectData[j].Length; + return length; + } + } + public RegionDataBlock RegionData; + public ObjectDataBlock[] ObjectData; + + public ObjectUpdateCachedPacket() + { + HasVariableBlocks = true; + Type = PacketType.ObjectUpdateCached; + Header = new Header(); + Header.Frequency = PacketFrequency.High; + Header.ID = 14; + Header.Reliable = true; + RegionData = new RegionDataBlock(); + ObjectData = null; + } + + public ObjectUpdateCachedPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + RegionData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ObjectData == null || ObjectData.Length != -1) { + ObjectData = new ObjectDataBlock[count]; + for(int j = 0; j < count; j++) + { ObjectData[j] = new ObjectDataBlock(); } + } + for (int j = 0; j < count; j++) + { ObjectData[j].FromBytes(bytes, ref i); } + } + + public ObjectUpdateCachedPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + RegionData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ObjectData == null || ObjectData.Length != count) { + ObjectData = new ObjectDataBlock[count]; + for(int j = 0; j < count; j++) + { ObjectData[j] = new ObjectDataBlock(); } + } + for (int j = 0; j < count; j++) + { ObjectData[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 7; + length += RegionData.Length; + length++; + for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } + if (Header.AckList != null && 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)ObjectData.Length; + for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 7; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += RegionData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + RegionData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int ObjectDataStart = 0; + do + { + int variableLength = 0; + int ObjectDataCount = 0; + + i = ObjectDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < ObjectData.Length) { + int blockLength = ObjectData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ObjectDataStart) { + variableLength += blockLength; + ++ObjectDataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)ObjectDataCount; + for (i = ObjectDataStart; i < ObjectDataStart + ObjectDataCount; i++) { ObjectData[i].ToBytes(packet, ref length); } + ObjectDataStart += ObjectDataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + ObjectDataStart < ObjectData.Length); + + return packets.ToArray(); + } + + public override byte[] ToBytes(Interfaces.IByteBufferPool pool, ref int size) + { + int length = 7; + length += RegionData.Length; + length++; + for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } + if (Header.AckList != null && Header.AckList.Length > 0) { length += Header.AckList.Length * 4 + 1; } + byte[] bytes = pool.LeaseBytes(length); + int i = 0; + Header.ToBytes(bytes, ref i); + RegionData.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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + + size = length; + return bytes; + } + + public override byte[][] ToBytesMultiple(Interfaces.IByteBufferPool pool, out int[] sizes) + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + System.Collections.Generic.List retSizes = new System.Collections.Generic.List(); + + int i = 0; + int fixedLength = 7; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) + { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += RegionData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + RegionData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int ObjectDataStart = 0; + do + { + int variableLength = 0; + int ObjectDataCount = 0; + + i = ObjectDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < ObjectData.Length) + { + int blockLength = ObjectData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU) + { + variableLength += blockLength; + ++ObjectDataCount; + } + else { break; } + ++i; + } + + int packetSize = fixedLength + variableLength + acksLength; + byte[] packet = pool.LeaseBytes(packetSize); + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)ObjectDataCount; + for (i = ObjectDataStart; i < ObjectDataStart + ObjectDataCount; i++) { ObjectData[i].ToBytes(packet, ref length); } + ObjectDataStart += ObjectDataCount; + + if (acksLength > 0) + { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + retSizes.Add(packetSize); + packets.Add(packet); + } while ( + ObjectDataStart < ObjectData.Length); + + sizes = retSizes.ToArray(); + return packets.ToArray(); + } + } + + /// + public sealed class ImprovedTerseObjectUpdatePacket : Packet + { + public override bool UsesBufferPooling + { + get + { + return true; + } + } + + /// + public sealed class RegionDataBlock : PacketBlock + { + public ulong RegionHandle; + public ushort TimeDilation; + + public override int Length + { + get + { + return 10; + } + } + + public RegionDataBlock() { } + public RegionDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(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)); + TimeDilation = (ushort)(bytes[i++] + (bytes[i++] << 8)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UInt64ToBytes(RegionHandle, bytes, i); i += 8; + bytes[i++] = (byte)(TimeDilation % 256); + bytes[i++] = (byte)((TimeDilation >> 8) % 256); + } + + } + + /// + public sealed class ObjectDataBlock : PacketBlock + { + public byte[] Data; + public byte[] TextureEntry; + + public override int Length + { + get + { + int length = 3; + if (Data != null) { length += Data.Length; } + if (TextureEntry != null) { length += TextureEntry.Length; } + return length; + } + } + + public ObjectDataBlock() { } + public ObjectDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + length = bytes[i++]; + Data = new byte[length]; + Buffer.BlockCopy(bytes, i, Data, 0, length); i += length; + length = (bytes[i++] + (bytes[i++] << 8)); + TextureEntry = new byte[length]; + Buffer.BlockCopy(bytes, i, TextureEntry, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + bytes[i++] = (byte)Data.Length; + Buffer.BlockCopy(Data, 0, bytes, i, Data.Length); i += Data.Length; + bytes[i++] = (byte)(TextureEntry.Length % 256); + bytes[i++] = (byte)((TextureEntry.Length >> 8) % 256); + Buffer.BlockCopy(TextureEntry, 0, bytes, i, TextureEntry.Length); i += TextureEntry.Length; + } + + } + + public override int Length + { + get + { + int length = 8; + length += RegionData.Length; + for (int j = 0; j < ObjectData.Length; j++) + length += ObjectData[j].Length; + return length; + } + } + public RegionDataBlock RegionData; + public ObjectDataBlock[] ObjectData; + + public ImprovedTerseObjectUpdatePacket() + { + HasVariableBlocks = true; + Type = PacketType.ImprovedTerseObjectUpdate; + Header = new Header(); + Header.Frequency = PacketFrequency.High; + Header.ID = 15; + Header.Reliable = true; + RegionData = new RegionDataBlock(); + ObjectData = null; + } + + public ImprovedTerseObjectUpdatePacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + RegionData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ObjectData == null || ObjectData.Length != -1) { + ObjectData = new ObjectDataBlock[count]; + for(int j = 0; j < count; j++) + { ObjectData[j] = new ObjectDataBlock(); } + } + for (int j = 0; j < count; j++) + { ObjectData[j].FromBytes(bytes, ref i); } + } + + public ImprovedTerseObjectUpdatePacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + RegionData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(ObjectData == null || ObjectData.Length != count) { + ObjectData = new ObjectDataBlock[count]; + for(int j = 0; j < count; j++) + { ObjectData[j] = new ObjectDataBlock(); } + } + for (int j = 0; j < count; j++) + { ObjectData[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 7; + length += RegionData.Length; + length++; + for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } + if (Header.AckList != null && 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)ObjectData.Length; + for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 7; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += RegionData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + RegionData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int ObjectDataStart = 0; + do + { + int variableLength = 0; + int ObjectDataCount = 0; + + i = ObjectDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < ObjectData.Length) { + int blockLength = ObjectData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ObjectDataStart) { + variableLength += blockLength; + ++ObjectDataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)ObjectDataCount; + for (i = ObjectDataStart; i < ObjectDataStart + ObjectDataCount; i++) { ObjectData[i].ToBytes(packet, ref length); } + ObjectDataStart += ObjectDataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + ObjectDataStart < ObjectData.Length); + + return packets.ToArray(); + } + + public override byte[] ToBytes(Interfaces.IByteBufferPool pool, ref int size) + { + int length = 7; + length += RegionData.Length; + length++; + for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } + if (Header.AckList != null && Header.AckList.Length > 0) { length += Header.AckList.Length * 4 + 1; } + byte[] bytes = pool.LeaseBytes(length); + int i = 0; + Header.ToBytes(bytes, ref i); + RegionData.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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + + size = length; + return bytes; + } + + public override byte[][] ToBytesMultiple(Interfaces.IByteBufferPool pool, out int[] sizes) + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + System.Collections.Generic.List retSizes = new System.Collections.Generic.List(); + + + int i = 0; + int fixedLength = 7; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) + { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += RegionData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + RegionData.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int ObjectDataStart = 0; + do + { + int variableLength = 0; + int ObjectDataCount = 0; + + i = ObjectDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < ObjectData.Length) + { + int blockLength = ObjectData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU) + { + variableLength += blockLength; + ++ObjectDataCount; + } + else { break; } + ++i; + } + + int packetSize = fixedLength + variableLength + acksLength; + byte[] packet = pool.LeaseBytes(packetSize); + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)ObjectDataCount; + for (i = ObjectDataStart; i < ObjectDataStart + ObjectDataCount; i++) { ObjectData[i].ToBytes(packet, ref length); } + ObjectDataStart += ObjectDataCount; + + if (acksLength > 0) + { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + retSizes.Add(packetSize); + packets.Add(packet); + } while ( + ObjectDataStart < ObjectData.Length); + + sizes = retSizes.ToArray(); + return packets.ToArray(); + } + } + + /// + public sealed class KillObjectPacket : Packet + { + public override bool UsesBufferPooling + { + get + { + return true; + } + } + + /// + public sealed class ObjectDataBlock : PacketBlock + { + public uint ID; + + public override int Length + { + get + { + return 4; + } + } + + public ObjectDataBlock() { } + public ObjectDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + ID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UIntToBytes(ID, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 8; + for (int j = 0; j < ObjectData.Length; j++) + length += ObjectData[j].Length; + return length; + } + } + public ObjectDataBlock[] ObjectData; + + public KillObjectPacket() + { + HasVariableBlocks = true; + Type = PacketType.KillObject; + Header = new Header(); + Header.Frequency = PacketFrequency.High; + Header.ID = 16; + Header.Reliable = true; + ObjectData = null; + } + + public KillObjectPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + int count = (int)bytes[i++]; + if(ObjectData == null || ObjectData.Length != -1) { + ObjectData = new ObjectDataBlock[count]; + for(int j = 0; j < count; j++) + { ObjectData[j] = new ObjectDataBlock(); } + } + for (int j = 0; j < count; j++) + { ObjectData[j].FromBytes(bytes, ref i); } + } + + public KillObjectPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + int count = (int)bytes[i++]; + if(ObjectData == null || ObjectData.Length != count) { + ObjectData = new ObjectDataBlock[count]; + for(int j = 0; j < count; j++) + { ObjectData[j] = new ObjectDataBlock(); } + } + for (int j = 0; j < count; j++) + { ObjectData[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 7; + length++; + for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 7; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int ObjectDataStart = 0; + do + { + int variableLength = 0; + int ObjectDataCount = 0; + + i = ObjectDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < ObjectData.Length) { + int blockLength = ObjectData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == ObjectDataStart) { + variableLength += blockLength; + ++ObjectDataCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)ObjectDataCount; + for (i = ObjectDataStart; i < ObjectDataStart + ObjectDataCount; i++) { ObjectData[i].ToBytes(packet, ref length); } + ObjectDataStart += ObjectDataCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + ObjectDataStart < ObjectData.Length); + + return packets.ToArray(); + } + + public override byte[] ToBytes(Interfaces.IByteBufferPool pool, ref int size) + { + int length = 7; + length++; + for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } + if (Header.AckList != null && Header.AckList.Length > 0) { length += Header.AckList.Length * 4 + 1; } + byte[] bytes = pool.LeaseBytes(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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + + size = length; + return bytes; + } + + public override byte[][] ToBytesMultiple(Interfaces.IByteBufferPool pool, out int[] sizes) + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + System.Collections.Generic.List retSizes = new System.Collections.Generic.List(); + + int i = 0; + int fixedLength = 7; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) + { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int ObjectDataStart = 0; + do + { + int variableLength = 0; + int ObjectDataCount = 0; + + i = ObjectDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < ObjectData.Length) + { + int blockLength = ObjectData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU) + { + variableLength += blockLength; + ++ObjectDataCount; + } + else { break; } + ++i; + } + + int packetSize = fixedLength + variableLength + acksLength; + byte[] packet = pool.LeaseBytes(packetSize); + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)ObjectDataCount; + for (i = ObjectDataStart; i < ObjectDataStart + ObjectDataCount; i++) { ObjectData[i].ToBytes(packet, ref length); } + ObjectDataStart += ObjectDataCount; + + if (acksLength > 0) + { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + retSizes.Add(packetSize); + packets.Add(packet); + } while ( + ObjectDataStart < ObjectData.Length); + + sizes = retSizes.ToArray(); + return packets.ToArray(); + } + } + + /// + public sealed class TransferPacketPacket : Packet + { + public override bool UsesBufferPooling + { + get + { + return true; + } + } + + /// + public sealed class TransferDataBlock : PacketBlock + { + public UUID TransferID; + public int ChannelType; + public int Packet; + public int Status; + public byte[] Data; + + public override int Length + { + get + { + int length = 30; + if (Data != null) { length += Data.Length; } + return length; + } + } + + public TransferDataBlock() { } + public TransferDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + TransferID.FromBytes(bytes, i); i += 16; + ChannelType = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + Packet = (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)); + length = (bytes[i++] + (bytes[i++] << 8)); + Data = new byte[length]; + Buffer.BlockCopy(bytes, i, Data, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + TransferID.ToBytes(bytes, i); i += 16; + Utils.IntToBytes(ChannelType, bytes, i); i += 4; + Utils.IntToBytes(Packet, bytes, i); i += 4; + Utils.IntToBytes(Status, bytes, i); i += 4; + bytes[i++] = (byte)(Data.Length % 256); + bytes[i++] = (byte)((Data.Length >> 8) % 256); + Buffer.BlockCopy(Data, 0, bytes, i, Data.Length); i += Data.Length; + } + + } + + public override int Length + { + get + { + int length = 7; + length += TransferData.Length; + return length; + } + } + public TransferDataBlock TransferData; + + public TransferPacketPacket() + { + HasVariableBlocks = false; + Type = PacketType.TransferPacket; + Header = new Header(); + Header.Frequency = PacketFrequency.High; + Header.ID = 17; + Header.Reliable = true; + TransferData = new TransferDataBlock(); + } + + public TransferPacketPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + TransferData.FromBytes(bytes, ref i); + } + + public TransferPacketPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + TransferData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 7; + length += TransferData.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + + public override byte[] ToBytes(Interfaces.IByteBufferPool pool, ref int size) + { + int length = 7; + length += TransferData.Length; + if (Header.AckList != null && Header.AckList.Length > 0) { length += Header.AckList.Length * 4 + 1; } + byte[] bytes = pool.LeaseBytes(length); + int i = 0; + Header.ToBytes(bytes, ref i); + TransferData.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + + size = length; + return bytes; + } + + public override byte[][] ToBytesMultiple(Interfaces.IByteBufferPool pool, out int[] sizes) + { + sizes = new int[1]; + return new byte[][] { this.ToBytes(pool, ref sizes[0]) }; + } + } + + /// + public sealed class SendXferPacketPacket : Packet + { + public override bool UsesBufferPooling + { + get + { + return true; + } + } + + /// + public sealed class XferIDBlock : PacketBlock + { + public ulong ID; + public uint Packet; + + public override int Length + { + get + { + return 12; + } + } + + public XferIDBlock() { } + public XferIDBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(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(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UInt64ToBytes(ID, bytes, i); i += 8; + Utils.UIntToBytes(Packet, bytes, i); i += 4; + } + + } + + /// + public sealed class DataPacketBlock : PacketBlock + { + public byte[] Data; + + public override int Length + { + get + { + int length = 2; + if (Data != null) { length += Data.Length; } + return length; + } + } + + public DataPacketBlock() { } + public DataPacketBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + length = (bytes[i++] + (bytes[i++] << 8)); + Data = new byte[length]; + Buffer.BlockCopy(bytes, i, Data, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + bytes[i++] = (byte)(Data.Length % 256); + bytes[i++] = (byte)((Data.Length >> 8) % 256); + Buffer.BlockCopy(Data, 0, bytes, i, Data.Length); i += Data.Length; + } + + } + + public override int Length + { + get + { + int length = 7; + length += XferID.Length; + length += DataPacket.Length; + return length; + } + } + public XferIDBlock XferID; + public DataPacketBlock DataPacket; + + public SendXferPacketPacket() + { + HasVariableBlocks = false; + Type = PacketType.SendXferPacket; + Header = new Header(); + Header.Frequency = PacketFrequency.High; + Header.ID = 18; + Header.Reliable = true; + XferID = new XferIDBlock(); + DataPacket = new DataPacketBlock(); + } + + public SendXferPacketPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + XferID.FromBytes(bytes, ref i); + DataPacket.FromBytes(bytes, ref i); + } + + public SendXferPacketPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + XferID.FromBytes(bytes, ref i); + DataPacket.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 7; + length += XferID.Length; + length += DataPacket.Length; + if (Header.AckList != null && 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); + DataPacket.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + + public override byte[] ToBytes(Interfaces.IByteBufferPool pool, ref int size) + { + int length = 7; + length += XferID.Length; + length += DataPacket.Length; + if (Header.AckList != null && Header.AckList.Length > 0) { length += Header.AckList.Length * 4 + 1; } + byte[] bytes = pool.LeaseBytes(length); + int i = 0; + Header.ToBytes(bytes, ref i); + XferID.ToBytes(bytes, ref i); + DataPacket.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + + size = length; + return bytes; + } + + public override byte[][] ToBytesMultiple(Interfaces.IByteBufferPool pool, out int[] sizes) + { + sizes = new int[1]; + return new byte[][] { this.ToBytes(pool, ref sizes[0]) }; + } + } + + /// + public sealed class ConfirmXferPacketPacket : Packet + { + public override bool UsesBufferPooling + { + get + { + return true; + } + } + + /// + public sealed class XferIDBlock : PacketBlock + { + public ulong ID; + public uint Packet; + + public override int Length + { + get + { + return 12; + } + } + + public XferIDBlock() { } + public XferIDBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(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(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UInt64ToBytes(ID, bytes, i); i += 8; + Utils.UIntToBytes(Packet, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 7; + length += XferID.Length; + return length; + } + } + public XferIDBlock XferID; + + public ConfirmXferPacketPacket() + { + HasVariableBlocks = false; + Type = PacketType.ConfirmXferPacket; + Header = new Header(); + Header.Frequency = PacketFrequency.High; + Header.ID = 19; + Header.Reliable = true; + XferID = new XferIDBlock(); + } + + public ConfirmXferPacketPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + XferID.FromBytes(bytes, ref i); + } + + public ConfirmXferPacketPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + XferID.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 7; + length += XferID.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + + public override byte[] ToBytes(Interfaces.IByteBufferPool pool, ref int size) + { + int length = 7; + length += XferID.Length; + if (Header.AckList != null && Header.AckList.Length > 0) { length += Header.AckList.Length * 4 + 1; } + byte[] bytes = pool.LeaseBytes(length); + int i = 0; + Header.ToBytes(bytes, ref i); + XferID.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + + size = length; + return bytes; + } + + public override byte[][] ToBytesMultiple(Interfaces.IByteBufferPool pool, out int[] sizes) + { + sizes = new int[1]; + return new byte[][] { this.ToBytes(pool, ref sizes[0]) }; + } + } + + /// + public sealed class AvatarAnimationPacket : Packet + { + public override bool UsesBufferPooling + { + get + { + return true; + } + } + + /// + public sealed class SenderBlock : PacketBlock + { + public UUID ID; + + public override int Length + { + get + { + return 16; + } + } + + public SenderBlock() { } + public SenderBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + ID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + ID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class AnimationListBlock : PacketBlock + { + public UUID AnimID; + public int AnimSequenceID; + + public override int Length + { + get + { + return 20; + } + } + + public AnimationListBlock() { } + public AnimationListBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AnimID.FromBytes(bytes, i); i += 16; + AnimSequenceID = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AnimID.ToBytes(bytes, i); i += 16; + Utils.IntToBytes(AnimSequenceID, bytes, i); i += 4; + } + + } + + /// + public sealed class AnimationSourceListBlock : PacketBlock + { + public UUID ObjectID; + + public override int Length + { + get + { + return 16; + } + } + + public AnimationSourceListBlock() { } + public AnimationSourceListBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + ObjectID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + ObjectID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class PhysicalAvatarEventListBlock : PacketBlock + { + public byte[] TypeData; + + public override int Length + { + get + { + int length = 1; + if (TypeData != null) { length += TypeData.Length; } + return length; + } + } + + public PhysicalAvatarEventListBlock() { } + public PhysicalAvatarEventListBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + length = bytes[i++]; + TypeData = new byte[length]; + Buffer.BlockCopy(bytes, i, TypeData, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + bytes[i++] = (byte)TypeData.Length; + Buffer.BlockCopy(TypeData, 0, bytes, i, TypeData.Length); i += TypeData.Length; + } + + } + + public override int Length + { + get + { + int length = 10; + length += Sender.Length; + for (int j = 0; j < AnimationList.Length; j++) + length += AnimationList[j].Length; + for (int j = 0; j < AnimationSourceList.Length; j++) + length += AnimationSourceList[j].Length; + for (int j = 0; j < PhysicalAvatarEventList.Length; j++) + length += PhysicalAvatarEventList[j].Length; + return length; + } + } + public SenderBlock Sender; + public AnimationListBlock[] AnimationList; + public AnimationSourceListBlock[] AnimationSourceList; + public PhysicalAvatarEventListBlock[] PhysicalAvatarEventList; + + public AvatarAnimationPacket() + { + HasVariableBlocks = true; + Type = PacketType.AvatarAnimation; + Header = new Header(); + Header.Frequency = PacketFrequency.High; + Header.ID = 20; + Header.Reliable = true; + Sender = new SenderBlock(); + AnimationList = null; + AnimationSourceList = null; + PhysicalAvatarEventList = null; + } + + public AvatarAnimationPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + Sender.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(AnimationList == null || AnimationList.Length != -1) { + AnimationList = new AnimationListBlock[count]; + for(int j = 0; j < count; j++) + { AnimationList[j] = new AnimationListBlock(); } + } + for (int j = 0; j < count; j++) + { AnimationList[j].FromBytes(bytes, ref i); } + count = (int)bytes[i++]; + if(AnimationSourceList == null || AnimationSourceList.Length != -1) { + AnimationSourceList = new AnimationSourceListBlock[count]; + for(int j = 0; j < count; j++) + { AnimationSourceList[j] = new AnimationSourceListBlock(); } + } + for (int j = 0; j < count; j++) + { AnimationSourceList[j].FromBytes(bytes, ref i); } + count = (int)bytes[i++]; + if(PhysicalAvatarEventList == null || PhysicalAvatarEventList.Length != -1) { + PhysicalAvatarEventList = new PhysicalAvatarEventListBlock[count]; + for(int j = 0; j < count; j++) + { PhysicalAvatarEventList[j] = new PhysicalAvatarEventListBlock(); } + } + for (int j = 0; j < count; j++) + { PhysicalAvatarEventList[j].FromBytes(bytes, ref i); } + } + + public AvatarAnimationPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + Sender.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(AnimationList == null || AnimationList.Length != count) { + AnimationList = new AnimationListBlock[count]; + for(int j = 0; j < count; j++) + { AnimationList[j] = new AnimationListBlock(); } + } + for (int j = 0; j < count; j++) + { AnimationList[j].FromBytes(bytes, ref i); } + count = (int)bytes[i++]; + if(AnimationSourceList == null || AnimationSourceList.Length != count) { + AnimationSourceList = new AnimationSourceListBlock[count]; + for(int j = 0; j < count; j++) + { AnimationSourceList[j] = new AnimationSourceListBlock(); } + } + for (int j = 0; j < count; j++) + { AnimationSourceList[j].FromBytes(bytes, ref i); } + count = (int)bytes[i++]; + if(PhysicalAvatarEventList == null || PhysicalAvatarEventList.Length != count) { + PhysicalAvatarEventList = new PhysicalAvatarEventListBlock[count]; + for(int j = 0; j < count; j++) + { PhysicalAvatarEventList[j] = new PhysicalAvatarEventListBlock(); } + } + for (int j = 0; j < count; j++) + { PhysicalAvatarEventList[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 7; + length += Sender.Length; + length++; + for (int j = 0; j < AnimationList.Length; j++) { length += AnimationList[j].Length; } + length++; + for (int j = 0; j < AnimationSourceList.Length; j++) { length += AnimationSourceList[j].Length; } + length++; + for (int j = 0; j < PhysicalAvatarEventList.Length; j++) { length += PhysicalAvatarEventList[j].Length; } + if (Header.AckList != null && 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); + bytes[i++] = (byte)AnimationList.Length; + for (int j = 0; j < AnimationList.Length; j++) { AnimationList[j].ToBytes(bytes, ref i); } + bytes[i++] = (byte)AnimationSourceList.Length; + for (int j = 0; j < AnimationSourceList.Length; j++) { AnimationSourceList[j].ToBytes(bytes, ref i); } + bytes[i++] = (byte)PhysicalAvatarEventList.Length; + for (int j = 0; j < PhysicalAvatarEventList.Length; j++) { PhysicalAvatarEventList[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 7; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += Sender.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + Sender.ToBytes(fixedBytes, ref i); + fixedLength += 3; + + int AnimationListStart = 0; + int AnimationSourceListStart = 0; + int PhysicalAvatarEventListStart = 0; + do + { + int variableLength = 0; + int AnimationListCount = 0; + int AnimationSourceListCount = 0; + int PhysicalAvatarEventListCount = 0; + + i = AnimationListStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < AnimationList.Length) { + int blockLength = AnimationList[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == AnimationListStart) { + variableLength += blockLength; + ++AnimationListCount; + } + else { break; } + ++i; + } + + i = AnimationSourceListStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < AnimationSourceList.Length) { + int blockLength = AnimationSourceList[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == AnimationSourceListStart) { + variableLength += blockLength; + ++AnimationSourceListCount; + } + else { break; } + ++i; + } + + i = PhysicalAvatarEventListStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < PhysicalAvatarEventList.Length) { + int blockLength = PhysicalAvatarEventList[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == PhysicalAvatarEventListStart) { + variableLength += blockLength; + ++PhysicalAvatarEventListCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)AnimationListCount; + for (i = AnimationListStart; i < AnimationListStart + AnimationListCount; i++) { AnimationList[i].ToBytes(packet, ref length); } + AnimationListStart += AnimationListCount; + + packet[length++] = (byte)AnimationSourceListCount; + for (i = AnimationSourceListStart; i < AnimationSourceListStart + AnimationSourceListCount; i++) { AnimationSourceList[i].ToBytes(packet, ref length); } + AnimationSourceListStart += AnimationSourceListCount; + + packet[length++] = (byte)PhysicalAvatarEventListCount; + for (i = PhysicalAvatarEventListStart; i < PhysicalAvatarEventListStart + PhysicalAvatarEventListCount; i++) { PhysicalAvatarEventList[i].ToBytes(packet, ref length); } + PhysicalAvatarEventListStart += PhysicalAvatarEventListCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + AnimationListStart < AnimationList.Length || + AnimationSourceListStart < AnimationSourceList.Length || + PhysicalAvatarEventListStart < PhysicalAvatarEventList.Length); + + return packets.ToArray(); + } + + public override byte[] ToBytes(Interfaces.IByteBufferPool pool, ref int size) + { + int length = 7; + length += Sender.Length; + length++; + for (int j = 0; j < AnimationList.Length; j++) { length += AnimationList[j].Length; } + length++; + for (int j = 0; j < AnimationSourceList.Length; j++) { length += AnimationSourceList[j].Length; } + length++; + for (int j = 0; j < PhysicalAvatarEventList.Length; j++) { length += PhysicalAvatarEventList[j].Length; } + if (Header.AckList != null && Header.AckList.Length > 0) { length += Header.AckList.Length * 4 + 1; } + byte[] bytes = pool.LeaseBytes(length); + int i = 0; + Header.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); } + bytes[i++] = (byte)AnimationSourceList.Length; + for (int j = 0; j < AnimationSourceList.Length; j++) { AnimationSourceList[j].ToBytes(bytes, ref i); } + bytes[i++] = (byte)PhysicalAvatarEventList.Length; + for (int j = 0; j < PhysicalAvatarEventList.Length; j++) { PhysicalAvatarEventList[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + + size = length; + return bytes; + } + + public override byte[][] ToBytesMultiple(Interfaces.IByteBufferPool pool, out int[] sizes) + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + System.Collections.Generic.List retSizes = new System.Collections.Generic.List(); + + int i = 0; + int fixedLength = 7; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) + { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += Sender.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + Sender.ToBytes(fixedBytes, ref i); + fixedLength += 3; + + int AnimationListStart = 0; + int AnimationSourceListStart = 0; + int PhysicalAvatarEventListStart = 0; + do + { + int variableLength = 0; + int AnimationListCount = 0; + int AnimationSourceListCount = 0; + int PhysicalAvatarEventListCount = 0; + + i = AnimationListStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < AnimationList.Length) + { + int blockLength = AnimationList[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU) + { + variableLength += blockLength; + ++AnimationListCount; + } + else { break; } + ++i; + } + + i = AnimationSourceListStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < AnimationSourceList.Length) + { + int blockLength = AnimationSourceList[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU) + { + variableLength += blockLength; + ++AnimationSourceListCount; + } + else { break; } + ++i; + } + + i = PhysicalAvatarEventListStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < PhysicalAvatarEventList.Length) + { + int blockLength = PhysicalAvatarEventList[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU) + { + variableLength += blockLength; + ++PhysicalAvatarEventListCount; + } + else { break; } + ++i; + } + + int packetSize = fixedLength + variableLength + acksLength; + byte[] packet = pool.LeaseBytes(packetSize); + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)AnimationListCount; + for (i = AnimationListStart; i < AnimationListStart + AnimationListCount; i++) { AnimationList[i].ToBytes(packet, ref length); } + AnimationListStart += AnimationListCount; + + packet[length++] = (byte)AnimationSourceListCount; + for (i = AnimationSourceListStart; i < AnimationSourceListStart + AnimationSourceListCount; i++) { AnimationSourceList[i].ToBytes(packet, ref length); } + AnimationSourceListStart += AnimationSourceListCount; + + packet[length++] = (byte)PhysicalAvatarEventListCount; + for (i = PhysicalAvatarEventListStart; i < PhysicalAvatarEventListStart + PhysicalAvatarEventListCount; i++) { PhysicalAvatarEventList[i].ToBytes(packet, ref length); } + PhysicalAvatarEventListStart += PhysicalAvatarEventListCount; + + if (acksLength > 0) + { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + retSizes.Add(packetSize); + packets.Add(packet); + } while ( + AnimationListStart < AnimationList.Length || + AnimationSourceListStart < AnimationSourceList.Length || + PhysicalAvatarEventListStart < PhysicalAvatarEventList.Length); + + sizes = retSizes.ToArray(); + return packets.ToArray(); + } + } + + /// + public sealed class AvatarSitResponsePacket : Packet + { + public override bool UsesBufferPooling + { + get + { + return true; + } + } + + /// + public sealed class SitObjectBlock : PacketBlock + { + public UUID ID; + + public override int Length + { + get + { + return 16; + } + } + + public SitObjectBlock() { } + public SitObjectBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + ID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + ID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class SitTransformBlock : PacketBlock + { + public bool AutoPilot; + public Vector3 SitPosition; + public Quaternion SitRotation; + public Vector3 CameraEyeOffset; + public Vector3 CameraAtOffset; + public bool ForceMouselook; + + public override int Length + { + get + { + return 50; + } + } + + public SitTransformBlock() { } + public SitTransformBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AutoPilot = (bytes[i++] != 0) ? (bool)true : (bool)false; + SitPosition.FromBytes(bytes, i); i += 12; + SitRotation.FromBytes(bytes, i, true); i += 12; + CameraEyeOffset.FromBytes(bytes, i); i += 12; + CameraAtOffset.FromBytes(bytes, i); i += 12; + ForceMouselook = (bytes[i++] != 0) ? (bool)true : (bool)false; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + bytes[i++] = (byte)((AutoPilot) ? 1 : 0); + SitPosition.ToBytes(bytes, i); i += 12; + SitRotation.ToBytes(bytes, i); i += 12; + CameraEyeOffset.ToBytes(bytes, i); i += 12; + CameraAtOffset.ToBytes(bytes, i); i += 12; + bytes[i++] = (byte)((ForceMouselook) ? 1 : 0); + } + + } + + public override int Length + { + get + { + int length = 7; + length += SitObject.Length; + length += SitTransform.Length; + return length; + } + } + public SitObjectBlock SitObject; + public SitTransformBlock SitTransform; + + public AvatarSitResponsePacket() + { + HasVariableBlocks = false; + Type = PacketType.AvatarSitResponse; + Header = new Header(); + Header.Frequency = PacketFrequency.High; + Header.ID = 21; + Header.Reliable = true; + Header.Zerocoded = true; + SitObject = new SitObjectBlock(); + SitTransform = new SitTransformBlock(); + } + + public AvatarSitResponsePacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + SitObject.FromBytes(bytes, ref i); + SitTransform.FromBytes(bytes, ref i); + } + + public AvatarSitResponsePacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + SitObject.FromBytes(bytes, ref i); + SitTransform.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 7; + length += SitObject.Length; + length += SitTransform.Length; + if (Header.AckList != null && Header.AckList.Length > 0) { length += Header.AckList.Length * 4 + 1; } + byte[] bytes = new byte[length]; + int i = 0; + Header.ToBytes(bytes, ref i); + SitObject.ToBytes(bytes, ref i); + SitTransform.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + + public override byte[] ToBytes(Interfaces.IByteBufferPool pool, ref int size) + { + int length = 7; + length += SitObject.Length; + length += SitTransform.Length; + if (Header.AckList != null && Header.AckList.Length > 0) { length += Header.AckList.Length * 4 + 1; } + byte[] bytes = pool.LeaseBytes(length); + int i = 0; + Header.ToBytes(bytes, ref i); + SitObject.ToBytes(bytes, ref i); + SitTransform.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + + size = length; + return bytes; + } + + public override byte[][] ToBytesMultiple(Interfaces.IByteBufferPool pool, out int[] sizes) + { + sizes = new int[1]; + return new byte[][] { this.ToBytes(pool, ref sizes[0]) }; + } + } + + /// + public sealed class CameraConstraintPacket : Packet + { + public override bool UsesBufferPooling + { + get + { + return true; + } + } + + /// + public sealed class CameraCollidePlaneBlock : PacketBlock + { + public Vector4 Plane; + + public override int Length + { + get + { + return 16; + } + } + + public CameraCollidePlaneBlock() { } + public CameraCollidePlaneBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + Plane.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Plane.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 7; + length += CameraCollidePlane.Length; + return length; + } + } + public CameraCollidePlaneBlock CameraCollidePlane; + + public CameraConstraintPacket() + { + HasVariableBlocks = false; + Type = PacketType.CameraConstraint; + Header = new Header(); + Header.Frequency = PacketFrequency.High; + Header.ID = 22; + Header.Reliable = true; + Header.Zerocoded = true; + CameraCollidePlane = new CameraCollidePlaneBlock(); + } + + public CameraConstraintPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + CameraCollidePlane.FromBytes(bytes, ref i); + } + + public CameraConstraintPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + CameraCollidePlane.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 7; + length += CameraCollidePlane.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + + public override byte[] ToBytes(Interfaces.IByteBufferPool pool, ref int size) + { + int length = 7; + length += CameraCollidePlane.Length; + if (Header.AckList != null && Header.AckList.Length > 0) { length += Header.AckList.Length * 4 + 1; } + byte[] bytes = pool.LeaseBytes(length); + int i = 0; + Header.ToBytes(bytes, ref i); + CameraCollidePlane.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + + size = length; + return bytes; + } + + public override byte[][] ToBytesMultiple(Interfaces.IByteBufferPool pool, out int[] sizes) + { + sizes = new int[1]; + return new byte[][] { this.ToBytes(pool, ref sizes[0]) }; + } + } + + /// + public sealed class ParcelPropertiesPacket : Packet + { + public override bool UsesBufferPooling + { + get + { + return true; + } + } + + /// + public sealed class ParcelDataBlock : PacketBlock + { + public int RequestResult; + public int SequenceID; + public bool SnapSelection; + public int SelfCount; + public int OtherCount; + public int PublicCount; + public int LocalID; + public UUID OwnerID; + public bool IsGroupOwned; + public uint AuctionID; + public int ClaimDate; + public int ClaimPrice; + public int RentPrice; + public Vector3 AABBMin; + public Vector3 AABBMax; + public byte[] Bitmap; + public int Area; + public byte Status; + public int SimWideMaxPrims; + public int SimWideTotalPrims; + public int MaxPrims; + public int TotalPrims; + public int OwnerPrims; + public int GroupPrims; + public int OtherPrims; + public int SelectedPrims; + public float ParcelPrimBonus; + public int OtherCleanTime; + public uint ParcelFlags; + public int SalePrice; + public byte[] Name; + public byte[] Desc; + public byte[] MusicURL; + public byte[] MediaURL; + public UUID MediaID; + public byte MediaAutoScale; + public UUID GroupID; + public int PassPrice; + public float PassHours; + public byte Category; + public UUID AuthBuyerID; + public UUID SnapshotID; + public Vector3 UserLocation; + public Vector3 UserLookAt; + public byte LandingType; + public bool RegionPushOverride; + public bool RegionDenyAnonymous; + public bool RegionDenyIdentified; + public bool RegionDenyTransacted; + + public override int Length + { + get + { + int length = 244; + if (Bitmap != null) { length += Bitmap.Length; } + if (Name != null) { length += Name.Length; } + if (Desc != null) { length += Desc.Length; } + if (MusicURL != null) { length += MusicURL.Length; } + if (MediaURL != null) { length += MediaURL.Length; } + return length; + } + } + + public ParcelDataBlock() { } + public ParcelDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + RequestResult = (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)); + SnapSelection = (bytes[i++] != 0) ? (bool)true : (bool)false; + SelfCount = (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)); + PublicCount = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + LocalID = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + OwnerID.FromBytes(bytes, i); i += 16; + IsGroupOwned = (bytes[i++] != 0) ? (bool)true : (bool)false; + AuctionID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + ClaimDate = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + 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)); + AABBMin.FromBytes(bytes, i); i += 12; + AABBMax.FromBytes(bytes, i); i += 12; + length = (bytes[i++] + (bytes[i++] << 8)); + Bitmap = new byte[length]; + Buffer.BlockCopy(bytes, i, Bitmap, 0, length); i += length; + Area = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + Status = (byte)bytes[i++]; + SimWideMaxPrims = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + SimWideTotalPrims = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + MaxPrims = (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)); + OwnerPrims = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + GroupPrims = (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)); + SelectedPrims = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + ParcelPrimBonus = Utils.BytesToFloat(bytes, i); i += 4; + OtherCleanTime = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + ParcelFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + SalePrice = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + length = bytes[i++]; + Name = new byte[length]; + Buffer.BlockCopy(bytes, i, Name, 0, length); i += length; + length = bytes[i++]; + Desc = new byte[length]; + Buffer.BlockCopy(bytes, i, Desc, 0, length); i += length; + length = bytes[i++]; + MusicURL = new byte[length]; + Buffer.BlockCopy(bytes, i, MusicURL, 0, length); i += length; + length = bytes[i++]; + MediaURL = new byte[length]; + Buffer.BlockCopy(bytes, i, MediaURL, 0, length); i += length; + MediaID.FromBytes(bytes, i); i += 16; + MediaAutoScale = (byte)bytes[i++]; + GroupID.FromBytes(bytes, i); i += 16; + PassPrice = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + PassHours = Utils.BytesToFloat(bytes, i); i += 4; + Category = (byte)bytes[i++]; + AuthBuyerID.FromBytes(bytes, i); i += 16; + SnapshotID.FromBytes(bytes, i); i += 16; + UserLocation.FromBytes(bytes, i); i += 12; + UserLookAt.FromBytes(bytes, i); i += 12; + LandingType = (byte)bytes[i++]; + RegionPushOverride = (bytes[i++] != 0) ? (bool)true : (bool)false; + RegionDenyAnonymous = (bytes[i++] != 0) ? (bool)true : (bool)false; + RegionDenyIdentified = (bytes[i++] != 0) ? (bool)true : (bool)false; + RegionDenyTransacted = (bytes[i++] != 0) ? (bool)true : (bool)false; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.IntToBytes(RequestResult, bytes, i); i += 4; + Utils.IntToBytes(SequenceID, bytes, i); i += 4; + bytes[i++] = (byte)((SnapSelection) ? 1 : 0); + Utils.IntToBytes(SelfCount, bytes, i); i += 4; + Utils.IntToBytes(OtherCount, bytes, i); i += 4; + Utils.IntToBytes(PublicCount, bytes, i); i += 4; + Utils.IntToBytes(LocalID, bytes, i); i += 4; + OwnerID.ToBytes(bytes, i); i += 16; + bytes[i++] = (byte)((IsGroupOwned) ? 1 : 0); + Utils.UIntToBytes(AuctionID, bytes, i); i += 4; + Utils.IntToBytes(ClaimDate, bytes, i); i += 4; + Utils.IntToBytes(ClaimPrice, bytes, i); i += 4; + Utils.IntToBytes(RentPrice, bytes, i); i += 4; + AABBMin.ToBytes(bytes, i); i += 12; + AABBMax.ToBytes(bytes, i); i += 12; + bytes[i++] = (byte)(Bitmap.Length % 256); + bytes[i++] = (byte)((Bitmap.Length >> 8) % 256); + Buffer.BlockCopy(Bitmap, 0, bytes, i, Bitmap.Length); i += Bitmap.Length; + Utils.IntToBytes(Area, bytes, i); i += 4; + bytes[i++] = Status; + Utils.IntToBytes(SimWideMaxPrims, bytes, i); i += 4; + Utils.IntToBytes(SimWideTotalPrims, bytes, i); i += 4; + Utils.IntToBytes(MaxPrims, bytes, i); i += 4; + Utils.IntToBytes(TotalPrims, bytes, i); i += 4; + Utils.IntToBytes(OwnerPrims, bytes, i); i += 4; + Utils.IntToBytes(GroupPrims, bytes, i); i += 4; + Utils.IntToBytes(OtherPrims, bytes, i); i += 4; + Utils.IntToBytes(SelectedPrims, bytes, i); i += 4; + Utils.FloatToBytes(ParcelPrimBonus, bytes, i); i += 4; + Utils.IntToBytes(OtherCleanTime, bytes, i); i += 4; + Utils.UIntToBytes(ParcelFlags, bytes, i); i += 4; + Utils.IntToBytes(SalePrice, bytes, i); i += 4; + bytes[i++] = (byte)Name.Length; + Buffer.BlockCopy(Name, 0, bytes, i, Name.Length); i += Name.Length; + bytes[i++] = (byte)Desc.Length; + Buffer.BlockCopy(Desc, 0, bytes, i, Desc.Length); i += Desc.Length; + bytes[i++] = (byte)MusicURL.Length; + Buffer.BlockCopy(MusicURL, 0, bytes, i, MusicURL.Length); i += MusicURL.Length; + bytes[i++] = (byte)MediaURL.Length; + Buffer.BlockCopy(MediaURL, 0, bytes, i, MediaURL.Length); i += MediaURL.Length; + MediaID.ToBytes(bytes, i); i += 16; + bytes[i++] = MediaAutoScale; + GroupID.ToBytes(bytes, i); i += 16; + Utils.IntToBytes(PassPrice, bytes, i); i += 4; + Utils.FloatToBytes(PassHours, bytes, i); i += 4; + bytes[i++] = Category; + AuthBuyerID.ToBytes(bytes, i); i += 16; + SnapshotID.ToBytes(bytes, i); i += 16; + UserLocation.ToBytes(bytes, i); i += 12; + UserLookAt.ToBytes(bytes, i); i += 12; + bytes[i++] = LandingType; + bytes[i++] = (byte)((RegionPushOverride) ? 1 : 0); + bytes[i++] = (byte)((RegionDenyAnonymous) ? 1 : 0); + bytes[i++] = (byte)((RegionDenyIdentified) ? 1 : 0); + bytes[i++] = (byte)((RegionDenyTransacted) ? 1 : 0); + } + + } + + /// + public sealed class AgeVerificationBlockBlock : PacketBlock + { + public bool RegionDenyAgeUnverified; + + public override int Length + { + get + { + return 1; + } + } + + public AgeVerificationBlockBlock() { } + public AgeVerificationBlockBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + RegionDenyAgeUnverified = (bytes[i++] != 0) ? (bool)true : (bool)false; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + bytes[i++] = (byte)((RegionDenyAgeUnverified) ? 1 : 0); + } + + } + + /// + public sealed class RegionAllowAccessBlockBlock : PacketBlock + { + public bool RegionAllowAccessOverride; + + public override int Length + { + get + { + return 1; + } + } + + public RegionAllowAccessBlockBlock() { } + public RegionAllowAccessBlockBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + RegionAllowAccessOverride = (bytes[i++] != 0) ? (bool)true : (bool)false; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + bytes[i++] = (byte)((RegionAllowAccessOverride) ? 1 : 0); + } + + } + + public override int Length + { + get + { + int length = 7; + length += ParcelData.Length; + length += AgeVerificationBlock.Length; + length += RegionAllowAccessBlock.Length; + return length; + } + } + public ParcelDataBlock ParcelData; + public AgeVerificationBlockBlock AgeVerificationBlock; + public RegionAllowAccessBlockBlock RegionAllowAccessBlock; + + public ParcelPropertiesPacket() + { + HasVariableBlocks = false; + Type = PacketType.ParcelProperties; + Header = new Header(); + Header.Frequency = PacketFrequency.High; + Header.ID = 23; + Header.Reliable = true; + Header.Zerocoded = true; + ParcelData = new ParcelDataBlock(); + AgeVerificationBlock = new AgeVerificationBlockBlock(); + RegionAllowAccessBlock = new RegionAllowAccessBlockBlock(); + } + + public ParcelPropertiesPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + ParcelData.FromBytes(bytes, ref i); + AgeVerificationBlock.FromBytes(bytes, ref i); + RegionAllowAccessBlock.FromBytes(bytes, ref i); + } + + public ParcelPropertiesPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + ParcelData.FromBytes(bytes, ref i); + AgeVerificationBlock.FromBytes(bytes, ref i); + RegionAllowAccessBlock.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 7; + length += ParcelData.Length; + length += AgeVerificationBlock.Length; + length += RegionAllowAccessBlock.Length; + if (Header.AckList != null && 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); + AgeVerificationBlock.ToBytes(bytes, ref i); + RegionAllowAccessBlock.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + + public override byte[] ToBytes(Interfaces.IByteBufferPool pool, ref int size) + { + int length = 7; + length += ParcelData.Length; + length += AgeVerificationBlock.Length; + if (Header.AckList != null && Header.AckList.Length > 0) { length += Header.AckList.Length * 4 + 1; } + byte[] bytes = pool.LeaseBytes(length); + int i = 0; + Header.ToBytes(bytes, ref i); + ParcelData.ToBytes(bytes, ref i); + AgeVerificationBlock.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + + size = length; + return bytes; + } + + public override byte[][] ToBytesMultiple(Interfaces.IByteBufferPool pool, out int[] sizes) + { + sizes = new int[1]; + return new byte[][] { this.ToBytes(pool, ref sizes[0]) }; + } + } + + /// + public sealed class ChildAgentUpdatePacket : Packet + { + public override bool UsesBufferPooling + { + get + { + return true; + } + } + + /// + public sealed class AgentDataBlock : PacketBlock + { + public ulong RegionHandle; + public uint ViewerCircuitCode; + public UUID AgentID; + public UUID SessionID; + public Vector3 AgentPos; + public Vector3 AgentVel; + public Vector3 Center; + public Vector3 Size; + public Vector3 AtAxis; + public Vector3 LeftAxis; + public Vector3 UpAxis; + public bool ChangedGrid; + public float Far; + public float Aspect; + public byte[] Throttles; + public uint LocomotionState; + public Quaternion HeadRotation; + public Quaternion BodyRotation; + public uint ControlFlags; + public float EnergyLevel; + public byte GodLevel; + public bool AlwaysRun; + public UUID PreyAgent; + public byte AgentAccess; + public byte[] AgentTextures; + public UUID ActiveGroupID; + + public override int Length + { + get + { + int length = 211; + if (Throttles != null) { length += Throttles.Length; } + if (AgentTextures != null) { length += AgentTextures.Length; } + return length; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + 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)); + ViewerCircuitCode = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + AgentPos.FromBytes(bytes, i); i += 12; + AgentVel.FromBytes(bytes, i); i += 12; + Center.FromBytes(bytes, i); i += 12; + Size.FromBytes(bytes, i); i += 12; + AtAxis.FromBytes(bytes, i); i += 12; + LeftAxis.FromBytes(bytes, i); i += 12; + UpAxis.FromBytes(bytes, i); i += 12; + ChangedGrid = (bytes[i++] != 0) ? (bool)true : (bool)false; + Far = Utils.BytesToFloat(bytes, i); i += 4; + Aspect = Utils.BytesToFloat(bytes, i); i += 4; + length = bytes[i++]; + Throttles = new byte[length]; + Buffer.BlockCopy(bytes, i, Throttles, 0, length); i += length; + LocomotionState = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + HeadRotation.FromBytes(bytes, i, true); i += 12; + BodyRotation.FromBytes(bytes, i, true); i += 12; + ControlFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + EnergyLevel = Utils.BytesToFloat(bytes, i); i += 4; + GodLevel = (byte)bytes[i++]; + AlwaysRun = (bytes[i++] != 0) ? (bool)true : (bool)false; + PreyAgent.FromBytes(bytes, i); i += 16; + AgentAccess = (byte)bytes[i++]; + length = (bytes[i++] + (bytes[i++] << 8)); + AgentTextures = new byte[length]; + Buffer.BlockCopy(bytes, i, AgentTextures, 0, length); i += length; + ActiveGroupID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UInt64ToBytes(RegionHandle, bytes, i); i += 8; + Utils.UIntToBytes(ViewerCircuitCode, bytes, i); i += 4; + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + AgentPos.ToBytes(bytes, i); i += 12; + AgentVel.ToBytes(bytes, i); i += 12; + Center.ToBytes(bytes, i); i += 12; + Size.ToBytes(bytes, i); i += 12; + AtAxis.ToBytes(bytes, i); i += 12; + LeftAxis.ToBytes(bytes, i); i += 12; + UpAxis.ToBytes(bytes, i); i += 12; + bytes[i++] = (byte)((ChangedGrid) ? 1 : 0); + Utils.FloatToBytes(Far, bytes, i); i += 4; + Utils.FloatToBytes(Aspect, bytes, i); i += 4; + bytes[i++] = (byte)Throttles.Length; + Buffer.BlockCopy(Throttles, 0, bytes, i, Throttles.Length); i += Throttles.Length; + Utils.UIntToBytes(LocomotionState, bytes, i); i += 4; + HeadRotation.ToBytes(bytes, i); i += 12; + BodyRotation.ToBytes(bytes, i); i += 12; + Utils.UIntToBytes(ControlFlags, bytes, i); i += 4; + Utils.FloatToBytes(EnergyLevel, bytes, i); i += 4; + bytes[i++] = GodLevel; + bytes[i++] = (byte)((AlwaysRun) ? 1 : 0); + PreyAgent.ToBytes(bytes, i); i += 16; + bytes[i++] = AgentAccess; + bytes[i++] = (byte)(AgentTextures.Length % 256); + bytes[i++] = (byte)((AgentTextures.Length >> 8) % 256); + Buffer.BlockCopy(AgentTextures, 0, bytes, i, AgentTextures.Length); i += AgentTextures.Length; + ActiveGroupID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class GroupDataBlock : PacketBlock + { + public UUID GroupID; + public ulong GroupPowers; + public bool AcceptNotices; + + public override int Length + { + get + { + return 25; + } + } + + public GroupDataBlock() { } + public GroupDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + GroupID.FromBytes(bytes, i); i += 16; + 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)); + AcceptNotices = (bytes[i++] != 0) ? (bool)true : (bool)false; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + GroupID.ToBytes(bytes, i); i += 16; + Utils.UInt64ToBytes(GroupPowers, bytes, i); i += 8; + bytes[i++] = (byte)((AcceptNotices) ? 1 : 0); + } + + } + + /// + public sealed class AnimationDataBlock : PacketBlock + { + public UUID Animation; + public UUID ObjectID; + + public override int Length + { + get + { + return 32; + } + } + + public AnimationDataBlock() { } + public AnimationDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + Animation.FromBytes(bytes, i); i += 16; + ObjectID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Animation.ToBytes(bytes, i); i += 16; + ObjectID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class GranterBlockBlock : PacketBlock + { + public UUID GranterID; + + public override int Length + { + get + { + return 16; + } + } + + public GranterBlockBlock() { } + public GranterBlockBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + GranterID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + GranterID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class NVPairDataBlock : PacketBlock + { + public byte[] NVPairs; + + public override int Length + { + get + { + int length = 2; + if (NVPairs != null) { length += NVPairs.Length; } + return length; + } + } + + public NVPairDataBlock() { } + public NVPairDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + length = (bytes[i++] + (bytes[i++] << 8)); + NVPairs = new byte[length]; + Buffer.BlockCopy(bytes, i, NVPairs, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + bytes[i++] = (byte)(NVPairs.Length % 256); + bytes[i++] = (byte)((NVPairs.Length >> 8) % 256); + Buffer.BlockCopy(NVPairs, 0, bytes, i, NVPairs.Length); i += NVPairs.Length; + } + + } + + /// + public sealed class VisualParamBlock : PacketBlock + { + public byte ParamValue; + + public override int Length + { + get + { + return 1; + } + } + + public VisualParamBlock() { } + public VisualParamBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + ParamValue = (byte)bytes[i++]; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + bytes[i++] = ParamValue; + } + + } + + /// + public sealed class AgentAccessBlock : PacketBlock + { + public byte AgentLegacyAccess; + public byte AgentMaxAccess; + + public override int Length + { + get + { + return 2; + } + } + + public AgentAccessBlock() { } + public AgentAccessBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AgentLegacyAccess = (byte)bytes[i++]; + AgentMaxAccess = (byte)bytes[i++]; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + bytes[i++] = AgentLegacyAccess; + bytes[i++] = AgentMaxAccess; + } + + } + + /// + public sealed class AgentInfoBlock : PacketBlock + { + public uint Flags; + + public override int Length + { + get + { + return 4; + } + } + + public AgentInfoBlock() { } + public AgentInfoBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + Flags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UIntToBytes(Flags, bytes, i); i += 4; + } + + } + + /// + public sealed class AgentInventoryHostBlock : PacketBlock + { + public byte[] InventoryHost; + + public override int Length + { + get + { + int length = 1; + if (InventoryHost != null) { length += InventoryHost.Length; } + return length; + } + } + + public AgentInventoryHostBlock() { } + public AgentInventoryHostBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + int length; + try + { + length = bytes[i++]; + InventoryHost = new byte[length]; + Buffer.BlockCopy(bytes, i, InventoryHost, 0, length); i += length; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + bytes[i++] = (byte)InventoryHost.Length; + Buffer.BlockCopy(InventoryHost, 0, bytes, i, InventoryHost.Length); i += InventoryHost.Length; + } + + } + + public override int Length + { + get + { + int length = 15; + length += AgentData.Length; + for (int j = 0; j < GroupData.Length; j++) + length += GroupData[j].Length; + for (int j = 0; j < AnimationData.Length; j++) + length += AnimationData[j].Length; + for (int j = 0; j < GranterBlock.Length; j++) + length += GranterBlock[j].Length; + for (int j = 0; j < NVPairData.Length; j++) + length += NVPairData[j].Length; + for (int j = 0; j < VisualParam.Length; j++) + length += VisualParam[j].Length; + for (int j = 0; j < AgentAccess.Length; j++) + length += AgentAccess[j].Length; + for (int j = 0; j < AgentInfo.Length; j++) + length += AgentInfo[j].Length; + for (int j = 0; j < AgentInventoryHost.Length; j++) + length += AgentInventoryHost[j].Length; + return length; + } + } + public AgentDataBlock AgentData; + public GroupDataBlock[] GroupData; + public AnimationDataBlock[] AnimationData; + public GranterBlockBlock[] GranterBlock; + public NVPairDataBlock[] NVPairData; + public VisualParamBlock[] VisualParam; + public AgentAccessBlock[] AgentAccess; + public AgentInfoBlock[] AgentInfo; + public AgentInventoryHostBlock[] AgentInventoryHost; + + public ChildAgentUpdatePacket() + { + HasVariableBlocks = true; + Type = PacketType.ChildAgentUpdate; + Header = new Header(); + Header.Frequency = PacketFrequency.High; + Header.ID = 25; + Header.Reliable = true; + Header.Zerocoded = true; + AgentData = new AgentDataBlock(); + GroupData = null; + AnimationData = null; + GranterBlock = null; + NVPairData = null; + VisualParam = null; + AgentAccess = null; + AgentInfo = null; + AgentInventoryHost = null; + } + + public ChildAgentUpdatePacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(GroupData == null || GroupData.Length != -1) { + GroupData = new GroupDataBlock[count]; + for(int j = 0; j < count; j++) + { GroupData[j] = new GroupDataBlock(); } + } + for (int j = 0; j < count; j++) + { GroupData[j].FromBytes(bytes, ref i); } + count = (int)bytes[i++]; + if(AnimationData == null || AnimationData.Length != -1) { + AnimationData = new AnimationDataBlock[count]; + for(int j = 0; j < count; j++) + { AnimationData[j] = new AnimationDataBlock(); } + } + for (int j = 0; j < count; j++) + { AnimationData[j].FromBytes(bytes, ref i); } + count = (int)bytes[i++]; + if(GranterBlock == null || GranterBlock.Length != -1) { + GranterBlock = new GranterBlockBlock[count]; + for(int j = 0; j < count; j++) + { GranterBlock[j] = new GranterBlockBlock(); } + } + for (int j = 0; j < count; j++) + { GranterBlock[j].FromBytes(bytes, ref i); } + count = (int)bytes[i++]; + if(NVPairData == null || NVPairData.Length != -1) { + NVPairData = new NVPairDataBlock[count]; + for(int j = 0; j < count; j++) + { NVPairData[j] = new NVPairDataBlock(); } + } + for (int j = 0; j < count; j++) + { NVPairData[j].FromBytes(bytes, ref i); } + count = (int)bytes[i++]; + if(VisualParam == null || VisualParam.Length != -1) { + VisualParam = new VisualParamBlock[count]; + for(int j = 0; j < count; j++) + { VisualParam[j] = new VisualParamBlock(); } + } + for (int j = 0; j < count; j++) + { VisualParam[j].FromBytes(bytes, ref i); } + count = (int)bytes[i++]; + if(AgentAccess == null || AgentAccess.Length != -1) { + AgentAccess = new AgentAccessBlock[count]; + for(int j = 0; j < count; j++) + { AgentAccess[j] = new AgentAccessBlock(); } + } + for (int j = 0; j < count; j++) + { AgentAccess[j].FromBytes(bytes, ref i); } + count = (int)bytes[i++]; + if(AgentInfo == null || AgentInfo.Length != -1) { + AgentInfo = new AgentInfoBlock[count]; + for(int j = 0; j < count; j++) + { AgentInfo[j] = new AgentInfoBlock(); } + } + for (int j = 0; j < count; j++) + { AgentInfo[j].FromBytes(bytes, ref i); } + count = (int)bytes[i++]; + if(AgentInventoryHost == null || AgentInventoryHost.Length != -1) { + AgentInventoryHost = new AgentInventoryHostBlock[count]; + for(int j = 0; j < count; j++) + { AgentInventoryHost[j] = new AgentInventoryHostBlock(); } + } + for (int j = 0; j < count; j++) + { AgentInventoryHost[j].FromBytes(bytes, ref i); } + } + + public ChildAgentUpdatePacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(GroupData == null || GroupData.Length != count) { + GroupData = new GroupDataBlock[count]; + for(int j = 0; j < count; j++) + { GroupData[j] = new GroupDataBlock(); } + } + for (int j = 0; j < count; j++) + { GroupData[j].FromBytes(bytes, ref i); } + count = (int)bytes[i++]; + if(AnimationData == null || AnimationData.Length != count) { + AnimationData = new AnimationDataBlock[count]; + for(int j = 0; j < count; j++) + { AnimationData[j] = new AnimationDataBlock(); } + } + for (int j = 0; j < count; j++) + { AnimationData[j].FromBytes(bytes, ref i); } + count = (int)bytes[i++]; + if(GranterBlock == null || GranterBlock.Length != count) { + GranterBlock = new GranterBlockBlock[count]; + for(int j = 0; j < count; j++) + { GranterBlock[j] = new GranterBlockBlock(); } + } + for (int j = 0; j < count; j++) + { GranterBlock[j].FromBytes(bytes, ref i); } + count = (int)bytes[i++]; + if(NVPairData == null || NVPairData.Length != count) { + NVPairData = new NVPairDataBlock[count]; + for(int j = 0; j < count; j++) + { NVPairData[j] = new NVPairDataBlock(); } + } + for (int j = 0; j < count; j++) + { NVPairData[j].FromBytes(bytes, ref i); } + count = (int)bytes[i++]; + if(VisualParam == null || VisualParam.Length != count) { + VisualParam = new VisualParamBlock[count]; + for(int j = 0; j < count; j++) + { VisualParam[j] = new VisualParamBlock(); } + } + for (int j = 0; j < count; j++) + { VisualParam[j].FromBytes(bytes, ref i); } + count = (int)bytes[i++]; + if(AgentAccess == null || AgentAccess.Length != count) { + AgentAccess = new AgentAccessBlock[count]; + for(int j = 0; j < count; j++) + { AgentAccess[j] = new AgentAccessBlock(); } + } + for (int j = 0; j < count; j++) + { AgentAccess[j].FromBytes(bytes, ref i); } + count = (int)bytes[i++]; + if(AgentInfo == null || AgentInfo.Length != count) { + AgentInfo = new AgentInfoBlock[count]; + for(int j = 0; j < count; j++) + { AgentInfo[j] = new AgentInfoBlock(); } + } + for (int j = 0; j < count; j++) + { AgentInfo[j].FromBytes(bytes, ref i); } + count = (int)bytes[i++]; + if(AgentInventoryHost == null || AgentInventoryHost.Length != count) { + AgentInventoryHost = new AgentInventoryHostBlock[count]; + for(int j = 0; j < count; j++) + { AgentInventoryHost[j] = new AgentInventoryHostBlock(); } + } + for (int j = 0; j < count; j++) + { AgentInventoryHost[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 7; + length += AgentData.Length; + length++; + for (int j = 0; j < GroupData.Length; j++) { length += GroupData[j].Length; } + length++; + for (int j = 0; j < AnimationData.Length; j++) { length += AnimationData[j].Length; } + length++; + for (int j = 0; j < GranterBlock.Length; j++) { length += GranterBlock[j].Length; } + length++; + for (int j = 0; j < NVPairData.Length; j++) { length += NVPairData[j].Length; } + length++; + for (int j = 0; j < VisualParam.Length; j++) { length += VisualParam[j].Length; } + length++; + for (int j = 0; j < AgentAccess.Length; j++) { length += AgentAccess[j].Length; } + length++; + for (int j = 0; j < AgentInfo.Length; j++) { length += AgentInfo[j].Length; } + length++; + for (int j = 0; j < AgentInventoryHost.Length; j++) { length += AgentInventoryHost[j].Length; } + if (Header.AckList != null && 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); } + bytes[i++] = (byte)AnimationData.Length; + for (int j = 0; j < AnimationData.Length; j++) { AnimationData[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)NVPairData.Length; + for (int j = 0; j < NVPairData.Length; j++) { NVPairData[j].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)AgentAccess.Length; + for (int j = 0; j < AgentAccess.Length; j++) { AgentAccess[j].ToBytes(bytes, ref i); } + bytes[i++] = (byte)AgentInfo.Length; + for (int j = 0; j < AgentInfo.Length; j++) { AgentInfo[j].ToBytes(bytes, ref i); } + bytes[i++] = (byte)AgentInventoryHost.Length; + for (int j = 0; j < AgentInventoryHost.Length; j++) { AgentInventoryHost[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 7; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + fixedLength += 8; + + int GroupDataStart = 0; + int AnimationDataStart = 0; + int GranterBlockStart = 0; + int NVPairDataStart = 0; + int VisualParamStart = 0; + int AgentAccessStart = 0; + int AgentInfoStart = 0; + int AgentInventoryHostStart = 0; + do + { + int variableLength = 0; + int GroupDataCount = 0; + int AnimationDataCount = 0; + int GranterBlockCount = 0; + int NVPairDataCount = 0; + int VisualParamCount = 0; + int AgentAccessCount = 0; + int AgentInfoCount = 0; + int AgentInventoryHostCount = 0; + + i = GroupDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < GroupData.Length) { + int blockLength = GroupData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == GroupDataStart) { + variableLength += blockLength; + ++GroupDataCount; + } + else { break; } + ++i; + } + + i = AnimationDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < AnimationData.Length) { + int blockLength = AnimationData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == AnimationDataStart) { + variableLength += blockLength; + ++AnimationDataCount; + } + else { break; } + ++i; + } + + i = GranterBlockStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < GranterBlock.Length) { + int blockLength = GranterBlock[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == GranterBlockStart) { + variableLength += blockLength; + ++GranterBlockCount; + } + else { break; } + ++i; + } + + i = NVPairDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < NVPairData.Length) { + int blockLength = NVPairData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == NVPairDataStart) { + variableLength += blockLength; + ++NVPairDataCount; + } + else { break; } + ++i; + } + + i = VisualParamStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < VisualParam.Length) { + int blockLength = VisualParam[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == VisualParamStart) { + variableLength += blockLength; + ++VisualParamCount; + } + else { break; } + ++i; + } + + i = AgentAccessStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < AgentAccess.Length) { + int blockLength = AgentAccess[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == AgentAccessStart) { + variableLength += blockLength; + ++AgentAccessCount; + } + else { break; } + ++i; + } + + i = AgentInfoStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < AgentInfo.Length) { + int blockLength = AgentInfo[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == AgentInfoStart) { + variableLength += blockLength; + ++AgentInfoCount; + } + else { break; } + ++i; + } + + i = AgentInventoryHostStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < AgentInventoryHost.Length) { + int blockLength = AgentInventoryHost[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == AgentInventoryHostStart) { + variableLength += blockLength; + ++AgentInventoryHostCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)GroupDataCount; + for (i = GroupDataStart; i < GroupDataStart + GroupDataCount; i++) { GroupData[i].ToBytes(packet, ref length); } + GroupDataStart += GroupDataCount; + + packet[length++] = (byte)AnimationDataCount; + for (i = AnimationDataStart; i < AnimationDataStart + AnimationDataCount; i++) { AnimationData[i].ToBytes(packet, ref length); } + AnimationDataStart += AnimationDataCount; + + packet[length++] = (byte)GranterBlockCount; + for (i = GranterBlockStart; i < GranterBlockStart + GranterBlockCount; i++) { GranterBlock[i].ToBytes(packet, ref length); } + GranterBlockStart += GranterBlockCount; + + packet[length++] = (byte)NVPairDataCount; + for (i = NVPairDataStart; i < NVPairDataStart + NVPairDataCount; i++) { NVPairData[i].ToBytes(packet, ref length); } + NVPairDataStart += NVPairDataCount; + + packet[length++] = (byte)VisualParamCount; + for (i = VisualParamStart; i < VisualParamStart + VisualParamCount; i++) { VisualParam[i].ToBytes(packet, ref length); } + VisualParamStart += VisualParamCount; + + packet[length++] = (byte)AgentAccessCount; + for (i = AgentAccessStart; i < AgentAccessStart + AgentAccessCount; i++) { AgentAccess[i].ToBytes(packet, ref length); } + AgentAccessStart += AgentAccessCount; + + packet[length++] = (byte)AgentInfoCount; + for (i = AgentInfoStart; i < AgentInfoStart + AgentInfoCount; i++) { AgentInfo[i].ToBytes(packet, ref length); } + AgentInfoStart += AgentInfoCount; + + packet[length++] = (byte)AgentInventoryHostCount; + for (i = AgentInventoryHostStart; i < AgentInventoryHostStart + AgentInventoryHostCount; i++) { AgentInventoryHost[i].ToBytes(packet, ref length); } + AgentInventoryHostStart += AgentInventoryHostCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + GroupDataStart < GroupData.Length || + AnimationDataStart < AnimationData.Length || + GranterBlockStart < GranterBlock.Length || + NVPairDataStart < NVPairData.Length || + VisualParamStart < VisualParam.Length || + AgentAccessStart < AgentAccess.Length || + AgentInfoStart < AgentInfo.Length || + AgentInventoryHostStart < AgentInventoryHost.Length); + + return packets.ToArray(); + } + + public override byte[] ToBytes(Interfaces.IByteBufferPool pool, ref int size) + { + int length = 7; + length += AgentData.Length; + length++; + for (int j = 0; j < GroupData.Length; j++) { length += GroupData[j].Length; } + length++; + for (int j = 0; j < AnimationData.Length; j++) { length += AnimationData[j].Length; } + length++; + for (int j = 0; j < GranterBlock.Length; j++) { length += GranterBlock[j].Length; } + length++; + for (int j = 0; j < NVPairData.Length; j++) { length += NVPairData[j].Length; } + length++; + for (int j = 0; j < VisualParam.Length; j++) { length += VisualParam[j].Length; } + length++; + for (int j = 0; j < AgentAccess.Length; j++) { length += AgentAccess[j].Length; } + length++; + for (int j = 0; j < AgentInfo.Length; j++) { length += AgentInfo[j].Length; } + if (Header.AckList != null && Header.AckList.Length > 0) { length += Header.AckList.Length * 4 + 1; } + byte[] bytes = pool.LeaseBytes(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); } + bytes[i++] = (byte)AnimationData.Length; + for (int j = 0; j < AnimationData.Length; j++) { AnimationData[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)NVPairData.Length; + for (int j = 0; j < NVPairData.Length; j++) { NVPairData[j].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)AgentAccess.Length; + for (int j = 0; j < AgentAccess.Length; j++) { AgentAccess[j].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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + + size = length; + return bytes; + } + + public override byte[][] ToBytesMultiple(Interfaces.IByteBufferPool pool, out int[] sizes) + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + System.Collections.Generic.List retSizes = new System.Collections.Generic.List(); + + int i = 0; + int fixedLength = 7; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) + { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += AgentData.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + AgentData.ToBytes(fixedBytes, ref i); + fixedLength += 7; + + int GroupDataStart = 0; + int AnimationDataStart = 0; + int GranterBlockStart = 0; + int NVPairDataStart = 0; + int VisualParamStart = 0; + int AgentAccessStart = 0; + int AgentInfoStart = 0; + do + { + int variableLength = 0; + int GroupDataCount = 0; + int AnimationDataCount = 0; + int GranterBlockCount = 0; + int NVPairDataCount = 0; + int VisualParamCount = 0; + int AgentAccessCount = 0; + int AgentInfoCount = 0; + + i = GroupDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < GroupData.Length) + { + int blockLength = GroupData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU) + { + variableLength += blockLength; + ++GroupDataCount; + } + else { break; } + ++i; + } + + i = AnimationDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < AnimationData.Length) + { + int blockLength = AnimationData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU) + { + variableLength += blockLength; + ++AnimationDataCount; + } + else { break; } + ++i; + } + + i = GranterBlockStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < GranterBlock.Length) + { + int blockLength = GranterBlock[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU) + { + variableLength += blockLength; + ++GranterBlockCount; + } + else { break; } + ++i; + } + + i = NVPairDataStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < NVPairData.Length) + { + int blockLength = NVPairData[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU) + { + variableLength += blockLength; + ++NVPairDataCount; + } + else { break; } + ++i; + } + + i = VisualParamStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < VisualParam.Length) + { + int blockLength = VisualParam[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU) + { + variableLength += blockLength; + ++VisualParamCount; + } + else { break; } + ++i; + } + + i = AgentAccessStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < AgentAccess.Length) + { + int blockLength = AgentAccess[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU) + { + variableLength += blockLength; + ++AgentAccessCount; + } + else { break; } + ++i; + } + + i = AgentInfoStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < AgentInfo.Length) + { + int blockLength = AgentInfo[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU) + { + variableLength += blockLength; + ++AgentInfoCount; + } + else { break; } + ++i; + } + + int packetSize = fixedLength + variableLength + acksLength; + byte[] packet = pool.LeaseBytes(packetSize); + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)GroupDataCount; + for (i = GroupDataStart; i < GroupDataStart + GroupDataCount; i++) { GroupData[i].ToBytes(packet, ref length); } + GroupDataStart += GroupDataCount; + + packet[length++] = (byte)AnimationDataCount; + for (i = AnimationDataStart; i < AnimationDataStart + AnimationDataCount; i++) { AnimationData[i].ToBytes(packet, ref length); } + AnimationDataStart += AnimationDataCount; + + packet[length++] = (byte)GranterBlockCount; + for (i = GranterBlockStart; i < GranterBlockStart + GranterBlockCount; i++) { GranterBlock[i].ToBytes(packet, ref length); } + GranterBlockStart += GranterBlockCount; + + packet[length++] = (byte)NVPairDataCount; + for (i = NVPairDataStart; i < NVPairDataStart + NVPairDataCount; i++) { NVPairData[i].ToBytes(packet, ref length); } + NVPairDataStart += NVPairDataCount; + + packet[length++] = (byte)VisualParamCount; + for (i = VisualParamStart; i < VisualParamStart + VisualParamCount; i++) { VisualParam[i].ToBytes(packet, ref length); } + VisualParamStart += VisualParamCount; + + packet[length++] = (byte)AgentAccessCount; + for (i = AgentAccessStart; i < AgentAccessStart + AgentAccessCount; i++) { AgentAccess[i].ToBytes(packet, ref length); } + AgentAccessStart += AgentAccessCount; + + packet[length++] = (byte)AgentInfoCount; + for (i = AgentInfoStart; i < AgentInfoStart + AgentInfoCount; i++) { AgentInfo[i].ToBytes(packet, ref length); } + AgentInfoStart += AgentInfoCount; + + if (acksLength > 0) + { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + retSizes.Add(packetSize); + packets.Add(packet); + + } while ( + GroupDataStart < GroupData.Length || + AnimationDataStart < AnimationData.Length || + GranterBlockStart < GranterBlock.Length || + NVPairDataStart < NVPairData.Length || + VisualParamStart < VisualParam.Length || + AgentAccessStart < AgentAccess.Length || + AgentInfoStart < AgentInfo.Length); + + sizes = retSizes.ToArray(); + return packets.ToArray(); + } + } + + /// + public sealed class ChildAgentAlivePacket : Packet + { + public override bool UsesBufferPooling + { + get + { + return true; + } + } + + /// + public sealed class AgentDataBlock : PacketBlock + { + public ulong RegionHandle; + public uint ViewerCircuitCode; + public UUID AgentID; + public UUID SessionID; + + public override int Length + { + get + { + return 44; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(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)); + ViewerCircuitCode = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UInt64ToBytes(RegionHandle, bytes, i); i += 8; + Utils.UIntToBytes(ViewerCircuitCode, bytes, i); i += 4; + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + } + + } + + public override int Length + { + get + { + int length = 7; + length += AgentData.Length; + return length; + } + } + public AgentDataBlock AgentData; + + public ChildAgentAlivePacket() + { + HasVariableBlocks = false; + Type = PacketType.ChildAgentAlive; + Header = new Header(); + Header.Frequency = PacketFrequency.High; + Header.ID = 26; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + } + + public ChildAgentAlivePacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + } + + public ChildAgentAlivePacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 7; + length += AgentData.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + + public override byte[] ToBytes(Interfaces.IByteBufferPool pool, ref int size) + { + int length = 7; + length += AgentData.Length; + if (Header.AckList != null && Header.AckList.Length > 0) { length += Header.AckList.Length * 4 + 1; } + byte[] bytes = pool.LeaseBytes(length); + int i = 0; + Header.ToBytes(bytes, ref i); + AgentData.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + + size = length; + return bytes; + } + + public override byte[][] ToBytesMultiple(Interfaces.IByteBufferPool pool, out int[] sizes) + { + sizes = new int[1]; + return new byte[][] { this.ToBytes(pool, ref sizes[0]) }; + } + } + + /// + public sealed class ChildAgentPositionUpdatePacket : Packet + { + public override bool UsesBufferPooling + { + get + { + return true; + } + } + + /// + public sealed class AgentDataBlock : PacketBlock + { + public ulong RegionHandle; + public uint ViewerCircuitCode; + public UUID AgentID; + public UUID SessionID; + public Vector3 AgentPos; + public Vector3 AgentVel; + public Vector3 Center; + public Vector3 Size; + public Vector3 AtAxis; + public Vector3 LeftAxis; + public Vector3 UpAxis; + public bool ChangedGrid; + + public override int Length + { + get + { + return 129; + } + } + + public AgentDataBlock() { } + public AgentDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(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)); + ViewerCircuitCode = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + AgentID.FromBytes(bytes, i); i += 16; + SessionID.FromBytes(bytes, i); i += 16; + AgentPos.FromBytes(bytes, i); i += 12; + AgentVel.FromBytes(bytes, i); i += 12; + Center.FromBytes(bytes, i); i += 12; + Size.FromBytes(bytes, i); i += 12; + AtAxis.FromBytes(bytes, i); i += 12; + LeftAxis.FromBytes(bytes, i); i += 12; + UpAxis.FromBytes(bytes, i); i += 12; + ChangedGrid = (bytes[i++] != 0) ? (bool)true : (bool)false; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + Utils.UInt64ToBytes(RegionHandle, bytes, i); i += 8; + Utils.UIntToBytes(ViewerCircuitCode, bytes, i); i += 4; + AgentID.ToBytes(bytes, i); i += 16; + SessionID.ToBytes(bytes, i); i += 16; + AgentPos.ToBytes(bytes, i); i += 12; + AgentVel.ToBytes(bytes, i); i += 12; + Center.ToBytes(bytes, i); i += 12; + Size.ToBytes(bytes, i); i += 12; + AtAxis.ToBytes(bytes, i); i += 12; + LeftAxis.ToBytes(bytes, i); i += 12; + UpAxis.ToBytes(bytes, i); i += 12; + bytes[i++] = (byte)((ChangedGrid) ? 1 : 0); + } + + } + + public override int Length + { + get + { + int length = 7; + length += AgentData.Length; + return length; + } + } + public AgentDataBlock AgentData; + + public ChildAgentPositionUpdatePacket() + { + HasVariableBlocks = false; + Type = PacketType.ChildAgentPositionUpdate; + Header = new Header(); + Header.Frequency = PacketFrequency.High; + Header.ID = 27; + Header.Reliable = true; + AgentData = new AgentDataBlock(); + } + + public ChildAgentPositionUpdatePacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + AgentData.FromBytes(bytes, ref i); + } + + public ChildAgentPositionUpdatePacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + AgentData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 7; + length += AgentData.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + + public override byte[] ToBytes(Interfaces.IByteBufferPool pool, ref int size) + { + int length = 7; + length += AgentData.Length; + if (Header.AckList != null && Header.AckList.Length > 0) { length += Header.AckList.Length * 4 + 1; } + byte[] bytes = pool.LeaseBytes(length); + int i = 0; + Header.ToBytes(bytes, ref i); + AgentData.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + + size = length; + return bytes; + } + + public override byte[][] ToBytesMultiple(Interfaces.IByteBufferPool pool, out int[] sizes) + { + sizes = new int[1]; + return new byte[][] { this.ToBytes(pool, ref sizes[0]) }; + } + } + + /// + public sealed class SoundTriggerPacket : Packet + { + public override bool UsesBufferPooling + { + get + { + return true; + } + } + + /// + public sealed class SoundDataBlock : PacketBlock + { + public UUID SoundID; + public UUID OwnerID; + public UUID ObjectID; + public UUID ParentID; + public ulong Handle; + public Vector3 Position; + public float Gain; + + public override int Length + { + get + { + return 88; + } + } + + public SoundDataBlock() { } + public SoundDataBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + SoundID.FromBytes(bytes, i); i += 16; + OwnerID.FromBytes(bytes, i); i += 16; + ObjectID.FromBytes(bytes, i); i += 16; + ParentID.FromBytes(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.FromBytes(bytes, i); i += 12; + Gain = Utils.BytesToFloat(bytes, i); i += 4; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + SoundID.ToBytes(bytes, i); i += 16; + OwnerID.ToBytes(bytes, i); i += 16; + ObjectID.ToBytes(bytes, i); i += 16; + ParentID.ToBytes(bytes, i); i += 16; + Utils.UInt64ToBytes(Handle, bytes, i); i += 8; + Position.ToBytes(bytes, i); i += 12; + Utils.FloatToBytes(Gain, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 7; + length += SoundData.Length; + return length; + } + } + public SoundDataBlock SoundData; + + public SoundTriggerPacket() + { + HasVariableBlocks = false; + Type = PacketType.SoundTrigger; + Header = new Header(); + Header.Frequency = PacketFrequency.High; + Header.ID = 29; + Header.Reliable = true; + SoundData = new SoundDataBlock(); + } + + public SoundTriggerPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + SoundData.FromBytes(bytes, ref i); + } + + public SoundTriggerPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + SoundData.FromBytes(bytes, ref i); + } + + public override byte[] ToBytes() + { + int length = 7; + length += SoundData.Length; + if (Header.AckList != null && 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 != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + return new byte[][] { ToBytes() }; + } + + public override byte[] ToBytes(Interfaces.IByteBufferPool pool, ref int size) + { + int length = 7; + length += SoundData.Length; + if (Header.AckList != null && Header.AckList.Length > 0) { length += Header.AckList.Length * 4 + 1; } + byte[] bytes = pool.LeaseBytes(length); + int i = 0; + Header.ToBytes(bytes, ref i); + SoundData.ToBytes(bytes, ref i); + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + + size = length; + return bytes; + } + + public override byte[][] ToBytesMultiple(Interfaces.IByteBufferPool pool, out int[] sizes) + { + sizes = new int[1]; + return new byte[][] { this.ToBytes(pool, ref sizes[0]) }; + } + } + + /// + public sealed class ObjectAnimationPacket : Packet + { + /// + public sealed class SenderBlock : PacketBlock + { + public UUID ID; + + public override int Length + { + get + { + return 16; + } + } + + public SenderBlock() { } + public SenderBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + ID.FromBytes(bytes, i); i += 16; + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + ID.ToBytes(bytes, i); i += 16; + } + + } + + /// + public sealed class AnimationListBlock : PacketBlock + { + public UUID AnimID; + public int AnimSequenceID; + + public override int Length + { + get + { + return 20; + } + } + + public AnimationListBlock() { } + public AnimationListBlock(byte[] bytes, ref int i) + { + FromBytes(bytes, ref i); + } + + public override void FromBytes(byte[] bytes, ref int i) + { + try + { + AnimID.FromBytes(bytes, i); i += 16; + AnimSequenceID = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); + } + catch (Exception) + { + throw new MalformedDataException(); + } + } + + public override void ToBytes(byte[] bytes, ref int i) + { + AnimID.ToBytes(bytes, i); i += 16; + Utils.IntToBytes(AnimSequenceID, bytes, i); i += 4; + } + + } + + public override int Length + { + get + { + int length = 8; + length += Sender.Length; + for (int j = 0; j < AnimationList.Length; j++) + length += AnimationList[j].Length; + return length; + } + } + public SenderBlock Sender; + public AnimationListBlock[] AnimationList; + + public ObjectAnimationPacket() + { + HasVariableBlocks = true; + Type = PacketType.ObjectAnimation; + Header = new Header(); + Header.Frequency = PacketFrequency.High; + Header.ID = 30; + Header.Reliable = true; + Sender = new SenderBlock(); + AnimationList = null; + } + + public ObjectAnimationPacket(byte[] bytes, ref int i) : this() + { + int packetEnd = bytes.Length - 1; + FromBytes(bytes, ref i, ref packetEnd, null); + } + + override public void FromBytes(byte[] bytes, ref int i, ref int packetEnd, byte[] zeroBuffer) + { + Header.FromBytes(bytes, ref i, ref packetEnd); + if (Header.Zerocoded && zeroBuffer != null) + { + packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; + bytes = zeroBuffer; + } + Sender.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(AnimationList == null || AnimationList.Length != -1) { + AnimationList = new AnimationListBlock[count]; + for(int j = 0; j < count; j++) + { AnimationList[j] = new AnimationListBlock(); } + } + for (int j = 0; j < count; j++) + { AnimationList[j].FromBytes(bytes, ref i); } + } + + public ObjectAnimationPacket(Header head, byte[] bytes, ref int i): this() + { + int packetEnd = bytes.Length - 1; + FromBytes(head, bytes, ref i, ref packetEnd); + } + + override public void FromBytes(Header header, byte[] bytes, ref int i, ref int packetEnd) + { + Header = header; + Sender.FromBytes(bytes, ref i); + int count = (int)bytes[i++]; + if(AnimationList == null || AnimationList.Length != count) { + AnimationList = new AnimationListBlock[count]; + for(int j = 0; j < count; j++) + { AnimationList[j] = new AnimationListBlock(); } + } + for (int j = 0; j < count; j++) + { AnimationList[j].FromBytes(bytes, ref i); } + } + + public override byte[] ToBytes() + { + int length = 7; + length += Sender.Length; + length++; + for (int j = 0; j < AnimationList.Length; j++) { length += AnimationList[j].Length; } + if (Header.AckList != null && 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); + bytes[i++] = (byte)AnimationList.Length; + for (int j = 0; j < AnimationList.Length; j++) { AnimationList[j].ToBytes(bytes, ref i); } + if (Header.AckList != null && Header.AckList.Length > 0) { Header.AcksToBytes(bytes, ref i); } + return bytes; + } + + public override byte[][] ToBytesMultiple() + { + System.Collections.Generic.List packets = new System.Collections.Generic.List(); + int i = 0; + int fixedLength = 7; + + byte[] ackBytes = null; + int acksLength = 0; + if (Header.AckList != null && Header.AckList.Length > 0) { + Header.AppendedAcks = true; + ackBytes = new byte[Header.AckList.Length * 4 + 1]; + Header.AcksToBytes(ackBytes, ref acksLength); + } + + fixedLength += Sender.Length; + byte[] fixedBytes = new byte[fixedLength]; + Header.ToBytes(fixedBytes, ref i); + Sender.ToBytes(fixedBytes, ref i); + fixedLength += 1; + + int AnimationListStart = 0; + do + { + int variableLength = 0; + int AnimationListCount = 0; + + i = AnimationListStart; + while (fixedLength + variableLength + acksLength < Packet.MTU && i < AnimationList.Length) { + int blockLength = AnimationList[i].Length; + if (fixedLength + variableLength + blockLength + acksLength <= MTU || i == AnimationListStart) { + variableLength += blockLength; + ++AnimationListCount; + } + else { break; } + ++i; + } + + byte[] packet = new byte[fixedLength + variableLength + acksLength]; + int length = fixedBytes.Length; + Buffer.BlockCopy(fixedBytes, 0, packet, 0, length); + if (packets.Count > 0) { packet[0] = (byte)(packet[0] & ~0x10); } + + packet[length++] = (byte)AnimationListCount; + for (i = AnimationListStart; i < AnimationListStart + AnimationListCount; i++) { AnimationList[i].ToBytes(packet, ref length); } + AnimationListStart += AnimationListCount; + + if (acksLength > 0) { + Buffer.BlockCopy(ackBytes, 0, packet, length, acksLength); + acksLength = 0; + } + + packets.Add(packet); + } while ( + AnimationListStart < AnimationList.Length); + + return packets.ToArray(); + } + } + +} diff --git a/SecondBotEvents/Config/basic_config.cs b/SecondBotEvents/Config/basic_config.cs new file mode 100644 index 0000000..b262e79 --- /dev/null +++ b/SecondBotEvents/Config/basic_config.cs @@ -0,0 +1,50 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace SecondBotEvents.Config +{ + public class basic_config : config + { + public basic_config(bool fromENV, string fromFolder = "") : base(fromENV, fromFolder) { } + protected override void makeSettings() + { + filename = "basic"; + settings.Add("username"); + settings.Add("password"); + settings.Add("loginuri"); + } + + public string getUsername() + { + return readSetting("username","Firstname Lastname"); + } + + public string getPassword() + { + return readSetting("password", "passwordHere"); + } + + public string getFirstName() + { + + string[] bits = readSetting("username", "Firstname Lastname").Split(" "); + return bits[0]; + } + + public string getLastName() + { + string[] bits = readSetting("username", "Firstname Lastname").Split(" "); + if(bits.Length == 2) + { + return bits[1]; + } + return "Resident"; + } + + public string getLoginURI() + { + return readSetting("loginuri", "secondlife"); + } + } +} diff --git a/SecondBotEvents/Config/config.cs b/SecondBotEvents/Config/config.cs new file mode 100644 index 0000000..fd18b5a --- /dev/null +++ b/SecondBotEvents/Config/config.cs @@ -0,0 +1,81 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; + +namespace SecondBotEvents.Config +{ + public abstract class config + { + protected Dictionary mysettings = new Dictionary(); + protected List settings = new List(); + protected string filename = "config"; + public config(bool fromENV, string fromFolder="") + { + makeSettings(); + loadSettings(fromENV, fromFolder); + } + + protected void loadSettings(bool fromENV, string fromFolder = "") + { + if(fromENV == true) + { + loadSettingsFromEnv(); + return; + } + loadSettingsFromFile(fromFolder); + } + + protected void loadSettingsFromFile(string fromFolder) + { + SimpleIO IO = new SimpleIO(); + IO.ChangeRoot(fromFolder); + string readfile = filename + ".json"; + if (IO.Exists(readfile) == false) + { + return; + } + JToken result = JsonConvert.DeserializeObject(IO.ReadFile(readfile)); + foreach (string setting in settings) + { + string value = Environment.GetEnvironmentVariable(key); + if (SecondbotHelpers.notempty(value) == false) + { + mysettings.Add(setting, ""); + continue; + } + mysettings.Add(setting, value); + } + } + + protected void loadSettingsFromEnv() + { + foreach (string setting in settings) + { + string key = filename + "_" + setting; + string value = Environment.GetEnvironmentVariable(key); + if (SecondbotHelpers.notempty(value) == false) + { + mysettings.Add(setting, ""); + continue; + } + mysettings.Add(setting, value); + } + } + + protected virtual void makeSettings() + { + + } + + protected string readSetting(string key, string defaultValue) + { + if (mysettings.ContainsKey(key) == false) + { + return defaultValue; + } + return mysettings[key]; + } + } +} diff --git a/SecondBotEvents/Config/http_config.cs b/SecondBotEvents/Config/http_config.cs new file mode 100644 index 0000000..de6dffc --- /dev/null +++ b/SecondBotEvents/Config/http_config.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace SecondBotEvents.Config +{ + public class http_config: config + { + public http_config(bool fromENV, string fromFolder = "") : base(fromENV, fromFolder) { } + protected override void makeSettings() + { + filename = "http"; + settings.Add("enabled"); + settings.Add("port"); + } + + public int getPort() + { + bool result = int.TryParse(readSetting("port", "8080"), out int port); + if(result == false) + { + return 8080; + } + return port; + } + + public bool getEnabled() + { + bool result = bool.TryParse(readSetting("enabled", "false"), out bool enabled); + if (result == false) + { + return false; + } + return enabled; + } + } + +} \ No newline at end of file diff --git a/SecondBotEvents/EventsSecondBot.cs b/SecondBotEvents/EventsSecondBot.cs index 98439ba..6c7fe48 100644 --- a/SecondBotEvents/EventsSecondBot.cs +++ b/SecondBotEvents/EventsSecondBot.cs @@ -11,7 +11,7 @@ namespace SecondBotEvents static void Main(string[] args) { Console.WriteLine("Welcome to Secondbot [Events build] version: " + AssemblyInfo.GetGitHash()); - EventsSecondBot worker = new EventsSecondBot(); + EventsSecondBot worker = new EventsSecondBot(args); while(worker.exit() == false) { @@ -22,15 +22,56 @@ namespace SecondBotEvents internal class EventsSecondBot { - protected http HttpService = null; - public EventsSecondBot() + public http HttpService = null; + public BotClient botClient = null; + + public string getVersion() + { + return AssemblyInfo.GetGitHash(); + } + + public bool fromEnv = false; + public string fromFolder = ""; + public EventsSecondBot(string[] args) + { + if (SecondbotHelpers.notempty(Environment.GetEnvironmentVariable("basic_username")) == true) + { + fromEnv = true; + } + restartServices(); + } + public void restartServices() + { + stopServices(); + startServices(); + } + protected void startServices() { HttpService = new http(this); + HttpService.start(); + botClient = new BotClient(this); + botClient.start(); + } + protected void stopServices() + { + if (HttpService != null) + { + HttpService.stop(); + } + if(botClient != null) + { + botClient.stop(); + } + HttpService = null; + botClient = null; + } + public bool exit() { return false; } + } public static class AssemblyInfo diff --git a/SecondBotEvents/Helpers.cs b/SecondBotEvents/Helpers.cs new file mode 100644 index 0000000..047c91c --- /dev/null +++ b/SecondBotEvents/Helpers.cs @@ -0,0 +1,173 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Reflection; +using System.Security.Cryptography; +using System.Text; + +namespace SecondBotEvents +{ + public static class StringExtensions + { + public static string FirstCharToUpper(this string input) + { + switch (input) + { + case null: throw new ArgumentNullException(nameof(input)); + case "": throw new ArgumentException($"{nameof(input)} cannot be empty", nameof(input)); + default: return input.First().ToString().ToUpper() + input.Substring(1); + } + } + } + public static class SecondbotHelpers + { + // + + public static byte[] ReadResourceFileBinary(Assembly targetenv, string filename) + { + try + { + byte[] dataset; + string[] files = targetenv.GetManifestResourceNames(); + string resourceName = files.Single(str => str.EndsWith(filename)); + using (Stream stream = targetenv.GetManifestResourceStream(resourceName)) + using (BinaryReader br = new BinaryReader(stream)) + { + const int bufferSize = 4096; + using (var ms = new MemoryStream()) + { + byte[] buffer = new byte[bufferSize]; + int count; + while ((count = br.Read(buffer, 0, buffer.Length)) != 0) + ms.Write(buffer, 0, count); + dataset = ms.ToArray(); + } + } + return dataset; + } + catch (Exception e) + { + return Encoding.UTF8.GetBytes(e.Message); + } + } + public static string ReadResourceFile(Assembly targetenv,string filename) + { + try + { + string[] files = targetenv.GetManifestResourceNames(); + string resourceName = files.Single(str => str.EndsWith(filename)); + string result = ""; + using (Stream stream = targetenv.GetManifestResourceStream(resourceName)) + using (StreamReader reader = new StreamReader(stream)) + { + result = reader.ReadToEnd(); + } + return result; + } + catch (Exception e) + { + return e.Message; + } + } + public static bool inrange(float current,float min,float max) + { + if(current <= max) + { + if(current >= min) + { + return true; + } + } + return false; + } + public static bool inbox(float expected, float current, float drift) + { + return distance_check(expected, current, drift, true); + } + public static bool distance_check(float expected, float current, float drift, bool current_value) + { + if (current > (expected + drift)) + { + return false; + } + else if (current < (expected - drift)) + { + return false; + } + return current_value; + } + public static string GetSHA1(string text) + { + SHA1 hash = SHA1CryptoServiceProvider.Create(); + byte[] plainTextBytes = Encoding.UTF8.GetBytes(text); + byte[] hashBytes = hash.ComputeHash(plainTextBytes); + string localChecksum = BitConverter.ToString(hashBytes) + .Replace("-", "").ToLowerInvariant(); + return localChecksum; + } + public static string[] ParseSLurl(string url) + { + if (url != null) + { + url = url.Replace("http://maps.secondlife.com/secondlife/", ""); + url = url.Replace("%20", " "); + string[] bits = url.Split('/'); + if (bits.Length == 4) + { + return bits; + } + } + return null; + } + public static string RegionnameFromSLurl(string url) + { + string[] bits = ParseSLurl(url); + if (bits != null) + { + if (bits.Length == 4) + { + return bits[0]; + } + } + return ""; + } + public static long UnixTimeNow() + { + var timeSpan = (DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0)); + return (long)timeSpan.TotalSeconds; + } + public static bool notempty(string V) + { + if (V != null) + { + if (V.Length > 0) + { + return true; + } + } + return false; + } + + public static bool isempty(string V) + { + if (V != null) + { + if (V.Length > 0) + { + return false; + } + } + return true; + } + + public static bool notempty(string[] V) + { + if (V != null) + { + return true; + } + return false; + } + } +} diff --git a/SecondBotEvents/LogFormater.cs b/SecondBotEvents/LogFormater.cs new file mode 100644 index 0000000..b4bdbb8 --- /dev/null +++ b/SecondBotEvents/LogFormater.cs @@ -0,0 +1,117 @@ +using System; +using System.Text; + +namespace SecondBotEvents +{ + public enum ConsoleLogLogLevel + { + Status, + Info, + Crit, + Warn, + Debug, + }; + public static class LogFormater + { + public static string Warn(string message,bool send_to_console) + { + return Add(message, ConsoleLogLogLevel.Warn, send_to_console); + } + public static string Crit(string message, bool send_to_console) + { + return Add(message, ConsoleLogLogLevel.Crit, send_to_console); + } + public static string Info(string message, bool send_to_console) + { + return Add(message, ConsoleLogLogLevel.Info, send_to_console); + } + public static string Status(string message, bool send_to_console) + { + return Add(message, ConsoleLogLogLevel.Status, send_to_console); + } + public static string Debug(string message, bool send_to_console) + { + return Add(message, ConsoleLogLogLevel.Debug, send_to_console); + } + public static string Warn(string message) + { + return Warn(message, true); + } + public static string Crit(string message) + { + return Crit(message, true); + } + public static string Info(string message) + { + return Info(message, true); + } + public static string Status(string message) + { + return Status(message, true); + } + public static string Debug(string message) + { + return Debug(message, true); + } + + private static string Add(string message, ConsoleLogLogLevel Level, bool send_to_console = true) + { + var date = DateTime.Now; + StringBuilder n = new StringBuilder(); + n.Append("["); + if (date.Hour < 10) + { + n.Append("0"); + } + n.Append(date.Hour.ToString()); + n.Append(":"); + if (date.Minute < 10) + { + n.Append("0"); + } + n.Append(date.Minute.ToString()); + n.Append("] "); + switch (Level) + { +#if DEBUG + case ConsoleLogLogLevel.Debug: + { + n.Append("Debug - "); + break; + } + case ConsoleLogLogLevel.Info: + { + n.Append("Info - "); + break; + } +#endif + case ConsoleLogLogLevel.Status: + { + n.Append("Status - "); + break; + } + case ConsoleLogLogLevel.Warn: + { + n.Append("Warn - "); + break; + } + case ConsoleLogLogLevel.Crit: + { + n.Append("Crit - "); + break; + } + default: + { + n.Append("Log - "); + break; + } + } + n.Append(message); + if(send_to_console == true) + { + Console.WriteLine(n.ToString()); + } + return n.ToString(); + } + } +} diff --git a/SecondBotEvents/SecondBotEvents.csproj b/SecondBotEvents/SecondBotEvents.csproj index 08a0556..26a709c 100644 --- a/SecondBotEvents/SecondBotEvents.csproj +++ b/SecondBotEvents/SecondBotEvents.csproj @@ -6,4 +6,12 @@ SecondBotEvents.Startup + + + + + + + + diff --git a/SecondBotEvents/Services/BotClient.cs b/SecondBotEvents/Services/BotClient.cs new file mode 100644 index 0000000..3f4b49c --- /dev/null +++ b/SecondBotEvents/Services/BotClient.cs @@ -0,0 +1,58 @@ +using OpenMetaverse; +using SecondBotEvents.Config; +using System; +using System.Collections.Generic; +using System.Text; + +namespace SecondBotEvents.Services +{ + internal class BotClient: service + { + public GridClient client = null; + public basic_config basicCfg = null; + public BotClient(EventsSecondBot setMaster) : base(setMaster) + { + basicCfg = new basic_config(master.fromEnv, master.fromFolder); + } + public override void start() + { + Console.WriteLine("Client service [Starting]"); + login(); + } + public override void stop() + { + Console.WriteLine("Client service [Stopping]"); + resetClient(); + } + + public void resetClient() + { + if (client != null) + { + client.Network.Logout(); + } + client = null; + client = new GridClient(); + } + public void login() + { + if (client == null) + { + resetClient(); + } + LoginParams loginParams = new LoginParams(); + loginParams.AgreeToTos = true; + loginParams.Version = "Build: " + master.getVersion(); + loginParams.FirstName = basicCfg.getFirstName(); + loginParams.LastName = basicCfg.getLastName(); + loginParams.Password = basicCfg.getPassword(); + loginParams.Timeout = 4000; + loginParams.URI = basicCfg.getLoginURI(); + if (loginParams.URI == "secondlife") + { + loginParams.URI = Settings.AGNI_LOGIN_SERVER; + } + client.Network.Login(loginParams); + } + } +} diff --git a/SecondBotEvents/Services/HTTP/http.cs b/SecondBotEvents/Services/HTTP/http.cs deleted file mode 100644 index 95a9f83..0000000 --- a/SecondBotEvents/Services/HTTP/http.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace SecondBotEvents.Services -{ - internal class http - { - protected EventsSecondBot master; - public http(EventsSecondBot setMaster) - { - master = setMaster; - Console.WriteLine("Starting HTTP service"); - } - } -} diff --git a/SecondBotEvents/Services/HTTP/http_config.cs b/SecondBotEvents/Services/HTTP/http_config.cs deleted file mode 100644 index bbafe8b..0000000 --- a/SecondBotEvents/Services/HTTP/http_config.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace SecondBotEvents.Services.HTTP -{ - public class http_config - { - public int port = 8080; - public bool enabled = false; - } -} diff --git a/SecondBotEvents/Services/http.cs b/SecondBotEvents/Services/http.cs new file mode 100644 index 0000000..57deb04 --- /dev/null +++ b/SecondBotEvents/Services/http.cs @@ -0,0 +1,33 @@ +using SecondBotEvents.Config; +using System; +using System.Collections.Generic; +using System.Text; + +namespace SecondBotEvents.Services +{ + internal class http: service + { + http_config myConfig; + public http(EventsSecondBot setMaster) : base(setMaster) + { + myConfig = new http_config(master.fromEnv,master.fromFolder); + } + public override void start() + { + if (myConfig.getEnabled() == true) + { + Console.WriteLine("HTTP service [Enabled]"); + return; + } + Console.WriteLine("HTTP service [Disabled]"); + } + public override void stop() + { + if (myConfig.getEnabled() == false) + { + return; + } + Console.WriteLine("HTTP service [Stopping]"); + } + } +} diff --git a/SecondBotEvents/Services/service.cs b/SecondBotEvents/Services/service.cs new file mode 100644 index 0000000..1a9db01 --- /dev/null +++ b/SecondBotEvents/Services/service.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace SecondBotEvents.Services +{ + internal abstract class service + { + protected EventsSecondBot master; + public service(EventsSecondBot setMaster) + { + master = setMaster; + } + + public virtual void start() + { + + } + public virtual void stop() + { + + } + public void restart() + { + stop(); + start(); + } + } +} diff --git a/SecondBotEvents/SimpleIO.cs b/SecondBotEvents/SimpleIO.cs new file mode 100644 index 0000000..ad4f774 --- /dev/null +++ b/SecondBotEvents/SimpleIO.cs @@ -0,0 +1,69 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.IO; + +namespace SecondBotEvents +{ + public class SimpleIO + { + protected string root_folder = ""; + public void ChangeRoot(string A) + { + + root_folder = A; + if (DirExists(root_folder) == false) + { + System.IO.Directory.CreateDirectory(root_folder); + } + } + public static bool DirExists(string target_folder) + { + return System.IO.Directory.Exists(target_folder); + } + public void Delete(string filename) + { + System.IO.File.Delete(root_folder+"/"+filename); + } + public void WriteFile(string filename,string content) + { + if(Exists(filename) == true) + { + Delete(filename); + } + System.IO.File.WriteAllText(@""+root_folder + "/" + filename, content); + } + + public void MarkOld(string targetfile) + { + System.IO.File.Move(@""+root_folder + "/" + targetfile, @"" + root_folder + "/" + targetfile+".old"); + } + public bool Exists(string targetfile) + { + return File.Exists(@""+root_folder+"/" + targetfile); + } + public static bool FileType(string targetfile, string matchtype) + { + string[] bits = targetfile.Split('.'); + if (bits[^1] == matchtype) + { + return true; + } + return false; + } + public string ReadFile(string targetfile) + { + if (Exists(targetfile) == true) + { + string return_text = ""; + using (var Stream = new FileStream(@"" + root_folder + "/" + targetfile, FileMode.Open, FileAccess.Read)) + using (var StreamReader = new StreamReader(Stream)) + { + return_text = StreamReader.ReadToEnd(); + } + return return_text; + } + return ""; + } + } +} diff --git a/Shared/Shared.csproj b/Shared/Shared.csproj index 1d781f4..4842fdd 100644 --- a/Shared/Shared.csproj +++ b/Shared/Shared.csproj @@ -9,10 +9,4 @@ - - - - - -