示例#1
0
        /// <summary>
        /// Set up all listeners for all default ports
        /// <seealso cref="Listener(int)"/>
        /// <seealso cref="Link(int, ClientInitialization)"/>
        /// </summary>
        public static void Setup()
        {
            if (__ALREADY_SETUP)
            {
                ServerMain.logging.Alert("static Listener.Setup : Already setup!");
                return;
            }

            ServerMain.logging.Info("Setting up default listeners...");
            lock (_clientSyncInit_lock)
            {
                foreach (var port in clientSyncInit.Keys)
                {
                    Instantiate(port);
                    ServerMain.logging.Log("Default listener set up on port " + port.Port);
                }
            }

            ServerMain.logging.Info("Setting up extension listeners...");
            foreach (var folder in EXTENSIONS_FOLDERS)
            {
                ServerExtensionInitializer.FolderSetup_listeners(folder, clientSyncInit, ServerMain.logging);
            }

            ServerMain.logging.Eyecatch("   DONE...");
            __ALREADY_SETUP = true;
        }
示例#2
0
 /// <summary>
 /// Dynamically link a port and an extension on the go
 /// </summary>
 /// <param name="port">Port to set up a listener on</param>
 /// <param name="extension">Extension to link</param>
 public static void Link(PEndPoint port, ServerExtensionInitializer extension)
 {
     if (clientSyncInit.ContainsKey(port))
     {
         ServerMain.logging.Alert("static Listener.Link : port " + port + " is already bounded!");
         return;
     }
     clientSyncInit.Add(port, extension);
     Instantiate(port);
 }
示例#3
0
        /// <summary>
        /// Unloads the listeners of an extension
        /// </summary>
        /// <param name="extName">Extension name</param>
        /// <param name="removeAsm">Whether to unload the assembly as well. Default : true</param>
        /// <param name="keepPath">Cf ServerExtensionInitializer. Whether to keep the path when unloading the assembly as well</param>
        public static void Unload(string extName, bool removeAsm = true, bool keepPath = false)
        {
            ServerMain.logging.Info("Unloading extension " + extName);
            List <PEndPoint> endPoints = new List <PEndPoint>();

            lock (Client._CLIENTS_LOCK)
            {
                foreach (var client in Client.Clients_collection)
                {
                    if (clientSyncInit[client.LocalEndPoint].ToString().Equals(extName))
                    {
                        if (!endPoints.Contains(client.LocalEndPoint))
                        {
                            endPoints.Add(client.LocalEndPoint);
                        }
                        client.Disconnect();
                    }
                }
            }
            foreach (var endPoint in endPoints)
            {
                clientSyncInit.Remove(endPoint);
            }

            foreach (var endPoint in endPoints)
            {
                LISTENERS[endPoint].Terminate();
            }

            ServerMain.logging.Log("All listeners of " + extName + " terminated");

            if (removeAsm)
            {
                ServerExtensionInitializer.RemoveAssembly(extName, keepPath);
            }
        }