Goes like this:
There are two pieces. 1 is the in-game side, and the other is the side program.
One the game-side there are two commands:
1) /sm deposit
2) /sm withdraw
Then there is the second side of things: The app. The app I am talking about is actually a small program the user would have to download. The app would be connected to the MC server plugin, and it would be connected to it's own server app.
Plugin responsibility:
1) process commands. When a player does /sm deposit <amount> or /sm withdraw <amount> the plugin must tell the stock market server app the name of the player, and the amount given or taken, and that is it!
2) Handle error messages returned by the stock server. Basically if I had $10 in my stock account and tried doing /sm withdraw 100 then the stock server will send an error message saying there aren't enough funds which the plugin must relay to the player. Or maybe I never registered my username therefore it will give an invalid user error.
Trade server responsibility:
1) Accept deposits and withdraws, and keep track of user accounts.
2) Process trades, and check stock prices.
3) Process account creation
So to clear things up I will go through what happens for me to participate in this program. I am assuming this feature has been created, and fully implemented on the server.
First I will go and download the Exchange client app. This is required for me to trade in the market.
Then I open the exchange app. I then type in Chief149 as my username as it is the username I play with in the server (MUST BE YOUR IN-GAME USERNAME!!!). There are two buttons: "Login" and "Register". I click register so my credentials are used to make a new account. View the spoiler for the back -end/technical stuff that goes on
When registering the client sends a register command to the server as well as username and password(hashed) data. The server then determines if the user is already registered and accepts the account creation request as a login rather than a registration so long as the account exists. If the account doesn't exist then the server makes it, and tells the client to log the user in.
Now my account is made and the client is showing me the "Portfolio". This shows my account balance, and any investments in stock.
Now I need to add funds. I go into the opticraft server and do /sm deposit 100000 to send $100000 to my portfolio. View spoiler for technical stuff.
When I use the command, the plugin sends data to the exchange server telling it to first see if my minecraft username exists as a trader account in the database. In my case it does exist therefore I get no error in-game, and the server adds the amount to the trade account. Note that if my opticraft account didn't have enough money in it then that would also raise an error
Now I decide I want buy 100 shares of Amazon, so I go back to the exchange/trade client, and I look for the "Trade" button. I click it, and I fill out the form. I decide I want to buy 100 shares of Amazon, so in the ticker symbol input I type AMZN. I want to buy so I make sure the "buy" option is checked. Then I click trade.
Firstly, the client will verify with the server that the ticker symbol is legit. If not an error will be given back to the client for the trader to see. Once the ticker symbol is verified to exist the server will then verify the user has the funds to perform the trade. If so then the server grabs the value of the stock's shares (AMZN in my case) from Finance.yahoo or some place, and applies the trade. Now no real money is traded, and the user isn't really investing in amazon. No shares are traded, but the user will have virtual money invested in virtual shares.
Now I can go to my portfolio in the trade client and view my trades. By clicking a trade the client asks the server what the current value of AMZN is, and gets it, does the calculations, and calculates the value of the stock based on price and shares owned.
One week later:
Amazon (AMZN) has gone up, but is starting to tinker down a bit. I go into the portfolio, click the AMZN trade. I enter in the number of shares I want to sell seeing as I have already made a profit, and click the "Sell" button.
The server gets the sell information. It verifies the stock symbol again, grabs the share price, and adds the share price * number of shares being sold to get how much it needs to add to the account balance. It then subtracts the number of shares sold from the number originally owned. This is done of course after verifying the user owns as many or more shares than he/she is trying to sell.
Now I want to put the profits to use in the Opticraft market to buy some coal. I go in-game and type /sm withdraw 10,000. Server verifies I have the account, and the money, and then subtracts that money from my stock exchange account and the plugin adds the money to my opticraft balance.
This is a huge idea, and a huge implementation, and perhaps a smaller version of this could be made, but this would add some realism to Opticraft being as the stock market would grab stock values from the real market.