-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
-Updated nickname registration and refresh -Updated channel registration to join
- Loading branch information
1 parent
91b00fb
commit f4f17ff
Showing
7 changed files
with
184 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,7 @@ | ||
# ChattingRoom-server | ||
|
||
CSU-OSA Chatting Room (server) | ||
|
||
CSU-OSA 聊天室(服务端) | ||
|
||
使用SpringBoot编写,目前采用Http通信。 |
49 changes: 49 additions & 0 deletions
49
src/main/java/cn/CSUOSA/ChattingRoomServer/Channel/ChannelInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package cn.CSUOSA.ChattingRoomServer.Channel; | ||
|
||
import cn.CSUOSA.ChattingRoomServer.User.UserInfo; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class ChannelInfo | ||
{ | ||
private final List<UserInfo> members; | ||
private final String name; | ||
private final String ticket; | ||
|
||
public ChannelInfo(String name, String ticket) | ||
{ | ||
this.name = name; | ||
this.ticket = ticket; | ||
members = new ArrayList<>(); | ||
} | ||
|
||
public boolean addMember(UserInfo member) | ||
{ | ||
if (!members.contains(member)) | ||
{ | ||
members.add(member); | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
public boolean removeMember(UserInfo member) | ||
{ | ||
if (members.contains(member)) | ||
{ | ||
members.remove(member); | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
public String getName() {return name;} | ||
|
||
public String getTicket() {return ticket;} | ||
|
||
public List<UserInfo> getMembers() | ||
{ | ||
return members; | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
src/main/java/cn/CSUOSA/ChattingRoomServer/ConsoleController/Processors.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package cn.CSUOSA.ChattingRoomServer.ConsoleController; | ||
|
||
import cn.CSUOSA.ChattingRoomServer.Channel.ChannelInfo; | ||
import cn.CSUOSA.ChattingRoomServer.Main; | ||
import cn.CSUOSA.ChattingRoomServer.OverWriteMethod.Out; | ||
import cn.CSUOSA.ChattingRoomServer.User.UserInfo; | ||
|
||
public class Processors | ||
{ | ||
public static void listObject(String[] args) | ||
{ | ||
switch (args[1]) | ||
{ | ||
case "-u", "--user" -> { | ||
if (Main.UserList.isEmpty()) | ||
Out.Warn("No User Online."); | ||
else | ||
{ | ||
UserInfo userInfo; | ||
StringBuilder strBuilder = new StringBuilder().append("\n"); | ||
strBuilder.append("User Count: ").append(Main.UserList.size()).append("\n"); | ||
for (String nowKey : Main.UserList.keySet()) | ||
{ | ||
userInfo = Main.UserList.get(nowKey); | ||
strBuilder.append(userInfo.getNick()) | ||
.append(" ") | ||
.append(userInfo.leftTime) | ||
.append("\n"); | ||
} | ||
strBuilder.append("\n"); | ||
|
||
Out.Info(strBuilder.toString()); | ||
} | ||
} | ||
case "-g", "--group" -> { | ||
if (Main.ChannelList.isEmpty()) | ||
Out.Warn("No Channel Opened."); | ||
else | ||
{ | ||
ChannelInfo channelInfo; | ||
StringBuilder strBuilder = new StringBuilder().append("\n"); | ||
strBuilder.append("Channel Count: ").append(Main.ChannelList.size()).append("\n"); | ||
for (String nowKey : Main.ChannelList.keySet()) | ||
{ | ||
channelInfo = Main.ChannelList.get(nowKey); | ||
strBuilder.append(channelInfo.getName()) | ||
.append(" ") | ||
.append(channelInfo.getTicket().isEmpty() ? "-null" : channelInfo.getTicket()) | ||
.append("\n"); | ||
} | ||
strBuilder.append("\n"); | ||
|
||
Out.Info(strBuilder.toString()); | ||
} | ||
} | ||
} | ||
|
||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/cn/CSUOSA/ChattingRoomServer/OverWriteMethod/Out.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package cn.CSUOSA.ChattingRoomServer.OverWriteMethod; | ||
|
||
import cn.CSUOSA.ChattingRoomServer.Main; | ||
|
||
import java.text.SimpleDateFormat; | ||
import java.util.Date; | ||
|
||
public class Out | ||
{ | ||
private static void println(String s) | ||
{ | ||
Main.lineReader.printAbove(getDateTime() + " " + s); | ||
} | ||
|
||
public static void Info(String info) | ||
{ | ||
println("\033[36m[Info]\t" + info + "\033[m"); | ||
} | ||
|
||
public static void Warn(String info) | ||
{ | ||
println("\033[33m[Warn]\t" + info + "\033[m"); | ||
} | ||
|
||
public static void Err(String info) | ||
{ | ||
println("\033[31m[Err]\t" + info + "\033[m"); | ||
} | ||
|
||
private static String getDateTime() | ||
{ | ||
return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/cn/CSUOSA/ChattingRoomServer/ReturnParams/BoolWithMsg.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package cn.CSUOSA.ChattingRoomServer.ReturnParams; | ||
|
||
public class BoolWithMsg | ||
{ | ||
boolean success; | ||
String msg; | ||
|
||
public BoolWithMsg(boolean b, String msg) | ||
{ | ||
success = b; | ||
this.msg = msg; | ||
} | ||
|
||
public boolean getSuccess() | ||
{ | ||
return success; | ||
} | ||
|
||
public String getMsg() | ||
{ | ||
return msg; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
server.port=8003 | ||
server.servlet.context-path=/chat | ||
logging.file=baeldung-disabled-console.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<configuration> | ||
<springProperty scope="context" name="LOGFILE" source="spring.application.name"/> | ||
<include resource= | ||
"org/springframework/boot/logging/logback/defaults.xml"/> | ||
<include resource= | ||
"org/springframework/boot/logging/logback/file-appender.xml"/> | ||
<root level="INFO"> | ||
<appender-ref ref="FILE"/> | ||
</root> | ||
</configuration> |