public static void HandleAuthenticationTicketMessage(WorldClient client, AuthenticationTicketMessage message)
        {
            if (!IPCAccessor.Instance.IsConnected)
            {
                client.Send(new AuthenticationTicketRefusedMessage());
                client.DisconnectLater(1000);
            }
            else
            {
                var reader = new BigEndianReader(Encoding.ASCII.GetBytes(message.ticket));
                var count  = reader.ReadByte();
                var ticket = reader.ReadUTFBytes(count);

                ApproachHandler.logger.Debug("Client request ticket {0}", ticket);
                IPCAccessor.Instance.SendRequest <AccountAnswerMessage>(new AccountRequestMessage
                {
                    Ticket = ticket
                }, delegate(AccountAnswerMessage msg)
                {
                    ServerBase <WorldServer> .Instance.IOTaskPool.AddMessage(delegate
                    {
                        ApproachHandler.OnAccountReceived(msg, client);
                    });
                }, delegate(IPCErrorMessage error)
                {
                    client.Disconnect();
                });
            }
        }
 private static void RefreshQueue()
 {
     try
     {
         System.Collections.Generic.List <WorldClient> list = new System.Collections.Generic.List <WorldClient>();
         int num = 0;
         lock (ApproachHandler.ConnectionQueue.SyncRoot)
         {
             foreach (WorldClient current in ApproachHandler.ConnectionQueue)
             {
                 num++;
                 if (!current.Connected)
                 {
                     list.Add(current);
                 }
                 if (!(System.DateTime.Now - current.InQueueUntil <= System.TimeSpan.FromSeconds(3.0)))
                 {
                     ApproachHandler.SendQueueStatusMessage(current, (ushort)num, (ushort)ApproachHandler.ConnectionQueue.Count);
                     current.QueueShowed = true;
                 }
             }
             foreach (WorldClient current in list)
             {
                 ApproachHandler.ConnectionQueue.Remove(current);
             }
         }
     }
     finally
     {
         ApproachHandler.m_queueRefresherTask = Task.Factory.StartNewDelayed(3000, new Action(ApproachHandler.RefreshQueue));
     }
 }
        private static void OnAccountReceived(AccountAnswerMessage message, WorldClient client)
        {
            lock (ApproachHandler.ConnectionQueue.SyncRoot)
            {
                ApproachHandler.ConnectionQueue.Remove(client);
            }
            if (client.QueueShowed)
            {
                ApproachHandler.SendQueueStatusMessage(client, 0, 0);
            }
            AccountData account = message.Account;

            if (account == null)
            {
                client.Send(new AuthenticationTicketRefusedMessage());
                client.DisconnectLater(1000);
            }
            else
            {
                WorldAccount worldAccount = Singleton <AccountManager> .Instance.FindById(account.Id);

                if (worldAccount != null)
                {
                    client.WorldAccount = worldAccount;
                    if (client.WorldAccount.ConnectedCharacter.HasValue)
                    {
                        Character character = Singleton <World> .Instance.GetCharacter(client.WorldAccount.ConnectedCharacter.Value);

                        if (character != null)
                        {
                            character.LogOut();
                        }
                    }
                }

                client.SetCurrentAccount(account);
                client.Send(new AuthenticationTicketAcceptedMessage());

                BasicHandler.SendBasicTimeMessage(client);
                ApproachHandler.SendServerOptionalFeaturesMessage(client, new sbyte[1] {
                    7
                });
                ApproachHandler.SendAccountCapabilitiesMessage(client);
                client.Send(new TrustStatusMessage(true, false));
                if (client.UserGroup.Role >= RoleEnum.Moderator)
                {
                    ApproachHandler.SendConsoleCommandsListMessage(client);
                }
            }
        }