diff --git a/LoginServer/conf/Config.xml b/LoginServer/conf/Config.xml index 7576db8..a2b0c10 100644 --- a/LoginServer/conf/Config.xml +++ b/LoginServer/conf/Config.xml @@ -10,7 +10,7 @@ 34526 localhost 8186 - org.moparscape.msc.ls.persistence.impl.DummyStorageMedium + org.moparscape.msc.ls.persistence.impl.SerializedStorageMedium org.moparscape.msc.ls.auth.impl.DummyAuth http://localhost/auth.php diff --git a/LoginServer/src/org/moparscape/msc/ls/model/BankItem.java b/LoginServer/src/org/moparscape/msc/ls/model/BankItem.java index c520856..7822943 100644 --- a/LoginServer/src/org/moparscape/msc/ls/model/BankItem.java +++ b/LoginServer/src/org/moparscape/msc/ls/model/BankItem.java @@ -1,7 +1,14 @@ package org.moparscape.msc.ls.model; -public class BankItem extends Item { - public BankItem(int id, int amount) { +import java.io.Serializable; + +public class BankItem extends Item implements Serializable { + /** + * + */ + private static final long serialVersionUID = 1L; + + public BankItem(int id, int amount) { super(id, amount); } } \ No newline at end of file diff --git a/LoginServer/src/org/moparscape/msc/ls/model/InvItem.java b/LoginServer/src/org/moparscape/msc/ls/model/InvItem.java index 1d4c0be..58f185f 100644 --- a/LoginServer/src/org/moparscape/msc/ls/model/InvItem.java +++ b/LoginServer/src/org/moparscape/msc/ls/model/InvItem.java @@ -1,14 +1,21 @@ package org.moparscape.msc.ls.model; -public class InvItem extends Item { - private boolean wielded; +import java.io.Serializable; - public InvItem(int id, int amount, boolean wielded) { - super(id, amount); - this.wielded = wielded; - } +public class InvItem extends Item implements Serializable { + /** + * + */ + private static final long serialVersionUID = 1L; + private boolean wielded; - public boolean isWielded() { - return wielded; - } + public InvItem(int id, int amount, boolean wielded) { + super(id, amount); + this.wielded = wielded; + } + + + public boolean isWielded() { + return wielded; + } } \ No newline at end of file diff --git a/LoginServer/src/org/moparscape/msc/ls/model/Item.java b/LoginServer/src/org/moparscape/msc/ls/model/Item.java index 22c4a5e..18eb1ac 100644 --- a/LoginServer/src/org/moparscape/msc/ls/model/Item.java +++ b/LoginServer/src/org/moparscape/msc/ls/model/Item.java @@ -1,6 +1,8 @@ package org.moparscape.msc.ls.model; -public class Item { +import java.io.Serializable; + +public class Item implements Serializable { private int amount; private int id; diff --git a/LoginServer/src/org/moparscape/msc/ls/model/PlayerSave.java b/LoginServer/src/org/moparscape/msc/ls/model/PlayerSave.java index cc323e1..2af7947 100644 --- a/LoginServer/src/org/moparscape/msc/ls/model/PlayerSave.java +++ b/LoginServer/src/org/moparscape/msc/ls/model/PlayerSave.java @@ -1,5 +1,6 @@ package org.moparscape.msc.ls.model; +import java.io.Serializable; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -7,7 +8,12 @@ import java.util.List; import org.moparscape.msc.ls.Server; import org.moparscape.msc.ls.util.DataConversions; -public class PlayerSave { +public class PlayerSave implements Serializable { + + /** + * + */ + private static final long serialVersionUID = 2613872958788286998L; public static PlayerSave loadPlayer(long user) { return Server.storage.loadPlayer(user); diff --git a/LoginServer/src/org/moparscape/msc/ls/persistence/impl/SerializedStorageMedium.java b/LoginServer/src/org/moparscape/msc/ls/persistence/impl/SerializedStorageMedium.java new file mode 100644 index 0000000..e78cebe --- /dev/null +++ b/LoginServer/src/org/moparscape/msc/ls/persistence/impl/SerializedStorageMedium.java @@ -0,0 +1,278 @@ +package org.moparscape.msc.ls.persistence.impl; + +import java.io.File; + + +/** + * @author xEnt + */ +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.util.Arrays; +import java.util.List; + +import org.moparscape.msc.ls.model.PlayerSave; +import org.moparscape.msc.ls.persistence.StorageMedium; +import org.moparscape.msc.ls.util.Config; +import org.moparscape.msc.ls.util.DataConversions; + +public class SerializedStorageMedium implements StorageMedium { + + ObjectOutputStream oos; + + @Override + public boolean savePlayer(PlayerSave s) { + try { + File f = new File(s.getUsername()); + if(!f.exists()) + f.createNewFile(); + oos = new ObjectOutputStream(new FileOutputStream(f)); + oos.writeObject(s); + } catch(Exception e) { + e.printStackTrace(); + } + finally { + try { + if (oos != null) { + oos.flush(); + oos.close(); + } + } catch (Exception ex) { + ex.printStackTrace(); + } + } + return false; + } + + @Override + public void shutdown() { + // TODO Auto-generated method stub + + } + + @Override + public void logTrade(long from, long to, int item, long amount, int x, + int y, int type, long date) { + // TODO Auto-generated method stub + + } + + @Override + public void logReport(long user, long reported, byte reason, int x, int y, + String status) { + // TODO Auto-generated method stub + + } + + @Override + public void resetOnlineFlag(int world) { + // TODO Auto-generated method stub + + } + + @Override + public void logKill(long user, long killed, byte type) { + // TODO Auto-generated method stub + + } + + @Override + public void addFriend(long user, long friend) { + // TODO Auto-generated method stub + + } + + @Override + public boolean addFriend_isOnline0(long user, long friend) { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean addFriend_isOnline1(long friend, long user) { + // TODO Auto-generated method stub + return false; + } + + @Override + public void removeFriend(long user, long friend) { + // TODO Auto-generated method stub + + } + + @Override + public boolean removeFriend_isOnline(long user) { + // TODO Auto-generated method stub + return false; + } + + @Override + public void addIgnore(long user, long friend) { + // TODO Auto-generated method stub + + } + + @Override + public void removeIgnore(long user, long friend) { + // TODO Auto-generated method stub + + } + + @Override + public List getFriendsOnline(long user) { + // TODO Auto-generated method stub + return null; + } + + @Override + public void chatBlock(int on, long user) { + // TODO Auto-generated method stub + + } + + @Override + public void privateBlock(int on, long user) { + // TODO Auto-generated method stub + + } + + @Override + public List getPrivateBlockFriendsOnline(long user) { + // TODO Auto-generated method stub + return null; + } + + @Override + public void tradeBlock(int on, long user) { + // TODO Auto-generated method stub + + } + + @Override + public void duelBlock(int on, long user) { + // TODO Auto-generated method stub + + } + + @Override + public boolean playerExists(long user) { + // TODO Auto-generated method stub + return true; + } + + @Override + public boolean isBanned(long user) { + // TODO Auto-generated method stub + return false; + } + + @Override + public int getGroupID(long user) { + // TODO Auto-generated method stub + return 11; + } + + private long ownerId = 0; + + @Override + public long getOwner(long user) { + return ownerId++; + } + + @Override + public void setOnlineFlag(int id, long user) { + // TODO Auto-generated method stub + + } + + @Override + public boolean ban(boolean setBanned, long user) { + // TODO Auto-generated method stub + return false; + } + + @Override + public void logBan(long user, long modhash) { + // TODO Auto-generated method stub + + } + + @Override + public void setGameSettings(int idx, boolean on, long user) { + // TODO Auto-generated method stub + + } + + @Override + public PlayerSave loadPlayer(long user) { + + PlayerSave ps = getPlayerData(user); + + if (ps == null) // new char + { + PlayerSave save = new PlayerSave(user); + save.setLocation(213, 452); + save.setAppearance((byte) 2, (byte) 8, (byte) 14, (byte) 0, (byte) 1, + (byte) 2, true, 0l); + + int[] exp = new int[Config.statArray.length]; + Arrays.fill(exp, 0); + int[] stats = exp.clone(); + + exp[3] = 1154; + save.setExp(exp); + stats[3] = 10; + save.setCurStats(stats); + return save; + } else { + return ps; + } + + } + + + + @Override + public void logLogin(long user, String ip) { + // TODO Auto-generated method stub + + } + + @Override + public void logIn(String ip, long user) { + // TODO Auto-generated method stub + + } + + @Override + public String getPass(long user) { + return ""; + } + + + public PlayerSave getPlayerData(long user) { + File userr = new File(DataConversions.hashToUsername(user)); + if (!userr.exists() ) + { + return null; + } + + try { + FileInputStream fis = new FileInputStream(userr); + + ObjectInputStream ois = new ObjectInputStream(fis); + PlayerSave ps = (PlayerSave)ois.readObject(); + return ps; + + } catch (Exception e) { + e.printStackTrace(); + } + + return null; + } + +}