Example #1
0
        public static void HandleIdentification(BigEndianReader reader, AuthClient client, AuthServer server)
        {
            IdentificationWithLoginTokenMessage message = new IdentificationWithLoginTokenMessage();

            message.Unpack(reader);
            Account  account = AccountManager.GetAccount(message.login);
            DateTime dateNow = DateTime.Now;

            //IF ACCOUNT EXIST
            if (account == null ||
                message.password != Tools.GetMd5(account.Password + client.Ticket)) //Test password
            {
                client.Send(new IdentificationFailedMessage((sbyte)IdentificationFailureReasonEnum.WRONG_CREDENTIALS));
                client.Disconnect();
                return;
            }
            client.account = account;
            //IF LIFE BANNED OR IP BANNED
            if (account.Banned || server.BlockedIp.Contains(client.Ip))
            {
                client.Send(new IdentificationFailedMessage((sbyte)IdentificationFailureReasonEnum.BANNED));
                client.Disconnect();
                return;
            }
            //IF TEMP BANNED
            if (account.EndBan > dateNow)
            {
                int ms = 0;
                ms = (int)account.EndBan.Subtract(dateNow).TotalMinutes;
                client.Send(new IdentificationFailedBannedMessage((sbyte)IdentificationFailureReasonEnum.BANNED, ms));
                client.Disconnect();
                return;
            }
            //IF ON MAINTENANCE
            if (AuthServer.onMaintenance && !account.isAdmin)
            {
                client.Send(new IdentificationFailedMessage((sbyte)IdentificationFailureReasonEnum.IN_MAINTENANCE));
                client.Disconnect();
                return;
            }
            //TODO QUEUE MANAGEMENT
            if (account.Pseudo == null || account.Pseudo.Length == 0)
            {
                client.Send(new NicknameRegistrationMessage());
                Out.Info($"First connection for account '{account.Username}'. Requesting a nickname.");
                return;
            }
            SendAccServer(client, server);
            //TODO AUTO CONNECT TO THE FIRST AVAILABLE SERVER
            if (message.autoconnect)
            {
                //client.Send(new SelectedServerRefusedMessage(1, (sbyte)ServerConnectionErrorEnum.SERVER_CONNECTION_ERROR_DUE_TO_STATUS, (sbyte)ServerStatusEnum.NOJOIN));
                Out.Debug(account.isAdmin ? $"+Admin {account.Pseudo}" : $"+User {account.Pseudo}");
            }
        }
Example #2
0
        public static void SendSelectServerData(AuthClient client, WorldServer world)
        {
            /* Check if is null */
            if (world == null)
            {
                return;
            }

            client.LookingOfServers = false;

            /* Bind Ticket */
            client.Account.Ticket = new AsyncRandom().RandomString(32);
            AccountManager.Instance.CacheAccount(client.Account);

            client.Account.LastConnection      = DateTime.Now;
            client.Account.LastConnectedIp     = client.UserGroup.Role == RoleEnum.Administrator ? "127.0.0.1" : client.IP;
            client.Account.LastConnectionWorld = world.Id;
            client.SaveNow();

            client.Send(new SelectedServerDataMessage(
                            (short)world.Id,
                            world.Address,
                            world.Port,
                            (client.UserGroup.Role >= world.RequiredRole || client.UserGroup.AvailableServers.Contains(world.Id)),
                            Encoding.ASCII.GetBytes(client.Account.Ticket).Select(x => (sbyte)x)));

            client.Disconnect();
        }
Example #3
0
        public bool DisconnectClient(AuthClient newClient)
        {
            bool       succes = false;
            AuthClient client = AuthServer.Instance.GetClients().Find(x => x.Account != null && x.Account.Id == newClient.Account.Id);

            if (client != null)
            {
                client.Disconnect();
                succes = true;
            }
            else
            {
                if (newClient.Account.LastSelectedServerId != 0)
                {
                    TransitionClient server = TransitionServer.Instance.GetServerClient(newClient.Account.LastSelectedServerId);
                    var serverData          = ServerRecord.GetWorldServer(newClient.Account.LastSelectedServerId);
                    if (server != null && server.IsConnected && serverData != null && serverData.Status != ServerStatusEnum.STARTING) // Online
                    {
                        MessagePool.SendRequest <DisconnectClientResultMessage>(server,
                                                                                new DisconnectClientRequestMessage {
                            AccountId = newClient.Account.Id,
                        },
                                                                                delegate(DisconnectClientResultMessage message) { succes = message.IsSucces; },
                                                                                delegate() { this.OnTransitionFailed(newClient); });
                    }
                    else
                    {
                        succes = false;
                    }
                }
            }

            return(succes);
        }
        public void DisconnectClientsUsingAccount(Account account)
        {
            AuthClient[] array = ServerBase <AuthServer> .Instance.FindClients((AuthClient entry) => entry.Account != null && entry.Account.Id == account.Id).ToArray <AuthClient>();

            AuthClient[] array2 = array;
            for (int i = 0; i < array2.Length; i++)
            {
                AuthClient authClient = array2[i];
                authClient.Disconnect();
            }
            if (account.LastConnectionWorld.HasValue)
            {
                WorldServer serverById = Singleton <WorldServerManager> .Instance.GetServerById(account.LastConnectionWorld.Value);

                if (serverById != null && serverById.Connected && serverById.IPCClient != null)
                {
                    serverById.IPCClient.SendRequest <DisconnectedClientMessage>(new DisconnectClientMessage(account.Id)
                                                                                 , delegate(DisconnectedClientMessage msg)
                    {
                    }, delegate(IPCErrorMessage error)
                    {
                    });
                }
            }
        }
Example #5
0
        public static void SelectedServer(ServerSelectionMessage message, AuthClient client)
        {
            string host      = ConfigurationManager.Instance.IsCustomHost == true ? ConfigurationManager.Instance.RealHost : ConfigurationManager.Instance.Host;
            var    encrypted = AccountsProvider.EncryptTicket(ServersManager.TransfertToGame(client.Account), client.AesKey);

            client.Send(new SelectedServerDataMessage((ushort)ConfigurationManager.Instance.ServerId, host, (ushort)ConfigurationManager.Instance.WorldPort, true, encrypted));
            client.Disconnect();
        }
Example #6
0
        public void ServerSelectionMessageFrame(AuthClient client, ServerSelectionMessage serverSelectionMessage)
        {
            List <uint> ports = new List <uint>();

            ports.Add(6666);

            client.SendPacket(new SelectedServerDataMessage(serverSelectionMessage.serverId, "127.0.0.1", ports, true, AuthenticationUtils.EncodeTicket(client.salt)));
            client.Disconnect();
        }
Example #7
0
        public static void HandleServerSelection(BigEndianReader reader, AuthClient client, AuthServer server)
        {
            ServerSelectionMessage message = new ServerSelectionMessage();

            message.Unpack(reader);
            client.Send(new SelectedServerDataMessage(1, "127.0.0.1", 442, true, client.Ticket));
            client.Disconnect();
            //client.Send(new SelectedServerRefusedMessage(message.serverId, (sbyte)ServerConnectionErrorEnum.SERVER_CONNECTION_ERROR_NO_REASON, (sbyte)ServerStatusEnum.NOJOIN));
            //TODO HANDLE SERVER CONNECTION REQUEST FROM CLIENT
        }
Example #8
0
        public static void HandlePacket(byte[] data, AuthClient client, AuthServer server)
        {
            BigEndianReader reader = new BigEndianReader(data);
            AuthClient      cl     = client;
            short           header = reader.ReadShort();
            uint            Id     = (uint)header >> 2;
            uint            Length = (uint)header & 3;

            reader = UpdateReader(reader, Length);
            if (!packetList.ContainsKey(Id))
            {
                Out.Warn($"Unexpected packet from { client.Ip}. Invalid packet ID[{ Id}]" +
                         "\nDisconnecting client");
                client.Disconnect();
                return;
            }
            Out.Debug($"{"New Packet",-12} : {packetList[Id].Method.Name.Remove(0, 6),30}[{Id,4}] <-- {client.Ip,-12}");
            packetList[Id](reader, client, server);
        }
Example #9
0
        public static void SendSelectServerData(AuthClient client, WorldServer world)
        {
            if (world != null)
            {
                client.LookingOfServers = false;
                client.Account.Ticket   = new AsyncRandom().RandomString(32);
                Singleton <AccountManager> .Instance.CacheAccount(client.Account);

                client.Account.LastConnection      = new DateTime?(DateTime.Now);
                client.Account.LastConnectedIp     = client.IP;
                client.Account.LastConnectionWorld = new int?(world.Id);
                client.SaveNow();

                var writer = new BigEndianWriter();
                writer.WriteByte((byte)client.Account.Ticket.Length);
                writer.WriteUTFBytes(client.Account.Ticket);
                client.Send(new SelectedServerDataMessage((ushort)world.Id, world.Address, world.Port, true, Cryptography.EncryptAES(writer.Data, client.AesKey)));

                client.Disconnect();
            }
        }
Example #10
0
        public static void HandleClearIdentificationMessage(AuthClient client, ClearIdentificationMessage message)
        {
            lock (ConnectionQueue.SyncRoot)
                ConnectionQueue.Remove(client);

            if (client.QueueShowed)
            {
                SendQueueStatusMessage(client, 0, 0); // close the popup
            }
            /* Invalid password */
            if (!CredentialManager.Instance.DecryptCredentials(out var account, message))
            {
                SendIdentificationFailedMessage(client, IdentificationFailureReasonEnum.WRONG_CREDENTIALS);
                client.DisconnectLater(1000);
                return;
            }

            /* Check ServerIP - AntiBot Mesure */
            if (!message.serverIp.Contains(AuthServer.CustomHost)) //Will cause problem with NAT as CustomHost will not be the public server IP
            {
                SendIdentificationFailedMessage(client, IdentificationFailureReasonEnum.BANNED);
                client.DisconnectLater(1000);
                return;
            }

            SendCredentialsAcknowledgementMessage(client);

            client.Account = account;
            /* Check Sanctions */
            if (account.IsBanned && account.BanEndDate > DateTime.Now)
            {
                SendIdentificationFailedBannedMessage(client, account.BanEndDate.Value);
                client.DisconnectLater(1000);
                return;
            }

            if (account.IsLifeBanned)
            {
                SendIdentificationFailedBannedMessage(client);
                client.DisconnectLater(1000);
                return;
            }

            if (account.BanEndDate < DateTime.Now)
            {
                account.IsBanned   = false;
                account.IsJailed   = false;
                account.BanEndDate = null;
            }

            var ipBan = AccountManager.Instance.FindMatchingIpBan(client.IP);

            if (ipBan != null && ipBan.GetRemainingTime() > TimeSpan.Zero)
            {
                SendIdentificationFailedBannedMessage(client, ipBan.GetEndDate());
                client.DisconnectLater(1000);
                return;
            }

            var hardwareIdBan = AccountManager.Instance.FindHardwareIdBan(message.hardwareId);

            if (hardwareIdBan != null)
            {
                SendIdentificationFailedBannedMessage(client);
                client.DisconnectLater(1000);
                return;
            }

            AccountManager.Instance.DisconnectClientsUsingAccount(account, client, success => AuthServer.Instance.IOTaskPool.AddMessage(() =>
            {
                // we must reload the record since it may have been modified
                if (success)
                {
                    account = AccountManager.Instance.FindAccountById(account.Id);
                }

                /* Bind Account to Client */
                client.Account   = account;
                client.UserGroup = AccountManager.Instance.FindUserGroup(account.UserGroupId);
                client.Account.LastHardwareId = message.hardwareId;

                if (client.UserGroup == null)
                {
                    SendIdentificationFailedMessage(client, IdentificationFailureReasonEnum.UNKNOWN_AUTH_ERROR);
                    logger.Error("User group {0} doesn't exist !", client.Account.UserGroupId);
                    return;
                }

                /* Propose at client to give a nickname */
                if (client.Account.Nickname == string.Empty)
                {
                    client.Send(new NicknameRegistrationMessage());
                    return;
                }

                SendIdentificationSuccessMessage(client, false);

                /* If autoconnect, send to the lastServer */
                if (message.autoconnect && client.Account.LastConnectionWorld != null && WorldServerManager.Instance.CanAccessToWorld(client, client.Account.LastConnectionWorld.Value))
                {
                    SendSelectServerData(client, WorldServerManager.Instance.GetServerById(client.Account.LastConnectionWorld.Value));
                }
                else
                {
                    SendServersListMessage(client, 0, true);
                }
            }), () =>
            {
                client.Disconnect();
                logger.Error("Error while joining last used world server, connection aborted");
            });
        }
Example #11
0
 public static IEnumerable <NetworkMessage> HandleIdentificationMessage(AuthClient client, IdentificationMessage message)
 {
     client.Disconnect();
     // Add to queue etc...
     return(Enumerable.Empty <NetworkMessage>());
 }
Example #12
0
        public static void BuildPacket(byte[] data, AuthClient client, AuthServer server)
        {
            BigEndianReader reader = new BigEndianReader(data);
            AuthClient      cl     = client;
            short           header = reader.ReadShort();
            uint            Id     = (uint)header >> 2;
            uint            Length = (uint)header & 3;

            reader = UpdateReader(reader, Length);
            Out.Debug($"=> Packet[{Id}] from {client.Ip}");
            #region
            switch (Id)
            {
            case 4:
                IdentificationWithLoginTokenMessage message = new IdentificationWithLoginTokenMessage();
                message.Unpack(reader);
                Account  account = AccountManager.GetAccount(message.login);
                DateTime dateNow = DateTime.Now;
                List <GameServerInformations> servers = new List <GameServerInformations>();
                foreach (WorldServer s in server.Servers.Values)     //Load each server
                {
                    int nbChar = AccountManager.GetNbChar(s.ServerId, account.Id);
                    servers.Add(new GameServerInformations((ushort)s.ServerId, (sbyte)s.Status, (sbyte)s.Completion, true, (sbyte)nbChar));
                }
                if (servers.Count < 1)
                {
                    AuthServer.onMaintenance = true;
                }
                if (account == null ||
                    message.password != Tools.GetMd5(account.Password + cl.Ticket))     //Test password
                {
                    client.Send(new IdentificationFailedMessage((sbyte)IdentificationFailureReasonEnum.WRONG_CREDENTIALS));
                    client.Disconnect();
                    return;
                }
                if (account.Banned)     // ban a vie
                {
                    client.Send(new IdentificationFailedMessage((sbyte)IdentificationFailureReasonEnum.BANNED));
                    client.Disconnect();
                    return;
                }
                if (account.EndBan > dateNow)    //Ban temp
                {
                    int ms = 0;
                    ms = (int)account.EndBan.Subtract(dateNow).TotalMinutes;
                    client.Send(new IdentificationFailedBannedMessage((sbyte)IdentificationFailureReasonEnum.BANNED, ms));
                    client.Disconnect();
                    return;
                }
                if (AuthServer.onMaintenance)     //Maintenance (In config)
                {
                    client.Send(new IdentificationFailedMessage((sbyte)IdentificationFailureReasonEnum.IN_MAINTENANCE));
                    client.Disconnect();
                    return;
                }
                client.account = account;

                double msSub = 0;
                if (account.EndSub > DateTime.Now)
                {
                    msSub = account.EndSub.Subtract(DateTime.Now).TotalMilliseconds;
                }
                client.Send(new IdentificationSuccessMessage(account.isAdmin, true, account.Pseudo, account.Id, 0, account.Question, msSub));
                Out.Debug(account.isAdmin? $"+Admin {account.Pseudo}" : $"+User {account.Pseudo}");
                client.Send(new ServersListMessage(servers));

                //TODO Get number of characters for each server
                return;

            default:
                client.Disconnect();
                return;
            }
            #endregion
        }