Working with numbers and strings
by Robert Fritzen · in Technical Issues · 04/16/2011 (7:13 pm) · 5 replies
Well, I'm stumped currently. I'm trying to finish up what's left of my experience system and this numbers thing is killing me.
I'm having some big time problems converting the data types of the numbers here for my system.
Running this code crashes my client with a runtime error, I've pinned it down to the AESEncrypt line, but the reason is for "Invalid Data", so I'm assuming it's the number conversion.
I'm not sure if itoa is the correct option here, or if there is a provided function that I should be using for string (or char[]/char *) -> F32 conversion.
Any ideas???
I'm having some big time problems converting the data types of the numbers here for my system.
F32 PGDStore::handleEndOfGame(string GUID) {
F32 gameEXP, final, gameTotal;
string currentGameEXP, myEXP, myEXP_encrypted, finalEncrypt;
myEXP_encrypted = getEXP();
pgdCry.AESDecrypt(GUID, myEXP_encrypted, myEXP, 1000);
currentGameEXP = getCurrentEXP();
gameTotal = dAtof(currentGameEXP.c_str());
gameEXP = dAtof(myEXP.c_str());
// perform addition
final = gameEXP + gameTotal;
char stor[64];
//encrypt the new variable
itoa(final, stor, 10);
pgdCry.AESEncrypt(GUID, string(stor), finalEncrypt, 1000);
//finalEncrypt = stor;
applyEXP(finalEncrypt);
cleanCurrent();
return final;
}Running this code crashes my client with a runtime error, I've pinned it down to the AESEncrypt line, but the reason is for "Invalid Data", so I'm assuming it's the number conversion.
I'm not sure if itoa is the correct option here, or if there is a provided function that I should be using for string (or char[]/char *) -> F32 conversion.
Any ideas???
About the author
Illinois Grad. Retired T3D Developer / Pack Dev.
#2
I'm just stuck on going the other way (F32 -> String (or char[]/char *))
04/17/2011 (8:00 am)
I'm using dAtof when converting the stored string value into the F32 value.I'm just stuck on going the other way (F32 -> String (or char[]/char *))
#4
*EDIT*
I must be doing something wrong somewhere, I'm still getting access violations from this code.
"This applications runtime has unexpectedly requested this application to code", or whatever that error is.
*EDIT 2*
And figured that out *slaps self*, turns out I was sending the wrong string data to AES (hence the invalid data error), now it's not correctly keeping the number in the storage, I'll take a crack at that in a bit.
04/18/2011 (11:34 am)
Sure, I'll give that a shot and report back.*EDIT*
I must be doing something wrong somewhere, I'm still getting access violations from this code.
"This applications runtime has unexpectedly requested this application to code", or whatever that error is.
*EDIT 2*
And figured that out *slaps self*, turns out I was sending the wrong string data to AES (hence the invalid data error), now it's not correctly keeping the number in the storage, I'll take a crack at that in a bit.
#5
The number values are being correctly stored in ONE of the class string objects, however once I try to encrypt the stored number value and try to "store" it in another class string variable, it just completely refuses to do so and just keeps the value (null) in the string.
PGDStore.h
And my end of game function
for some unknown reason, it is just completely refusing to store encEXP, which to the function AESEncrypt, the third var is a "Reference" output variable, which should be storing the data in the string.
I have no idea what's wrong, and not sure what to do at this point.
here's my console output when calling the function
04/19/2011 (8:21 am)
Ok, now I'm just outright confused.The number values are being correctly stored in ONE of the class string objects, however once I try to encrypt the stored number value and try to "store" it in another class string variable, it just completely refuses to do so and just keeps the value (null) in the string.
PGDStore.h
#include <fstream>
#include <string>
#include "console/PGDCrypto/cryptoPackage.h" //PGD Crypto Lib
#include "console/console.h"
#include "console/consoleInternal.h"
#define PGD_CONTAINER_DEBUG 1
using namespace std;
#ifndef pgdstore_H
#define pgdstore_H
class PGDStore {
string currentEXP;
string encEXP;
string encOFF;
public:
void addCurrentEXP(const F32 add);
void promoteOFF(string encrypted);
string getEXP();
string getOFF();
string getCurrentEXP();
F32 handleEndOfGame(string GUID);
void cleanCurrent();
string packageStoreForUpload(CryptoPP::Integer e, CryptoPP::Integer n);
void loadStore(string encEXP, string encOFF);
void checkData();
static void create();
static void destroy();
protected:
PGDStore();
~PGDStore();
};
extern PGDStore *store;
#endifAnd my end of game function
F32 PGDStore::handleEndOfGame(string GUID) {
F32 gameEXP, final, gameTotal;
string currentGameEXP, myEXP, myEXP_encrypted;
myEXP_encrypted = getEXP();
if(myEXP_encrypted.compare("0") != 0) {
pgdCry.AESDecrypt(GUID, myEXP_encrypted, myEXP, 1000);
}
else {
myEXP = "0";
}
currentGameEXP = getCurrentEXP();
gameTotal = dAtof(currentGameEXP.c_str());
gameEXP = dAtof(myEXP.c_str());
// perform addition
final = gameEXP + gameTotal;
if(PGD_CONTAINER_DEBUG) {
Con::printf("MY EXP: %fnTotal: %fnNow Have: %f", gameEXP, gameTotal, final);
}
char stor[64];
//encrypt the new variable
dSprintf(stor, sizeof(stor), "%f", final);
pgdCry.AESEncrypt(GUID, string(stor), encEXP, 1000);
if(PGD_CONTAINER_DEBUG) {
Con::printf("applying EXP: %s", encEXP);
}
cleanCurrent();
return final;
}for some unknown reason, it is just completely refusing to store encEXP, which to the function AESEncrypt, the third var is a "Reference" output variable, which should be storing the data in the string.
I have no idea what's wrong, and not sure what to do at this point.
here's my console output when calling the function
==>2534.expGrantingAction("TEST", "");
*** CONTAINER DATA ***
CEXP: Â }
SEXP: (null)
SOFF: (null)
Current Game EXP: 30.000000
Adding This Number: 5.000000
Current Game EXP (after add): 30.000000
Buffer: 35.000000
Added Final: 35.000000.
gain 5
No Stored Player EXP, return 0
==>2534.declareCompletedGame();
GUID: 10000003
No Stored Player EXP, return 0
*** CONTAINER DATA ***
CEXP: Ã~ø
SEXP: (null)
SOFF: (null)
MY EXP: 0.000000
Total: 35.000000
Now Have: 35.000000
applying EXP: (null)
Torque 3D Owner Aun Taraseina