Пример #1
0
 public void tilemap(Message msg) {
   while (!msg.eom()) {
     int id = msg.uint8();
     String resnm = msg.string();
     int resver = msg.uint16();
     nsets[id] = new Resource.Spec(resnm, resver);
   }
 }
Пример #2
0
 private ByTile(Resource res, Message buf, Map<Integer, Factory> refs) {
   tag = new String[buf.uint8()];
   sub = new Factory[tag.length];
   for (int i = 0; i < tag.length; i++) {
     tag[i] = buf.string();
     sub[i] = refs.get(buf.int16());
   }
   def = refs.get(buf.int16());
 }
Пример #3
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));
     }
   }
 }
 public String tryauth(AuthClient cl) throws IOException {
   if (WebBrowser.self == null) {
     throw (new AuthException("Could not find any web browser to launch"));
   }
   Message rpl = cl.cmd("web", method());
   String stat = rpl.string();
   URL url;
   if (stat.equals("ok")) {
     url = new URL(rpl.string());
   } else if (stat.equals("no")) {
     throw (new AuthException(rpl.string()));
   } else {
     throw (new RuntimeException("Unexpected reply `" + stat + "' from auth server"));
   }
   try {
     WebBrowser.self.show(url);
   } catch (WebBrowser.BrowserException e) {
     throw (new AuthException("Could not launch web browser"));
   }
   rpl = cl.cmd("wait");
   stat = rpl.string();
   if (stat.equals("ok")) {
     return (rpl.string());
   } else if (stat.equals("no")) {
     throw (new AuthException(rpl.string()));
   } else {
     throw (new RuntimeException("Unexpected reply `" + stat + "' from auth server"));
   }
 }
Пример #5
0
 public void fill(Message msg) {
   String mmname = msg.string().intern();
   if (mmname.equals("")) mnm = null;
   else mnm = mmname;
   int[] pfl = new int[256];
   while (true) {
     int pidx = msg.uint8();
     if (pidx == 255) break;
     pfl[pidx] = msg.uint8();
   }
   Message blob = msg.inflate();
   id = blob.int64();
   for (int i = 0; i < tiles.length; i++) tiles[i] = blob.uint8();
   for (int i = 0; i < z.length; i++) z[i] = blob.int16();
   for (int i = 0; i < ol.length; i++) ol[i] = 0;
   while (true) {
     int pidx = blob.uint8();
     if (pidx == 255) break;
     int fl = pfl[pidx];
     int type = blob.uint8();
     Coord c1 = new Coord(blob.uint8(), blob.uint8());
     Coord c2 = new Coord(blob.uint8(), blob.uint8());
     int ol;
     if (type == 0) {
       if ((fl & 1) == 1) ol = 2;
       else ol = 1;
     } else if (type == 1) {
       if ((fl & 1) == 1) ol = 8;
       else ol = 4;
     } else {
       throw (new RuntimeException("Unknown plot type " + type));
     }
     for (int y = c1.y; y <= c2.y; y++) {
       for (int x = c1.x; x <= c2.x; x++) {
         this.ol[x + (y * cmaps.x)] |= ol;
       }
     }
   }
   invalidate();
 }
Пример #6
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);
 }
Пример #7
0
 public Res cons(final Resource res, Message buf) {
   int id = buf.uint16();
   Res ret = new Res(res, id);
   GLState light = Light.deflight;
   while (!buf.eom()) {
     String thing = buf.string().intern();
     if (thing == "col") {
       Color amb = col(buf);
       Color dif = col(buf);
       Color spc = col(buf);
       double shine = buf.cpfloat();
       Color emi = col(buf);
       ret.states.add(new Colors(amb, dif, spc, emi, (float) shine));
     } else if (thing == "linear") {
       ret.linear = true;
     } else if (thing == "mipmap") {
       ret.mipmap = true;
     } else if (thing == "nofacecull") {
       ret.states.add(nofacecull);
     } else if (thing == "tex") {
       final int tid = buf.uint16();
       ret.left.add(
           new Res.Resolver() {
             public void resolve(Collection<GLState> buf) {
               for (Resource.Image img : res.layers(Resource.imgc)) {
                 if (img.id == tid) {
                   buf.add(img.tex().draw());
                   buf.add(img.tex().clip());
                   return;
                 }
               }
               throw (new RuntimeException(
                   String.format("Specified texture %d not found in %s", tid, res)));
             }
           });
     } else if (thing == "texlink") {
       final String nm = buf.string();
       final int ver = buf.uint16();
       final int tid = buf.uint16();
       ret.left.add(
           new Res.Resolver() {
             public void resolve(Collection<GLState> buf) {
               Indir<Resource> tres = res.pool.load(nm, ver);
               for (Resource.Image img : tres.get().layers(Resource.imgc)) {
                 if (img.id == tid) {
                   buf.add(img.tex().draw());
                   buf.add(img.tex().clip());
                   return;
                 }
               }
               throw (new RuntimeException(
                   String.format(
                       "Specified texture %d for %s not found in %s", tid, res, tres)));
             }
           });
     } else if (thing == "light") {
       String l = buf.string();
       if (l.equals("pv")) {
         light = Light.vlights;
       } else if (l.equals("pp")) {
         light = Light.plights;
       } else if (l.equals("n")) {
         light = null;
       } else {
         throw (new Resource.LoadException("Unknown lighting type: " + thing, res));
       }
     } else {
       throw (new Resource.LoadException("Unknown material part: " + thing, res));
     }
   }
   if (light != null) ret.states.add(light);
   return (ret);
 }
Пример #8
0
 private ByRes(Resource res, Message buf, Map<Integer, Factory> refs) {
   String resnm = buf.string();
   int resver = buf.uint16();
   this.res = res.pool.load(resnm, resver);
 }