登录命令扩展增加成功与失败的回调方法,用户定制更加灵活

This commit is contained in:
wchao 2018-07-31 10:47:24 +08:00
parent 52cadc63fc
commit 12c81c7d0a
10 changed files with 362 additions and 44 deletions

73
jim-client/jim-client.iml Normal file
View File

@ -0,0 +1,73 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="jim-common" />
<orderEntry type="library" name="Maven: org.t-io:tio-core:2.4.0.v20180508-RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.t-io:tio-utils:2.4.0.v20180508-RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-text:1.3" level="project" />
<orderEntry type="library" name="Maven: cn.hutool:hutool-all:4.0.10" level="project" />
<orderEntry type="library" name="Maven: com.google.guava:guava:23.0" level="project" />
<orderEntry type="library" name="Maven: com.google.code.findbugs:jsr305:1.3.9" level="project" />
<orderEntry type="library" name="Maven: com.google.errorprone:error_prone_annotations:2.0.18" level="project" />
<orderEntry type="library" name="Maven: com.google.j2objc:j2objc-annotations:1.1" level="project" />
<orderEntry type="library" name="Maven: org.codehaus.mojo:animal-sniffer-annotations:1.14" level="project" />
<orderEntry type="library" name="Maven: org.jodd:jodd-core:4.3.2" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-compress:1.14" level="project" />
<orderEntry type="library" name="Maven: org.redisson:redisson:3.7.0" level="project" />
<orderEntry type="library" name="Maven: io.netty:netty-common:4.1.24.Final" level="project" />
<orderEntry type="library" name="Maven: io.netty:netty-codec:4.1.24.Final" level="project" />
<orderEntry type="library" name="Maven: io.netty:netty-buffer:4.1.24.Final" level="project" />
<orderEntry type="library" name="Maven: io.netty:netty-transport:4.1.24.Final" level="project" />
<orderEntry type="library" name="Maven: io.netty:netty-resolver:4.1.24.Final" level="project" />
<orderEntry type="library" name="Maven: io.netty:netty-resolver-dns:4.1.24.Final" level="project" />
<orderEntry type="library" name="Maven: io.netty:netty-codec-dns:4.1.24.Final" level="project" />
<orderEntry type="library" name="Maven: io.netty:netty-handler:4.1.24.Final" level="project" />
<orderEntry type="library" name="Maven: javax.cache:cache-api:1.0.0" level="project" />
<orderEntry type="library" name="Maven: io.projectreactor:reactor-core:3.1.7.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.reactivestreams:reactive-streams:1.0.2" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.25" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.7.9" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.7.9" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.7.9.2" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.7.0" level="project" />
<orderEntry type="library" name="Maven: net.bytebuddy:byte-buddy:1.8.11" level="project" />
<orderEntry type="library" name="Maven: org.jodd:jodd-bean:3.7.1" level="project" />
<orderEntry type="library" name="Maven: nl.basjes.parse.useragent:yauaa:1.4" level="project" />
<orderEntry type="library" name="Maven: args4j:args4j:2.33" level="project" />
<orderEntry type="library" name="Maven: commons-logging:commons-logging:1.2" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-lang3:3.6" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-collections4:4.1" level="project" />
<orderEntry type="library" name="Maven: org.yaml:snakeyaml:1.18" level="project" />
<orderEntry type="library" name="Maven: com.typesafe:config:1.3.1" level="project" />
<orderEntry type="library" name="Maven: commons-io:commons-io:2.5" level="project" />
<orderEntry type="library" name="Maven: commons-codec:commons-codec:1.10" level="project" />
<orderEntry type="library" name="Maven: ch.qos.logback:logback-classic:1.2.3" level="project" />
<orderEntry type="library" name="Maven: ch.qos.logback:logback-core:1.2.3" level="project" />
<orderEntry type="library" name="Maven: ch.qos.logback:logback-access:1.2.3" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:jcl-over-slf4j:1.7.25" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:jul-to-slf4j:1.7.25" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:log4j-over-slf4j:1.7.25" level="project" />
<orderEntry type="library" name="Maven: redis.clients:jedis:2.7.3" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-pool2:2.3" level="project" />
<orderEntry type="library" name="Maven: com.jfinal:jfinal:3.2" level="project" />
<orderEntry type="library" name="Maven: cglib:cglib-nodep:3.2.5" level="project" />
<orderEntry type="library" name="Maven: net.oschina.j2cache:j2cache-core:2.3.21-release" level="project" />
<orderEntry type="library" name="Maven: com.github.ben-manes.caffeine:caffeine:2.6.2" level="project" />
<orderEntry type="library" name="Maven: de.ruedigermoeller:fst:2.57" level="project" />
<orderEntry type="library" name="Maven: org.javassist:javassist:3.21.0-GA" level="project" />
<orderEntry type="library" name="Maven: org.objenesis:objenesis:2.5.1" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:slf4j-simple:1.7.25" level="project" />
<orderEntry type="library" name="Maven: com.alibaba:fastjson:1.2.35" level="project" />
<orderEntry type="library" name="Maven: jline:jline:2.14.2" level="project" />
</component>
</module>

71
jim-common/jim-common.iml Normal file
View File

@ -0,0 +1,71 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Maven: org.t-io:tio-core:2.4.0.v20180508-RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.t-io:tio-utils:2.4.0.v20180508-RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-text:1.3" level="project" />
<orderEntry type="library" name="Maven: cn.hutool:hutool-all:4.0.10" level="project" />
<orderEntry type="library" name="Maven: com.google.guava:guava:23.0" level="project" />
<orderEntry type="library" name="Maven: com.google.code.findbugs:jsr305:1.3.9" level="project" />
<orderEntry type="library" name="Maven: com.google.errorprone:error_prone_annotations:2.0.18" level="project" />
<orderEntry type="library" name="Maven: com.google.j2objc:j2objc-annotations:1.1" level="project" />
<orderEntry type="library" name="Maven: org.codehaus.mojo:animal-sniffer-annotations:1.14" level="project" />
<orderEntry type="library" name="Maven: org.jodd:jodd-core:4.3.2" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-compress:1.14" level="project" />
<orderEntry type="library" name="Maven: org.redisson:redisson:3.7.0" level="project" />
<orderEntry type="library" name="Maven: io.netty:netty-common:4.1.24.Final" level="project" />
<orderEntry type="library" name="Maven: io.netty:netty-codec:4.1.24.Final" level="project" />
<orderEntry type="library" name="Maven: io.netty:netty-buffer:4.1.24.Final" level="project" />
<orderEntry type="library" name="Maven: io.netty:netty-transport:4.1.24.Final" level="project" />
<orderEntry type="library" name="Maven: io.netty:netty-resolver:4.1.24.Final" level="project" />
<orderEntry type="library" name="Maven: io.netty:netty-resolver-dns:4.1.24.Final" level="project" />
<orderEntry type="library" name="Maven: io.netty:netty-codec-dns:4.1.24.Final" level="project" />
<orderEntry type="library" name="Maven: io.netty:netty-handler:4.1.24.Final" level="project" />
<orderEntry type="library" name="Maven: javax.cache:cache-api:1.0.0" level="project" />
<orderEntry type="library" name="Maven: io.projectreactor:reactor-core:3.1.7.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.reactivestreams:reactive-streams:1.0.2" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.25" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.7.9" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.7.9" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.7.9.2" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.7.0" level="project" />
<orderEntry type="library" name="Maven: net.bytebuddy:byte-buddy:1.8.11" level="project" />
<orderEntry type="library" name="Maven: org.jodd:jodd-bean:3.7.1" level="project" />
<orderEntry type="library" name="Maven: nl.basjes.parse.useragent:yauaa:1.4" level="project" />
<orderEntry type="library" name="Maven: args4j:args4j:2.33" level="project" />
<orderEntry type="library" name="Maven: commons-logging:commons-logging:1.2" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-lang3:3.6" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-collections4:4.1" level="project" />
<orderEntry type="library" name="Maven: org.yaml:snakeyaml:1.18" level="project" />
<orderEntry type="library" name="Maven: com.typesafe:config:1.3.1" level="project" />
<orderEntry type="library" name="Maven: commons-io:commons-io:2.5" level="project" />
<orderEntry type="library" name="Maven: commons-codec:commons-codec:1.10" level="project" />
<orderEntry type="library" name="Maven: ch.qos.logback:logback-classic:1.2.3" level="project" />
<orderEntry type="library" name="Maven: ch.qos.logback:logback-core:1.2.3" level="project" />
<orderEntry type="library" name="Maven: ch.qos.logback:logback-access:1.2.3" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:jcl-over-slf4j:1.7.25" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:jul-to-slf4j:1.7.25" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:log4j-over-slf4j:1.7.25" level="project" />
<orderEntry type="library" name="Maven: redis.clients:jedis:2.7.3" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-pool2:2.3" level="project" />
<orderEntry type="library" name="Maven: com.jfinal:jfinal:3.2" level="project" />
<orderEntry type="library" name="Maven: cglib:cglib-nodep:3.2.5" level="project" />
<orderEntry type="library" name="Maven: net.oschina.j2cache:j2cache-core:2.3.21-release" level="project" />
<orderEntry type="library" name="Maven: com.github.ben-manes.caffeine:caffeine:2.6.2" level="project" />
<orderEntry type="library" name="Maven: de.ruedigermoeller:fst:2.57" level="project" />
<orderEntry type="library" name="Maven: org.javassist:javassist:3.21.0-GA" level="project" />
<orderEntry type="library" name="Maven: org.objenesis:objenesis:2.5.1" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:slf4j-simple:1.7.25" level="project" />
<orderEntry type="library" name="Maven: com.alibaba:fastjson:1.2.35" level="project" />
<orderEntry type="library" name="Maven: jline:jline:2.14.2" level="project" />
</component>
</module>

12
jim-parent/jim-parent.iml Normal file
View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_5">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -0,0 +1,78 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="jim-server" />
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpclient:4.0" level="project" />
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpcore:4.0.1" level="project" />
<orderEntry type="library" name="Maven: commons-logging:commons-logging:1.1.1" level="project" />
<orderEntry type="library" name="Maven: commons-codec:commons-codec:1.10" level="project" />
<orderEntry type="module" module-name="jim-common" />
<orderEntry type="library" name="Maven: org.t-io:tio-core:2.4.0.v20180508-RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.t-io:tio-utils:2.4.0.v20180508-RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-text:1.3" level="project" />
<orderEntry type="library" name="Maven: cn.hutool:hutool-all:4.0.10" level="project" />
<orderEntry type="library" name="Maven: com.google.guava:guava:23.0" level="project" />
<orderEntry type="library" name="Maven: com.google.code.findbugs:jsr305:1.3.9" level="project" />
<orderEntry type="library" name="Maven: com.google.errorprone:error_prone_annotations:2.0.18" level="project" />
<orderEntry type="library" name="Maven: com.google.j2objc:j2objc-annotations:1.1" level="project" />
<orderEntry type="library" name="Maven: org.codehaus.mojo:animal-sniffer-annotations:1.14" level="project" />
<orderEntry type="library" name="Maven: org.jodd:jodd-core:4.3.2" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-compress:1.14" level="project" />
<orderEntry type="library" name="Maven: org.redisson:redisson:3.7.0" level="project" />
<orderEntry type="library" name="Maven: io.netty:netty-common:4.1.24.Final" level="project" />
<orderEntry type="library" name="Maven: io.netty:netty-codec:4.1.24.Final" level="project" />
<orderEntry type="library" name="Maven: io.netty:netty-buffer:4.1.24.Final" level="project" />
<orderEntry type="library" name="Maven: io.netty:netty-transport:4.1.24.Final" level="project" />
<orderEntry type="library" name="Maven: io.netty:netty-resolver:4.1.24.Final" level="project" />
<orderEntry type="library" name="Maven: io.netty:netty-resolver-dns:4.1.24.Final" level="project" />
<orderEntry type="library" name="Maven: io.netty:netty-codec-dns:4.1.24.Final" level="project" />
<orderEntry type="library" name="Maven: io.netty:netty-handler:4.1.24.Final" level="project" />
<orderEntry type="library" name="Maven: javax.cache:cache-api:1.0.0" level="project" />
<orderEntry type="library" name="Maven: io.projectreactor:reactor-core:3.1.7.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.reactivestreams:reactive-streams:1.0.2" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.25" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.7.9" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.7.9" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.7.9.2" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.7.0" level="project" />
<orderEntry type="library" name="Maven: net.bytebuddy:byte-buddy:1.8.11" level="project" />
<orderEntry type="library" name="Maven: org.jodd:jodd-bean:3.7.1" level="project" />
<orderEntry type="library" name="Maven: nl.basjes.parse.useragent:yauaa:1.4" level="project" />
<orderEntry type="library" name="Maven: args4j:args4j:2.33" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-lang3:3.6" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-collections4:4.1" level="project" />
<orderEntry type="library" name="Maven: org.yaml:snakeyaml:1.18" level="project" />
<orderEntry type="library" name="Maven: com.typesafe:config:1.3.1" level="project" />
<orderEntry type="library" name="Maven: commons-io:commons-io:2.5" level="project" />
<orderEntry type="library" name="Maven: ch.qos.logback:logback-classic:1.2.3" level="project" />
<orderEntry type="library" name="Maven: ch.qos.logback:logback-core:1.2.3" level="project" />
<orderEntry type="library" name="Maven: ch.qos.logback:logback-access:1.2.3" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:jcl-over-slf4j:1.7.25" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:jul-to-slf4j:1.7.25" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:log4j-over-slf4j:1.7.25" level="project" />
<orderEntry type="library" name="Maven: redis.clients:jedis:2.7.3" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-pool2:2.3" level="project" />
<orderEntry type="library" name="Maven: net.oschina.j2cache:j2cache-core:2.3.21-release" level="project" />
<orderEntry type="library" name="Maven: com.github.ben-manes.caffeine:caffeine:2.6.2" level="project" />
<orderEntry type="library" name="Maven: de.ruedigermoeller:fst:2.57" level="project" />
<orderEntry type="library" name="Maven: org.javassist:javassist:3.21.0-GA" level="project" />
<orderEntry type="library" name="Maven: org.objenesis:objenesis:2.5.1" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:slf4j-simple:1.7.25" level="project" />
<orderEntry type="library" name="Maven: com.alibaba:fastjson:1.2.35" level="project" />
<orderEntry type="library" name="Maven: jline:jline:2.14.2" level="project" />
<orderEntry type="library" name="Maven: io.github.lukehutch:fast-classpath-scanner:2.4.1" level="project" />
<orderEntry type="library" name="Maven: com.thoughtworks.paranamer:paranamer:2.5.2" level="project" />
<orderEntry type="library" name="Maven: com.jfinal:jfinal:3.2" level="project" />
<orderEntry type="library" name="Maven: cglib:cglib-nodep:3.2.5" level="project" />
<orderEntry type="library" name="Maven: org.jsoup:jsoup:1.10.3" level="project" />
</component>
</module>

View File

@ -21,33 +21,20 @@ import org.jim.server.command.handler.processor.handshake.WsHandshakeProcessor;
*
*/
public class DemoWsHandshakeProcessor extends WsHandshakeProcessor{
/**
* WS握手方法返回Null则业务层不同意握手断开连接!
*/
@Override
public ImPacket handshake(ImPacket packet, ChannelContext channelContext) throws Exception {
public void onAfterHandshaked(ImPacket packet, ChannelContext channelContext) throws Exception {
WsRequestPacket wsRequestPacket = (WsRequestPacket) packet;
WsSessionContext wsSessionContext = (WsSessionContext) channelContext.getAttribute();
if (wsRequestPacket.isHandShake()) {
LoginReqHandler loginHandler = (LoginReqHandler)CommandManager.getCommand(Command.COMMAND_LOGIN_REQ);
HttpRequest request = wsSessionContext.getHandshakeRequestPacket();
String username = request.getParams().get("username") == null ? null : (String)request.getParams().get("username")[0];
String password = request.getParams().get("password") == null ? null : (String)request.getParams().get("password")[0];
String token = request.getParams().get("token") == null ? null : (String)request.getParams().get("token")[0];
LoginReqBody loginBody = new LoginReqBody(username,password,token);
byte[] loginBytes = JsonKit.toJsonBytes(loginBody);
request.setBody(loginBytes);
request.setBodyString(new String(loginBytes,HttpConst.CHARSET_NAME));
Object loginResponse = loginHandler.handler(request, channelContext);
if(loginResponse == null)
return null;
WsResponsePacket wsResponsePacket = new WsResponsePacket();
wsResponsePacket.setHandShake(true);
wsResponsePacket.setCommand(Command.COMMAND_HANDSHAKE_RESP);
wsSessionContext.setHandshaked(true);
return wsResponsePacket;
}
return null;
LoginReqHandler loginHandler = (LoginReqHandler)CommandManager.getCommand(Command.COMMAND_LOGIN_REQ);
HttpRequest request = wsSessionContext.getHandshakeRequestPacket();
String username = request.getParams().get("username") == null ? null : (String)request.getParams().get("username")[0];
String password = request.getParams().get("password") == null ? null : (String)request.getParams().get("password")[0];
String token = request.getParams().get("token") == null ? null : (String)request.getParams().get("token")[0];
LoginReqBody loginBody = new LoginReqBody(username,password,token);
byte[] loginBytes = JsonKit.toJsonBytes(loginBody);
request.setBody(loginBytes);
request.setBodyString(new String(loginBytes,HttpConst.CHARSET_NAME));
Object loginResponse = loginHandler.handler(request, channelContext);
}
}

View File

@ -26,23 +26,5 @@ public class ImDemoAioListener extends ImServerAioListener{
@Override
public void onAfterSent(ChannelContext channelContext, Packet packet, boolean isSentSuccess) {
if(packet instanceof ImPacket){
ImPacket imPacket = (ImPacket)packet;
if(imPacket.getCommand() == Command.COMMAND_LOGIN_RESP || imPacket.getCommand() == Command.COMMAND_HANDSHAKE_RESP){//首次登陆;
ImSessionContext imSessionContext = (ImSessionContext)channelContext.getAttribute();
User user = imSessionContext.getClient().getUser();
if(user.getGroups() != null){
for(Group group : user.getGroups()){//发送加入群组通知
ImPacket groupPacket = new ImPacket(Command.COMMAND_JOIN_GROUP_REQ,JsonKit.toJsonBytes(group));
try {
JoinGroupReqHandler joinGroupReqHandler = CommandManager.getCommand(Command.COMMAND_JOIN_GROUP_REQ, JoinGroupReqHandler.class);
joinGroupReqHandler.joinGroupNotify(groupPacket, channelContext);
} catch (Exception e) {
log.error(e.toString(),e);
}
}
}
}
}
}
}

View File

@ -11,7 +11,14 @@ import java.util.UUID;
import org.apache.commons.lang3.StringUtils;
import org.jim.common.Const;
import org.jim.common.ImPacket;
import org.jim.common.ImSessionContext;
import org.jim.common.packets.Command;
import org.jim.common.utils.JsonKit;
import org.jim.server.command.CommandManager;
import org.jim.server.command.handler.JoinGroupReqHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.tio.core.ChannelContext;
import org.jim.common.http.HttpConst;
import org.jim.common.packets.Group;
@ -28,6 +35,8 @@ import cn.hutool.core.util.RandomUtil;
*/
public class LoginServiceProcessor implements LoginProcessorIntf{
private Logger logger = LoggerFactory.getLogger(LoginServiceProcessor.class);
public static final Map<String, User> tokenMap = new HashMap<>();
private static String[] familyName = new String[] { "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
@ -118,7 +127,30 @@ public class LoginServiceProcessor implements LoginProcessorIntf{
}
return this.getUser(loginname, password);
}
@Override
public void onSuccess(ChannelContext channelContext) {
logger.info("登录成功回调方法");
ImSessionContext imSessionContext = (ImSessionContext)channelContext.getAttribute();
User user = imSessionContext.getClient().getUser();
if(user.getGroups() != null){
for(Group group : user.getGroups()){//发送加入群组通知
ImPacket groupPacket = new ImPacket(Command.COMMAND_JOIN_GROUP_REQ,JsonKit.toJsonBytes(group));
try {
JoinGroupReqHandler joinGroupReqHandler = CommandManager.getCommand(Command.COMMAND_JOIN_GROUP_REQ, JoinGroupReqHandler.class);
joinGroupReqHandler.joinGroupNotify(groupPacket, channelContext);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
@Override
public void onFailed(ChannelContext channelContext) {
logger.info("登录失败回调方法");
}
@Override
public boolean isProtocol(ChannelContext channelContext) {

77
jim-server/jim-server.iml Normal file
View File

@ -0,0 +1,77 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpclient:4.0" level="project" />
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpcore:4.0.1" level="project" />
<orderEntry type="library" name="Maven: commons-logging:commons-logging:1.1.1" level="project" />
<orderEntry type="library" name="Maven: commons-codec:commons-codec:1.10" level="project" />
<orderEntry type="module" module-name="jim-common" />
<orderEntry type="library" name="Maven: org.t-io:tio-core:2.4.0.v20180508-RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.t-io:tio-utils:2.4.0.v20180508-RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-text:1.3" level="project" />
<orderEntry type="library" name="Maven: cn.hutool:hutool-all:4.0.10" level="project" />
<orderEntry type="library" name="Maven: com.google.guava:guava:23.0" level="project" />
<orderEntry type="library" name="Maven: com.google.code.findbugs:jsr305:1.3.9" level="project" />
<orderEntry type="library" name="Maven: com.google.errorprone:error_prone_annotations:2.0.18" level="project" />
<orderEntry type="library" name="Maven: com.google.j2objc:j2objc-annotations:1.1" level="project" />
<orderEntry type="library" name="Maven: org.codehaus.mojo:animal-sniffer-annotations:1.14" level="project" />
<orderEntry type="library" name="Maven: org.jodd:jodd-core:4.3.2" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-compress:1.14" level="project" />
<orderEntry type="library" name="Maven: org.redisson:redisson:3.7.0" level="project" />
<orderEntry type="library" name="Maven: io.netty:netty-common:4.1.24.Final" level="project" />
<orderEntry type="library" name="Maven: io.netty:netty-codec:4.1.24.Final" level="project" />
<orderEntry type="library" name="Maven: io.netty:netty-buffer:4.1.24.Final" level="project" />
<orderEntry type="library" name="Maven: io.netty:netty-transport:4.1.24.Final" level="project" />
<orderEntry type="library" name="Maven: io.netty:netty-resolver:4.1.24.Final" level="project" />
<orderEntry type="library" name="Maven: io.netty:netty-resolver-dns:4.1.24.Final" level="project" />
<orderEntry type="library" name="Maven: io.netty:netty-codec-dns:4.1.24.Final" level="project" />
<orderEntry type="library" name="Maven: io.netty:netty-handler:4.1.24.Final" level="project" />
<orderEntry type="library" name="Maven: javax.cache:cache-api:1.0.0" level="project" />
<orderEntry type="library" name="Maven: io.projectreactor:reactor-core:3.1.7.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.reactivestreams:reactive-streams:1.0.2" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.25" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.7.9" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.7.9" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.7.9.2" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.7.0" level="project" />
<orderEntry type="library" name="Maven: net.bytebuddy:byte-buddy:1.8.11" level="project" />
<orderEntry type="library" name="Maven: org.jodd:jodd-bean:3.7.1" level="project" />
<orderEntry type="library" name="Maven: nl.basjes.parse.useragent:yauaa:1.4" level="project" />
<orderEntry type="library" name="Maven: args4j:args4j:2.33" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-lang3:3.6" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-collections4:4.1" level="project" />
<orderEntry type="library" name="Maven: org.yaml:snakeyaml:1.18" level="project" />
<orderEntry type="library" name="Maven: com.typesafe:config:1.3.1" level="project" />
<orderEntry type="library" name="Maven: commons-io:commons-io:2.5" level="project" />
<orderEntry type="library" name="Maven: ch.qos.logback:logback-classic:1.2.3" level="project" />
<orderEntry type="library" name="Maven: ch.qos.logback:logback-core:1.2.3" level="project" />
<orderEntry type="library" name="Maven: ch.qos.logback:logback-access:1.2.3" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:jcl-over-slf4j:1.7.25" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:jul-to-slf4j:1.7.25" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:log4j-over-slf4j:1.7.25" level="project" />
<orderEntry type="library" name="Maven: redis.clients:jedis:2.7.3" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-pool2:2.3" level="project" />
<orderEntry type="library" name="Maven: net.oschina.j2cache:j2cache-core:2.3.21-release" level="project" />
<orderEntry type="library" name="Maven: com.github.ben-manes.caffeine:caffeine:2.6.2" level="project" />
<orderEntry type="library" name="Maven: de.ruedigermoeller:fst:2.57" level="project" />
<orderEntry type="library" name="Maven: org.javassist:javassist:3.21.0-GA" level="project" />
<orderEntry type="library" name="Maven: org.objenesis:objenesis:2.5.1" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:slf4j-simple:1.7.25" level="project" />
<orderEntry type="library" name="Maven: com.alibaba:fastjson:1.2.35" level="project" />
<orderEntry type="library" name="Maven: jline:jline:2.14.2" level="project" />
<orderEntry type="library" name="Maven: io.github.lukehutch:fast-classpath-scanner:2.4.1" level="project" />
<orderEntry type="library" name="Maven: com.thoughtworks.paranamer:paranamer:2.5.2" level="project" />
<orderEntry type="library" name="Maven: com.jfinal:jfinal:3.2" level="project" />
<orderEntry type="library" name="Maven: cglib:cglib-nodep:3.2.5" level="project" />
<orderEntry type="library" name="Maven: org.jsoup:jsoup:1.10.3" level="project" />
</component>
</module>

View File

@ -49,6 +49,7 @@ public class LoginReqHandler extends AbCmdHandler {
User user = loginServiceHandler.getUser(loginReqBody,channelContext);
if (user == null ) {
log.info("登录失败, loginname:{}, password:{}", loginReqBody.getLoginname(), loginReqBody.getPassword());
loginServiceHandler.onFailed(channelContext);
Aio.remove(channelContext, "loginname and token is null");
return null;
}
@ -63,6 +64,7 @@ public class LoginReqHandler extends AbCmdHandler {
bindUnbindGroup(channelContext, user);//初始化绑定或者解绑群组;
loginRespBodyBuilder.setUser(user);
loginRespBodyBuilder.setToken(token);
loginServiceHandler.onSuccess(channelContext);
RespBody respBody = new RespBody(Command.COMMAND_LOGIN_RESP,ImStatus.C10007).setData(loginRespBodyBuilder);
return ImKit.ConvertRespPacket(respBody, channelContext);
}

View File

@ -14,4 +14,8 @@ import org.jim.server.command.handler.processor.ProcessorIntf;
public interface LoginProcessorIntf extends ProcessorIntf{
public User getUser(LoginReqBody loginReqBody ,ChannelContext channelContext);
public void onSuccess(ChannelContext channelContext);
public void onFailed(ChannelContext channelContext);
}