private void EventManager_OnAvatarLeavingRegion(ScenePresence presence, SimpleRegionInfo newRegion)
        {
            //Add them to the cache
            LeavingRegionInfo info = new LeavingRegionInfo()
            {
                RegionServerURI = newRegion.InsecurePublicHTTPServerURI, SessionID = presence.ControllingClient.SessionId
            };

            _avatarRegionCache.AddOrUpdate(presence.UUID, info, CACHE_EXPIRATION_TIME);
        }
        private string IncomingCommand(byte[] data, string path, string param)
        {
            using (MemoryStream str = new MemoryStream(data))
            {
                OSDMap map = (OSDMap)OSDParser.DeserializeJson(str);

                UUID sessionID = map["sessionId"].AsUUID();
                UUID userID    = map["userId"].AsUUID();
                UUID regionID  = map["regionId"].AsUUID();

                Scene scene = _scenes.FirstOrDefault((s) => s.RegionInfo.RegionID == regionID);
                if (scene == null)//No scene found...
                {
                    return(BuildCommandResponse(RemoteCommandResponse.NOTFOUND, null));
                }

                if (!scene.ConnectionManager.IsAuthorized(userID, sessionID))
                {
                    //They might not be in the scene, check if they have left recently
                    LeavingRegionInfo info = null;
                    if (!_avatarRegionCache.TryGetValue(userID, out info) || info.SessionID != sessionID)
                    {
                        return(BuildCommandResponse(RemoteCommandResponse.UNAUTHORIZED, null));//Wrong sessionID or was never here
                    }
                    //They moved out of this region
                    return(BuildMovedCommandResponse(userID));
                }

                ScenePresence presence = scene.GetScenePresence(userID);
                if (presence == null || presence.IsChildAgent)//Make sure that they are actually in the region
                {
                    return(BuildMovedCommandResponse(userID));
                }

                //Process the command
                RemoteCommandType commandID = (RemoteCommandType)map["id"].AsInteger();
                switch (commandID)
                {
                case RemoteCommandType.AvatarChatCommand:
                    return(ProcessAvatarChatCommand(presence, map));

                case RemoteCommandType.AvatarTeleportCommand:
                    return(ProcessAvatarTeleportCommand(presence, map));
                }
            }
            return(BuildCommandResponse(RemoteCommandResponse.INVALID, null));
        }
 private void EventManager_OnAvatarLeavingRegion(ScenePresence presence, SimpleRegionInfo newRegion)
 {
     //Add them to the cache
     LeavingRegionInfo info = new LeavingRegionInfo() { RegionServerURI = newRegion.InsecurePublicHTTPServerURI, SessionID = presence.ControllingClient.SessionId };
     _avatarRegionCache.AddOrUpdate(presence.UUID, info, CACHE_EXPIRATION_TIME);
 }