import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.*;
import java.util.Scanner;  // Import the Scanner class

public class User {
	
	protected InetAddress addIP;
	protected String pseudo;
	protected int nport;
	protected boolean actif;

	public User(int nport){
		try
		{
			this.addIP = InetAddress.getLocalHost();
		}
		catch(UnknownHostException e) {
			System.out.println("Could not find local address!");
		}
		
		this.nport = nport;
		this.actif = true;
		
	}
	
	
	public InetAddress getAddIP() {
		return addIP;
	}


	public void setAddIP(InetAddress addIP) {
		this.addIP = addIP;
	}


	public String getPseudo() {
		return pseudo;
	}


	public void setPseudo() {
	    Scanner myObj = new Scanner(System.in);  // Create a Scanner object
	    System.out.println("Enter pseudo :");
	    String tmpPseudo = myObj.nextLine();  // Read user input

		while(not(this.validatePseudo(tmpPseudo))) {
			System.out.println("Already taken, choose another one :");
		    tmpPseudo = myObj.nextLine();  // Read user input
		}
		
		this.pseudo = tmpPseudo;
	}
	
	public Boolean validatePseudo(String tmpPseudo) {
		// Call broadcast 
		InetAddress broadcastIP = InetAddress.getLocalHost(); // change to broadcast
		
		DatagramSocket dgramSocket = new DatagramSocket(1001,addIP);
		byte[] buffer = new byte[256];
		
		DatagramPacket outPacket= newDatagramPacket(tmpPseudo.getBytes(), tmpPseudo.length(),broadcastIP, 1001);
		
		
		

		Socket link = new Socket(addIP,2);
		
		return 
	}


	public int getNport() {
		return nport;
	}


	public void setNport(int nport) {
		this.nport = nport;
	}


	public boolean isActif() {
		return actif;
	}


	public void setActif(boolean actif) {
		this.actif = actif;
	}

	

	public static void main(String[] args) {
			User usr1 = new User(3);
			usr1.setPseudo();
	}
}
