Added logging of vault clears for display in the leaderboard

This commit is contained in:
simon 2018-03-05 21:47:28 -05:00
parent 0a75cb557d
commit f8c5dac969
8 changed files with 135 additions and 4 deletions

View File

@ -4,6 +4,7 @@ import com.mongodb.DBObject;
import net.simon987.npcplugin.event.CpuInitialisationListener;
import net.simon987.npcplugin.event.VaultWorldUpdateListener;
import net.simon987.npcplugin.event.WorldCreationListener;
import net.simon987.npcplugin.io.StatsDatabaseManager;
import net.simon987.server.ServerConfiguration;
import net.simon987.server.assembly.CpuHardware;
import net.simon987.server.game.GameObject;
@ -21,6 +22,8 @@ public class NpcPlugin extends ServerPlugin implements GameObjectDeserializer, C
*/
private static ArrayList<RadioTower> radioTowers;
private static StatsDatabaseManager statsDbManager;
@Override
public void init(ServerConfiguration configuration) {
@ -30,6 +33,8 @@ public class NpcPlugin extends ServerPlugin implements GameObjectDeserializer, C
radioTowers = new ArrayList<>(32);
statsDbManager = new StatsDatabaseManager(configuration);
LogManager.LOGGER.info("Initialised NPC plugin");
}
@ -52,6 +57,8 @@ public class NpcPlugin extends ServerPlugin implements GameObjectDeserializer, C
return ElectricBox.deserialize(obj);
} else if (objType == Portal.ID) {
return Portal.deserialize(obj);
} else if (objType == VaultExitPortal.ID) {
return VaultExitPortal.deserialize(obj);
}
return null;
@ -72,4 +79,8 @@ public class NpcPlugin extends ServerPlugin implements GameObjectDeserializer, C
public static ArrayList<RadioTower> getRadioTowers() {
return radioTowers;
}
public static StatsDatabaseManager getStatsDbManager() {
return statsDbManager;
}
}

View File

@ -140,7 +140,7 @@ public class VaultDimension {
if (exitPortalPt != null) {
Portal exitPortal = new Portal();
VaultExitPortal exitPortal = new VaultExitPortal();
exitPortal.setDst(exitLocation);
exitPortal.setX(exitPortalPt.x);
exitPortal.setY(exitPortalPt.y);

View File

@ -157,6 +157,7 @@ public class VaultDoor extends GameObject implements Programmable, Enterable, Up
VaultDoor vaultDoor = new VaultDoor(0); //cypherId ?
vaultDoor.setX((int) obj.get("x"));
vaultDoor.setY((int) obj.get("y"));
vaultDoor.setObjectId((long) obj.get("i"));
if (obj.containsField("homeX") && obj.containsField("homeY")) {

View File

@ -0,0 +1,61 @@
package net.simon987.npcplugin;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;
import net.simon987.server.game.ControllableUnit;
import net.simon987.server.game.GameObject;
import net.simon987.server.game.Location;
import net.simon987.server.logging.LogManager;
/**
* Final exit portal located in the 'last' World of a Vault dimension
*/
public class VaultExitPortal extends Portal {
public static final int ID = 9;
@Override
public BasicDBObject mongoSerialise() {
BasicDBObject dbObject = new BasicDBObject();
dbObject.put("i", getObjectId());
dbObject.put("x", getX());
dbObject.put("y", getY());
dbObject.put("t", ID);
dbObject.put("dstWorldX", getDst().worldX);
dbObject.put("dstWorldY", getDst().worldY);
dbObject.put("dstX", getDst().x);
dbObject.put("dstY", getDst().y);
dbObject.put("dstDimension", getDst().dimension);
return dbObject;
}
@Override
public boolean enter(GameObject object) {
LogManager.LOGGER.info(((ControllableUnit) object).getParent().getUsername() + " Completed vault " +
object.getWorld().getDimension());
NpcPlugin.getStatsDbManager().saveVaultCompletion((ControllableUnit) object, object.getWorld().getDimension());
return super.enter(object);
}
public static Portal deserialize(DBObject obj) {
VaultExitPortal portal = new VaultExitPortal();
portal.setDst(new Location(
(int) obj.get("dstWorldX"),
(int) obj.get("dstWorldY"),
(String) obj.get("dstDimension"),
(int) obj.get("dstX"),
(int) obj.get("dstY")));
portal.setX((int) obj.get("x"));
portal.setY((int) obj.get("y"));
return portal;
}
}

View File

@ -0,0 +1,49 @@
package net.simon987.npcplugin.io;
import com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException;
import net.simon987.server.ServerConfiguration;
import net.simon987.server.game.ControllableUnit;
import net.simon987.server.io.DatabaseManager;
import net.simon987.server.logging.LogManager;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
public class StatsDatabaseManager extends DatabaseManager {
public StatsDatabaseManager(ServerConfiguration config) {
super(config);
}
public void saveVaultCompletion(ControllableUnit unit, String dimension) {
Connection connection = getConnection();
try {
PreparedStatement p = connection.prepareStatement("INSERT INTO mar_vault_clear " +
"(username, clear_time, vault_id) VALUES (?,?,?)");
p.setString(1, unit.getParent().getUsername());
p.setInt(2, 0);
p.setString(3, dimension);
int result = p.executeUpdate();
LogManager.LOGGER.fine("Saved vault clear (" + result + " rows changed)");
} catch (MySQLIntegrityConstraintViolationException e) {
LogManager.LOGGER.fine("This vault was already cleared by " + unit.getParent().getUsername());
} catch (SQLException e) {
LogManager.LOGGER.severe(e.getMessage());
e.printStackTrace();
} finally {
try {
connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}

View File

@ -13,6 +13,8 @@ public interface ControllableUnit {
void setParent(User user);
User getParent();
ArrayList<Integer> getKeyboardBuffer();
Memory getFloppyData();

View File

@ -167,7 +167,11 @@ public class DebugHandler implements MessageHandler {
}
} catch (Exception e) {
return Arrays.toString(e.getStackTrace()).replaceAll(", ", "\n");
String message = e.getMessage();
message += "\n " + Arrays.toString(e.getStackTrace()).replaceAll(", ", "\n");
return message;
}
@ -213,7 +217,10 @@ public class DebugHandler implements MessageHandler {
} catch (Exception e) {
return Arrays.toString(e.getStackTrace()).replaceAll(", ", "\n");
String message = e.getMessage();
message += "\n " + Arrays.toString(e.getStackTrace()).replaceAll(", ", "\n");
return message;
}
}

View File

@ -179,7 +179,7 @@ public class SocketServer extends WebSocketServer {
JSONObject json = new JSONObject();
json.put("t", "tick");
LogManager.LOGGER.info("Notified " + userManager.getOnlineUsers().size() + " users");
// LogManager.LOGGER.info("Notified " + userManager.getOnlineUsers().size() + " users");
ArrayList<OnlineUser> onlineUsers = new ArrayList<>(userManager.getOnlineUsers()); //Avoid ConcurrentModificationException
for (OnlineUser user : onlineUsers) {