Beispiel #1
0
 public void run() {
   try {
     InputStream in;
     OutputStream out;
     try {
       in = sk.getInputStream();
       out = sk.getOutputStream();
     } catch (IOException e) {
       throw (new RuntimeException(e));
     }
     while (true) {
       try {
         int len = Utils.int32d(read(in, 4), 0);
         if (!auth && (len > 256)) return;
         Message msg = new MessageBuf(read(in, len));
         String cmd = msg.string();
         Object[] args = msg.list();
         Object[] reply;
         if (auth) {
           Command cc = commands.get(cmd);
           if (cc != null) reply = cc.run(this, args);
           else reply = new Object[] {"nocmd"};
         } else {
           if (cmd.equals("nonce")) {
             reply = new Object[] {nonce};
           } else if (cmd.equals("auth")) {
             if (Arrays.equals((byte[]) args[0], ckey)) {
               reply = new Object[] {"ok"};
               auth = true;
             } else {
               reply = new Object[] {"no"};
             }
           } else {
             return;
           }
         }
         MessageBuf rb = new MessageBuf();
         rb.addlist(reply);
         byte[] rbuf = new byte[4 + rb.size()];
         Utils.uint32e(rb.size(), rbuf, 0);
         rb.fin(rbuf, 4);
         out.write(rbuf);
       } catch (IOException e) {
         return;
       }
     }
   } catch (InterruptedException e) {
   } finally {
     try {
       sk.close();
     } catch (IOException e) {
       throw (new RuntimeException(e));
     }
   }
 }
Beispiel #2
0
 public Res cons(Resource res, Message buf) {
   int id = buf.uint16();
   Res ret = new Res(res, id);
   while (!buf.eom()) {
     String nm = buf.string();
     Object[] args = buf.list();
     if (nm.equals("linear")) {
       /* XXX: These should very much be removed and
        * specified directly in the texture layer
        * instead. */
       ret.linear = true;
     } else if (nm.equals("mipmap")) {
       ret.mipmap = true;
     } else {
       ResCons2 cons = rnames.get(nm);
       if (cons == null)
         throw (new Resource.LoadException("Unknown material part name: " + nm, res));
       ret.left.add(cons.cons(res, args));
     }
   }
   return (ret);
 }