home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1999 April / PCO0499.ISO / filesbbs / mac / vnc-mac.hqx / binary / Server / VNCServer.rsrc / JAVA_133_rfbProto.class (.txt) < prev    next >
Encoding:
Java Class File  |  1999-01-25  |  8.1 KB  |  435 lines

  1. import java.awt.Event;
  2. import java.io.BufferedInputStream;
  3. import java.io.DataInputStream;
  4. import java.io.IOException;
  5. import java.io.OutputStream;
  6. import java.net.Socket;
  7.  
  8. class rfbProto {
  9.    final String versionMsg = "RFB 003.003\n";
  10.    final int ConnFailed;
  11.    final int NoAuth = 1;
  12.    final int VncAuth = 2;
  13.    final int VncAuthOK;
  14.    final int VncAuthFailed = 1;
  15.    final int VncAuthTooMany = 2;
  16.    final int FramebufferUpdate;
  17.    final int SetColourMapEntries = 1;
  18.    final int Bell = 2;
  19.    final int ServerCutText = 3;
  20.    final int SetPixelFormat;
  21.    final int FixColourMapEntries = 1;
  22.    final int SetEncodings = 2;
  23.    final int FramebufferUpdateRequest = 3;
  24.    final int KeyEvent = 4;
  25.    final int PointerEvent = 5;
  26.    final int ClientCutText = 6;
  27.    static final int EncodingRaw = 0;
  28.    static final int EncodingCopyRect = 1;
  29.    static final int EncodingRRE = 2;
  30.    static final int EncodingCoRRE = 4;
  31.    static final int EncodingHextile = 5;
  32.    final int HextileRaw = 1;
  33.    final int HextileBackgroundSpecified = 2;
  34.    final int HextileForegroundSpecified = 4;
  35.    final int HextileAnySubrects = 8;
  36.    final int HextileSubrectsColoured = 16;
  37.    String host;
  38.    int port;
  39.    Socket sock;
  40.    // $FF: renamed from: is java.io.DataInputStream
  41.    DataInputStream field_0;
  42.    // $FF: renamed from: os java.io.OutputStream
  43.    OutputStream field_1;
  44.    boolean inNormalProtocol = false;
  45.    // $FF: renamed from: v vncviewer
  46.    vncviewer field_2;
  47.    int serverMajor;
  48.    int serverMinor;
  49.    String desktopName;
  50.    int framebufferWidth;
  51.    int framebufferHeight;
  52.    int bitsPerPixel;
  53.    int depth;
  54.    boolean bigEndian;
  55.    boolean trueColour;
  56.    int redMax;
  57.    int greenMax;
  58.    int blueMax;
  59.    int redShift;
  60.    int greenShift;
  61.    int blueShift;
  62.    int updateNRects;
  63.    int updateRectX;
  64.    int updateRectY;
  65.    int updateRectW;
  66.    int updateRectH;
  67.    int updateRectEncoding;
  68.    int copyRectSrcX;
  69.    int copyRectSrcY;
  70.    byte[] eventBuf = new byte[72];
  71.    int eventBufLen;
  72.    int pointerMask;
  73.    int oldModifiers;
  74.  
  75.    rfbProto(String var1, int var2, vncviewer var3) throws IOException {
  76.       this.field_2 = var3;
  77.       this.host = var1;
  78.       this.port = var2;
  79.       this.sock = new Socket(this.host, this.port);
  80.       this.field_0 = new DataInputStream(new BufferedInputStream(this.sock.getInputStream(), 16384));
  81.       this.field_1 = this.sock.getOutputStream();
  82.    }
  83.  
  84.    void close() {
  85.       try {
  86.          this.sock.close();
  87.       } catch (Exception var2) {
  88.          ((Throwable)var2).printStackTrace();
  89.       }
  90.    }
  91.  
  92.    void readVersionMsg() throws IOException {
  93.       byte[] var1 = new byte[12];
  94.       this.field_0.readFully(var1);
  95.       if (var1[0] == 82 && var1[1] == 70 && var1[2] == 66 && var1[3] == 32 && var1[4] >= 48 && var1[4] <= 57 && var1[5] >= 48 && var1[5] <= 57 && var1[6] >= 48 && var1[6] <= 57 && var1[7] == 46 && var1[8] >= 48 && var1[8] <= 57 && var1[9] >= 48 && var1[9] <= 57 && var1[10] >= 48 && var1[10] <= 57 && var1[11] == 10) {
  96.          this.serverMajor = (var1[4] - 48) * 100 + (var1[5] - 48) * 10 + (var1[6] - 48);
  97.          this.serverMinor = (var1[8] - 48) * 100 + (var1[9] - 48) * 10 + (var1[10] - 48);
  98.       } else {
  99.          throw new IOException("Host " + this.host + " port " + this.port + " is not an RFB server");
  100.       }
  101.    }
  102.  
  103.    void writeVersionMsg() throws IOException {
  104.       byte[] var1 = new byte[12];
  105.       "RFB 003.003\n".getBytes(0, 12, var1, 0);
  106.       this.field_1.write(var1);
  107.    }
  108.  
  109.    int readAuthScheme() throws IOException {
  110.       int var1 = this.field_0.readInt();
  111.       switch (var1) {
  112.          case 0:
  113.             int var2 = this.field_0.readInt();
  114.             byte[] var3 = new byte[var2];
  115.             this.field_0.readFully(var3);
  116.             throw new IOException(new String(var3, 0));
  117.          case 1:
  118.          case 2:
  119.             return var1;
  120.          default:
  121.             throw new IOException("Unknown authentication scheme from RFB server " + var1);
  122.       }
  123.    }
  124.  
  125.    void writeClientInit() throws IOException {
  126.       if (this.field_2.options.shareDesktop) {
  127.          this.field_1.write(1);
  128.       } else {
  129.          this.field_1.write(0);
  130.       }
  131.  
  132.       this.field_2.options.disableShareDesktop();
  133.    }
  134.  
  135.    void readServerInit() throws IOException {
  136.       this.framebufferWidth = this.field_0.readUnsignedShort();
  137.       this.framebufferHeight = this.field_0.readUnsignedShort();
  138.       this.bitsPerPixel = this.field_0.readUnsignedByte();
  139.       this.depth = this.field_0.readUnsignedByte();
  140.       this.bigEndian = this.field_0.readUnsignedByte() != 0;
  141.       this.trueColour = this.field_0.readUnsignedByte() != 0;
  142.       this.redMax = this.field_0.readUnsignedShort();
  143.       this.greenMax = this.field_0.readUnsignedShort();
  144.       this.blueMax = this.field_0.readUnsignedShort();
  145.       this.redShift = this.field_0.readUnsignedByte();
  146.       this.greenShift = this.field_0.readUnsignedByte();
  147.       this.blueShift = this.field_0.readUnsignedByte();
  148.       byte[] var1 = new byte[3];
  149.       this.field_0.read(var1);
  150.       int var2 = this.field_0.readInt();
  151.       byte[] var3 = new byte[var2];
  152.       this.field_0.readFully(var3);
  153.       this.desktopName = new String(var3, 0);
  154.       this.inNormalProtocol = true;
  155.    }
  156.  
  157.    int readServerMessageType() throws IOException {
  158.       return this.field_0.read();
  159.    }
  160.  
  161.    void readFramebufferUpdate() throws IOException {
  162.       this.field_0.readByte();
  163.       this.updateNRects = this.field_0.readUnsignedShort();
  164.    }
  165.  
  166.    void readFramebufferUpdateRectHdr() throws IOException {
  167.       this.updateRectX = this.field_0.readUnsignedShort();
  168.       this.updateRectY = this.field_0.readUnsignedShort();
  169.       this.updateRectW = this.field_0.readUnsignedShort();
  170.       this.updateRectH = this.field_0.readUnsignedShort();
  171.       this.updateRectEncoding = this.field_0.readInt();
  172.       if (this.updateRectX + this.updateRectW > this.framebufferWidth || this.updateRectY + this.updateRectH > this.framebufferHeight) {
  173.          throw new IOException("Framebuffer update rectangle too large: " + this.updateRectW + "x" + this.updateRectH + " at (" + this.updateRectX + "," + this.updateRectY + ")");
  174.       }
  175.    }
  176.  
  177.    void readCopyRect() throws IOException {
  178.       this.copyRectSrcX = this.field_0.readUnsignedShort();
  179.       this.copyRectSrcY = this.field_0.readUnsignedShort();
  180.    }
  181.  
  182.    String readServerCutText() throws IOException {
  183.       byte[] var1 = new byte[3];
  184.       this.field_0.read(var1);
  185.       int var2 = this.field_0.readInt();
  186.       byte[] var3 = new byte[var2];
  187.       this.field_0.readFully(var3);
  188.       return new String(var3, 0);
  189.    }
  190.  
  191.    void writeFramebufferUpdateRequest(int var1, int var2, int var3, int var4, boolean var5) throws IOException {
  192.       byte[] var6 = new byte[]{3, (byte)(var5 ? 1 : 0), (byte)(var1 >> 8 & 255), (byte)(var1 & 255), (byte)(var2 >> 8 & 255), (byte)(var2 & 255), (byte)(var3 >> 8 & 255), (byte)(var3 & 255), (byte)(var4 >> 8 & 255), (byte)(var4 & 255)};
  193.       this.field_1.write(var6);
  194.    }
  195.  
  196.    void writeSetPixelFormat(int var1, int var2, boolean var3, boolean var4, int var5, int var6, int var7, int var8, int var9, int var10) throws IOException {
  197.       byte[] var11 = new byte[]{0, 0, 0, 0, (byte)var1, (byte)var2, (byte)(var3 ? 1 : 0), (byte)(var4 ? 1 : 0), (byte)(var5 >> 8 & 255), (byte)(var5 & 255), (byte)(var6 >> 8 & 255), (byte)(var6 & 255), (byte)(var7 >> 8 & 255), (byte)(var7 & 255), (byte)var8, (byte)var9, (byte)var10, 0, 0, 0};
  198.       this.field_1.write(var11);
  199.    }
  200.  
  201.    void writeFixColourMapEntries(int var1, int var2, int[] var3, int[] var4, int[] var5) throws IOException {
  202.       byte[] var6 = new byte[6 + var2 * 6];
  203.       var6[0] = 1;
  204.       var6[2] = (byte)(var1 >> 8 & 255);
  205.       var6[3] = (byte)(var1 & 255);
  206.       var6[4] = (byte)(var2 >> 8 & 255);
  207.       var6[5] = (byte)(var2 & 255);
  208.  
  209.       for(int var7 = 0; var7 < var2; ++var7) {
  210.          var6[6 + var7 * 6] = (byte)(var3[var7] >> 8 & 255);
  211.          var6[6 + var7 * 6 + 1] = (byte)(var3[var7] & 255);
  212.          var6[6 + var7 * 6 + 2] = (byte)(var4[var7] >> 8 & 255);
  213.          var6[6 + var7 * 6 + 3] = (byte)(var4[var7] & 255);
  214.          var6[6 + var7 * 6 + 4] = (byte)(var5[var7] >> 8 & 255);
  215.          var6[6 + var7 * 6 + 5] = (byte)(var5[var7] & 255);
  216.       }
  217.  
  218.       this.field_1.write(var6);
  219.    }
  220.  
  221.    void writeSetEncodings(int[] var1, int var2) throws IOException {
  222.       byte[] var3 = new byte[4 + 4 * var2];
  223.       var3[0] = 2;
  224.       var3[2] = (byte)(var2 >> 8 & 255);
  225.       var3[3] = (byte)(var2 & 255);
  226.  
  227.       for(int var4 = 0; var4 < var2; ++var4) {
  228.          var3[4 + 4 * var4] = (byte)(var1[var4] >> 24 & 255);
  229.          var3[5 + 4 * var4] = (byte)(var1[var4] >> 16 & 255);
  230.          var3[6 + 4 * var4] = (byte)(var1[var4] >> 9 & 255);
  231.          var3[7 + 4 * var4] = (byte)(var1[var4] & 255);
  232.       }
  233.  
  234.       this.field_1.write(var3);
  235.    }
  236.  
  237.    void writeClientCutText(String var1) throws IOException {
  238.       byte[] var2 = new byte[8 + var1.length()];
  239.       var2[0] = 6;
  240.       var2[4] = (byte)(var1.length() >> 24 & 255);
  241.       var2[5] = (byte)(var1.length() >> 16 & 255);
  242.       var2[6] = (byte)(var1.length() >> 8 & 255);
  243.       var2[7] = (byte)(var1.length() & 255);
  244.       var1.getBytes(0, var1.length(), var2, 8);
  245.       this.field_1.write(var2);
  246.    }
  247.  
  248.    void writePointerEvent(Event var1) throws IOException {
  249.       if (var1.id == 501) {
  250.          this.pointerMask = 1;
  251.          if ((var1.modifiers & 8) != 0) {
  252.             if (this.field_2.options.reverseMouseButtons2And3) {
  253.                this.pointerMask = 4;
  254.             } else {
  255.                this.pointerMask = 2;
  256.             }
  257.          }
  258.  
  259.          if ((var1.modifiers & 4) != 0) {
  260.             if (this.field_2.options.reverseMouseButtons2And3) {
  261.                this.pointerMask = 2;
  262.             } else {
  263.                this.pointerMask = 4;
  264.             }
  265.          }
  266.       } else if (var1.id == 502) {
  267.          this.pointerMask = 0;
  268.       }
  269.  
  270.       var1.modifiers &= -13;
  271.       this.eventBufLen = 0;
  272.       this.writeModifierKeyEvents(var1.modifiers);
  273.       if (var1.x < 0) {
  274.          var1.x = 0;
  275.       }
  276.  
  277.       if (var1.y < 0) {
  278.          var1.y = 0;
  279.       }
  280.  
  281.       this.eventBuf[this.eventBufLen++] = 5;
  282.       this.eventBuf[this.eventBufLen++] = (byte)this.pointerMask;
  283.       this.eventBuf[this.eventBufLen++] = (byte)(var1.x >> 8 & 255);
  284.       this.eventBuf[this.eventBufLen++] = (byte)(var1.x & 255);
  285.       this.eventBuf[this.eventBufLen++] = (byte)(var1.y >> 8 & 255);
  286.       this.eventBuf[this.eventBufLen++] = (byte)(var1.y & 255);
  287.       if (this.pointerMask == 0) {
  288.          this.writeModifierKeyEvents(0);
  289.       }
  290.  
  291.       this.field_1.write(this.eventBuf, 0, this.eventBufLen);
  292.    }
  293.  
  294.    void writeKeyEvent(Event var1) throws IOException {
  295.       int var2 = var1.key;
  296.       boolean var3 = false;
  297.       if (var1.id == 401 || var1.id == 403) {
  298.          var3 = true;
  299.       }
  300.  
  301.       if (var1.id != 403 && var1.id != 404) {
  302.          if (var2 < 32) {
  303.             if ((var1.modifiers & 2) != 0) {
  304.                var2 += 96;
  305.             } else {
  306.                switch (var2) {
  307.                   case 8:
  308.                      var2 = 65288;
  309.                      break;
  310.                   case 9:
  311.                      var2 = 65289;
  312.                      break;
  313.                   case 10:
  314.                      var2 = 65293;
  315.                      break;
  316.                   case 27:
  317.                      var2 = 65307;
  318.                }
  319.             }
  320.          } else if (var2 >= 127) {
  321.             if (var2 == 127) {
  322.                var2 = 65535;
  323.             } else if (var2 < 65280 || var2 > 65535) {
  324.                return;
  325.             }
  326.          }
  327.       } else {
  328.          switch (var2) {
  329.             case 1000:
  330.                var2 = 65360;
  331.                break;
  332.             case 1001:
  333.                var2 = 65367;
  334.                break;
  335.             case 1002:
  336.                var2 = 65365;
  337.                break;
  338.             case 1003:
  339.                var2 = 65366;
  340.                break;
  341.             case 1004:
  342.                var2 = 65362;
  343.                break;
  344.             case 1005:
  345.                var2 = 65364;
  346.                break;
  347.             case 1006:
  348.                var2 = 65361;
  349.                break;
  350.             case 1007:
  351.                var2 = 65363;
  352.                break;
  353.             case 1008:
  354.                var2 = 65470;
  355.                break;
  356.             case 1009:
  357.                var2 = 65471;
  358.                break;
  359.             case 1010:
  360.                var2 = 65472;
  361.                break;
  362.             case 1011:
  363.                var2 = 65473;
  364.                break;
  365.             case 1012:
  366.                var2 = 65474;
  367.                break;
  368.             case 1013:
  369.                var2 = 65475;
  370.                break;
  371.             case 1014:
  372.                var2 = 65476;
  373.                break;
  374.             case 1015:
  375.                var2 = 65477;
  376.                break;
  377.             case 1016:
  378.                var2 = 65478;
  379.                break;
  380.             case 1017:
  381.                var2 = 65479;
  382.                break;
  383.             case 1018:
  384.                var2 = 65480;
  385.                break;
  386.             case 1019:
  387.                var2 = 65481;
  388.                break;
  389.             default:
  390.                return;
  391.          }
  392.       }
  393.  
  394.       this.eventBufLen = 0;
  395.       this.writeModifierKeyEvents(var1.modifiers);
  396.       this.writeKeyEvent(var2, var3);
  397.       if (!var3) {
  398.          this.writeModifierKeyEvents(0);
  399.       }
  400.  
  401.       this.field_1.write(this.eventBuf, 0, this.eventBufLen);
  402.    }
  403.  
  404.    void writeKeyEvent(int var1, boolean var2) throws IOException {
  405.       this.eventBuf[this.eventBufLen++] = 4;
  406.       this.eventBuf[this.eventBufLen++] = (byte)(var2 ? 1 : 0);
  407.       this.eventBuf[this.eventBufLen++] = 0;
  408.       this.eventBuf[this.eventBufLen++] = 0;
  409.       this.eventBuf[this.eventBufLen++] = (byte)(var1 >> 24 & 255);
  410.       this.eventBuf[this.eventBufLen++] = (byte)(var1 >> 16 & 255);
  411.       this.eventBuf[this.eventBufLen++] = (byte)(var1 >> 8 & 255);
  412.       this.eventBuf[this.eventBufLen++] = (byte)(var1 & 255);
  413.    }
  414.  
  415.    void writeModifierKeyEvents(int var1) throws IOException {
  416.       if ((var1 & 2) != (this.oldModifiers & 2)) {
  417.          this.writeKeyEvent(65507, (var1 & 2) != 0);
  418.       }
  419.  
  420.       if ((var1 & 1) != (this.oldModifiers & 1)) {
  421.          this.writeKeyEvent(65505, (var1 & 1) != 0);
  422.       }
  423.  
  424.       if ((var1 & 4) != (this.oldModifiers & 4)) {
  425.          this.writeKeyEvent(65511, (var1 & 4) != 0);
  426.       }
  427.  
  428.       if ((var1 & 8) != (this.oldModifiers & 8)) {
  429.          this.writeKeyEvent(65513, (var1 & 8) != 0);
  430.       }
  431.  
  432.       this.oldModifiers = var1;
  433.    }
  434. }
  435.