Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main;
- import DataTypes.*;
- public final class Format {
- public static boolean showDecompressinginfo;
- public static boolean showServerdetails;
- public static boolean showPlayers;
- public static boolean showChat;
- public static boolean showKills;
- public static boolean showRevives;
- public static boolean onlyDecompress;
- public static boolean verbose;
- public static boolean cleanverbose;
- public static String automatic(Message message) {
- if (cleanverbose) verbose = true;
- switch (message.getType().getType()){
- case 0x00:
- if(showServerdetails) return serverdetails(message) + "\n";
- if (verbose) return message.toStringNoData() + "\n" + serverdetails(message) + "\n";
- return "";
- case 0x50:
- if (showKills) return kill(message) + "\n";
- if (verbose) return message.toStringNoData() + "\n" + kill(message) + "\n";
- return "";
- case (byte) 0xA0:
- if (showRevives) return revive(message) + "\n";
- if (verbose) return message.toStringNoData() + "\n" + revive(message) + "\n";
- return "";
- case 0x51:
- if(showChat) return chat(message) + "\n";
- if (verbose) return message.toStringNoData() + "\n" + chat(message) + "\n";
- return "";
- case 0x11:
- if (showPlayers)return player_add(message);
- if (verbose) return message.toStringNoData() + "\n" + player_add(message) + "\n";
- player_add(message); //needs to happen to properly add a player to the playerlist
- return "";
- case 0x12:
- if (showPlayers) return player_remove(message) + "\n";
- if (verbose) return message.toStringNoData() + "\n" + player_remove(message) + "\n";
- player_remove(message); //needs to happen to properly remove a player from the playerlist
- return "";
- case 0x10: //tick
- if (cleanverbose) return "";
- //$FALL-THROUGH$
- case (byte) 0xF1: //playerupdate
- if (cleanverbose) return "";
- //$FALL-THROUGH$
- case 0x20: //vehicleupdate
- if (cleanverbose) return "";
- //$FALL-THROUGH$
- case (byte) 0x90: //PROJECTILE_UPDATE
- if (cleanverbose) return "";
- //$FALL-THROUGH$
- case (byte) 0x91: //PROJECTILE_ADD
- if (cleanverbose) return "";
- //$FALL-THROUGH$
- case (byte) 0x92: //PROJECTILE_REMOVE
- if (cleanverbose) return "";
- //$FALL-THROUGH$
- default:
- if(verbose)return message.toString() + "\n";
- return "";
- }
- }
- //MESSAGETYPE_SERVERDETAILS 0x00
- public static String serverdetails (Message message) {
- byte[] data = message.getData();
- String output = "";
- int i;
- output += ("Version: " + DemoUtils.ByteToInt(data, 0));
- output += (" TimePerTick: " + DemoUtils.ByteToFloat(data, 4));
- output += (" IP: " + new String(DemoUtils.getBytesBeforeZeroByte(data, 8)));
- i = DemoUtils.findZeroByte(data, 8) + 1;
- output += (" Servername: " + new String (DemoUtils.getBytesBeforeZeroByte(data, i)));
- i = DemoUtils.findZeroByte(data, i) + 1;
- output += (" MaxPlayers: " + data[i]);
- i++;
- output += (" Roundlength: " + (DemoUtils.ByteToShort(data[i], data[i+1])/60) + "min");
- i +=2;
- output += (" Briefingtime: " + (DemoUtils.ByteToShort(data[i], data[i+1])/60) + "min");
- i +=2;
- output += (" Mapname: " + new String(DemoUtils.getBytesBeforeZeroByte(data, i)));
- i = DemoUtils.findZeroByte(data, i) + 1;
- output += (" Gamemmode: " + new String(DemoUtils.getBytesBeforeZeroByte(data, i)));
- i = DemoUtils.findZeroByte(data, i) + 1;
- output += (" Maplayer: ");
- switch (data[i] & 0xFF) {
- case 16: output += "inf"; break;
- case 32: output += "alt"; break;
- case 64: output += "std"; break;
- case 128: output += "lrg"; break;
- default: output += "ERROR: UNRECOGNIZED GAMEMODE ID";
- }
- i++;
- output += (" Opfor: " + new String(DemoUtils.getBytesBeforeZeroByte(data, i)));
- i = DemoUtils.findZeroByte(data, i) + 1;
- output += (" Blufor: " + new String(DemoUtils.getBytesBeforeZeroByte(data, i)));
- i = DemoUtils.findZeroByte(data, i) + 1;
- /*
- * TO DO: Need to convert epoch into human readable time
- */
- output += (" Gamestart(epoch): " + DemoUtils.ByteToInt(data, i));
- i +=4;
- output += (" OpforTickets: " + DemoUtils.ByteToShort(data[i], data[i+1]));
- i +=2;
- output += (" BluforTickets: " + DemoUtils.ByteToShort(data[i], data[i+1]));
- i +=2;
- output += (" Mapsize: " + DemoUtils.ByteToFloat(data, i));
- return output;
- }
- //MESSAGETYPE_PLAYER_ADD 0x11
- public static String player_add (Message message) {
- byte[] data = message.getData();
- String output = "";
- Player player;
- byte id;
- String clantag;
- String name;
- String hash;
- String ip;
- //Format is
- //id ZEROBYTE clantag SPACE name ZEROBYTE hash ZEROBYTE ip ZEROBYTE
- //clantag can be nonexistant, ip is always nonexistant and hash is nonexistant for bots
- //spaces and zerobytes will exist regardles
- //zerobyte is 0x00, space is 0x20
- //Playeradd has atleast 1 player, maybe more.
- for (int counter = 0;counter < data.length;counter++) {
- id = data[counter++];
- clantag = new String (DemoUtils.getBytes(data, counter, (byte) 0x20));
- counter = DemoUtils.findByte(data, counter, (byte) 0x20) +1;
- name = DemoUtils.getStringBeforeZeroByte(data, counter);
- counter = DemoUtils.findZeroByte(data, counter) + 1;
- hash = DemoUtils.getStringBeforeZeroByte(data, counter);
- counter = DemoUtils.findZeroByte(data, counter) + 1;
- ip = DemoUtils.getStringBeforeZeroByte(data, counter);
- player = new Player(id,clantag, name, hash, ip);
- Playerlist.playerlist.add(player);
- output += ("Player joined: " + player + "\n");
- }
- return output;
- }
- //MESSAGETYPE_PLAYER_REMOVE 0x12
- //this is always just a single player, unlike PLAYER_ADD
- public static String player_remove (Message message) {
- byte[] data = message.getData();
- String output = "";
- output += ("Player left: " + Playerlist.removeId(data[0]));
- return output;
- }
- //MESSAGETYPE_KILL 0x50
- public static String kill (Message message) {
- byte[] data = message.getData();
- String output = "";
- output += Playerlist.getPlayerFromId(data[0]).getClanAndName()
- + " killed "
- + Playerlist.getPlayerFromId(data[1]).getClanAndName()
- + " with "
- + new String(DemoUtils.getBytesBeforeZeroByte(data, 2));
- return output;
- }
- //MESSAGETYPE_REVIVE 0xA0
- public static String revive (Message message) {
- byte[] data = message.getData();
- String output = "";
- output += Playerlist.getPlayerFromId(data[0]).getClanAndName()
- + " revived "
- + Playerlist.getPlayerFromId(data[1]).getClanAndName();
- return output;
- }
- //MESSAGETYPE_CHAT 0x51
- public static String chat(Message message) {
- byte[] data = message.getData();
- String output = "";
- output += (Playerlist.getPlayerFromId(data[1]).getClanAndName() + " (Channel: " + DemoUtils.ByteToLongHex(data[0]) + "): " + new String(data, 2,data.length-3));
- return output;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement