Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Code Gallery (https://forums.graalonline.com/forums/forumdisplay.php?f=179)
-   -   Banking Database (https://forums.graalonline.com/forums/showthread.php?t=73267)

Rapidwolve 04-04-2007 12:03 AM

Banking Database
 
Just whipped up a Banking Database system for Terra, but I decided to start fresh and to try to go for something more advanced, so I guess I'll just leave this here. Hopefully it will help someone with their loadvars/savevars. All functions are at the top of the script, if you wanted to you can make a client ATM or something and just use these functions save accounts and stuff.

Save this in an NPC called 'Banking' or something, and don't forget to give your (npcserver) rights to mud/bank/*.txt
PHP Code:

/***************************************
*                                      *
*     BANKING                          *
*     by RW for Terra                  *
*                                      *
****************************************/
/*
Functions and Parameters:

CreateAccount(account_owner, initial_money, start_rate, password) -- To create a new account
Deposit(account_id, money_ammount, password) -- For Deposits
Withdraw(account_id, money_ammount, password) -- For withdrawls
NextAvailableID() -- Returns the next available ID number.
ChangePassword(account_id, requester, oldpassword, newpassword) -- To change the account password
*CheckAccess(accountid, password) -- Checks to see if the password matches the specified account ID's password
sendMessage(topic, message) -- Sends an NC message in format 'Banking (topic): message'
Error(id) -- Returns error message for specified error id
*DumpAccountsList() -- Dumps all accounts information to the RC (Only works on debug mode)

Features to come:
DeleteAccount(accountid, password, confirmation_code) -- When function is called with no confirmation code, one is generated. With a confirmation code the account is deleted.
*ApplyRates -- Applys the specified yearly rate for each account, if no rate exists the default is applied. (Default: 1.5%)


(* signifies a security risk)

*/

function onCreated()
  
CreateVariables();

function 
CreateVariables(){
  
this.debug_mode false;  // Output all actions to RC
  
this.yearly_rate 1.5;   // Default yearly rate
  
this.database_location "mud/bank/main_database.txt"// Database text file
  
sendMessage("System""The script of the database was updated.");
}


public function 
Deposit(accountidammountpassword){
  if (!
CheckAccess(temp.accountidtemp.password)) return Error();
  if (
temp.ammount 15 || temp.ammount 500000) return Error(1temp.accountidtemp.ammount);
  
temp.deposit.loadVars(this.database_location);
  if (!
temp.deposit.("account_" temp.accountid)) return Error(3temp.accountid);
  
temp.deposit.("account_" temp.accountid)[1] += temp.ammount;
  
temp.deposit.saveVars(this.database_location0);
  
sendMessage("Deposit"format(_("%f was deposited into account_%i"), temp.ammounttemp.accountid));
}

public function 
Withdraw(accountidammountpassword){
  if (!
CheckAccess(temp.accountidtemp.password)) return Error();
  if (
temp.ammount 15 || temp.ammount 500000) return Error(2temp.accountidtemp.ammount);
  
temp.withdraw.loadVars(this.database_location);
  if (!
temp.withdraw.("account_" temp.accountid)) return Error(3temp.accountid);
  
temp.withdraw.("account_" temp.accountid)[1] -= temp.ammount;
  
temp.withdraw.saveVars(this.database_location0);
  
sendMessage("Withdrawl"format(_("%f was withdrawn from account_%i"), temp.ammounttemp.accountid));
}

public function 
CreateAccount(accountownerstart_ammountstart_ratepassword){
  
temp.conditionsok = ((temp.start_ammount 50 || temp.start_ammount 500000) && (temp.accountowner && temp.start_ammount && temp.start_rate) == true true:false);
  if (!
temp.conditionsok) return Error();
  
temp.create.loadVars(this.database_location);
  
temp.accountid NextAvailableID();  
  if (!
temp.start_ratetemp.start_rate this.yearly_rate;
  if (
temp.create.("account_" temp.accountid)) temp.accountid = (NextAvailableID() + 1);
  
temp.create.("account_" temp.accountid) = new [4];
  
temp.create.("account_" temp.accountid)[0] = temp.accountowner;
  
temp.create.("account_" temp.accountid)[1] = temp.start_ammount;
  
temp.create.("account_" temp.accountid)[2] = temp.start_rate;
  
temp.create.("account_" temp.accountid)[3] = temp.password;
  
temp.create.saveVars(this.database_location0);
  
sendMessage("New Account"format(_("account_%i was created, with a initial deposit of %f and a start rate of %f"), temp.accountidtemp.start_ammounttemp.start_rate));
}

public function 
DumpAccountsList(){
  
temp.dump.loadVars(this.database_location);
  
sendMessage("Accounts Dump"format(_("Account, Money, Interest, Password")));
    for (
temp.itemp.dump.getdynamicvarnames())
      
sendMessage("Accounts Dump"temp.dump.(@temp.i));
}

public function 
NextAvailableID(){
  
temp.id.loadVars(this.database_location);
    for (
temp.itemp.id.getdynamicvarnames())
      
temp.nextavailable temp.i.substring(("account_").length());
  return (
temp.nextavailable 1);
}

public function 
CheckAccess(accountidpassword){
  
temp.check.loadVars(this.database_location);
  
temp.allowed false;
    if (
lowercase(temp.check.("account_" temp.accountid)[3]) == lowercase(temp.password))
      
temp.allowed true;
  return 
temp.allowed;
}

public function 
ChangePassword(accountidrequesteroldpasswordnewpassword){
  if (!
CheckAccess(temp.accountidtemp.oldpassword)) return Error();
    
temp.change.loadVars(this.database_location);
     if (
lowercase(temp.change.("account_" temp.accountid)[0]) == lowercase(temp.requester)){
      
temp.change.("account_" temp.accountid)[3] = temp.newpassword;
   }
   
temp.change.saveVars(this.database_location0);
}

public function 
ApplyRates(){
/*
scheduleevent((60 * 60 * 24 * 31 * 12), "ApplyRates", ""); // Apply rates every year
*/
}

function 
onApplyRates() ApplyRates();

public function 
sendMessage(topicmessage){
  if (
this.debug_mode)
    echo(
format(_("Banking (%s): %s"), temp.topictemp.message));
}

public function 
Error(error_idaccountidammount){
  switch (
temp.error_id){
    case 
1:
    
temp.message 
    
format(_("$%f is an invalid ammount for a deposit, called by AccountID: %i."), temp.ammounttemp.accountid);
    break;
    
    case 
2:
    
temp.message 
    
format(_("$%f is an invalid ammount for a withdrawl, called by AccountID: %i."), temp.ammounttemp.accountid);
    break;
    
    case 
3:
    
temp.message 
    
format(_("AccountID: %i doesn't exist"), temp.accountid);
    break;
    
    default:
    
temp.message 
    
"Unknown error occured.";
    break;
}
 
temp.message @= " Error Code |" SPC temp.error_id;
 
sendMessage("Error"temp.message);



Gambet 04-04-2007 12:13 AM

It's alright.


My bank system that I released a while back dominated all other bank systems though. It was hot.

Rapidwolve 04-04-2007 12:16 AM

Quote:

Originally Posted by Gambet (Post 1296513)
It's alright.


My bank system that I released a while back dominated all other bank systems though. It was hot.

I see :oo:, anyways this is just a database yours was a whole system, from clientside to serverside.

killerogue 04-04-2007 12:20 AM

Oi, nice work Rapid.

Check your PMs in a few.

Twinny 04-04-2007 12:43 AM

Quote:

Originally Posted by Gambet (Post 1296513)
It's alright.


My bank system that I released a while back dominated all other bank systems though. It was hot.

Your bank system was narrow in the ways it could be used :whatever:

Kristi 04-04-2007 02:15 AM

Quote:

Originally Posted by Twinny (Post 1296527)
Your bank system was narrow in the ways it could be used :whatever:

Not to mention a fairly sizable security risk.

Gambet 04-04-2007 02:47 AM

Quote:

Originally Posted by Twinny (Post 1296527)
Your bank system was narrow in the ways it could be used :whatever:


You don't make any sense.


It does what it's supposed to, and it's easily customizable.


Quote:

Originally Posted by Kristi (Post 1296580)
Not to mention a fairly sizable security risk.


Yeah, except implying that Graalians are stupid isn't a solid basis on a security risk when players are allowed to choose their own password.


I provide the tools, the rest is out of my hands. Besides, I provided the system, it could be altered by any server that wishes for it to be another method where players don't pick their own passwords.


We don't need to argue about this AGAIN.

Chandler 04-04-2007 08:06 AM

Here we go again, Gambet.

Kristi 04-04-2007 05:58 PM

Quote:

Originally Posted by Gambet (Post 1296585)
We don't need to argue about this AGAIN.

When you bring up an opinion such as "oh your system is decent but mine was the hottest thing ever" (that is a paraphrase, not a direct quote) which claims superiority, you can surely expect someone who disagrees to reply. If you do not want to start such a discussion, do not provide the bomb to start the war :)

Gambet 04-04-2007 08:21 PM

Quote:

Originally Posted by Kristi (Post 1296733)
When you bring up an opinion such as "oh your system is decent but mine was the hottest thing ever" (that is a paraphrase, not a direct quote) which claims superiority, you can surely expect someone who disagrees to reply. If you do not want to start such a discussion, do not provide the bomb to start the war :)


Meh, I didn't mean it so negatively.



I'm actually glad that people still release code to the public, no matter what it is, mostly any code can be used as a reference to learn about different ways of using different functions, such as in RW's example here with savevars and loadvars.

Inverness 04-05-2007 12:48 AM

Quote:

Originally Posted by Gambet (Post 1296773)
I'm actually glad that people still release code to the public, no matter what it is, mostly any code can be used as a reference to learn about different ways of using different functions, such as in RW's example here with savevars and loadvars.

You've inspired me to hurry up and polish my dialog system for release :D

Chompy 04-05-2007 01:36 AM

Quote:

Originally Posted by Inverness (Post 1296867)
You've inspired me to hurry up and polish my dialog system for release :D

WOOT! Take off :]
That dialog system owns! :o


All times are GMT +2. The time now is 09:24 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.