Skip to content

Commit

Permalink
Merge pull request #101 from anlingyi/release
Browse files Browse the repository at this point in the history
1.6.6-beta
  • Loading branch information
anlingyi authored Sep 3, 2023
2 parents 235f9d8 + c64801c commit e098d3e
Show file tree
Hide file tree
Showing 51 changed files with 746 additions and 129 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# XEChat-Idea

> Version 1.6.5-beta
> Version 1.6.6-beta
> 基于Netty的IDEA即时聊天插件:让你能够在IDEA里实现聊天、下棋、斗地主!(理论上支持JetBrains全系列开发工具🙂)
> 浏览器端:[XEChat-Web](https://github.com/anlingyi/xechat-web)
- [目录](#xechat-idea)
- [项目介绍](#项目介绍)
- [项目结构](#项目结构)
Expand Down Expand Up @@ -103,6 +105,7 @@
* [实现一个自定义命令](https://xeblog.cn/articles/79)
* [实现一个自定义消息](https://xeblog.cn/articles/100)
* [实现一个联机对战游戏](https://xeblog.cn/articles/95)
* [WebSocket协议接入文档](https://xeblog.cn/articles/112)

## 运行 & 部署

Expand Down
2 changes: 1 addition & 1 deletion xechat-commons/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>cn.xeblog</groupId>
<artifactId>xechat-commons</artifactId>
<version>1.6.5-beta</version>
<version>1.6.6-beta</version>
<build>
<plugins>
<plugin>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package cn.xeblog.commons.entity;

import cn.xeblog.commons.enums.Platform;
import cn.xeblog.commons.enums.UserStatus;
import lombok.AllArgsConstructor;
import lombok.Data;
Expand All @@ -16,16 +17,63 @@
@AllArgsConstructor
public class LoginDTO implements Serializable {

/**
* 昵称
*/
private String username;

/**
* 状态
*/
private UserStatus status;

/**
* 是否是重连
*/
private boolean reconnected;

/**
* 插件版本
*/
private String pluginVersion;

/**
* 令牌
*/
private String token;

/**
* 全局唯一ID
*/
private String uuid;

/**
* 来源平台
*/
private Platform platform;

public void setStatus(UserStatus status) {
this.status = status;
}

public void setStatus(String status) {
try {
this.status = UserStatus.valueOf(status);
} catch (Exception e) {
this.status = UserStatus.FISHING;
}
}

public void setPlatform(Platform platform) {
this.platform = platform;
}

public void setPlatform(String platform) {
try {
this.platform = Platform.valueOf(platform);
} catch (Exception e) {
this.platform = Platform.IDEA;
}
}

}
18 changes: 18 additions & 0 deletions xechat-commons/src/main/java/cn/xeblog/commons/entity/Request.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cn.xeblog.commons.entity;

import cn.xeblog.commons.enums.Action;
import cn.xeblog.commons.enums.Protocol;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
Expand Down Expand Up @@ -30,4 +31,21 @@ public class Request<T> implements Serializable {
*/
private Action action;

private Protocol protocol;

public Request(T body, Action action) {
this.body = body;
this.action = action;
}

public void setAction(Action action) {
this.action = action;
}

public void setAction(String action) {
try {
this.action = Action.valueOf(action);
} catch (Exception e) {
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cn.xeblog.commons.entity;

import cn.xeblog.commons.enums.Permissions;
import cn.xeblog.commons.enums.Platform;
import cn.xeblog.commons.enums.UserStatus;
import io.netty.channel.Channel;
import lombok.*;
Expand Down Expand Up @@ -74,6 +75,10 @@ public class User implements Serializable {
@Setter
private int permit;

@Getter
@Setter
private Platform platform;

/**
* 通道
*/
Expand All @@ -98,6 +103,7 @@ public User(String id, String username, UserStatus status, String ip, IpRegion r
this.ip = ip;
this.region = region;
this.channel = channel;
this.platform = Platform.IDEA;
}

public void send(Response response) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,12 @@ public boolean hasUser(String username) {
return false;
}

public void setMsgType(MsgType msgType) {
this.msgType = msgType;
}

public void setMsgType(String msgType) {
this.msgType = MsgType.valueOf(msgType);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,12 @@ public class WeatherDTO implements Serializable {
*/
private String location;

public void setType(WeatherType type) {
this.type = type;
}

public void setType(String type) {
this.type = WeatherType.build(type);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,12 @@ public GameInviteResultDTO(InviteStatus status) {
this.status = status;
}

public void setStatus(InviteStatus status) {
this.status = status;
}

public void setStatus(String status) {
this.status = InviteStatus.valueOf(status);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,12 @@ public enum MsgType {
ROOM_CLOSE;
}

public void setMsgType(MsgType msgType) {
this.msgType = msgType;
}

public void setMsgType(String msgType) {
this.msgType = MsgType.valueOf(msgType);
}

}
20 changes: 20 additions & 0 deletions xechat-commons/src/main/java/cn/xeblog/commons/enums/Platform.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package cn.xeblog.commons.enums;

/**
* 平台
*
* @author anlingyi
* @date 2023/9/1 8:20 PM
*/
public enum Platform {

/**
* Jetbrains平台
*/
IDEA,
/**
* Web平台
*/
WEB

}
21 changes: 21 additions & 0 deletions xechat-commons/src/main/java/cn/xeblog/commons/enums/Protocol.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package cn.xeblog.commons.enums;

/**
* 协议类型
*
* @author anlingyi
* @date 2023/9/2 1:18 AM
*/
public enum Protocol {

/**
* 默认协议
*/
DEFAULT,

/**
* WebSocket协议
*/
WEBSOCKET

}
4 changes: 2 additions & 2 deletions xechat-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
}

group 'cn.xeblog'
version '1.6.5-beta'
version '1.6.6-beta'

sourceCompatibility = 11
targetCompatibility = 11
Expand All @@ -20,7 +20,7 @@ repositories {
}

ext {
xechatCommonsVersion = '1.6.5-beta'
xechatCommonsVersion = '1.6.6-beta'
lombokVersion = '1.18.24'
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void exec(ClientConnectConsumer consumer) {
if (channelInitializer == null) {
channelInitializer = new DefaultChannelInitializer();
}
GlobalThreadPool.execute(() -> XEChatClient.run(host, port, channelInitializer, consumer));
GlobalThreadPool.execute(() -> XEChatClient.run(this, consumer));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public class Reactor<T> implements Future<ReactResult<T>> {

private Channel channel;

private boolean completed;

public Reactor() {
this(15, TimeUnit.SECONDS);
}
Expand Down Expand Up @@ -71,6 +73,11 @@ public ReactResult<T> get(long timeout, @NotNull TimeUnit unit) {
}

protected void setResult(ReactResult<T> result) {
if (completed) {
return;
}

this.completed = true;
this.result = result;
latch.countDown();
close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ protected boolean check(String[] args) {
public static String getMac() {
try {
Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces();
if (networkInterfaces.hasMoreElements()) {
while (networkInterfaces.hasMoreElements()) {
NetworkInterface networkInterface = networkInterfaces.nextElement();
byte[] bytes = networkInterface.getHardwareAddress();
if (bytes != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import cn.xeblog.commons.entity.react.request.DownloadReact;
import cn.xeblog.commons.entity.react.result.DownloadReactResult;
import cn.xeblog.commons.enums.MessageType;
import cn.xeblog.commons.enums.Platform;
import cn.xeblog.plugin.action.ConsoleAction;
import cn.xeblog.plugin.action.ReactAction;
import cn.xeblog.plugin.action.handler.ReactResultConsumer;
Expand Down Expand Up @@ -68,14 +69,15 @@ private void renderName(Response<UserMsgDTO> response) {
User user = response.getUser();
IpRegion region = user.getRegion();
final String shortProvince = MapUtil.getStr(IpConstants.SHORT_PROVINCE, region.getProvince(), region.getCountry());
String platform = user.getPlatform() == Platform.WEB ? " ༄" : " ♨";
String roleDisplay = "";
if (user.getRole() == User.Role.ADMIN) {
roleDisplay = " ☆";
}

ConsoleAction.renderText(
String.format("[%s][%s] %s (%s)%s:", response.getTime(), shortProvince, user.getUsername(),
user.getStatus().getName(), roleDisplay), Style.USER_NAME);
String.format("[%s][%s] %s (%s)%s%s:", response.getTime(), shortProvince, user.getUsername(),
user.getStatus().getName(), platform, roleDisplay), Style.USER_NAME);
}

private void renderImage(Response<UserMsgDTO> response) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import cn.xeblog.commons.entity.User;
import cn.xeblog.commons.enums.UserStatus;
import cn.xeblog.plugin.action.ConnectionAction;
import cn.xeblog.plugin.tools.browser.config.BrowserConfig;
import cn.xeblog.plugin.tools.read.ReadConfig;
import com.intellij.openapi.project.Project;
import io.netty.channel.Channel;
Expand Down Expand Up @@ -80,6 +81,11 @@ public class DataCache {
*/
public static ReadConfig readConfig = new ReadConfig();

/**
* 浏览器配置
*/
public static BrowserConfig browserConfig = new BrowserConfig();

/**
* 获取用户信息
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package cn.xeblog.plugin.client;

import cn.xeblog.plugin.handler.AbstractChannelInitializer;
import cn.xeblog.plugin.action.ConnectionAction;
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.*;
import io.netty.channel.nio.NioEventLoopGroup;
Expand All @@ -15,12 +15,16 @@ public class XEChatClient {
private static final String HOST = "localhost";
private static final int PORT = 1024;

public static void run(String host, int port, AbstractChannelInitializer channelInitializer, ClientConnectConsumer consumer) {
public static void run(ConnectionAction connectionAction, ClientConnectConsumer consumer) {
String host = connectionAction.getHost();
int port = connectionAction.getPort();
if (host == null) {
host = HOST;
connectionAction.setHost(HOST);
}
if (port == 0) {
port = PORT;
connectionAction.setPort(PORT);
}

EventLoopGroup group = new NioEventLoopGroup();
Expand All @@ -30,7 +34,7 @@ public static void run(String host, int port, AbstractChannelInitializer channel
.channel(NioSocketChannel.class)
.option(ChannelOption.TCP_NODELAY, true)
.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 10000)
.handler(channelInitializer);
.handler(connectionAction.getChannelInitializer());
ChannelFuture channelFuture = bootstrap.connect(host, port)
.addListener((ChannelFutureListener) future -> {
Channel channel = future.channel();
Expand Down
Loading

0 comments on commit e098d3e

Please sign in to comment.