Codice aggiornato:
Ma non funziona ancora.... ho controllato con wireshark e il pacchetto che manda il client legittimo contiene esattamente gli stessi dati.codice:import TCP.Client; import java.util.Arrays; public class bot { private static Client client; // create the TCP socket with the library private static void create_socket(String host, int port) { client = new Client(); client.setHost(host); client.setPort(port); client.start(); } // keep alive private static void keep_alive() { byte bs[] = new byte[1]; bs[0]=0; client.sendBytes(bs); client.sendBytes(bs); } private static void handshake() { client.createPacket(59); client.addPacket((byte)2); client.addPacket(28); // 28 for 1.2.5; 39 for 1.3.1 try { client.addPacket(("shadowyviper;127.0.0.1:25565").getBytes("UTF-16BE")); } catch(Exception ex) { ex.printStackTrace(); } client.sendPacket(); //client.send("localhost"); //client.sendInt(25565); } private static String ar2str(byte[] ar) { StringBuffer result = new StringBuffer(); for(int i=0; i<ar.length; i++) { result.append((char)ar[i]); } return result.toString(); } private static void info() { client.sendInt(0xFE); byte[] b = client.receiveBytes(); if(b[0]!=-1) {System.err.println("ERRORE del SERVER");} b[0]=0; String s1 = ar2str(b); byte[] b1 = null; try { b1 = s1.getBytes("US-ASCII"); } catch(Exception ex) { ex.printStackTrace(); } String s = ar2str(b1); String[] s_ar = s.split("\\?"); String nome = s_ar[0].substring(4); String players = s_ar[1]; String stacks = s_ar[2]; System.out.println(nome+" "+players+"/"+stacks); } // main public static void main(String[] args) { String c = ""; create_socket("localhost", 25565); info(); handshake(); while(c!=null) { System.out.println(c=client.receive()); } } }![]()

Rispondi quotando