Separated amount of private/offline stores

Have you created a useful tool? or Do you want to get help building one? This is the right place!
Forum rules
READ NOW: L2j Forums Rules of Conduct
Post Reply
User avatar
Jesus.M
Posts: 41
Joined: Sun Apr 25, 2010 11:33 am
Location: Lithuania
Contact:

Separated amount of private/offline stores

Post by Jesus.M »

Is there any abilities to count amount of private/offline stores and dwarven manufactures using PHP+MySQL for web page, or should I do it via Telnet? Or there isn't any abilities to do it at all? I couldn't find anything in database...
Design meets code. Obey the code!
User avatar
denser
Posts: 1392
Joined: Wed May 30, 2007 9:13 pm
Location: Russia
Contact:

Re: Separated amount of private/offline stores

Post by denser »

you have to make cron script for counting and make db for your site.
native method for this absent...
Tiger, once tasted human flesh, will want to taste it again
L2J - the place where glad to see you any time!
User avatar
Jesus.M
Posts: 41
Joined: Sun Apr 25, 2010 11:33 am
Location: Lithuania
Contact:

Re: Separated amount of private/offline stores

Post by Jesus.M »

Easy to say :P but how that script should look exactly?
Design meets code. Obey the code!
User avatar
jurchiks
Posts: 6769
Joined: Sat Sep 19, 2009 4:16 pm
Location: Eastern Europe

Re: Separated amount of private/offline stores

Post by jurchiks »

does lastactive change when you're in offline store mode? if yes, you can check which are online=0 and lastactive=now
If you have problems, FIRST TRY SOLVING THEM YOURSELF, and if you get errors, TRY TO ANALYZE THEM, and ONLY if you can't help it, THEN ask here.
Otherwise you will never learn anything if all you do is copy-paste!
Discussion breeds innovation.
User avatar
pinkcore
Posts: 247
Joined: Fri Jul 24, 2009 3:04 am
Location: Czech Republic

Re: Separated amount of private/offline stores

Post by pinkcore »

jurchiks wrote:does lastactive change when you're in offline store mode? if yes, you can check which are online=0 and lastactive=now
I think its not important...

Use character_offline_trade table and count all rows and you will get all offline stores :P

So you can only work with offline traders / crafters beacuse characters table is not designed to determine if is online player in trade mode or not.
I'm not here only for food!
User avatar
nonom
L2j Veteran
L2j Veteran
Posts: 649
Joined: Wed Mar 11, 2009 10:34 pm
Location: Magmeld

Re: Separated amount of private/offline stores

Post by nonom »

pinkcore wrote:
jurchiks wrote:does lastactive change when you're in offline store mode? if yes, you can check which are online=0 and lastactive=now
I think its not important...

Use character_offline_trade table and count all rows and you will get all offline stores :P

So you can only work with offline traders / crafters beacuse characters table is not designed to determine if is online player in trade mode or not.
@pinkcore: the character_offline_trade table is empty each time that l2j server is deployed, so you cant determinate the current number on this way. Try get it yourself

Code: Select all

SELECT * FROM `character_offline_trade`
Take a look in storeOffliners() method in OfflineTradersTable.java to see how they are being stored on each shutdown/restart.

Code: Select all

public static void storeOffliners()	{		...			for (L2PcInstance pc : L2World.getInstance().getAllPlayers().values())			{				...					if ((pc.getPrivateStoreType() != L2PcInstance.STORE_PRIVATE_NONE) && (pc.getClient() == null || pc.getClient().isDetached()))					...						con.commit(); // flush, then seems all of them are commited ;)					}				...	}
Try to make another custom method to save this count in another place. Next, you can get it through php or whatever you want.

I hope it help
Image
"There are three kinds of people in this world, those who can count and those who can't"
User avatar
denser
Posts: 1392
Joined: Wed May 30, 2007 9:13 pm
Location: Russia
Contact:

Re: Separated amount of private/offline stores

Post by denser »

try to add

Code: Select all

try            {                if ((Config.OFFLINE_TRADE_ENABLE || Config.OFFLINE_CRAFT_ENABLE) && Config.RESTORE_OFFLINERS)                    OfflineTradersTable.storeOffliners();            }            catch (Throwable t)            {                _log.log(Level.WARNING, "Error saving offline shops.",t);            }
to L2PcInstance.java in method "store". it made each 15 minutes to store table...
on server start that table become empty but in 15 mins - again fills by offliners if any
Tiger, once tasted human flesh, will want to taste it again
L2J - the place where glad to see you any time!
User avatar
pinkcore
Posts: 247
Joined: Fri Jul 24, 2009 3:04 am
Location: Czech Republic

Re: Separated amount of private/offline stores

Post by pinkcore »

@pinkcore: the character_offline_trade table is empty each time that l2j server is deployed, so you cant determinate the current number on this way. Try get it yourself
Oops sorry i forgot, but regular saving (Like denser's idea) is better than saving on shutdown. Beacuse if your machine or something get freezed all offliners are removed.
I'm not here only for food!
User avatar
denser
Posts: 1392
Joined: Wed May 30, 2007 9:13 pm
Location: Russia
Contact:

Re: Separated amount of private/offline stores

Post by denser »

my idea is damn bad coz if you have 1000 players - it become many-many-,any sql queries...MANY.
need to make globaltask or threadpool.

but direction is right ))

i done it :) thx ThE_PuNiSheR for help and explaination :P
here you are, make in scripts folder cron/OfflineTradeStore.java:

[java]package cron; import java.util.logging.Level;import java.util.logging.Logger; import com.l2jserver.Config;import com.l2jserver.gameserver.ThreadPoolManager;import com.l2jserver.gameserver.datatables.OfflineTradersTable; public class OfflineTradeStore{        public static final Logger _log = Logger.getLogger(OfflineTradeStore.class.getName());        private long _init = 1000 * 60 * 15;        private long _delay = 1000 * 60 * 15;                public OfflineTradeStore()        {                ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(new store(), _init, _delay);                 }                private class store implements Runnable        {                public void run()                {                        try                        {                                if ((Config.OFFLINE_TRADE_ENABLE || Config.OFFLINE_CRAFT_ENABLE) && Config.RESTORE_OFFLINERS)                                {                                        OfflineTradersTable.storeOffliners();                                        _log.info("Offline traders stored via cron!");                                }                        }                        catch (Throwable t)                        {                                _log.log(Level.WARNING, "Error saving offline shops.", t);                        }                }        }                        public static void main(String[] args)        {                new OfflineTradeStore();        }}[/java]
register at scripts.cfg.

it makes store offliners after script load immediately, and each 15 minutes after...so if your server crushes after load - you get chance to save you poor offliners ^^
Last edited by denser on Sun Sep 05, 2010 5:57 am, edited 1 time in total.
Tiger, once tasted human flesh, will want to taste it again
L2J - the place where glad to see you any time!
User avatar
pinkcore
Posts: 247
Joined: Fri Jul 24, 2009 3:04 am
Location: Czech Republic

Re: Separated amount of private/offline stores

Post by pinkcore »

denser wrote:my idea is damn bad coz if you have 1000 players - it become many-many-,any sql queries...MANY.
need to make globaltask or threadpool.

but direction is right ))

i done it :) thx ThE_PuNiSheR for help and explaination :P
here you are, make in scripts folder cron/OfflineTradeStore.java:

[java]package cron; import java.util.logging.Level;import java.util.logging.Logger; import com.l2jserver.Config;import com.l2jserver.gameserver.ThreadPoolManager;import com.l2jserver.gameserver.datatables.OfflineTradersTable; public class OfflineTradeStore{        public static final Logger _log = Logger.getLogger(OfflineTradeStore.class.getName());        private long _init = 0;        private long _delay = 1000 * 60 * 15;                public OfflineTradeStore()        {                ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(new store(), _init, _delay);                 }                private class store implements Runnable        {                public void run()                {                        try                        {                                if ((Config.OFFLINE_TRADE_ENABLE || Config.OFFLINE_CRAFT_ENABLE) && Config.RESTORE_OFFLINERS)                                {                                        OfflineTradersTable.storeOffliners();                                        _log.info("Offline traders stored via cron!");                                }                        }                        catch (Throwable t)                        {                                _log.log(Level.WARNING, "Error saving offline shops.", t);                        }                }        }                        public static void main(String[] args)        {                new OfflineTradeStore();        }}[/java]
register at scripts.cfg.

it makes store offliners after script load immediately, and each 15 minutes after...so if your server crushes after load - you get chance to save you poor offliners ^^
I was thinking about 1 bad condition:
1. You shutdown server with Offliners and data is safely stored.
2. You start it again with this cron script, script will be loaded before restoring offliners so table will be cleaned beacuse there will be no offliners in the world at the moment. I will test it but I'm too lazy for now.
I'm not here only for food!
User avatar
UnAfraid
L2j Veteran
L2j Veteran
Posts: 4199
Joined: Mon Jul 23, 2007 4:25 pm
Location: Bulgaria
Contact:

Re: Separated amount of private/offline stores

Post by UnAfraid »

just set init start to 10 mins..
Image
User avatar
pinkcore
Posts: 247
Joined: Fri Jul 24, 2009 3:04 am
Location: Czech Republic

Re: Separated amount of private/offline stores

Post by pinkcore »

ThE_PuNiSheR wrote:just set init start to 10 mins..
Yea it's easy but I'm thinking about saving after offliners are restored cause if my server crashes to 10 minutes all is lost too :D

But I have did the cron scripts are loaded as last thing on server startup:
(I know this isn't best way how to do it but i wanted to contribute :roll:

Core side:

Code: Select all

Index: java/com/l2jserver/gameserver/GameServer.java===================================================================--- java/com/l2jserver/gameserver/GameServer.java   (revision 4407)+++ java/com/l2jserver/gameserver/GameServer.java   (working copy)@@ -464,6 +453,18 @@        _log.info("Server Loaded in " + ((serverLoadEnd - serverLoadStart) / 1000) + " seconds");                AutoAnnounceTaskManager.getInstance();+       +       try+       {+           _log.info("Running Cron");+           File cron = new File(Config.DATAPACK_ROOT + "/data/cron.cfg");+           if(!Config.ALT_DEV_NO_HANDLERS || !Config.ALT_DEV_NO_QUESTS)+               L2ScriptEngineManager.getInstance().executeScriptList(cron);+       }+       catch (IOException ioe)+       {+           _log.severe("Failed loading cron.cfg, no script going to be loaded");+       }    }        public static void main(String[] args) throws Exception 
DP side:

Code: Select all

Index: data/cron.cfg===================================================================--- data/cron.cfg   (revision 0)+++ data/cron.cfg   (revision 0)@@ -0,0 +1 @@+cron/OfflineTradeStore.java\ No newline at end of fileIndex: data/scripts/cron/OfflineTradeStore.java===================================================================--- data/scripts/cron/OfflineTradeStore.java    (revision 0)+++ data/scripts/cron/OfflineTradeStore.java    (revision 0)@@ -0,0 +1,45 @@+package cron;+ +import java.util.logging.Level;+import java.util.logging.Logger;+ +import com.l2jserver.Config;+import com.l2jserver.gameserver.ThreadPoolManager;+import com.l2jserver.gameserver.datatables.OfflineTradersTable;+ +public class OfflineTradeStore+{+        public static final Logger _log = Logger.getLogger(OfflineTradeStore.class.getName());+        private long _init = 0;+        private long _delay = 1000 * 60 * 15;+        +        public OfflineTradeStore()+        {+                ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(new store(), _init, _delay);         +        }+        +        private class store implements Runnable+        {+                public void run()+                {+                        try+                        {+                                if ((Config.OFFLINE_TRADE_ENABLE || Config.OFFLINE_CRAFT_ENABLE) && Config.RESTORE_OFFLINERS)+                                {+                                        OfflineTradersTable.storeOffliners();+                                        _log.info("Offline traders stored via cron!");+                                }+                        }+                        catch (Throwable t)+                        {+                                _log.log(Level.WARNING, "Error saving offline shops.", t);+                        }+                }+        }+        +        +        public static void main(String[] args)+        {+                new OfflineTradeStore();+        }+}\ No newline at end of file
I'm not here only for food!
User avatar
denser
Posts: 1392
Joined: Wed May 30, 2007 9:13 pm
Location: Russia
Contact:

Re: Separated amount of private/offline stores

Post by denser »

here a little cumulative patch to focus all ideas :)
core:
[diff]Index: com/l2jserver/Config.java===================================================================--- com/l2jserver/Config.java   (revision 4410)+++ com/l2jserver/Config.java   (working copy)@@ -398,6 +398,7 @@    public static boolean ALT_DEV_NO_HANDLERS;    public static boolean ALT_DEV_NO_QUESTS;    public static boolean ALT_DEV_NO_SPAWNS;+   public static boolean ALT_DEV_NO_CRON;    public static boolean SERVER_LIST_TESTSERVER;    public static int THREAD_P_EFFECTS;    public static int THREAD_P_GENERAL;@@ -1668,6 +1675,7 @@                    ALT_DEV_NO_HANDLERS = Boolean.parseBoolean(General.getProperty("AltDevNoHandlers", "False"));                    ALT_DEV_NO_QUESTS = Boolean.parseBoolean(General.getProperty("AltDevNoQuests", "False"));                    ALT_DEV_NO_SPAWNS = Boolean.parseBoolean(General.getProperty("AltDevNoSpawns", "False"));+                   ALT_DEV_NO_CRON = Boolean.parseBoolean(General.getProperty("AltDevNoCron", "False"));                    THREAD_P_EFFECTS = Integer.parseInt(General.getProperty("ThreadPoolSizeEffects", "10"));                    THREAD_P_GENERAL = Integer.parseInt(General.getProperty("ThreadPoolSizeGeneral", "13"));                    IO_PACKET_THREAD_CORE_SIZE = Integer.parseInt(General.getProperty("UrgentPacketThreadCoreSize", "2"));Index: com/l2jserver/gameserver/GameServer.java===================================================================--- com/l2jserver/gameserver/GameServer.java    (revision 4410)+++ com/l2jserver/gameserver/GameServer.java    (working copy)@@ -464,6 +467,20 @@        _log.info("Server Loaded in " + ((serverLoadEnd - serverLoadStart) / 1000) + " seconds");                AutoAnnounceTaskManager.getInstance();+       +       try+       {+           _log.info("Loading Cron Scripts...");+           File cron = new File(Config.DATAPACK_ROOT + "/data/cron.cfg");+           if(!Config.ALT_DEV_NO_CRON)+               L2ScriptEngineManager.getInstance().executeScriptList(cron);+           else+               _log.info("Loading Cron Scripts disabled by alternative configuration.");+       }+       catch (IOException ioe)+       {+           _log.severe("Failed loading cron.cfg, no script going to be loaded");+       }    }        public static void main(String[] args) throws Exception\ No newline at end of fileIndex: config/General.properties===================================================================--- config/General.properties   (revision 4410)+++ config/General.properties   (working copy)@@ -758,4 +758,8 @@  # Don't load spawntable. # Default: False AltDevNoSpawns = False++# Don't load cron.cfg+# Default: False+AltDevNoCron = False\ No newline at end of file[/diff]

DP:
[diff]### Eclipse Workspace Patch 1.0#P gameserverIndex: data/scripts/cron/OfflineTradeStore.java===================================================================--- data/scripts/cron/OfflineTradeStore.java    (revision 0)+++ data/scripts/cron/OfflineTradeStore.java    (revision 0)@@ -0,0 +1,49 @@+package cron;+ +import java.util.logging.Level;+import java.util.logging.Logger;++import com.l2jserver.Config;+import com.l2jserver.gameserver.ThreadPoolManager;+import com.l2jserver.gameserver.datatables.OfflineTradersTable;++/**+ * @author denser+ * @author ThE_PuNiSheR+ */+public class OfflineTradeStore+{+        public static final Logger _log = Logger.getLogger(OfflineTradeStore.class.getName());+        private long _init = 0;+        private long _delay = 1000 * 60 * 15;+        +        public OfflineTradeStore()+        {+                ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(new store(), _init, _delay);         +        }+        +        private class store implements Runnable+        {+                public void run()+                {+                        try+                        {+                                if ((Config.OFFLINE_TRADE_ENABLE || Config.OFFLINE_CRAFT_ENABLE) && Config.RESTORE_OFFLINERS)+                                {+                                        OfflineTradersTable.storeOffliners();+                                        _log.info("Offline traders stored via cron!");+                                }+                        }+                        catch (Throwable t)+                        {+                                _log.log(Level.WARNING, "Error saving offline shops.", t);+                        }+                }+        }+        +        +        public static void main(String[] args)+        {+                new OfflineTradeStore();+        }+}\ No newline at end of fileIndex: data/cron.cfg===================================================================--- data/cron.cfg   (revision 0)+++ data/cron.cfg   (revision 0)@@ -0,0 +1,4 @@+# Feel free to add here your own scripts++# CRON+cron/OfflineTradeStore.java\ No newline at end of file [/diff]
Tiger, once tasted human flesh, will want to taste it again
L2J - the place where glad to see you any time!
Post Reply