コード例 #1
0
ファイル: Server.cs プロジェクト: aarondl/Project-2Q
        /// <summary>
        /// Creates a server from a ServerConfig with a parameter
        /// to provide an interface for logging.
        /// </summary>
        /// <param name="config">The configuration to build the Server from.</param>
        /// <param name="logFunction">The function to call to log text for the application.</param>
        public Server(Configuration.ServerConfig config, Project2QService.WriteLogFunction logFunction)
        {
            //Instantiate and load databases
            uc = new UserCollection();
            cc = new ChannelCollection();
            uc.LoadRegisteredUsers( "userdb\\" + config.Name + ".udb" );

            //Rip up this little guy to help us out :D
            currentHost = new IRCHost();
            currentIP = null;

            this.authmode = !File.Exists( "userdb\\" + config.Name + ".udb" );

            this.writeLogFunction = logFunction;

            //Assign a Server ID
            this.serverId = Server.NextServerId;
            if ( this.serverId == -1 ) throw new OverflowException( "Too many servers created." );
            servers[serverId] = this;

            //Save the configuration.
            this.config = config;

            //Tie default static handlers together for this instance of IRCEvents.
            irce = new IRCEvents();

            //Initialize the socket pipe before the modules. Modules are scary.
            state = State.Disconnected;

            socketPipe = new SocketPipe(
                this.serverId, config.RetryTimeout, config.OperationTimeout, config.SendInhibit, config.SocketBufferSize ); //Default values for now, get them from config later plz.
            socketPipe.OnDisconnect += new SocketPipe.NoParams( this.OnDisconnect );
            socketPipe.OnReceive += new SocketPipe.ReceiveData( this.OnReceive );
        }
コード例 #2
0
ファイル: 2QService.cs プロジェクト: aarondl/Project-2Q
        /// <summary>
        /// Constructs a 2Q.
        /// </summary>
        /// <param name="configFile">The configuration file.</param>
        /// <param name="consoleRead">Redirection of stdin.</param>
        /// <param name="consoleWrite">Redirection of stdout.</param>
        public Project2QService(string configFile, TextReader consoleRead, TextWriter consoleWrite)
        {
            config = new Configuration( configFile );

            logFile = new FileStream( Environment.CurrentDirectory + "\\2Q.log", FileMode.Append,
                FileAccess.Write, FileShare.None );

            Console.SetIn( consoleRead );
            Console.SetOut( consoleWrite );

            modules = new IModule[MaxModules];
            servers = new ServerThread[MaxServers];
        }
コード例 #3
0
ファイル: Rcon.cs プロジェクト: aarondl/Project-2Q
        /// <summary>
        /// Creates an Rcon Server
        /// </summary>
        /// <param name="rconfig">RConsole Configuration to build off.</param>
        public Rcon(Configuration.RconConfig rconfig)
        {
            rconConnections = new SocketPipe[Rcon.MaxRconConnections];
            for ( int i = 0; i < Rcon.MaxRconConnections; i++ )
                rconConnections[i] = null;

            this.rconfig = rconfig;
            if ( File.Exists( rconfig.UserFile ) )
                rconUsers = new RconUserFile( rconfig.UserFile );
            else
                rconUsers = null; //For now.
            listenSocket = new Socket( AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp );
            listenSocket.SendBufferSize = rconfig.SocketBufferSize;
            listenSocket.ReceiveBufferSize = rconfig.SocketBufferSize;
        }
コード例 #4
0
ファイル: 2QService.cs プロジェクト: aarondl/Project-2Q
        /// <summary>
        /// Constructs a 2Q.
        /// </summary>
        /// <param name="configFile">Path to the configuration file.</param>
        public Project2QService(string configFile)
        {
            /*this.CanPauseAndContinue = true;
            this.CanShutdown = true;
            this.CanStop = true;
            this.CanHandlePowerEvent = true;
            this.AutoLog = false;
            this.ServiceName = "2Q";*/

            config = new Configuration( configFile );
            //config = new Configuration();

            logFile = new FileStream( Environment.CurrentDirectory + "\\2Q.log", FileMode.Append,
                FileAccess.Write, FileShare.None );
        }
コード例 #5
0
ファイル: ScriptedModule.cs プロジェクト: aarondl/Project-2Q
 /// <summary>
 /// Creates a module and readies it for loading.
 /// </summary>
 /// <param name="moduleConfiguration">The configuration of the module.</param>
 /// <param name="moduleId">The id number of the module relative the server.</param>
 /// <param name="bindTo">The server to bind the module events to.</param>
 public ScriptedModule(Configuration.ModuleConfig moduleConfiguration, int moduleId)
 {
     this.modConfig = moduleConfiguration;
     this.moduleId = moduleId;
     this.moduleSpace = null;
 }
コード例 #6
0
ファイル: Rcon.cs プロジェクト: aarondl/Project-2Q
 /// <summary>
 /// Creates an Rcon Server with the ability to log.
 /// </summary>
 /// <param name="rconfig">An RConsole Configuration to build off.</param>
 /// <param name="writeLog">The function to call with logging information.</param>
 public Rcon(Configuration.RconConfig rconfig, Project2QService.WriteLogFunction writeLog)
     : this(rconfig)
 {
     writeLogFunction = writeLog;
 }
コード例 #7
0
ファイル: Server.cs プロジェクト: aarondl/Project-2Q
 /// <summary>
 /// Creates a server from a ServerConfig.
 /// </summary>
 /// <param name="config">The configuration to build the Server from.</param>
 public Server(Configuration.ServerConfig config)
     : this(config, null)
 {
 }
コード例 #8
0
ファイル: 2QService.cs プロジェクト: aarondl/Project-2Q
        /// <summary>
        /// Loads modules for the bot.
        /// </summary>
        /// <param name="mods">The modules to load.</param>
        public static void LoadModules(Configuration.ModuleConfig[] mods)
        {
            if ( mods == null ) return;

            foreach ( Configuration.ModuleConfig c in mods ) {

                //Check if all files are present.
                //This check is redundant. It happens again in the actual module loading but we can skip a lot
                //of memory allocation and what-not stuff by doing it here first.
                bool filecheck = true;
                foreach ( string filename in c.FileNames )
                    if ( !File.Exists( Path.GetFullPath( filename ) ) &&
                        ( Configuration.ModuleConfig.ModulePath == null ||
                         !File.Exists( Path.GetFullPath( Path.Combine( Configuration.ModuleConfig.ModulePath, filename ) ) ) ) ) {
                        WriteLog( "  Module load Failed: " + c.FullName + ", File not found: " + Path.GetFileName( filename ) );
                        filecheck = false;
                        break;
                    }

                //TODO: Make sure this check works. Seems okay.
                if ( filecheck && c.IsScript )
                    foreach ( string filename in c.Includes )
                        if ( !File.Exists( Path.GetFullPath( filename ) ) &&
                            ( Configuration.ModuleConfig.IncludePath == null ||
                             !File.Exists( Path.GetFullPath( Path.Combine( Configuration.ModuleConfig.IncludePath, filename ) ) ) ) ) {
                            if ( !File.Exists( filename ) &&
                                !File.Exists( Path.GetFullPath( Path.Combine( Configuration.ModuleConfig.FrameworkPath, filename ) ) ) ) {
                                WriteLog( "  Module load Failed: " + c.FullName + ", Referenced Dependency not found: " + Path.GetFileName( filename ) );
                                filecheck = false;
                                break;
                            }
                        }

                if ( !filecheck )
                    continue;

                //Assign moduleId if we can.
                int moduleId = Project2QService.NextModuleID;
                if ( moduleId == -1 ) throw new OverflowException( "Too many modules created." );

                //Load up the modules, catch ModuleLoadExceptions to avoid crashing if a bad module is around.
                if ( c.IsScript ) {
                    ScriptedModule sm = new ScriptedModule( c, moduleId );

                    try {
                        sm.LoadModule();
                    }
                    catch ( ModuleLoadException mle ) {
                        WriteLog( "  Module load failed: " + "." + c.FullName + ", " + mle.Message );
                        string[] errors = mle.CompilerErrors;
                        if ( errors != null )
                            foreach ( string error in errors )
                                WriteLog( "   Compiler Error: " + error );
                        continue;
                    }

                    modules[moduleId] = sm;

                    //WriteLog( "  Module Loaded: " + c.FullName ); Cheating for nicer output. See StartServerThreads

                }
                else {
                    CompiledModule cm = new CompiledModule( c, moduleId );

                    try {
                        cm.LoadModule();
                    }
                    catch ( ModuleLoadException mle ) {
                        WriteLog( "  Module load failed: " + mle.Message );
                        continue;
                    }

                    modules[moduleId] = cm;

                    //WriteLog( "  Module Loaded: " + c.FullName ); Cheating for nicer output. See StartServerThreads
                }

            }
        }
コード例 #9
0
ファイル: 2QService.cs プロジェクト: aarondl/Project-2Q
 /// <summary>
 /// Load a module.
 /// </summary>
 /// <param name="mc">The module config of the module to load.</param>
 public static void LoadModule(Configuration.ModuleConfig mc)
 {
     LoadModules( new Configuration.ModuleConfig[] { mc } );
 }