Beispiel #1
0
    public void Dispose()
    {
        if (Disposed)
        {
            return;
        }

        if (this is LoginSession loginSession)
        {
            MapleServer.GetLoginServer().RemoveSession(loginSession);
        }

        if (this is GameSession gameSession)
        {
            MapleServer.GetGameServer().RemoveSession(gameSession);
        }

        Disposed = true;
        Complete();
        Thread.Join(STOP_TIMEOUT);

        CloseClient();

#if DEBUG
        GC.SuppressFinalize(this);
#endif
    }
    public override void Handle(LoginSession session, PacketReader packet)
    {
        LoginMode mode     = (LoginMode)packet.ReadByte();
        string    username = packet.ReadUnicodeString();
        string    password = packet.ReadUnicodeString();

        if (string.IsNullOrEmpty(username))
        {
            session.Send(LoginResultPacket.SendLoginMode(Packets.LoginMode.IncorrectId));
            return;
        }

        Account account;

        if (DatabaseManager.Accounts.AccountExists(username.ToLower()))
        {
            if (!DatabaseManager.Accounts.Authenticate(username, password, out account))
            {
                session.Send(LoginResultPacket.SendLoginMode(Packets.LoginMode.IncorrectPassword));
                return;
            }

            Session loggedInAccount = MapleServer.GetSessions(MapleServer.GetLoginServer(), MapleServer.GetGameServer()).FirstOrDefault(p => p switch
            {
                LoginSession s => s.AccountId == account.Id,
                GameSession s => s.Player?.AccountId == account.Id,
                _ => false
            });