Jump to content

[CRITICAL UPDATE]Web Vending Database (Standalone and FluxCP Addon)


Recommended Posts

Posted (edited)

Source inserting shop info into database.
 
Few source lines and a little bit of magic php + js
Decorated with new Twitter Bootstrap

 

Remake of this http://www.eathena.ws/board/index.php?showtopic=255406  /oops 
 
Installation
 
/src/map/vending.c
 
Function: vending_closevending
 
After 

clif_closevendingboard(&sd->bl, 0);

Add

//vending to db [Sanasol]
if( SQL_ERROR == Sql_Query(mmysql_handle,"delete from `vending` where `char_id`='%d'", sd->status.char_id) )
Sql_ShowDebug(mmysql_handle);
//vending to db [Sanasol]

Function: vending_purchasereq

 

After

// vending item
pc_additem(sd, &vsd->status.cart[idx], amount, LOG_TYPE_VENDING);
vsd->vending[vend_list[i]].amount -= amount;
pc_cart_delitem(vsd, idx, amount, 0, LOG_TYPE_VENDING);
clif_vendingreport(vsd, idx, amount);

Add

//vending to db [Sanasol]
		if(vsd->vending[vend_list[i]].amount >= 1)
		{
			if( SQL_ERROR == Sql_Query(mmysql_handle,"update `vending` set `amount`='%d' where `char_id`='%d' and `index`='%d'", vsd->vending[vend_list[i]].amount, vsd->status.char_id, vend_list[i]) )
				Sql_ShowDebug(mmysql_handle);
		}
		else
		{
			if( SQL_ERROR == Sql_Query(mmysql_handle,"delete from `vending` where `char_id`='%d' and `index`='%d'", vsd->status.char_id, vend_list[i]) )
				Sql_ShowDebug(mmysql_handle);
		}
//vending to db [Sanasol]

Function: vending_openvending
 
After

clif_openvending(sd,sd->bl.id,sd->vending);

Add

 //vending to db [Sanasol]
    for( j = 0; j < count; j++ )
    {
        int index = sd->vending[j].index;
        struct item_data* data = itemdb_search(sd->status.cart[index].nameid);
        int nameid = ( data->view_id > 0 ) ? data->view_id : sd->status.cart[index].nameid;
        int amount = sd->vending[j].amount;
        int price = cap_value(sd->vending[j].value, 0, (unsigned int)battle_config.vending_max_value);
        
        if( SQL_ERROR == Sql_Query(mmysql_handle,"INSERT INTO `vending` (`char_id`,`name`,`index`,`nameid`,`amount`,`price`,`refine`,`card0`,`card1`,`card2`,`card3`) VALUES (%d, '%s', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d')", sd->status.char_id, message, j, nameid, amount, price, sd->status.cart[index].refine, sd->status.cart[index].card[0], sd->status.cart[index].card[1], sd->status.cart[index].card[2], sd->status.cart[index].card[3]) )
        Sql_ShowDebug(mmysql_handle);
    }
    //vending to db [Sanasol]
 

/src/map/unit.c

 

After

		case BL_PC: {
			struct map_session_data *sd = (struct map_session_data*)bl;

			if(sd->shadowform_id){ //if shadow target has leave the map
			    struct block_list *d_bl = map_id2bl(sd->shadowform_id);
			    if( d_bl )
				    status_change_end(d_bl,SC__SHADOWFORM,INVALID_TIMER);
			}
			//Leave/reject all invitations.
			if(sd->chatID)
				chat_leavechat(sd,0);
			if(sd->trade_partner)
				trade_tradecancel(sd);

Add

            //vending to db [Sanasol]
            vending_closevending(sd);
            //vending to db [Sanasol]

Create table

CREATE TABLE IF NOT EXISTS `vending` (
  `char_id` int(11) unsigned NOT NULL DEFAULT '0',
  `name` varchar(50) DEFAULT NULL,
  `index` tinyint(3) unsigned NOT NULL DEFAULT '0',
  `nameid` int(11) unsigned NOT NULL DEFAULT '0',
  `amount` int(11) unsigned NOT NULL DEFAULT '0',
  `price` bigint(20) unsigned NOT NULL DEFAULT '0',
  `refine` tinyint(3) unsigned NOT NULL DEFAULT '0',
  `card0` smallint(11) NOT NULL DEFAULT '0',
  `card1` smallint(11) NOT NULL DEFAULT '0',
  `card2` smallint(11) NOT NULL DEFAULT '0',
  `card3` smallint(11) NOT NULL DEFAULT '0',
  PRIMARY KEY (`char_id`,`index`),
  KEY `char_id` (`char_id`),
  KEY `nameid` (`nameid`)
) ENGINE=MyISAM;

 
Screenshots

 

Main page

69e9a99f1f02c192e3e2cef9562b.png

 

 

Map position tooltip

84c4ecf6c00cc0f01c182bdff472.png

For map showing need *.gat files

Approximate position, accurate display at map could not to achieve :(

 

And Search

1fb870736fd032484e2452df9f50.png

 

Item images very old, you need to add the new items

 

 

FluxCP Screens

[spoiler=Main Vending DB]e56669e30bf1f420c9484f948e1d.png

[spoiler=Search]d21beacb490bc2f4415285fee024.png

 

[spoiler=Map]399cb907803a06ce3e009b5f97d5.png

Demo

FluxCP Demo

 

Sources

github.png

Sources

Sources FluxCP Addon

 

Sources is absolutely free, but if you want you can do donation

ba074bc683178eb863ef108f820a.png

 

In attach web scripts with items images

Edited by Sanasol
  • Upvote 9
Posted

Thanks! Working man! :)

 

Hope you release an addon or module that will be compatible with flux , :) thanks!

 

your hopes was heard

 

FluxCP addon ready

 

https://github.com/S-anasol/sanasol/tree/master/merchant_db_flux

 

Installation: move `vending` addon folder to `fluxcp-folder\addons`

oh... forgot about update data in table

 

Function: vending_purchasereq

 

After

// vending item
pc_additem(sd, &vsd->status.cart[idx], amount, LOG_TYPE_VENDING);
vsd->vending[vend_list[i]].amount -= amount;
pc_cart_delitem(vsd, idx, amount, 0, LOG_TYPE_VENDING);
clif_vendingreport(vsd, idx, amount);

 

Add

//vending to db [Sanasol]
        if(vsd->vending[vend_list[i]].amount >= 1)
        {
            if( SQL_ERROR == Sql_Query(mmysql_handle,"update `vending` set `amount`='%d' where `char_id`='%d' and `index`='%d'", vsd->vending[vend_list[i]].amount, vsd->status.char_id, vend_list[i]) )
                Sql_ShowDebug(mmysql_handle);
        }
        else
        {
            if( SQL_ERROR == Sql_Query(mmysql_handle,"delete from `vending` where `char_id`='%d' and `index`='%d'", vsd->status.char_id, vend_list[i]) )
                Sql_ShowDebug(mmysql_handle);
        }
//vending to db [Sanasol]
 

 

Posted

Sir how to fix this

2rxjg2s.png

 

did you add sql ?

 

CREATE TABLE IF NOT EXISTS `vending` (

`char_id` int(11) unsigned NOT NULL DEFAULT '0',

`name` varchar(50) DEFAULT NULL,

`index` tinyint(3) unsigned NOT NULL DEFAULT '0',

`nameid` int(11) unsigned NOT NULL DEFAULT '0',

`amount` int(11) unsigned NOT NULL DEFAULT '0',

`price` bigint(20) unsigned NOT NULL DEFAULT '0',

`refine` tinyint(3) unsigned NOT NULL DEFAULT '0',

`card0` smallint(11) NOT NULL DEFAULT '0',

`card1` smallint(11) NOT NULL DEFAULT '0',

`card2` smallint(11) NOT NULL DEFAULT '0',

`card3` smallint(11) NOT NULL DEFAULT '0',

PRIMARY KEY (`char_id`,`index`),

KEY `char_id` (`char_id`),

KEY `nameid` (`nameid`)

) ENGINE=MyISAM;

Posted (edited)

Found a Bug

 

 

When u Open a Shop with a Char he will display all in the Vending DB ,  but when you close the shop he dont remove the SQL entrys from DB , this will cause the Duplicate Error MSGs in the mapserver

 

2rxjg2s.png

Edited by ossi0110
Posted

Found a Bug

 

 

When u Open a Shop with a Char he will display all in the Vending DB ,  but when you close the shop he dont remove the SQL entrys from DB , this will cause the Duplicate Error MSGs in the mapserver

 

2rxjg2s.png

 

First part of code must delete after close shop. Did you add it?

 

Function: vending_closevending
 
After

 

clif_closevendingboard(&sd->bl, 0);

 

Add

 

//vending to db [Sanasol]
if( SQL_ERROR == Sql_Query(mmysql_handle,"delete from `vending` where `char_id`='%d'", sd->status.char_id) )
Sql_ShowDebug(mmysql_handle);
//vending to db [Sanasol]

 

Posted (edited)

yep i added it 

 

 

*==========================================
 * Close shop
 *------------------------------------------*/
void vending_closevending(struct map_session_data* sd) {
    nullpo_retv(sd);


    if( sd->state.vending ) {
        sd->state.vending = false;
        clif->closevendingboard(&sd->bl, 0);


        //vending to db [Sanasol ]
        if( SQL_ERROR == SQL->Query(mmysql_handle,"delete from `vending` where `char_id`='%d'", sd->status.char_id) )
        Sql_ShowDebug(mmysql_handle);
        //vending to db [Sanasol]


        idb_remove(vending->db, sd->status.char_id);
    }
}
 

 

Edited by ossi0110
Posted (edited)

yep here is error what he drops when im using a Shop,

 

hes not clearing the SQL DB after closing a shop

[SQL]: DB error - Duplicate entry '150000-0' for key 'PRIMARY'
[Debug]: at vending.c:311 - INSERT INTO `vending` (`char_id`,`name`,`index`,`nameid`,`amount`,`price`,`refine`,`card0`,`card1`,`card2`,`card3`) VALUES (150000, 'sdsadasda', '0', '1101', '1', '100000', 
 

 

 

EDIT

 

the problem only happens when using AUTOTRADE , then de dont remove the SQL entrys when u log back in 

 

 

How to Reproduce:

 

1=  Open a shop and use  @autotrade

2= log the char back ingamge

3=  Open a shop and use @autotrade

4=  you will have now a Error in map serveer

Edited by ossi0110
  • Upvote 1
Posted

when i test it work fine with autotrade

 

wait, i will test on last rA rev.



yes on rAthena this bug :(

 

My emulator delete normally.



Fixed! :)

 

/src/map/unit.c

 

After

        case BL_PC: {
            struct map_session_data *sd = (struct map_session_data*)bl;

            if(sd->shadowform_id){ //if shadow target has leave the map
             struct block_list *d_bl = map_id2bl(sd->shadowform_id);
             if( d_bl )
                 status_change_end(d_bl,SC__SHADOWFORM,INVALID_TIMER);
            }
            //Leave/reject all invitations.
            if(sd->chatID)
                chat_leavechat(sd,0);
            if(sd->trade_partner)
                trade_tradecancel(sd);
 

 

Add

            //vending to db [Sanasol]
            vending_closevending(sd);
            //vending to db [Sanasol]

 

 

Posted

Thanks! Working man! :)

 

Hope you release an addon or module that will be compatible with flux , :) thanks!

 

your hopes was heard

 

FluxCP addon ready

 

https://github.com/S-anasol/sanasol/tree/master/merchant_db_flux

 

Installation: move `vending` addon folder to `fluxcp-folder\addons`

oh... forgot about update data in table

 

Function: vending_purchasereq

 

After

// vending item
pc_additem(sd, &vsd->status.cart[idx], amount, LOG_TYPE_VENDING);
vsd->vending[vend_list[i]].amount -= amount;
pc_cart_delitem(vsd, idx, amount, 0, LOG_TYPE_VENDING);
clif_vendingreport(vsd, idx, amount);

 

Add

//vending to db [Sanasol]
        if(vsd->vending[vend_list[i]].amount >= 1)
        {
            if( SQL_ERROR == Sql_Query(mmysql_handle,"update `vending` set `amount`='%d' where `char_id`='%d' and `index`='%d'", vsd->vending[vend_list[i]].amount, vsd->status.char_id, vend_list[i]) )
                Sql_ShowDebug(mmysql_handle);
        }
        else
        {
            if( SQL_ERROR == Sql_Query(mmysql_handle,"delete from `vending` where `char_id`='%d' and `index`='%d'", vsd->status.char_id, vend_list[i]) )
                Sql_ShowDebug(mmysql_handle);
        }
//vending to db [Sanasol]
 

 

Thanks for this! :) Can't download it, error: git did not exit cleanly (exit code 128)

Posted

Thanks for this! :) Can't download it, error: git did not exit cleanly (exit code 128)

Problem with you account and probably ssh keys. Google it
Posted (edited)

ah found...

 

[26-Aug-2013 03:25:45 America/Los_Angeles] PHP Warning:  require(/home/server/public_html/merch/class.db.php) [<a href='function.require'>function.require</a>]: failed to open stream: No such file or directory in /home/server/public_html/merchant_db/config.php on line 8
[26-Aug-2013 03:25:45 America/Los_Angeles] PHP Fatal error:  require() [<a href='function.require'>function.require</a>]: Failed opening required '/home/server/public_html/merch/class.db.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/server/public_html/merchant_db/config.php on line 8
[26-Aug-2013 03:27:10 America/Los_Angeles] PHP Warning:  require(/home/server/public_html/merch/class.db.php) [<a href='function.require'>function.require</a>]: failed to open stream: No such file or directory in /home/server/public_html/merchant_db/config.php on line 8
[26-Aug-2013 03:27:10 America/Los_Angeles] PHP Fatal error:  require() [<a href='function.require'>function.require</a>]: Failed opening required '/home/server/public_html/merch/class.db.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/server/public_html/merchant_db/config.php on line 8
[26-Aug-2013 03:29:23 America/Los_Angeles] PHP Warning:  require(/home/server/public_html/merch/class.db.php) [<a href='function.require'>function.require</a>]: failed to open stream: No such file or directory in /home/server/public_html/merchant_db/config.php on line 8
[26-Aug-2013 03:29:23 America/Los_Angeles] PHP Fatal error:  require() [<a href='function.require'>function.require</a>]: Failed opening required '/home/server/public_html/merch/class.db.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/server/public_html/merchant_db/config.php on line 8
[26-Aug-2013 03:29:25 America/Los_Angeles] PHP Warning:  require(/home/server/public_html/merch/class.db.php) [<a href='function.require'>function.require</a>]: failed to open stream: No such file or directory in /home/server/public_html/merchant_db/config.php on line 8
[26-Aug-2013 03:29:25 America/Los_Angeles] PHP Fatal error:  require() [<a href='function.require'>function.require</a>]: Failed opening required '/home/server/public_html/merch/class.db.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/server/public_html/merchant_db/config.php on line 8
[26-Aug-2013 03:29:27 America/Los_Angeles] PHP Warning:  require(/home/server/public_html/merch/class.db.php) [<a href='function.require'>function.require</a>]: failed to open stream: No such file or directory in /home/server/public_html/merchant_db/config.php on line 8
[26-Aug-2013 03:29:27 America/Los_Angeles] PHP Fatal error:  require() [<a href='function.require'>function.require</a>]: Failed opening required '/home/server/public_html/merch/class.db.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/server/public_html/merchant_db/config.php on line 8
[26-Aug-2013 03:29:31 America/Los_Angeles] PHP Warning:  require(/home/server/public_html/merch/class.db.php) [<a href='function.require'>function.require</a>]: failed to open stream: No such file or directory in /home/server/public_html/merchant_db/config.php on line 8
[26-Aug-2013 03:29:31 America/Los_Angeles] PHP Fatal error:  require() [<a href='function.require'>function.require</a>]: Failed opening required '/home/server/public_html/merch/class.db.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/server/public_html/merchant_db/config.php on line 8
[26-Aug-2013 03:32:21 America/Los_Angeles] PHP Warning:  require(/home/server/public_html/merch/class.db.php) [<a href='function.require'>function.require</a>]: failed to open stream: No such file or directory in /home/server/public_html/merchant_db/config.php on line 8
[26-Aug-2013 03:32:21 America/Los_Angeles] PHP Fatal error:  require() [<a href='function.require'>function.require</a>]: Failed opening required '/home/server/public_html/merch/class.db.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/server/public_html/merchant_db/config.php on line 8
[26-Aug-2013 03:32:31 America/Los_Angeles] PHP Warning:  require(/home/server/public_html/merch/class.db.php) [<a href='function.require'>function.require</a>]: failed to open stream: No such file or directory in /home/server/public_html/merchant_db/config.php on line 8
[26-Aug-2013 03:32:31 America/Los_Angeles] PHP Fatal error:  require() [<a href='function.require'>function.require</a>]: Failed opening required '/home/server/public_html/merch/class.db.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/server/public_html/merchant_db/config.php on line 8
[26-Aug-2013 03:32:39 America/Los_Angeles] PHP Warning:  require(/home/server/public_html/merch/class.db.php) [<a href='function.require'>function.require</a>]: failed to open stream: No such file or directory in /home/server/public_html/merchant_db/config.php on line 8
[26-Aug-2013 03:32:39 America/Los_Angeles] PHP Fatal error:  require() [<a href='function.require'>function.require</a>]: Failed opening required '/home/server/public_html/merch/class.db.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/server/public_html/merchant_db/config.php on line 8
[26-Aug-2013 03:34:34 America/Los_Angeles] PHP Warning:  require(/home/server/public_html/merch/class.db.php) [<a href='function.require'>function.require</a>]: failed to open stream: No such file or directory in /home/server/public_html/merchant_db/config.php on line 8
[26-Aug-2013 03:34:34 America/Los_Angeles] PHP Fatal error:  require() [<a href='function.require'>function.require</a>]: Failed opening required '/home/server/public_html/merch/class.db.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/server/public_html/merchant_db/config.php on line 8
[26-Aug-2013 03:35:54 America/Los_Angeles] PHP Warning:  require(/home/server/public_html/merch/class.db.php) [<a href='function.require'>function.require</a>]: failed to open stream: No such file or directory in /home/server/public_html/merchant_db/config.php on line 8
[26-Aug-2013 03:35:54 America/Los_Angeles] PHP Fatal error:  require() [<a href='function.require'>function.require</a>]: Failed opening required '/home/server/public_html/merch/class.db.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/server/public_html/merchant_db/config.php on line 8
[26-Aug-2013 03:37:11 America/Los_Angeles] PHP Warning:  require(/home/server/public_html/merch/class.db.php) [<a href='function.require'>function.require</a>]: failed to open stream: No such file or directory in /home/server/public_html/vending/config.php on line 8
[26-Aug-2013 03:37:11 America/Los_Angeles] PHP Fatal error:  require() [<a href='function.require'>function.require</a>]: Failed opening required '/home/server/public_html/merch/class.db.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/server/public_html/vending/config.php on line 8
[26-Aug-2013 03:37:40 America/Los_Angeles] PHP Warning:  require(/home/server/public_html/merch/class.db.php) [<a href='function.require'>function.require</a>]: failed to open stream: No such file or directory in /home/server/public_html/vending/config.php on line 8
[26-Aug-2013 03:37:40 America/Los_Angeles] PHP Fatal error:  require() [<a href='function.require'>function.require</a>]: Failed opening required '/home/server/public_html/merch/class.db.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/server/public_html/vending/config.php on line 8
[26-Aug-2013 03:47:17 America/Los_Angeles] PHP Warning:  require(/home/server/public_html/merch/class.db.php) [<a href='function.require'>function.require</a>]: failed to open stream: No such file or directory in /home/server/public_html/vending/config.php on line 8
[26-Aug-2013 03:47:17 America/Los_Angeles] PHP Fatal error:  require() [<a href='function.require'>function.require</a>]: Failed opening required '/home/server/public_html/merch/class.db.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/server/public_html/vending/config.php on line 8
[26-Aug-2013 03:51:27 America/Los_Angeles] PHP Warning:  require(/home/server/public_html/merch/class.db.php) [<a href='function.require'>function.require</a>]: failed to open stream: No such file or directory in /home/server/public_html/merchant_db/config.php on line 8
[26-Aug-2013 03:51:27 America/Los_Angeles] PHP Fatal error:  require() [<a href='function.require'>function.require</a>]: Failed opening required '/home/server/public_html/merch/class.db.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/server/public_html/merchant_db/config.php on line 8
[26-Aug-2013 03:51:31 America/Los_Angeles] PHP Warning:  require(/home/server/public_html/merch/class.db.php) [<a href='function.require'>function.require</a>]: failed to open stream: No such file or directory in /home/server/public_html/merchant_db/config.php on line 8
[26-Aug-2013 03:51:31 America/Los_Angeles] PHP Fatal error:  require() [<a href='function.require'>function.require</a>]: Failed opening required '/home/server/public_html/merch/class.db.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/server/public_html/merchant_db/config.php on line 8
Edited by HristDead

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...