Using transfer_funds() in bank mods.

Programmers Guild

Moderator: Andreas the Wise

Post Reply
Erik Mortis
Posts: 7238
Joined: Thu Oct 02, 2003 10:37 pm
Location: County of Monty Crisco
Contact:

Using transfer_funds() in bank mods.

Post by Erik Mortis »

Code: Select all

function transfer_funds($instigator, $sender, $receiver, $funds, $reason, $server)
//Takes money from one account and put it in another. 
//A session MUST be active to use this function. ie begin_session() in util.php.
//Returns 0 on success. 
//Returns 1 on failure due to insufficient funds. 
//2 is returned if the account for the reciever did not exist.
//3 if the sender doesn't exist.
//4 if trying to send to yourself.
//5 if funds to move are neg
//6 if the receiver is an Inactive account.
//7 if the instigator is an Inactive account.
//8 if we couldn't actualy make all the changes. 
//Handles cleaning up all inputs.
//Handles error messages and logging.
//In terms of sql transactions, this function is self contained. If called as part
//of a transaction that has used begin_transaction() it will not interfer with that transaction. 
//Other wise it will cause a new transaction to be started and will commmit or recall that transaction
//only based on what happens here. 
//If used as part of a greater transaction ALWATS call begin_transaction() first
//and use commit_transaction() or abort_transaction() to complete. 
The parameter names kinda explain things clearly.
$instigator // the account that is causing the transfer. Often the person sending the money.
$sender // What account are we pulling from?
$receiver // What account is the money going into.
$funds // How much are we moving.
$reason // A string explaining why we are moving the money.
$server // A connection to the server gained from bank_server_connect().

transfer_funds() makes use of the transaction ability in sql. ie if any part of the transfer fails, it doesn't happen.

If you plan to use transfer_funds() in a mod you must do it as follows.

Code: Select all

require_once ('../../require/config.php'); //needed for bank constants
require_once ('../../require/util.php'); //needed to connect to server and transaction
require_once ('../../require/bankops'); //needed for transfer_funds()
error_reporting(E_ALL); // I require this.

begin_session() //required to move money and useful info is in here. NEVER modify it. Consider all data safe or keep a local copy you have sanitized. 
If you are just going to move money and nothing else with the server you can just called transfer_funds() without any issue.

if you are going to do other modifications along with the transfer you must make sure it all works, or doesn't happen at all. read up on database transactions.

The following are the functions you will need.
begin_transaction($server)
commit_transaction()
abort_transaction().

Here is a basic idea to use:

Code: Select all

//all the requires and stuff
//anything you might need first. 
$server = bank_server_connect();

begin_transaction($server)

//your sql queries here. 
transfer_funds(); //with all the info it will require. 

//next check if the all the queries succeeded. You can check as you go, or check it at the end in some way. 

//everything went well
commit_transaction();

//something failed
abort_transaction();
If you use begin_transaction() you MUST end it with commit or abort functions. Failing to do so will lock up the bank for the user until they relogin.

Be sure that all your error checking is being done. We don't want money moving but without the service being rendered. Also make sure transfer_funds() succeeded if you are using begin_transaction(). Once you call that function you become responsible for making sure everything worked.

Erik Mortis
Posts: 7238
Joined: Thu Oct 02, 2003 10:37 pm
Location: County of Monty Crisco
Contact:

Re: Using transfer_funds() in bank mods.

Post by Erik Mortis »

Ignore all this crap! I'm gonna redo it... it angers me how it is now.

User avatar
Andreas the Wise
Posts: 5253
Joined: Sat Oct 27, 2007 10:41 pm
Location: The Island of Melangia, Atterock, Kildare
Contact:

Re: Using transfer_funds() in bank mods.

Post by Andreas the Wise »

Ok. My bank mod won't be able to be released until Jonas makes me images anyway ...
The character Andreas the Wise is on indefinite leave.
However, this account still manages:
Cla'Udi - Count of Melangia
Manuel - CEO of VBNC. For all you'll ever need.
Vincent Waldgrave - Lord General of Gralus
Q - Director of SAMIN
Duke Mel'Kat - Air Pirate, Melangian, and Duke of the Flying Duchy of Glanurchy

And references may be made to Vur'Alm Xei'Bôn (a Nelagan Micron of undisclosed purpose).

Erik Mortis
Posts: 7238
Joined: Thu Oct 02, 2003 10:37 pm
Location: County of Monty Crisco
Contact:

Re: Using transfer_funds() in bank mods.

Post by Erik Mortis »

I'm trying to find a way to have transfer handle transactions in a proper way.. and not interfer with it being used in a larger transaction.... this plan turned out to messy.. thus.. it will go away.

User avatar
Kaiser Leto III
Posts: 540
Joined: Wed Dec 23, 2009 10:58 am

Re: Using transfer_funds() in bank mods.

Post by Kaiser Leto III »

Andreas the Wise wrote:Ok. My bank mod won't be able to be released until Jonas makes me images anyway ...
Almost forgotten. Stupid me. :fish

I will ask someone else for help too, so we get it finished faster. ;)


EDIT: can you send me the list once more, to this account, please?
Signed by the Nifty Hand of,
Leto III Ozymandias 'the Desired' of the Noble Line of Win'Eth

Post Reply

Return to “Church of the Machine God”

Who is online

Users browsing this forum: No registered users and 3 guests