home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1999 May / PCWK5A99.ISO / Linuxwld / linuxwld.exe / ChatSession.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-05-31  |  5.7 KB  |  241 lines

  1. import java.net.URL;
  2. import java.util.StringTokenizer;
  3.  
  4. public class ChatSession extends IRCSession {
  5.    public ParaChat gui;
  6.    String nickName;
  7.    String realName;
  8.    String connectAlg;
  9.    String password;
  10.    private boolean unicode;
  11.    private boolean roomAdmin = false;
  12.    private boolean isSU = false;
  13.    private boolean inError = false;
  14.    private String operator;
  15.  
  16.    public boolean isSU() {
  17.       return this.isSU;
  18.    }
  19.  
  20.    public boolean isRoomAdmin() {
  21.       return this.roomAdmin;
  22.    }
  23.  
  24.    public String getOperator() {
  25.       return this.operator;
  26.    }
  27.  
  28.    private boolean legalAdminCommand(String var1) {
  29.       if (!this.roomAdmin) {
  30.          return false;
  31.       } else {
  32.          return var1.startsWith("/expel") || var1.startsWith("/topic") || var1.startsWith("/room") || var1.startsWith("/pch_display") || var1.startsWith("/pch_meta");
  33.       }
  34.    }
  35.  
  36.    public void userSaid(String var1) {
  37.       if (var1 != null && var1.length() != 0) {
  38.          try {
  39.             var1 = var1.trim();
  40.             if (var1.charAt(0) == '/' && !this.legalAdminCommand(var1) && !this.isSU) {
  41.                this.toUser("Sorry, IRC-style '/' commands are not supported.");
  42.                this.toUser("type '*admin' to get the room admin console (admin privs needed)");
  43.                this.toUser("type '*beep' to control audio cues when people enter and depart the room");
  44.                this.toUser("type '*chat' to set your chat window properties");
  45.                this.toUser("type '*ignore' to ignore messages from any other nickname");
  46.                this.toUser("type '*page' to request a private conversation with an operator");
  47.                this.toUser("type '*priv <nickname>' to set up a private window for that nick");
  48.                this.toUser("type '/help' to get this message");
  49.             } else {
  50.                super.userSaid(var1);
  51.             }
  52.          } catch (Exception var2) {
  53.          }
  54.       }
  55.    }
  56.  
  57.    protected void toUser(String var1) {
  58.       this.gui.toUser(var1);
  59.    }
  60.  
  61.    protected void toUser(String var1, String var2, String var3) {
  62.       this.gui.toUser(var1, var2, var3);
  63.    }
  64.  
  65.    protected void msgYouAreAdmin() {
  66.       this.toUser("**** You have room administration powers *****");
  67.       this.roomAdmin = true;
  68.    }
  69.  
  70.    protected void msgYouAreSuperUser() {
  71.       this.toUser("**** You have SYSTEM administration powers *****");
  72.       this.isSU = true;
  73.    }
  74.  
  75.    protected void msgUserSockAccept() {
  76.       this.toUser(">> The remote machine has accepted the network request ... please wait.");
  77.    }
  78.  
  79.    protected void msgPing() {
  80.    }
  81.  
  82.    protected void msgUserJoin(String var1, String var2) {
  83.       if (this.gui.showJoinLeave) {
  84.          this.toUser(">> " + var1 + " has joined channel " + var2);
  85.       }
  86.  
  87.       this.gui.addUser(var1);
  88.       if (this.gui.entryBeep != null) {
  89.          this.gui.play(this.gui.getCodeBase(), "sounds/" + this.gui.entryBeep);
  90.       }
  91.  
  92.    }
  93.  
  94.    protected void msgUserPart(String var1, String var2) {
  95.       if (this.gui.showJoinLeave) {
  96.          this.toUser(">> " + var1 + " has left channel " + var2);
  97.       }
  98.  
  99.       this.gui.partUser(var1);
  100.       if (this.gui.partBeep != null) {
  101.          this.gui.play(this.gui.getCodeBase(), "sounds/" + this.gui.partBeep);
  102.       }
  103.  
  104.    }
  105.  
  106.    protected void msgPrivMsg(String var1, String var2, String var3) {
  107.       if (!this.gui.toBeIgnored(var1)) {
  108.          this.toUser(var1, var2, var3);
  109.       }
  110.    }
  111.  
  112.    protected void msgPrivMsg(String var1, String var2) {
  113.       if (!this.gui.toBeIgnored(var1)) {
  114.          this.toUser("[" + var1 + "] >>" + var2);
  115.       }
  116.  
  117.    }
  118.  
  119.    protected void miscCmd(int var1, String var2) {
  120.    }
  121.  
  122.    protected void msgUserMotd(String var1) {
  123.       this.toUser(var1);
  124.    }
  125.  
  126.    protected void msgUserWelcome(String var1) {
  127.       this.gui.msgConnect();
  128.    }
  129.  
  130.    protected void msgUserTopic(String var1) {
  131.       this.toUser("The topic is: " + var1);
  132.    }
  133.  
  134.    protected void msgUserNames(String var1) {
  135.       this.gui.setUserNames(var1);
  136.    }
  137.  
  138.    protected void msgUserError(int var1, String var2) {
  139.       if (!this.inError) {
  140.          this.inError = true;
  141.          if (var1 != 421 && var1 != 451) {
  142.             if (var1 == 551) {
  143.                StringTokenizer var3 = new StringTokenizer(var2);
  144.                String var4 = var3.nextToken();
  145.                String var5 = var3.nextToken();
  146.                int var6 = Integer.parseInt(var5);
  147.                this.gui.toUser("ParaChat has detected a request to move your session to a different server.");
  148.                this.gui.toUser("This may be in order to balance load on the servers, or to replace/update a server");
  149.                this.gui.toUser("Please wait while we try and reconnect your session to " + var4 + ":" + var5);
  150.                this.inError = false;
  151.  
  152.                try {
  153.                   ((IRCSession)this).connect(this.nickName, this.password, this.realName, var4, var6, -1, this.connectAlg, this.unicode);
  154.                } catch (Exception var8) {
  155.                   ((Throwable)var8).printStackTrace();
  156.                   this.gui.toUser("Redirection connection to " + var4 + ":" + var6 + " failed: " + var8);
  157.                   this.gui.msgDisconnect("Could not connect to redirected server " + var4 + ":" + var6);
  158.                }
  159.             } else {
  160.                if (this.gui != null) {
  161.                   this.gui.msgDisconnect(var2);
  162.                }
  163.  
  164.                this.gui = null;
  165.                ((IRCSession)this).disconnect();
  166.                this.inError = false;
  167.             }
  168.          }
  169.       }
  170.    }
  171.  
  172.    protected void msgSwitchChannel(String var1) {
  173.       if (this.gui != null) {
  174.          this.gui.setChannel(var1);
  175.       }
  176.  
  177.    }
  178.  
  179.    protected void msgUserDisplay(String var1) {
  180.       if (this.gui != null) {
  181.          StringTokenizer var2 = new StringTokenizer(var1);
  182.          if (var2.hasMoreTokens()) {
  183.             String var3 = var2.nextToken();
  184.             if (var3.equals("upres")) {
  185.                this.gui.handleSingleDirective("upresdisp", var2, true);
  186.                return;
  187.             }
  188.  
  189.             if (var3.equals("touser")) {
  190.                if (var2.hasMoreTokens()) {
  191.                   String var4 = var2.nextToken("\n");
  192.                   this.gui.toUser(var4);
  193.                   return;
  194.                }
  195.             } else {
  196.                if (var3.equals("cruise")) {
  197.                   try {
  198.                      this.gui.cruiseTo(new URL(var2.nextToken()));
  199.                      return;
  200.                   } catch (Exception var5) {
  201.                      return;
  202.                   }
  203.                }
  204.  
  205.                if (var3.equals("rpl_page")) {
  206.                   this.operator = var2.nextToken();
  207.                   this.gui.toUser(this.gui.xtab.translate("Starting a private conversation with operator ") + this.operator);
  208.                   this.gui.handleSingleDirective("page_operator", var2, true);
  209.                   return;
  210.                }
  211.  
  212.                if (var3.equals("exec")) {
  213.                   try {
  214.                      String var7 = var2.nextToken("\n");
  215.                      this.gui.toUser("[executing remote control command \"" + var7 + "\"]\n");
  216.                      this.gui.executeLine(var7);
  217.                      return;
  218.                   } catch (Exception var6) {
  219.                      return;
  220.                   }
  221.                }
  222.             }
  223.          }
  224.       }
  225.  
  226.    }
  227.  
  228.    public ChatSession() {
  229.       super(System.out, System.out);
  230.    }
  231.  
  232.    public void init(ParaChat var1, String var2, String var3, String var4, String var5, boolean var6) {
  233.       this.gui = var1;
  234.       this.nickName = var2;
  235.       this.realName = var4;
  236.       this.password = var3;
  237.       this.connectAlg = var5;
  238.       this.unicode = var6;
  239.    }
  240. }
  241.