示例#1
0
        /// <summary>
        /// Initialises a new <see cref="ServerChat"/> instance.
        /// </summary>
        /// <param name="netServer"></param>
        /// <param name="authenticator"></param>
        /// <param name="userManager"></param>
        /// <param name="messageHistoryCapacity"></param>
        public ServerChat(NetServer netServer, ServerAuthenticator authenticator, ServerUserManager userManager, int messageHistoryCapacity)
        {
            this.netServer              = netServer;
            this.authenticator          = authenticator;
            this.userManager            = userManager;
            this.messageHistoryCapacity = messageHistoryCapacity;

            this.messageHistory = new List <ChatMessage>();

            netServer.RegisterPacketHandler(MODULE_NAME, packetHandler);
            userManager.OnLogin += loginHandler;
        }
示例#2
0
        public ServerTrading(NetServer netServer, ServerAuthenticator authenticator, ServerUserManager userManager)
        {
            this.netServer     = netServer;
            this.authenticator = authenticator;
            this.userManager   = userManager;

            this.activeTrades    = new Dictionary <string, Trade>();
            this.completedTrades = new Dictionary <string, CompletedTrade>();

            netServer.RegisterPacketHandler(MODULE_NAME, packetHandler);
            userManager.OnLogin += loginEventHandler;
        }
示例#3
0
 /// <summary>
 /// Initialises a new <see cref="ServerChat"/> instance and loads the chat history from the given file.
 /// </summary>
 /// <param name="netServer"></param>
 /// <param name="authenticator"></param>
 /// <param name="userManager"></param>
 /// <param name="messageHistoryCapacity"></param>
 /// <param name="messageHistoryStorePath"></param>
 public ServerChat(NetServer netServer, ServerAuthenticator authenticator, ServerUserManager userManager, int messageHistoryCapacity, string messageHistoryStorePath) : this(netServer, authenticator, userManager, messageHistoryCapacity)
 {
     Load(messageHistoryStorePath);
 }
示例#4
0
文件: Server.cs 项目: Maatss/Phinix
        static void Main()
        {
            // Read in the config and initialise the logging module
            Config = Config.Load(CONFIG_FILE);
            Logger = new Logger(Config.LogPath, Config.DisplayVerbosity, Config.LogVerbosity);

            // Set up module instances
            Connections   = new NetServer(new IPEndPoint(Config.Address, Config.Port), Config.MaxConnections);
            Authenticator = new ServerAuthenticator(
                netServer: Connections,
                serverName: Config.ServerName,
                serverDescription: Config.ServerDescription,
                authType: Config.AuthType
                );
            UserManager = new ServerUserManager(Connections, Authenticator, Config.MaxDisplayNameLength);
            Chat        = new ServerChat(Connections, Authenticator, UserManager, Config.ChatHistoryLength);
            Trading     = new ServerTrading(Connections, Authenticator, UserManager);

            // Add handler for ILoggable modules
            Authenticator.OnLogEntry += ILoggableHandler;
            UserManager.OnLogEntry   += ILoggableHandler;
            Chat.OnLogEntry          += ILoggableHandler;
            Trading.OnLogEntry       += ILoggableHandler;

            // Load saved data
            Authenticator.Load(Config.CredentialDatabasePath);
            UserManager.Load(Config.UserDatabasePath);
            Chat.Load(Config.ChatHistoryPath);
            Trading.Load(Config.TradeDatabasePath);

            // Start listening for connections
            Connections.Start();

            // State our auth type and where we're listening from
            Logger.Log(Verbosity.INFO, string.Format("Accepting auth type \"{0}\"", Config.AuthType.ToString()));
            Logger.Log(Verbosity.INFO, string.Format("Phinix server version {0} listening on {1}:{2}", Version, Connections.Endpoint.Address, Connections.Endpoint.Port));

            // Set up an exit condition on SIGINT/Ctrl+C
            Console.CancelKeyPress += shutdownHandler;

            // Start interpreting commands
            CommandInterpreter interpreter = new CommandInterpreter();

            while (!exiting)
            {
                // Wait until we've got a command to interpret
                string line = Console.ReadLine();

                // Don't do anything if the command is empty
                if (string.IsNullOrEmpty(line))
                {
                    continue;
                }

                // Break the line down into the command and its arguments
                List <string> arguments = new List <string>(line.Split(' '));
                string        command   = arguments.First();
                arguments.RemoveAt(0); // Remove the command from the argument list

                // Check if we've been given the exit command
                // This is checked here to avoid weird workarounds from the interpreter
                if (command == "exit" || command == "quit" || command == "stop")
                {
                    shutdownHandler();
                    break;
                }

                // Interpret the command and its arguments
                interpreter.Run(command, arguments);
            }
        }
示例#5
0
 public ServerTrading(NetServer netServer, ServerAuthenticator authenticator, ServerUserManager userManager, string tradeDatabasePath) : this(netServer, authenticator, userManager)
 {
     Load(tradeDatabasePath);
 }