i am going to explode.

This commit is contained in:
Xircon 2026-02-21 23:18:44 -05:00
parent fc61af4b66
commit 5c08c3ffb9
8 changed files with 71 additions and 45 deletions

View File

@ -13,13 +13,13 @@ import javax.swing.*;
import java.awt.*; import java.awt.*;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.io.PrintStream; import java.io.PrintStream;
import java.net.Socket;
import java.util.Objects; import java.util.Objects;
public class Xenon implements Runnable { public class Xenon implements Runnable {
public static void main(String[] args) {new Xenon().start();} public static void main(String[] args) {new Xenon().start();}
public Color buttonColour = new Color(55, 90, 129); public Color buttonColour = new Color(55, 90, 129);
public Image xenonIcon; public Image xenonIcon;
public static JLabel serverName = new JLabel(Networking.ServerName, SwingConstants.CENTER);
static final String propertiesFile = "client.properties"; static final String propertiesFile = "client.properties";
// Properties // Properties
@ -56,6 +56,7 @@ public class Xenon implements Runnable {
logText.setLineWrap(true); logText.setLineWrap(true);
logText.setEditable(false); logText.setEditable(false);
JScrollPane logScrollPane = new JScrollPane(logText); JScrollPane logScrollPane = new JScrollPane(logText);
logScrollPane.setAutoscrolls(true);
logFrame.add(logScrollPane); logFrame.add(logScrollPane);
PrintStream systemOutput = new PrintStream(new CustomOutputStream(logText)); PrintStream systemOutput = new PrintStream(new CustomOutputStream(logText));
System.setOut(systemOutput); System.setOut(systemOutput);
@ -176,7 +177,6 @@ public class Xenon implements Runnable {
send.addActionListener(e -> { send.addActionListener(e -> {
if (TextClient.socket == null || !TextClient.socket.isConnected() || TextClient.socket.isClosed()) {JOptionPane.showMessageDialog(null, "Ensure you are Connected to a Server!", "Error", JOptionPane.ERROR_MESSAGE);} if (TextClient.socket == null || !TextClient.socket.isConnected() || TextClient.socket.isClosed()) {JOptionPane.showMessageDialog(null, "Ensure you are Connected to a Server!", "Error", JOptionPane.ERROR_MESSAGE);}
else { else {
Log.info("Sending " + sendField.getText());
TextClient.messageBuffer = sendField.getText(); TextClient.messageBuffer = sendField.getText();
SwingUtilities.invokeLater(() -> sendField.setText("")); SwingUtilities.invokeLater(() -> sendField.setText(""));
} }
@ -194,7 +194,22 @@ public class Xenon implements Runnable {
centrePanel.add(textarea, BorderLayout.CENTER); centrePanel.add(textarea, BorderLayout.CENTER);
// Side Panel // Side Panel
JPanel sidePanel = sideJPanel(); JPanel sidePanel = new JPanel(new BorderLayout());
sidePanel.setBackground(new Color(60,63,65));
JPanel bottomSidePanel = new JPanel(new BorderLayout());
JPanel topSidePanel = new JPanel(new BorderLayout());
// Mute Button
JToggleButton muteButton = muteJToggleButton();
// Deaf Button
JToggleButton deafButton = deafJToggleButton();
topSidePanel.add(serverName, BorderLayout.NORTH);
bottomSidePanel.add(muteButton, BorderLayout.WEST);
bottomSidePanel.add(deafButton, BorderLayout.CENTER);
sidePanel.add(bottomSidePanel, BorderLayout.SOUTH);
sidePanel.add(topSidePanel, BorderLayout.NORTH);
//Adding Components to the Frame. //Adding Components to the Frame.
mainFrame.getContentPane().add(BorderLayout.NORTH, menubar); mainFrame.getContentPane().add(BorderLayout.NORTH, menubar);
@ -204,22 +219,6 @@ public class Xenon implements Runnable {
mainFrame.setVisible(true); mainFrame.setVisible(true);
} }
private @NonNull JPanel sideJPanel() {
JPanel sidePanel = new JPanel(new BorderLayout());
sidePanel.setBackground(new Color(60,63,65));
JPanel bottomSidePanel = new JPanel(new BorderLayout());
// Mute Button
JToggleButton muteButton = muteJToggleButton();
// Deaf Button
JToggleButton deafButton = deafJToggleButton();
bottomSidePanel.add(muteButton, BorderLayout.WEST);
bottomSidePanel.add(deafButton, BorderLayout.CENTER);
sidePanel.add(bottomSidePanel, BorderLayout.SOUTH);
return sidePanel;
}
private @NonNull JToggleButton deafJToggleButton() { private @NonNull JToggleButton deafJToggleButton() {
JToggleButton deafButton = new JToggleButton("Deafen"); JToggleButton deafButton = new JToggleButton("Deafen");
deafButton.setBackground(buttonColour); deafButton.setBackground(buttonColour);

View File

@ -5,14 +5,14 @@ import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
public class CustomOutputStream extends OutputStream { public class CustomOutputStream extends OutputStream {
private JTextArea textArea; private final JTextArea textArea;
public CustomOutputStream(JTextArea textArea) { public CustomOutputStream(JTextArea textArea) {
this.textArea = textArea; this.textArea = textArea;
} }
@Override @Override
public void write(int b) throws IOException { public void write(int b) {
// redirects data to the text area // redirects data to the text area
textArea.append(String.valueOf((char)b)); textArea.append(String.valueOf((char)b));
// scrolls the text area to the end of data // scrolls the text area to the end of data

View File

@ -2,7 +2,6 @@ package net.xircon.xenon.client.io;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.Appender;
import javax.swing.*; import javax.swing.*;

View File

@ -2,18 +2,18 @@ package net.xircon.xenon.client.networking;
import net.xircon.xenon.client.io.Log; import net.xircon.xenon.client.io.Log;
import javax.annotation.Nullable;
import java.io.IOException; import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Socket; import java.net.Socket;
import java.net.SocketAddress;
import java.net.SocketTimeoutException;
public class Networking { public class Networking {
public static final String NAME_TERMINATOR = "\uffff"; public static final String NAME_TERMINATOR = "\uffff";
public static final String MESSAGE_TERMINATOR = "\ufffe"; public static final String MESSAGE_TERMINATOR = "\ufffe";
public static final String SERVER_ID_START = "\ufff0";
public static final String SERVER_ID_END = "\ufff1";
public static final String SEVER_CONNECTION = "\ufff2";
public static int PortVoIP = 49190; public static int PortVoIP = 49190;
public static int PortText = 49180; public static int PortText = 49180;
public static String ServerName = "";
public static void disconnectFromServer(Socket socket) { public static void disconnectFromServer(Socket socket) {
try { try {

View File

@ -1,9 +1,12 @@
package net.xircon.xenon.client.networking.textclient; package net.xircon.xenon.client.networking.textclient;
import net.xircon.xenon.client.Xenon;
import net.xircon.xenon.client.io.Log; import net.xircon.xenon.client.io.Log;
import net.xircon.xenon.client.networking.Networking; import net.xircon.xenon.client.networking.Networking;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import javax.swing.*;
import java.awt.*;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
@ -14,9 +17,9 @@ import java.net.SocketAddress;
import java.net.SocketTimeoutException; import java.net.SocketTimeoutException;
public class TextClient implements Runnable { public class TextClient implements Runnable {
private String nickname; private final String nickname;
public static String messageBuffer = ""; public static String messageBuffer = "";
private String address; private final String address;
public static Socket socket; public static Socket socket;
public TextClient(String address, String nickname) { public TextClient(String address, String nickname) {
@ -28,27 +31,40 @@ public class TextClient implements Runnable {
try { try {
socket = connectToServer(address, Networking.PortText); socket = connectToServer(address, Networking.PortText);
assert socket != null; assert socket != null;
// Input From Server
// BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream())); new Thread(() -> {
// PrintWriter output = new PrintWriter(socket.getOutputStream(), true); try {
// output.println(nickname + Networking.NAME_TERMINATOR + messageBuffer + Networking.MESSAGE_TERMINATOR);
// String messageFromServer = input.readLine();
// Log.info("Server Message: " + messageFromServer);
PrintWriter output = new PrintWriter(socket.getOutputStream(), true);
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream())); BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
String serverMessage;
while ((serverMessage = input.readLine()) != null) {
if (serverMessage.startsWith(Networking.SERVER_ID_START) && serverMessage.endsWith(Networking.SERVER_ID_END)) {
Log.info("Server Message: " + serverMessage);
String serverName = serverMessage.substring(1, serverMessage.length() - 1);
SwingUtilities.invokeLater(() -> {
Xenon.serverName.setText(serverName);
Xenon.serverName.setForeground(new Color(0, 129, 0));
});
}
Thread.sleep(500);
Log.info("Server Message: " + serverMessage);
}
} catch (IOException | InterruptedException e) {
Log.warn("Could not Read Data!");
}
});
PrintWriter output = new PrintWriter(socket.getOutputStream(), true);
while(socket.isConnected()) { while(socket.isConnected()) {
if (!messageBuffer.isEmpty()) { if (!messageBuffer.isEmpty()) {
output.println(nickname + Networking.NAME_TERMINATOR + messageBuffer + Networking.MESSAGE_TERMINATOR); output.println(nickname + Networking.NAME_TERMINATOR + messageBuffer + Networking.MESSAGE_TERMINATOR);
Log.info("Sending! " + nickname + Networking.NAME_TERMINATOR + messageBuffer + Networking.MESSAGE_TERMINATOR); Log.info("Sending! " + nickname + Networking.NAME_TERMINATOR + messageBuffer + Networking.MESSAGE_TERMINATOR);
messageBuffer = new String(); messageBuffer = "";
String messageFromServer = input.readLine();
Log.info("Server Message: " + messageFromServer);
} else { } else {
Thread.sleep(500); Thread.sleep(500);
} }
} }
} catch (IOException | InterruptedException e) { } catch (IOException | InterruptedException e) {
Log.warn("Could not Read/Send Data!"); Log.warn("Could not Send Data!");
} }
} }

View File

@ -13,7 +13,6 @@ import static net.xircon.xenon.server.networking.Networking.*;
//import java.net. //import java.net.
public class Xenon implements Runnable { public class Xenon implements Runnable {
private Thread serverThread;
public static void main(String[] args) {new Xenon().start();} public static void main(String[] args) {new Xenon().start();}
private static final String propertiesFile = "server.properties"; private static final String propertiesFile = "server.properties";
@ -21,7 +20,7 @@ public class Xenon implements Runnable {
public void start() { public void start() {
serverThread = new Thread(this, "serverThread"); Thread serverThread = new Thread(this, "serverThread");
serverThread.start(); serverThread.start();
} }

View File

@ -2,6 +2,9 @@ package net.xircon.xenon.server.networking;
public class Networking { public class Networking {
public static String ServerName = "Xenon Test Server"; public static String ServerName = "Xenon Test Server";
public static final String SERVER_ID_START = "\ufff0";
public static final String SERVER_ID_END = "\ufff1";
public static final String SEVER_CONNECTION = "\ufff2";
public static int PortVoIP = 49190; public static int PortVoIP = 49190;
public static int PortText = 49180; public static int PortText = 49180;
} }

View File

@ -2,6 +2,7 @@ package net.xircon.xenon.server.networking.textserver;
import net.xircon.xenon.server.io.Log; import net.xircon.xenon.server.io.Log;
import net.xircon.xenon.server.io.database.Database; import net.xircon.xenon.server.io.database.Database;
import net.xircon.xenon.server.networking.Networking;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
@ -18,18 +19,27 @@ public class ClientHandler implements Runnable {
@Override @Override
public void run() { public void run() {
while (clientSocket.isConnected()) try { boolean sentServername = false;
while (clientSocket.isConnected() && !clientSocket.isClosed()) try {
BufferedReader input = new BufferedReader(new InputStreamReader(clientSocket.getInputStream())); BufferedReader input = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
PrintWriter output = new PrintWriter(clientSocket.getOutputStream(), true); PrintWriter output = new PrintWriter(clientSocket.getOutputStream(), true);
clientSocket.setKeepAlive(true);
if (!sentServername) {
Log.info("Sending Server Info to Client");
output.println(Networking.SERVER_ID_START + Networking.ServerName + Networking.SERVER_ID_END);
sentServername = true;
}
String message = input.readLine(); String message = input.readLine();
String[] namedMessage = message.split(Database.NAME_TERMINATOR, -1); String[] namedMessage = message.split(Database.NAME_TERMINATOR, -1);
Log.info("<" + namedMessage[0] + "> " + namedMessage[1]); Log.info("<" + namedMessage[0] + "> " + namedMessage[1]);
Database.write(message); Database.write(message);
output.println("Server Received Message!");
clientSocket.setKeepAlive(true);
} catch (IOException e) { } catch (IOException e) {
Log.warn("Could not Read Message From Client"); Log.warn("Could not Read Message From Client, Closing Connection");
try {
clientSocket.close();
} catch (IOException ex) {
Log.err("Failed to Close Client Socket");
}
} }
} }
} }