Skip to content

Commit

Permalink
split net part to FocessSocket
Browse files Browse the repository at this point in the history
  • Loading branch information
MidCoard committed Oct 1, 2022
1 parent c348d95 commit 2c0c22e
Show file tree
Hide file tree
Showing 64 changed files with 377 additions and 2,463 deletions.
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
<util.version>1.1.12</util.version>
<scheduler.version>1.1.6</scheduler.version>
<sysout.version>1.0.2</sysout.version>
<socket.version>1.0.1</socket.version>
</properties>

<repositories>
Expand Down Expand Up @@ -130,6 +131,11 @@
<artifactId>poi-ooxml</artifactId>
<version>${poi.version}</version>
</dependency>
<dependency>
<groupId>top.focess</groupId>
<artifactId>focess-socket</artifactId>
<version>${socket.version}</version>
</dependency>
</dependencies>

<build>
Expand Down
94 changes: 53 additions & 41 deletions src/main/java/top/focess/qq/FocessQQ.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@
import org.checkerframework.checker.nullness.qual.Nullable;
import org.jetbrains.annotations.UnmodifiableView;
import top.focess.command.CommandResult;
import top.focess.net.IllegalPortException;
import top.focess.net.receiver.FocessClientReceiver;
import top.focess.net.receiver.FocessReceiver;
import top.focess.net.receiver.FocessUDPMultiReceiver;
import top.focess.net.receiver.FocessUDPReceiver;
import top.focess.net.socket.FocessSidedClientSocket;
import top.focess.net.socket.FocessSidedSocket;
import top.focess.net.socket.FocessSocket;
import top.focess.net.socket.FocessUDPSocket;
import top.focess.qq.api.bot.Bot;
import top.focess.qq.api.bot.BotLoginException;
import top.focess.qq.api.bot.BotManager;
Expand All @@ -29,10 +38,13 @@
import top.focess.qq.api.event.chat.ConsoleChatEvent;
import top.focess.qq.api.event.server.ServerStartEvent;
import top.focess.qq.api.event.server.ServerStopEvent;
import top.focess.qq.api.net.*;
import top.focess.qq.api.net.ClientReceiver;
import top.focess.qq.api.net.ServerMultiReceiver;
import top.focess.qq.api.net.ServerReceiver;
import top.focess.qq.api.net.Socket;
import top.focess.qq.api.plugin.Plugin;
import top.focess.qq.api.plugin.PluginLoadException;
import top.focess.qq.api.schedule.Schedulers;
import top.focess.qq.api.scheduler.Schedulers;
import top.focess.qq.api.util.IOHandler;
import top.focess.qq.api.util.config.LangConfig;
import top.focess.qq.api.util.logger.FocessLogger;
Expand All @@ -42,7 +54,6 @@
import top.focess.qq.core.listeners.ChatListener;
import top.focess.qq.core.listeners.ConsoleListener;
import top.focess.qq.core.listeners.PluginListener;
import top.focess.qq.core.net.*;
import top.focess.qq.core.permission.Permission;
import top.focess.qq.core.permission.PermissionEnv;
import top.focess.qq.core.plugin.PluginClassLoader;
Expand Down Expand Up @@ -169,33 +180,28 @@ private static boolean hasNextLine() {
/**
* The default socket
*/
@Nullable
private static Socket socket;
private static @Nullable Socket socket;
/**
* The default udp socket
*/
@Nullable
private static Socket udpSocket;
private static @Nullable Socket udpSocket;
/**
* The default udp server receiver
*/
@Nullable
private static ServerReceiver udpServerReceiver;
private static @Nullable ServerReceiver udpServerReceiver;
/**
* The default server receiver
*/
@Nullable
private static ServerReceiver serverReceiver;

private static @Nullable ServerReceiver serverReceiver;
/**
* The default client receiver
*/
@Nullable
private static ClientReceiver clientReceiver;
private static @Nullable ClientReceiver clientReceiver;
/**
* The default server multi receiver
*/
@Nullable
private static ServerMultiReceiver udpServerMultiReceiver;
private static @Nullable ServerMultiReceiver udpServerMultiReceiver;
/**
* The Mirai Bot user or we call it QQ number
*/
Expand Down Expand Up @@ -278,33 +284,27 @@ public static BotManager getBotManager() {
return botManager;
}

@Nullable
public static Socket getSocket() {
public static @Nullable Socket getSocket() {
return socket;
}

@Nullable
public static ServerReceiver getServerReceiver() {
public static @Nullable ServerReceiver getServerReceiver() {
return serverReceiver;
}

@Nullable
public static ClientReceiver getClientReceiver() {
public static @Nullable ClientReceiver getClientReceiver() {
return clientReceiver;
}

@Nullable
public static Socket getUdpSocket() {
public static @Nullable Socket getUdpSocket() {
return udpSocket;
}

@Nullable
public static ServerReceiver getUdpServerReceiver() {
public static @Nullable ServerReceiver getUdpServerReceiver() {
return udpServerReceiver;
}

@Nullable
public static ServerMultiReceiver getUdpServerMultiReceiver() {
public static @Nullable ServerMultiReceiver getUdpServerMultiReceiver() {
return udpServerMultiReceiver;
}

Expand Down Expand Up @@ -462,17 +462,19 @@ public static void main(final String[] args) {
if (sidedOption == null)
try {
final FocessSocket focessSocket = new FocessSocket(option.get(IntegerOptionType.INTEGER_OPTION_TYPE));
focessSocket.registerReceiver(serverReceiver = new FocessReceiver(focessSocket));
socket = focessSocket;
FocessReceiver receiver = new FocessReceiver(focessSocket);
focessSocket.registerReceiver(receiver);
serverReceiver = new ServerReceiver(receiver);
socket = new Socket(focessSocket);
getLogger().infoLang("create-focess-socket-server");
} catch (final Exception e) {
getLogger().thrLang("exception-create-focess-socket-server", e);
}
else {
try {
final FocessSidedSocket focessSidedSocket = new FocessSidedSocket(option.get(IntegerOptionType.INTEGER_OPTION_TYPE));
focessSidedSocket.registerReceiver(serverReceiver = new FocessSidedReceiver());
socket = focessSidedSocket;
serverReceiver = new ServerReceiver(focessSidedSocket.getReceiver());
socket = new Socket(focessSidedSocket);
getLogger().infoLang("create-focess-sided-socket-server");
} catch (final Exception e) {
getLogger().thrLang("exception-create-focess-sided-socket-server", e);
Expand All @@ -488,8 +490,10 @@ public static void main(final String[] args) {
final String host = option.get(OptionType.DEFAULT_OPTION_TYPE);
final int port = option.get(IntegerOptionType.INTEGER_OPTION_TYPE);
final String name = option.get(OptionType.DEFAULT_OPTION_TYPE);
focessSocket.registerReceiver(clientReceiver = new FocessClientReceiver(focessSocket, localhost, host, port, name));
socket = focessSocket;
FocessClientReceiver receiver = new FocessClientReceiver(focessSocket, localhost, host, port, name);
focessSocket.registerReceiver(receiver);
clientReceiver = new ClientReceiver(receiver);
socket = new Socket(focessSocket);
getLogger().infoLang("create-focess-socket-client");
} catch (final Exception e) {
getLogger().thrLang("exception-create-focess-socket-client", e);
Expand All @@ -499,9 +503,9 @@ public static void main(final String[] args) {
final String host = option.get(OptionType.DEFAULT_OPTION_TYPE);
final int port = option.get(IntegerOptionType.INTEGER_OPTION_TYPE);
final String name = option.get(OptionType.DEFAULT_OPTION_TYPE);
final FocessSidedClientSocket focessSidedClientSocket = new FocessSidedClientSocket(host, port);
focessSidedClientSocket.registerReceiver(clientReceiver = new FocessSidedClientReceiver(focessSidedClientSocket, name));
socket = focessSidedClientSocket;
final FocessSidedClientSocket focessSidedClientSocket = new FocessSidedClientSocket(host, port, name);
clientReceiver = new ClientReceiver(focessSidedClientSocket.getReceiver());
socket = new Socket(focessSidedClientSocket);
getLogger().infoLang("create-focess-sided-socket-client");
} catch (final Exception e) {
getLogger().thrLang("exception-create-focess-sided-socket-client", e);
Expand All @@ -512,11 +516,17 @@ public static void main(final String[] args) {
if (option != null) {
try {
final FocessUDPSocket focessUDPSocket = new FocessUDPSocket(option.get(IntegerOptionType.INTEGER_OPTION_TYPE));
if (multiOption == null)
focessUDPSocket.registerReceiver(udpServerReceiver = new FocessUDPReceiver(focessUDPSocket));
else
focessUDPSocket.registerReceiver(udpServerMultiReceiver = new FocessUDPMultiReceiver(focessUDPSocket));
udpSocket = focessUDPSocket;
if (multiOption == null) {
FocessUDPReceiver receiver = new FocessUDPReceiver(focessUDPSocket);
focessUDPSocket.registerReceiver(receiver);
udpServerReceiver = new ServerReceiver(receiver);
}
else {
FocessUDPMultiReceiver receiver = new FocessUDPMultiReceiver(focessUDPSocket);
focessUDPSocket.registerReceiver(receiver);
udpServerMultiReceiver = new ServerMultiReceiver(receiver);
}
udpSocket = new Socket(focessUDPSocket);
getLogger().infoLang("create-focess-udp-socket-client");
} catch (final IllegalPortException e) {
getLogger().thrLang("exception-create-focess-udp-socket-client", e);
Expand Down Expand Up @@ -573,6 +583,7 @@ public static void exit() {
Thread.sleep(5000);
} catch (InterruptedException e) {
}
System.err.println("Force Shutdown");
System.exit(0);
}).start();
}
Expand Down Expand Up @@ -652,6 +663,7 @@ public void enable() {
this.registerCommand(new ExecCommand());
this.registerCommand(new PauseCommand());
this.registerCommand(new TestCommand());
this.registerCommand(new PermissionCommand());
getLogger().debugLang("register-default-commands");
this.registerSpecialArgumentComplexHandler("previous", new PreviousArgumentHandler());
this.registerSpecialArgumentComplexHandler("next", new NextArgumentHandler());
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/top/focess/qq/api/command/CommandLine.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import top.focess.command.CommandResult;
import top.focess.qq.FocessQQ;
import top.focess.qq.api.plugin.Plugin;
import top.focess.qq.api.schedule.Schedulers;
import top.focess.qq.api.scheduler.Schedulers;
import top.focess.qq.api.util.IOHandler;
import top.focess.qq.core.permission.Permission;
import top.focess.qq.core.permission.PermissionEnv;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/top/focess/qq/api/event/EventManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.google.common.collect.Maps;
import org.jetbrains.annotations.NotNull;
import top.focess.qq.FocessQQ;
import top.focess.qq.api.schedule.Schedulers;
import top.focess.qq.api.scheduler.Schedulers;
import top.focess.qq.core.debug.Section;
import top.focess.qq.core.permission.Permission;
import top.focess.qq.core.permission.PermissionEnv;
Expand Down
22 changes: 0 additions & 22 deletions src/main/java/top/focess/qq/api/net/Client.java

This file was deleted.

Loading

0 comments on commit 2c0c22e

Please sign in to comment.