Cash ticket
#4

Okay, so instead of doing this, I just sat down for 20 minutes and wrote myself a better version of this. So please remove whatever you added and do all the things below.

GameServer\doFuncItem.cpp:

find the following function: "do_ItemUse"

you could theoretically put it after all the checks are done, but to make it easier for you just search for the upcoming line:

 

switch(item->m_itemProto->getItemIndex())

to the bottom of the switch statement (after it says "break;")

add the following line

 

// instead of case 11371 use YOUR id for the cash ticket.

case 11371:
do_ItemUse_CashTicket(ch, msg);
break;

 

now just go to the bottom of the doFuncItem.cpp and add the following lines

 

void do_ItemUse_CashTicket(CPC* ch, CNetMsg::SP& rmsg)
{

RequestClient::doItemUse* packet = reinterpret_cast<RequestClient::doItemUse*>(rmsg->m_buf);

if (ch->m_inventory.isValidNormalInventory(packet->tab, packet->invenIndex) == false)
{
LOG_ERROR("HACKING? : invalid packet. char_index[%d] tab[%d] invenIndex[%d]",
ch->m_index, packet->tab, packet->invenIndex);
ch->m_desc->Close("invalid packet");
return;
}

// ¾ÆÀÌÅÛ Ã£±â
CItem* item = ch->m_inventory.getItem(packet->tab, packet->invenIndex);
if (item == NULL)
{
LOG_ERROR("HACKING? : not found item. char_index[%d] tab[%d] invenIndex[%d]",
ch->m_index, packet->tab, packet->invenIndex);
ch->m_desc->Close("not found item");
return;
}

if (item->getVIndex() != packet->virtualIndex)
{
LOG_ERROR("HACKING? : invalid virtual index. char_index[%d] tab[%d] invenIndex[%d]",
ch->m_index, packet->tab, packet->invenIndex);
ch->m_desc->Close("invalid virtual index");
return;
}

if (item->getWearPos() != WEARING_NONE)
{
LOG_ERROR("HACKING? : item is wearing. char_index[%d] tab[%d] invenIndex[%d]",
ch->m_index, packet->tab, packet->invenIndex);
ch->m_desc->Close("invalid virtual index");
return;
}

if (item->Count() < 1)
{
ch->m_inventory.deleteItemByItem(item);
return;
}

if (ch->m_level < item->m_itemProto->GetItemProtoLevel() || ch->m_level > item->m_itemProto->GetItemProtoLevel2())
{
CNetMsg::SP msg(new CNetMsg);
ResponseClient::ItemNotUseMsg(msg, MSG_ITEM_USE_ERROR_LOWLEVEL);
SEND_Q(msg, ch->m_desc);
return;
}

int amount = item->m_itemProto->getItemNum0();

if (amount <= 0)
{
LOG_ERROR("Num0 was %d, please check the item %d and get it fixed.", amount, item->getDBIndex());
return;
}

CLCString sql(1024);
CDBCmd cmd;
cmd.Init(&gserver->m_dbauth);

sql.Format("UPDATE bg_user SET cash = cash + %d WHERE user_code = %d", amount, ch->m_desc->m_index);
cmd.SetQuery(sql);
if (!cmd.Update())
{
LOG_ERROR("Cash Query failed for user %d. Tried to add %d cash. no item loss.", ch->m_desc->m_index, amount);
return;
}

ch->m_inventory.decreaseItemCount(item, 1);

CLCString message(1024);
message.Format("Wow, you just recieved %d cash!", amount);

CNetMsg::SP clientMsg(new CNetMsg);
SayMsg(clientMsg, MSG_CHAT_NOTICE, 0, "", "", message);
SEND_Q(clientMsg, ch->m_desc);

}

for this to work open doFunc.h, scroll to the bottom and but this above the "#endif"

 

void do_ItemUse_CashTicket(CPC* ch, CNetMsg::SP& msg);



Okay so now you have to add one more thing to the source and your newstobm file and you are good to go.

 

GameServer\Server.cpp

find the ConnectDB() function.

add this at the top of it:

if (!mysql_real_connect (
&m_dbauth,
m_config.Find("Auth DB", "IP"),
m_config.Find("Auth DB", "User"),
m_config.Find("Auth DB", "Password"),
m_config.Find("Auth DB", "DBName"),
0, NULL, 0))
{
LOG_ERROR("Can't connect Auth DB : ip[%s] id[%s] pw[%s] dbname[%s] error[%s]",
m_config.Find("Auth DB", "IP"),
m_config.Find("Auth DB", "User"),
m_config.Find("Auth DB", "Password"),
m_config.Find("Auth DB", "DBName"),
mysql_error(&m_dbauth)
);
return false;
}



same file, CServer() function and find where it says "mysql_init(&m_dbchar);" and add this below:

mysql_init(&m_dbauth);

GameServer\Server.h

find "MYSQL        m_dbchar;" and put this below it:

MYSQL m_dbauth;

 

Source is done now. Go to your newStobm.bin file in your GameServer folder(s) and add the following:

[Auth DB]
IP=127.0.0.1
DBName=november_auth
User=root
Password=

obviously replace with your ip etc.

 

Alright, last thing to do is for you to create an Item. Here is an example on how it should look like!

2

Where it says "NONE" in your tool/database it will be "Num0" or something similar. Num0 is the amount of cash you will recieve from the Ticket.

Export everything, start servers, enjoy. Hope I didn't miss anything, but this is how you should be doing it.

kravens pls dont steal this design too ?

 

Edit: oh and if you want multiple cash tickets, you could add more cash tickets like this:

 

case 11371:
case 11372:
case 11373:
case 11374:
do_ItemUse_CashTicket(ch, msg);
break;

OR go out of the switch statement and at the following lines

/* 11371 = first cash ticket id
* 11374 = last cash ticket id
*/
if (item->m_itemProto->getItemIndex() >= 11371 && item->m_itemProto->getItemIndex() <= 11374)
{
do_ItemUse_CashTicket(ch, msg);
}



 



Messages In This Thread
[No subject] - by Matt Hias - 04-13-2021, 06:16 AM
[No subject] - by Joker - 04-13-2021, 02:22 PM
[No subject] - by Matt Hias - 04-13-2021, 03:42 PM
[No subject] - by Veni - 04-13-2021, 06:55 PM
[No subject] - by Matt Hias - 04-14-2021, 07:54 AM
[No subject] - by Veni - 04-14-2021, 08:04 AM
[No subject] - by Matt Hias - 04-14-2021, 08:25 AM
[No subject] - by Veni - 04-14-2021, 08:34 AM
[No subject] - by Matt Hias - 04-14-2021, 09:01 AM
[No subject] - by Scura - 04-14-2021, 09:13 AM
[No subject] - by Matt Hias - 04-14-2021, 09:23 AM
[No subject] - by Matt Hias - 04-14-2021, 10:37 AM
[No subject] - by Veni - 04-14-2021, 10:52 AM
[No subject] - by Matt Hias - 04-15-2021, 11:22 AM
[No subject] - by Veni - 04-15-2021, 12:11 PM
[No subject] - by Matt Hias - 04-15-2021, 12:56 PM
[No subject] - by Matt Hias - 04-22-2021, 08:33 PM
[No subject] - by Scura - 04-22-2021, 10:26 PM
[No subject] - by rondo157 - 04-23-2021, 02:34 AM
[No subject] - by Matt Hias - 04-23-2021, 08:01 AM
[No subject] - by Matt Hias - 04-23-2021, 08:17 AM
[No subject] - by Scura - 04-23-2021, 08:41 AM
[No subject] - by Matt Hias - 04-23-2021, 08:53 AM
[No subject] - by rondo157 - 04-23-2021, 02:26 PM
[No subject] - by nicolasg - 05-04-2022, 10:37 PM
[No subject] - by Veni - 05-05-2022, 06:23 AM
[No subject] - by rondo157 - 05-06-2022, 07:17 AM
[No subject] - by Scura - 05-06-2022, 10:18 AM
[No subject] - by nicolasg - 05-06-2022, 02:30 PM
[No subject] - by Scura - 05-06-2022, 02:38 PM
[No subject] - by nicolasg - 05-06-2022, 02:43 PM
[No subject] - by Scura - 05-06-2022, 03:10 PM
[No subject] - by Desarija - 05-06-2022, 03:12 PM
[No subject] - by Scura - 05-06-2022, 03:17 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)