private void OnCommunicatorConnect(SocketAsyncEventArgs args) { if (args.SocketError != SocketError.Success) { Timer.Add("CommReconnect", 10000, false, () => { if (AuthCommunicator?.Connected ?? true) { ConnectCommunicator(); } }); Logger.WriteLog(LogType.Error, "Could not connect to the Auth server! Trying again in a few seconds..."); return; } Logger.WriteLog(LogType.Network, "*** Connected to the Auth Server!"); AuthCommunicator.OnReceive += OnCommunicatorReceive; AuthCommunicator.Send(new LoginRequestPacket { ServerId = Config.ServerInfoConfig.Id, Password = Config.ServerInfoConfig.Password, PublicAddress = PublicAddress }); AuthCommunicator.ReceiveAsync(); }
private void OnCommunicatorAccept(LengthedSocket socket) { AuthCommunicator.AcceptAsync(); lock (GameServers) GameServerQueue.Add(new CommunicatorClient(socket, this)); Logger.WriteLog(LogType.Network, $"A Game server has connected! Remote: {socket.RemoteAddress}"); }
public void Shutdown() { AuthCommunicator?.Close(); AuthCommunicator = null; ListenerSocket?.Close(); ListenerSocket = null; Loop.Stop(); }
private void MsgGameInfoRequest(ServerInfoRequestPacket packet) { AuthCommunicator.Send(new ServerInfoResponsePacket { AgeLimit = Config.ServerInfoConfig.AgeLimit, PKFlag = Config.ServerInfoConfig.PKFlag, CurrentPlayers = CurrentPlayers, GamePort = Config.GameConfig.Port, QueuePort = Config.QueueConfig.Port, MaxPlayers = (ushort)Config.SocketAsyncConfig.MaxClients }); }
private void MsgLoginResponse(LoginResponsePacket packet) { if (packet.Response == CommLoginReason.Success) { Logger.WriteLog(LogType.Network, "Successfully authenticated with the Auth server!"); return; } AuthCommunicator?.Close(); AuthCommunicator = null; Logger.WriteLog(LogType.Error, "Could not authenticate with the Auth server! Shutting down internal communication!"); }
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 }); }
private void OnCommunicatorConnect(SocketAsyncEventArgs args) { if (args.SocketError != SocketError.Success) { OnCommunicatorError(args); return; } Logger.WriteLog(LogType.Network, "*** Connected to the Auth Server!"); AuthCommunicator.OnReceive += OnCommunicatorReceive; AuthCommunicator.Send(new LoginRequestPacket { ServerId = Config.ServerInfoConfig.Id, Password = Config.ServerInfoConfig.Password, PublicAddress = PublicAddress }); AuthCommunicator.ReceiveAsync(); }
public void ConnectCommunicator() { if (AuthCommunicator?.Connected ?? false) { AuthCommunicator?.Close(); } try { AuthCommunicator = new LengthedSocket(SizeType.Word); AuthCommunicator.OnConnect += OnCommunicatorConnect; AuthCommunicator.ConnectAsync(new IPEndPoint(IPAddress.Parse(Config.CommunicatorConfig.Address), Config.CommunicatorConfig.Port)); } catch (Exception e) { Logger.WriteLog(LogType.Error, "Unable to create or start listening on the client socket! Retrying soon... Exception:"); Logger.WriteLog(LogType.Error, e); } Logger.WriteLog(LogType.Network, $"*** Connecting to auth server! Address: {Config.CommunicatorConfig.Address}:{Config.CommunicatorConfig.Port}"); }