Bugs corrigidos

This commit is contained in:
GustavoHMDS committed 2026-10-07 22:29:20 -03:00
1 parent e5eb4f3f9c
commit 1d9faa93f8
6 files changed
+14 -14

No files matched your search

@@ -91,6 +91,7 @@ public class PrivateChatWindow extends JFrame {
);
connection.send(message.toByteArray());
receiveMessage(message);
messageField.setText("");
@@ -178,6 +178,7 @@ public class PublicChatWindow extends JFrame {
InetAddress ip = InetAddress.getByName(ipField.getText());
pitiupi.sendTcp(msg, ip);
receiveMessage(msg);
} catch (Exception ex) {
Logger.getLogger(
@@ -193,6 +194,7 @@ public class PublicChatWindow extends JFrame {
InetAddress ip = InetAddress.getByName(ipField.getText());
pitiupi.sendUdpUnicast(msg, ip);
receiveMessage(msg);
} catch (Exception ex) {
Logger.getLogger(
@@ -84,6 +84,12 @@ public class MultiProtocolChat extends Plugin {
@Override
public boolean receiveBytes(TcpConnection connection, byte[] bytes) {
MpChatMessage mpChatMessage = parseMessage(bytes);
if (mpChatMessage == null) {
System.out.println("Invalid message received");
return true;
}
else System.out.println(mpChatMessage.getMessage());
privateChatController.receiveMessage(connection, mpChatMessage);
return true;
}
@@ -61,9 +61,10 @@ public class PluginManager {
private Plugin getPlugin(String pluginId) {
for (LoadedPlugin loadedPlugin : loadedPlugins) {
if (loadedPlugin.getPlugin().getIdentifier().equals(pluginId))
if (loadedPlugin.getPlugin().getIdentifier().equals(pluginId)) {
return loadedPlugin.getPlugin();
}
}
return null;
}
@@ -80,7 +81,7 @@ public class PluginManager {
plugin.receivePrivateConnection(connection);
return false;
return true;
}
public void handleDisconnection(TcpConnection connection, String receiverId) {
@@ -117,7 +118,6 @@ public class PluginManager {
ServiceLoader<Plugin> serviceLoader = ServiceLoader.load(Plugin.class, classLoader);
for (Plugin plugin : serviceLoader) {
System.out.println("Loading: " + plugin.getName());
LoadedPlugin loadedPlugin = new LoadedPlugin(plugin, classLoader);
plugin.createPlugin(pitiupi);
@@ -66,8 +66,6 @@ public class SocketTCP extends Thread {
try {
serverSocket = new ServerSocket(connectionManager.getPort());
address = InetAddress.getByName(InetAddress.getLocalHost().getHostAddress());
if (address != null) System.out.println("SocketTCP: "+ address);
else System.out.println("Adress: Null");
} catch (IOException ex) {
System.out.println("There is no socket connection. Sorry.");
System.out.println(ex.toString());
@@ -262,7 +260,6 @@ public class SocketTCP extends Thread {
* @param connection conexão cujo fluxo de entrada será processado.
*/
private void startReceiver(TcpConnection connection) {
System.out.println("Starting TCP connection receiver.");
if (!connection.isPrivate()) {
publicConnectionReceiver(connection);
@@ -275,7 +272,6 @@ public class SocketTCP extends Thread {
}
if (pluginManager.handleConnection(connection, connection.getReceiver())) {
System.out.println("Private connection receiver established.");
privateConnectionReceiver(connection);
}
else {
@@ -351,7 +347,6 @@ public class SocketTCP extends Thread {
while (running) {
try {
byte[] message = connection.receive();
System.out.println("Um plugin recebeu uma mensagem");
InfoMessage sysMessage = InfoMessage.parseSystemInfo(message);
if (sysMessage == null) {
@@ -6,6 +6,7 @@ import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;
import java.net.SocketException;
import java.util.Arrays;
/**
* Representa uma conexão TCP ativa com um peer remoto.
@@ -40,8 +41,6 @@ public class TcpConnection {
this.input = new DataInputStream(socket.getInputStream());
this.output = new DataOutputStream(socket.getOutputStream());
this.address = socket.getInetAddress();
if (address != null) System.out.println("TcpConnection: " + address);
else System.out.println("Adress: Null");
this.lastActivity = System.currentTimeMillis();
this.timeout = 300_000; // 5 minutos
}
@@ -60,8 +59,6 @@ public class TcpConnection {
output.write(message);
output.flush();
updateLastActivity();
System.out.println("TcpConnection enviou uma mensagem de tamanho: " + message.length);
}
/**
@@ -77,12 +74,11 @@ public class TcpConnection {
byte[] receive() throws IOException {
int length = input.readInt();
System.out.println("TcpConnection recebeu uma mensagem de tamanho: " + length);
if (length < 0) throw new IOException("Invalid message length.");
byte[] message = input.readNBytes(length);
if (message.length != length) {
throw new IOException("Connection closed before receiving the complete message.");
}