Author SHA1 Message Date
GustavoHMDS 1d9faa93f8 Bugs corrigidos 2026-10-07 22:29:20 -03:00
GustavoHMDS e5eb4f3f9c WIP: Fazendo testes 2026-10-07 20:38:57 -03:00
GustavoHMDS 581a924afc BugFix e atualização da interface no mpChat 2026-10-07 19:31:37 -03:00
GustavoHMDS 7a699cd280 Arquivos faltando no commit anterior 2026-10-07 17:13:03 -03:00
GustavoHMDS 88b75ad75f WIP: atualizar o mpChat para os novos menus 2026-10-07 16:59:08 -03:00
31 changed files with 453 additions and 236 deletions

No files matched your search

+5
View File
@@ -0,0 +1,5 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
+5
View File
@@ -0,0 +1,5 @@
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_X" default="true" project-jdk-name="openjdk-26" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
+8
View File
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/pitiupi.mpChat.iml" filepath="$PROJECT_DIR$/pitiupi.mpChat.iml" />
</modules>
</component>
</project>
+6
View File
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
-40
View File
@@ -1,40 +0,0 @@
package GUI;
import pitiupi.models.Menus.MenuCategory;
import pitiupi.models.Menus.MulticastMenus.MulticastSubMenu;
import plugin.MultiProtocolChat;
import javax.swing.*;
import java.awt.*;
public class ChatMenu extends MulticastSubMenu {
private final MultiProtocolChat multiProtocolChat;
public ChatMenu(MultiProtocolChat multiProtocolChat) {
this.multiProtocolChat = multiProtocolChat;
this.setText("MP-Chat");
JMenuItem startPrivateChat = new JMenuItem("start Private Chat");
startPrivateChat.addActionListener(e -> showPrivateChatDialog());
this.add(startPrivateChat);
}
public void newMenuItem(JMenuItem newMenuItem, ChatWindow chatWindow) {
newMenuItem.addActionListener(e -> chatWindow.setVisible(true));
this.add(newMenuItem);
}
public void removeMenuItem(JMenuItem removeMenuItem) {
this.remove(removeMenuItem);
}
private void showPrivateChatDialog() {
}
@Override
public String getText() {
return "MP-Chat";
}
}
-94
View File
@@ -1,94 +0,0 @@
package GUI;
import net.MpChatMessage;
import pitiupi.control.ConnectionManager;
import javax.swing.*;
import java.awt.*;
import java.net.InetAddress;
import java.net.UnknownHostException;
public abstract class ChatWindow extends JFrame {
protected final ConnectionManager connectionManager;
private JTextArea receivedMessagesArea;
protected JTextField messageField;
public ChatWindow(ConnectionManager connectionManager) {
this.connectionManager = connectionManager;
initComponents();
}
private void initComponents() {
setTitle("Socket Test");
setSize(700, 500);
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
JPanel mainPanel = new JPanel(new BorderLayout(10, 10));
mainPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
initReceivedMessagesPanel(mainPanel);
initBottomPanel(mainPanel);
setContentPane(mainPanel);
}
private void initReceivedMessagesPanel(JPanel mainPanel) {
receivedMessagesArea = new JTextArea();
receivedMessagesArea.setEditable(false);
receivedMessagesArea.setLineWrap(true);
receivedMessagesArea.setWrapStyleWord(true);
JScrollPane messagesScrollPane = new JScrollPane(receivedMessagesArea);
messagesScrollPane.setBorder(BorderFactory.createTitledBorder("Mensagens recebidas"));
mainPanel.add(messagesScrollPane, BorderLayout.CENTER);
}
private void initBottomPanel(JPanel mainPanel) {
messageField = new JTextField();
JPanel bottomPanel = new JPanel(new BorderLayout(10, 10));
bottomPanel.add(messageField, BorderLayout.CENTER);
initButtons(bottomPanel);
mainPanel.add(bottomPanel, BorderLayout.SOUTH);
}
protected abstract void initButtons(JPanel bottomPanel);
protected MpChatMessage createMessage(String tipoMensagem) {
try {
String nome = connectionManager.getUserName();
String ip = InetAddress.getLocalHost().getHostAddress();
String message = messageField.getText();
return new MpChatMessage(nome, ip, tipoMensagem, message);
} catch (UnknownHostException e) {
throw new RuntimeException(e);
}
}
public void receiveMessage(MpChatMessage msg) {
SwingUtilities.invokeLater(() -> {
String mensagem = String.format(
"[%s] %s (%s): %s%n",
msg.getTipoMensagem(),
msg.getNome(),
msg.getIp(),
msg.getMessage()
);
receivedMessagesArea.append(mensagem);
receivedMessagesArea.setCaretPosition(receivedMessagesArea.getDocument().getLength());
});
}
}
@@ -2,10 +2,10 @@ package GUI;
import pitiupi.models.Menus.MulticastMenus.MulticastActionMenu;
public class PublicChatMenu extends MulticastActionMenu {
public class MulticastMpChatMenu extends MulticastActionMenu {
PublicChatWindow publicChatWindow;
PublicChatMenu(PublicChatWindow publicChatWindow) {
public MulticastMpChatMenu(PublicChatWindow publicChatWindow) {
this.publicChatWindow = publicChatWindow;
}
@@ -14,8 +14,9 @@ public class PublicChatMenu extends MulticastActionMenu {
publicChatWindow.setVisible(true);
}
@Override
public String getText() {
return "";
return "MP-Chat";
}
}
@@ -1,38 +0,0 @@
package GUI;
import control.ChatController;
import pitiupi.models.Menus.UnicastMenus.UnicastActionMenu;
import pitiupi.models.User;
import plugin.MultiProtocolChat;
import javax.swing.*;
import java.awt.*;
import java.net.InetAddress;
public class PrivateChatMenu extends UnicastActionMenu {
PrivateChatWindow privateChatWindow;
private final MultiProtocolChat multiProtocolChat;
private final ChatController chatController;
public PrivateChatMenu(PrivateChatWindow PrivateChatWindow, MultiProtocolChat multiProtocolChat, ChatController chatController) {
this.privateChatWindow = PrivateChatWindow;
this.multiProtocolChat = multiProtocolChat;
this.chatController = chatController;
}
@Override
public void onClick(User user) {
if (multiProtocolChat.openConnection(user.getAddress())
else errorLabel.setVisible(true);
dialog.setContentPane(contentPanel);
dialog.pack();
dialog.setLocationRelativeTo(SwingUtilities.getWindowAncestor(privateChatWindow));
dialog.setVisible(true);
}
@Override
public String getText() {
return "start Private Chat";
}
}
+93 -14
View File
@@ -1,43 +1,122 @@
package GUI;
import net.MpChatMessage;
import pitiupi.control.ConnectionManager;
import pitiupi.net.tcp.TcpConnection;
import pitiupi.plugin.Pitiupi;
import javax.swing.*;
import java.awt.*;
import java.net.InetAddress;
import java.util.logging.Level;
import java.util.logging.Logger;
public class PrivateChatWindow extends ChatWindow {
public class PrivateChatWindow extends JFrame {
private final Pitiupi pitiupi;
private final TcpConnection connection;
public PrivateChatWindow(ConnectionManager ConnectionManager, TcpConnection connection) {
super(ConnectionManager);
private final JTextArea receivedMessagesArea;
private final JTextField messageField;
public PrivateChatWindow(
Pitiupi pitiupi,
TcpConnection connection
) {
this.pitiupi = pitiupi;
this.connection = connection;
}
@Override
protected void initButtons(JPanel bottomPanel) {
setTitle("Chat privado");
setSize(700, 500);
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
JPanel mainPanel = new JPanel(new BorderLayout(10, 10));
mainPanel.setBorder(
BorderFactory.createEmptyBorder(10, 10, 10, 10)
);
receivedMessagesArea = new JTextArea();
receivedMessagesArea.setEditable(false);
receivedMessagesArea.setLineWrap(true);
receivedMessagesArea.setWrapStyleWord(true);
JScrollPane messagesScrollPane =
new JScrollPane(receivedMessagesArea);
messagesScrollPane.setBorder(
BorderFactory.createTitledBorder("Mensagens")
);
mainPanel.add(
messagesScrollPane,
BorderLayout.CENTER
);
JPanel bottomPanel = new JPanel(
new BorderLayout(10, 10)
);
messageField = new JTextField();
JButton tcpButton = new JButton("TCP");
tcpButton.addActionListener(e -> sendTCP());
JPanel buttonsPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT, 5, 0));
bottomPanel.add(
messageField,
BorderLayout.CENTER
);
buttonsPanel.add(tcpButton);
bottomPanel.add(
tcpButton,
BorderLayout.EAST
);
bottomPanel.add(buttonsPanel, BorderLayout.EAST);
mainPanel.add(
bottomPanel,
BorderLayout.SOUTH
);
setContentPane(mainPanel);
}
private void sendTCP() {
try {
MpChatMessage msg = createMessage("TCP Private");
connection.send(msg.toByteArray());
String nome = pitiupi.getUserName();
MpChatMessage message = new MpChatMessage(
nome,
InetAddress.getLocalHost().getHostAddress(),
"TCP Private",
messageField.getText()
);
connection.send(message.toByteArray());
receiveMessage(message);
messageField.setText("");
} catch (Exception ex) {
Logger.getLogger(PrivateChatWindow.class.getName()).log(Level.SEVERE, null, ex);
Logger.getLogger(
PrivateChatWindow.class.getName()
).log(Level.SEVERE, null, ex);
}
}
public void receiveMessage(MpChatMessage message) {
SwingUtilities.invokeLater(() -> {
String texto = String.format(
"[%s] %s (%s): %s%n",
message.getTipoMensagem(),
message.getNome(),
message.getIp(),
message.getMessage()
);
receivedMessagesArea.append(texto);
receivedMessagesArea.setCaretPosition(
receivedMessagesArea.getDocument().getLength()
);
});
}
}
+141 -16
View File
@@ -2,36 +2,95 @@ package GUI;
import net.MpChatMessage;
import pitiupi.control.ConnectionManager;
import pitiupi.plugin.Pitiupi;
import javax.swing.*;
import javax.swing.text.BadLocationException;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyledDocument;
import java.awt.*;
import java.net.InetAddress;
import java.util.logging.Level;
import java.util.logging.Logger;
public class PublicChatWindow extends ChatWindow {
public class PublicChatWindow extends JFrame {
private final Pitiupi pitiupi;
private JTextPane receivedMessagesArea;
private JTextField messageField;
private JTextField ipField;
public PublicChatWindow(ConnectionManager connectionManager) {
super(connectionManager);
public PublicChatWindow(Pitiupi pitiupi) {
this.pitiupi = pitiupi;
initComponents();
}
@Override
protected void initButtons(JPanel bottomPanel) {
private void initComponents() {
setTitle("Public Chat");
setSize(700, 500);
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
JPanel mainPanel = new JPanel(new BorderLayout(10, 10));
mainPanel.setBorder(
BorderFactory.createEmptyBorder(10, 10, 10, 10)
);
initReceivedMessagesPanel(mainPanel);
initBottomPanel(mainPanel);
setContentPane(mainPanel);
}
private void initReceivedMessagesPanel(JPanel mainPanel) {
receivedMessagesArea = new JTextPane();
receivedMessagesArea.setEditable(false);
JScrollPane messagesScrollPane = new JScrollPane(receivedMessagesArea);
messagesScrollPane.setBorder(
BorderFactory.createTitledBorder("Mensagens recebidas")
);
mainPanel.add(messagesScrollPane, BorderLayout.CENTER);
}
private void initBottomPanel(JPanel mainPanel) {
messageField = new JTextField();
JPanel bottomPanel = new JPanel(
new BorderLayout(10, 10)
);
bottomPanel.add(messageField, BorderLayout.CENTER);
initIpField(bottomPanel);
initCommunicationButtons(bottomPanel);
mainPanel.add(bottomPanel, BorderLayout.SOUTH);
}
private void initIpField(JPanel bottomPanel) {
ipField = new JTextField();
ipField.setPreferredSize(new Dimension(130, 30));
JPanel ipPanel = new JPanel(new BorderLayout(5, 5));
JPanel ipPanel = new JPanel(
new BorderLayout(5, 5)
);
ipPanel.add(new JLabel("IP destino:"), BorderLayout.WEST);
ipPanel.add(
new JLabel("IP destino:"),
BorderLayout.WEST
);
ipPanel.add(ipField, BorderLayout.CENTER);
ipPanel.add(
ipField,
BorderLayout.CENTER
);
bottomPanel.add(ipPanel, BorderLayout.WEST);
}
@@ -45,13 +104,71 @@ public class PublicChatWindow extends ChatWindow {
udpButton.addActionListener(e -> sendUDP());
multicastButton.addActionListener(e -> sendMulticast());
JPanel buttonsPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT, 5, 0));
JPanel buttonsPanel = new JPanel(
new FlowLayout(FlowLayout.RIGHT, 5, 0)
);
buttonsPanel.add(tcpButton);
buttonsPanel.add(udpButton);
buttonsPanel.add(multicastButton);
bottomPanel.add(buttonsPanel, BorderLayout.EAST);
bottomPanel.add(
buttonsPanel,
BorderLayout.EAST
);
}
private MpChatMessage createMessage(String tipoMensagem) {
try {
String nome = pitiupi.getUserName();
String ip = InetAddress.getLocalHost().getHostAddress();
String message = messageField.getText();
return new MpChatMessage(
nome,
ip,
tipoMensagem,
message
);
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
public void receiveMessage(MpChatMessage msg) {
SwingUtilities.invokeLater(() -> {
String mensagem = String.format(
"[%s] %s (%s): %s%n",
msg.getTipoMensagem(),
msg.getNome(),
msg.getIp(),
msg.getMessage()
);
StyledDocument document = receivedMessagesArea.getStyledDocument();
SimpleAttributeSet attributes = new SimpleAttributeSet();
if (msg.getTipoMensagem().equals("TCP Unicast") || msg.getTipoMensagem().equals("UDP Unicast")) {
StyleConstants.setForeground(attributes, new Color(128, 0, 128));
}
try {
document.insertString(
document.getLength(),
mensagem,
attributes
);
receivedMessagesArea.setCaretPosition(
document.getLength()
);
} catch (BadLocationException ex) {
Logger.getLogger(PublicChatWindow.class.getName()).log(Level.SEVERE, null, ex);
}
});
}
private void sendTCP() {
@@ -60,10 +177,13 @@ public class PublicChatWindow extends ChatWindow {
InetAddress ip = InetAddress.getByName(ipField.getText());
connectionManager.sendTcp(msg, ip);
pitiupi.sendTcp(msg, ip);
receiveMessage(msg);
} catch (Exception ex) {
Logger.getLogger(PublicChatWindow.class.getName()).log(Level.SEVERE, null, ex);
Logger.getLogger(
PublicChatWindow.class.getName()
).log(Level.SEVERE, null, ex);
}
}
@@ -73,10 +193,13 @@ public class PublicChatWindow extends ChatWindow {
InetAddress ip = InetAddress.getByName(ipField.getText());
connectionManager.sendUdpUnicast(msg, ip);
pitiupi.sendUdpUnicast(msg, ip);
receiveMessage(msg);
} catch (Exception ex) {
Logger.getLogger(PublicChatWindow.class.getName()).log(Level.SEVERE, null, ex);
Logger.getLogger(
PublicChatWindow.class.getName()
).log(Level.SEVERE, null, ex);
}
}
@@ -84,10 +207,12 @@ public class PublicChatWindow extends ChatWindow {
try {
MpChatMessage msg = createMessage("UDP Multicast");
connectionManager.sendUdpMulticast(msg);
pitiupi.sendUdpMulticast(msg);
} catch (Exception ex) {
Logger.getLogger(PublicChatWindow.class.getName()).log(Level.SEVERE, null, ex);
Logger.getLogger(
PublicChatWindow.class.getName()
).log(Level.SEVERE, null, ex);
}
}
}
@@ -0,0 +1,26 @@
package GUI;
import control.PrivateChatController;
import pitiupi.models.Menus.UnicastMenus.UnicastActionMenu;
import pitiupi.models.User;
public class UnicastMpChatMenu extends UnicastActionMenu {
private final PrivateChatController controller;
public UnicastMpChatMenu(
PrivateChatController controller
) {
this.controller = controller;
}
@Override
public void onClick(User user) {
controller.openChat(user);
}
@Override
public String getText() {
return "Start Private Chat";
}
}
@@ -0,0 +1,116 @@
package control;
import GUI.PrivateChatWindow;
import net.MpChatMessage;
import pitiupi.models.User;
import pitiupi.net.tcp.TcpConnection;
import pitiupi.plugin.Pitiupi;
import plugin.MultiProtocolChat;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
public class PrivateChatController {
private final Pitiupi pitiupi;
private final MultiProtocolChat multiProtocolChat;
/*
* Relaciona o endereço do usuário à janela de chat.
*/
private final Map<String, PrivateChatWindow> windows;
/*
* Endereços para os quais uma conexão já foi solicitada,
* mas ainda não chegou.
*/
private final Set<String> pendingConnections;
public PrivateChatController(
Pitiupi pitiupi,
MultiProtocolChat multiProtocolChat
) {
this.pitiupi = pitiupi;
this.multiProtocolChat = multiProtocolChat;
this.windows = new HashMap<>();
this.pendingConnections = new HashSet<>();
}
public void openChat(User user) {
String address = user.getAddress().getHostAddress();
PrivateChatWindow window = windows.get(address);
/*
* Já existe uma janela para esse usuário.
*/
if (window != null) {
window.setVisible(true);
window.toFront();
window.requestFocus();
return;
}
/*
* Já estamos esperando uma conexão para esse usuário.
*/
if (pendingConnections.contains(address)) {
return;
}
/*
* Ainda não existe conexão.
*/
pendingConnections.add(address);
multiProtocolChat.openConnection(address);
}
public void receiveMessage(TcpConnection connection, MpChatMessage message) {
String address = connection.getAddress().toString();
PrivateChatWindow window = windows.get(address);
if (window == null) {
return;
}
window.receiveMessage(message);
}
/**
* Deve ser chamado quando uma nova conexão privada chegar.
*/
public void connectionReceived(TcpConnection connection) {
String address = connection.getAddress().toString();
pendingConnections.remove(address);
PrivateChatWindow window = new PrivateChatWindow(
pitiupi,
connection
);
windows.put(address, window);
window.setVisible(true);
window.toFront();
window.requestFocus();
}
/**
* Fecha a janela e remove o relacionamento.
*/
public void closeChat(TcpConnection connection) {
String address = connection.getAddress().toString();
PrivateChatWindow window = windows.remove(address);
if (window != null) {
window.dispose();
}
}
}
@@ -1,24 +1,29 @@
package plugin;
import GUI.ChatMenu;
import control.ChatController;
import GUI.MulticastMpChatMenu;
import GUI.PrivateChatWindow;
import GUI.PublicChatWindow;
import GUI.UnicastMpChatMenu;
import control.PrivateChatController;
import net.MpChatMessage;
import pitiupi.control.ConnectionManager;
import pitiupi.control.GuiManager;
import pitiupi.models.Menus.MenuCategory;
import pitiupi.models.Messages.Message;
import pitiupi.net.tcp.TcpConnection;
import pitiupi.models.Plugin;
import pitiupi.plugin.Pitiupi;
import javax.swing.*;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.net.InetAddress;
import java.util.List;
public class MultiProtocolChat extends Plugin {
ChatController chatController;
ConnectionManager connectionManager;
GuiManager guiManager;
Pitiupi pitiupi;
PrivateChatController privateChatController;
PublicChatWindow publicChatWindow;
@Override
public String getName() {
@@ -41,30 +46,37 @@ public class MultiProtocolChat extends Plugin {
}
@Override
public void createPlugin(ConnectionManager connectionManager, GuiManager guiManager) {
this.connectionManager = connectionManager;
this.guiManager = guiManager;
public void createPlugin(Pitiupi pitiupi) {
this.pitiupi = pitiupi;
ChatMenu chatMenu = new ChatMenu(this);
chatController = new ChatController(connectionManager, chatMenu);
guiManager.addMulticastMenu(chatMenu);
privateChatController = new PrivateChatController(pitiupi, this);
publicChatWindow = new PublicChatWindow(pitiupi);
MulticastMpChatMenu multicastMpChatMenu = new MulticastMpChatMenu(publicChatWindow);
UnicastMpChatMenu unicastMpChatMenu = new UnicastMpChatMenu(privateChatController);
pitiupi.createMenu(MenuCategory.Social, multicastMpChatMenu);
pitiupi.createMenu(MenuCategory.Social, unicastMpChatMenu);
}
@Override
public Message getMessage() {
return new MpChatMessage();
public List<Class<? extends Message>> getMessages() {
return List.of(MpChatMessage.class);
}
@Override
public void receiveMessage(byte[] message) {
MpChatMessage mpChatMessage = parseMessage(message);
chatController.receivePublic(mpChatMessage);
public void receiveMessage(Message message) {
if (message instanceof MpChatMessage mpChatMessage) {
publicChatWindow.receiveMessage(mpChatMessage);
}
}
@Override
public boolean receivePrivateConnection(TcpConnection connection) {
SwingUtilities.invokeLater(() -> {
chatController.addChatWindow(connection);
privateChatController.connectionReceived(connection);
});
return true;
}
@@ -72,25 +84,29 @@ public class MultiProtocolChat extends Plugin {
@Override
public boolean receiveBytes(TcpConnection connection, byte[] bytes) {
MpChatMessage mpChatMessage = parseMessage(bytes);
chatController.receivePrivate(connection, mpChatMessage);
if (mpChatMessage == null) {
System.out.println("Invalid message received");
return true;
}
else System.out.println(mpChatMessage.getMessage());
privateChatController.receiveMessage(connection, mpChatMessage);
return true;
}
@Override
public boolean onSocketClosed(TcpConnection connection) {
chatController.removeChatWindow(connection);
privateChatController.closeChat(connection);
return true;
}
public boolean openConnection(String ip) {
public void openConnection(String ip) {
try {
connectionManager.connectPluginTcp(InetAddress.getByName(ip), getIdentifier(), getIdentifier());
return true;
pitiupi.connectTcp(InetAddress.getByName(ip), getIdentifier(), getIdentifier());
}
catch (Exception e) {
System.out.println("Error opening connection: " + e.getMessage());
}
return false;
}
private MpChatMessage parseMessage(byte[] bytes) {
-1
View File
@@ -111,7 +111,6 @@ public class MenuBar extends JMenuBar {
}
public void addPluginMenu(MenuCategory category, JMenuItem menu){
System.out.println("addPluginMenu");
categories.get(category).add(menu);
}
}
@@ -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);
+3 -2
View File
@@ -271,8 +271,9 @@ public class SocketTCP extends Thread {
return;
}
if (pluginManager.handleConnection(connection, connection.getReceiver()))
if (pluginManager.handleConnection(connection, connection.getReceiver())) {
privateConnectionReceiver(connection);
}
else {
InfoMessage.sendSystemInfo(
connection,
@@ -336,7 +337,7 @@ public class SocketTCP extends Thread {
* ao plugin destinatário.
*
* <p>Dados que não representam mensagens de controle são entregues
* diretamente ao {@link PrivateConnectionPlugin}. Mensagens de controle
* diretamente ao {@link pitiupi.models.Plugin}. Mensagens de controle
* relacionadas ao encerramento ou a erros internos provocam a notificação
* do plugin e o fechamento da conexão.</p>
*
@@ -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.
@@ -77,6 +78,7 @@ public class TcpConnection {
byte[] message = input.readNBytes(length);
if (message.length != length) {
throw new IOException("Connection closed before receiving the complete message.");
}