FromOSD() public method

Deserialize the module from OSD
public FromOSD ( OSDMap map ) : void
map OSDMap
return void
        protected virtual OSDMap OnMessageReceived(OSDMap message)
        {
            if (!message.ContainsKey("Method"))
                return null;

            if (m_capsService == null)
                return null;

            string method = message["Method"].AsString();
            if (method != "RegionIsOnline" &&
                method != "LogoutRegionAgents" &&
                method != "ArrivedAtDestination" &&
                method != "CancelTeleport" &&
                method != "AgentLoggedOut" &&
                method != "SendChildAgentUpdate" &&
                method != "TeleportAgent" &&
                method != "CrossAgent")
                return null;

            UUID AgentID = message["AgentID"].AsUUID();
            UUID requestingRegion = message["RequestingRegion"].AsUUID();

            IClientCapsService clientCaps = m_capsService.GetClientCapsService(AgentID);

            IRegionClientCapsService regionCaps = null;
            if (clientCaps != null)
                regionCaps = clientCaps.GetCapsService(requestingRegion);

            if (method == "LogoutRegionAgents")
            {
                LogOutAllAgentsForRegion(requestingRegion);
            }
            else if (method == "RegionIsOnline")
            //This gets fired when the scene is fully finished starting up
            {
                //Log out all the agents first, then add any child agents that should be in this region
                //Don't do this, we don't need to kill all the clients right now
                IGridService GridService = m_registry.RequestModuleInterface<IGridService>();

                if (GridService != null)
                {
                    GridRegion requestingGridRegion = GridService.GetRegionByUUID(null, requestingRegion);
                    if (requestingGridRegion != null)
                        Util.FireAndForget(o => EnableChildAgentsForRegion(requestingGridRegion));
                }
            }
            else if (method == "ArrivedAtDestination")
            {
                if (regionCaps == null || clientCaps == null)
                    return null;
                //Received a callback
                if (clientCaps.InTeleport) //Only set this if we are in a teleport,
                    //  otherwise (such as on login), this won't check after the first tp!
                    clientCaps.CallbackHasCome = true;

                regionCaps.Disabled = false;

                //The agent is getting here for the first time (eg. login)
                OSDMap body = ((OSDMap)message["Message"]);

                //Parse the OSDMap
                int DrawDistance = body["DrawDistance"].AsInteger();

                AgentCircuitData circuitData = new AgentCircuitData();
                circuitData.FromOSD((OSDMap)body["Circuit"]);

                //Now do the creation
                EnableChildAgents(AgentID, requestingRegion, DrawDistance, circuitData);
            }
            else if (method == "CancelTeleport")
            {
                if (regionCaps == null || clientCaps == null)
                    return null;
                //Only the region the client is root in can do this
                IRegionClientCapsService rootCaps = clientCaps.GetRootCapsService();
                if (rootCaps != null && rootCaps.RegionHandle == regionCaps.RegionHandle)
                {
                    //The user has requested to cancel the teleport, stop them.
                    clientCaps.RequestToCancelTeleport = true;
                    regionCaps.Disabled = false;
                }
            }
            else if (method == "AgentLoggedOut")
            {
                //ONLY if the agent is root do we even consider it
                if (regionCaps != null && regionCaps.RootAgent)
                {
                    OSDMap body = ((OSDMap)message["Message"]);

                    AgentPosition pos = new AgentPosition();
                    pos.FromOSD((OSDMap)body["AgentPos"]);

                    regionCaps.Disabled = true;

                    Util.FireAndForget(o =>
                    {
                        LogoutAgent(regionCaps, false); //The root is killing itself
                        SendChildAgentUpdate(pos, regionCaps);
                    });
                }
            }
            else if (method == "SendChildAgentUpdate")
            {
                if (regionCaps == null || clientCaps == null)
                    return null;
                IRegionClientCapsService rootCaps = clientCaps.GetRootCapsService();

                if (rootCaps != null && rootCaps.RegionHandle == regionCaps.RegionHandle) //Has to be root
                {
                    OSDMap body = ((OSDMap)message["Message"]);

                    AgentPosition pos = new AgentPosition();
                    pos.FromOSD((OSDMap)body["AgentPos"]);

                    SendChildAgentUpdate(pos, regionCaps);
                    regionCaps.Disabled = false;
                }
            }
            else if (method == "TeleportAgent")
            {
                if (regionCaps == null || clientCaps == null)
                    return null;
                IRegionClientCapsService rootCaps = clientCaps.GetRootCapsService();
                if (rootCaps != null && rootCaps.RegionHandle == regionCaps.RegionHandle)
                {
                    OSDMap body = ((OSDMap)message["Message"]);

                    GridRegion destination = new GridRegion();
                    destination.FromOSD((OSDMap)body["Region"]);

                    uint TeleportFlags = body["TeleportFlags"].AsUInteger();

                    AgentCircuitData Circuit = new AgentCircuitData();
                    Circuit.FromOSD((OSDMap)body["Circuit"]);

                    AgentData AgentData = new AgentData();
                    AgentData.FromOSD((OSDMap)body["AgentData"]);
                    regionCaps.Disabled = false;

                    //Don't need to wait for this to finish on the main http thread
                    Util.FireAndForget(o =>
                    {
                        string reason;
                        TeleportAgent(ref destination, TeleportFlags,
                            Circuit, AgentData, AgentID, requestingRegion, out reason);
                    });
                    return null;
                }
            }
            else if (method == "CrossAgent")
            {
                if (regionCaps == null || clientCaps == null)
                    return null;
                IRegionClientCapsService rootCaps = clientCaps.GetRootCapsService();
                if (rootCaps == null || rootCaps.RegionHandle == regionCaps.RegionHandle)
                {
                    //This is a simulator message that tells us to cross the agent
                    OSDMap body = ((OSDMap)message["Message"]);

                    Vector3 pos = body["Pos"].AsVector3();
                    Vector3 Vel = body["Vel"].AsVector3();
                    GridRegion Region = new GridRegion();
                    Region.FromOSD((OSDMap)body["Region"]);
                    AgentCircuitData Circuit = new AgentCircuitData();
                    Circuit.FromOSD((OSDMap)body["Circuit"]);
                    AgentData AgentData = new AgentData();
                    AgentData.FromOSD((OSDMap)body["AgentData"]);
                    regionCaps.Disabled = false;

                    Util.FireAndForget(o =>
                    {
                        string reason;
                        CrossAgent(Region, pos, Vel, Circuit, AgentData,
                            AgentID, requestingRegion, out reason);
                    });

                    return null;
                }

                OSDMap result = new OSDMap();
                result["success"] = false;
                result["Note"] = false;
                return result;
            }

            return null;
        }
 public override void FromOSD(OSDMap map)
 {
     Success = map["Success"];
     CircuitData = new AgentCircuitData();
     CircuitData.FromOSD((OSDMap) map["CircuitData"]);
     SeedCap = map["SeedCap"];
     Reason = map["Reason"];
 }
 public override void FromOSD(OSDMap map)
 {
     Success = map["Success"];
     if (map.ContainsKey("AgentData"))
     {
         AgentData = new AgentData();
         AgentData.FromOSD((OSDMap)map["AgentData"]);
     }
     if (map.ContainsKey("CircuitData"))
     {
         CircuitData = new AgentCircuitData();
         CircuitData.FromOSD((OSDMap)map["CircuitData"]);
     }
 }
 public override void FromOSD(OSDMap map)
 {
     Destination = new GridRegion();
     Destination.FromOSD((OSDMap)map["Destination"]);
     TeleportFlags = map["TeleportFlags"];
     CircuitData = new AgentCircuitData();
     CircuitData.FromOSD((OSDMap)map["CircuitData"]);
 }
        void DeserializeUsers (IScene scene)
        {
            var regionName = scene.RegionInfo.RegionName;
            var readFile = BuildSaveFileName (regionName);
            if (!File.Exists (readFile))
                return;

            var regionUsers = 0;
            OSDMap sceneAgents = (OSDMap)OSDParser.DeserializeJson (File.ReadAllText (readFile));
            foreach (OSD o in sceneAgents.Values) {
                AgentCircuitData data = new AgentCircuitData ();
                OSDMap user = (OSDMap)o;

                data.FromOSD ((OSDMap)user ["ClientInfo"]);
                m_scene.AuthenticateHandler.AddNewCircuit (data.CircuitCode, data);
                OSDMap remoteIP = (OSDMap)user ["RemoteEndPoint"];
                IPEndPoint ep = new IPEndPoint (IPAddress.Parse (remoteIP ["Address"].AsString ()), remoteIP ["Port"].AsInteger ());

                m_scene.ClientServers [0].AddClient (data.CircuitCode, data.AgentID, data.SessionID, ep, data);
                IScenePresence sp = m_scene.GetScenePresence (data.AgentID);
                sp.MakeRootAgent (user ["Position"].AsVector3 (), user ["IsFlying"].AsBoolean (), true);
                sp.SceneViewer.SendPresenceFullUpdate (sp);

                regionUsers += 1;
            }

            File.Delete (readFile);
            MainConsole.Instance.InfoFormat ("[Restart]: {0} users loaded into {1}", regionUsers, regionName);
        }
        private void DeserializeUsers()
        {
            if (!File.Exists(BuildSaveFileName()))
                return;
            foreach (OSD o in ((OSDMap)OSDParser.DeserializeJson(File.ReadAllText(BuildSaveFileName()))).Values)
            {
                AgentCircuitData data = new AgentCircuitData();
                OSDMap user = (OSDMap)o;
                data.FromOSD((OSDMap)user["ClientInfo"]);
                m_scene.AuthenticateHandler.AddNewCircuit(data.CircuitCode, data);
                OSDMap remoteIP = (OSDMap)user["RemoteEndPoint"];
                IPEndPoint ep = new IPEndPoint(IPAddress.Parse(remoteIP["Address"].AsString()), remoteIP["Port"].AsInteger());
                m_scene.ClientServers[0].AddClient(data.CircuitCode, data.AgentID, data.SessionID, ep, data);
                IScenePresence sp = m_scene.GetScenePresence(data.AgentID);
                sp.MakeRootAgent(user["Position"].AsVector3(), user["IsFlying"].AsBoolean(), true);
                sp.SceneViewer.SendPresenceFullUpdate(sp);
            }

            File.Delete(BuildSaveFileName());
        }