| 
					
				 | 
			
			
				@@ -0,0 +1,168 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+/* 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ * To change this license header, choose License Headers in Project Properties. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ * To change this template file, choose Tools | Templates 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ * and open the template in the editor. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+package test; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.json.JSONObject; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import rsx.BomberStudentClient; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+/** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ * @author loquicom 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+public class TestServer { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public static void main(String[] args) throws InterruptedException { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //Creation client BomberStudent 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        BomberStudentClient bsc = new BomberStudentClient(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //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()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //Recherche serveur actif 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        int nbRes = bsc.findServer(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (nbRes == 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            System.err.println("Aucun serveur"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //Selectionne le 1er serveur qui à repondu 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        System.out.println("Connexion"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        bsc.selectServer(0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+         
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //Execute une/des requetes(s) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        /* 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        System.out.println("Envoi"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if(!bsc.send("GET", "nop")){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            System.err.println("Impossible envoyer la requete"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        System.out.println("Reception"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        print(bsc.receive()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //*/ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        /* 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Thread.sleep(10000); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //*/ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        /* 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        bsc.send("GET", "game/list"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        JSONObject json = bsc.receive(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        System.out.println(json.toString(1)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //*/ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        /* 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        JSONObject param = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        param.put("name", "gameTest"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        param.put("map", "map1"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        bsc.send("POST", "game/create", param); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        JSONObject json = bsc.receive(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        System.out.println(json.toString(1)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Thread.sleep(30000); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        bsc.send("GET", "game/list"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        json = bsc.receive(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        System.out.println(json.toString(1)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        param = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        param.put("move", "right"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        bsc.send("POST", "player/move", param); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //bsc.send("POST", "game/quit"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //*/ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        /* 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        JSONObject param = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        param.put("name", "gameTest"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        bsc.send("POST", "game/join", param); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        JSONObject json = bsc.receive(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        System.out.println(json.toString(1)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        bsc.send("GET", "game/list"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        json = bsc.receive(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        System.out.println(json.toString(1)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        param = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        param.put("move", "right"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        bsc.send("POST", "player/move", param); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        param = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        param.put("move", "left"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        bsc.send("POST", "player/move", param); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        param = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        param.put("move", "up"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        bsc.send("POST", "player/move", param); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //*/ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        /* 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        JSONObject param = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        param.put("name", "gameTest"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        param.put("map", "map1"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        bsc.send("POST", "game/create", param); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        JSONObject json = bsc.receive(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        System.out.println(json.toString(1)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Thread.sleep(2000); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        param = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        param.put("class", "major"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        bsc.send("POST", "object/new", param); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        json = bsc.receive(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        System.out.println(json.toString(1)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Thread.sleep(10000); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //*/ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+         
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        /* 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        JSONObject param = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        param.put("name", "gameTest"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        param.put("map", "map1"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        bsc.send("POST", "game/create", param); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        JSONObject json = bsc.receive(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        System.out.println(json.toString(1)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Thread.sleep(20000); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //*/ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        /* 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        JSONObject param = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        param.put("name", "gameTest"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        bsc.send("POST", "game/join", param); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        JSONObject json = bsc.receive(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        System.out.println(json.toString(1)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        param = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        param.put("class", "mine"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        param.put("pos", "2,1"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        bsc.send("POST", "attack/bomb", param); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        json = bsc.receive(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        System.out.println(json.toString(1)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //*/ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+         
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        JSONObject param = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        param.put("name", "gameTest"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        param.put("map", "map1"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        bsc.send("POST", "game/create", param); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        JSONObject json = bsc.receive(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        System.out.println(json.toString(1)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        param = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        param.put("class", "remote"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        param.put("pos", "2,1"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        bsc.send("POST", "attack/bomb", param); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        json = bsc.receive(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        System.out.println(json.toString(1)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        param.put("class", "classic"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        param.put("pos", "3,1"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        bsc.send("POST", "attack/bomb", param); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        json = bsc.receive(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        System.out.println(json.toString(1)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        bsc.send("POST", "attack/remote/go"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Thread.sleep(5000); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        param = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        param.put("class", "remote"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        param.put("pos", "3,5"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        bsc.send("POST", "attack/bomb", param); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        json = bsc.receive(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        System.out.println(json.toString(1)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        bsc.send("POST", "attack/remote/go"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+         
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        bsc.close(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public static void print(JSONObject json) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (json != null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            System.out.println("Code : " + json.getString("statut")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            System.out.println("Message : " + json.getString("message")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+} 
			 |