-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
137 changed files
with
3,763 additions
and
3,246 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.chenkh.vchat.base; | ||
|
||
import com.chenkh.vchat.base.bean.MsgType; | ||
import com.chenkh.vchat.base.msg.Msg; | ||
import com.chenkh.vchat.base.msg.ServerMsg; | ||
|
||
public interface IDecoder { | ||
|
||
|
||
|
||
boolean support(byte[] bytes); | ||
|
||
/** | ||
* 将一个byte数组转换成对象 | ||
* @param bytes | ||
* @return | ||
*/ | ||
Object decode(byte[] bytes); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.chenkh.vchat.base; | ||
|
||
public interface IEncoder { | ||
|
||
boolean support(Object content); | ||
|
||
byte[] encode(Object content); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
base/src/main/java/com/chenkh/vchat/base/bean/MsgType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package com.chenkh.vchat.base.bean; | ||
|
||
public class MsgType { | ||
|
||
public enum Server2Client{ | ||
/** | ||
* 登录 | ||
*/ | ||
LOGIN, | ||
|
||
/** | ||
* 离线消息 | ||
*/ | ||
OFFLINE_MSG, | ||
|
||
/** | ||
* 聊天信息 | ||
*/ | ||
CHAT, | ||
|
||
/** | ||
* 陌生好友 | ||
*/ | ||
STRAGER_MSG, | ||
|
||
/** | ||
* 好友状态发生改变 | ||
*/ | ||
FRIEND_STATE_CHANGED, | ||
|
||
/** | ||
* 注册结果 | ||
*/ | ||
REGISTER_RESULT, | ||
|
||
/** | ||
* 查询结果 | ||
*/ | ||
QUERY_RESULT, | ||
|
||
/** | ||
* 添加好友结果 | ||
*/ | ||
ADD_FRIEND_RESULT, | ||
|
||
/** | ||
* 删除好友结果 | ||
*/ | ||
DELETE_FRIEND_RESULT | ||
|
||
} | ||
|
||
|
||
public enum Client2Server{ | ||
/** | ||
* 登录 | ||
*/ | ||
LOGIN, /** | ||
* 注册 | ||
*/ | ||
REGISTER, | ||
/** | ||
* 用户状态改变 | ||
*/ | ||
USER_STATE_CHANGED, | ||
/** | ||
* 删除好友 | ||
*/ | ||
DELETE_FRIEND, | ||
/** | ||
* 查找好友 | ||
*/ | ||
QUERY, | ||
/** | ||
* 添加好友 | ||
*/ | ||
ADD_FRIEND, | ||
/** | ||
* 聊天消息 | ||
*/ | ||
CHAT, | ||
} | ||
|
||
} | ||
|
||
|
12 changes: 12 additions & 0 deletions
12
base/src/main/java/com/chenkh/vchat/base/function/ThiConsumer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.chenkh.vchat.base.function; | ||
|
||
@FunctionalInterface | ||
public interface ThiConsumer<T,U,W>{ | ||
void accept(T t, U u, W w); | ||
default ThiConsumer<T,U,W> andThen(ThiConsumer<? super T,? super U,? super W> consumer){ | ||
return (t, u, w)->{ | ||
accept(t, u, w); | ||
consumer.accept(t, u, w); | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,20 @@ | ||
package com.chenkh.vchat.base.msg; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.Getter; | ||
|
||
import java.nio.channels.AsynchronousSocketChannel; | ||
import java.sql.Timestamp; | ||
|
||
public class ChatMsg implements ServerMsg,ClientMsg { | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public class ChatMsg { | ||
private final int fromId; | ||
private final int toId; | ||
private final String content; | ||
private final Timestamp date; | ||
|
||
public ChatMsg(int fromId, int toId,String content, Timestamp date) { | ||
this.fromId = fromId; | ||
this.toId = toId; | ||
this.content = content; | ||
this.date = date; | ||
} | ||
|
||
public int getFromId() { | ||
return fromId; | ||
} | ||
|
||
public String getContent() { | ||
return content; | ||
} | ||
|
||
public Timestamp getDate() { | ||
return date; | ||
} | ||
|
||
@Override | ||
public void parse(ClientMsgMgr mgr) { | ||
mgr.parseMsg(this); | ||
} | ||
|
||
@Override | ||
public void parse(ServerMsgMgr mgr, AsynchronousSocketChannel socket) { | ||
mgr.parseMsg(this, socket); | ||
|
||
} | ||
|
||
public int getToId() { | ||
return toId; | ||
} | ||
|
||
} |
27 changes: 20 additions & 7 deletions
27
base/src/main/java/com/chenkh/vchat/base/msg/ClientMsg.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,29 @@ | ||
package com.chenkh.vchat.base.msg; | ||
|
||
import com.chenkh.vchat.base.bean.MsgType; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.Getter; | ||
|
||
import java.io.Serializable; | ||
import java.nio.channels.AsynchronousSocketChannel; | ||
|
||
/** | ||
* 客户端信息的总接口,分解时,需要借助服务器消息管理器接口,和一个通道口 | ||
* @author Administrator | ||
* | ||
*/ | ||
public interface ClientMsg extends Serializable { | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public class ClientMsg<T> { | ||
|
||
public void parse(ServerMsgMgr mgr,AsynchronousSocketChannel socket); | ||
|
||
private MsgType.Client2Server msgType; | ||
|
||
|
||
private T body; | ||
|
||
|
||
public static <V> ClientMsg<V> builder(MsgType.Client2Server msgType, V body){ | ||
return new ClientMsg<>(msgType, body); | ||
} | ||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package com.chenkh.vchat.base.msg; | ||
|
||
|
||
import com.chenkh.vchat.base.bean.MsgType; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Data | ||
@Builder | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class Msg<T> { | ||
|
||
|
||
private String command; | ||
|
||
private MsgBody<T> msgBody; | ||
|
||
|
||
|
||
public static <V> Msg<V> buildClientMsg(MsgType.Client2Server msgType,V msgBody){ | ||
return buildClientMsg(msgType, true, null, msgBody); | ||
} | ||
|
||
public static <V> Msg<V> buildClientMsg(MsgType.Client2Server msgType,boolean success,String reason,V msgBody){ | ||
Msg<V> msg = new Msg<V>(); | ||
msg.setCommand(msgType.toString()); | ||
MsgBody<V> vMsgBody = new MsgBody<V>(); | ||
vMsgBody.setSuccess(success); | ||
vMsgBody.setReason(reason); | ||
vMsgBody.setBody(msgBody); | ||
msg.setMsgBody(vMsgBody); | ||
return msg; | ||
} | ||
|
||
|
||
public static <V> Msg<V> buildServerMsg(MsgType.Server2Client msgType,V msgBody){ | ||
return buildServerMsg(msgType, true, null, msgBody); | ||
} | ||
|
||
public static <V> Msg<V> buildServerMsg(MsgType.Server2Client msgType,boolean success,String reason,V msgBody){ | ||
Msg<V> msg = new Msg<V>(); | ||
msg.setCommand(msgType.toString()); | ||
MsgBody<V> vMsgBody = new MsgBody<V>(); | ||
vMsgBody.setSuccess(success); | ||
vMsgBody.setReason(reason); | ||
vMsgBody.setBody(msgBody); | ||
msg.setMsgBody(vMsgBody); | ||
return msg; | ||
} | ||
|
||
|
||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.chenkh.vchat.base.msg; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Data | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class MsgBody<T> { | ||
|
||
private boolean success; | ||
|
||
private String reason; | ||
|
||
private T body; | ||
|
||
} |
Oops, something went wrong.