Page 1 of 1

Separated amount of private/offline stores

Posted: Sat Jun 19, 2010 10:52 pm
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...

Re: Separated amount of private/offline stores

Posted: Sun Jun 20, 2010 6:34 am
by denser
you have to make cron script for counting and make db for your site.
native method for this absent...

Re: Separated amount of private/offline stores

Posted: Sun Jun 20, 2010 6:57 am
by Jesus.M
Easy to say :P but how that script should look exactly?

Re: Separated amount of private/offline stores

Posted: Sun Jun 20, 2010 11:03 am
by jurchiks
does lastactive change when you're in offline store mode? if yes, you can check which are online=0 and lastactive=now

Re: Separated amount of private/offline stores

Posted: Sun Aug 08, 2010 3:06 pm
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.

Re: Separated amount of private/offline stores

Posted: Sun Aug 08, 2010 9:10 pm
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

Re: Separated amount of private/offline stores

Posted: Sat Sep 04, 2010 8:35 am
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

Re: Separated amount of private/offline stores

Posted: Sat Sep 04, 2010 10:40 am
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.

Re: Separated amount of private/offline stores

Posted: Sat Sep 04, 2010 6:57 pm
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 ^^

Re: Separated amount of private/offline stores

Posted: Sat Sep 04, 2010 9:13 pm
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.

Re: Separated amount of private/offline stores

Posted: Sat Sep 04, 2010 10:37 pm
by UnAfraid
just set init start to 10 mins..

Re: Separated amount of private/offline stores

Posted: Sat Sep 04, 2010 11:09 pm
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

Re: Separated amount of private/offline stores

Posted: Sun Sep 05, 2010 1:29 pm
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]