Exemple #1
0
        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();
        }
Exemple #2
0
        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}");
        }
Exemple #3
0
        public void Shutdown()
        {
            AuthCommunicator?.Close();
            AuthCommunicator = null;

            ListenerSocket?.Close();
            ListenerSocket = null;

            Loop.Stop();
        }
Exemple #4
0
 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
     });
 }
Exemple #5
0
        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!");
        }
Exemple #6
0
        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
            });
        }
Exemple #7
0
        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();
        }
Exemple #8
0
        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}");
        }