Author Topic: Persistent Store - Ideas?  (Read 885 times)

Baaleos

  • Administrator
  • Hero Member
  • *****
  • Posts: 1916
  • Karma: +0/-0
Persistent Store - Ideas?
« on: January 05, 2011, 11:15:43 am »


               Im currently making a Persistent Store Framework for my Server, which will be re-usable for all the stores in the module.
However, I've run into a snag.

1. I have the onOpen event set to Load All ITEMS from the nwnx database, into the inventory of the Store - This works
2. The on Close Event Wipes all items stored in the db, for that store, and then Stores the inventory items from the store, into the database again - To Account for any items that may have been purchased. This also works.
However, I realised that I would need to add a function in here, to delete items once they have been stored in the db, from the inventory, via DestroyObject. This is to prevent object duplication. eg - Original Stays in store, and then re-open store, gets duplicate.
I however had another problem - If the store has any base items - eg Items normally sold defined by toolset, these too would appear in the inventory, and be subject to the same storage/recovery.

The only way to solve this I thought, might be to Delete Inventory Contents onStore open event before doing any recovery, thus preventing Toolset items from being stored over and over again, after mod loads etc on StoreOpens - this also causes the problem that means that stocking the Shop's becomes an issue.
 
Does anyone have any thoughts on this?
When I ran Worlds of Rhun, I did get very much into Database Integration with website content management systems. eg - Control Game Settings via Website Control Panel, or  Creation of Items via database. eg - Define the Items in a database, and then the gameserver creates them via the spec's I specified.

Because the framework im working on, uses database already, it occurs to me, I could make a similar system, where I could define my items in a WebSite, and have a CronJob or something or other kick off once a week to re-stock my shops. (Cronjob's are scripts that run on a website).
 
The idea I am leaning towards, is not to actually define the items via website, but to actually Store a single item of each type into the nwnx database, which could then become a new Palette of sorts.
eg - Instead of copying items from DM Creator Pallette, copy the items from the Database Table instead.

Restocking of the Shops could be as simple as
Copying Item1 from ITEM_TEMPLATES to PER_STORE1 (times x amount of times)

Also - I'd be interested in hearing peoples opinions on Database driven Stores vs Standard ones. I know that Standard Stores suffer from the issue of Lag if they are over stocked, this often why we need to restart our servers once in a while, but the system im building the Inventories of the Stores themselves, will actually be empty, until the players come along to buy something.

Plus - If utilizing mySQL database as the storage system, and using the Expiration value, it allows for Items to be given a LifeTime - eg Items will remain in the store until either Purchased, or until X amount of days have passed.
Once again - to use the Expire ,I will likely have to use a CronJob.

Does anyone else use CronJobs?
I realise it might sound like a silly idea, but if you think of it, CronJobs are external to the nwn server, so would allow you to create large loops, and powerful database queries, that would not affect the server in the slightest.

CronJob's I used to use included
Transfer Players Post Count from forum to InGame Rewards
Transfer Players Forum Rank to InGame Rank (eg - Admin = Admin, Moderator = DM etc)
 
Im actually getting kinda excited at the prospects of this system - the geek in me. Lol
               
               

               
            

Baaleos

  • Administrator
  • Hero Member
  • *****
  • Posts: 1916
  • Karma: +0/-0
Persistent Store - Ideas?
« Reply #1 on: January 05, 2011, 11:10:12 pm »


               For anyone interested,

I managed to create my Cron Job that transfers new item types out of the persistent store, and saves them to another database table.



This table, is then going to be a pallette of sorts.

I can then copy items from this table, back into the stores, to restock them, in the database.

Or even automate the process via another cronjob.

eg - Once per week, select 20 random items from the table, and copy them to the store.

or - if the store has certain flags, such as selling only certain items, the cron could be set to copy only the correct item types.



I did encounter some problems, mainly working with the 'Blob' data type.



1. Because its non-numeric, you must enclose in quotation marks before submitting the mysql query.

2. Because it can contain quotation marks, you must use mysql_escape_string() on it, to make it safe for transport.



This is what I am using.

Note - this is in php, so does not impact nwserver performance, infact, this script that does the transfer of data, is executed on a completely separate host/server than the one the game runs on.

I've got the Cron set to run twice every hour, and it only copies items that it detects have not been transfered/harvested yet. (It doesnt delete the originally, they stay in the store, until purchased)



eg - If the resref and Item Name does not exist in the template table, then it transfers, if it does, it skips it.





function StoreInTemplates($val,$resref,$item_name)

{

      mysql_query("insert into item_templates (val,resref,item_name) values ('".mysql_escape_string($val)."','".$resref."','".$item_name."')") or die(mysql_error());

}

               
               

               
            

Legacy_Greyfort

  • Sr. Member
  • ****
  • Posts: 442
  • Karma: +0/-0
Persistent Store - Ideas?
« Reply #2 on: January 07, 2011, 01:05:10 am »


               I like what you've done sounds good. I would be intresed in seeing finished project.  I also like the idea of the external data base.  It seems sound especialy if your useing items that are in the toolset, or made by toolset and saved.  If you plan on saving custom made items, I have run into issue that only a Linux run server can fix due to the nwnx_struct.  This mod/plugin has item property functions that allows you to save those props to a data base then recreate item by resref then apply db item prop to item, making the custom item.  Outside of that I dont see any problems with your idea, but I havent used cronjob or external extenders other then nwnx and what it has for windows.  Fuzzy, lightfoot, virusman would better know especial virusman he has made some verynice plugins/modules for NWNX2 (for nwn1)and I think nwnx4(for nwn2) you could also try asking them in forums at: http://www.nwnx.org/
               
               

               
            

Baaleos

  • Administrator
  • Hero Member
  • *****
  • Posts: 1916
  • Karma: +0/-0
Persistent Store - Ideas?
« Reply #3 on: January 10, 2011, 12:47:26 pm »


               Hi Greyfort,

Thanks for the feedback.

Yeah I managed to get the system working, Albeit, I had to make the Persistent Stores so that only one player can open them at a time.



eg - Because when the store is loaded, all items are deleted from the database, and only re-applied to the database on StoreClose



Its to prevent duplication or players opening the store finding there no items.



I tested the Importability of the blob for an item. (a Custom Item I made in another module - Called the Belt of Duplicity)



I copied its data from my template table, and inserted it via Query into the Shop Table, for the Shop in question, and voila, the Belt appeared in that shop next time I opened the shop.



It does actually present quite alot of possibilities.



eg - Online Auctions of Items etc

   - Player Uploadable/Downloadable items.





For instance, another system I developed in my old PW, was a Dynamic Loot System, where items could fall in 5 tier categories.



1 - Blue

2 - Green

3 - Magenta

4 - Yellow

5 - Red   (Unique)



a Tier 1 Item for instance, would have 1 Randomly Chosen Damage type property, and 1 Misc Property.



and a Tier 4, would have upto 3 Damage Properties, and about 5 Misc Properties.

(Misc =  Immune to Dmg Type etc)



Tier 5 being the Most Rare of all, and being strictly honest, I only encountered one of them falling EVER.

All of these items were named according to a Diablo Style naming convention, <Prefix> ItemType <Suffix>.

Eg - Platinum Long Sword of the Heavens



The name ordinarily didnt affect what item properties appeared, but if the Prefix, Itemtype, and Suffix joined together to create a combo that existed in my database of Combo/Tier 5 items, then it would load the Item Properties for that specific combo, from the database.

These combo Items would have potentially 10 or so Properties, and would be considered Godly. Hense the Rarity.



Anyhow.....

It occurs to me, that re-introducing this system into my New PW would be a good move, especially if Players wanted to auction off their items to other players.



eg - Go to merchant, sell the item, item gets put in database, its details are collected, and viewable via a Website showing its name, description, and item properties. Players would then be capable of bidding on the item via PHP Website.



If a player wins the Bid/Auction, the item is then transfered/copied into their Players Inventory, next time they log in.



Auction systems are incredibly complicated to build, especially if done in the real world etc, Im not saying it will be easy for me, its just going to be time consuming. hehe.