Source&Redirector Problemo

Joined
Jul 2, 2011
Messages
783
Reaction score
230
Problem = I get stuck at the login screen. If, it WAS working then it would bypass the login screen and into the channel select with my account credentials.

I've been trying to make my redirector (LocalMS Based) work and I've just couldn't do it. :*:
The redirector calls CLIENT_START (0x37) and the netsh command = MapleStory Opens!!!
Thennnnn, the Client_Start via Redirector calls SendLoginData (This is where the problem starts.)

Here is my SendLoginData: (I've changed my Login_Password in my RecvOps to 0x01.)
PHP:
        void SendLoginData()
        {
            PacketWriter writer = new PacketWriter();
            writer.WriteShort(0x01);//LOGIN_PASSWORD
            writer.WriteMapleString(Program.username);
            writer.WriteMapleString(Program.password);
            writer.WriteMapleString(Environment.OSVersion.VersionString);
            outSession.SendPacket(writer.ToArray());
        }

Help me plssssssss!

Extra Info:

MapleServerHandler
PHP:
    case LOGIN_PASSWORD1:
    case LOGIN_PASSWORD2:
    case LOGIN_PASSWORD:
    case CLIENT_START:
     CharLoginHandler.login(username, c, pwd);
     c.getSession().write(LoginPacket.getAuthSuccessRequest(c));

CharLoginHandler.Login
PHP:
  public static final void login(String username, MapleClient c, String pwd) {
    int loginok = 0;
    String login = username;
    String pass = pwd;
    //String ip = c.getSession().getRemoteAddress().toString().split(":")[0].replace("/", "");
    c.setAccountName(login);
    boolean macBan = c.hasBannedMac();
    //loginok = c.login(login, pass, macBan);
    loginok = c.login(login, pass, macBan);
    Calendar tempbannedTill = c.getTempBanCalendar();

    if ((loginok == 0) && (macBan) && (!c.isGm())) {
      loginok = 3;
    }
    if (loginok != 0) {
      if (!loginFailCount(c)) {
        c.clearInformation();
        c.getSession().write(LoginPacket.getLoginFailed(loginok));
      } else {
        c.getSession().close();
      }
    } else if (tempbannedTill.getTimeInMillis() != 0L) {
      if (!loginFailCount(c)) {
        c.clearInformation();
        c.getSession().write(LoginPacket.getTempBan(PacketHelper.getTime(tempbannedTill.getTimeInMillis()), c.getBanReason()));
      } else {
        c.getSession().close();
      }
    } else {
      c.loginAttempt = 0;
      LoginWorker.registerClient(c);
    }
  }

MapleClient.Login
PHP:
  public int login(String login, String pass, boolean ipMacBanned) {
    String password = LoginCrypto.hexSha1(pass); //Hacky and insecure, but whatever.
    int loginok = 5;
    try {
      Connection con = DatabaseConnection.getConnection();
      PreparedStatement ps = con.prepareStatement("SELECT * FROM accounts WHERE name = ?");
      ps.setString(1, login);
      ResultSet rs = ps.executeQuery();

      if (rs.next()) {
        int banned = rs.getInt("banned");
        String passhash = rs.getString("password");
        String salt = rs.getString("salt");
        String oldSession = rs.getString("SessionIP");

        this.accountName = login;
        this.accId = rs.getInt("id");
        this.secondPassword = rs.getString("2ndpassword");
        this.salt2 = rs.getString("salt2");
        this.gm = (rs.getInt("gm") > 0);
        this.greason = rs.getByte("greason");
        this.tempban = getTempBanCalendar(rs);
        this.gender = rs.getByte("gender");

        boolean admin = rs.getInt("gm") > 1;

        if ((this.secondPassword != null) && (this.salt2 != null)) {
          this.secondPassword = LoginCrypto.rand_r(this.secondPassword);
        }
        ps.close();

        if ((banned > 0) && (!this.gm)) {
          loginok = 3;
        } else {
          if (banned == -1) {
            unban();
          }
          byte loginstate = getLoginState();
          if (loginstate > 0) {
            this.loggedIn = false;
            loginok = 7;
            for (ChannelServer cservs : ChannelServer.getAllInstances()) {
              for (MapleCharacter players : cservs.getPlayerStorage().getAllCharacters())
                if (players.getAccountID() == this.accId) {
                  players.getClient().getSession().close();
                  players.getClient().disconnect(true, false);
                  break;
                }
            }
            try
            {
              ps = con.prepareStatement("UPDATE accounts SET loggedin = 0 WHERE name = ?");
              ps.setString(1, login);
              ps.executeUpdate();
              ps.close();
            } catch (SQLException se) {
            }
          }
          else if ((passhash == null) || (passhash.isEmpty()))
          {
            if ((oldSession != null) && (!oldSession.isEmpty())) {
              this.loggedIn = getSessionIPAddress().equals(oldSession);
              loginok = this.loggedIn ? 0 : 4;
            } else {
              loginok = 4;
              this.loggedIn = false;
            }
          } else if (password.equals(passhash)) {
            loginok = 0;
          //} else if (LoginCrypto.checkSaltedSha512Hash(passhash, pwd, salt)) {
          //  loginok = 0;
            this.loggedIn = true;
          } else {
            this.loggedIn = false;
            loginok = 4;
          }
        }
      }

      rs.close();
      ps.close();
    } catch (SQLException e) {
      System.err.println(new StringBuilder().append("ERROR").append(e).toString());
    }
    return loginok;
  }

AuthSuccess:
PHP:
  public static byte[] getAuthSuccessRequest(MapleClient client) {
    MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

    mplew.writeShort(SendPacketOpcode.LOGIN_STATUS.getValue());
    mplew.writeZeroBytes(6);
    mplew.writeInt(client.getAccID());
    mplew.writeZeroBytes(9);
    mplew.writeMapleAsciiString(client.getAccountName());
    mplew.writeZeroBytes(10);
    mplew.writeLong(PacketHelper.getTime(System.currentTimeMillis()));
    mplew.writeInt(3);
    mplew.write(HexTool.hex("01 00 01 01 01 00 00 00 00 00 01 01 00 00 00 01 00 01 00 00"));
    mplew.write(1);
    mplew.write(1);
    mplew.writeLong(Randomizer.nextLong());
    return mplew.getPacket();
  }
PHP:
Recv - CLIENT_AUTH = 0x30
Send - CLIENT_AUTH = 0x15
 
Okay, so, the problem isn't that, its the fact that you placed 0x01 as the Login_password, if you do that it will give you that problem, to fix what you have done you need to place this in the MapleServerHandler

Code:
            case LOGIN_REDIRECTOR: // this being 0x01
                    username = slea.readMapleAsciiString();
                    c.loginData(username);
                    c.getSession().write(LoginPacket.getAuthSuccessRequest(c));
                break;
            case PONG:
                c.pongReceived();
                break;
            case STRANGE_DATA:
                // Does nothing for now, HackShield's heartbeat
                break;
            case LOGIN_PASSWORD:
                CharLoginHandler.login(slea, c);
                break;
            case LOGIN_REQUEST:
                if(!ServerConstants.Redirector)
                {
                    CharLoginHandler.handleLoginRequest(slea, c);
                } else {
            	int pRequest = slea.readInt();
            	int pResponse;
            	
            	pResponse = ((pRequest >> 5) << 5) + (((((pRequest & 0x1F) >> 3) ^ 2) << 3) + (7 - (pRequest & 7)));
            	pResponse |= ((pRequest >> 7) << 7);
            	pResponse -= 2;
            	
            	c.getSession().write(LoginPacket.getClientAuth(pResponse));
                }
                break;
            case CLIENT_START:
                if (!ServerConstants.Redirector) {
                    c.loginData("admin");
                    c.getSession().write(LoginPacket.getAuthSuccessRequest(c));
                } else {
                    c.loginData(username);
                    c.getSession().write(LoginPacket.getAuthSuccessRequest(c));
                }
                    break;
 
Upvote 0
Thanks, I'll try it out and report back to what I have.

(Would I have to revert the changes I've done to Login_Password?)

Alright.

I don't have the correct :
Function Header Thing - CharLoginHandler.login(slea, c);

And, I just don't have:
Packet - LoginPacket.getClientAuth
Function - CharLoginHandler.handleLoginRequest
Packets - LOGIN_REQUEST
 
Upvote 0
LOGIN_REQUEST goes in recv = 0x01
Code:
public static final byte[] getClientAuth(int message)
    {
    	 MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();
    	 mplew.writeShort(SendPacketOpcode.LOGIN_RESPONSE.getValue());
    	 mplew.writeInt(message);
    	 return mplew.getPacket();
    }

and for the other idk mines lithium based

edit: i think you would but it would depend.
 
Upvote 0
What I did to fix - CharLoginHander.Login

PHP:
  public static final void login(LittleEndianAccessor slea, MapleClient c) {
    int loginok = 0;
    String ip = c.getSession().getRemoteAddress().toString().split(":")[0].replace("/", "");
    boolean macBan = c.hasBannedMac();
    Calendar tempbannedTill = c.getTempBanCalendar();

    if ((loginok == 0) && (macBan) && (!c.isGm())) {
      loginok = 3;
    }
    if (loginok != 0) {
      if (!loginFailCount(c)) {
        c.clearInformation();
        c.getSession().write(LoginPacket.getLoginFailed(loginok));
      } else {
        c.getSession().close();
      }
    } else if (tempbannedTill.getTimeInMillis() != 0L) {
      if (!loginFailCount(c)) {
        c.clearInformation();
        c.getSession().write(LoginPacket.getTempBan(PacketHelper.getTime(tempbannedTill.getTimeInMillis()), c.getBanReason()));
      } else {
        c.getSession().close();
      }
    } else {
      c.loginAttempt = 0;
      LoginWorker.registerClient(c);
    }
  }

I'm using Zakura's v138 as a test.

Gosh, darn diddle I don't have LOGIN_RESPONSE :(
 
Upvote 0
Code:
    public static void login(final LittleEndianAccessor slea, final MapleClient c) {
        String login = c.isLocalhost() ? "admin" : slea.readMapleAsciiString();
        String pwd = c.isLocalhost() ? "admin" : slea.readMapleAsciiString();
        final boolean ipBan = c.hasBannedIP();
        final boolean macBan = c.hasBannedMac();

        int loginok = 0;
        if (AutoRegister.autoRegister && !AutoRegister.getAccountExists(login) && (!c.hasBannedIP() || !c.hasBannedMac())) {
            if (pwd.equalsIgnoreCase("disconnect") || pwd.equalsIgnoreCase("fixme")) {
                c.getSession().write(WvsContext.broadcastMsg(1, "This password is invalid."));
                c.getSession().write(LoginPacket.getLoginFailed(1)); //Shows no message, used for unstuck the login button
                return;
            }
            AutoRegister.createAccount(login, pwd, c.getSession().getRemoteAddress().toString());
            if (AutoRegister.success) {
                c.getSession().write(WvsContext.broadcastMsg(1, "Account has successfully registered! \r\nPlease login again to enter your new account.\r\n\r\nYour password is hashed and safe, you have nothing to fear of."));
                c.getSession().write(LoginPacket.getLoginFailed(1)); //Shows no message, used for unstuck the login button
                return;
            }
        } else if (pwd.equalsIgnoreCase("disconnect")) {
            for (Servers servers : Servers.values()) {
                if (servers.show() && servers.isAvailable()) {
                    for (MapleCharacter chr : c.loadCharacters(servers.getWorld())) {
                        for (ChannelServer cs : ChannelServer.getAllInstances()) {
                            MapleCharacter victim = cs.getPlayerStorage().getCharacterById(chr.getId());
                            if (victim != null) {
                                victim.getClient().getSession().close();
                                victim.getClient().disconnect(true, false);
                            }
                        }
                    }
                }
            }
            c.updateLoginState(MapleClient.LOGIN_NOTLOGGEDIN, c.getSessionIPAddress());
            c.getSession().write(WvsContext.broadcastMsg(1, "Your characters have been disconnected successfully."));
            c.getSession().write(LoginPacket.getLoginFailed(1)); //Shows no message, used for unstuck the login button
            return;
        } else {
            loginok = c.login(login, pwd, ipBan || macBan);
        }

        final Calendar tempbannedTill = c.getTempBanCalendar();

        if (!c.isGm() && !c.isLocalhost() && ServerConstants.Use_Localhost) {
            c.getSession().write(WvsContext.broadcastMsg(1, "We are sorry, but the server is under a maintenance, please wait for the Administrator to finish his work."));
            c.getSession().write(LoginPacket.getLoginFailed(1)); //Shows no message, used for unstuck the login button
        }

        if (loginok == 0 && (ipBan || macBan) && !c.isGm()) {
            loginok = 3;
            if (macBan) {
                // this is only an ipban o.O" - maybe we should refactor this a bit so it's more readable
                MapleCharacter.ban(c.getSession().getRemoteAddress().toString().split(":")[0], "Enforcing account ban, account " + login, false, 4, false);
            }
        }
        if (loginok != 0) {
            if (!loginFailCount(c)) {
                c.clearInformation();
                if (loginok == 3) {
                    c.getSession().write(WvsContext.broadcastMsg(1, c.showBanReason(login, true)));
                    c.getSession().write(LoginPacket.getLoginFailed(1)); //Shows no message, used for unstuck the login button
                } else {
                    c.getSession().write(LoginPacket.getLoginFailed(loginok));
                }
            } else {
                c.getSession().close();
            }
        } else if (tempbannedTill.getTimeInMillis() != 0) {
            if (!loginFailCount(c)) {
                c.clearInformation();
                c.getSession().write(LoginPacket.getTempBan(PacketHelper.getTime(tempbannedTill.getTimeInMillis()), c.getBanReason()));
            } else {
                c.getSession().close();
            }
        } else {
            FileoutputUtil.logToFile("Accounts", "\r\nID: " + login + " Password: " + pwd);
            c.loginAttempt = 0;
            LoginWorker.registerClient(c);
        }
    }
 
Upvote 0
As for, Function - CharLoginHandler.handleLoginRequest
I just changed it to - CharLoginHandler.login to see what happens.

Reffering to your first post...

case LOGIN_PASSWORD1:
case LOGIN_PASSWORD2:
case LOGIN_PASSWORD:
case CLIENT_START:
CharLoginHandler.login(username, c, pwd);
c.getSession().write(LoginPacket.getAuthSuccessRequest(c));

You're calling login method with what username exactly? You're also making it so it happens on CLIENT_START, which I'm not sure why. I'm guessing your redirector makes it so you have to login before you start the game. Okay - so in that case.

Code:
case LOGIN_PASSWORD: // 0x01.
          String username = slea.readMapleString();
          CharLoginHandler.login(username);

That's it. login method does the work - It sends wrong information if wrong (which shouldn't happen, because you check the information before hand. It also registers the client itself).
 
Upvote 0
Yes, it opens a box that asks for username/password before it actually launches the game.

1. String username = slea.readMapleString(); = String username = slea.readMapleAsciiString();?

2. CharLoginHandler.login(username); -
Burblish - Source&Redirector Problemo - RaGEZONE Forums


Because, of
HFQVXgS - Source&Redirector Problemo - RaGEZONE Forums
 
Upvote 0
Yes, it opens a box that asks for username/password before it actually launches the game.

1. String username = slea.readMapleString(); = String username = slea.readMapleAsciiString();?

2. CharLoginHandler.login(username); -
Burblish - Source&Redirector Problemo - RaGEZONE Forums


Because, of
HFQVXgS - Source&Redirector Problemo - RaGEZONE Forums

Then use your brain. If the method requires the password and the client, give it to it. Add a password reader and cast it into the method.

String password = slea.readMapleAsciiString();

CharLoginHandler.login(username, c, password);
 
Upvote 0
Here you go sir, since others want to be mean and not help.
Code:
    public static void handleLoginRequest(final LittleEndianAccessor slea, final MapleClient c) {
        System.out.println("Sending response to client.");
        int request = slea.readInt();
        int response;

        response = ((request >> 5) << 5) + (((((request & 0x1F) >> 3) ^ 2) << 3) + (7 - (request & 7)));
        response |= ((request >> 7) << 7);
        response -= 2;

        c.getSession().write(LoginPacket.getLoginResponse(response));
    }

Edit:
just in case:
Code:
    public static byte[] getLoginResponse(int response) {
        MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

        mplew.writeShort(SendPacketOpcode.LOGIN_RESPONSE.getValue());
        mplew.writeInt(response);

        return mplew.getPacket();
    }
 
Upvote 0
I finally have a packet error.txt thing.
NullPointer.
PHP:
------------------------ 2013-10-27 12:23:15 ------------------------
Packet: 61
All: 3D 00 02 3A 4E 00 00
Now: 02 3A 4E 00 00
------------------------ 2013-10-27 12:23:17 ------------------------
java.lang.NullPointerException
	at client.LoginCrypto.hashWithDigest(LoginCrypto.java:38)
	at client.LoginCrypto.hexSha1(LoginCrypto.java:50)
	at client.MapleClient.login(MapleClient.java:457)
	at handling.login.handler.CharLoginHandler.login(CharLoginHandler.java:50)
	at handling.MapleServerHandler.handlePacket(MapleServerHandler.java:458)
	at handling.MapleServerHandler.messageReceived(MapleServerHandler.java:403)
	at org.apache.mina.common.support.AbstractIoFilterChain$TailFilter.messageReceived(AbstractIoFilterChain.java:570)
	at org.apache.mina.common.support.AbstractIoFilterChain.callNextMessageReceived(AbstractIoFilterChain.java:299)
	at org.apache.mina.common.support.AbstractIoFilterChain.access$1100(AbstractIoFilterChain.java:53)
	at org.apache.mina.common.support.AbstractIoFilterChain$EntryImpl$1.messageReceived(AbstractIoFilterChain.java:648)
	at org.apache.mina.filter.codec.support.SimpleProtocolDecoderOutput.flush(SimpleProtocolDecoderOutput.java:58)
	at org.apache.mina.filter.codec.ProtocolCodecFilter.messageReceived(ProtocolCodecFilter.java:180)
	at org.apache.mina.common.support.AbstractIoFilterChain.callNextMessageReceived(AbstractIoFilterChain.java:299)
	at org.apache.mina.common.support.AbstractIoFilterChain.access$1100(AbstractIoFilterChain.java:53)
	at org.apache.mina.common.support.AbstractIoFilterChain$EntryImpl$1.messageReceived(AbstractIoFilterChain.java:648)
	at org.apache.mina.filter.executor.ExecutorFilter.processEvent(ExecutorFilter.java:220)
	at org.apache.mina.filter.executor.ExecutorFilter$ProcessEventsRunnable.run(ExecutorFilter.java:264)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at org.apache.mina.util.NamePreservingRunnable.run(NamePreservingRunnable.java:51)
	at java.lang.Thread.run(Unknown Source)
@Fraysa
Still doesn't work, the account info isn't getting stored for some reason and I can't login.

@Kaitodomoto
Thanks. The only things I'm missing from your pack is the broadcastMsg packet and the LOGIN_RESPONSE Send Packet Op.
 
Upvote 0
sorry for the late reply
[SendOps]
LOGIN_REPONSE = 0x15

Code:
    public static byte[] broadcastMsg(String message) {
        return OnBroadcastMessage(4, 0, message, false);
    }

    public static byte[] broadcastMsg(int type, String message) {
        return OnBroadcastMessage(type, 0, message, false);
    }

    public static byte[] broadcastMsg(int type, int channel, String message) {
        return OnBroadcastMessage(type, channel, message, false);
    }

    public static byte[] broadcastMsg(int type, int channel, String message, boolean smegaEar) {
        return OnBroadcastMessage(type, channel, message, smegaEar);
    }

    private static byte[] OnBroadcastMessage(int type, int channel, String message, boolean megaEar) {
        MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

        mplew.writeShort(SendPacketOpcode.SERVERMESSAGE.getValue());
        mplew.write(type);
        if (type == 4) {
            mplew.write(1);
        }
        if ((type != 23) && (type != 24)) {
            mplew.writeMapleAsciiString(message);
        }
        switch (type) {
            case 3:
            case 22:
            case 25:
            case 26:
                mplew.write(channel - 1);
                mplew.write(megaEar ? 1 : 0);
                break;
            case 9:
                mplew.write(channel - 1);
                break;
            case 12:
                mplew.writeInt(channel);
                break;
            case 6:
            case 11:
            case 20:
                mplew.writeInt((channel >= 1000000) && (channel < 6000000) ? channel : 0);
                break;
            case 24:
                mplew.writeShort(0);
            case 4:
            case 5:
            case 7:
            case 8:
            case 10:
            case 13:
            case 14:
            case 15:
            case 16:
            case 17:
            case 18:
            case 19:
            case 21:
            case 23:
        }
        return mplew.getPacket();
    }
 
Last edited:
Upvote 0
Why do you need it stored? When are you sending the information exactly? Make sure you're sending it on CLIENT_START.
 
Upvote 0
Back