示例#1
0
 /**
  * Method to ignore all incoming messages from a user
  *
  * @param i the user to ignore
  * @param quite if true will not show confirmation
  * @return true on succes, false on failure
  */
 private boolean ignore(String i, boolean quiet) {
   if (username.equals(i) || i.equals("server") || admins.contains(i)) {
     if (!quiet) {
       error("can't ignore that person");
     }
     return false;
   }
   if (!users.contains(i)) {
     if (!quiet) {
       error("user does not exists");
     }
     return false;
   }
   if (ignores.contains(i)) {
     if (!quiet) {
       error("already ignoring user");
     }
     return false;
   }
   ignores.add(i);
   updateList();
   if (!quiet) {
     serverMessage("ignoring " + i);
   }
   return true;
 }
示例#2
0
 /**
  * adds a new user to the interal list of users
  *
  * @param un the name of the user to be added
  */
 public void userAdd(String un) {
   if (!users.contains(un)) {
     users.add(un);
     updateList();
     if (!un.equals(username) && showUserStatus)
       serverMessage(un + " has joined " + server.channel);
   }
 }
示例#3
0
  public DecreasePheromone() {
    ArrayList<String> providedThings = new ArrayList<String>();
    providedThings.add("pheromone");
    this.setProperty("providedThings", providedThings);

    ArrayList<String> requiredThings = new ArrayList<String>();
    requiredThings.add("pheromone");
    requiredThings.add("parameterList");
    this.setProperty("requiredThings", requiredThings);
  }
示例#4
0
 /** cleans up a connection by removing all user from all maintained lists */
 public void close() {
   error("Connection to server was lost");
   admin = false;
   users.clear();
   afks.clear();
   ignores.clear();
   admins.clear();
   channels.clear();
   cboChannels.removeAllItems();
   updateList();
 }
  public void refresh() {
    Message message = new Message();
    try {
      message = this.trainingTeaBLService.showFrameStrategy();

    } catch (RemoteException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    if (message.getMesType().equals(MessageType.traTea_showStrategy_fail)) {
      // JOptionPane.showMessageDialog(this, "整体框架策略尚未发布!");
      jl1.setVisible(true);
      jb2.setEnabled(false);
      if (jsp1 != null) {
        jsp1.setVisible(false);
      }
    } else if (message.getMesType().equals(MessageType.traTea_showStrategy_success)) {
      jl1.setVisible(false);
      ArrayList<Dean> dean = message.getDeans();
      ArrayList<String> attriOfDean = message.getAttriOfDean();
      tm1 = new StrategyTableModel(dean, attriOfDean);
      if (jsp1 != null) {
        jt1.setModel(tm1);
        jsp1.setVisible(true);
      } else {
        jt1 = new JTable();
        jt1.setModel(tm1);

        jsp1 = new JScrollPane(jt1);
        strategy.add(jsp1);
      }

      if (dean.size() >= 15) {
        jb1.setEnabled(false);
      }

      jb2.setEnabled(true);

    } else {
      JOptionPane.showMessageDialog(this, "你的网络貌似有点问题!");
    }
  }
示例#6
0
  public void run() {
    ArrayList<Sensor> sensors = new ArrayList<Sensor>();
    ArrayList<Rule> rules = new ArrayList<Rule>();
    ArrayList<Actuator> actuators = new ArrayList<Actuator>();

    ArrayList<String> typeList =
        this.hasProperty("typeList")
            ? (ArrayList<String>) this.getBoxedProperty("typeList")
            : new ArrayList<String>();
    typeList.add("ddos");
    typeList.add("malicious");

    Location location = (Location) this.getBoxedProperty("location");

    Sampler sampler = (Sampler) this.getBoxedProperty("sampler");
    Double pheromone = (Double) sampler.execute().getBoxedProperty("result");

    Agent agent =
        (Agent)
            (new Agent())
                .setNewBoxedProperty("location", location)
                .setNewBoxedProperty("typeList", typeList)
                .setNewBoxedProperty("sensors", sensors)
                .setNewBoxedProperty("rules", rules)
                .setNewBoxedProperty("pheromone", pheromone)
                .setNewBoxedProperty("actuator", actuators);

    ArrayList<Agent> agentList = (ArrayList<Agent>) location.getBoxedProperty("agentList");

    Thing locationContainer = (new Thing()).setProperty("object", location);

    Thing agentListContainer = (new Thing()).setProperty("object", agentList);

    LocationSensor locationSensor =
        (LocationSensor)
            (new LocationSensor())
                .setNewBoxedProperty("agent", agent)
                .setProperty("resultContainer", locationContainer);
    sensors.add(locationSensor);

    AgentListSensor agentListSensor =
        (AgentListSensor)
            (new AgentListSensor())
                .setProperty("locationContainer", locationContainer)
                .setProperty("resultContainer", agentListContainer);
    sensors.add(agentListSensor);

    Thing DDoSCommAgentListContainer = new Thing();
    AgentSensor DDoSCommAgentSensor =
        (AgentSensor)
            (new AgentSensor())
                .setProperty("agentListContainer", agentListContainer)
                .setNewBoxedProperty("type", "ddoscomm")
                .setProperty("resultContainer", DDoSCommAgentListContainer);
    sensors.add(DDoSCommAgentSensor);

    ArrayList<Location> targetList =
        this.hasBoxedProperty("targetList")
            ? (ArrayList<Location>) this.getBoxedProperty("targetList")
            : new ArrayList<Location>();
    Thing targetListContainer = (new Thing()).setProperty("object", targetList);
    TargetSensor targetSensor =
        (TargetSensor)
            (new TargetSensor())
                .setProperty("DDoSCommAgentListContainer", DDoSCommAgentListContainer)
                .setProperty("targetListContainer", targetListContainer)
                .setProperty("resultContainer", targetListContainer);
    sensors.add(targetSensor);

    Thing graphContainer = (Thing) this.getProperty("graphContainer");
    Double lifeCounter =
        (Double)
            (this.hasProperty("lifeCounter")
                ? this.getBoxedProperty("lifeCounter")
                : new Double(100));

    MASONSimScheduler scheduler = (MASONSimScheduler) this.getBoxedProperty("scheduler");
    MASONSimDeScheduler descheduler = (MASONSimDeScheduler) this.getBoxedProperty("descheduler");

    ArrayList<String> ddosAttackTypeList = new ArrayList<String>();
    ddosAttackTypeList.add("ddosattack");
    ddosAttackTypeList.add("malicious");

    DDoSAgentRule ddosAgentRule =
        (DDoSAgentRule)
            (new DDoSAgentRule())
                .setNewBoxedProperty(
                    "SendCommAgentListActuator",
                    (new SendCommAgentListActuator())
                        .setNewBoxedProperty("scheduler", scheduler)
                        .setNewBoxedProperty("descheduler", descheduler)
                        .setProperty("locationContainer", locationContainer)
                        .setProperty("targetListContainer", targetListContainer)
                        .setProperty("graphContainer", graphContainer)
                        .setProperty("agentListContainer", agentListContainer)
                        .setNewBoxedProperty(
                            "CreateAgentActuator",
                            (new CreateAgentActuator())
                                .setNewBoxedProperty("scheduler", scheduler)
                                .setNewBoxedProperty("descheduler", descheduler)
                                .setNewBoxedProperty(
                                    "agentGenerator",
                                    (new CommAgentGenerator())
                                        .setNewBoxedProperty("typeList", ddosAttackTypeList)
                                        .setNewBoxedProperty("scheduler", scheduler)
                                        .setNewBoxedProperty("descheduler", descheduler)
                                        .setNewBoxedProperty("location", location)
                                        .setProperty("graphContainer", graphContainer)
                                        .setNewBoxedProperty("lifeCounter", lifeCounter))
                                .setProperty("agentListContainer", agentListContainer)));

    rules.add(ddosAgentRule);

    this.setNewBoxedProperty("result", agent);
  }
示例#7
0
 /**
  * Recieving method for private
  *
  * @param un the name of the user sending the message
  * @param message the message that was sent
  */
 public void recievePrivate(String un, String message) {
   if (!ignores.contains(un)) {
     privates.recievePrivate(un, message);
   }
 }
示例#8
0
 /**
  * Reciving method for a whisper
  *
  * @param un the name of the user sending the whisper
  * @param message the message that was sent
  */
 public void recieveWhisper(String un, String message) {
   if (!ignores.contains(un)) {
     sendText(un, message, true);
   }
 }
示例#9
0
 /**
  * Recieving method for a chat message
  *
  * @param un the name of the user sending the chat
  * @param message the message that was sent
  */
 public void recieveChat(String un, String message) {
   if (!ignores.contains(un)) {
     sendText(un, message, false);
   }
 }
示例#10
0
 /**
  * changes the name of a user, updating list of admins, afks, ignoes, and master user list
  *
  * @param on old username
  * @param nn new username
  */
 public void rename(String on, String nn) {
   if (admins.contains(on)) {
     admins.remove(admins.indexOf(on));
     admins.add(nn);
   }
   if (afks.contains(on)) {
     afks.remove(afks.indexOf(on));
     afks.add(nn);
   }
   if (ignores.contains(on)) {
     ignores.remove(ignores.indexOf(on));
     ignores.add(nn);
   }
   users.remove(on);
   users.add(nn);
   updateList();
   serverMessage(on + " renamed to " + nn);
 }
示例#11
0
 /**
  * removes a user from the user list
  *
  * @param un the name of the user to be removed
  */
 public void userDel(String un) {
   users.remove(users.indexOf(un));
   if (ignores.contains(un)) {
     ignores.remove(ignores.indexOf(un));
   }
   if (afks.contains(un)) {
     afks.remove(afks.indexOf(un));
   }
   if (admins.contains(un)) {
     admins.remove(admins.indexOf(un));
   }
   updateList();
   serverMessage(un + " has left " + server.channel);
   privates.serverMessage(un, un + " has left");
 }
示例#12
0
 /** sorts the user list and rebuilds the user list from the sorted user vector, */
 public void updateList() {
   Object[] tmp = users.toArray();
   Arrays.sort(tmp);
   userList.setListData(tmp);
 }
示例#13
0
  /**
   * Method to parse a command and perform the specified action
   *
   * @param cmd the command that the user typed
   * @return a status indicator to tell if the command was valid
   */
  public boolean parseCommand(String cmd) {
    cmd = cmd.intern();
    if (cmd == "help" || cmd == "?") {
      String commands =
          "Listing  available commands:\n"
              + "<pre>\\help or \\? \t\t- display this message<br>"
              + "\\admin &lt;passphrase&gt; \t- become an admin<br>"
              + "\\create &lt;channel&gt; [password]\t- create a new channel with optional password<br>"
              + "\\join &lt;channel&gt;  [password]\t- join channel with optional password<br>"
              + "\\disconnect \t\t- disconnect from server<br>"
              + "\\whisper &lt;user&gt; &lt;message&gt; \t- whisper to a user<br>"
              + "\\private &lt;user&gt; \t- start a private message session<br>"
              + "\\ignore &lt;user&gt; \t- ignores a user<br>"
              + "\\clearignore \t\t- clear list of ignores<br>"
              + "\\reconnect \t\t- attempt to reconnect to server<br>"
              + "\\rename &lt;new name&gt; \t- change your username<br>"
              + "\\invite &lt;user&gt; \t- invite user to join at your channel<br>";
      if (admin) {
        commands +=
            "\\kick &lt;user&gt; \t\t- kick user from room<br>"
                + "\\logstart \t\t- start logging sessoin<br>"
                + "\\logstop \t\t- stop logging session<br>";
      }
      commands += "up or down \t\t- cycle your chat history</pre>";
      sendText("server", commands, false);
      return true;
    } else if (cmd == "disconnect") {
      if (server != null) {
        stop();
      }
      return true;
    } else if (cmd == "reconnect") {
      if (username == null) {
        error(
            "username still invalid. use \\rename &lt;new name&gt; to chose a new name and reconnect");
      } else {
        if (server != null) {
          stop();
        }
        server = new ServerConnection(this);
      }
      return true;
    } else if (cmd == "clearignore") {
      ignores.clear();
      updateList();
      serverMessage("ignore list cleared");
      return true;
    } else if (cmd.startsWith("whisper")) {
      int start = cmd.indexOf(' ');
      if (start < 0) {
        error("usage: \\whisper &lt;user&gt; &lt;message&gt;");
        return false;
      }
      cmd = cmd.substring(start + 1);
      start = cmd.indexOf(' ');
      if (start < 0) {
        error("usage: \\whisper &lt;user&gt; &lt;message&gt;");
        return false;
      }
      String un = cmd.substring(0, start);
      if (username.equals(un) || !users.contains(un)) {
        error("invalid user");
        return false;
      }
      String message = cmd.substring(start + 1);
      if (message.length() < 1) {
        error("usage: \\whisper &lt;user&gt; &lt;message&gt;");
      }
      sendWhisper(un, message);
      sendText(username, message, true);
      return true;
    } else if (cmd.startsWith("invite")) {
      String channel = (String) cboChannels.getSelectedItem();
      int start = cmd.indexOf(' ');
      if (start < 0) {
        error("usage: \\invite &lt;user&gt;");
        return false;
      }

      String un = cmd.substring(start + 1);

      if ((un.length() < 1) || (un.length() > 10) || (!un.matches("[\\w_-]+?"))) {
        error(un + " invalid user");
        return false;
      }

      if (username.equals(un)) {
        error("You cannot invite youself");
        return false;
      }

      if (users.contains(un)) {
        error(un + "  is already in your Channel");
        return false;
      }
      String message = un + " has been invited to join a channel " + channel;
      sendInvite(un, message);
      sendText(username, message, false);
      return true;

    } else if (cmd.startsWith("private")) {
      int start = cmd.indexOf(' ');
      if (start < 0) {
        error("usage: \\private &lt;user&gt;");
        return false;
      }
      String un = cmd.substring(start + 1);
      if (username.equals(un)) {
        error("cannot private message yourself");
        return false;
      }
      privates.newPrivate(un);
      return true;
    } else if (cmd.startsWith("rename")) {
      int start = cmd.indexOf(' ');
      if (start < 0) {
        error("usage: \\rename &lt;newname&gt;");
        return false;
      }
      String newName = cmd.substring(start + 1);
      if ((newName.length() < 1)
          || (newName.length()) > 10
          || (newName.equals("server"))
          || (!newName.matches("[\\w_-]+?"))) {
        error("invalid name");
        return false;
      }
      if (!server.connected) {
        server = new ServerConnection(this);
      }
      if (username == null) {
        username = newName;
        server.writeObject(new SD_UserAdd(newName));
      } else {
        rename(username, newName);
        username = newName;
        server.writeObject(new SD_Rename(null, username));
      }
      return true;
    } else if (cmd.startsWith("ignore")) {
      int start = cmd.indexOf(' ');
      if (start < 0) {
        error("usage: \\ignre &lt;user&gt;");
        return false;
      }
      ignore(cmd.substring(start + 1), false);
      return true;
    } else if (cmd.startsWith("join")) {
      int start = cmd.indexOf(' ');
      if (start < 0) {
        error("usage: \\join &lt;channel&gt; [password]");
        return false;
      }
      String name = cmd.substring(start + 1);
      String pass = null;
      start = name.indexOf(' ');
      if (start > 0) {
        pass = name.substring(start + 1);
        name = name.substring(0, start);
      }
      server.writeObject(new SD_Channel(false, name, pass));
      return true;
    } else if (cmd.startsWith("create")) {
      int start = cmd.indexOf(' ');
      if (start < 0) {
        error("usage: \\create &lt;channel&gt; [password]");
        return false;
      }
      String name = cmd.substring(start + 1);
      String pass = null;
      start = name.indexOf(' ');
      if (start > 0) {
        pass = name.substring(start + 1);
        name = name.substring(0, start);
      }
      server.writeObject(new SD_Channel(true, name, pass));
      return true;
      /*		} else if (cmd.startsWith("proxy")) {
      int start = cmd.indexOf(' ');
      if (start < 0) {
      	error("usage: \\proxy &lt;host&gt; &lt;port&gt;");
      	return false;
      }
      String phost = cmd.substring(start+1);
      start = phost.indexOf(' ');
      if (start < 0) {
      	error("usage: \\proxy &lt;host&gt; &lt;port&gt;");
      	return false;
      }
      String pport = phost.substring(start+1);
      phost = phost.substring(0, start);
      Properties systemSettings = System.getProperties();
      systemSettings.put("proxySet", "true");
      systemSettings.put("proxyHost", phost);
      systemSettings.put("proxyPort", pport);
      System.setProperties(systemSettings);
      serverMessage("Using " + phost + ":" + pport + " as proxy server<br>you can type \\reconnect to reconnect with this proxy");
      return true; */
    } else if (cmd.startsWith("admin")) {
      int start = cmd.indexOf(' ');
      if (start < 0) {
        error("usage: \\admin &lt;password&gt;");
        return false;
      }
      String pass = cmd.substring(start + 1);
      server.writeObject(new SD_AdminAdd(pass));
      return true;
    } else if (admin && cmd.startsWith("kick")) {
      int start = cmd.indexOf(' ');
      if (start < 0) {
        error("usage: \\kick &lt;user&gt;");
        return false;
      }
      String un = cmd.substring(start + 1);
      if (un.equals(username)) {
        error("cannot kick yourself");
        return false;
      }
      server.writeObject(new SD_Kick(un));
      return true;
    } else if (admin && cmd == "logstart") {
      server.writeObject(new SD_Log(true));
      return true;
    } else if (admin && cmd == "logstop") {
      server.writeObject(new SD_Log());
      return true;
    }
    error("unrecognized command, type \\help for help");
    return false;
  }