use of com.zx.sms.codec.sgip12.msg.SgipBindRequestMessage in project SMSGate by Lihuanghe.
the class SgipBindRequestMessageCodec method decode.
@Override
protected void decode(ChannelHandlerContext ctx, Message msg, List<Object> out) throws Exception {
int commandId = msg.getHeader().getCommandId();
if (packetType.getCommandId() != commandId) {
// 不解析,交给下一个codec
out.add(msg);
return;
}
SgipBindRequestMessage requestMessage = new SgipBindRequestMessage(msg.getHeader());
requestMessage.setTimestamp(msg.getTimestamp());
ByteBuf bodyBuffer = Unpooled.wrappedBuffer(msg.getBodyBuffer());
requestMessage.setLoginType(bodyBuffer.readUnsignedByte());
requestMessage.setLoginName(bodyBuffer.readCharSequence(SgipBindRequest.LOGINNAME.getLength(), GlobalConstance.defaultTransportCharset).toString().trim());
requestMessage.setLoginPassowrd(bodyBuffer.readCharSequence(SgipBindRequest.LOGINPASSWD.getLength(), GlobalConstance.defaultTransportCharset).toString().trim());
requestMessage.setReserve(bodyBuffer.readCharSequence(SgipBindRequest.RESERVE.getLength(), GlobalConstance.defaultTransportCharset).toString().trim());
ReferenceCountUtil.release(bodyBuffer);
out.add(requestMessage);
}
use of com.zx.sms.codec.sgip12.msg.SgipBindRequestMessage in project SMSGate by Lihuanghe.
the class SgipSessionLoginManager method doLogin.
@Override
protected void doLogin(Channel ch) {
// 发送bind请求
SgipEndpointEntity sgipentity = (SgipEndpointEntity) entity;
SgipBindRequestMessage bind = createBindRequest(sgipentity);
ch.writeAndFlush(bind);
}
use of com.zx.sms.codec.sgip12.msg.SgipBindRequestMessage in project SMSGate by Lihuanghe.
the class SgipSessionLoginManager method validClientMsg.
@Override
protected int validClientMsg(EndpointEntity entity, Object msg) {
SgipEndpointEntity sgipentity = (SgipEndpointEntity) entity;
SgipBindRequestMessage message = (SgipBindRequestMessage) msg;
if (sgipentity.getLoginName().equals(message.getLoginName()) && sgipentity.getLoginPassowrd().equals(message.getLoginPassowrd())) {
return 0;
} else {
return 1;
}
}
use of com.zx.sms.codec.sgip12.msg.SgipBindRequestMessage in project SMSGate by Lihuanghe.
the class SgipSessionLoginManager method failedLogin.
@Override
protected void failedLogin(ChannelHandlerContext ctx, Object msg, long status) {
if (msg instanceof SgipBindRequestMessage) {
logger.error("Connected error status :{},msg : {}", status, msg);
SgipBindRequestMessage message = (SgipBindRequestMessage) msg;
// 认证失败
SgipBindResponseMessage resp = new SgipBindResponseMessage(((Message) message).getHeader());
resp.setResult((short) status);
resp.setTimestamp(((Message) message).getTimestamp());
ChannelFuture promise = ctx.writeAndFlush(resp);
final ChannelHandlerContext finalctx = ctx;
promise.addListener(new GenericFutureListener() {
public void operationComplete(Future future) throws Exception {
finalctx.close();
}
});
} else {
logger.error("connect msg type error : {}", msg);
ctx.close();
}
}
use of com.zx.sms.codec.sgip12.msg.SgipBindRequestMessage in project SMSGate by Lihuanghe.
the class SgipSessionLoginManager method createBindRequest.
private SgipBindRequestMessage createBindRequest(SgipEndpointEntity entity) {
SgipBindRequestMessage req = new SgipBindRequestMessage();
req.setLoginName(entity.getLoginName());
req.setLoginPassowrd(entity.getLoginPassowrd());
req.getHeader().setNodeId(entity.getNodeId());
/**
* 登录类型。
* 1:SP向SMG建立的连接,用于发送命令
* 2:SMG向SP建立的连接,用于发送命令
* 3:SMG之间建立的连接,用于转发命令
* 4:SMG向GNS建立的连接,用于路由表的检索和维护
* 5:GNS向SMG建立的连接,用于路由表的更新
* 6:主备GNS之间建立的连接,用于主备路由表的一致性
* 11:SP与SMG以及SMG之间建立的测试连接,用于跟踪测试
* 其它:保留
*/
if (entity.getChannelType() == ChannelType.UP) {
req.setLoginType((short) 2);
} else if (entity.getChannelType() == ChannelType.DOWN) {
req.setLoginType((short) 1);
}
return req;
}
Aggregations