Emberveil source

tests/ClientSmoke.java

import java.net.InetAddress;
import java.nio.file.*;

/** Local end-to-end test, deliberately outside the shipped client entry point. */
public class ClientSmoke extends Game {
    static String testName;
    static boolean exitWhenDone;
    private int ticks;
    private boolean attempted;
    private boolean opened;
    @Override public void processGameLoop() {
        if (!attempted) {
            attempted=true;
            myUsername=testName; myPassword="local-smoke-only";
            loginScreenState=2;
            login(myUsername,myPassword,false);
            if (!loggedIn) {
                System.err.println("SMOKE LOGIN FAILED: " + loginMessage1 + " " + loginMessage2);
                System.exit(1);
            }
            System.out.println("SMOKE: successful encrypted client login.");
        }
        super.processGameLoop();
        if (loggedIn && loadingStage==2 && !opened && ++ticks>100) {
            opened=true;
            stream.createFrame(103); stream.writeWordBigEndian(8); stream.writeString("journal");
            System.out.println("SMOKE: world loaded; journal command sent.");
        }
        if (opened && ++ticks>200) {
            if (openInterfaceID != 8134) throw new AssertionError("Journal interface did not open: " + openInterfaceID);
            System.out.println("SMOKE PASS: world rendered and custom journal received.");
            if (exitWhenDone) System.exit(0);
            stream.createFrame(103); stream.writeWordBigEndian(6); stream.writeString("watch");
            // Keep the window available for visual inspection; closing the client logs out.
            ticks=-1000000;
        }
    }
    public static void main(String[] args) throws Exception {
        testName=args.length>0 ? args[0] : "ev"+Long.toString(System.nanoTime()%100000000L);
        exitWhenDone=args.length>2 && args[2].equals("exit");
        if (!testName.matches("ev[0-9]{1,8}")) throw new IllegalArgumentException("Only generated QA characters may be used");
        Path save=Paths.get("game/2006Scape Server/data/characters/"+testName+".txt");
        if (Files.exists(save) && !(args.length>1 && args[1].equals("reconnect"))) throw new IllegalStateException("Refusing to reuse existing smoke character");
        ClientSettings.SERVER_IP="127.0.0.1"; ClientSettings.CHECK_CRC=false;
        ClientSettings.SHOW_NAVBAR=false; ClientSettings.HIDE_ROOFS=true;
        ClientSettings.CUSTOM_SETTINGS_TAB=true;
        Game.nodeID=10; Game.portOff=0; Game.setHighMem(); Game.isMembers=true;
        Signlink.storeid=32; Signlink.startpriv(InetAddress.getLocalHost());
        new ClientSmoke().createClientFrame(503,765);
        new Thread(() -> { try { Thread.sleep(300000); } catch(Exception ignored) {} System.exit(0); }).start();
    }
}