diff --git a/pom.xml b/pom.xml index fa72ec9..195c436 100644 --- a/pom.xml +++ b/pom.xml @@ -13,8 +13,8 @@ cn.csuosa ChattingRoom-server - beta-0.3.0 + beta-0.3.1 14 diff --git a/src/main/java/cn/CSUOSA/ChattingRoomServer/Channel/ChannelActions.java b/src/main/java/cn/CSUOSA/ChattingRoomServer/Channel/ChannelActions.java index 468aca0..288586e 100644 --- a/src/main/java/cn/CSUOSA/ChattingRoomServer/Channel/ChannelActions.java +++ b/src/main/java/cn/CSUOSA/ChattingRoomServer/Channel/ChannelActions.java @@ -43,7 +43,6 @@ public static boolean verifyChannel(String name, String ticket) } } - //频道创建相关 @PostMapping("/create") public BoolMsgWithObj channelCreation(@RequestParam(value = "usrNick") String usrNick, @RequestParam(value = "name") String name, String usrTicket, @Nullable String ticket) @@ -89,7 +88,6 @@ public BoolMsgWithObj channelJoin(@RequestParam(value = "usrNick") String usrNic if (!verifyUser(usrNick, usrTicket)) return new BoolMsgWithObj(false, "Authentication failed."); - if (name.length() < 4 || name.length() > 64 || (ticket != null && ticket.length() != 6)) return new BoolMsgWithObj(false, "Invalid name or ticket length."); else diff --git a/src/main/java/cn/CSUOSA/ChattingRoomServer/Main.java b/src/main/java/cn/CSUOSA/ChattingRoomServer/Main.java index 6ecf4a6..9372577 100644 --- a/src/main/java/cn/CSUOSA/ChattingRoomServer/Main.java +++ b/src/main/java/cn/CSUOSA/ChattingRoomServer/Main.java @@ -3,6 +3,7 @@ import cn.CSUOSA.ChattingRoomServer.Channel.ChannelInfo; import cn.CSUOSA.ChattingRoomServer.ConsoleController.CmdProcessor; import cn.CSUOSA.ChattingRoomServer.Message.MessageListEntry; +import cn.CSUOSA.ChattingRoomServer.Message.MessageListMaintain; import cn.CSUOSA.ChattingRoomServer.OverWriteMethod.Out; import cn.CSUOSA.ChattingRoomServer.User.UserInfo; import cn.CSUOSA.ChattingRoomServer.User.UserMapTimer; @@ -19,24 +20,22 @@ @SpringBootApplication public class Main { - public static ConcurrentHashMap UserList; - public static ConcurrentHashMap ChannelList; - public static ConcurrentHashMap MsgList; - public static UserMapTimer userMapTimer = new UserMapTimer(); - public static MessageListThread msgListCleaner = new MessageListThread(); + + public final static ConcurrentHashMap UserList = new ConcurrentHashMap<>(); //用户列表 + public final static ConcurrentHashMap ChannelList = new ConcurrentHashMap<>(); //频道列表 + public final static ConcurrentHashMap MsgList = new ConcurrentHashMap<>(); //消息队列 + public final static UserMapTimer userMapTimer = new UserMapTimer(); + public final static MessageListMaintain msgListCleaner = new MessageListMaintain(); public static Terminal terminal; public static LineReader lineReader; public static long msgCount = 0; - + private static ConfigurableApplicationContext CAC; @Autowired Environment environment; public static void main(String[] args) { - UserList = new ConcurrentHashMap<>(); //用户列表 - ChannelList = new ConcurrentHashMap<>(); //频道列表 - new Thread(new CmdProcessor()).start(); //启动命令行处理器 CAC = SpringApplication.run(Main.class, args); //启动SpringBoot @@ -53,13 +52,7 @@ public static void main(String[] args) } Out.Info("Channel [PublicChannel] Opened"); - Main.ChannelList.put("PublicChannel", new ChannelInfo("PublicChannel", "", false));======= - UserList = new ConcurrentHashMap<>(); - ChannelList = new HashMap<>(); - - CAC = SpringApplication.run(Main.class, args); - new Thread(userMapTimer).start(); - new Thread(new CmdProcessor()).start(); + Main.ChannelList.put("PublicChannel", new ChannelInfo("PublicChannel", "", false)); } -} +} \ No newline at end of file diff --git a/src/main/java/cn/CSUOSA/ChattingRoomServer/Message/MessageActions.java b/src/main/java/cn/CSUOSA/ChattingRoomServer/Message/MessageActions.java index bb3c76d..003ee85 100644 --- a/src/main/java/cn/CSUOSA/ChattingRoomServer/Message/MessageActions.java +++ b/src/main/java/cn/CSUOSA/ChattingRoomServer/Message/MessageActions.java @@ -1,6 +1,5 @@ package cn.CSUOSA.ChattingRoomServer.Message; - import cn.CSUOSA.ChattingRoomServer.Main; import cn.CSUOSA.ChattingRoomServer.ReturnParams.BoolMsgWithObj; import cn.CSUOSA.ChattingRoomServer.User.UserInfo; @@ -12,6 +11,7 @@ import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Collections; import java.util.Date; import static cn.CSUOSA.ChattingRoomServer.Channel.ChannelActions.verifyChannel; @@ -22,7 +22,7 @@ public class MessageActions { @PostMapping("/send") - public BoolMsgWithObj sendMsg(@RequestParam(value = "usrNick") String usrNick, @RequestParam(value = "name") String name, String usrTicket, @Nullable String ticket, ArrayList msg) + public BoolMsgWithObj sendMsg(@RequestParam(value = "usrNick") String usrNick, @RequestParam(value = "name") String name, String usrTicket, @Nullable String ticket, String msg) { if (!verifyUser(usrNick, usrTicket)) return new BoolMsgWithObj(false, "Authentication failed."); @@ -33,7 +33,7 @@ public BoolMsgWithObj sendMsg(@RequestParam(value = "usrNick") String usrNick, @ if (!Main.ChannelList.get(name).getMembers().contains(Main.UserList.get(usrNick))) return new BoolMsgWithObj(false, "You are not a member of that channel."); - MessageInfo newMsg = new MessageInfo(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()), name, usrNick, msg); + MessageInfo newMsg = new MessageInfo(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()), name, usrNick, new ArrayList<>(Collections.singletonList(msg))); long mid = newMsg.getMsgID(); MessageListEntry msgListEntry = new MessageListEntry(newMsg); diff --git a/src/main/java/cn/CSUOSA/ChattingRoomServer/Message/MessageListMaintain.java b/src/main/java/cn/CSUOSA/ChattingRoomServer/Message/MessageListMaintain.java new file mode 100644 index 0000000..90b3bcc --- /dev/null +++ b/src/main/java/cn/CSUOSA/ChattingRoomServer/Message/MessageListMaintain.java @@ -0,0 +1,35 @@ +package cn.CSUOSA.ChattingRoomServer.Message; + +import cn.CSUOSA.ChattingRoomServer.Main; + +public class MessageListMaintain implements Runnable +{ + @Override + public void run() + { + try + { + while (true) + { + synchronized (this) + { + if (!Main.MsgList.isEmpty()) + { + Main.MsgList.forEach((key, value) -> { + MessageListEntry msgEntry = Main.MsgList.get(key); + + if (msgEntry.getQuoteCount() == 0) + { + Main.MsgList.remove(key); + } + }); + } + wait(60 * 1000); + } + } + } catch (Exception e) + { + e.printStackTrace(); + } + } +}