示例#1
0
  /**
   * Konstruktor, uebernimmt eine Socket-Verbindung vom Server, initialisiert die Ein-und
   * Ausgabestreams des Sockets und speichert seine Spielernummer, die er vom Server zugewiesen
   * bekommt. Diese wird dann zuletzt an den Communicator gesendet.
   *
   * @param connection Socketverbindung
   * @param server Server-Objekt
   * @param cnt Spielernummer
   * @param gameID Spiel-ID
   * @param name Spielname
   * @exception IOException
   * @exception SocketException
   */
  public ServerThread(Socket connection, Server server, int cnt, int gameID, String name) {
    this.connection = connection;
    this.server = server;
    this.myNumber = cnt;
    this.gameID = gameID;
    this.nameOfTheGame = name;

    try {
      out =
          new PrintWriter(
              new BufferedWriter(new OutputStreamWriter(this.connection.getOutputStream())));
      in = new BufferedReader(new InputStreamReader(this.connection.getInputStream()));
    } catch (IOException e) {
      String log = "player " + (myNumber + 1) + ":error creating ServerThread\n";
      System.out.print(log);
      this.server.log(log, server.getPort());
    }

    send("1" + Integer.toString(myNumber)); // sende die zugewiesene
    // Spielernummer
    // an den Communicator
    try {
      this.connection.setSoTimeout(1800000);
      this.connection.setSoLinger(true, 6); // optional?
    } catch (SocketException e) {
      String log = "player " + (myNumber + 1) + ": error setting socket options\n";
      System.out.print(log);
      this.server.log(log, server.getPort());
    }
  }
示例#2
0
  public void startLobby() {
    server.broadcastMessage(GOLD + "[ServerGames]" + GREEN + " Countdown started.");

    clearAll();

    bets.clear();
    this.clearEnt();
    load();
    tpAll(waiting);
    ServerGames.current = worlds.get(new Random().nextInt(ServerGames.worlds.size()));

    for (Player p : server.getOnlinePlayers()) {
      showAllFor(p);
      showPlayer(p);

      if (isTribute(p) || isSpectator(p)) clearItems(p);
    }

    loaded.clear();

    this.resetPlayers();

    state = State.LOBBY;
    game = new Lobby(this);

    startTimer();
  }
示例#3
0
  public void run() {
    try {
      Telnet.writeLine(cs, "<fggreen> >>> Welcome to AdaMUD <<< <reset>");
      Telnet.flushInput(cs);

      while ((player = s.getPlayerDB().login(cs, s)) == null) ;
      player.look();

      while (true) {
        System.out.println("Waiting for message");
        String message = Telnet.readLine(cs).trim();

        if (message == null) {
          // Disconnected
          break;
        }

        if (message.equals("bye")) {
          Telnet.writeLine(cs, "Goodbye!");
          break;
        }

        parseCommand(message);
      }

      cs.close();
    } catch (IOException e) {
      System.out.println("Client error: " + e);
    } finally {
      s.getPlayerDB().remove(player);
      s.remove(cs);
    }
  }
示例#4
0
  /**
   * Main Method
   *
   * @param args command line arguments
   */
  public static void main(String[] args) {
    // init logging
    try {
      Logging.init("lucane.log", "ALL");
    } catch (IOException ioe) {
      System.err.println("Unable to init logging, exiting.");
      System.exit(1);
    }

    Server server = null;
    ServerConfig config = null;

    try {
      config = new ServerConfig(CONFIG_FILE);
    } catch (Exception e) {
      Logging.getLogger().severe("Unable to read or parse the config file.");
      e.printStackTrace();
      System.exit(1);
    }

    // Server creation
    server = new Server(config);
    server.generateKeys();
    Logging.getLogger().info("Server is ready.");
    server.run();
  }
  /** Stops Jetty. */
  private void stopJetty() {
    // Jetty does not really stop the server if port is busy.
    try {
      if (httpSrv != null) {
        // If server was successfully started, deregister ports.
        if (httpSrv.isStarted()) ctx.ports().deregisterPorts(getClass());

        // Record current interrupted status of calling thread.
        boolean interrupted = Thread.interrupted();

        try {
          httpSrv.stop();
        } finally {
          // Reset interrupted flag on calling thread.
          if (interrupted) Thread.currentThread().interrupt();
        }
      }
    } catch (InterruptedException ignored) {
      if (log.isDebugEnabled()) log.debug("Thread has been interrupted.");

      Thread.currentThread().interrupt();
    } catch (Exception e) {
      U.error(log, "Failed to stop Jetty HTTP server.", e);
    }
  }
示例#6
0
 /**
  * ************************************************************************ Start Workflow.
  *
  * @param AD_Workflow_ID workflow
  * @return true if started
  */
 private boolean startWorkflow(int AD_Workflow_ID) {
   log.fine(AD_Workflow_ID + " - " + m_pi);
   boolean started = false;
   if (DB.isRemoteProcess()) {
     log.info("trying to running on the server");
     Server server = CConnection.get().getServer();
     try {
       if (server != null) { // 	See ServerBean
         log.info("running on the server");
         m_pi = server.workflow(m_wscctx, m_pi, AD_Workflow_ID);
         log.finest("server => " + m_pi);
         started = true;
       }
     } catch (Exception ex) {
       log.log(Level.SEVERE, "AppsServer error", ex);
       started = false;
     }
   }
   //	Run locally
   if (!started && !m_IsServerProcess) {
     log.info("running locally");
     MWorkflow wf = MWorkflow.get(m_wscctx, AD_Workflow_ID);
     MWFProcess wfProcess = null;
     if (m_pi.isBatch()) wfProcess = wf.start(m_pi); // 	may return null
     else wfProcess = wf.startWait(m_pi); // 	may return null
     started = wfProcess != null;
   }
   return started;
 } //  startWorkflow
示例#7
0
 public boolean disablePlugin(String name) {
   try {
     Server.getPluginManager().disablePlugin(Server.getPluginManager().getPlugin(name));
     return true;
   } catch (NullPointerException e) {
     return false;
   }
 }
示例#8
0
 /**
  * trennt die Socketverbindung zum entsprechenden Client
  *
  * @exception IOException
  */
 public void closeConnection() {
   try {
     connection.close();
   } catch (IOException e) {
     String log = "player " + (myNumber + 1) + ": error closing connection\n";
     System.out.print(log);
     server.log(log, server.getPort());
   }
 }
示例#9
0
  public static void main(String args[]) throws Exception {
    Server server = createServer(args);

    if (server == null) {
      usage();
    }

    System.out.println("Server started.");
    server.runServer();
  }
示例#10
0
 /**
  * ************************************************************************ Start Java Process
  * Class. instanciate the class implementing the interface ProcessCall. The class can be a
  * Server/Client class (when in Package org compiere.process or org.compiere.model) or a client
  * only class (e.g. in org.compiere.report)
  *
  * @return true if success
  */
 private boolean startProcess() {
   log.fine(m_pi.toString());
   boolean started = false;
   if (DB.isRemoteProcess()) {
     Server server = CConnection.get().getServer();
     try {
       if (server != null) { // 	See ServerBean
         m_pi = server.process(m_wscctx, m_pi);
         log.finest("server => " + m_pi);
         started = true;
       }
     } catch (UndeclaredThrowableException ex) {
       Throwable cause = ex.getCause();
       if (cause != null) {
         if (cause instanceof InvalidClassException)
           log.log(
               Level.SEVERE, "Version Server <> Client: " + cause.toString() + " - " + m_pi, ex);
         else
           log.log(Level.SEVERE, "AppsServer error(1b): " + cause.toString() + " - " + m_pi, ex);
       } else log.log(Level.SEVERE, " AppsServer error(1) - " + m_pi, ex);
       started = false;
     } catch (Exception ex) {
       Throwable cause = ex.getCause();
       if (cause == null) cause = ex;
       log.log(Level.SEVERE, "AppsServer error - " + m_pi, cause);
       started = false;
     }
   }
   //	Run locally
   if (!started && !m_IsServerProcess) {
     ProcessCall myObject = null;
     try {
       Class myClass = Class.forName(m_pi.getClassName());
       myObject = (ProcessCall) myClass.newInstance();
       if (myObject == null) m_pi.setSummary("No Instance for " + m_pi.getClassName(), true);
       else myObject.startProcess(m_wscctx, m_pi, m_trx);
       if (m_trx != null) {
         m_trx.commit();
         m_trx.close();
       }
     } catch (Exception e) {
       if (m_trx != null) {
         m_trx.rollback();
         m_trx.close();
       }
       m_pi.setSummary("Error starting Class " + m_pi.getClassName(), true);
       log.log(Level.SEVERE, m_pi.getClassName(), e);
     }
   }
   return !m_pi.isError();
 } //  startProcess
 private void saveServers() {
   File serverDir = new File(settings.getLocalFolder(), "servers");
   if (!serverDir.exists()) {
     serverDir.mkdirs();
   }
   for (Server s : model.getAllServers()) {
     try {
       File serverFile = new File(serverDir, s.getName() + ".server");
       s.writeToFile(serverFile);
     } catch (IOException ex) {
       logger.log(Level.SEVERE, null, ex);
     }
   }
 }
 public void deleteKnownServer() {
   Server currentServer = model.getCurrentServer();
   if (currentServer != null) {
     try {
       model.removeServer(currentServer);
       File serverDir = new File(settings.getLocalFolder(), "servers");
       File serverFile = new File(serverDir, currentServer.getName() + ".server");
       Files.delete(serverFile.toPath());
     } catch (IOException ex) {
       model.addErrorMessage("Server-Datei konnte nicht gelöscht werden");
       logger.log(Level.SEVERE, null, ex);
     }
     model.fireChange();
   }
 }
示例#13
0
  public void startFinished() {
    if (bets != null && !bets.isEmpty() && bets.size() > 0) {
      for (int i = 0; i < bets.size(); i++) {
        try {
          Bet b = bets.get(i);

          if (isTribute(server.getPlayer(b.tribute))) {
            addScore(b.better, b.wager / 4);
            addScore(b.tribute, b.wager / 4);
          } else {
            subtractScore(b.better, b.wager);
          }

          bets.remove(b);
        } catch (Exception e) {
          e.printStackTrace();
        }
      }
    }

    clearAll();
    load();
    bets.clear();

    state = State.DONE;
    game = new Finished(this);

    startTimer();
  }
示例#14
0
  public void startGame() {
    state = State.IN_GAME;

    for (Tribute t : ServerGames.tributes) {
      t.player.setHealth(20);
      t.player.setFoodLevel(20);
      clearItems(t.player);
      if (!t.player.isOnline()) {
        ServerGames.tributes.remove(t);
      }
    }

    loaded.clear();
    Chests.resetChests();

    bets.clear();

    clearAll();
    load();

    for (Player p : getCorn().getWorld().getPlayers()) {
      p.setCompassTarget(getCorn());
    }

    server.broadcastMessage(GOLD + "[ServerGames]" + GREEN + " Let the game begin!");

    game = new Game(this);

    startTimer();
  }
  /** Method declaration */
  public void run() {

    Channel c = init();

    if (c != null) {
      try {
        while (true) {
          String sql = mInput.readUTF();

          mServer.trace(mThread + ":" + sql);

          if (sql == null) {
            break;
          }

          write(mDatabase.execute(sql, c).getBytes());
        }
      } catch (Exception e) {
      }
    }

    try {
      mSocket.close();
    } catch (IOException e) {
    }

    if (mDatabase.isShutdown()) {
      System.out.println("The database is shutdown");
      System.exit(0);
    }
  }
  /**
   * Checks that the only connector configured for the current jetty instance and returns it.
   *
   * @return Connector instance.
   * @throws GridException If no or more than one connectors found.
   */
  private AbstractNetworkConnector getJettyConnector() throws GridException {
    if (httpSrv.getConnectors().length == 1) {
      Connector connector = httpSrv.getConnectors()[0];

      if (!(connector instanceof AbstractNetworkConnector))
        throw new GridException(
            "Error in jetty configuration. Jetty connector should extend "
                + "AbstractNetworkConnector class.");

      return (AbstractNetworkConnector) connector;
    } else
      throw new GridException(
          "Error in jetty configuration [connectorsFound="
              + httpSrv.getConnectors().length
              + "connectorsExpected=1]");
  }
示例#17
0
 public List<String> getBannedPlayers() throws APIException {
   List<String> a = new ArrayList<String>();
   for (OfflinePlayer p : Server.getBannedPlayers()) {
     a.add(p.getName());
   }
   return a;
 }
示例#18
0
  public Player getPlayerExact(String playerName) {
    Player player = Server.getPlayerExact(playerName);
    if (player == null) {
      player = JSONAPI.loadOfflinePlayer(playerName);
    }

    return player;
  }
示例#19
0
 public static void main(String argv[]) {
   int port = 1099;
   if (argv.length > 0) {
     try {
       port = Integer.parseInt(argv[0]);
     } catch (Exception e) {
       e.printStackTrace();
     }
   }
   try {
     Server server = new Server(port);
     server.serviceClient();
     System.out.println("Client serviced");
   } catch (Exception ex) {
     ex.printStackTrace();
   }
 }
示例#20
0
  public APIWrapperMethods(Server server) {
    bukget = new BukGetAPIMethods(server);
    jsonapi = new JSONAPIAPIMethods(server);
    permissions = new PermissionWrapper(server);

    if (server.getPluginManager().getPlugin("Vault") != null) {
      RegisteredServiceProvider<Economy> rsp =
          server.getServicesManager().getRegistration(Economy.class);
      if (rsp != null) {
        econ = rsp.getProvider();
      }
      RegisteredServiceProvider<Chat> rsp2 =
          server.getServicesManager().getRegistration(Chat.class);
      if (rsp2 != null) {
        chat = rsp2.getProvider();
      }
    }
  }
示例#21
0
  public Inventory getChestContents(String world, int x, int y, int z) throws Exception {
    BlockState d = Server.getWorld(world).getBlockAt(x, y, z).getState();

    if (d instanceof Chest) {
      return ((Chest) d).getInventory();
    }

    return null;
  }
示例#22
0
  public String[] getSignText(String world, int x, int y, int z) throws Exception {
    BlockState d = Server.getWorld(world).getBlockAt(x, y, z).getState();

    if (d instanceof Sign) {
      return ((Sign) d).getLines();
    }

    return null;
  }
示例#23
0
  public List<String> getPlayerNames() {
    List<String> names = new ArrayList<String>();

    for (Player p : Server.getOnlinePlayers()) {
      names.add(p.getName());
    }

    return names;
  }
示例#24
0
 public boolean teleport(String playername, String world, int x, int y, int z) {
   try {
     Player p = getPlayerExact(playername);
     p.teleport(new Location(Server.getWorld(world), x, y, z));
     p.saveData();
     return true;
   } catch (Exception e) {
     return false;
   }
 }
示例#25
0
 private String getFriendsMessage(Packet packet) {
   ArrayList<String> friends = new ArrayList<String>();
   friends = server.getfriendlist(packet.getSender());
   String friendsMessage = "";
   // Prepare delimited list to send to sender
   for (int i = 0; i < friends.size(); i++) {
     friendsMessage = friendsMessage + friends.get(i) + ":";
   }
   return friendsMessage;
 }
示例#26
0
  public String topInGame() {
    String most = "";

    for (Player p : server.getOnlinePlayers()) {
      if (getScore(p) > getScore(most)) {
        most = p.getName();
      }
    }

    return most;
  }
示例#27
0
  public List<String> getPluginFiles(String pluginName) {
    try {
      File dir = Server.getPluginManager().getPlugin(pluginName).getDataFolder();
      RecursiveDirLister d = new RecursiveDirLister(dir);

      return d.getFileListing();
    } catch (Exception e) {
      // e.printStackTrace();
      return new ArrayList<String>();
    }
  }
示例#28
0
  public boolean clearChestSlot(String world, int x, int y, int z, int slot) {
    try {
      Inventory inv =
          ((Chest) Server.getWorld(world).getBlockAt(x, y, z).getState()).getInventory();
      inv.clear(slot);

      return true;
    } catch (Exception e) {
      return false;
    }
  }
示例#29
0
  public boolean setSignText(String world, int x, int y, int z, int line, String txt) {
    BlockState d = Server.getWorld(world).getBlockAt(x, y, z).getState();

    if (d instanceof Sign) {
      ((Sign) d).setLine(line, txt);
      ((Sign) d).update();
      return true;
    }

    return false;
  }
示例#30
0
  public void runCommand(String... obj) {
    StringBuilder command = new StringBuilder();
    for (String s : obj) {
      command.append(s);
    }

    String cmd = command.toString();

    outLog.info("Command run by remote user: '******'");

    Server.dispatchCommand(getServer().getConsoleSender(), cmd);
  }