Когда клиент запрашивает авторизацию (4game)
[SRC="java"]/*
* Java Server Emulator Project Blackout / PointBlank
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Authors: DarkSkeleton, sjke, Felixx
* Copyright © 2013 PBDevâ„¢
*/
package ru.pb.auth.network.client.packets.client;
import ru.pb.auth.controller.AccountController;
import ru.pb.auth.network.client.packets.ClientPacket;
import ru.pb.auth.network.client.packets.server.SM_LOGIN_AUTH;
import ru.pb.auth.network.client.packets.server.SM_UNK_545;
import ru.pb.global.dao.impl.MissionDaoImpl;
import ru.pb.global.enums.LoginAccess;
import ru.pb.global.enums.State;
import ru.pb.global.utils.NetworkUtil;
/**
* �Ÿ�°�º�µÑ‚ �»�¾�³�¸�½�° �¾Ñ‚ �º�»�¸�µ�½Ñ‚�°
*
* @author sjke
*/
public class CM_LOGIN extends ClientPacket {
private String login, password;
private int loginLength, passwordLength;
public CM_LOGIN(int opcode) {
super(opcode);
}
private int error;
@Override
public void readImpl() {
/*//readC();
//readH();
//error = readH();
//readC();
loginLength = readC();
passwordLength = readC();
login = readS(loginLength).trim();
password = readS(passwordLength).trim();
getConnection().setMac(NetworkUtil.parseMac(readB(6)));
//readH();
//readC();
//readB(4);
//readQ();
//readB(32);*/
readH();
readC();
readB(5);
loginLength = readC();
passwordLength = readC();
login = readS(loginLength);
password = readS(passwordLength);
getConnection().setMac(NetworkUtil.parseMac(readB(6)));
readH();
readC();
}
@Override
public void runImpl()
{
State state = getConnection().getAccount() == null ? AccountController.getInstance().accountLogin(login, password,getConnection()) : State.AUTHED;
switch (state)
{
case INVALID:
{
sendPacket(new SM_LOGIN_AUTH(LoginAccess.EVENT_ERROR_LOGIN, getConnection().getAccount()));
break;
}
case BLOCKED: {
sendPacket(new SM_LOGIN_AUTH(LoginAccess.EVENT_ERROR_EVENT_LOG_IN_BLOCK_ACCOUNT, getConnection().getAccount()));
break;
}
case IP_BLOCKED: {
sendPacket(new SM_LOGIN_AUTH(LoginAccess.EVENT_ERROR_EVENT_LOG_IN_TIME_OUT2, getConnection().getAccount()));
break;
}
case ERROR_AUTH: {
sendPacket(new SM_LOGIN_AUTH(LoginAccess.EVENT_ERROR_EVENT_LOG_IN_INVALID_ACCOUNT, getConnection().getAccount()));
break;
}
case ALREADY_EXIST: {
sendPacket(new SM_LOGIN_AUTH(LoginAccess.EVENT_ERROR_EVENT_LOG_IN_ALEADY_LOGIN, getConnection().getAccount()));
break;
}
case REGION_BLOCKED: {
sendPacket(new SM_LOGIN_AUTH(LoginAccess.EVENT_ERROR_EVENT_LOG_IN_REGION_BLOCKED, getConnection().getAccount()));
break;
}
case AUTHED:
{
MissionDaoImpl.getInstance().updateDB("accounts", "mac", getConnection().getMac(), "id", String.valueOf(getConnection().getAccount().getId()), null, null);
sendPacket(new SM_LOGIN_AUTH(LoginAccess.EVENT_ERROR_SUCCESS, getConnection().getAccount()));
MissionDaoImpl.getInstance().updateDB("accounts", "ip", getConnection().getIp(), "id", String.valueOf(getConnection().getAccount().getId()), null, null);
break;
}
}
sendPacket(new SM_UNK_545());
}
}
[/SRC]
[SRC="java"]/*
* Java Server Emulator Project Blackout / PointBlank
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Authors: DarkSkeleton, sjke, Felixx
* Copyright © 2013 PBDevâ„¢
*/
package ru.pb.auth.network.client.packets.client;
import ru.pb.auth.controller.AccountController;
import ru.pb.auth.network.client.packets.ClientPacket;
import ru.pb.auth.network.client.packets.server.SM_LOGIN_AUTH;
import ru.pb.auth.network.client.packets.server.SM_UNK_545;
import ru.pb.global.dao.impl.MissionDaoImpl;
import ru.pb.global.enums.LoginAccess;
import ru.pb.global.enums.State;
import ru.pb.global.utils.NetworkUtil;
/**
* �Ÿ�°�º�µÑ‚ �»�¾�³�¸�½�° �¾Ñ‚ �º�»�¸�µ�½Ñ‚�°
*
* @author sjke
*/
public class CM_LOGIN extends ClientPacket {
private String login, password;
private int loginLength, passwordLength;
public CM_LOGIN(int opcode) {
super(opcode);
}
private int error;
@Override
public void readImpl() {
/*//readC();
//readH();
//error = readH();
//readC();
loginLength = readC();
passwordLength = readC();
login = readS(loginLength).trim();
password = readS(passwordLength).trim();
getConnection().setMac(NetworkUtil.parseMac(readB(6)));
//readH();
//readC();
//readB(4);
//readQ();
//readB(32);*/
readH();
readC();
readB(5);
loginLength = readC();
passwordLength = readC();
login = readS(loginLength);
password = readS(passwordLength);
getConnection().setMac(NetworkUtil.parseMac(readB(6)));
readH();
readC();
}
@Override
public void runImpl()
{
State state = getConnection().getAccount() == null ? AccountController.getInstance().accountLogin(login, password,getConnection()) : State.AUTHED;
switch (state)
{
case INVALID:
{
sendPacket(new SM_LOGIN_AUTH(LoginAccess.EVENT_ERROR_LOGIN, getConnection().getAccount()));
break;
}
case BLOCKED: {
sendPacket(new SM_LOGIN_AUTH(LoginAccess.EVENT_ERROR_EVENT_LOG_IN_BLOCK_ACCOUNT, getConnection().getAccount()));
break;
}
case IP_BLOCKED: {
sendPacket(new SM_LOGIN_AUTH(LoginAccess.EVENT_ERROR_EVENT_LOG_IN_TIME_OUT2, getConnection().getAccount()));
break;
}
case ERROR_AUTH: {
sendPacket(new SM_LOGIN_AUTH(LoginAccess.EVENT_ERROR_EVENT_LOG_IN_INVALID_ACCOUNT, getConnection().getAccount()));
break;
}
case ALREADY_EXIST: {
sendPacket(new SM_LOGIN_AUTH(LoginAccess.EVENT_ERROR_EVENT_LOG_IN_ALEADY_LOGIN, getConnection().getAccount()));
break;
}
case REGION_BLOCKED: {
sendPacket(new SM_LOGIN_AUTH(LoginAccess.EVENT_ERROR_EVENT_LOG_IN_REGION_BLOCKED, getConnection().getAccount()));
break;
}
case AUTHED:
{
MissionDaoImpl.getInstance().updateDB("accounts", "mac", getConnection().getMac(), "id", String.valueOf(getConnection().getAccount().getId()), null, null);
sendPacket(new SM_LOGIN_AUTH(LoginAccess.EVENT_ERROR_SUCCESS, getConnection().getAccount()));
MissionDaoImpl.getInstance().updateDB("accounts", "ip", getConnection().getIp(), "id", String.valueOf(getConnection().getAccount().getId()), null, null);
break;
}
}
sendPacket(new SM_UNK_545());
}
}
[/SRC]
PHP код:
<?php
[Info] Missing S for: [C] 0xA03 CM_LOGIN
java.lang.IndexOutOfBoundsException: readerIndex(119) + length(110) exceeds writerIndex(155): UnpooledHeapByteBuf(ridx: 119, widx: 155, cap: 155)
at io.netty.buffer.AbstractByteBuf.checkReadableBytes(AbstractByteBuf.java:1161)
at io.netty.buffer.AbstractByteBuf.readBytes(AbstractByteBuf.java:669)
at io.netty.buffer.AbstractByteBuf.readBytes(AbstractByteBuf.java:677)
at io.netty.buffer.SwappedByteBuf.readBytes(SwappedByteBuf.java:523)
at ru.pb.global.network.packets.BaseClientPacket.readS(BaseClientPacket.java:132)
at ru.pb.auth.network.client.packets.client.CM_LOGIN.readImpl(CM_LOGIN.java:68)
at ru.pb.global.network.packets.BaseClientPacket.read(BaseClientPacket.java:42)
at ru.pb.auth.network.client.ClientConnection.read(ClientConnection.java:116)
at ru.pb.auth.network.client.ClientConnection.decode(ClientConnection.java:83)
at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:226)
at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:139)
at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:338)
at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:324)
at io.netty.handler.logging.LoggingHandler.channelRead(LoggingHandler.java:297)
at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:338)
at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:324)
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:785)
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:126)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:485)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:452)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:346)
at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:101)
at java.lang.Thread.run(Unknown Source)
[Info] Account: admin Хї
- contains bad symbols or bad length.[Check the contents of login & password]
[Info] Client [id:1, ip: 213.191.10.45] sending packet: [S] 0xA04 SM_LOGIN_AUTH; capacity: 4; writable: 4
[Info] Client [id:1, ip: 213.191.10.45] sending packet: [S] 0xA04 SM_UNK_545; capacity: 4; writable: 4
[Info] Client [id:1, ip: 213.191.10.45] sending packet: [S] 0xA77 SM_UNK_2678; capacity: 4; writable: 4
[Info] Client [id:1, ip: 213.191.10.45] will be disconnected
[Info] Client [id:1, ip: 213.191.10.45] disconnected
Добавлено через 2 минуты
[SRC="java"]/*
* Java Server Emulator Project Blackout / PointBlank
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Authors: DarkSkeleton, sjke, Felixx
* Copyright © 2013 PBDev™
*/
package ru.pb.global.network.packets;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Базовый пкет клиента
*
* @author sjke
*/
public abstract class BaseClientPacket<P extends BaseClientPacket, T extends Connection> extends BasePacket implements Cloneable, Runnable {
private static final Logger log = LoggerFactory.getLogger(BaseClientPacket.class);
private T client;
protected BaseClientPacket(int opcode) {
super(PacketType.CLIENT, opcode);
}
public final boolean read() {
try {
readImpl();
return true;
} catch (Exception re) {
log.error("Reading failed for packet " + this, re);
return false;
}
}
protected abstract void readImpl();
protected abstract void runImpl();
public final T getConnection() {
return client;
}
public void setConnection(T client) {
this.client = client;
}
public final int getRemainingBytes() {
return getBuf().readableBytes();
}
protected final int readD() {
try {
return getBuf().readInt();
} catch (Exception e) {
log.error("Missing D for: " + this);
}
return 0;
}
protected final int readC() {
try {
return getBuf().readByte() & 0xFF;
} catch (Exception e) {
log.error("Missing C for: " + this);
}
return 0;
}
protected final boolean readBool() {
try {
return getBuf().readInt() == 1;
} catch (Exception e) {
log.error("Missing Bool for: " + this);
}
return false;
}
protected final int readH() {
try {
return getBuf().readShort() & 0xFFFF;
} catch (Exception e) {
log.error("Missing H for: " + this);
}
return 0;
}
protected final double readDF() {
try {
return getBuf().readDouble();
} catch (Exception e) {
log.error("Missing DF for: " + this);
}
return 0;
}
protected final float readF() {
try {
return getBuf().readFloat();
} catch (Exception e) {
log.error("Missing F for: " + this);
}
return 0;
}
protected final long readQ() {
try {
return getBuf().readLong();
} catch (Exception e) {
log.error("Missing Q for: " + this);
}
return 0;
}
protected String readS(int size) {
try {
byte[] data = new byte[size];
getBuf().readBytes(data);
return new String(data, "windows-1251");
} catch (Exception e) {
log.error("Missing S for: " + this);
e.printStackTrace();
}
return "";
}
protected final byte[] readB(int length) {
byte[] result = new byte[length];
try {
getBuf().readBytes(result);
} catch (Exception e) {
log.error("Missing byte[] for: " + this);
}
return result;
}
protected final byte readB() {
try {
return getBuf().readByte();
} catch (Exception e) {
log.error("Missing byte[] for: " + this);
}
return -1;
}
public abstract P clonePacket();
}
[/SRC]