Beispiel #1
0
        public static void HandleIdentificationMessage(AuthClient client, IdentificationMessage message)
        {
            /* Wrong Version */
            if (!message.version.IsUpToDate())
            {
                SendIdentificationFailedForBadVersionMessage(client, VersionExtension.ExpectedVersion);
                client.DisconnectLater(1000);
                return;
            }

            var patch = AuthServer.Instance.GetConnectionSwfPatch();

            if (patch != null)
            {
                client.Send(new RawDataMessageFixed(patch));
            }
        }
Beispiel #2
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");
            });
        }
Beispiel #3
0
        public void Indentificate(AuthClient client)
        {
            ConnectionHandler.SendCredentialsAcknowledgementMessage(client);

            if (!client.IdentificationMessage.version.IsUpToDate())
            {
                ConnectionHandler.SendIdentificationFailedForBadVersionMessage(client, VersionExtension.ExpectedVersion);
                client.DisconnectLater(1000);
                return;
            }

            Account account;

            if (!CredentialManager.Instance.DecryptCredentials(out account, client, client.IdentificationMessage.credentials.Select(entry => (byte)entry)))
            {
                ConnectionHandler.SendIdentificationFailedMessage(client, IdentificationFailureReasonEnum.WRONG_CREDENTIALS);
                client.DisconnectLater(1000);
                return;
            }

            if (account.IsLifeBanned)
            {
                ConnectionHandler.SendIdentificationFailedMessage(client, IdentificationFailureReasonEnum.BANNED);
                client.DisconnectLater(1000);
                return;
            }

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

            if (ipBan != null)
            {
                ConnectionHandler.SendIdentificationFailedBannedMessage(client, ipBan.GetEndDate());
                client.DisconnectLater(1000);
                return;
            }

            AccountManager.Instance.DisconnectClientsUsingAccount(account);
            client.Account = account;

            if (client.Account.Nickname == string.Empty)
            {
                client.Send(new NicknameRegistrationMessage());
                return;
            }

            ConnectionHandler.SendIdentificationSuccessMessage(client, false);

            if (client.IdentificationMessage.autoconnect)
            {
                WorldServer worldServer = null;
                if (client.IdentificationMessage.serverId != 0)
                {
                    worldServer = WorldServerManager.Instance.GetServerById(client.IdentificationMessage.serverId);
                }
                else if (client.Account.LastConnectionWorld.HasValue)
                {
                    worldServer = WorldServerManager.Instance.GetServerById(client.Account.LastConnectionWorld.Value);
                }

                if (worldServer != null && WorldServerManager.Instance.CanAccessToWorld(client, worldServer))
                {
                    ConnectionHandler.SendSelectServerData(client, worldServer);
                }
                else
                {
                    client.LookingOfServers = true;
                    ConnectionHandler.SendServersListMessage(client);
                }
            }
            else
            {
                client.LookingOfServers = true;
                ConnectionHandler.SendServersListMessage(client);
            }
        }