Number Storage Not Working?
by Robert Fritzen · in Technical Issues · 03/25/2011 (11:04 am) · 2 replies
Hello, I'm trying to finish up what's left in my Rank/Progression system, and I appear to have slammed into a giant brick wall here.
I have a class object which stores three variables, encryptedExperience, encryptedOfficer, and CurrentGameEXP, all of the std::string data type. When a player does an action that warrants experience game, the data is sent to the GameConnection Class, through a function. I then obtain the client's NetConnection and fork the necessary values over to that class and then use this code here:
This is the class object that should be handling the correct storage:
the value is correct in this function, I added an echo statement to the TS onGainExperience function to print out on the screen how much EXP is gained, and it runs fine. The problem begins here:
For some reason unknown, the value stored in getCurrentEXP is some insanely huge number, when it should be blank (I start it blank every game), which then should be setting off the reading function to have the value 0.
Then the very interesting part happens, it hits the printf line, and says the value in F32 add, is 0, yet it's printing correctly in the echo() statement.
I'm really close to finishing this, so any help would be greatly appreciated, if you need me to show any additional code, just ask. The cryptography functions are the same ones in my xxz568 resource if you need to see them, and they are functioning correctly.
I have a class object which stores three variables, encryptedExperience, encryptedOfficer, and CurrentGameEXP, all of the std::string data type. When a player does an action that warrants experience game, the data is sent to the GameConnection Class, through a function. I then obtain the client's NetConnection and fork the necessary values over to that class and then use this code here:
extern PGDStore store; //main object created in main.cpp
void NetConnection::handleEXPGain(F32 add) {
store.addCurrentEXP(add);
char buff[64];
ltoa(add, buff, 10);
Con::executef("onGainExperience", (const char *)buff);
}This is the class object that should be handling the correct storage:
#include <fstream>
#include <string>
#include "console/PGDCrypto/cryptoPackage.h" //PGD Crypto Lib
#include "platform/platform.h"
#include "console/console.h"
#include "console/consoleInternal.h"
#include "console/ast.h"
#include "core/resManager.h"
#include "core/stream/fileStream.h"
#include "console/compiler.h"
#include "platform/event.h"
#include "platform/platformInput.h"
#include "core/util/journal/journal.h"
using namespace std;
#ifndef pgdstore_H
#define pgdstore_H
class PGDStore {
public:
void addCurrentEXP(F32 add);
void applyEXP(string encrypted);
void applyOFF(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);
private:
string currentEXP;
string encEXP;
string encOFF;
};
#endifthe value is correct in this function, I added an echo statement to the TS onGainExperience function to print out on the screen how much EXP is gained, and it runs fine. The problem begins here:
void PGDStore::addCurrentEXP(F32 add) {
string dec_current = getCurrentEXP();
F32 my_game_exp = dAtof(dec_current.c_str());
F32 final = my_game_exp + add;
string encryptedFinal;
char buff[64];
dSprintf(buff, 64, "%i", final);
pgdCry.AESEncrypt(STRUCTURE_CE_ENCRYPTION_KEY, string(buff), encryptedFinal, 1000);
Con::printf("I Have Added %i EXP to your %i EXP, you now have %i (%s).", add, my_game_exp, final, buff);
currentEXP = encryptedFinal;
}
string PGDStore::getCurrentEXP() {
if(currentEXP.compare("") == 0) {
return "0";
}
string decryptedFinal;
pgdCry.AESDecrypt(STRUCTURE_CE_ENCRYPTION_KEY, currentEXP, decryptedFinal, 1000);
if(atoi(decryptedFinal.data()) < 0) {
currentEXP = "";
return "0";
}
return decryptedFinal;
}For some reason unknown, the value stored in getCurrentEXP is some insanely huge number, when it should be blank (I start it blank every game), which then should be setting off the reading function to have the value 0.
Then the very interesting part happens, it hits the printf line, and says the value in F32 add, is 0, yet it's printing correctly in the echo() statement.
I'm really close to finishing this, so any help would be greatly appreciated, if you need me to show any additional code, just ask. The cryptography functions are the same ones in my xxz568 resource if you need to see them, and they are functioning correctly.
About the author
Illinois Grad. Retired T3D Developer / Pack Dev.
#2
the TEST data gives 1 EXP per call, the problem comes into play when trying to add the two numbers, they are just completely refusing to do so, and thus the encryption is screwing up, and even crashing my client at times.
here is a sample of the stored data in the container after using the code
Am I missing something when it comes to working with the F32 Class???
04/12/2011 (8:58 am)
Another update, with some debug outputs nowvoid PGDStore::addCurrentEXP(const F32 add) {
string dec_current = getCurrentEXP();
const F32 my_game_exp = dAtof(dec_current.data());
if(PGD_CONTAINER_DEBUG)
Con::printf("Current Game EXP: %i", my_game_exp);
const F32 final = my_game_exp + add;
if(PGD_CONTAINER_DEBUG)
Con::printf("Current Game EXP (after add): %i", my_game_exp);
char buff[64];
//dSprintf(buff, 64, "%i", final);
itoa(add, buff, 10);
//using a sample key
pgdCry.AESEncrypt("StoredEXP", string(buff), currentEXP, 1000);
if(PGD_CONTAINER_DEBUG) {
Con::printf("Buffer: %s", buff);
Con::printf("Added Final: %i.", final);
}
}the TEST data gives 1 EXP per call, the problem comes into play when trying to add the two numbers, they are just completely refusing to do so, and thus the encryption is screwing up, and even crashing my client at times.
==>2540.EXPGrantingAction("TEST", "");
No Stored Current EXP, return 0
Current Game EXP: 0
Current Game EXP (after add): 0
Buffer: 1
Added Final: 0.
gain 1
No Stored Player EXP, return 0here is a sample of the stored data in the container after using the code
*** CONTAINER DATA *** CEXP: 0 <--- This is the new stored value from above code SEXP: (null) SOFF: (null)
Am I missing something when it comes to working with the F32 Class???
Torque Owner Robert Fritzen
Phantom Games Development
Basically, I've changed it to use a pointer object w/ ::Create() function on game start up, however I'm still getting some very interesting numbers in my output.
mainLoop.cpp
#include "console/PGDCrypto/PGDStore.h" . . . void StandardMainLoop::init() { . . . PGDStore::create(); }PGDStore.cpp
PGDStore *store = NULL; void PGDStore::create() { store = new PGDStore; Con::printf("*Rank Storeage Container Initialized."); } //other code shown above unchanged.PGDStore.h
class PGDStore { public: void addCurrentEXP(F32 add); void applyEXP(string encrypted); void applyOFF(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); static void create(); private: string currentEXP; string encEXP; string encOFF; }; extern PGDStore *store; #endifI'm not sure if from this point it's an error in my C++ code, or I'm initializing/using it wrong. If you need anything else from this code let me know, I really want to get this fixed.