Skip to content

Commit

Permalink
Merge branch 'release/1.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
ichenkaihua committed Apr 10, 2020
2 parents af69f72 + a1c4750 commit 6c810d5
Show file tree
Hide file tree
Showing 137 changed files with 3,763 additions and 3,246 deletions.
18 changes: 17 additions & 1 deletion base/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,29 @@
<parent>
<artifactId>vchat</artifactId>
<groupId>com.chenkh</groupId>
<version>1.0.0</version>
<version>1.1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
<artifactId>base</artifactId>

<dependencies>


<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.12</version>
<scope>provided</scope>
</dependency>


<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.6</version>
</dependency>

</dependencies>


Expand Down
20 changes: 20 additions & 0 deletions base/src/main/java/com/chenkh/vchat/base/IDecoder.java
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);

}
9 changes: 9 additions & 0 deletions base/src/main/java/com/chenkh/vchat/base/IEncoder.java
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);

}
5 changes: 5 additions & 0 deletions base/src/main/java/com/chenkh/vchat/base/bean/Friend.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.chenkh.vchat.base.bean;

import com.google.gson.annotations.Expose;

import java.io.Serializable;
import java.sql.Timestamp;

Expand All @@ -9,7 +11,9 @@ public class Friend implements Serializable, Comparable<Friend> {
private String phone;
private String sex;
private String addr;
@Expose
private Timestamp rDate;
@Expose
private Group group;
private String noteName;
private String sign;
Expand Down Expand Up @@ -40,6 +44,7 @@ public void setNoteName(String noteName) {
this.noteName = noteName;
}


public Group getGroup() {
return group;
}
Expand Down
86 changes: 86 additions & 0 deletions base/src/main/java/com/chenkh/vchat/base/bean/MsgType.java
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 base/src/main/java/com/chenkh/vchat/base/function/ThiConsumer.java
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);
};
}
}
44 changes: 9 additions & 35 deletions base/src/main/java/com/chenkh/vchat/base/msg/ChatMsg.java
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 base/src/main/java/com/chenkh/vchat/base/msg/ClientMsg.java
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);
}



}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.chenkh.vchat.base.msg;

import com.chenkh.vchat.base.bean.MsgType;
import com.chenkh.vchat.base.msg.both.DeleteFriendMsg;
import com.chenkh.vchat.base.msg.both.UserStateChangeMsg;
import com.chenkh.vchat.base.msg.server.AddFriendSucess;
Expand All @@ -11,7 +12,10 @@

public interface ClientMsgMgr {

public void parseMsg(ServerMsg msg);

void processMsg(MsgType.Server2Client type,MsgBody body);

/* public void parseMsg(ServerMsg msg);
public void parseMsg(LoginResultMsg msg);
Expand All @@ -38,7 +42,7 @@ public interface ClientMsgMgr {
public void parseMsg(DeleteFriendMsg msg);
public void parseMsg(StrangerMsg msg);
public void parseMsg(StrangerMsg msg);*/



Expand Down
58 changes: 58 additions & 0 deletions base/src/main/java/com/chenkh/vchat/base/msg/Msg.java
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;
}





}
20 changes: 20 additions & 0 deletions base/src/main/java/com/chenkh/vchat/base/msg/MsgBody.java
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;

}
Loading

0 comments on commit 6c810d5

Please sign in to comment.