楓之谷私服v113/v120 自動註冊

應該一般端口都會有的... 我拿來備份一下

  1. ServerConstants.java上方宣告處多加一條宣告
public static boolean AUTO_REGISTER = true;//自動註冊
  1. LoginServer.java加上兩個函數
public static boolean getAutoReg() {
        return ServerConstants.AUTO_REGISTER;
    }

public static void setAutoReg(boolean x) {
        ServerConstants.AUTO_REGISTER = x;
    }
  1. handling/login/handler新增 AutoRegister.java 內容如下
package handling.login.handler;

import client.LoginCrypto;
import database.DatabaseConnection;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class AutoRegister {

    private static final int ACCOUNTS_PER_IP = 1;
    public static boolean autoRegister = true;
    public static boolean success = false;

    public static boolean getAccountExists(String login) {
        boolean accountExists = false;
        Connection con = DatabaseConnection.getConnection();
        try {
            PreparedStatement ps = con.prepareStatement("SELECT name FROM accounts WHERE name = ?");
            ps.setString(1, login);
            ResultSet rs = ps.executeQuery();
            if (rs.first()) {
                accountExists = true;
            }
        } catch (SQLException ex) {
            System.out.println(ex);
        }
        return accountExists;
    }

    public static void createAccount(String login, String pwd, String eip) {
        String sockAddr = eip;
        Connection con;

        try {
            con = DatabaseConnection.getConnection();
        } catch (Exception ex) {
            System.out.println(ex);
            return;
        }

        try {
            ResultSet rs;
            PreparedStatement ipc = con.prepareStatement("SELECT SessionIP FROM accounts WHERE SessionIP = ?");

            ipc.setString(1, sockAddr.substring(1, sockAddr.lastIndexOf(':')));
            rs = ipc.executeQuery();
            if ((rs.first() == false || rs.last() == true) && rs.getRow() < ACCOUNTS_PER_IP) {

                PreparedStatement ps = con.prepareStatement("INSERT INTO accounts (name, password, email, birthday, macs, SessionIP) VALUES (?, ?, ?, ?, ?, ?)");/*) {*/

                ps.setString(1, login);
                ps.setString(2, LoginCrypto.hexSha1(pwd));
                ps.setString(3, "autoregister@mail.com");
                ps.setString(4, "2008-04-07");
                ps.setString(5, "00-00-00-00-00-00");
                ps.setString(6, sockAddr.substring(1, sockAddr.lastIndexOf(':')));
                ps.executeUpdate();
            }

            success = true;
        } catch (SQLException ex) {
            System.out.println(ex);
            return;
        }
        /*                }
         }
         rs.close();
         } catch (SQLException ex) {
         System.out.println(ex);
         }*/
    }
}

  1. handling/login/handler/CharLoginHandler.java
    搜索
final boolean macBan = c.hasBannedMac();

在它底下加上

int loginok = 0;
if (Boolean.parseBoolean(ServerProperties.getProperty("tms.AutoRegister"))) {

            if (AutoRegister.autoRegister && !AutoRegister.getAccountExists(login) && (!c.hasBannedIP() || !c.hasBannedMac())) {
                if (pwd.equalsIgnoreCase("disconnect") || pwd.equalsIgnoreCase("fixme")) {
                    c.getSession().write(MaplePacketCreator.serverNotice(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(MaplePacketCreator.serverNotice(1, "帳號創建成功,請重新登入!"));
//                    c.getSession().write(LoginPacket.getLoginFailed(1)); //Shows no message, used for unstuck the login button
//                    return;
                }
            }
        }