public static void main(final String[] args) { File logdir = new File(LOG_DIR); if (!logdir.exists()) logdir.mkdirs(); File log = new File(logdir, "client.log"); // redirect all console output to the file try { PrintStream out = new PrintStream(new FileOutputStream(log, true), true); out.format("[%s] ===== Client started =====%n", timestampf.format(new Date())); System.setOut(out); System.setErr(out); } catch (FileNotFoundException e) { e.printStackTrace(); } /* Set up the error handler as early as humanly possible. */ ThreadGroup g = new ThreadGroup("Haven main group"); String ed; if (!(ed = Utils.getprop("haven.errorurl", "")).equals("")) { try { final haven.error.ErrorHandler hg = new haven.error.ErrorHandler(new java.net.URL(ed)); hg.sethandler( new haven.error.ErrorGui(null) { public void errorsent() { hg.interrupt(); } }); g = hg; } catch (java.net.MalformedURLException e) { } } Thread main = new HackThread( g, new Runnable() { public void run() { main2(args); } }, "Haven main thread"); main.start(); }
private void initgl() { final Thread caller = Thread.currentThread(); final haven.error.ErrorHandler h = haven.error.ErrorHandler.find(); addGLEventListener( new GLEventListener() { Debug.DumpGL dump = null; public void display(GLAutoDrawable d) { GL2 gl = d.getGL().getGL2(); /* if((dump == null) || (dump.getDownstreamGL() != gl)) dump = new Debug.DumpGL((GL4bc)gl); if(Debug.kf2 && !Debug.pk2) dump.dump("/tmp/gldump"); dump.reset(); gl = dump; */ if (inited) redraw(gl); } public void init(GLAutoDrawable d) { GL gl = d.getGL(); glconf = GLConfig.fromgl(gl, d.getContext(), getChosenGLCapabilities()); glconf.pref = GLSettings.load(glconf, true); ui.cons.add(glconf); if (h != null) { h.lsetprop("gl.vendor", gl.glGetString(gl.GL_VENDOR)); h.lsetprop("gl.version", gl.glGetString(gl.GL_VERSION)); h.lsetprop("gl.renderer", gl.glGetString(gl.GL_RENDERER)); h.lsetprop("gl.exts", Arrays.asList(gl.glGetString(gl.GL_EXTENSIONS).split(" "))); h.lsetprop("gl.caps", d.getChosenGLCapabilities().toString()); h.lsetprop("gl.conf", glconf); } gstate = new GLState() { public void apply(GOut g) { BGL gl = g.gl; gl.glColor3f(1, 1, 1); gl.glPointSize(4); gl.joglSetSwapInterval(1); gl.glEnable(GL.GL_BLEND); // gl.glEnable(GL.GL_LINE_SMOOTH); gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA); if (g.gc.glmajver >= 2) gl.glBlendEquationSeparate(GL.GL_FUNC_ADD, GL2.GL_MAX); if (g.gc.havefsaa()) { /* Apparently, having sample * buffers in the config enables * multisampling by default on * some systems. */ g.gl.glDisable(GL.GL_MULTISAMPLE); } GOut.checkerr(gl); } public void unapply(GOut g) {} public void prep(Buffer buf) { buf.put(global, this); } }; } public void reshape( GLAutoDrawable d, final int x, final int y, final int w, final int h) { ostate = OrthoState.fixed(new Coord(w, h)); rtstate = new GLState() { public void apply(GOut g) { g.st.proj = Projection.makeortho(new Matrix4f(), 0, w, 0, h, -1, 1); } public void unapply(GOut g) {} public void prep(Buffer buf) { buf.put(proj2d, this); } }; HavenPanel.this.w = w; HavenPanel.this.h = h; } public void displayChanged(GLAutoDrawable d, boolean cp1, boolean cp2) {} public void dispose(GLAutoDrawable d) {} }); }
private void initgl() { final haven.error.ErrorHandler h = haven.error.ErrorHandler.find(); addGLEventListener( new GLEventListener() { public void takescreenshot(int width, int height) { try { String curtimestamp = new SimpleDateFormat("yyyy-MM-dd_HH.mm.ss.SSS").format(new Date()); File outputfile = new File(String.format("screenshots/%s.png", curtimestamp)); outputfile.getParentFile().mkdirs(); Screenshot.writeToFile(outputfile, width, height); ui.root .findchild(GameUI.class) .msg( String.format("Screenshot has been saved as \"%s\"", outputfile.getName()), Color.WHITE); } catch (Exception ex) { System.out.println("Unable to take screenshot: " + ex.getMessage()); } } public void display(GLAutoDrawable d) { if (HavenPanel.needtotakescreenshot) { takescreenshot(d.getWidth(), d.getHeight()); HavenPanel.needtotakescreenshot = false; } GL2 gl = d.getGL().getGL2(); /* if((dump == null) || (dump.getDownstreamGL() != gl)) dump = new Debug.DumpGL((GL4bc)gl); if(Debug.kf2 && !Debug.pk2) dump.dump("/tmp/gldump"); dump.reset(); gl = dump; */ if (inited) redraw(gl); } public void init(GLAutoDrawable d) { try { GL gl = d.getGL(); glconf = GLConfig.fromgl(gl, d.getContext(), getChosenGLCapabilities()); glconf.pref = GLSettings.load(glconf, true); ui.cons.add(glconf); if (h != null) { String vendor = gl.glGetString(gl.GL_VENDOR); isATI = vendor.contains("AMD") || vendor.contains("ATI"); h.lsetprop("gl.vendor", vendor); h.lsetprop("gl.version", gl.glGetString(gl.GL_VERSION)); h.lsetprop("gl.renderer", gl.glGetString(gl.GL_RENDERER)); h.lsetprop("gl.exts", Arrays.asList(gl.glGetString(gl.GL_EXTENSIONS).split(" "))); h.lsetprop("gl.caps", d.getChosenGLCapabilities().toString()); h.lsetprop("gl.conf", glconf); } gstate = new GLState() { public void apply(GOut g) { BGL gl = g.gl; gl.glColor3f(1, 1, 1); gl.glPointSize(4); gl.joglSetSwapInterval(1); gl.glEnable(GL.GL_BLEND); // gl.glEnable(GL.GL_LINE_SMOOTH); gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA); if (g.gc.glmajver >= 2) gl.glBlendEquationSeparate(GL.GL_FUNC_ADD, GL2.GL_MAX); if (g.gc.havefsaa()) { /* Apparently, having sample * buffers in the config enables * multisampling by default on * some systems. */ g.gl.glDisable(GL.GL_MULTISAMPLE); } GOut.checkerr(gl); } public void unapply(GOut g) {} public void prep(Buffer buf) { buf.put(global, this); } }; } catch (RuntimeException e) { uncaught = e; throw (e); } } public void reshape( GLAutoDrawable d, final int x, final int y, final int w, final int h) { ostate = OrthoState.fixed(new Coord(w, h)); new GLState() { public void apply(GOut g) { g.st.proj = Projection.makeortho(new Matrix4f(), 0, w, 0, h, -1, 1); } public void unapply(GOut g) {} public void prep(Buffer buf) { buf.put(proj2d, this); } }; HavenPanel.w = w; HavenPanel.h = h; } public void dispose(GLAutoDrawable d) {} }); }
public Session run(HavenPanel hp) throws InterruptedException { ui = hp.newui(null); ui.setreceiver(this); ui.bind(new LoginScreen(ui.root), 1); String username; boolean savepw = false; Utils.setpref("password", ""); byte[] token = null; if (Utils.getpref("savedtoken", "").length() == 64) token = Utils.hex2byte(Utils.getpref("savedtoken", null)); username = Utils.getpref("username", ""); String authserver = (Config.authserv == null) ? address : Config.authserv; retry: do { byte[] cookie; if (initcookie != null) { username = inituser; cookie = initcookie; initcookie = null; } else if (token != null) { savepw = true; ui.uimsg(1, "token", username); while (true) { Message msg; synchronized (msgs) { while ((msg = msgs.poll()) == null) msgs.wait(); } if (msg.id == 1) { if (msg.name == "login") { break; } else if (msg.name == "forget") { token = null; Utils.setpref("savedtoken", ""); continue retry; } } } ui.uimsg(1, "prg", "Authenticating..."); AuthClient auth = null; try { auth = new AuthClient(authserver, username); if (!auth.trytoken(token)) { auth.close(); token = null; Utils.setpref("savedtoken", ""); ui.uimsg(1, "error", "Invalid save"); continue retry; } cookie = auth.cookie; } catch (java.io.IOException e) { ui.uimsg(1, "error", e.getMessage()); continue retry; } finally { try { if (auth != null) auth.close(); } catch (java.io.IOException e) { } } } else { String password; ui.uimsg(1, "passwd", username, savepw); while (true) { Message msg; synchronized (msgs) { while ((msg = msgs.poll()) == null) msgs.wait(); } if (msg.id == 1) { if (msg.name == "login") { username = (String) msg.args[0]; password = (String) msg.args[1]; savepw = (Boolean) msg.args[2]; break; } } } ui.uimsg(1, "prg", "Authenticating..."); AuthClient auth = null; try { try { auth = new AuthClient(authserver, username); } catch (UnknownHostException e) { ui.uimsg(1, "error", "Could not locate server"); continue retry; } if (!auth.trypasswd(password)) { auth.close(); password = ""; ui.uimsg(1, "error", "Username or password incorrect"); continue retry; } cookie = auth.cookie; if (savepw) { if (auth.gettoken()) Utils.setpref("savedtoken", Utils.byte2hex(auth.token)); } } catch (java.io.IOException e) { ui.uimsg(1, "error", e.getMessage()); continue retry; } finally { try { if (auth != null) auth.close(); } catch (java.io.IOException e) { } } } ui.uimsg(1, "prg", "Connecting..."); try { sess = new Session(InetAddress.getByName(address), username, cookie); } catch (UnknownHostException e) { ui.uimsg(1, "error", "Could not locate server"); continue retry; } Thread.sleep(100); while (true) { if (sess.state == "") { Utils.setpref("username", username); ui.destroy(1); break retry; } else if (sess.connfailed != 0) { String error; switch (sess.connfailed) { case 1: error = "Invalid authentication token"; break; case 2: error = "Already logged in"; break; case 3: error = "Could not connect to server"; break; case 4: error = "This client is too old"; break; case 5: error = "Authentication token expired"; break; default: error = "Connection failed"; break; } ui.uimsg(1, "error", error); sess = null; continue retry; } synchronized (sess) { sess.wait(); } } } while (true); haven.error.ErrorHandler.setprop("usr", sess.username); return (sess); // (new RemoteUI(sess, ui)).start(); }