msg.java

来自「jsp开发的在线答疑系统」· Java 代码 · 共 87 行

JAVA
87
字号

package chatweb;


public class Msg {
  
   
   public static final int TYPE_MSG = 0;
   
   public static final int TYPE_CUSTOMMSG = 1;
  
   public static final int TYPE_INFO = 2;
   
   public static final int TYPE_ERROR = 3;
   
   public static final int TYPE_WSPSND = 11;
   
   public static final int TYPE_WSPRCV = 12;
  
   public static final int TYPE_USERS = 20;
   
   public static final int TYPE_ADMIN = 30;
   
   public static final int TYPE_ADMINCHANGE = 31;
   
   public static final int TYPE_KEEPQUIET = 40;
  
   public static final int TYPE_KICKOUT = 41;

  
   private final int to;
 
   private final String writer;
 
   private final String msg;

   private final int msgType;


   public Msg(
      final int msgType,
      final int to,
      final String msg,
      final String writer) {
      this.to = to;
      this.msg = msg;
      this.writer = writer;
      this.msgType = msgType;
   }


   public final String getString(final int id) {
      if (to == -1 || to == id || id == -2) {
         switch (msgType) {
            case Msg.TYPE_MSG :
               return ("MSG:" + writer + ">" + msg + "\r\n");
            case Msg.TYPE_CUSTOMMSG :
               return ("CUSTOM:" + writer + ">" + msg + "\r\n");
            case Msg.TYPE_INFO :
               return ("INFO:" + writer + ">" + msg + "\r\n");
            case Msg.TYPE_USERS :
               return ("USERS:" + msg + "\r\n");
            case Msg.TYPE_ERROR :
               return ("ERROR:" + msg + "\r\n");
            case Msg.TYPE_WSPSND :
               return ("WSPSND:" + writer + ">" + msg + "\r\n");
            case Msg.TYPE_WSPRCV :
               return ("WSPRCV:" + writer + ">" + msg + "\r\n");
            case Msg.TYPE_ADMIN :
               return ("ADMIN:" + msg + "\r\n");
            case Msg.TYPE_ADMINCHANGE :
               return ("ADMCG:" + msg + "\r\n");
            case Msg.TYPE_KEEPQUIET :
               return ("KEEPQUIET:" + writer + ">" + msg + "\r\n");
            case Msg.TYPE_KICKOUT :
               return ("KICKOUT:" + writer + ">" + msg + "\r\n");
            default :
               System.out.println(
                  "msgtype :" + msgType);
               return null;
         }
      } else {
         return null;
      }
   }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?