Atualizei os plugins para funcionarem com a nova divisão
This commit is contained in:
1 parent
96b8faca5b
commit
9fb4952f32
6 files changed
+9
-132
No files matched your search
Whitespace-only changes.
@@ -1,20 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<module type="JAVA_MODULE" version="4">
|
|
||||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
|
||||||
<exclude-output />
|
|
||||||
<content url="file://$MODULE_DIR$">
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
|
||||||
</content>
|
|
||||||
<orderEntry type="inheritedJdk" />
|
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
|
||||||
<orderEntry type="module-library">
|
|
||||||
<library>
|
|
||||||
<CLASSES>
|
|
||||||
<root url="jar://$MODULE_DIR$/../pitiupi/dist/pitiupi.jar!/" />
|
|
||||||
</CLASSES>
|
|
||||||
<JAVADOC />
|
|
||||||
<SOURCES />
|
|
||||||
</library>
|
|
||||||
</orderEntry>
|
|
||||||
</component>
|
|
||||||
</module>
|
|
||||||
@@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Generated
+2
-1
@@ -1,5 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_X" default="true" project-jdk-name="openjdk-26" project-jdk-type="JavaSDK">
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_26_PREVIEW" project-jdk-name="openjdk-26" project-jdk-type="JavaSDK">
|
||||||
<output url="file://$PROJECT_DIR$/out" />
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
||||||
@@ -52,12 +52,14 @@ public class ConnectionManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendUdpMulticast(Message message) {
|
public boolean sendUdpMulticast(Message message) {
|
||||||
try {
|
try {
|
||||||
socketUDP.sendMulticast(message);
|
socketUDP.sendMulticast(message);
|
||||||
|
return true;
|
||||||
} catch (Exception _) {
|
} catch (Exception _) {
|
||||||
System.err.println("Error sending UDP Multicast");
|
System.err.println("Error sending UDP Multicast");
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void broadcastLocal(byte[] message) {
|
public void broadcastLocal(byte[] message) {
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ import java.util.logging.Logger;
|
|||||||
* a utilizar o timeout padrão definido por {@link #STANDARD_TIMEOUT}.</p>
|
* a utilizar o timeout padrão definido por {@link #STANDARD_TIMEOUT}.</p>
|
||||||
*/
|
*/
|
||||||
public class ConnectionFactory {
|
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;
|
private static final int STANDARD_TIMEOUT = 300_000;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -64,7 +64,9 @@ public class ConnectionFactory {
|
|||||||
connection.send(handshake.toByteArray());
|
connection.send(handshake.toByteArray());
|
||||||
HandshakeMessage handshakeResponse = validateConnection(connection);
|
HandshakeMessage handshakeResponse = validateConnection(connection);
|
||||||
|
|
||||||
if (handshakeResponse == null) return null;
|
if (handshakeResponse == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
connection.setTimeout(STANDARD_TIMEOUT);
|
connection.setTimeout(STANDARD_TIMEOUT);
|
||||||
|
|
||||||
@@ -102,7 +104,6 @@ public class ConnectionFactory {
|
|||||||
|
|
||||||
if (handshake == null) return null;
|
if (handshake == null) return null;
|
||||||
|
|
||||||
|
|
||||||
connection.send(handshake.createResponse().toByteArray());
|
connection.send(handshake.createResponse().toByteArray());
|
||||||
|
|
||||||
connection.setSender(handshake.getSender());
|
connection.setSender(handshake.getSender());
|
||||||
|
|||||||
Reference in new issue
Block a user