예제 #1
0
        public UDPCircuitsManager(IPAddress bindAddress, int port, IMServiceInterface imService, ChatServiceInterface chatService, SceneInterface scene,
                                  List <IPortControlServiceInterface> portControlServices)
        {
            m_PortControlServices = portControlServices;
            Scene         = scene;
            m_IMService   = imService;
            m_ChatService = chatService;
            m_BindAddress = bindAddress;
            LocalPort     = port;
            var ep = new IPEndPoint(m_BindAddress, LocalPort);

            /* trigger early init of UDPPacketDecoder. We do not want this to happen on first teleport */
            AgentCircuit.m_PacketDecoder.CheckInit();
            m_UdpSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);

            try
            {
                if (m_UdpSocket.Ttl < 128)
                {
                    m_UdpSocket.Ttl = 128;
                }
            }
            catch (SocketException)
            {
                m_Log.Debug("Failed to increase default TTL");
            }

            /* since Win 2000, there is a WSAECONNRESET, we do not want that in our code */
            try
            {
                const int SIO_UDP_CONNRESET = -1744830452;

                m_UdpSocket.IOControl(SIO_UDP_CONNRESET, new byte[] { 0, 0, 0, 0 }, null);
            }
            catch (SocketException)
            {
                /* however, mono does not have an idea about what this is all about, so we catch that here */
            }

            /* handle Bind before starting anything else */
            m_UdpSocket.Bind(ep);

            LocalPort = ((IPEndPoint)m_UdpSocket.LocalEndPoint).Port;

            foreach (IPortControlServiceInterface portControl in m_PortControlServices)
            {
                portControl.EnablePort(new AddressFamily[] { AddressFamily.InterNetwork }, ProtocolType.Udp, LocalPort);
            }

            if (m_ChatService != null)
            {
                m_ChatThread = ThreadManager.CreateThread(ChatSendHandler);
                m_ChatThread.Start();
            }
            m_Log.InfoFormat("Initialized UDP Circuits Manager at {0}:{1}", bindAddress.ToString(), LocalPort);
        }
예제 #2
0
 internal void EnableListen()
 {
     if (m_ChatListener == null)
     {
         try
         {
             m_ChatService  = CurrentScene.GetService <ChatServiceInterface>();
             m_ChatListener = m_ChatService.AddAgentListen(0, string.Empty, UUID.Zero, string.Empty, GetMyUUID, GetMyPosition, OnChatReceive);
         }
         catch
         {
             /* intentionally ignored */
         }
     }
 }
        public void DoSayTo(UUID target, int channel, string text)
        {
            ChatServiceInterface chatService = CurrentScene.GetService <ChatServiceInterface>();

            chatService.Send(new ListenEvent
            {
                ID             = ID,
                Type           = ListenEvent.ChatType.Say,
                Channel        = channel,
                GlobalPosition = GlobalPosition,
                Name           = Name,
                Message        = text,
                TargetID       = target,
                SourceType     = ListenEvent.ChatSourceType.Agent,
                OwnerID        = ID
            });
        }
예제 #4
0
        protected override void SendChatPass(ListenEvent le)
        {
            ChatServiceInterface chatService = m_ChatService;

            chatService?.Send(le);
        }
예제 #5
0
        protected SceneImplementation(
            SceneImplementationFactory sceneParams,
            RegionInfo ri)
            : base(ri.Size.X, ri.Size.Y)
        {
            SceneCapabilities.Add("ProductInfoRequest", new ProductInfoRequestCapability(this));
            m_Scenes     = sceneParams.Scenes;
            m_HttpServer = sceneParams.HttpServer;
            if (sceneParams.AssetService == null)
            {
                throw new ArgumentNullException("persistentAssetService");
            }
            if (sceneParams.GridService == null)
            {
                throw new ArgumentNullException("gridService");
            }
            if (ri == null)
            {
                throw new ArgumentNullException(nameof(ri));
            }
            if (sceneParams.AvatarNameServices == null)
            {
                throw new ArgumentNullException("avatarNameServices");
            }
            if (sceneParams.SimulationDataStorage == null)
            {
                throw new ArgumentNullException("simulationDataStorage");
            }
            if (sceneParams.EstateService == null)
            {
                throw new ArgumentNullException("estateService");
            }
            if (sceneParams.m_CapabilitiesConfig == null)
            {
                throw new ArgumentNullException("capabilitiesConfig");
            }
            if (sceneParams.RegionStorage == null)
            {
                throw new ArgumentNullException("regionStorage");
            }

            #region Setup services
            m_ChatService           = sceneParams.ChatFactory.Instantiate(ri.ID);
            RegionStorage           = sceneParams.RegionStorage;
            GroupsNameService       = sceneParams.GroupsNameService;
            GroupsService           = sceneParams.GroupsService;
            m_NeighborService       = sceneParams.NeighborService;
            m_SimulationDataStorage = sceneParams.SimulationDataStorage;
            PersistentAssetService  = sceneParams.AssetService;
            TemporaryAssetService   = sceneParams.AssetCacheService;
            GridService             = sceneParams.GridService;
            ExperienceService       = sceneParams.ExperienceService;
            ExperienceNameService   = sceneParams.ExperienceNameService;
            EstateService           = sceneParams.EstateService;
            /* next line is there to break the circular dependencies */
            TryGetScene = m_Scenes.TryGetValue;

            UserAgentServicePlugins.AddRange(sceneParams.UserAgentServicePlugins);
            AssetServicePlugins.AddRange(sceneParams.AssetServicePlugins);
            InventoryServicePlugins.AddRange(sceneParams.InventoryServicePlugins);

            #endregion

            #region Setup Region Data
            ID                        = ri.ID;
            GatekeeperURI             = ri.GridURI;
            Access                    = ri.Access;
            ID                        = ri.ID;
            Name                      = ri.Name;
            Owner                     = ri.Owner;
            GridPosition              = ri.Location;
            ProductName               = ri.ProductName;
            RegionPort                = ri.ServerPort;
            m_ExternalHostNameService = sceneParams.ExternalHostNameService;
            #endregion

            /* load estate flags cache */
            uint       estateID;
            EstateInfo estate;
            if (EstateService.RegionMap.TryGetValue(ID, out estateID) &&
                EstateService.TryGetValue(estateID, out estate))
            {
                m_EstateData = estate;
            }
            else
            {
                throw new ArgumentException("Could not load estate data");
            }

            m_RestartObject    = new RestartObject(m_Scenes, this, sceneParams, sceneParams.RegionStorage);
            m_IMService        = sceneParams.IMService;
            m_UDPServer        = new UDPCircuitsManager(new IPAddress(0), (int)ri.ServerPort, sceneParams.IMService, m_ChatService, this, sceneParams.PortControlServices);
            CapabilitiesConfig = sceneParams.m_CapabilitiesConfig;
            foreach (AvatarNameServiceInterface avNameService in sceneParams.AvatarNameServices)
            {
                AvatarNameServices.Add(avNameService);
            }

            Terrain     = new TerrainController(this);
            Environment = new EnvironmentController(this, sceneParams.WindModelFactory);

            if (sceneParams.PathfindingServiceFactory != null)
            {
                PathfindingService = sceneParams.PathfindingServiceFactory.Instantiate(this);
            }

            m_IMRouter = sceneParams.IMRouter;
            m_IMRouter.SceneIM.Add(IMSend);
            OnRemove += RemoveScene;
            m_UDPServer.Start();

            ScriptThreadPool = sceneParams.ScriptWorkerThreadPoolFactory.InstantiateThreadPool(ID);
        }
예제 #6
0
        public bool Run()
        {
            m_Log.InfoFormat("Testing Execution of {1} ({0})", m_AssetID, m_ScriptFile);
            IScriptAssembly scriptAssembly = null;

            try
            {
                using (var reader = new StreamReader(m_ScriptFile, new UTF8Encoding(false)))
                {
                    scriptAssembly = CompilerRegistry.ScriptCompilers.Compile(AppDomain.CurrentDomain, UGUI.Unknown, m_AssetID, reader, includeOpen: OpenFile);
                }
                m_Log.InfoFormat("Compilation of {1} ({0}) successful", m_AssetID, m_ScriptFile);
            }
            catch (CompilerException e)
            {
                m_Log.ErrorFormat("Compilation of {1} ({0}) failed: {2}", m_AssetID, m_ScriptFile, e.Message);
                m_Log.WarnFormat("Stack Trace:\n{0}", e.StackTrace);
                return(false);
            }
            catch (Exception e)
            {
                m_Log.ErrorFormat("Compilation of {1} ({0}) failed: {2}", m_AssetID, m_ScriptFile, e.Message);
                m_Log.WarnFormat("Stack Trace:\n{0}", e.StackTrace);
                return(false);
            }

            RegionInfo rInfo;

            try
            {
                var estate = new EstateInfo
                {
                    ParentEstateID = 1,
                    ID             = m_EstateID,
                    Owner          = m_EstateOwner,
                    Name           = m_EstateName
                };
                m_EstateService.Add(estate);
                m_EstateService.RegionMap[m_RegionID] = m_EstateID;

                rInfo = new RegionInfo
                {
                    Name        = m_RegionName,
                    ID          = m_RegionID,
                    Location    = m_RegionLocation,
                    Size        = m_RegionSize,
                    ProductName = m_ProductName,
                    ServerPort  = (uint)m_RegionPort,
                    Owner       = m_RegionOwner,
                    Flags       = RegionFlags.RegionOnline,
                    Access      = m_RegionAccess,
                    GridURI     = m_GatekeeperURI
                };
                m_RegionStorage.RegisterRegion(rInfo);
            }
            catch (Exception e)
            {
                m_Log.Error("Registration of region failed", e);
                return(false);
            }

            SceneInterface scene;

            try
            {
                scene = m_SceneFactory.Instantiate(rInfo);
            }
            catch (Exception e)
            {
                m_Log.ErrorFormat("Running of {1} ({0}) failed: Failed to start region ID {2}: {3}: {4}\n{5}", m_AssetID, m_ScriptFile, m_RegionID, e.GetType().FullName, e.Message, e.StackTrace);
                return(false);
            }

            try
            {
                m_Scenes.Add(scene);
                scene.LoadSceneSync();
            }
            catch (Exception e)
            {
                m_Log.Error("Starting region failed", e);
                return(false);
            }

            try
            {
                ExperienceServiceInterface experienceService = scene.ExperienceService;
                if (experienceService != null)
                {
                    experienceService.Add(new ExperienceInfo
                    {
                        ID         = m_ExperienceID,
                        Creator    = m_ScriptOwner,
                        Owner      = m_ScriptOwner,
                        Properties = ExperiencePropertyFlags.Grid /* make this grid-wide since otherwise we have to configure a lot more */
                    });
                }
                else
                {
                    m_ExperienceID = UEI.Unknown;
                }
            }
            catch (Exception e)
            {
                m_Log.Error("Creating experience failed", e);
                return(false);
            }

            if (!string.IsNullOrEmpty(m_AssetSourcesConfig))
            {
                AddAssets(scene.AssetService);
            }

            if (!string.IsNullOrEmpty(m_ScriptStatesConfig))
            {
                AddScriptStates();
            }

            if (!string.IsNullOrEmpty(m_LoadOarFileName))
            {
                try
                {
                    using (var s = new FileStream(m_LoadOarFileName, FileMode.Open))
                    {
                        OAR.Load(m_Scenes, scene, OAR.LoadOptions.PersistUuids, s);
                    }
                }
                catch (Exception e)
                {
                    m_Log.Error("Loading oar failed", e);
                    return(false);
                }
            }

            m_Runner.OtherThreadResult = false;

            foreach (string additionalObject in m_AdditionalObjectConfigs)
            {
                m_Log.InfoFormat("Adding object from section {0}", additionalObject);
                if (!TryAddAdditionalObject(scene, additionalObject))
                {
                    m_Log.Info("Failed to add object");
                    return(false);
                }
            }

            try
            {
                var grp = new ObjectGroup
                {
                    RezzingObjectID = m_RezzingObjID
                };
                var part = new ObjectPart(m_ObjectID);
                grp.Add(1, part.ID, part);
                part.ObjectGroup    = grp;
                grp.Owner           = m_ObjectOwner;
                grp.LastOwner       = m_ObjectLastOwner;
                part.Creator        = m_ObjectCreator;
                part.Name           = m_ObjectName;
                part.Description    = m_ObjectDescription;
                part.GlobalPosition = m_Position;
                part.GlobalRotation = m_Rotation;
                part.BaseMask       = m_ObjectPermissionsBase;
                part.OwnerMask      = m_ObjectPermissionsOwner;
                part.NextOwnerMask  = m_ObjectPermissionsNext;
                part.EveryoneMask   = m_ObjectPermissionsEveryone;
                part.GroupMask      = m_ObjectPermissionsGroup;

                var item = new ObjectPartInventoryItem(m_ItemID)
                {
                    AssetType     = AssetType.LSLText,
                    AssetID       = m_AssetID,
                    InventoryType = InventoryType.LSL,
                    LastOwner     = m_ScriptLastOwner,
                    Creator       = m_ScriptCreator,
                    Owner         = m_ScriptOwner,
                    Name          = m_ScriptName,
                    Description   = m_ScriptDescription
                };
                item.Permissions.Base      = m_ScriptPermissionsBase;
                item.Permissions.Current   = m_ScriptPermissionsOwner;
                item.Permissions.EveryOne  = m_ScriptPermissionsEveryone;
                item.Permissions.Group     = m_ScriptPermissionsGroup;
                item.Permissions.NextOwner = m_ScriptPermissionsNext;
                item.ExperienceID          = m_ExperienceID;

                scene.Add(grp);

                foreach (string invconfig in m_AdditionalInventoryConfigs)
                {
                    AddAdditionalInventory(part, invconfig);
                }
                ChatServiceInterface chatService = scene.GetService <ChatServiceInterface>();
                if (chatService != null)
                {
                    chatService.AddRegionListener(PUBLIC_CHANNEL, string.Empty, UUID.Zero, "", GetUUID, null, PublicChannelLog);
                    chatService.AddRegionListener(DEBUG_CHANNEL, string.Empty, UUID.Zero, "", GetUUID, null, DebugChannelLog);
                }
                byte[] serializedState;
                m_ScriptStates.TryGetValue(item.ID, out serializedState);
                ScriptInstance scriptInstance = scriptAssembly.Instantiate(part, item, serializedState);
                part.Inventory.Add(item);
                item.ScriptInstance = scriptInstance;
                item.ScriptInstance.Start(m_StartParameter);
                m_Log.Info("Script started");

                if (Debugger.IsAttached)
                {
                    m_RunTimeoutEvent.WaitOne();
                }
                else
                {
                    m_KillTimer = new Timer(KillTimerCbk, null, m_TimeoutMs + 5000, Timeout.Infinite);
                    m_RunTimeoutEvent.WaitOne(m_TimeoutMs);
                }
                return(m_Runner.OtherThreadResult);
            }
            catch (Exception e)
            {
                m_Log.Error("Starting script failed", e);
                return(false);
            }
        }