Skip to content

Commit

Permalink
Patch 1.4.1
Browse files Browse the repository at this point in the history
Bug fixes
IP for every user (for cList command)
Icon path fix
-----------------------------------------
Release Version
  • Loading branch information
KatCote committed Jan 13, 2023
1 parent 2b3e3a7 commit a874be8
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 16 deletions.
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
</p>

<p align="center">
<img src="https://img.shields.io/badge/Patch-v1.4.0-success" alt="Patch">
<img src="https://img.shields.io/badge/Patch-v1.4.1-success" alt="Patch">
<img src="https://img.shields.io/badge/Java-openjdk--19-orange" alt="Java">
<img src="https://img.shields.io/badge/License-MIT-red" alt="License">
</p>
Expand All @@ -19,26 +19,26 @@ Project in progress.

Project run on Java 19 and contains all the necessary libraries.

`Config.ini` - Contains a ip, port, client window size and default theme changes.
`Config.ini` - Contains a ip, port, client window size and default theme changes

`Settings.ini` - Contains a User settings for Client.
`Settings.ini` - Contains a User settings for Client

`.idea` - Intellij IDEA run files and Libs.
`.idea` - Intellij IDEA run files and Libs

`src` - Resourses for both sides (Client-Server).
`src` - Resourses for both sides (Client-Server)

`chat-server` - server platform at configs port, ByteBuffer message Client-Server data exchange.
Has console for CMD or IDE.
`chat-server` - server platform at configs port, ByteBuffer message Client-Server data exchange
Has console for CMD or IDE

`chat-client` - client platform with "/" commads to server. Has GUI with Dark CSS Style (it is not CMD).
`chat-client` - client platform with "/" commads to server. Has GUI with switchable theme

Client commands:

`/changename` - Change client name to NotNull (or space at all) for all clients and on a server

`/exit` - Exit chat from both sides

`/motd` - Set MOTD for new clients
`/motd` - Set MOTD for new clients or show MOTD

`/help` - Show page with all commands

Expand All @@ -48,7 +48,7 @@ Server commands:

`motd` - Set MOTD for new clients

`clist` - List of all clients is this session (online)
`clist` - List of all clients is this session (online) with IP

`help` - Show page with all commands

Expand Down
3 changes: 2 additions & 1 deletion Settings.ini
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#Return to default Username
#Changed a current theme
#Fri Jan 13 03:46:17 MSK 2023
CURRENT_THEME=dark-theme.css
USERNAME=default
USERNAME_CHECKBOX=true
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ public void start(Stage primaryStage) throws Exception {
.getPath(), StandardCharsets.UTF_8));

String classDirectory = currentClass.getParent();
String urlBase = classDirectory.substring(0, classDirectory.length() - 26);
String urlBase = classDirectory.substring(0, classDirectory.length() - 19);
iconURL = urlBase.split(":")[0] +
":/" + urlBase.substring(2).replaceAll("\\\\", "/") +
"/CSChat/chat-client/src/main/resources/com.katcote.chatclient/images/icon.png";
"/chat-client/src/main/resources/com.katcote.chatclient/images/icon.png";

int WIDTH = Integer.parseInt(props.getProperty("W_WIDTH"));
int HEIGHT = Integer.parseInt(props.getProperty("W_HEIGHT"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,13 @@ protected synchronized void decode(ChannelHandlerContext ctx, ByteBuf msg, List<
return;
}

out.add("\n" + msg.toString(charset).substring(12) + "\n");
String msg_decoded = msg.toString(charset).substring(12);

while (msg_decoded.contains("[SERVER_MSG]")) {
msg_decoded = msg_decoded.replace("[SERVER_MSG]", "");
}

out.add("\n" + msg_decoded + "\n");
return;
}
try {
Expand Down
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ static class serverConsole extends Thread {
private static void csCommand(String command) {
switch (command.toLowerCase().split(" ")[0]) {
case "stop" -> {
System.out.print("\n>>>");
MainHandler.stopServer();
try {
sleep(5000);
Expand Down Expand Up @@ -40,7 +41,9 @@ private static void csCommand(String command) {
break;
}
for (int i = 0; i < MainHandler.cList().size(); i++) {
System.out.println(i + " | " + MainHandler.cList().get(i));
System.out.println(i
+ " | " + MainHandler.cList().get(i)
+ " | " + MainHandler.cListIP().get(i));
}
}

Expand Down
17 changes: 17 additions & 0 deletions chat-server/src/main/java/com/katcote/chatserver/MainHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,21 @@ public class MainHandler extends SimpleChannelInboundHandler<String> {

private static final List<Channel> channelsList = new ArrayList<>();
private static final List<String> userNameList = new ArrayList<>();
private static final List<String> userIPList = new ArrayList<>();
private String clientName;
private static int newClientIndex = 1;

@Override
public void channelActive(ChannelHandlerContext ctx) {
System.out.println("Client is connected: " + ctx);
System.out.print("\n>>>");
ctx.writeAndFlush("[SERVER_MSG]Wait_for_username");
clientName = "Client #" + newClientIndex;
channelsList.add(ctx.channel());
userNameList.add(clientName);
userIPList.add(String.valueOf(ctx)
.substring(0, String.valueOf(ctx).length()-2)
.split("/")[2]);
newClientIndex++;
}

Expand All @@ -41,6 +46,7 @@ protected void channelRead0(ChannelHandlerContext ctx, String msg) {
clientName = preClientName;

System.out.println("USERNAME: " + clientNameBuf + " -> " + clientName);
System.out.print("\n>>>");
sysMessage(clientNameBuf + " changed name to " + clientName + "\n");

int bufIndex = channelsList.indexOf(ctx.channel());
Expand All @@ -52,8 +58,10 @@ protected void channelRead0(ChannelHandlerContext ctx, String msg) {
}
case "/exit" -> {
System.out.println(clientName + " left");
System.out.print("\n>>>");
sysMessage(clientName + " left\n");
userNameList.remove(channelsList.indexOf(ctx.channel()));
userIPList.remove(channelsList.indexOf(ctx.channel()));
channelsList.remove(ctx.channel());
ctx.close();
return;
Expand All @@ -64,6 +72,7 @@ protected void channelRead0(ChannelHandlerContext ctx, String msg) {
return;
}
System.out.println("MOTD: " + ServerApplication.MOTD + " -> " + msg.substring(6));
System.out.print("\n>>>");
ServerApplication.MOTD = msg.substring(6);
sysMessage("New MOTD: " + ServerApplication.MOTD + "\n");
return;
Expand All @@ -87,6 +96,8 @@ protected void channelRead0(ChannelHandlerContext ctx, String msg) {
userNameList.add(bufIndex, clientName);
}
ctx.writeAndFlush("[SERVER_MSG]" + ServerApplication.MOTD + "\n");
ctx.writeAndFlush("\n");
sysMessage(clientName + " join\n");
return;
}
broadcastMessage(msg, clientName);
Expand All @@ -108,8 +119,13 @@ public static List cList() {
return userNameList;
}

public static List cListIP() {
return userIPList;
}

public void broadcastMessage(String msg, String clientName) {
System.out.printf("%s: %s [%s]%n", new java.util.Date(), msg, clientName);
System.out.print("\n>>>");
String out = String.format("[%s]: %s\n", clientName, msg);
for (io.netty.channel.Channel c : channelsList) {
c.writeAndFlush(out);
Expand All @@ -119,6 +135,7 @@ public void broadcastMessage(String msg, String clientName) {
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
System.out.println(("Client " + clientName + " is closed."));
System.out.print("\n>>>");
sysMessage(clientName + " left\n");
userNameList.remove(channelsList.indexOf(ctx.channel()));
channelsList.remove(ctx.channel());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

public class ServerApplication {

public static String MOTD = "CSChat System v1.4.0 Stable";
public static String MOTD = "CSChat System v1.4.1 Stable";
public static final String MOTD_DEF = MOTD;

public static void main(String[] args) {
Expand Down
Binary file not shown.
Binary file modified chat-server/target/classes/com/katcote/chatserver/MainHandler.class
Binary file not shown.

0 comments on commit a874be8

Please sign in to comment.