Updates for task conversion.
This commit is contained in:
parent
aee0952c17
commit
82903fde47
@ -0,0 +1,7 @@
|
||||
package mineplex.chestConverter;
|
||||
|
||||
public class AccountTask
|
||||
{
|
||||
public String Task;
|
||||
public String UUID;
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
package mineplex.chestConverter;
|
||||
|
||||
import mineplex.core.common.util.Callback;
|
||||
|
||||
public class AsyncJsonWebCall extends JsonWebCall
|
||||
{
|
||||
public AsyncJsonWebCall(String url)
|
||||
{
|
||||
super(url);
|
||||
}
|
||||
|
||||
public void Execute()
|
||||
{
|
||||
Thread asyncThread = new Thread(new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
AsyncJsonWebCall.super.Execute();
|
||||
}
|
||||
});
|
||||
|
||||
asyncThread.start();
|
||||
}
|
||||
|
||||
public void Execute(final Object argument)
|
||||
{
|
||||
Thread asyncThread = new Thread(new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
AsyncJsonWebCall.super.Execute(argument);
|
||||
}
|
||||
});
|
||||
|
||||
asyncThread.start();
|
||||
}
|
||||
|
||||
public <T> void Execute(final Class<T> callbackClass, final Callback<T> callback)
|
||||
{
|
||||
Thread asyncThread = new Thread(new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
AsyncJsonWebCall.super.Execute(callbackClass, callback);
|
||||
}
|
||||
});
|
||||
|
||||
asyncThread.start();
|
||||
}
|
||||
|
||||
public <T> void Execute(final Class<T> callbackClass, final Callback<T> callback, final Object argument)
|
||||
{
|
||||
Thread asyncThread = new Thread(new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
AsyncJsonWebCall.super.Execute(callbackClass, callback, argument);
|
||||
}
|
||||
});
|
||||
|
||||
asyncThread.start();
|
||||
}
|
||||
}
|
@ -1,8 +1,10 @@
|
||||
package mineplex.chestConverter;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class ChestConverter
|
||||
@ -13,29 +15,41 @@ public class ChestConverter
|
||||
public static void main (String args[])
|
||||
{
|
||||
_repository = new ChestConverterRepository();
|
||||
int count = 5000;
|
||||
int count = 0;
|
||||
int batchAmount = 5000;
|
||||
|
||||
HashMap<String, Integer> tasks = _repository.getTaskList();
|
||||
|
||||
while (true)
|
||||
{
|
||||
long time = System.currentTimeMillis();
|
||||
HashMap<String, Integer> playerMap = _repository.retrieveKeyInventoryBatch(count);
|
||||
HashMap<String, List<Integer>> playerMap = new HashMap<String, List<Integer>>();
|
||||
|
||||
if (playerMap.size() == 0)
|
||||
|
||||
List<AccountTask> taskList = _repository.getTasks(count, batchAmount);
|
||||
|
||||
if (taskList.size() == 0)
|
||||
return;
|
||||
|
||||
_repository.incrementClient(playerMap, false);
|
||||
_repository.deleteKeys(count);
|
||||
for (AccountTask task : taskList)
|
||||
{
|
||||
if (!playerMap.containsKey(task.UUID))
|
||||
playerMap.put(task.UUID, new ArrayList<Integer>());
|
||||
|
||||
playerMap.get(task.UUID).add(tasks.get(task.Task));
|
||||
}
|
||||
|
||||
_repository.incrementClients(playerMap);
|
||||
try
|
||||
{
|
||||
log("Natural sleep. " + count + " took " + (System.currentTimeMillis() - time) / 1000 + " seconds.");
|
||||
Thread.sleep(250);
|
||||
count += batchAmount;
|
||||
log("Natural sleep. " + batchAmount + " took " + (System.currentTimeMillis() - time) / 1000 + " seconds. Count = " + + count);
|
||||
Thread.sleep(100);
|
||||
}
|
||||
catch (InterruptedException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,23 +5,20 @@ import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
public class ChestConverterRepository
|
||||
{
|
||||
private String _connectionString = "jdbc:mysql://db.mineplex.com:3306/Account";
|
||||
private String _connectionString = "jdbc:mysql://db.mineplex.com:3306/Account?allowMultiQueries=true";
|
||||
private String _userName = "root";
|
||||
private String _password = "tAbechAk3wR7tuTh";
|
||||
|
||||
private static String RETRIEVE_CHESTS = "SELECT A.uuid, count FROM accountInventory INNER JOIN accounts AS A ON A.id = accountInventory.accountId WHERE itemId = 56 AND count > 0 ORDER BY accountInventory.id LIMIT ?;";
|
||||
private static String RETRIEVE_KEYS = "SELECT A.uuid, count FROM accountInventory INNER JOIN accounts AS A ON A.id = accountInventory.accountId WHERE itemId = 67 AND count > 0 ORDER BY accountInventory.id LIMIT ?;";
|
||||
|
||||
private static String DELETE_CHESTS = "DELETE FROM accountInventory WHERE itemId = 56 ORDER BY accountInventory.id LIMIT ?";
|
||||
private static String DELETE_KEYS = "DELETE FROM accountInventory WHERE itemId = 67 ORDER BY accountInventory.id LIMIT ?";
|
||||
|
||||
private static String INSERT_CLIENT_INVENTORY = "INSERT INTO accountInventory (accountId, itemId, count) SELECT accounts.id, ?, ? FROM accounts WHERE accounts.uuid = ? ON DUPLICATE KEY UPDATE count=count + VALUES(count);";
|
||||
private static String UPDATE_CLIENT_INVENTORY = "UPDATE accountInventory AS AI INNER JOIN accounts ON AI.accountId = accounts.id SET AI.count = AI.count + ? WHERE accounts.uuid = ? AND AI.itemId = ?;";
|
||||
private static String ADD_ACCOUNT_TASK = "INSERT INTO accountTasks (accountId, taskId) VALUES (?, ?);";
|
||||
private static String RETRIEVE_TASKS = "SELECT id, name FROM tasks;";
|
||||
|
||||
private static Connection _connection;
|
||||
|
||||
@ -56,24 +53,24 @@ public class ChestConverterRepository
|
||||
}
|
||||
}
|
||||
|
||||
public HashMap<String, Integer> retrieveChestInventoryBatch(int count)
|
||||
public HashMap<String, Integer> getTaskList()
|
||||
{
|
||||
HashMap<String, Integer> playerList = new HashMap<String, Integer>();
|
||||
|
||||
HashMap<String, Integer> tasks = new HashMap<String, Integer>();
|
||||
PreparedStatement preparedStatement = null;
|
||||
|
||||
try
|
||||
{
|
||||
if (_connection == null || _connection.isClosed())
|
||||
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
||||
|
||||
preparedStatement = _connection.prepareStatement(RETRIEVE_TASKS);
|
||||
preparedStatement.execute();
|
||||
|
||||
preparedStatement = _connection.prepareStatement(RETRIEVE_CHESTS);
|
||||
preparedStatement.setInt(1, count);
|
||||
ResultSet resultSet = preparedStatement.executeQuery();
|
||||
ResultSet resultSet = preparedStatement.getResultSet();
|
||||
|
||||
while (resultSet.next())
|
||||
{
|
||||
playerList.put(resultSet.getString(1), resultSet.getInt(2));
|
||||
tasks.put(resultSet.getString(2), resultSet.getInt(1));
|
||||
}
|
||||
}
|
||||
catch (Exception exception)
|
||||
@ -95,133 +92,64 @@ public class ChestConverterRepository
|
||||
}
|
||||
}
|
||||
|
||||
return playerList;
|
||||
return tasks;
|
||||
}
|
||||
|
||||
public HashMap<String, Integer> retrieveKeyInventoryBatch(int count)
|
||||
public List<AccountTask> getTasks(int skip, int count)
|
||||
{
|
||||
return new JsonWebCall("http://accounts.mineplex.com/PlayerAccount/GetTasksByCount").Execute(new com.google.gson.reflect.TypeToken<List<AccountTask>>(){}.getType(), new SearchConf(skip, count));
|
||||
}
|
||||
|
||||
public void incrementClients(HashMap<String, List<Integer>> playerList)
|
||||
{
|
||||
HashMap<String, Integer> playerList = new HashMap<String, Integer>();
|
||||
|
||||
PreparedStatement preparedStatement = null;
|
||||
Statement statement = null;
|
||||
|
||||
try
|
||||
{
|
||||
if (_connection == null || _connection.isClosed())
|
||||
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
||||
|
||||
preparedStatement = _connection.prepareStatement(RETRIEVE_KEYS);
|
||||
preparedStatement.setInt(1, count);
|
||||
ResultSet resultSet = preparedStatement.executeQuery();
|
||||
|
||||
while (resultSet.next())
|
||||
statement = _connection.createStatement();
|
||||
HashMap<Integer, List<Integer>> playerIdList = new HashMap<Integer, List<Integer>>();
|
||||
String queryString = "";
|
||||
for (Entry<String, List<Integer>> entry : playerList.entrySet())
|
||||
{
|
||||
playerList.put(resultSet.getString(1), resultSet.getInt(2));
|
||||
queryString += "SELECT id FROM accounts WHERE accounts.uuid = '" + entry.getKey() + "' LIMIT 1;";
|
||||
}
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
exception.printStackTrace();
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (preparedStatement != null)
|
||||
|
||||
statement.execute(queryString);
|
||||
statement.getUpdateCount();
|
||||
|
||||
for (Entry<String, List<Integer>> entry : playerList.entrySet())
|
||||
{
|
||||
try
|
||||
ResultSet resultSet = statement.getResultSet();
|
||||
|
||||
while (resultSet.next())
|
||||
{
|
||||
preparedStatement.close();
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
for (Integer taskId : entry.getValue())
|
||||
{
|
||||
if (!playerIdList.containsKey(resultSet.getInt(1)))
|
||||
playerIdList.put(resultSet.getInt(1), new ArrayList<Integer>());
|
||||
|
||||
playerIdList.get(resultSet.getInt(1)).add(taskId);
|
||||
}
|
||||
}
|
||||
statement.getMoreResults();
|
||||
}
|
||||
}
|
||||
|
||||
return playerList;
|
||||
}
|
||||
|
||||
public void incrementClient(HashMap<String, Integer> playerList, boolean chest)
|
||||
{
|
||||
PreparedStatement preparedStatement = null;
|
||||
|
||||
try
|
||||
{
|
||||
if (_connection == null || _connection.isClosed())
|
||||
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
||||
|
||||
preparedStatement = _connection.prepareStatement(UPDATE_CLIENT_INVENTORY);
|
||||
|
||||
for (Entry<String, Integer> entry : playerList.entrySet())
|
||||
preparedStatement = _connection.prepareStatement(ADD_ACCOUNT_TASK);
|
||||
System.out.println("adding to mysql db.");
|
||||
for (Entry<Integer, List<Integer>> entry : playerIdList.entrySet())
|
||||
{
|
||||
preparedStatement.setInt(1, entry.getValue());
|
||||
preparedStatement.setString(2, entry.getKey());
|
||||
preparedStatement.setInt(3, chest ? 690 : 692);
|
||||
|
||||
preparedStatement.addBatch();
|
||||
|
||||
if (chest)
|
||||
for (Integer taskId : entry.getValue())
|
||||
{
|
||||
if (entry.getValue() > 20)
|
||||
{
|
||||
preparedStatement.setInt(1, 1);
|
||||
preparedStatement.setString(2, entry.getKey());
|
||||
preparedStatement.setInt(3, 692);
|
||||
|
||||
preparedStatement.addBatch();
|
||||
}
|
||||
|
||||
if (entry.getValue() > 50)
|
||||
{
|
||||
preparedStatement.setInt(1, 1);
|
||||
preparedStatement.setString(2, entry.getKey());
|
||||
preparedStatement.setInt(3, 691);
|
||||
|
||||
preparedStatement.addBatch();
|
||||
}
|
||||
preparedStatement.setInt(1, entry.getKey());
|
||||
preparedStatement.setInt(2, taskId);
|
||||
preparedStatement.addBatch();
|
||||
}
|
||||
}
|
||||
|
||||
int[] rowsAffected = preparedStatement.executeBatch();
|
||||
int i = 0;
|
||||
|
||||
preparedStatement.close();
|
||||
preparedStatement = _connection.prepareStatement(INSERT_CLIENT_INVENTORY);
|
||||
|
||||
for (Entry<String, Integer> entry : playerList.entrySet())
|
||||
{
|
||||
if (rowsAffected[i] < 1)
|
||||
{
|
||||
preparedStatement.setInt(1, chest ? 690 : 692);
|
||||
preparedStatement.setInt(2, entry.getValue());
|
||||
preparedStatement.setString(3, entry.getKey());
|
||||
|
||||
preparedStatement.addBatch();
|
||||
|
||||
if (chest)
|
||||
{
|
||||
if (entry.getValue() > 20)
|
||||
{
|
||||
preparedStatement.setInt(1, 692);
|
||||
preparedStatement.setInt(2, 1);
|
||||
preparedStatement.setString(3, entry.getKey());
|
||||
|
||||
preparedStatement.addBatch();
|
||||
}
|
||||
|
||||
if (entry.getValue() > 50)
|
||||
{
|
||||
preparedStatement.setInt(1, 691);
|
||||
preparedStatement.setInt(2, 1);
|
||||
preparedStatement.setString(3, entry.getKey());
|
||||
|
||||
preparedStatement.addBatch();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
preparedStatement.executeBatch();
|
||||
}
|
||||
catch (Exception exception)
|
||||
@ -243,74 +171,4 @@ public class ChestConverterRepository
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void deleteChests(int count)
|
||||
{
|
||||
PreparedStatement preparedStatement = null;
|
||||
|
||||
try
|
||||
{
|
||||
if (_connection == null || _connection.isClosed())
|
||||
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
||||
|
||||
preparedStatement = _connection.prepareStatement(DELETE_CHESTS);
|
||||
preparedStatement.setInt(1, count);
|
||||
preparedStatement.executeUpdate();
|
||||
|
||||
System.out.println("Deleting " + count + " inventory records.");
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
exception.printStackTrace();
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (preparedStatement != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
preparedStatement.close();
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void deleteKeys(int count)
|
||||
{
|
||||
PreparedStatement preparedStatement = null;
|
||||
|
||||
try
|
||||
{
|
||||
if (_connection == null || _connection.isClosed())
|
||||
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
||||
|
||||
preparedStatement = _connection.prepareStatement(DELETE_KEYS);
|
||||
preparedStatement.setInt(1, count);
|
||||
preparedStatement.executeUpdate();
|
||||
|
||||
System.out.println("Deleting " + count + " inventory records.");
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
exception.printStackTrace();
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (preparedStatement != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
preparedStatement.close();
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,359 @@
|
||||
package mineplex.chestConverter;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
import mineplex.core.common.util.Callback;
|
||||
import mineplex.core.common.util.UtilSystem;
|
||||
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.conn.scheme.PlainSocketFactory;
|
||||
import org.apache.http.conn.scheme.Scheme;
|
||||
import org.apache.http.conn.scheme.SchemeRegistry;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.client.DefaultHttpClient;
|
||||
import org.apache.http.impl.conn.PoolingClientConnectionManager;
|
||||
import org.apache.http.message.BasicHeader;
|
||||
import org.apache.http.protocol.HTTP;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
public class JsonWebCall
|
||||
{
|
||||
private String _url;
|
||||
private PoolingClientConnectionManager _connectionManager;
|
||||
|
||||
public JsonWebCall(String url)
|
||||
{
|
||||
_url = url;
|
||||
|
||||
SchemeRegistry schemeRegistry = new SchemeRegistry();
|
||||
schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
|
||||
|
||||
_connectionManager = new PoolingClientConnectionManager(schemeRegistry);
|
||||
_connectionManager.setMaxTotal(200);
|
||||
_connectionManager.setDefaultMaxPerRoute(20);
|
||||
}
|
||||
|
||||
public String ExecuteReturnStream(Object argument)
|
||||
{
|
||||
HttpClient httpClient = new DefaultHttpClient(_connectionManager);
|
||||
InputStream in = null;
|
||||
String result = null;
|
||||
|
||||
try
|
||||
{
|
||||
HttpResponse response;
|
||||
|
||||
Gson gson = new Gson();
|
||||
HttpPost request = new HttpPost(_url);
|
||||
|
||||
if (argument != null)
|
||||
{
|
||||
StringEntity params = new StringEntity(gson.toJson(argument));
|
||||
params.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
|
||||
request.setEntity(params);
|
||||
}
|
||||
|
||||
response = httpClient.execute(request);
|
||||
|
||||
if (response != null)
|
||||
{
|
||||
in = response.getEntity().getContent();
|
||||
result = convertStreamToString(in);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
System.out.println("Error executing JsonWebCall: \n" + ex.getMessage());
|
||||
System.out.println("Result: \n" + result);
|
||||
|
||||
for (StackTraceElement trace : ex.getStackTrace())
|
||||
{
|
||||
System.out.println(trace);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
httpClient.getConnectionManager().shutdown();
|
||||
|
||||
if (in != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
in.close();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public void Execute()
|
||||
{
|
||||
Execute((Object)null);
|
||||
}
|
||||
|
||||
public void Execute(Object argument)
|
||||
{
|
||||
HttpClient httpClient = new DefaultHttpClient(_connectionManager);
|
||||
InputStream in = null;
|
||||
|
||||
try
|
||||
{
|
||||
Gson gson = new Gson();
|
||||
HttpPost request = new HttpPost(_url);
|
||||
|
||||
if (argument != null)
|
||||
{
|
||||
StringEntity params = new StringEntity(gson.toJson(argument));
|
||||
params.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
|
||||
request.setEntity(params);
|
||||
}
|
||||
|
||||
httpClient.execute(request);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
System.out.println("JsonWebCall.Execute() Error:\n" + ex.getMessage());
|
||||
|
||||
for (StackTraceElement trace : ex.getStackTrace())
|
||||
{
|
||||
System.out.println(trace);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
httpClient.getConnectionManager().shutdown();
|
||||
|
||||
if (in != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
in.close();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public <T> T Execute(Class<T> returnClass)
|
||||
{
|
||||
return Execute(returnClass, (Object)null);
|
||||
}
|
||||
|
||||
public <T> T Execute(Type returnType, Object argument)
|
||||
{
|
||||
HttpClient httpClient = new DefaultHttpClient(_connectionManager);
|
||||
InputStream in = null;
|
||||
T returnData = null;
|
||||
String result = null;
|
||||
|
||||
try
|
||||
{
|
||||
HttpResponse response;
|
||||
|
||||
Gson gson = new Gson();
|
||||
HttpPost request = new HttpPost(_url);
|
||||
|
||||
if (argument != null)
|
||||
{
|
||||
StringEntity params = new StringEntity(gson.toJson(argument));
|
||||
params.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
|
||||
request.setEntity(params);
|
||||
}
|
||||
|
||||
response = httpClient.execute(request);
|
||||
|
||||
if (response != null)
|
||||
{
|
||||
in = response.getEntity().getContent();
|
||||
|
||||
result = convertStreamToString(in);
|
||||
returnData = new Gson().fromJson(result, returnType);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
System.out.println("Error executing JsonWebCall: \n" + ex.getMessage());
|
||||
System.out.println("Result: \n" + result);
|
||||
|
||||
for (StackTraceElement trace : ex.getStackTrace())
|
||||
{
|
||||
System.out.println(trace);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
httpClient.getConnectionManager().shutdown();
|
||||
|
||||
if (in != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
in.close();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return returnData;
|
||||
}
|
||||
|
||||
public <T> T Execute(Class<T> returnClass, Object argument)
|
||||
{
|
||||
HttpClient httpClient = new DefaultHttpClient(_connectionManager);
|
||||
InputStream in = null;
|
||||
T returnData = null;
|
||||
String result = null;
|
||||
|
||||
try
|
||||
{
|
||||
HttpResponse response;
|
||||
|
||||
Gson gson = new Gson();
|
||||
HttpPost request = new HttpPost(_url);
|
||||
|
||||
if (argument != null)
|
||||
{
|
||||
StringEntity params = new StringEntity(gson.toJson(argument));
|
||||
params.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
|
||||
request.setEntity(params);
|
||||
}
|
||||
|
||||
response = httpClient.execute(request);
|
||||
|
||||
if (response != null)
|
||||
{
|
||||
in = response.getEntity().getContent();
|
||||
|
||||
result = convertStreamToString(in);
|
||||
returnData = new Gson().fromJson(result, returnClass);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
System.out.println("Error executing JsonWebCall: \n" + ex.getMessage());
|
||||
System.out.println("Result: \n" + result);
|
||||
|
||||
for (StackTraceElement trace : ex.getStackTrace())
|
||||
{
|
||||
System.out.println(trace);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
httpClient.getConnectionManager().shutdown();
|
||||
|
||||
if (in != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
in.close();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return returnData;
|
||||
}
|
||||
|
||||
public <T> void Execute(Class<T> callbackClass, Callback<T> callback)
|
||||
{
|
||||
Execute(callbackClass, callback, (Object)null);
|
||||
}
|
||||
|
||||
public <T> void Execute(Class<T> callbackClass, Callback<T> callback, Object argument)
|
||||
{
|
||||
HttpClient httpClient = new DefaultHttpClient(_connectionManager);
|
||||
InputStream in = null;
|
||||
String result = null;
|
||||
|
||||
try
|
||||
{
|
||||
HttpResponse response;
|
||||
|
||||
Gson gson = new Gson();
|
||||
HttpPost request = new HttpPost(_url);
|
||||
|
||||
if (argument != null)
|
||||
{
|
||||
StringEntity params = new StringEntity(gson.toJson(argument));
|
||||
params.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
|
||||
request.setEntity(params);
|
||||
}
|
||||
|
||||
response = httpClient.execute(request);
|
||||
|
||||
if (response != null && callback != null)
|
||||
{
|
||||
in = response.getEntity().getContent();
|
||||
|
||||
result = convertStreamToString(in);
|
||||
callback.run(new Gson().fromJson(result, callbackClass));
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
System.out.println("Error executing JsonWebCall: \n" + ex.getMessage());
|
||||
UtilSystem.printStackTrace(ex.getStackTrace());
|
||||
System.out.println("Result: \n" + result);
|
||||
}
|
||||
finally
|
||||
{
|
||||
httpClient.getConnectionManager().shutdown();
|
||||
|
||||
if (in != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
in.close();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected String convertStreamToString(InputStream is)
|
||||
{
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
String line = null;
|
||||
try {
|
||||
while ((line = reader.readLine()) != null) {
|
||||
sb.append(line + "\n");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
is.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package mineplex.chestConverter;
|
||||
|
||||
public class SearchConf
|
||||
{
|
||||
public SearchConf(int skip, int count)
|
||||
{
|
||||
Skip = skip;
|
||||
Count = count;
|
||||
}
|
||||
|
||||
public int Skip;
|
||||
public int Count;
|
||||
}
|
@ -76,6 +76,7 @@
|
||||
<Compile Include="Model\Server\GameServer\MineKart\MineKart.cs" />
|
||||
<Compile Include="Model\Server\GameServer\MineKart\MineKartStats.cs" />
|
||||
<Compile Include="Model\Server\PvpServer\Weapon.cs" />
|
||||
<Compile Include="SearchConf.cs" />
|
||||
<Compile Include="Tokens\AccountBatchToken.cs" />
|
||||
<Compile Include="Tokens\AccountNameToken.cs" />
|
||||
<Compile Include="Tokens\AccountTask.cs" />
|
||||
|
13
Website/LOC.Core/SearchConf.cs
Normal file
13
Website/LOC.Core/SearchConf.cs
Normal file
@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace LOC.Core
|
||||
{
|
||||
public class SearchConf
|
||||
{
|
||||
public int Skip { get; set; }
|
||||
public int Count { get; set; }
|
||||
}
|
||||
}
|
@ -72,13 +72,13 @@
|
||||
return accounts;
|
||||
}
|
||||
|
||||
public List<AccountTask> GetTasksByCount(int count)
|
||||
public List<AccountTask> GetTasksByCount(SearchConf searchConf)
|
||||
{
|
||||
var tasks = new List<AccountTask>();
|
||||
|
||||
using (var repository = _repositoryFactory.CreateRepository())
|
||||
{
|
||||
var gameTasks = repository.GetAll<GameTask>().OrderBy(x => x.GameTaskId).Take(count).Include(x => x.Account).ToList();
|
||||
var gameTasks = repository.GetAll<GameTask>().OrderBy(x => x.GameTaskId).Skip(searchConf.Skip).Take(searchConf.Count).Include(x => x.Account).ToList();
|
||||
|
||||
foreach (var task in gameTasks)
|
||||
{
|
||||
|
@ -6,6 +6,7 @@
|
||||
using Core.Model.Sales;
|
||||
using Core.Tokens;
|
||||
using Core.Tokens.Client;
|
||||
using LOC.Core;
|
||||
|
||||
public interface IAccountAdministrator
|
||||
{
|
||||
@ -42,6 +43,6 @@
|
||||
|
||||
ClientToken GetAccountByUUID(string uuid);
|
||||
|
||||
List<AccountTask> GetTasksByCount(int count);
|
||||
List<AccountTask> GetTasksByCount(SearchConf searchConf);
|
||||
}
|
||||
}
|
||||
|
@ -9,6 +9,7 @@
|
||||
using Core.Tokens.Client;
|
||||
using Newtonsoft.Json;
|
||||
using System.Collections.Generic;
|
||||
using LOC.Core;
|
||||
|
||||
public class PlayerAccountController : Controller
|
||||
{
|
||||
@ -40,9 +41,9 @@
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public ActionResult GetTasksByCount(int count)
|
||||
public ActionResult GetTasksByCount(SearchConf searchConf)
|
||||
{
|
||||
var tasks = _accountAdministrator.GetTasksByCount(count);
|
||||
var tasks = _accountAdministrator.GetTasksByCount(searchConf);
|
||||
|
||||
var json = JsonConvert.SerializeObject(tasks);
|
||||
return Content(json, "application/json");
|
||||
|
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Loading…
Reference in New Issue
Block a user