[Add-On][All ver.] - Player transfer system
For those who say it's unoptimized, I don't give a fuck. Take it or leave it.
server.PlayerTransfer.java :
PHP Code:
package server;
import client.*;
import java.sql.SQLException;
import java.util.*;
import server.maps.MapleMapFactory;
import tools.DatabaseConnection;
import net.world.MapleParty;
import java.sql.*;
/**
*
* @author FateJiki
*/
public class PlayerTransfer {
public static List<MapleCharacter> transferList = new ArrayList<MapleCharacter>();
public static void addCharacter(MapleCharacter chr){
synchronized(transferList){
if(!transferList.contains(chr)){
transferList.add(chr);
}
}
}
public static MapleCharacter retrieveCharacter(int cid, MapleClient c){
MapleCharacter chr = null;
synchronized(transferList){
for(MapleCharacter xferList : transferList){
if(xferList.getId() == cid){
chr = xferList;
chr.client = c;
updateCServer(chr);
}
}
if(chr == null){
try{
chr = MapleCharacter.loadCharFromDB(cid, c, true);
} catch(SQLException e){
e.printStackTrace();
}
}
}
return chr;
}
public static void removeCharacter(int cid){
synchronized(transferList){
for(MapleCharacter removeList : transferList){
if(removeList.getId() == cid){
transferList.remove(removeList);
}
}
}
}
private synchronized static void updateCServer(MapleCharacter ret){
MapleClient client = ret.getClient();
MapleMapFactory mapFactory = client.getChannelServer().getMapFactory();
ret.map = mapFactory.getMap(ret.mapid);
if (ret.map == null) {
ret.map = mapFactory.getMap(100000000);
}
}
}
ChangeChannelHandler.java :
Replace
PHP Code:
c.getPlayer().saveToDB(true);
with :
PHP Code:
PlayerTransfer.addCharacter(c.getPlayer());
PlayerLoggedInHandler :
Replace :
PHP Code:
player.loadCharFromDB
with :
PHP Code:
MapleCharacter player = PlayerTransfer.retrieveCharacter(cid, c);
This should speed up the channel changing process and put less stress on the SQL Server.
If you want me to keep releasing shit, provide credits if you plan to use this.
Re: [All ver.] - Player transfer system
I like it. :)
________________________________________________________
Can someone please help me: http://forum.ragezone.com/f566/help-...nished-716918/
Scania vanished and I have no way to select a world. There are no worlds in the world selection screen.
Re: [All ver.] - Player transfer system
Please review the section guidelines. A new tag system has been implemented as of 1/1/11. Other than that, great job!
Re: [Add-On][All ver.] - Player transfer system
so what it does? and how do we do it?
Re: [Add-On][All ver.] - Player transfer system
Quote:
Originally Posted by
Gardenshotel
so what it does? and how do we do it?
Everytime you change channels, the server saves your character to the Database, then reloads it from the database. What this does is that it caches your character information and reloads it from inside the cache. (Then gets disposed of after load).
It's very useful and faster.
Re: [Add-On][All ver.] - Player transfer system
Just a really quick question. In my ChangeChannelHanler.java I don't have
PHP Code:
c.getPlayer().saveToDB(true);
Idk maybe MoopleDEV did it differently.
Re: [Add-On][All ver.] - Player transfer system
Okay I get most of the function you provided but what does the synchronized have to do with all this??
Re: [Add-On][All ver.] - Player transfer system
Quote:
Originally Posted by
iAkira
Okay I get most of the function you provided but what does the synchronized have to do with all this??
I just thought it might help. If it doesn't feel free to remove it yourself.
---------- Post added at 08:58 PM ---------- Previous post was at 08:55 PM ----------
Quote:
Originally Posted by
HorrorChix89
Just a really quick question. In my ChangeChannelHanler.java I don't have
PHP Code:
c.getPlayer().saveToDB(true);
Idk maybe MoopleDEV did it differently.
PHP Code:
public void changeChannel() {
expiretask.cancel(false);
cancelMagicDoor();
saveCooldowns();
if (getBuffedValue(MapleBuffStat.MONSTER_RIDING) != null) {
cancelEffectFromBuffStat(MapleBuffStat.MONSTER_RIDING);
}
if (getBuffedValue(MapleBuffStat.PUPPET) != null) {
cancelEffectFromBuffStat(MapleBuffStat.PUPPET);
}
if (getBuffedValue(MapleBuffStat.COMBO) != null) {
cancelEffectFromBuffStat(MapleBuffStat.COMBO);
}
getInventory(MapleInventoryType.EQUIPPED).checked(false); //test
saveToDB(true);
getMap().removePlayer(this);
getClient().getChannelServer().removePlayer(this);
getClient().updateLoginState(MapleClient.LOGIN_SERVER_TRANSITION);
For MoopleDEV users, that method is located in MapleCharacter@ChangeChannel
Gosh, why put another method like this? So pointless.
}
Re: [Add-On][All ver.] - Player transfer system
Can you just use ret.map like that? Is it public at your source?
Re: [Add-On][All ver.] - Player transfer system
Quote:
Originally Posted by
Deagan ツ
Can you just use ret.map like that? Is it public at your source?
I think I made it public. This is to update the MapFactory, so it realizes you are on another channel.
Re: [Add-On][All ver.] - Player transfer system
Quote:
Originally Posted by
FateJiki
I just thought it might help. If it doesn't feel free to remove it yourself.
---------- Post added at 08:58 PM ---------- Previous post was at 08:55 PM ----------
PHP Code:
public void changeChannel() {
expiretask.cancel(false);
cancelMagicDoor();
saveCooldowns();
if (getBuffedValue(MapleBuffStat.MONSTER_RIDING) != null) {
cancelEffectFromBuffStat(MapleBuffStat.MONSTER_RIDING);
}
if (getBuffedValue(MapleBuffStat.PUPPET) != null) {
cancelEffectFromBuffStat(MapleBuffStat.PUPPET);
}
if (getBuffedValue(MapleBuffStat.COMBO) != null) {
cancelEffectFromBuffStat(MapleBuffStat.COMBO);
}
getInventory(MapleInventoryType.EQUIPPED).checked(false); //test
saveToDB(true);
getMap().removePlayer(this);
getClient().getChannelServer().removePlayer(this);
getClient().updateLoginState(MapleClient.LOGIN_SERVER_TRANSITION);
For MoopleDEV users, that method is located in MapleCharacter@ChangeChannel
Gosh, why put another method like this? So pointless.
}
Thanks I was wondering where it was:thumbup1:
Re: [Add-On][All ver.] - Player transfer system
Quote:
Originally Posted by
FateJiki
I think I made it public. This is to update the MapFactory, so it realizes you are on another channel.
I understand what it does, but the ret.map wouldn't work at like every other source...
ret.getMap() would work about everywhere though.
Re: [Add-On][All ver.] - Player transfer system
Quote:
Originally Posted by
Deagan ツ
I understand what it does, but the ret.map wouldn't work at like every other source...
ret.getMap() would work about everywhere though.
Indeed. Though it's not complicated to change it from a private to a public.
Re: [Add-On][All ver.] - Player transfer system
It needs to be synchronized as I can definitely see this going through multiple threads as once. You'll get concurrency problems all over the place.
Anyways I think a Map would be better for this as you're clearly going for speed. I think the memory usage for Map isn't much worse than List here anyhow.
Re: [Add-On][All ver.] - Player transfer system
Quote:
Originally Posted by
FateJiki
Indeed. Though it's not complicated to change it from a private to a public.
I would prefer only calling something from another class when necessary over having it public all-time but meh, it isn't that much of a difference.
Nice release anyways, not really sure if this is faster than sql though.