public Server(IHostApplicationLifetime hostApplicationLifetime, IAuthUnitOfWorkFactory authUnitOfWorkFactory) { _hostApplicationLifetime = hostApplicationLifetime; _authUnitOfWorkFactory = authUnitOfWorkFactory; Configuration.OnLoad += ConfigLoaded; Configuration.OnReLoad += ConfigReLoaded; Configuration.Load(); Loop = new MainLoop(this, MainLoopTime); Timer = new Timer(); SetupServerList(); LengthedSocket.InitializeEventArgsPool(Config.SocketAsyncConfig.MaxClients * Config.SocketAsyncConfig.ConcurrentOperationsByClient); BufferManager.Initialize(Config.SocketAsyncConfig.BufferSize, Config.SocketAsyncConfig.MaxClients, Config.SocketAsyncConfig.ConcurrentOperationsByClient); CommandProcessor.RegisterCommand("exit", ProcessExitCommand); CommandProcessor.RegisterCommand("reload", ProcessReloadCommand); CommandProcessor.RegisterCommand("create", ProcessCreateCommand); }
public Client(LengthedSocket socket, Server server, IAuthUnitOfWorkFactory authUnitOfWorkFactory) { _authUnitOfWorkFactory = authUnitOfWorkFactory; Socket = socket; Server = server; State = ClientState.Connected; Timer = new Timer(); Socket.OnError += OnError; Socket.OnReceive += OnReceive; Socket.OnDecrypt += OnDecrypt; Socket.ReceiveAsync(); var rnd = new Random(); OneTimeKey = rnd.NextUInt(); SessionId1 = rnd.NextUInt(); SessionId2 = rnd.NextUInt(); SendPacket(new ProtocolVersionPacket(OneTimeKey)); // This is here (after ProtocolVersionPacket), so it won't get encrypted Socket.OnEncrypt += OnEncrypt; Timer.Add("timeout", Server.Config.AuthConfig.ClientTimeout * 1000, false, () => { Logger.WriteLog(LogType.Network, "*** Client timed out! Ip: {0}", Socket.RemoteAddress); Close(true); }); Logger.WriteLog(LogType.Network, "*** Client connected from {0}", Socket.RemoteAddress); }