Skip to content

Commit

Permalink
BUG Fix (#8)
Browse files Browse the repository at this point in the history
* Development update
-Updated nickname registration and refresh
-Updated channel registration to join

* Development update
-Upgrade to a safer POST method
-Added a framework for message receiving and sending

* Development update
-Message List basic function.

* fix!
-Fixed the bug that User can send messages to the channel even if he/she is not a member of the channel.

* Fix.
-Fixed the bug that MsgListMaintain thread can't work properly.
-Fixed the bug that user can't send msg to channel.
  • Loading branch information
Oct-autumn authored Nov 19, 2021
1 parent 2f47c02 commit f1d1e24
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 23 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

<groupId>cn.csuosa</groupId>
<artifactId>ChattingRoom-server</artifactId>
<version>beta-0.3.0</version>

<version>beta-0.3.1</version>

<properties>
<maven.compiler.source>14</maven.compiler.source>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
27 changes: 10 additions & 17 deletions src/main/java/cn/CSUOSA/ChattingRoomServer/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -19,24 +20,22 @@
@SpringBootApplication
public class Main
{
public static ConcurrentHashMap<String, UserInfo> UserList;
public static ConcurrentHashMap<String, ChannelInfo> ChannelList;
public static ConcurrentHashMap<Long, MessageListEntry> MsgList;
public static UserMapTimer userMapTimer = new UserMapTimer();
public static MessageListThread msgListCleaner = new MessageListThread();

public final static ConcurrentHashMap<String, UserInfo> UserList = new ConcurrentHashMap<>(); //用户列表
public final static ConcurrentHashMap<String, ChannelInfo> ChannelList = new ConcurrentHashMap<>(); //频道列表
public final static ConcurrentHashMap<Long, MessageListEntry> 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
Expand All @@ -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));
}
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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<String> 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.");
Expand All @@ -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);

Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
}
}

0 comments on commit f1d1e24

Please sign in to comment.