package voxo.client.actions;
import java.io.IOException;
import java.net.UnknownHostException;
import java.util.EnumSet;
import voxo.client.controllers.ClientController;
import voxo.client.services.NetworkService;
import voxo.client.views.MainView;
import voxo.common.entities.Packet;
import voxo.common.enums.EnumPacket;
import voxo.common.enums.EnumVerbose;
public class LogoutAction {
public LogoutAction(ClientController c, String username, MainView j){
if (c.getVoiceSender() != null) c.getVoiceSender().killSocket();
if (c.getVoiceReceiver() != null) c.getVoiceReceiver().killSocket();
//Supprimer l'identite stockee chez le client
c.setMe(null);
//ressetter la view
c.removeGUIListener(j);
j.dispose();
c.addGUIListener(new MainView(c));
try {
NetworkService.sendPacket(new Packet(EnumPacket.CLIENT_Logout, username));
} catch (UnknownHostException e) {
c.getVerbose().addConsoleMsg(e, EnumSet.of(EnumVerbose.ToConsole, EnumVerbose.ToLog));
new ServerErrorAction(c);
} catch (IOException e) {
c.getVerbose().addConsoleMsg(e, EnumSet.of(EnumVerbose.ToConsole, EnumVerbose.ToLog));
new ServerErrorAction(c);
}
}
}