/* serverc.c */ /* The source file containing functions whose purpose is to communicate with the backend server or device. These functions also verify all data recieved from the server/device and return either a 0, 1 or 2. */ /* (c) 2008 by ccfreak2k */ getCurrentFunds() { /* NOTE: Returns a 1 if there was a verification error. */ /* Get the current funds from the server. */ int playerID; int currentFunds; outport(3,playerID); /* Start crafting the packet. */ outport(4,GETCURRENTFUNDSAID); outport(6,1); /* Raise the trigger to signal the gate to dispatch the packet. */ while (true == true) { /* Wait for the packet muxer to lower the trigger. */ if (inport(6) == 1) { outport(6,0); /* But set the flag down first. */ /* Trigger lowered; read and verify the values. */ if (inport(3) != playerID) return 1; else if (inport(3) == FLAGACCOUNTAID) return 2; else if (inport(3) != GETCURRENTFUNDSAID) return 1; else /* Both values are ok, so give the current funds and signal success. */ currentFunds = inport(11); return 0; } } } setCurrentFunds(a,b) int a,b; { /* NOTE: Expects two ints: which action to perform, and how much money to w/d. */ /* NOTE: Returns a 1 if there was a verification error. */ /* NOTE: Returns a 2 on a funds mismatch (it also calls sendFlagPacket() automatically when this happens). */ /* Tell the server to perform a withdrawl/deposit. */ int playerID; int currentFunds; outport(3,playerID); /* Start crafting the packet. */ outport(4,a); outport(5,b); outport(6,1); /* Raise the trigger to signal the gate to dispatch the packet. */ switch (a) { /* Do some math while we wait. */ case WITHDRAWFUNDSAID: currentFunds -= b; case DEPOSITFUNDSAID: currentFunds += b; } while (true == true) { /* Wait for the packet muxer to lower the trigger. */ if (inport(6) == 0) { /* Start verifying the information. */ outport(6,0); /* But set the flag down first. */ if (inport(3) != playerID) return 1; else if (inport(3) != a) return 1; else if (inport(11) != currentFunds) { /* This is a special case that requires a new packet to be sent. */ sendFlagPacket(); return 2; /* Special code that we send if the account was flagged. */ } else return 0; /* Success! */ } } } sendFlagPacket() { /* Sends a packet to flag the account because of funds mismatch. */ int playerID; outport(3,playerID); outport(4,FLAGACCOUNTAID); outport(6,1); while (true == true) { if (inport(6) == 0) return; } }