示例#1
0
  public void nick_name(String msg) {
    try {
      String name = msg.substring(13);
      this.setName(name);
      Vector v = father.onlineList;
      boolean isRepeatedName = false;
      int size = v.size();
      for (int i = 0; i < size; i++) {
        ServerAgentThread tempSat = (ServerAgentThread) v.get(i);
        if (tempSat.getName().equals(name)) {
          isRepeatedName = true;
          break;
        }
      }
      if (isRepeatedName == true) {
        dout.writeUTF("<#NAME_REPEATED#>");
        din.close();
        dout.close();
        sc.close();
        flag = false;
      } else {
        v.add(this);
        father.refreshList();
        String nickListMsg = "";
        StringBuilder nickListMsgSb = new StringBuilder();
        size = v.size();
        for (int i = 0; i < size; i++) {
          ServerAgentThread tempSat = (ServerAgentThread) v.get(i);
          nickListMsgSb.append("!");
          nickListMsgSb.append(tempSat.getName());
        }
        nickListMsgSb.append("<#NICK_LIST#>");
        nickListMsg = nickListMsgSb.toString();
        Vector tempv = father.onlineList;
        size = tempv.size();
        for (int i = 0; i < size; i++) {
          ServerAgentThread tempSat = (ServerAgentThread) tempv.get(i);
          tempSat.dout.writeUTF(nickListMsg);
          if (tempSat != this) {
            tempSat.dout.writeUTF("<#MSG#>" + this.getName() + "is now online....");
          }
        }
      }

    } catch (IOException e) {
      e.printStackTrace();
    }
  }
示例#2
0
  public void client_leave(String msg) {
    try {
      Vector tempv = father.onlineList;
      tempv.remove(this);
      int size = tempv.size();
      String nl = "<#NICK_LIST#>";
      for (int i = 0; i < size; i++) {
        ServerAgentThread tempSat = (ServerAgentThread) tempv.get(i);
        tempSat.dout.writeUTF("<#MSG#>" + this.getName() + "is offline....");
        nl = nl + "|" + tempSat.getName();
      }

      for (int i = 0; i < size; i++) {
        ServerAgentThread tempSat = (ServerAgentThread) tempv.get(i);
        tempSat.dout.writeUTF(nl);
      }
      this.flag = false;
      father.refreshList();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }