v83 moopledev AutoRegister
:: 各種フォーム :: MapleプログラムReleases
Page 1 of 1
v83 moopledev AutoRegister
src.client
に
AutoRegister.java
を作成
を追加
LoginPasswordHandler.java
を作成
を追加
SQL
に
AutoRegister.java
を作成
- Code:
package client;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.ResultSet;
import tools.DatabaseConnection;
public class AutoRegister {
private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(MapleClient.class);
private static final int ACCOUNTS_PER_IP = 3;
public static final boolean autoRegister = true;
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, pwd);//lol, no encryption. in fags we are <3
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) {
log.error("Something bad with autoregister.\r\n" + ex);
}
}
}
を追加
LoginPasswordHandler.java
を作成
- Code:
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick>
Matthias Butz <matze>
Jan Christian Meyer <vimes>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation 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>.
*/
package net.login.handler;
import client.AutoRegister;
import client.MapleCharacter;
import client.MapleClient;
import java.util.Calendar;
import net.MaplePacketHandler;
import net.channel.ChannelServer;
import server.TimerManager;
import tools.DateUtil;
import tools.MaplePacketCreator;
import tools.data.input.SeekableLittleEndianAccessor;
public final class LoginPasswordHandler implements MaplePacketHandler {
public boolean validateState(MapleClient c) {
return !c.isLoggedIn();
}
ChannelServer cserv;
private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(MapleClient.class);
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
int loginok = 0;
String login = slea.readMapleAsciiString();
String pwd = slea.readMapleAsciiString();
c.setAccountName(login);
final boolean isBanned = c.hasBannedIP() || c.hasBannedMac();
boolean ipBan = c.hasBannedIP();
boolean macBan = c.hasBannedMac();
if (AutoRegister.getAccountExists(login)) {
loginok = c.login(login, pwd, ipBan || macBan);
} else if (AutoRegister.success = true && (!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);
if (loginok == 0 && isBanned) {
loginok = 3;
MapleCharacter.ban(c.getSession().getRemoteAddress().toString().split(":")[0], "Mac/IP Re-ban", false);
} else if (loginok != 0) {
c.announce(MaplePacketCreator.getLoginFailed(loginok));
return;
}
if (c.finishLogin() == 0) {
c.announce(MaplePacketCreator.getAuthSuccess(c, c.getAccountName()));
final MapleClient client = c;
c.setIdleTask(TimerManager.getInstance().schedule(new Runnable() {
public void run() {
client.getSession().close(true);
}
}, 600000));
} else {
c.announce(MaplePacketCreator.getLoginFailed(7));
}
}
}
を追加
SQL
- Code:
ALTER TABLE `accounts` ADD COLUMN `lastknownip` VARCHAR(30) NOT NULL DEFAULT '' AFTER `macs`;
ALTER TABLE `accounts` ADD COLUMN `email` VARCHAR(255) NOT NULL DEFAULT '' AFTER `pic`;
:: 各種フォーム :: MapleプログラムReleases
Page 1 of 1
Permissions in this forum:
返信投稿: 不可
|
|