mirror of
https://github.com/correl/mage.git
synced 2025-03-07 20:53:18 -10:00
Serializing all net traffic (for tracking and optimization).
This commit is contained in:
parent
82716349db
commit
b76c0e5b16
2 changed files with 55 additions and 0 deletions
|
@ -38,6 +38,7 @@ import mage.client.draft.DraftPanel;
|
|||
import mage.client.game.GamePanel;
|
||||
import mage.client.plugins.impl.Plugins;
|
||||
import mage.client.util.GameManager;
|
||||
import mage.client.util.object.SaveObjectUtil;
|
||||
import mage.interfaces.callback.CallbackClient;
|
||||
import mage.interfaces.callback.ClientCallback;
|
||||
import mage.view.AbilityPickerView;
|
||||
|
@ -74,6 +75,7 @@ public class CallbackClientImpl implements CallbackClient {
|
|||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
SaveObjectUtil.saveObject(callback.getData(), callback.getMethod());
|
||||
try {
|
||||
logger.info(callback.getMessageId() + " -- " + callback.getMethod());
|
||||
if (callback.getMethod().equals("startGame")) {
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
package mage.client.util.object;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
|
||||
|
||||
public class SaveObjectUtil {
|
||||
|
||||
private static boolean saveIncomeData = false;
|
||||
|
||||
static {
|
||||
saveIncomeData = System.getProperty("saveObjects") != null;
|
||||
}
|
||||
|
||||
public static void saveObject(Object object, String name) {
|
||||
if (saveIncomeData) {
|
||||
ObjectOutputStream oos = null;
|
||||
try {
|
||||
File dir = new File("income");
|
||||
if (!dir.exists() || dir.exists() && dir.isFile()) {
|
||||
boolean bCreated = dir.mkdir();
|
||||
if (!bCreated) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
String time = now("[yyyy_MM_dd][H-mm-ss]");
|
||||
File f = new File("income" + File.separator + name + "_" + time + ".save");
|
||||
if (!f.exists()) {
|
||||
f.createNewFile();
|
||||
}
|
||||
oos = new ObjectOutputStream(new FileOutputStream(f));
|
||||
oos.writeObject(object);
|
||||
oos.close();
|
||||
|
||||
} catch (FileNotFoundException e) {
|
||||
return;
|
||||
} catch (IOException io) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static String now(String dateFormat) {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
|
||||
return sdf.format(cal.getTime());
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue