diff --git a/src/cucky/jGuard/lib/LogComparator.java b/src/cucky/jGuard/lib/LogComparator.java new file mode 100644 index 0000000..355a48f --- /dev/null +++ b/src/cucky/jGuard/lib/LogComparator.java @@ -0,0 +1,22 @@ +package cucky.jGuard.lib; + +import cucky.jGuard.lib.object.Log; +import java.util.Comparator; + +public class LogComparator implements Comparator { + + @Override + public int compare(Log t1, Log t2) { + /* + int fromResult = Long.compare(t1.getFrom(), t2.getFrom()); + if (fromResult == 0) { + return fromResult; + } + //return fromResult; + + return Long.compare(t1.getTo(), t2.getTo()); + */ + return Long.compare(t1.getFrom(), t2.getFrom()); + } + +} diff --git a/src/cucky/jGuard/lib/LogFile.java b/src/cucky/jGuard/lib/LogFile.java new file mode 100644 index 0000000..7cae561 --- /dev/null +++ b/src/cucky/jGuard/lib/LogFile.java @@ -0,0 +1,81 @@ +package cucky.jGuard.lib; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.PrintWriter; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.logging.Level; +import java.util.logging.Logger; + +public class LogFile { + + // nazev souboru + private static final String outFile = "log.txt"; + // zapisovat i log do console + private static boolean consoleLog = true; + // format datumu a casu + private static String dateFormat = "dd.MM.YY HH:m:ss"; + // debug rezim + private static boolean debug = true; + + private static File out = new File(outFile); + + private static final DateFormat df = new SimpleDateFormat(dateFormat); + + private static void write(Object text, boolean line) { + + try { + if (!out.exists()) { + out.createNewFile(); + } + PrintWriter pwOut = new PrintWriter(new FileOutputStream(out, true), true); + pwOut.print(df.format(new Date())); + pwOut.write("\t"); + if (line) { + pwOut.println(text); + } else { + pwOut.print(text); + } + pwOut.close(); + + } catch (Exception ex) { + Logger.getLogger(LogFile.class.getName()).log(Level.SEVERE, null, ex); + } + + } + + public static void printErr(String line) { + write("E\t" + line, true); + if (consoleLog) { + System.err.println(line); + } + } + + public static void printInfo(String line) { + write("I\t" + line, true); + if (consoleLog) { + System.out.println(line); + } + } + + public static void printDebug(String line) { + write("D\t" + line, true); + if (debug) { + if (consoleLog) { + System.out.println(line); + } + } + + } + + public static void clear() { + try { + out.delete(); + } catch (Exception ex) { + Logger.getLogger(LogFile.class.getName()).log(Level.SEVERE, null, ex); + } + } + +} diff --git a/src/cucky/jGuard/lib/MapComparator.java b/src/cucky/jGuard/lib/MapComparator.java new file mode 100644 index 0000000..3d3f0a9 --- /dev/null +++ b/src/cucky/jGuard/lib/MapComparator.java @@ -0,0 +1,13 @@ +package cucky.jGuard.lib; + +import cucky.jGuard.lib.object.Map; +import java.util.Comparator; + + +public class MapComparator implements Comparator { + + @Override + public int compare(Map obj1, Map obj2) { + return obj1.getName().compareTo(obj2.getName()); + } +} diff --git a/src/cucky/jGuard/lib/Message.java b/src/cucky/jGuard/lib/Message.java new file mode 100644 index 0000000..9252d22 --- /dev/null +++ b/src/cucky/jGuard/lib/Message.java @@ -0,0 +1,135 @@ +package cucky.jGuard.lib; + +import java.io.Serializable; + + +public class Message implements Serializable { + + public static final int CLIENT_VERSION = 1; + public static final int AUTH_REQUEST = 2; + public static final int AUTH = 3; + public static final int AUTH_SUCEFULL = 4; + public static final int AUTH_FAIL = 5; + public static final int ONLINE_CLIENTS = 6; + public static final int UPDATE = 7; + public static final int SERVER_SETTINGS = 8; + public static final int USER_INFO = 9; + + /** + * zprava serveru zobrazena klientovi + * @param String text zpravy + */ + public static final int SERVER_MESSAGE = 10; + + + /********************** MAPY **********************/ + + /** + * informace o mape + */ + public static final int MAP = 100; + + /** + * pridani mapy + * @param nazev mapy + */ + public static final int ADD_MAP = 101; + + /** + * odebrani mapy + * @param id mapy + */ + public static final int REMOVE_MAP = 102; + + /** + * nastavuje zamek mapy + * int[] kde index + * 0: id mapy + * 1: 0 = odemceno + * 1 = zamceno + */ + public static final int SET_MAP_LOCK = 103; + + /********************** OBJEKTY **********************/ + + /** + * presun objektu + * int[] kde index + * 0: id mapy + * 1. id objektu + * 2: pozice x + * 3: pozice y + */ + public static final int MOVE_OBJECT = 201; + + /** + * aktualizace informaci o objektu + * MapObjekt - objekt + */ + public static final int UPDATE_OBJECT = 202; + + /** + * novy objekt + * MapObjekt - objekt + */ + public static final int ADD_OBJECT = 203; + + /** + * zmana stavu objektu + * @param int druh stavu + */ + public static final int STATE_UPDATE = 204; + + /** + * pridani typu zarizeni + * @param String nazev zarizeni + * @param String string obrazku + */ + public static final int ADD_OBJECT_TYPE = 205; + + /** + * seznam typu zarizeni + * @param ArrayList seznam + */ + public static final int LIST_OBJECT_TYPE = 206; + + /********************** SPOJENI **********************/ + /** + * nove spojení + * @param ObjectConnection + */ + public static final int NEW_CONNECTION = 300; + + /** + * uprava spojení + * @param ObjectConnection + */ + public static final int EDIT_CONNECTION = 301; + + /*************************************************/ + + private int type; + private Object msg; + + public Message(int type, Object msg) { + this.type = type; + this.msg = msg; + } + + public int getType() { + return type; + } + + public void setType(int type) { + this.type = type; + } + + public Object getMsg() { + return msg; + } + + public void setMsg(Object msg) { + this.msg = msg; + } + +} \ No newline at end of file diff --git a/src/cucky/jGuard/lib/OSValidator.java b/src/cucky/jGuard/lib/OSValidator.java new file mode 100644 index 0000000..c95996f --- /dev/null +++ b/src/cucky/jGuard/lib/OSValidator.java @@ -0,0 +1,32 @@ +package cucky.jGuard.lib; + + +public class OSValidator { + + private static String OS = System.getProperty("os.name").toLowerCase(); + + public static boolean isWindows() { + + return (OS.indexOf("win") >= 0); + + } + + public static boolean isMac() { + + return (OS.indexOf("mac") >= 0); + + } + + public static boolean isUnix() { + + return (OS.indexOf("nix") >= 0 || OS.indexOf("nux") >= 0 || OS.indexOf("aix") > 0 ); + + } + + public static boolean isSolaris() { + + return (OS.indexOf("sunos") >= 0); + + } + +}