Excellzone

Forum and disscussions since 2010


You are not connected. Please login or register

View previous topic View next topic Go down Message [Page 1 of 1]

#1
Excell

avatar
Head Administer
Head Administer
For those who wants the autoregister for v75

LoginServer.java
add
Code:
private boolean AutoReg;
private byte AutoRegLimit;

above
Code:
private static LoginServer instance = new LoginServer();

and 2 times
Code:

AutoReg = Boolean.parseBoolean(prop.getProperty("net.sf.odinms.world.AutoRegister", "false"));
AutoRegLimit = Byte.parseByte(prop.getProperty("net.sf.odinms.login.AutoRegisterLimit", "5"));

above
Code:
try {
fileReader = new FileReader("subnet.properties");

add
Code:
public boolean AutoRegister() {
return AutoReg;
}

public byte AutoRegLimit() {
return AutoRegLimit;
}

under
Code:
public Map<Integer, Integer> getLoad() {
return load;
}

save / open LoginPasswordHandler.java

and replace your code with this one
Code:
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation. You may not use, modify
or distribute this program under any other version of the
GNU Affero General Public License.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package net.sf.odinms.net.login.handler;

import net.sf.odinms.client.MapleCharacter;
import net.sf.odinms.client.MapleClient;
import net.sf.odinms.net.MaplePacketHandler;
import net.sf.odinms.net.login.LoginWorker;
import net.sf.odinms.server.AutoRegister;
import net.sf.odinms.tools.MaplePacketCreator;
import net.sf.odinms.tools.data.input.SeekableLittleEndianAccessor;
import net.sf.odinms.tools.KoreanDateUtil;
import java.util.Calendar;
import net.sf.odinms.net.login.LoginServer;

public class LoginPasswordHandler implements MaplePacketHandler {
// private static Logger log = LoggerFactory.getLogger(LoginPasswordHandler.class);
@Override
public boolean validateState(MapleClient c) {
return !c.isLoggedIn();
}

@Override
public void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
String login = slea.readMapleAsciiString();
String pwd = slea.readMapleAsciiString();
c.setAccountName(login);
int loginok = 0;
boolean ipBan = c.hasBannedIP();
boolean macBan = c.hasBannedMac();
if (AutoRegister.getAccountExists(login)) {
loginok = c.login(login, pwd, ipBan || macBan);
} else if (LoginServer.getInstance().AutoRegister() && (!ipBan || !macBan)) {
AutoRegister.createAccount(login, pwd, c.getSession().getRemoteAddress().toString());
if (AutoRegister.success) {
loginok = c.login(login, pwd, ipBan || macBan);
}
} else loginok = c.login(login, pwd, ipBan || macBan);
Calendar tempbannedTill = c.getTempBanCalendar();
if (loginok == 0 && (ipBan || macBan)) {
loginok = 3;
if (macBan) {
String[] ipSplit = c.getSession().getRemoteAddress().toString().split(":");
MapleCharacter.ban(ipSplit[0], "Enforcing account ban, account " + login, false);
}
}
if (loginok == 3) {
c.getSession().write(MaplePacketCreator.getPermBan(c.getBanReason()));
return;
} else if (loginok != 0) {
c.getSession().write(MaplePacketCreator.getLoginFailed(loginok));
return;
} else if (tempbannedTill.getTimeInMillis() != 0) {
long tempban = KoreanDateUtil.getTempBanTimestamp(tempbannedTill.getTimeInMillis());
byte reason = c.getBanReason();
c.getSession().write(MaplePacketCreator.getTempBan(tempban, reason));
return;
}
if (c.isGm()) {
LoginWorker.getInstance().registerGMClient(c);
} else {
LoginWorker.getInstance().registerClient(c);
}
}
}

save / Add AutoRegister.java

Code:
package net.sf.odinms.server;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import net.sf.odinms.client.LoginCrypto;
import net.sf.odinms.client.MapleClient;
import net.sf.odinms.net.login.LoginServer;
import net.sf.odinms.database.DatabaseConnection;

public class AutoRegister {

public static boolean success;
private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(MapleClient.class);

public static boolean getAccountExists(String login) {
boolean accountExists = false;
try {
Connection con = DatabaseConnection.getConnection();
String sql = "SELECT name FROM accounts WHERE name = ?";
PreparedStatement ps = con.prepareStatement(sql);
ps.setString(1, login);
ResultSet rs = ps.executeQuery();
if (rs.first()) {
accountExists = true;
}
rs.close();
ps.close();
} catch (Exception ex) {
log.warn("OdinTeh: Error acquiring the account of (" + login + ") check AutoRegister.");
}
return accountExists;
}

public static void createAccount(String login, String pwd, String eip) {
try {
PreparedStatement ipq = DatabaseConnection.getConnection().prepareStatement("SELECT lastknownip FROM accounts WHERE lastknownip = ?");
ipq.setString(1, eip.substring(1, eip.lastIndexOf(':')));
ResultSet rs = ipq.executeQuery();
if (!rs.first() || rs.last() && rs.getRow() < LoginServer.getInstance().AutoRegLimit()) {
try {
PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("INSERT INTO accounts (name, password, email, birthday, macs, lastknownip) VALUES (?, ?, ?, ?, ?, ?)");
ps.setString(1, login);
ps.setString(2, LoginCrypto.hexShaOne(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, eip.substring(1, eip.lastIndexOf(':')));
ps.executeUpdate();
ps.close();
success = true;
} catch (Exception ex) {
log.warn("OdinTeh: Error creating the account of (" + login + " | " + pwd + " | " + eip + ").");
ipq.close();
rs.close();
return;
}
}
ipq.close();
rs.close();
} catch (Exception ex) {
log.warn("OdinTeh: Error creating " + login + "'s account.");
}
}
}

save / then replace LoginCrypto.java

Code:
/*
* This file is part of the OdinMS Maple Story Server Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc> Matthias Butz
* <matze@odinms.de> Jan Christian Meyer <vimes@odinms.de>
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General
* Public License version 3 as published by the Free Software Foundation. You may not use, modify or distribute this
* program under any other version of the GNU Affero General Public License.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along with this program. If not, see
* <http://www.gnu.org/licenses/>.
*/

package net.sf.odinms.client;

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Random;
import net.sf.odinms.tools.HexTool;

public class LoginCrypto {

private LoginCrypto() {
}

private static String toSimpleHexString(byte[] bytes) {
return HexTool.toString(bytes).replace(" ", "").toLowerCase();
}

private static String hashWithDigest(String in, String digest) {
try {
MessageDigest Digester = MessageDigest.getInstance(digest);
Digester.update(in.getBytes("UTF-8"), 0, in.length());
byte[] sha1Hash = Digester.digest();
return toSimpleHexString(sha1Hash);
} catch (NoSuchAlgorithmException ex) {
throw new RuntimeException("Hashing the password failed", ex);
} catch (UnsupportedEncodingException e) {
throw new RuntimeException("Encoding the string failed", e);
}

}

public static String hexShaOne(String in) {
return hashWithDigest(in, "SHA-1");
}

private static String hexSha1(String in) {
return hashWithDigest(in, "SHA-1");
}

private static String hexSha512(String in) {
return hashWithDigest(in, "SHA-512");
}

public static boolean checkSha1Hash(String hash, String password) {
return hash.equals(hexSha1(password));
}

public static boolean checkSaltedSha512Hash(String hash, String password, String salt) {
return hash.equals(makeSaltedSha512Hash(password, salt));
}

public static String makeSaltedSha512Hash(String password, String salt) {
return hexSha512(password + salt);
}

public static String makeSalt() {
byte[] salt = new byte[16];
new Random().nextBytes(salt);
return toSimpleHexString(salt);
}
}

save / open world.properties
add some under

Code:
# AutoRegister. [ True = On OR False = Off ]
# Default (false)
net.sf.odinms.world.AutoRegister=True

# AutoRegister Limit Per IP.
# Default (5)
net.sf.odinms.login.AutoRegisterLimit=5

View user profile http://excellzone.mrforum.net

View previous topic View next topic Back to top Message [Page 1 of 1]


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