출처: ww.자바.kr
안녕하세요. JST금빛 입니다.
본 컨넥터 소스에 대한 모든 저작권은 JST금빛 에게 있습니다.
무료 배포 및 수정은 가능하지만 영리적 목적으로 판매하는 것을 엄격히 금지 합니다.
다른 사이트나 카페로 퍼가시는 분들은 반드시 출처 및 본 사이트의 주소(
www.자바.kr) 를 함께 기재해주시기 바랍니다.
이번 3편에서는 이제 운영하고 계시는 서버팩과 컨넥터가 잘 호환되도록 하는 파일과 소스코드들을 추가해보겠습니다.
먼저 아래 링크에서 파일을 다운받으시고 압축을 풀어주세요.
그럼 4개의 java 파일이 나올건데요, 우선 본인 서버팩에 적당한 패키지 하나를 만들어주시고 그 안에 드래그해서 넣어주세요.
자, 그럼 이제 에러가 나올텐데요, 지금부터 잘 따라오시면 됩니다. 거의 다 왔으니 힘내세요^^
먼저 컨넥터에서 계정로그인하는 부분을 별도 로그인서버가 담당할텐데요,
제가 이렇게 설계한 이유는요 차후에 강의글에서 길게 한번 설명드리기로 하고 일단 잘 작동하게 하는데 집중하겠습니다.
이 별도로 만든 로그인서버는 Netty 4.0 버전대 라이브러리를 사용합니다.
그래서 아래 링크에서 Netty 라이브러리 파일을 다운받으신 뒤, lib 폴더 아시죠? 그 안에 넣어주세요.
그런 다음에 우리가 1편에서 라이브러리를 프로젝트에 불러왔던 방식과 같은 방식으로 추가해주시면 됩니다.
그런다음, 아래 내용들을 잘 보시고 팩에 잘 이식해주세요.
저희 JST는 일팩을 기반으로 코드를 작성하기 때문에 에바팩과 메서드명이나 클래스명이 다를 수 있습니다.
하지만 쓰임세는 비슷하니 각자 알맞게 수정하셔서 사용해주세요. (차후에 에바팩 코드를 따로 올려드리겠습니다. 지금 시간이 없어서...)
필드명 : approved 타입 : tinyint 새로생성
--------------------------------------------------
<entry key="jstconnector">true</entry>
<entry key="jstconnectorport">6000</entry>
<entry key="cipher">true</entry>
<entry key="sameIpCreatAccountLimit">3</entry>
<entry key="sameIpAccessAccountLimit">3</entry>
--------------------------------------------------
@Configure(file = SERVER, key = "jstconnector")
public static boolean JST_CONNECTOR = false;
@Configure(file = SERVER, key = "jstconnectorport")
public static int JST_CONNECTOR_PORT = 6000;
@Configure(file = SERVER, key = "cipher")
public static boolean JST_CIPHER = true;
@Configure(file = SERVER, key = "sameIpCreatAccountLimit")
public static int SAME_IP_CREAT_ACCOUNT_LIMIT = 3;
@Configure(file = SERVER, key = "sameIpAccessAccountLimit")
public static int SAME_IP_ACCESS_ACCOUNT_LIMIT = 3;
--------------------------------------------------
private boolean _isApproved;
public boolean isApproved() { return _isApproved; }
public static void updateApproved(final String name, boolean f) {
L1QueryUtil.execute("UPDATE accounts SET approved=? WHERE name=?", f, name);
}
private static class Factory implements EntityFactory<L1Account> {
@Override
public L1Account fromResultSet(ResultSet rs) throws SQLException {
L1Account result = new L1Account();
result._id = rs.getInt("id");
result._name = rs.getString("name");
result._password = rs.getString("password");
result._accessLevel = rs.getInt("access_level");
result._characterSlot = rs.getInt("character_slot");
result._lastActivatedAt = rs.getTimestamp("last_activated_at");
result._ip = rs.getString("ip");
result._host = rs.getString("host");
result._isActive = rs.getBoolean("is_active");
result._isApproved = rs.getBoolean("approved"); // 추가
return result;
}
}
public static L1Account create(int id, final String name, final String rawPassword, final String ip, final String host) {
String password = encodePassword(rawPassword);
Timestamp currentTime = new Timestamp(System.currentTimeMillis());
String sql = "INSERT INTO accounts SET id=?, name=?, password=?, access_level=?, character_slot=?, last_activated_at=?, ip=?, host=?,
is_active=?, approved=?"; // approved=? 추가
L1QueryUtil.execute(sql, id, name, password, 0, 0, currentTime, ip, host, true, true); // 맨 마지막에 true 추가
return findById(id);
}
public static int creatCountByIp(String ip) {
return L1QueryUtil.selectAll(new Factory(), "SELECT * FROM accounts WHERE ip=?", ip).size();
}
--------------------------------------------------
L1Account account = L1Account.findByName(accountName); // 검색
// 상위 부분에 추가
if (accountLength > 12 || passwordLength > 12 || accountLength < 6 || passwordLength < 6) {
client.close();
return;
}
String ip = client.getIp(); // 이걸 찾아서 그 아랫부분에 아래 구문 추가
if (!ip.equals("127.0.0.1")) { // 아이피당 최대 클라접속 허용 체크
int creatCount = L1Account.creatCountByIp(ip);
if (creatCount >= Config.SAME_IP_ACCESS_ACCOUNT_LIMIT) {
client.kick();
return;
}
}
if (!Config.JST_CONNECTOR && account == null) { // 주황색 표기부분 추가. 앞에 ! 기호 잘 확인해주세요.
if (Config.AUTO_CREATE_ACCOUNTS) {
account = L1Account.create(accountName, password, ip, host);
} else {
Log.error("account missing for user " + accountName);
}
}
if (!account.isApproved()) { // 바로 밑에 부분에 추가
client.close();
return;
}
--------------------------------------------------
Server.java 혹은 GameServer.java 에서 아래 구문 적당한 위치에 추가.
AccountInspectServer.getInstance(); // 컨넥터 계정인증 서버 오픈
--------------------------------------------------
public static final int REASON_LOGIN_OK_CONNECTOR = 0x01;
public static final int REASON_CREAT_ACCOUNT = 0x02;
public static final int REASON_ACCOUNT_IN_USE = 0x16;
public static final int REASON_ACCOUNT_CREAT_FAIL = 0x17;
--------------------------------------------------
close() 메서드 안에 아래 추가
L1Account.updateApproved(getAccountName(), false);
--------------------------------------------------
LineageClient.java 혹은 다른 파일이 될 수도 있습니다. (팩마다 많이 다르죠?)
// 복호화 하는 부분에 아래 구문을 보시고 각자 알맞게 수정해주세요.
if (Config.JST_CIPHER) data = packet;
else data = cipher.decryptBlowfish(packet);
// 암호화 하는 부분에 아래 구문을 보시고 각자 알맞게 수정해주세요.
if (Config.JST_CIPHER) data = array;
else data = client.getCipher().encryptHash(array);
--------------------------------------------------
아마 일팩코드라서 햇갈리시는 분들이 많이 계실 것 같은데요,
에바팩의 코드로 (공개된 감x팩 사용) 곧 추가로 올려드리겠습니다.