Exemplo n.º 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();
    }
  }
Exemplo n.º 2
0
 public void surrender(String msg) {
   try {
     String name = msg.substring(10);
     Vector v = father.onlineList;
     int size = v.size();
     for (int i = 0; i < size; i++) {
       ServerAgentThread tempSat = (ServerAgentThread) v.get(i);
       if (tempSat.getName().equals(name)) {
         tempSat.dout.writeUTF(msg);
         break;
       }
     }
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
Exemplo n.º 3
0
 public void challenge(String msg) {
   try {
     String name1 = this.getName();
     String name2 = msg.substring(13);
     Vector v = father.onlineList;
     int size = v.size();
     for (int i = 0; i < size; i++) {
       ServerAgentThread tempSat = (ServerAgentThread) v.get(i);
       if (tempSat.getName().equals(name2)) {
         tempSat.dout.writeUTF("<#CHALLENGE#>" + name1);
         break;
       }
     }
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
Exemplo n.º 4
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();
    }
  }