Code: Show/Hide ...
public static int getInt32(byte[] msg, int pos) { return (int)( ((msg[pos+3] & 0xFF) << 24) + ((msg[pos+2] & 0xFF) << 16) + ((msg[pos+1] & 0xFF) << 8) + (msg[pos ] & 0xFF) ); } ... case 0x29: //Map checksum System.out.println("Receieved: Map checksum"); String mapName = new String(data, 1, 16); long mapCRC = validator.getChecksum(mapName.trim()); if (mapCRC == -1) break; //File not found long mCrc = getInt32(data, 17) & 0xFFFFFFFFL; System.out.println(" map " + mapCRC + "/" + mCrc); if (mapCRC != mCrc) System.out.println(" " + mapName.trim() + " out of sync"); //Receieved: Map checksum // map 1087398166/3002814809 // smallmap.lvl out of sync ... |
Code: Show/Hide import java.io.*;
import java.util.zip.*; public class validator { static final int version = 1; public validator() { System.out.println("-- validator v" + version + " --"); } public static long getChecksum(byte[] file) { CRC32 crc = new CRC32(); crc.reset(); crc.update(file); return crc.getValue(); } public static long getChecksum(String fileName) { byte[] file = {0}; try { RandomAccessFile raf = new RandomAccessFile(fileName, "r"); raf.readFully(file); raf.close(); } catch(SecurityException e) { System.out.println("-- Err: Security settings too high to read local files --"); } catch(FileNotFoundException e) { System.out.println("-- Could not locate " + fileName + " --"); return -1; } catch(EOFException e) { System.err.println("-- Err: End of File exception --"); } catch(IOException e) { System.err.println("-- Err: IO exception --"); } //CRC32 crc = new CRC32(); //crc.reset(); //crc.update(file); //return crc.getValue(); return getChecksum(file); } } |