package test;

import java.net.UnknownHostException;
import java.util.ArrayList;
import org.json.JSONObject;
import rsx.BomberStudentClient;
import rsx.BomberStudentRequest;
import rsx.tcp.TcpClient;

/**
 * Exemple appel vers le serveur
 * @author Arthur Brandao
 */
public class ServerTest {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws InterruptedException {
        
        /*
        Broadcast b = new Broadcast(18426);
        System.out.println(b.search("i'm a bomberstudent server"));
        System.out.println("Resultat : " + !b.getServers().isEmpty());
        //*/
        /*
        TcpClient cli = new TcpClient("127.0.0.1", 18642);
        cli.connect();
        cli.send("Bonjour toi le serveur comment que ça va ?");
        System.out.println(cli.receive());
        cli.close();
        //*/
        //*
        BomberStudentClient bsc = new BomberStudentClient();
        int a = bsc.findServer();
        if(a == 0){
            System.err.println("Aucun serveur");
            return;
        }
        //Ajout handler
        bsc.addHandler("server/end", new HandlerServerEnd());
        bsc.addHandler("game/newplayer", new HandlerPlayerJoin());
        bsc.addHandler("game/quit", new HandlerPlayerQuit());
        bsc.addHandler("player/position/update", new HandlerPlayerMove());
        bsc.addHandler("player/major/end", new HandlerPlayerMajorEnd());
        bsc.addHandler("attack/newbomb", new HandlerAttackBomb());
        bsc.addHandler("attack/affect", new HandlerAttackAffect());
        bsc.addHandler("attack/explose", new HandlerAttackExplode());
        //Connexion
        bsc.selectServer(0);
        bsc.send("POST", "aze/rty");
        System.out.println("A");
        Thread.sleep(15000);
        System.out.println("B");
        JSONObject json = bsc.receive();
        System.out.println(json.toString(1));
        bsc.close();
        //*/
    }
    
}
