BetaStory V75
Would you like to react to this message? Create an account in a few clicks or log in to continue.

My pserver Prob

2 posters

Go down

My pserver Prob Empty My pserver Prob

Post by Frosti Mon Mar 22, 2010 9:26 pm

Code:
package net.sf.odinms.client;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.ResultSet;
import net.sf.odinms.database.DatabaseConnection;

public class AutoRegister {

    private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(MapleClient.class);
    private static final int ACCOUNTS_PER_IP = 5;
    public static final boolean autoRegister = false;
    public static boolean success;

    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 (Exception 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) {
            log.error("ERROR", ex);
            return;
        }
        try {
            PreparedStatement ipc = con.prepareStatement("SELECT lastknownip FROM accounts WHERE lastknownip = ?");
            ipc.setString(1, sockAddr.substring(1, sockAddr.lastIndexOf(':')));
            ResultSet rs = ipc.executeQuery();
            if (rs.first() == false || rs.last() == true && rs.getRow() < ACCOUNTS_PER_IP) {
                try {
                    PreparedStatement ps = con.prepareStatement("INSERT INTO accounts (name, password, email, birthday, macs, lastknownip) VALUES (?, ?, ?, ?, ?, ?)");
                    ps.setString(1, login);
                    ps.setString(2, LoginCrypto.hexSha1(pwd));
                    ps.setString(3, "no@email.provided");
                    ps.setString(4, "0000-00-00");
                    ps.setString(5, "00-00-00-00-00-00");
                    ps.setString(6, sockAddr.substring(1, sockAddr.lastIndexOf(':')));
                    ps.executeUpdate();
                    ps.close();
                    success = true;
                } catch (SQLException ex) {
                    log.error("ERROR", ex);
                    return;
                }
            }
            ipc.close();
            rs.close();
        } catch (SQLException ex) {
        }
    }
}

Please Help
Frosti
Frosti
Gamemaster
Gamemaster

Posts : 38
Reputation : 0
Join date : 2010-01-25
Age : 30

Back to top Go down

My pserver Prob Empty Re: My pserver Prob

Post by Stealth Mon Mar 22, 2010 9:33 pm

Change

(name, password, email, birthday, macs, lastknownip) VALUES (?, ?, ?, ?, ?, ?)
To

(name, password, email, birthday, lastknownip) VALUES (?, ?, ?, ?, ?)
And change

ps.setString(5, "00-00-00-00-00-00");
ps.setString(6, sockAddr.substring(1, sockAddr.lastIndexOf(':')));
To

ps.setString(5, sockAddr.substring(1, sockAddr.lastIndexOf(':')));
Stealth
Stealth
Admin
Admin

Posts : 262
Reputation : 14
Join date : 2010-01-21
Age : 31
Location : Canada, Alberta

Back to top Go down

My pserver Prob Empty Re: My pserver Prob

Post by Frosti Mon Mar 22, 2010 9:34 pm

ok thanks Awesome Face
Frosti
Frosti
Gamemaster
Gamemaster

Posts : 38
Reputation : 0
Join date : 2010-01-25
Age : 30

Back to top Go down

My pserver Prob Empty Re: My pserver Prob

Post by Sponsored content


Sponsored content


Back to top Go down

Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum