server.java (1453B)
1 package space.nocebo; 2 3 import java.net.*; 4 import java.io.*; 5 import java.util.*; 6 import java.util.concurrent.ExecutorService; 7 import java.util.concurrent.Executors; 8 import space.nocebo.util; 9 10 public class server { 11 12 public static ArrayList<acc> Accounts = new ArrayList<acc>(); 13 public static ArrayList<script> Scripts = new ArrayList<script>(); 14 public static ArrayList<group> Groups = new ArrayList<group>(); 15 public static ArrayList<game> Games = new ArrayList<game>(); 16 17 public static game getGame(script ms, group mg) { 18 game gm; 19 if (Games.isEmpty() == false) 20 for (game g : Games) { 21 if (g.isThisMyGame(mg) == true) { 22 return g; 23 } 24 } 25 gm = new game(ms,mg); 26 server.Games.add(gm); 27 28 return gm; 29 } 30 31 public static void main(String[] args) throws IOException { 32 server.Scripts.add(new script("Dark Knight", "Gordon", "Alfred", 1)); 33 server.Scripts.add(new script("Andy", "Red", "Brooks", 2)); 34 server.Scripts.add(new script("Don", "Michael", "Sonny", 3)); 35 server.Scripts.add(new script("Tyler", "Marla", "Bob", 4)); 36 server.Scripts.add(new script("Neo", "Morpheus", "Agent Smith", 5)); 37 Socket connection; 38 ServerSocket serverSocket; 39 40 ExecutorService executor = Executors.newFixedThreadPool(10); 41 int port = 1234; 42 serverSocket = new ServerSocket(port); 43 while (true) { 44 System.out.println("Waiting for connections"); 45 connection = serverSocket.accept(); 46 executor.execute(new servertask(connection)); 47 } 48 } 49 }