コード例 #1
0
ファイル: Client.cs プロジェクト: nako75/CoCSharp-server-dev
        public Client(Socket client, Socket server, NetworkManagerAsyncSettings settings)
        {
            Dumper = new MessageDumper();
            Logger = new MessageLogger();

            Processor        = new MessageProcessorNaClProxy(Crypto8.StandardKeyPair);
            ClientConnection = new NetworkManagerAsync(client, settings, Processor);
            ClientConnection.MessageReceived += ClientReceived;

            ServerConnection = new NetworkManagerAsync(server, settings, Processor);
            ServerConnection.MessageReceived += ServerReceived;
        }
コード例 #2
0
 public Proxy()
 {
     Connections = new List <Client>();
     Settings    = new NetworkManagerAsyncSettings();
     _listener   = new Socket(SocketType.Stream, ProtocolType.Tcp);
 }
コード例 #3
0
        public Server()
        {
            const string LOG_DIR_PATH     = "logs";
            const string CONFIG_FILE_PATH = "server_config.xml";

            // Initialize our loggers.
            _logs = new Logs(LOG_DIR_PATH);
            _logs.RegisterLogger <ClanLogger>();
            _logs.RegisterLogger <CleanErrorLogger>();
            _logs.Info($"Loading config at '{CONFIG_FILE_PATH}'...");

            // Initialize our configs.
            _config = new ServerConfiguration();
            // If the config does not exists we create it.
            if (!File.Exists(CONFIG_FILE_PATH))
            {
                _logs.Warn($"Config at '{CONFIG_FILE_PATH}' was not found; creating one.");
                _config.Save(CONFIG_FILE_PATH);
            }
            // If we couldn't load all of the configs or part of the config is missing
            // we overwrite it.
            else if (!_config.Load(CONFIG_FILE_PATH))
            {
                // Keep a backup of the old config.
                var oldName = CONFIG_FILE_PATH;
                var newName = $"{Path.GetFileNameWithoutExtension(CONFIG_FILE_PATH)}_old_{DateTime.Now.ToString("dd-HH-mm-ss-ff")}{Path.GetExtension(CONFIG_FILE_PATH)}";
                File.Move(oldName, newName);

                _logs.Warn($"Was unable to load config at '{CONFIG_FILE_PATH}' completely; overwriting old one.");
                _config.Save(CONFIG_FILE_PATH);
            }

            // Check whether the values in server configuration is valid.
            if (!CheckConfig())
            {
                _logs.Error("Server configuration was incorrect.");
                Close();

                Environment.Exit(1);
            }

            // Initialize our thread-safe client list.
            _clients = new ClientCollection();
            _cache   = new CacheManager();

            _factories = new FactoryManager(this);
            _factories.RegisterFactory <LevelSaveFactory>();
            _factories.RegisterFactory <ClanSaveFactory>();

            // Initialize the Web API.
            // TODO: Turn into plugin when the plugin system is set up.
            _webApi = new WebApi(this);

            _levels = new LevelManager(this);
            _clans  = new ClanManager(this);
            // Initialize our message handler, to handle incoming messages.
            _handler = new MessageHandler(this);

            _heartbeat  = new Timer(DoHeartbeat, null, 5000, 5000);
            _listener   = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            _acceptPool = new SocketAsyncEventArgsPool(8, AcceptCompleted);
            _settings   = new NetworkManagerAsyncSettings(64, 64, 32);
        }