Server administration.

This commit is contained in:
marcins78@gmail.com
2012-04-03 13:57:33 +00:00
parent fed10c1ade
commit 1c36602793
4 changed files with 59 additions and 108 deletions

View File

@@ -119,24 +119,24 @@ public class DeckDAO {
throw new RuntimeException("Unable to store player deck to DB", exp);
}
}
private void appendList(StringBuilder sb, List<String> cards) {
for (String card : cards)
sb.append("," + card);
}
private LotroDeck getDeckFromDB(int playerId, String name) {
try {
String contents = getDeckContentsFromDB(playerId, name);
if (contents != null) {
return buildDeckFromContents(contents);
} else {
return null;
}
} catch (SQLException exp) {
throw new RuntimeException("Unable to get player deck from DB", exp);
}
}
//
// private void appendList(StringBuilder sb, List<String> cards) {
// for (String card : cards)
// sb.append("," + card);
// }
//
// private LotroDeck getDeckFromDB(int playerId, String name) {
// try {
// String contents = getDeckContentsFromDB(playerId, name);
// if (contents != null) {
// return buildDeckFromContents(contents);
// } else {
// return null;
// }
// } catch (SQLException exp) {
// throw new RuntimeException("Unable to get player deck from DB", exp);
// }
// }
private String buildContentsFromDeck(LotroDeck deck) {
StringBuilder sb = new StringBuilder();
@@ -253,29 +253,29 @@ public class DeckDAO {
connection.close();
}
}
private String getDeckContentsFromDB(int playerId, String name) throws SQLException {
Connection connection = _dbAccess.getDataSource().getConnection();
try {
PreparedStatement statement = connection.prepareStatement("select contents from deck where player_id=? and name=?");
try {
statement.setInt(1, playerId);
statement.setString(2, name);
ResultSet rs = statement.executeQuery();
try {
if (rs.next()) {
return rs.getString(1);
} else {
return null;
}
} finally {
rs.close();
}
} finally {
statement.close();
}
} finally {
connection.close();
}
}
//
// private String getDeckContentsFromDB(int playerId, String name) throws SQLException {
// Connection connection = _dbAccess.getDataSource().getConnection();
// try {
// PreparedStatement statement = connection.prepareStatement("select contents from deck where player_id=? and name=?");
// try {
// statement.setInt(1, playerId);
// statement.setString(2, name);
// ResultSet rs = statement.executeQuery();
// try {
// if (rs.next()) {
// return rs.getString(1);
// } else {
// return null;
// }
// } finally {
// rs.close();
// }
// } finally {
// statement.close();
// }
// } finally {
// connection.close();
// }
// }
}

View File

@@ -17,15 +17,18 @@ public class LeagueDAO {
_dbAccess = dbAccess;
}
public void addLeague(String name, String type, int startTime, int endTime) throws SQLException, IOException {
public void addLeague(String name, String type, String clazz, String parameters, int startTime, int endTime) throws SQLException, IOException {
Connection conn = _dbAccess.getDataSource().getConnection();
try {
PreparedStatement statement = conn.prepareStatement("insert into league (name, type, start, end) values (?, ?, ?, ?)");
PreparedStatement statement = conn.prepareStatement("insert into league (name, type, class, parameters, start, end, status) values (?, ?, ?, ?, ?, ?, ?)");
try {
statement.setString(1, name);
statement.setString(2, type);
statement.setInt(3, startTime);
statement.setInt(4, endTime);
statement.setString(3, clazz);
statement.setString(4, parameters);
statement.setInt(5, startTime);
statement.setInt(6, endTime);
statement.setInt(7, 0);
statement.execute();
} finally {
statement.close();

View File

@@ -56,17 +56,6 @@ public class AdminResource extends AbstractResource {
return "OK";
}
// @Path("/migrate")
// @GET
// public String migrate(
// @Context HttpServletRequest request) throws Exception {
// validateAdmin(request);
//
// _lotroServer.migrateReplays();
//
// return "OK";
// }
@Path("/shutdown")
@GET
public String shutdown(
@@ -96,12 +85,14 @@ public class AdminResource extends AbstractResource {
public String addLeague(
@FormParam("name") String name,
@FormParam("type") String type,
@FormParam("class") String clazz,
@FormParam("parameters") String parameters,
@FormParam("start") int start,
@FormParam("end") int end,
@Context HttpServletRequest request) throws Exception {
validateAdmin(request);
_leagueDao.addLeague(name, type, start, end);
_leagueDao.addLeague(name, type, clazz, parameters, start, end);
return "OK";
}
@@ -132,24 +123,6 @@ public class AdminResource extends AbstractResource {
return "OK";
}
// @Path("/moveCollections")
// @POST
// public String moveCollections(
// @FormParam("collectionFrom") String collectionFrom,
// @FormParam("collectionTo") String collectionTo,
// @Context HttpServletRequest request) throws Exception {
// validateAdmin(request);
//
// Map<Player, CardCollection> playerCollections = _collectionsManager.getPlayersCollection(collectionFrom);
// for (Map.Entry<Player, CardCollection> playerCollection : playerCollections.entrySet()) {
// Player player = playerCollection.getKey();
//
// _collectionsManager.moveCollectionToCollection(player, createCollectionType(collectionFrom), createCollectionType(collectionTo));
// }
//
// return "OK";
// }
//
private List<String> getItems(String values) {
List<String> result = new LinkedList<String>();
for (String pack : values.split("\n")) {

View File

@@ -16,34 +16,17 @@
<form method="POST" action="server/admin/addLeague">
Name: <input type="text" name="name"><br/>
Type: <input type="text" name="type"><br/>
Code: <input type="text" name="type"><br/>
Type: <select name="class">
<option value="com.gempukku.lotro.league.ConstructedLeagueData">Constructed</option>
<option value="com.gempukku.lotro.league.SealedLeagueData">Sealed</option>
</select><br/>
Parameters: <input type="text" name="parameters"><br/>
Start: <input type="text" name="start"><br/>
End: <input type="text" name="end"><br/>
<input type="submit" value="Add league">
</form>
<h2>Add season</h2>
<form method="POST" action="server/admin/addLeagueSeason">
League type: <input type="text" name="leagueType"><br/>
Season type: <input type="text" name="type"><br/>
Format: <input type="text" name="format"><br/>
Product: <textarea rows="5" cols="20" name="product"></textarea><br/>
Start: <input type="text" name="start"><br/>
End: <input type="text" name="end"><br/>
Max matches: <input type="text" name="maxMatches"><br/>
<input type="submit" value="Add season">
</form>
<h2>Add league product</h2>
<form method="POST" action="server/admin/addLeagueProduct">
Type: <input type="text" name="leagueType"><br/>
Product: <textarea rows="5" cols="20" name="product"></textarea><br/>
Skip base collection: <input type="checkbox" name="skipBaseCollection" value="true"/><br/>
<input type="submit" value="Add product">
</form>
<h1>Collections</h1>
<h2>Add items</h2>
@@ -55,13 +38,5 @@
<input type="submit" value="Add items">
</form>
<h2>Move cards in collections</h2>
<form method="POST" action="server/admin/moveCollections">
Collection from: <input type="text" name="collectionFrom"><br/>
Collection to: <input type="text" name="collectionTo"><br/>
<input type="submit" value="Add items">
</form>
</body>
</html>