public bool Start() { // If no config file has been found, these values are 0 by default if (Config.GameConfig.Port == 0 || Config.GameConfig.Backlog == 0) { Logger.WriteLog(LogType.Error, "Invalid config values!"); return(false); } Loop.Start(); SetupCommunicator(); try { ListenerSocket = new LengthedSocket(SizeType.Dword, false); ListenerSocket.OnError += OnError; ListenerSocket.OnAccept += OnAccept; ListenerSocket.Bind(new IPEndPoint(IPAddress.Any, Config.GameConfig.Port)); ListenerSocket.Listen(Config.GameConfig.Backlog); } catch (Exception e) { Logger.WriteLog(LogType.Error, "Unable to create or start listening on the client socket! Exception:"); Logger.WriteLog(LogType.Error, e); return(false); } LoginManager.OnLogin += OnLogin; QueueManager = new QueueManager(this); ListenerSocket.AcceptAsync(); Logger.WriteLog(LogType.Network, "*** Listening for clients on port {0}", Config.GameConfig.Port); Timer.Add("SessionExpire", 10000, true, () => { var toRemove = new List <uint>(); lock (IncomingClients) { toRemove.AddRange(IncomingClients.Where(ic => ic.Value.ExpireTime < DateTime.Now).Select(ic => ic.Key)); foreach (var rem in toRemove) { IncomingClients.Remove(rem); } } }); Timer.Add("QueueManagerUpdate", Config.QueueConfig.UpdateInterval, true, () => { QueueManager.Update(Config.ServerInfoConfig.MaxPlayers - CurrentPlayers); }); return(true); }
private void MsgRedirectRequest(RedirectRequestPacket packet) { lock (IncomingClients) { if (IncomingClients.ContainsKey(packet.Id)) { IncomingClients.Remove(packet.Id); } IncomingClients.Add(packet.Id, new LoginAccountEntry(packet)); } AuthCommunicator.Send(new RedirectResponsePacket { AccountId = packet.Id, Response = RedirectResult.Success }); }
public LoginAccountEntry AuthenticateClient(Client client, uint accountId, uint oneTimeKey) { lock (IncomingClients) { if (!IncomingClients.ContainsKey(accountId)) { return(null); } var entry = IncomingClients[accountId]; if (entry == null || entry.OneTimeKey != oneTimeKey) { return(null); } IncomingClients.Remove(accountId); return(entry); } }