Ejemplo n.º 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}");
            }
        }
Ejemplo n.º 2
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
        }