package beacon;

import java.awt.*;
import java.net.*;
import java.io.*;
import java.lang.*;
import java.util.*;

public class FirstClient {
  BClient bc;

  public static void main(String args[]){
    new FirstClient(args);
  }

  FirstClient(String args[]) {
    bc = new BClient();
    bc.setServer(args[0]);
    
    bc.setIdentity(args[1], args[2]);
    try {
      System.out.println(bc.setLocation(2020));
    } catch (Exception e) { System.out.println("Dammit: "+e); }

    (new PongThread(bc)).start();
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String what;
    System.out.print("bha> ");
    try {
      while(true){
	while(br.ready() && ((what = br.readLine())!=null)){
	  String cmd, cargs[];
	  cargs = new String[1];
	  int ct=0;
	  StringTokenizer stok = new StringTokenizer(what);
	  cmd = stok.nextToken();
	  while(stok.hasMoreTokens()){
	    cargs[ct] = stok.nextToken();
	    ct++;
	  }
	  if(cmd.equals("where"))
	    System.out.println(bc.requestLocation(cargs[0]));
	  if(cmd.equals("remove"))
	    System.out.println(bc.removeLocation(2020));
	  if(cmd.equals("unhide"))
	    System.out.println(bc.setLocation(2020));
	  if(cmd.equals("passwd"))
	    System.out.println(bc.changePassword(cargs[0]));
	  System.out.print("bha> ");
	}
	Thread.currentThread().yield();
      }
    } catch (Exception e) { System.out.println("OOps: "+e); }
  }
}
