Example #1
0
  private static void serverWaiting() throws Exception {
    System.out.println("Waiting Mode");
    ServerSocket waitingSocket = new ServerSocket(serverInfo.getPort());
    String line;

    while (true) {
      Socket connectionSocket = waitingSocket.accept();
      BufferedReader in =
          new BufferedReader(new InputStreamReader(connectionSocket.getInputStream()));
      DataOutputStream out = new DataOutputStream(connectionSocket.getOutputStream());
      // System.out.println("Waiting for migration");
      line = in.readLine();
      // System.out.println("Received: " + line);
      String info = line;
      out.writeBytes("Info OK\n");
      line = in.readLine();
      // System.out.println("Received: " + line);
      serverInit();
      game.setMoving(true);
      reconstruction(info);
      out.writeBytes("Bind OK\n");
      waitingSocket.close();
      break;
    }
    while (!allConnected) {
      System.out.print("");
    }
    game.setMoving(false);
    // System.out.println("Fin server waiting");
    serverRunning();
  }
Example #2
0
  private static void recuperacionFallas() {
    File file = new File(serverName + ".swp");
    if (file.exists()) {
      try {
        System.out.println("Un fichero de salvaguarda es presente:");
        System.out.println("Quiere recuperar el antiguo juego(y/n)?");
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        while (true) {
          String s = in.readLine();
          if (s.equals("y")) {
            recuperationServer();
            InputStream ips = new FileInputStream(serverName + ".swp");
            InputStreamReader ipsr = new InputStreamReader(ips);
            BufferedReader br = new BufferedReader(ipsr);
            String info = br.readLine();
            reconstruction(info);
            game.setRecoveringServer(false);
            break;
          } else if (s.equals("n")) {
            serverInit();
            break;
          }
        }

      } catch (FileNotFoundException e) {
        System.out.println("Failed to wait");
      } catch (IOException e) {
        System.out.println("Failed to wait");
      }

    } else serverInit();
    saveStateServer();
  }
Example #3
0
  public static void main(String[] args) {
    // Establecimiento del game en el rmiserver
    if (args.length == 0) {
      System.out.println("Wrong number of argument");
      System.exit(1);
    }

    listAddr = new ListAddr();
    serverInfo = listAddr.getServer(args[args.length - 1]);
    serverName = args[args.length - 1];

    if (args.length == 2 && args[0].equals("wait")) {
      try {
        serverWaiting();
      } catch (Exception e) {
        System.out.println("Failed to wait");
      }
    } else {
      if (args.length == 2) numPlayer = Integer.parseInt(args[0]);
      serverInit();

      File file = new File(serverName + ".swp");
      if (file.exists()) {
        try {
          InputStream ips = new FileInputStream(serverName + ".swp");
          InputStreamReader ipsr = new InputStreamReader(ips);
          BufferedReader br = new BufferedReader(ipsr);
          String info = br.readLine();
          reconstruction(info);
        } catch (FileNotFoundException e) {
          System.out.println("Failed to wait");
        } catch (IOException e) {
          System.out.println("Failed to wait");
        }
      }
      saveStateServer();
      serverRunning();
    }
  }