import java.io.*; import java.net.*; import java.util.*; class ServerThread extends Thread { Socket incoming; int counter; Fod game; DataInputStream in; PrintStream out; ServerThread (Socket i, int c, Fod g) { incoming = i; counter = c; game = g; } public void run(){ try { in = new DataInputStream(incoming.getInputStream()); out = new PrintStream(incoming.getOutputStream()); boolean done = false; String str = in.readLine(); while (!done){ System.out.println("Streamin: "+in); if (str.trim().equals("BYE")) { done = true;} else if (str.trim().equals("BYE")) { game.join(counter);} else if (str.trim().equals("DRAGON")){ str = in.readLine(); while (!str.equals("END")){ Dragon d = new Dragon(str); System.out.println("DRAGON: "+d); d.Owner = (short)counter; game.dragons.put(d.name,d); str = in.readLine(); } } else if (str.trim().equals("CITY")){ str = in.readLine(); while (!str.equals("END")){ City c = new City(str); System.out.println("CITY: "+c); c.Owner = (short)counter; game.cities.put(c.Name,c); //Markera de egna stadsrutorna som checkade Area a = c.getArea(game.Map); if(!game.players[counter].scannedareas.contains(a)) game.players[counter].scannedareas.addElement(a); str = in.readLine(); } } else if(str.trim().equals("SPELL")){ str = in.readLine(); while(!str.equals("END")){ System.out.println("SPELL:"+str); game.players[counter].spells.addElement(str); str = in.readLine(); } } else if (str.trim().equals("PLAYER")){ str = in.readLine(); game.players[counter].homeCity = str; str = in.readLine(); game.players[counter].requestname += Integer.parseInt(str); str = in.readLine(); // Läs END } else if (str.trim().equals("ENDTRANS")){ game.players[counter].ready = true; } sleep(100); // System.out.println(counter+" BEFORE1"); str = in.readLine(); // System.out.println(counter+" BEFORE2"); if (str == null) { //Check if we are ready reading System.out.println(counter+" connection BROKEN!!!!"); done = true; } } incoming.close(); System.out.println("Spawn " + counter + " died. \r"); } catch(NullPointerException e){ System.out.println("Player "+counter+" connection died"); game.players[counter].kill(); for(int i = 1;i