/**
   * This method is responsible for the creation of the Client UI.
   *
   * @param args[0] The host to connect to.
   */
  public static void main(String[] args) {
    // Get loginId
    String id = "";
    String pw = "";
    try {
      id = args[0];
    } catch (ArrayIndexOutOfBoundsException e) {
      System.out.println("ERROR - No login ID specified. Connection aborted.");
      System.exit(0);
    }
    try {
      pw = args[1];
    } catch (ArrayIndexOutOfBoundsException e) {
      System.out.println("ERROR - Password not specified. Connection aborted.");
      System.exit(0);
    }
    // Get host
    String host = "";
    try {
      host = args[2];
    } catch (ArrayIndexOutOfBoundsException e) {
      host = "localhost";
    }

    // Get port
    int port = 0;
    try {
      port = Integer.parseInt(args[3]);
    } catch (Throwable t) {
      port = DEFAULT_PORT; // Set port to 5555
    }

    ClientConsole chat = new ClientConsole(id, pw, host, port);
    chat.accept(); // Wait for console data
  }
Exemple #2
0
 public MobGroup(int Aid, int cID, String groupData) {
   int maxLevel = 0;
   id = Aid;
   align = Constants.ALIGNEMENT_NEUTRE;
   cellID = cID;
   aggroDistance = Constants.getAggroByLevel(maxLevel);
   isFix = true;
   _creationDate = System.currentTimeMillis();
   int guid = -1;
   for (String data : groupData.split(";")) {
     String[] infos = data.split(",");
     try {
       int id = Integer.parseInt(infos[0]);
       int min = Integer.parseInt(infos[1]);
       int max = Integer.parseInt(infos[2]);
       Monstre m = World.getMonstre(id);
       List<MobGrade> mgs = new ArrayList<MobGrade>();
       // on ajoute a la liste les grades possibles
       for (MobGrade MG : m.getGrades().values())
         if (MG.level >= min && MG.level <= max) mgs.add(MG);
       if (mgs.isEmpty()) continue;
       // On prend un grade au hasard entre 0 et size -1 parmis les mobs possibles
       _Mobs.put(guid, mgs.get(Formulas.getRandomValue(0, mgs.size() - 1)));
       guid--;
     } catch (Exception e) {
       continue;
     }
     ;
   }
   orientation = (Formulas.getRandomValue(0, 3) * 2) + 1;
 }
Exemple #3
0
 // @SuppressWarnings("static-access")
 public void runCmd(String[] cmd) {
   // String cmdName = cmd[0].toLowerCase().trim();
   String msg;
   int target;
   switch (cmd[0].toLowerCase().trim()) {
     case "votekick":
       ChatServer.sendOne(
           ChatServer.getClientID(name),
           Colors.DARKRED + "/vote and /votekick are unimplemented.");
       break;
       /*if (cmd.length != 2) {
       	ChatServer.sendOne(ChatServer.getClientID(name), Colors.DARKRED + "votekick syntax: /votekick <user>");
       	break;
       }
       target = ChatServer.getClientID(cmd[1]); //get id of user name
       String starter = name;
       if (target == -1) {
       	ChatServer.sendOne(ChatServer.getClientID(name), Colors.DARKRED + "User '" + cmd[1] + "' is not online");;
       } else {
       	startVote("kick", ChatServer.getClientID(starter), target, "kick");
       	vote(ChatServer.getClientID(starter), 1); //voter also votes yes
       }
       break;*/
     case "vote":
       ChatServer.sendOne(
           ChatServer.getClientID(name),
           Colors.DARKRED + "/vote and /votekick are unimplemented.");
       break;
       /*if (cmd.length != 2) {
       	ChatServer.sendOne(ChatServer.getClientID(name), Colors.DARKRED + "vote syntax: /vote <yes | no>");
       	break;
       }
       int voter = ChatServer.getClientID(name);
       if (cmd[1].equalsIgnoreCase("yes")) {
       	ChatServer.vote(voter, 1);
       } else if (cmd[1].equalsIgnoreCase("no")) {
       	ChatServer.vote(voter, 0);
       } else if (cmd[1].equalsIgnoreCase("end")) {
       	ChatServer.sendOne(ChatServer.getClientID(name), Colors.DARKRED + "Ending current vote and tallying results.");
       } else {
       	ChatServer.sendOne(ChatServer.getClientID(name), Colors.DARKRED + "Please vote \"yes\" or \"no\"");
       }
       break;*/
     case "me":
     case "emote":
       if (cmd.length <= 1) {
         ChatServer.sendOne(
             ChatServer.getClientID(name), Colors.DARKRED + "me syntax: /me &lt;message&gt;");
         break;
       }
       msg = "";
       for (int i = 1; i < cmd.length; i++) {
         msg += cmd[i] + " ";
       }
       ChatServer.sendAll(Colors.WHITE + "> " + Colors.GREEN + name + Colors.WHITE + " " + msg);
       break;
     case "msg":
     case "message":
       if (cmd.length < 3) {
         ChatServer.sendOne(
             ChatServer.getClientID(name),
             Colors.DARKRED + "msg syntax: /msg &lt;user&gt; &lt;message&gt;");
         break;
       }
       msg = "";
       for (int i = 2; i < cmd.length; i++) {
         msg += cmd[i] + " ";
       }
       target = ChatServer.getClientID(cmd[1]);
       lastUserPMd = target;
       if (target == -1) {
         ChatServer.sendOne(
             ChatServer.getClientID(name), Colors.DARKRED + "User '" + cmd[1] + "' is not online");
       } else {
         // ChatServer.sendOne(ChatServer.getClientID(name), target, Colors.PINK + "" + msg);
         ChatServer.sendOne(target, Colors.PINK + "" + name + " -> you: " + msg);
         ChatServer.sendOne(
             ChatServer.getClientID(name), Colors.PINK + "me -> " + cmd[1] + ": " + msg);
         ChatServer.sendMods(Colors.PINK + "" + name + " -> " + cmd[1] + ": " + msg);
       }
       break;
     case "r":
     case "reply":
       if (cmd.length < 2) {
         ChatServer.sendOne(
             ChatServer.getClientID(name), Colors.DARKRED + "reply syntax: /r &lt;message&gt;");
         break;
       }
       if (lastUserPMd == -1) {
         ChatServer.sendOne(
             ChatServer.getClientID(name), Colors.DARKRED + "You have not messaged anyone yet");
         break;
       }
       msg = "";
       for (int i = 1; i < cmd.length; i++) {
         msg += cmd[i] + " ";
       }
       target = lastUserPMd;
       if (target == -1) {
         ChatServer.sendOne(
             ChatServer.getClientID(name),
             Colors.DARKRED + "User '" + ChatServer.getClientName(target) + "' is not online");
         ;
       } else {
         // ChatServer.sendOne(ChatServer.getClientID(name), target, Colors.PINK + "" + msg);
         ChatServer.sendOne(target, Colors.PINK + "" + name + " -> you: " + msg);
         ChatServer.sendOne(
             ChatServer.getClientID(name),
             Colors.PINK + "me -> " + ChatServer.getClientName(target) + ": " + msg);
         ChatServer.sendMods(
             Colors.PINK + "" + name + " -> " + ChatServer.getClientName(target) + ": " + msg);
       }
       break;
     case "help":
     case "?":
       if (cmd.length != 1) {
         ChatServer.sendOne(ChatServer.getClientID(name), Colors.DARKRED + "help syntax: /help");
         break;
       }
       String cmds = "";
       if (getRank() > 0) cmds += "/me /logout /msg /r /who /help /ping ";
       if (getRank() > 1) cmds += "/kick /broadcast /mute ";
       if (getRank() > 2) cmds += "/stop /kickall /pex ";
       ChatServer.sendOne(
           ChatServer.getClientID(name), Colors.LIGHTGREEN + "Available commands: " + cmds);
       break;
     case "who":
     case "list":
       if (cmd.length != 1) {
         ChatServer.sendOne(
             ChatServer.getClientID(name), Colors.DARKRED + "user list syntax: /list");
         break;
       }
       ChatServer.sendOne(
           ChatServer.getClientID(name),
           Colors.LIGHTGREEN + "Users online: " + ChatServer.getClientsOnline());
       break;
     case "logout":
     case "logoff":
     case "dc":
       leave();
       break;
     case "ping":
     case "pong":
       if (cmd.length == 1) {
         ChatServer.sendOne(ChatServer.getClientID(name), "Pong!");
       } else {
         String str = "";
         for (int i = 1; i < cmd.length; i++) {
           str += cmd[i] + " ";
         }
         ChatServer.sendOne(ChatServer.getClientID(name), str);
       }
       break;
     case "stop": // admin
       if (getRank() < 3) {
         ChatServer.sendOne(
             ChatServer.getClientID(name),
             Colors.RED + "You do not have permission to use this command");
         break;
       }
       if (cmd.length != 1) {
         ChatServer.sendOne(
             ChatServer.getClientID(name), Colors.DARKRED + "ChatServer stop syntax: /stop");
         break;
       }
       ChatServer.sendOne(ChatServer.getClientID(name), Colors.RED + "Server is shutting down...");
       System.exit(0);
       break;
     case "kick": // mod
       if (getRank() < 2) {
         ChatServer.sendOne(
             ChatServer.getClientID(name),
             Colors.RED + "You do not have permission to use this command");
         break;
       }
       if (cmd.length < 2) {
         ChatServer.sendOne(
             ChatServer.getClientID(name),
             Colors.DARKRED + "kick syntax: /kick &lt;user &lt;reason&gt;&gt;");
         break;
       }
       if (ChatServer.getClientID(cmd[1]) == -1) {
         ChatServer.sendOne(
             ChatServer.getClientID(name), Colors.DARKRED + "User '" + cmd[1] + "' is not online");
         ;
       } else {
         if (cmd.length == 2) {
           ChatServer.kick(ChatServer.getClientID(name), ChatServer.getClientID(cmd[1]));
         } else if (cmd.length > 2) {
           msg = "";
           for (int i = 2; i < cmd.length; i++) {
             msg += cmd[i] + " ";
           }
           ChatServer.kick(ChatServer.getClientID(cmd[1]), msg);
         }
       }
       break;
     case "kickall": // admin
       if (getRank() < 3) {
         ChatServer.sendOne(
             ChatServer.getClientID(name),
             Colors.RED + "You do not have permission to use this command");
         break;
       }
       if (cmd.length != 1) {
         ChatServer.sendOne(
             ChatServer.getClientID(name), Colors.DARKRED + "kickall syntax: /kickall");
         break;
       }
       // ChatServer.kickAll();
       ChatServer.pushToChat(Colors.DARKRED + "kickall command is unimplemented");
       break;
     case "mute": // mod
       if (getRank() < 2) {
         ChatServer.sendOne(
             ChatServer.getClientID(name),
             Colors.RED + "You do not have permission to use this command");
         break;
       }
       if (cmd.length < 2) {
         ChatServer.sendOne(
             ChatServer.getClientID(name), Colors.DARKRED + "mute syntax: /mute &lt;user&gt;");
         break;
       }
       if (ChatServer.getClientID(cmd[1]) == -1) {
         ChatServer.sendOne(
             ChatServer.getClientID(name), Colors.DARKRED + "User '" + cmd[1] + "' is not online");
       }
       ChatServer.mute(ChatServer.getClientID(cmd[1]));
       ChatServer.sendOne(
           ChatServer.getClientID(cmd[1]),
           Colors.RED
               + "You have been "
               + ((ChatServer.getClient(cmd[1]).isMuted()) ? "muted" : "unmuted"));
       ChatServer.sendOne(
           ChatServer.getClientID(name),
           Colors.RED
               + ""
               + cmd[1]
               + " has been "
               + ((ChatServer.getClient(cmd[1]).isMuted()) ? "muted" : "unmuted"));
       break;
     case "broadcast": // mod
     case "bc":
       if (getRank() < 2) {
         ChatServer.sendOne(
             ChatServer.getClientID(name),
             Colors.RED + "You do not have permission to use this command");
         break;
       }
       if (cmd.length < 2) {
         ChatServer.sendOne(
             ChatServer.getClientID(name),
             Colors.DARKRED + "broadcast syntax: /broadcast &lt;message&gt;");
         break;
       }
       msg = "";
       for (int i = 1; i < cmd.length; i++) {
         msg += cmd[i] + " ";
       }
       ChatServer.sendAll(
           Colors.DARKRED
               + "["
               + Colors.LIGHTGREEN
               + "Broadcast"
               + Colors.DARKRED
               + "]"
               + Colors.LIGHTGREEN
               + Colors.BOLD
               + " "
               + msg);
       break;
     case "pex": // admin
     case "rank":
       if (getRank() < 3) {
         ChatServer.sendOne(
             ChatServer.getClientID(name),
             Colors.RED + "You do not have permission to use this command");
         break;
       }
       if (cmd.length < 2 || cmd.length > 4) { // /pex promote user rank
         ChatServer.sendOne(
             ChatServer.getClientID(name),
             Colors.DARKRED
                 + "permissions syntax: /pex &lt;promote | demote&gt; &lt;user&gt; or /pex set &lt;user &lt;user | mod | admin&gt;&gt;");
         break;
       }
       if (cmd[2].equals(name)) {
         ChatServer.sendOne(
             ChatServer.getClientID(name), Colors.DARKRED + "You cannot promote/demote yourself");
         break;
       }
       if (ChatServer.getClientID(cmd[2]) == -1) {
         ChatServer.sendOne(
             ChatServer.getClientID(name), Colors.DARKRED + "User '" + cmd[2] + "' is not online");
       }
       switch (cmd[1].toLowerCase().trim()) {
         case "set":
           if (cmd.length != 4) {
             ChatServer.sendOne(
                 ChatServer.getClientID(name),
                 Colors.DARKRED
                     + "permissions syntax: /pex set &lt;user &lt;user | mod | admin&gt;&gt;");
           } else {
             switch (cmd[3].toLowerCase().trim()) {
               case "mod":
               case "moderator":
                 ChatServer.promoteClient(ChatServer.getClientID(cmd[2]), 2);
                 ChatServer.sendOne(
                     ChatServer.getClientID(cmd[2]), "You have been moved to moderator");
                 ChatServer.sendOne(
                     ChatServer.getClientID(name),
                     Colors.PINK + "Changed " + cmd[2] + " to moderator");
                 break;
               case "admin":
               case "administrator":
                 ChatServer.promoteClient(ChatServer.getClientID(cmd[2]), 3);
                 ChatServer.sendOne(
                     ChatServer.getClientID(cmd[2]), "You have been moved to administrator");
                 ChatServer.sendOne(
                     ChatServer.getClientID(name),
                     Colors.PINK + "Changed " + cmd[2] + " to administrator");
                 break;
               case "user":
                 ChatServer.promoteClient(ChatServer.getClientID(cmd[2]), 1);
                 ChatServer.sendOne(ChatServer.getClientID(cmd[2]), "You have been moved to user");
                 ChatServer.sendOne(
                     ChatServer.getClientID(name), Colors.PINK + "Changed " + cmd[2] + " to user");
                 break;
               default:
                 ChatServer.sendOne(
                     ChatServer.getClientID(name),
                     Colors.DARKRED
                         + "permissions syntax: /pex set &lt;user &lt;user | mod | admin&gt;&gt;");
                 break;
             }
           }
           break;
         case "promote":
           if (cmd.length != 3) {
             ChatServer.sendOne(
                 ChatServer.getClientID(name),
                 Colors.DARKRED
                     + "permissions syntax: /pex &lt;promote | demote&gt; &lt;user&gt;");
           } else {
             ChatServer.promoteClient(ChatServer.getClientID(cmd[2]));
             ChatServer.sendOne(ChatServer.getClientID(cmd[2]), "You have been promoted");
             ChatServer.sendOne(ChatServer.getClientID(name), Colors.PINK + "Promoted " + cmd[2]);
           }
           break;
         case "demote":
           if (cmd.length != 3) {
             ChatServer.sendOne(
                 ChatServer.getClientID(name),
                 Colors.DARKRED
                     + "permissions syntax: /pex &lt;promote | demote&gt; &lt;user&gt;");
           } else {
             ChatServer.demoteClient(ChatServer.getClientID(cmd[2]));
             ChatServer.sendOne(ChatServer.getClientID(cmd[2]), "You have been demoted");
             ChatServer.sendOne(ChatServer.getClientID(name), Colors.PINK + "Demoted " + cmd[2]);
           }
           break;
         default:
           ChatServer.sendOne(
               ChatServer.getClientID(name),
               Colors.DARKRED
                   + "permissions syntax: /pex &lt;promote | demote&gt; &lt;user&gt; or /pex set &lt;user &lt;user | mod | admin&gt;&gt;");
           break;
       }
       break;
     default:
       ChatServer.sendOne(
           ChatServer.getClientID(name),
           Colors.DARKRED + "Unknown command. Type /help for a list of commands.");
       break;
   }
 }
 public void handleMessageFromClientUI(Object message) {
   String parsed = "";
   if (!((Message) message).message.startsWith("#") && isConnected()) {
     super.handleMessageFromClientUI(message);
     return;
   }
   {
     parsed = ((Message) message).message.substring(1);
     if (parsed.equals("quit")) {
       try {
         closeConnection();
       } catch (IOException ex) {
         ex.printStackTrace();
         System.exit(1);
       }
       System.exit(0);
     } else if (parsed.equals("logoff")) {
       try {
         closeConnection();
       } catch (IOException ex) {
         ex.printStackTrace();
         System.exit(1);
       }
     } else if (parsed.equals("login")) {
       if (isConnected()) {
         System.out.println("Error: Already connected");
         return;
       }
       try {
         openConnection();
       } catch (IOException ex) {
         System.out.println("Error: " + ex.getMessage());
         ex.printStackTrace();
       }
     } else if (parsed.startsWith("sethost")) {
       if (isConnected()) {
         System.out.println("Error: Already connected");
         return;
       } else {
         String host = "";
         try {
           host = parsed.split(" ")[1];
         } catch (ArrayIndexOutOfBoundsException ex) {
           System.out.println("Error: Must specify host");
           return;
         }
         setHost(host);
       }
     } else if (parsed.startsWith("setport")) {
       if (isConnected()) {
         System.out.println("Error: Already connected");
         return;
       }
       int port = 0;
       try {
         port = Integer.parseInt(parsed.split(" ")[1]);
       } catch (ArrayIndexOutOfBoundsException ex) {
         System.out.println("Error: Must specify port");
         return;
       }
       setPort(port);
     } else if (parsed.equals("getport")) {
       System.out.println("Port: " + getPort());
     } else if (parsed.equals("gethost")) {
       System.out.println("Host: " + getHost());
     }
   }
 }
 protected void connectionException(Exception exception) {
   System.out.println("Connection exception: " + exception.getMessage());
   exception.printStackTrace();
   System.exit(1);
 }
Exemple #6
0
    public MobGroup(
        int Aid, int Aalign, ArrayList<MobGrade> possibles, Carte Map, int cell, int maxSize) {
      id = Aid;
      align = Aalign;
      // Détermination du nombre de mob du groupe
      _creationDate = System.currentTimeMillis();

      int rand = 0;
      int nbr = 0;

      switch (maxSize) {
        case 0:
          return;
        case 1:
          nbr = 1;
          break;
        case 2:
          nbr = Formulas.getRandomValue(1, 2); // 1:50%	2:50%
          break;
        case 3:
          nbr = Formulas.getRandomValue(1, 3); // 1:33.3334%	2:33.3334%	3:33.3334%
          break;
        case 4:
          rand = Formulas.getRandomValue(0, 99);
          if (rand < 22) // 1:22%
          nbr = 1;
          else if (rand < 48) // 2:26%
          nbr = 2;
          else if (rand < 74) // 3:26%
          nbr = 3;
          else // 4:26%
          nbr = 4;
          break;
        case 5:
          rand = Formulas.getRandomValue(0, 99);
          if (rand < 15) // 1:15%
          nbr = 1;
          else if (rand < 35) // 2:20%
          nbr = 2;
          else if (rand < 60) // 3:25%
          nbr = 3;
          else if (rand < 85) // 4:25%
          nbr = 4;
          else // 5:15%
          nbr = 5;
          break;
        case 6:
          rand = Formulas.getRandomValue(0, 99);
          if (rand < 10) // 1:10%
          nbr = 1;
          else if (rand < 25) // 2:15%
          nbr = 2;
          else if (rand < 45) // 3:20%
          nbr = 3;
          else if (rand < 65) // 4:20%
          nbr = 4;
          else if (rand < 85) // 5:20%
          nbr = 5;
          else // 6:15%
          nbr = 6;
          break;
        case 7:
          rand = Formulas.getRandomValue(0, 99);
          if (rand < 9) // 1:9%
          nbr = 1;
          else if (rand < 20) // 2:11%
          nbr = 2;
          else if (rand < 35) // 3:15%
          nbr = 3;
          else if (rand < 55) // 4:20%
          nbr = 4;
          else if (rand < 75) // 5:20%
          nbr = 5;
          else if (rand < 91) // 6:16%
          nbr = 6;
          else // 7:9%
          nbr = 7;
          break;
        default:
          rand = Formulas.getRandomValue(0, 99);
          if (rand < 9) // 1:9%
          nbr = 1;
          else if (rand < 20) // 2:11%
          nbr = 2;
          else if (rand < 33) // 3:13%
          nbr = 3;
          else if (rand < 50) // 4:17%
          nbr = 4;
          else if (rand < 67) // 5:17%
          nbr = 5;
          else if (rand < 80) // 6:13%
          nbr = 6;
          else if (rand < 91) // 7:11%
          nbr = 7;
          else // 8:9%
          nbr = 8;
          break;
      }
      // On vérifie qu'il existe des monstres de l'alignement demandé pour éviter les boucles
      // infinies
      boolean haveSameAlign = false;
      for (MobGrade mob : possibles) {
        if (mob.getTemplate().getAlign() == align) haveSameAlign = true;
      }

      if (!haveSameAlign) return; // S'il n'y en a pas
      int guid = -1;

      int maxLevel = 0;
      for (int a = 0; a < nbr; a++) {
        MobGrade Mob = null;
        do {
          int random =
              Formulas.getRandomValue(
                  0, possibles.size() - 1); // on prend un mob au hasard dans le tableau
          Mob = possibles.get(random).getCopy();
        } while (Mob.getTemplate().getAlign() != align);

        if (Mob.getLevel() > maxLevel) maxLevel = Mob.getLevel();

        _Mobs.put(guid, Mob);
        guid--;
      }
      aggroDistance = Constants.getAggroByLevel(maxLevel);

      if (align != Constants.ALIGNEMENT_NEUTRE) aggroDistance = 15;

      cellID = (cell == -1 ? Map.getRandomFreeCellID() : cell);
      if (cellID == 0) return;

      orientation = Formulas.getRandomValue(0, 3) * 2;
      isFix = false;
    }
Exemple #7
0
 private long get_timeElapsedInSeconds() {
   return ((System.currentTimeMillis() - _creationDate)) / 1000;
 }