= Updated core documentation quickly
This commit is contained in:
@@ -8,8 +8,7 @@ import dataStructures.UserInput;
|
|||||||
|
|
||||||
public class CommandThread extends Thread
|
public class CommandThread extends Thread
|
||||||
{
|
{
|
||||||
// Pile of variables
|
// Pile of variables. This may be packaged later as thread arguments.
|
||||||
// TODO(wisp): Consider packaging this up into a thread arguments object potentially...?
|
|
||||||
CommandManager manager;
|
CommandManager manager;
|
||||||
UserInput input;
|
UserInput input;
|
||||||
KittyGuild guild;
|
KittyGuild guild;
|
||||||
|
|||||||
@@ -12,13 +12,13 @@ import utils.LogFilter;
|
|||||||
// This is where we put everything and swap out the moving parts,
|
// This is where we put everything and swap out the moving parts,
|
||||||
// ie MySQL, PostgreSQL, SQLite, etc...
|
// ie MySQL, PostgreSQL, SQLite, etc...
|
||||||
//
|
//
|
||||||
// TODO(wisp): Right now this can be messed up with SQL injection stuff if users
|
// Right now this can be messed up with SQL injection stuff if users
|
||||||
// are allowed to directly touch data. Leaving it like this temporarily.
|
// are allowed to directly touch data. Leaving it like this temporarily,
|
||||||
|
// and is for prototyping only!
|
||||||
public class DatabaseDriver
|
public class DatabaseDriver
|
||||||
{
|
{
|
||||||
|
// Config and local varaibles
|
||||||
private JDBCDriver driver;
|
private JDBCDriver driver;
|
||||||
|
|
||||||
// Note: Changing these values can mess up the database...
|
|
||||||
private final String globalTableName = "kitty_globals";
|
private final String globalTableName = "kitty_globals";
|
||||||
private final String globalKeyName = "GlobalKey";
|
private final String globalKeyName = "GlobalKey";
|
||||||
private final String globalValueName = "GlobalValue";
|
private final String globalValueName = "GlobalValue";
|
||||||
@@ -28,6 +28,7 @@ public class DatabaseDriver
|
|||||||
driver = null;
|
driver = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set up and create a table in the database
|
||||||
public boolean Connect()
|
public boolean Connect()
|
||||||
{
|
{
|
||||||
driver = new JDBCDriverSQLite();
|
driver = new JDBCDriverSQLite();
|
||||||
@@ -54,7 +55,7 @@ public class DatabaseDriver
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// the key will be created if it doesn't exist, and the default value returned.
|
// Creates a key. The key will be created if it doesn't exist, and the default value returned.
|
||||||
public String CreateGetKey(String key)
|
public String CreateGetKey(String key)
|
||||||
{
|
{
|
||||||
GlobalLog.Log(LogFilter.Database, "CreateGeyKey: key-" + key);
|
GlobalLog.Log(LogFilter.Database, "CreateGeyKey: key-" + key);
|
||||||
@@ -71,41 +72,38 @@ public class DatabaseDriver
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Prototype formatting for key updating
|
||||||
private void UpdateKey(String key, String value)
|
private void UpdateKey(String key, String value)
|
||||||
{
|
{
|
||||||
//GlobalLog.Log(LogFilter.Database, "Update key " + key);
|
|
||||||
String command = "UPDATE " + globalTableName + " SET " + globalValueName + " = '" + value + "' WHERE " + globalKeyName + "= '" + key + "';";
|
String command = "UPDATE " + globalTableName + " SET " + globalValueName + " = '" + value + "' WHERE " + globalKeyName + "= '" + key + "';";
|
||||||
//GlobalLog.Log(LogFilter.Database, "Composed command: " + command);
|
|
||||||
driver.ExecuteStatement(command);
|
driver.ExecuteStatement(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Protoype updating for seeing if a key exists
|
||||||
private boolean HasKey(String key)
|
private boolean HasKey(String key)
|
||||||
{
|
{
|
||||||
//GlobalLog.Log(LogFilter.Database, "Has key " + key);
|
|
||||||
String command = "SELECT COUNT(1) as count FROM " + globalTableName + " WHERE " + globalKeyName + " = '" + key + "';";
|
String command = "SELECT COUNT(1) as count FROM " + globalTableName + " WHERE " + globalKeyName + " = '" + key + "';";
|
||||||
//GlobalLog.Log(LogFilter.Database, "Composed command: " + command);
|
|
||||||
ResultSet set = driver.ExecuteReturningStatement(command);
|
ResultSet set = driver.ExecuteReturningStatement(command);
|
||||||
String out = ResultAsString(set, "count");
|
String out = ResultAsString(set, "count");
|
||||||
return out.charAt(0) == '1';
|
return out.charAt(0) == '1';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Prototype for getting a key
|
||||||
private String GetKey(String key)
|
private String GetKey(String key)
|
||||||
{
|
{
|
||||||
//GlobalLog.Log(LogFilter.Database, "Getting key " + key);
|
|
||||||
String command = "SELECT " + globalValueName + " as searchedKey FROM " + globalTableName +" WHERE " + globalKeyName + "= \'" + key + "\';";
|
String command = "SELECT " + globalValueName + " as searchedKey FROM " + globalTableName +" WHERE " + globalKeyName + "= \'" + key + "\';";
|
||||||
//GlobalLog.Log(LogFilter.Database, "Composed command: " + command);
|
|
||||||
ResultSet set = driver.ExecuteReturningStatement(command);
|
ResultSet set = driver.ExecuteReturningStatement(command);
|
||||||
return ResultAsString(set, "searchedKey");
|
return ResultAsString(set, "searchedKey");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Prototype for creating a key
|
||||||
private void CreateKey(String key, String value)
|
private void CreateKey(String key, String value)
|
||||||
{
|
{
|
||||||
//GlobalLog.Log(LogFilter.Database, "Creating Key " + key);
|
|
||||||
String command = "INSERT INTO " + globalTableName + " (GlobalKey, GlobalValue) VALUES ('" + key + "', '" + value + "');";
|
String command = "INSERT INTO " + globalTableName + " (GlobalKey, GlobalValue) VALUES ('" + key + "', '" + value + "');";
|
||||||
//GlobalLog.Log(LogFilter.Database, "Composed command: " + command);
|
|
||||||
driver.ExecuteStatement(command);
|
driver.ExecuteStatement(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Transforms a result into a string if possible.
|
||||||
private String ResultAsString(ResultSet rs, String key)
|
private String ResultAsString(ResultSet rs, String key)
|
||||||
{
|
{
|
||||||
if(rs == null)
|
if(rs == null)
|
||||||
|
|||||||
@@ -32,9 +32,7 @@ public class DatabaseManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Thumbs through registered objects and syncs them with the database.
|
// Thumbs through registered objects and syncs them with the database.
|
||||||
// TODO(wisp) Right now this just syncs on the main thread, but we will
|
// Consider moving this operation to a separate thread.
|
||||||
// want to have upkeep commands queue up for a dedicated database thread
|
|
||||||
// in the future to offload the wait times.
|
|
||||||
public void Upkeep()
|
public void Upkeep()
|
||||||
{
|
{
|
||||||
for(int i = 0 ; i < trackedObjects.size(); ++i)
|
for(int i = 0 ; i < trackedObjects.size(); ++i)
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package core;
|
package core;
|
||||||
|
|
||||||
|
// Objects inheriting from this are capable of being stored in and
|
||||||
|
// have their data populated from database entries.
|
||||||
public abstract class DatabaseTrackedObject
|
public abstract class DatabaseTrackedObject
|
||||||
{
|
{
|
||||||
private boolean isDirty;
|
private boolean isDirty;
|
||||||
@@ -26,10 +28,8 @@ public abstract class DatabaseTrackedObject
|
|||||||
isDirty = false;
|
isDirty = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(wisp): Not the best way to handle this, potentially consider
|
// Consider an object factory instead of dedicated serialization methods
|
||||||
// using an object factory that looks up how to serialize and
|
// if this starts to become impractical. For now, it works.
|
||||||
// deserialize based on the type of the thing being tracked.
|
|
||||||
// For now, this is fine.
|
|
||||||
public abstract String Serialize();
|
public abstract String Serialize();
|
||||||
public abstract void DeSerialzie(String string);
|
public abstract void DeSerialzie(String string);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,10 +34,7 @@ public class ObjectBuilderFactory
|
|||||||
// RPManger for tracking RP system
|
// RPManger for tracking RP system
|
||||||
private static RPManager rpManager;
|
private static RPManager rpManager;
|
||||||
|
|
||||||
// NOTE(wisp): This is designed to initialize at the last possible second.
|
// Lazy initialization style for
|
||||||
// The idea behind this is that there may be other things that may need
|
|
||||||
// time to initialize before the factory can use them, and this guarantees
|
|
||||||
// they get the time they need.
|
|
||||||
private static boolean hasInitialized;
|
private static boolean hasInitialized;
|
||||||
private static Semaphore initMutex = new Semaphore(1);
|
private static Semaphore initMutex = new Semaphore(1);
|
||||||
private static void LazyInit()
|
private static void LazyInit()
|
||||||
@@ -50,8 +47,7 @@ public class ObjectBuilderFactory
|
|||||||
initMutex.acquire();
|
initMutex.acquire();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// NOTE(wisp): Actually put all the init code here.
|
// Initialization here. This is where we could read from something external.
|
||||||
// In the future, this is where we would read from something external.
|
|
||||||
guildCache = new HashMap<String, KittyGuild>();
|
guildCache = new HashMap<String, KittyGuild>();
|
||||||
userCache = new HashMap<String, KittyUser>();
|
userCache = new HashMap<String, KittyUser>();
|
||||||
channelCache = new HashMap<String, KittyChannel>();
|
channelCache = new HashMap<String, KittyChannel>();
|
||||||
|
|||||||
+2
-1
@@ -8,7 +8,8 @@ import core.CommandManager.ThreadData;
|
|||||||
import utils.GlobalLog;
|
import utils.GlobalLog;
|
||||||
import utils.LogFilter;
|
import utils.LogFilter;
|
||||||
|
|
||||||
// NOTE(wisp): This is a class designed to be asked about various kittybot stats
|
// This is a class designed to be asked about various kittybot stats.
|
||||||
|
// It follows a singleton pattern, and is accessable from anywhere internally.
|
||||||
public class Stats
|
public class Stats
|
||||||
{
|
{
|
||||||
public static String botName = "KittyBot";
|
public static String botName = "KittyBot";
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package core;
|
package dataStructures;
|
||||||
|
|
||||||
|
// This is a structure representing an image reponse for handing around.
|
||||||
public class GenericImage
|
public class GenericImage
|
||||||
{
|
{
|
||||||
private String artist;
|
private String artist;
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package network;
|
|||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import core.*;
|
import core.*;
|
||||||
|
import dataStructures.GenericImage;
|
||||||
import offline.*;
|
import offline.*;
|
||||||
import utils.*;
|
import utils.*;
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package network;
|
|||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import core.*;
|
import core.*;
|
||||||
|
import dataStructures.GenericImage;
|
||||||
import utils.*;
|
import utils.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user