Search in sources :

Example 1 with UpstreamSession

use of org.dragonet.proxy.network.UpstreamSession in project DragonProxy by DragonetMC.

the class TimingsExport method reportTimings.

/**
 * Builds a JSON timings report and sends it to Aikar's viewer
 *
 * @param sender Sender that issued the command
 */
public static void reportTimings(UpstreamSession sender) {
    JsonObject out = new JsonObject();
    out.addProperty("version", DragonProxy.getInstance().getVersion());
    // TODO
    out.addProperty("maxplayers", 2);
    out.addProperty("start", TimingsManager.timingStart / 1000);
    out.addProperty("end", System.currentTimeMillis() / 1000);
    out.addProperty("sampletime", (System.currentTimeMillis() - TimingsManager.timingStart) / 1000);
    if (!Timings.isPrivacy()) {
        // TODO
        out.addProperty("server", "DragonProxy : name");
        out.addProperty("motd", DragonProxy.getInstance().getMotd());
        out.addProperty("online-mode", DragonProxy.getInstance().getAuthMode().equals("online"));
        // "data:image/png;base64,"
        out.addProperty("icon", "");
    }
    final Runtime runtime = Runtime.getRuntime();
    RuntimeMXBean runtimeBean = ManagementFactory.getRuntimeMXBean();
    JsonObject system = new JsonObject();
    system.addProperty("timingcost", getCost());
    system.addProperty("name", System.getProperty("os.name"));
    system.addProperty("version", System.getProperty("os.version"));
    system.addProperty("jvmversion", System.getProperty("java.version"));
    system.addProperty("arch", System.getProperty("os.arch"));
    system.addProperty("maxmem", runtime.maxMemory());
    system.addProperty("cpu", runtime.availableProcessors());
    system.addProperty("runtime", ManagementFactory.getRuntimeMXBean().getUptime());
    system.addProperty("flags", String.join(" ", runtimeBean.getInputArguments()));
    system.add("gc", JsonUtil.mapToObject(ManagementFactory.getGarbageCollectorMXBeans(), (input) -> new JsonUtil.JSONPair(input.getName(), JsonUtil.toArray(input.getCollectionCount(), input.getCollectionTime()))));
    out.add("system", system);
    TimingsHistory[] history = HISTORY.toArray(new TimingsHistory[HISTORY.size() + 1]);
    // Current snapshot
    history[HISTORY.size()] = new TimingsHistory();
    JsonObject timings = new JsonObject();
    for (TimingIdentifier.TimingGroup group : TimingIdentifier.GROUP_MAP.values()) {
        for (Timing id : group.timings.stream().toArray(Timing[]::new)) {
            if (!id.timed && !id.isSpecial())
                continue;
            timings.add(String.valueOf(id.id), JsonUtil.toArray(group.id, id.name));
        }
    }
    JsonObject idmap = new JsonObject();
    idmap.add("groups", JsonUtil.mapToObject(TimingIdentifier.GROUP_MAP.values(), (group) -> new JsonUtil.JSONPair(group.id, group.name)));
    idmap.add("handlers", timings);
    idmap.add("worlds", JsonUtil.mapToObject(TimingsHistory.levelMap.entrySet(), (entry) -> new JsonUtil.JSONPair(entry.getValue(), entry.getKey())));
    idmap.add("tileentity", JsonUtil.mapToObject(TimingsHistory.blockEntityMap.entrySet(), (entry) -> new JsonUtil.JSONPair(entry.getKey(), entry.getValue())));
    idmap.add("entity", JsonUtil.mapToObject(TimingsHistory.entityMap.entrySet(), (entry) -> new JsonUtil.JSONPair(entry.getKey(), entry.getValue())));
    out.add("idmap", idmap);
    // Information about plugins, needed but empty
    out.add("plugins", new JsonArray());
    // Information on the proxy Config
    JsonObject config = new JsonObject();
    if (!Timings.getIgnoredConfigSections().contains("all")) {
        JsonObject jsonConfig = JsonUtil.toObject(DragonProxy.getInstance().getConfig());
        Timings.getIgnoredConfigSections().forEach(jsonConfig::remove);
        config.add("DragonProxy", jsonConfig);
    } else {
        config.add("DragonProxy", null);
    }
    out.add("config", config);
    new TimingsExport(sender, out, history).start();
}
Also used : HttpURLConnection(java.net.HttpURLConnection) JsonObject(com.google.gson.JsonObject) RuntimeMXBean(java.lang.management.RuntimeMXBean) URL(java.net.URL) Date(java.util.Date) HISTORY(co.aikar.timings.TimingsManager.HISTORY) SimpleDateFormat(java.text.SimpleDateFormat) UpstreamSession(org.dragonet.proxy.network.UpstreamSession) GsonBuilder(com.google.gson.GsonBuilder) InetAddress(java.net.InetAddress) JsonArray(com.google.gson.JsonArray) java.io(java.io) Gson(com.google.gson.Gson) JsonUtil(org.dragonet.common.utilities.JsonUtil) GZIPOutputStream(java.util.zip.GZIPOutputStream) DragonProxy(org.dragonet.proxy.DragonProxy) ManagementFactory(java.lang.management.ManagementFactory) JsonObject(com.google.gson.JsonObject) RuntimeMXBean(java.lang.management.RuntimeMXBean) JsonArray(com.google.gson.JsonArray)

Example 2 with UpstreamSession

use of org.dragonet.proxy.network.UpstreamSession in project DragonProxy by DragonetMC.

the class CacheCommand method execute.

public void execute(DragonProxy proxy, String[] args) {
    if (args.length == 0) {
        if (proxy.getSessionRegister().getAll().isEmpty()) {
            proxy.getLogger().info("No session, no cache");
            return;
        }
        proxy.getLogger().info("Display cache info per session");
        for (UpstreamSession session : proxy.getSessionRegister().getAll().values()) {
            proxy.getLogger().info("Session: " + session.getRaknetID() + " (" + session.getUsername() + ")");
            proxy.getLogger().info("\tentities :" + session.getEntityCache().getEntities().size());
            proxy.getLogger().info("\tchunks :" + session.getChunkCache().getChunks().size());
        }
    }
}
Also used : UpstreamSession(org.dragonet.proxy.network.UpstreamSession)

Example 3 with UpstreamSession

use of org.dragonet.proxy.network.UpstreamSession in project DragonProxy by DragonetMC.

the class TestCommand method execute.

public void execute(DragonProxy proxy, String[] args) {
    if (args.length == 0) {
        System.out.println("This is a developer's command! ");
        return;
    }
    UpstreamSession player = proxy.getSessionRegister().getAll().values().toArray(new UpstreamSession[1])[0];
    if (args[0].equalsIgnoreCase("status")) {
        PlayStatusPacket s = new PlayStatusPacket();
        s.status = PlayStatusPacket.PLAYER_SPAWN;
        player.sendPacket(s);
    } else if (args[0].equalsIgnoreCase("res")) {
        player.sendPacket(new ResourcePacksInfoPacket());
    } else if (args[0].equalsIgnoreCase("pos")) {
        player.sendChat("pos at: " + player.getEntityCache().getClientEntity().x + ", " + player.getEntityCache().getClientEntity().y + ", " + player.getEntityCache().getClientEntity().z);
    } else if (args[0].equalsIgnoreCase("respawn")) {
        RespawnPacket resp = new RespawnPacket();
        resp.position = new Vector3F(Float.parseFloat(args[1]), Float.parseFloat(args[2]), Float.parseFloat(args[3]));
        player.sendPacket(resp);
    } else if (args[0].equalsIgnoreCase("chunkradius")) {
        player.sendPacket(new ChunkRadiusUpdatedPacket(8));
    } else if (args[0].equalsIgnoreCase("setspawnpos")) {
        SetSpawnPositionPacket packetSetSpawnPosition = new SetSpawnPositionPacket();
        packetSetSpawnPosition.position = new BlockPosition(Integer.parseInt(args[1]), Integer.parseInt(args[2]), Integer.parseInt(args[3]));
        player.sendPacket(packetSetSpawnPosition);
    } else if (args[0].equalsIgnoreCase("motion")) {
        SetEntityMotionPacket mot = new SetEntityMotionPacket();
        mot.rtid = 1L;
        mot.motion = new Vector3F(0f, 0f, 0f);
        player.sendPacket(mot);
    } else if (args[0].equalsIgnoreCase("die")) {
        player.sendPacket(new SetHealthPacket(0));
    } else if (args[0].equalsIgnoreCase("tp")) {
        Vector3F dest = new Vector3F(Float.parseFloat(args[1]), Float.parseFloat(args[2]), Float.parseFloat(args[3]));
        MovePlayerPacket m = new MovePlayerPacket();
        m.rtid = 1L;
        m.mode = (byte) (Integer.parseInt(args[4]) & 0xFF);
        m.position = dest;
        player.sendPacket(m);
        player.sendChat("\u00a7bTeleported to: " + dest.toString());
    } else if (args[0].equalsIgnoreCase("moveentity")) {
        Vector3F dest = new Vector3F(Float.parseFloat(args[1]), Float.parseFloat(args[2]), Float.parseFloat(args[3]));
        MoveEntityPacket m = new MoveEntityPacket();
        m.rtid = 1L;
        m.teleported = args[4].equalsIgnoreCase("true");
        m.position = dest;
        player.sendPacket(m);
        player.sendChat("\u00a7bTeleported to: " + dest.toString());
    } else if (args[0].equalsIgnoreCase("chunk")) {
        /*
             * FullChunkData chunk = new FullChunkData(Integer.parseInt(args[1]),
			 * Integer.parseInt(args[2])); Arrays.fill(chunk.ids, (byte)1);
             */
        ChunkData data = new ChunkData();
        data.sections = new Section[16];
        for (int cy = 0; cy < 16; cy++) {
            data.sections[cy] = new Section();
            Arrays.fill(data.sections[cy].blockIds, (byte) 1);
        }
        FullChunkDataPacket chunk = new FullChunkDataPacket();
        chunk.x = Integer.parseInt(args[1]);
        chunk.z = Integer.parseInt(args[2]);
        data.encode();
        chunk.payload = data.getBuffer();
        player.sendPacket(chunk);
    } else if (args[0].equalsIgnoreCase("form")) {
        testForm(player);
    } else if (args[0].equalsIgnoreCase("sound")) {
        int id = Integer.parseInt(args[1]);
        LevelSoundEventPacket pk = new LevelSoundEventPacket();
        CachedEntity self = player.getEntityCache().getClientEntity();
        pk.position = new Vector3F((float) self.x, (float) self.y, (float) self.z);
        pk.sound = LevelSoundEventPacket.Sound.fromID(id);
        player.sendPacket(pk);
        player.sendChat("\u00a7bSound ID " + pk.sound.soundID + " (" + pk.sound.name() + ") sent");
    } else if (args[0].equalsIgnoreCase("painting")) {
        AddPaintingPacket pk = new AddPaintingPacket();
        pk.rtid = player.getEntityCache().getNextAtomicLong().incrementAndGet();
        pk.eid = pk.rtid;
        pk.pos = new BlockPosition(Integer.parseInt(args[1]), Integer.parseInt(args[2]), Integer.parseInt(args[3]));
        pk.direction = Integer.parseInt(args[4]);
        pk.title = args[5];
        player.sendPacket(pk);
        player.sendChat("\u00a7bPainting " + pk.title + " spawned at " + pk.pos.toString());
    }
}
Also used : ChunkData(org.dragonet.protocol.type.chunk.ChunkData) BlockPosition(org.dragonet.common.maths.BlockPosition) CachedEntity(org.dragonet.proxy.network.cache.CachedEntity) Section(org.dragonet.protocol.type.chunk.Section) Vector3F(org.dragonet.common.maths.Vector3F) UpstreamSession(org.dragonet.proxy.network.UpstreamSession)

Aggregations

UpstreamSession (org.dragonet.proxy.network.UpstreamSession)3 HISTORY (co.aikar.timings.TimingsManager.HISTORY)1 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 JsonArray (com.google.gson.JsonArray)1 JsonObject (com.google.gson.JsonObject)1 java.io (java.io)1 ManagementFactory (java.lang.management.ManagementFactory)1 RuntimeMXBean (java.lang.management.RuntimeMXBean)1 HttpURLConnection (java.net.HttpURLConnection)1 InetAddress (java.net.InetAddress)1 URL (java.net.URL)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 GZIPOutputStream (java.util.zip.GZIPOutputStream)1 BlockPosition (org.dragonet.common.maths.BlockPosition)1 Vector3F (org.dragonet.common.maths.Vector3F)1 JsonUtil (org.dragonet.common.utilities.JsonUtil)1 ChunkData (org.dragonet.protocol.type.chunk.ChunkData)1 Section (org.dragonet.protocol.type.chunk.Section)1