feature/separacao-gerenciadores #1

Merged
gustavo merged 31 commits from feature/separacao-gerenciadores into main 2026-09-30 18:34:54 -03:00
Showing only changes of commit 93ac292f72 - Show all commits
+22 -1
View File
@@ -15,6 +15,7 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import pitiupi.net.HeartbeatMessage;
import pitiupi.net.Message;
import pitiupi.plugin.Plugin;
/**
@@ -147,9 +148,15 @@ public class SocketUDP extends Thread {
main.getHeartbeatManager().receiveHeartbeat(heartbeat, msgPacket.getAddress());
continue;
}
Message message = tryParseMessage(msgPacket.getData());
if (message == null) {
continue;
}
for (Plugin plugin : main.getPlugins()) {
System.out.println(msgPacket.getAddress().toString());
plugin.receiveMessage(msgPacket.getData());
plugin.receiveMessage(message);
}
}
}
@@ -172,6 +179,20 @@ public class SocketUDP extends Thread {
}
}
private Message tryParseMessage(byte[] data) {
try {
ByteArrayInputStream bis = new ByteArrayInputStream(data);
ObjectInputStream ois = new ObjectInputStream(bis);
Object object = ois.readObject();
if (object instanceof Message message) return message;
return null;
} catch (IOException | ClassNotFoundException ex) {
return null;
}
}
/**
* Inicia a recepção de mensagens UDP.
*/