From 9fb4952f3297cff00d839470efb97a6b7f8573eb Mon Sep 17 00:00:00 2001 From: GustavoHMDS Date: Tue, 29 Sep 2026 11:30:48 -0300 Subject: [PATCH] =?UTF-8?q?Atualizei=20os=20plugins=20para=20funcionarem?= =?UTF-8?q?=20com=20a=20nova=20divis=C3=A3o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pitiupi.testSocket/Makefile | 0 pitiupi.testSocket/pitiupi.testSocket.iml | 20 ---- pitiupi.testSocket/src/plugin/TestChat.java | 107 ------------------ pitiupi/.idea/misc.xml | 3 +- .../pitiupi/control/ConnectionManager.java | 4 +- .../pitiupi/net/tcp/ConnectionFactory.java | 7 +- 6 files changed, 9 insertions(+), 132 deletions(-) create mode 100644 pitiupi.testSocket/Makefile delete mode 100644 pitiupi.testSocket/pitiupi.testSocket.iml delete mode 100644 pitiupi.testSocket/src/plugin/TestChat.java diff --git a/pitiupi.testSocket/Makefile b/pitiupi.testSocket/Makefile new file mode 100644 index 0000000..e69de29 diff --git a/pitiupi.testSocket/pitiupi.testSocket.iml b/pitiupi.testSocket/pitiupi.testSocket.iml deleted file mode 100644 index 4e2cbb3..0000000 --- a/pitiupi.testSocket/pitiupi.testSocket.iml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/pitiupi.testSocket/src/plugin/TestChat.java b/pitiupi.testSocket/src/plugin/TestChat.java deleted file mode 100644 index ddaabdb..0000000 --- a/pitiupi.testSocket/src/plugin/TestChat.java +++ /dev/null @@ -1,107 +0,0 @@ -package plugin; - -import GUI.ChatMenu; -import control.ChatController; -import net.TestChatMessage; -import pitiupi.control.ConnectionManager; -import pitiupi.control.GuiManager; -import pitiupi.net.Message; -import pitiupi.net.tcp.TcpConnection; -import pitiupi.plugin.PrivateConnectionPlugin; - -import javax.swing.*; -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.ObjectInputStream; -import java.net.InetAddress; - -public class TestChat implements PrivateConnectionPlugin{ - ChatController chatController; - ConnectionManager connectionManager; - GuiManager guiManager; - - @Override - public String getName() { - return "MultiProtocol chat"; - } - - @Override - public String getAuthor() { - return "Gustavo Henrique"; - } - - @Override - public String getVersion() { - return "0"; - } - - @Override - public String getIdentifier() { - return "Multi.Protocol.Chat.Pitiupi"; - } - - @Override - public void createPlugin(ConnectionManager connectionManager, GuiManager guiManager) { - this.connectionManager = connectionManager; - this.guiManager = guiManager; - - ChatMenu chatMenu = new ChatMenu(this); - chatController = new ChatController(connectionManager, chatMenu); - guiManager.addMenu(chatMenu); - } - - @Override - public Message getMessage() { - return new TestChatMessage(); - } - - @Override - public void receiveMessage(byte[] message) { - TestChatMessage testChatMessage = parseMessage(message); - chatController.receivePublic(testChatMessage); - } - - - @Override - public void receivePrivateConnection(TcpConnection tcpConnection) { - SwingUtilities.invokeLater(() -> { - chatController.addChatWindow(tcpConnection); - }); - } - - @Override - public void receiveBytes(TcpConnection connection, byte[] bytes) { - TestChatMessage testChatMessage = parseMessage(bytes); - chatController.receivePrivate(connection, testChatMessage); - } - - @Override - public void onSocketClosed(TcpConnection tcpConnection) { - chatController.removeChatWindow(tcpConnection); - } - - public boolean openConnection(String ip) { - try { - connectionManager.connectPluginTcp(InetAddress.getByName(ip), getIdentifier(), getIdentifier()); - return true; - } - catch (Exception e) { - System.out.println("Error opening connection: " + e.getMessage()); - } - return false; - } - - private TestChatMessage parseMessage(byte[] bytes) { - ByteArrayInputStream bis = new ByteArrayInputStream(bytes); - ObjectInputStream ois; - try { - ois = new ObjectInputStream(bis); - if (ois.readObject() instanceof TestChatMessage msg) { - return msg; - } - } catch (IOException | ClassNotFoundException ex) { - System.out.println(ex.toString()); - } - return null; - } -} diff --git a/pitiupi/.idea/misc.xml b/pitiupi/.idea/misc.xml index 8547fc5..0ae1195 100644 --- a/pitiupi/.idea/misc.xml +++ b/pitiupi/.idea/misc.xml @@ -1,5 +1,6 @@ + - + \ No newline at end of file diff --git a/pitiupi/src/pitiupi/control/ConnectionManager.java b/pitiupi/src/pitiupi/control/ConnectionManager.java index 3956b68..8fc360b 100644 --- a/pitiupi/src/pitiupi/control/ConnectionManager.java +++ b/pitiupi/src/pitiupi/control/ConnectionManager.java @@ -52,12 +52,14 @@ public class ConnectionManager { } } - public void sendUdpMulticast(Message message) { + public boolean sendUdpMulticast(Message message) { try { socketUDP.sendMulticast(message); + return true; } catch (Exception _) { System.err.println("Error sending UDP Multicast"); } + return false; } public void broadcastLocal(byte[] message) { diff --git a/pitiupi/src/pitiupi/net/tcp/ConnectionFactory.java b/pitiupi/src/pitiupi/net/tcp/ConnectionFactory.java index 33488fd..954a56e 100644 --- a/pitiupi/src/pitiupi/net/tcp/ConnectionFactory.java +++ b/pitiupi/src/pitiupi/net/tcp/ConnectionFactory.java @@ -24,7 +24,7 @@ import java.util.logging.Logger; * a utilizar o timeout padrĂ£o definido por {@link #STANDARD_TIMEOUT}.

*/ public class ConnectionFactory { - private static final int HANDSHAKE_TIMEOUT = 5000; + private static final int HANDSHAKE_TIMEOUT = 1000; private static final int STANDARD_TIMEOUT = 300_000; /** @@ -64,7 +64,9 @@ public class ConnectionFactory { connection.send(handshake.toByteArray()); HandshakeMessage handshakeResponse = validateConnection(connection); - if (handshakeResponse == null) return null; + if (handshakeResponse == null) { + return null; + } connection.setTimeout(STANDARD_TIMEOUT); @@ -102,7 +104,6 @@ public class ConnectionFactory { if (handshake == null) return null; - connection.send(handshake.createResponse().toByteArray()); connection.setSender(handshake.getSender());