Skip to content

Commit

Permalink
add some defines to reduce usages of hardcoded r>>8
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob1 committed Dec 28, 2017
1 parent fbf7210 commit ac24810
Show file tree
Hide file tree
Showing 102 changed files with 632 additions and 627 deletions.
62 changes: 31 additions & 31 deletions src/client/Client.cpp
Expand Up @@ -97,7 +97,7 @@ Client::Client():
std::string SessionKey = preferences["User"]["SessionKey"].asString();
std::string Elevation = preferences["User"]["Elevation"].asString();

authUser.ID = ID;
authUser.UserID = ID;
authUser.Username = Username;
authUser.SessionID = SessionID;
authUser.SessionKey = SessionKey;
Expand Down Expand Up @@ -149,9 +149,9 @@ void Client::Initialise(std::string proxyString)
//Begin version check
versionCheckRequest = http_async_req_start(NULL, "http://" SERVER "/Startup.json", NULL, 0, 0);

if (authUser.ID)
if (authUser.UserID)
{
std::string idTempString = format::NumberToString<int>(authUser.ID);
std::string idTempString = format::NumberToString<int>(authUser.UserID);
char *id = new char[idTempString.length() + 1];
std::strcpy (id, idTempString.c_str());
char *session = new char[authUser.SessionID.length() + 1];
Expand Down Expand Up @@ -945,9 +945,9 @@ void Client::WritePrefs()

if (configFile)
{
if (authUser.ID)
if (authUser.UserID)
{
preferences["User"]["ID"] = authUser.ID;
preferences["User"]["ID"] = authUser.UserID;
preferences["User"]["SessionID"] = authUser.SessionID;
preferences["User"]["SessionKey"] = authUser.SessionKey;
preferences["User"]["Username"] = authUser.Username;
Expand Down Expand Up @@ -1003,8 +1003,8 @@ RequestStatus Client::UploadSave(SaveInfo & save)
char * data;
int dataLength = 0;
std::stringstream userIDStream;
userIDStream << authUser.ID;
if (authUser.ID)
userIDStream << authUser.UserID;
if (authUser.UserID)
{
if (!save.GetGameSave())
{
Expand Down Expand Up @@ -1244,11 +1244,11 @@ RequestStatus Client::ExecVote(int saveID, int direction)
char * data;
int dataLength = 0;

if (authUser.ID)
if (authUser.UserID)
{
char * directionText = (char*)(direction==1?"Up":"Down");
std::string saveIDText = format::NumberToString<int>(saveID);
std::string userIDText = format::NumberToString<int>(authUser.ID);
std::string userIDText = format::NumberToString<int>(authUser.UserID);

char *id = new char[saveIDText.length() + 1];
std::strcpy(id, saveIDText.c_str());
Expand Down Expand Up @@ -1399,7 +1399,7 @@ LoginStatus Client::Login(std::string username, std::string password, User & use
char passwordHash[33];
char totalHash[33];

user.ID = 0;
user.UserID = 0;
user.Username = "";
user.SessionID = "";
user.SessionKey = "";
Expand Down Expand Up @@ -1443,7 +1443,7 @@ LoginStatus Client::Login(std::string username, std::string password, User & use
}

user.Username = username;
user.ID = userIDTemp;
user.UserID = userIDTemp;
user.SessionID = sessionIDTemp;
user.SessionKey = sessionKeyTemp;
std::string userElevation = userElevationTemp;
Expand Down Expand Up @@ -1472,10 +1472,10 @@ RequestStatus Client::DeleteSave(int saveID)
char * data = NULL;
int dataStatus, dataLength;
urlStream << "http://" << SERVER << "/Browse/Delete.json?ID=" << saveID << "&Mode=Delete&Key=" << authUser.SessionKey;
if(authUser.ID)
if(authUser.UserID)
{
std::stringstream userIDStream;
userIDStream << authUser.ID;
userIDStream << authUser.UserID;
data = http_auth_get((char *)urlStream.str().c_str(), (char *)(userIDStream.str().c_str()), NULL, (char *)(authUser.SessionID.c_str()), &dataStatus, &dataLength);
}
else
Expand All @@ -1495,10 +1495,10 @@ RequestStatus Client::AddComment(int saveID, std::string comment)
char * data = NULL;
int dataStatus, dataLength;
urlStream << "http://" << SERVER << "/Browse/Comments.json?ID=" << saveID;
if(authUser.ID)
if(authUser.UserID)
{
std::stringstream userIDStream;
userIDStream << authUser.ID;
userIDStream << authUser.UserID;

const char *const postNames[] = { "Comment", NULL };
const char *const postDatas[] = { (char*)(comment.c_str()) };
Expand All @@ -1524,10 +1524,10 @@ RequestStatus Client::FavouriteSave(int saveID, bool favourite)
urlStream << "http://" << SERVER << "/Browse/Favourite.json?ID=" << saveID << "&Key=" << authUser.SessionKey;
if(!favourite)
urlStream << "&Mode=Remove";
if(authUser.ID)
if(authUser.UserID)
{
std::stringstream userIDStream;
userIDStream << authUser.ID;
userIDStream << authUser.UserID;
data = http_auth_get((char *)urlStream.str().c_str(), (char *)(userIDStream.str().c_str()), NULL, (char *)(authUser.SessionID.c_str()), &dataStatus, &dataLength);
}
else
Expand All @@ -1547,10 +1547,10 @@ RequestStatus Client::ReportSave(int saveID, std::string message)
char * data = NULL;
int dataStatus, dataLength;
urlStream << "http://" << SERVER << "/Browse/Report.json?ID=" << saveID << "&Key=" << authUser.SessionKey;
if(authUser.ID)
if(authUser.UserID)
{
std::stringstream userIDStream;
userIDStream << authUser.ID;
userIDStream << authUser.UserID;

const char *const postNames[] = { "Reason", NULL };
const char *const postDatas[] = { (char*)(message.c_str()) };
Expand All @@ -1574,10 +1574,10 @@ RequestStatus Client::UnpublishSave(int saveID)
char * data = NULL;
int dataStatus, dataLength;
urlStream << "http://" << SERVER << "/Browse/Delete.json?ID=" << saveID << "&Mode=Unpublish&Key=" << authUser.SessionKey;
if(authUser.ID)
if(authUser.UserID)
{
std::stringstream userIDStream;
userIDStream << authUser.ID;
userIDStream << authUser.UserID;
data = http_auth_get((char *)urlStream.str().c_str(), (char *)(userIDStream.str().c_str()), NULL, (char *)(authUser.SessionID.c_str()), &dataStatus, &dataLength);
}
else
Expand All @@ -1597,10 +1597,10 @@ RequestStatus Client::PublishSave(int saveID)
char *data;
int dataStatus;
urlStream << "http://" << SERVER << "/Browse/View.json?ID=" << saveID << "&Key=" << authUser.SessionKey;
if (authUser.ID)
if (authUser.UserID)
{
std::stringstream userIDStream;
userIDStream << authUser.ID;
userIDStream << authUser.UserID;
const char *const postNames[] = { "ActionPublish", NULL };
const char *const postDatas[] = { "" };
size_t postLengths[] = { 1 };
Expand All @@ -1626,10 +1626,10 @@ SaveInfo * Client::GetSave(int saveID, int saveDate)
}
char * data;
int dataStatus, dataLength;
if(authUser.ID)
if(authUser.UserID)
{
std::stringstream userIDStream;
userIDStream << authUser.ID;
userIDStream << authUser.UserID;
data = http_auth_get((char *)urlStream.str().c_str(), (char *)(userIDStream.str().c_str()), NULL, (char *)(authUser.SessionID.c_str()), &dataStatus, &dataLength);
}
else
Expand Down Expand Up @@ -1866,10 +1866,10 @@ std::vector<SaveInfo*> * Client::SearchSaves(int start, int count, std::string q
{
urlStream << "&Category=" << format::URLEncode(category);
}
if(authUser.ID)
if(authUser.UserID)
{
std::stringstream userIDStream;
userIDStream << authUser.ID;
userIDStream << authUser.UserID;
data = http_auth_get((char *)urlStream.str().c_str(), (char *)(userIDStream.str().c_str()), NULL, (char *)(authUser.SessionID.c_str()), &dataStatus, &dataLength);
}
else
Expand Down Expand Up @@ -1935,10 +1935,10 @@ std::list<std::string> * Client::RemoveTag(int saveID, std::string tag)
char * data = NULL;
int dataStatus, dataLength;
urlStream << "http://" << SERVER << "/Browse/EditTag.json?Op=delete&ID=" << saveID << "&Tag=" << tag << "&Key=" << authUser.SessionKey;
if(authUser.ID)
if(authUser.UserID)
{
std::stringstream userIDStream;
userIDStream << authUser.ID;
userIDStream << authUser.UserID;
data = http_auth_get((char *)urlStream.str().c_str(), (char *)(userIDStream.str().c_str()), NULL, (char *)(authUser.SessionID.c_str()), &dataStatus, &dataLength);
}
else
Expand Down Expand Up @@ -1977,10 +1977,10 @@ std::list<std::string> * Client::AddTag(int saveID, std::string tag)
char * data = NULL;
int dataStatus, dataLength;
urlStream << "http://" << SERVER << "/Browse/EditTag.json?Op=add&ID=" << saveID << "&Tag=" << tag << "&Key=" << authUser.SessionKey;
if(authUser.ID)
if(authUser.UserID)
{
std::stringstream userIDStream;
userIDStream << authUser.ID;
userIDStream << authUser.UserID;
data = http_auth_get((char *)urlStream.str().c_str(), (char *)(userIDStream.str().c_str()), NULL, (char *)(authUser.SessionID.c_str()), &dataStatus, &dataLength);
}
else
Expand Down
4 changes: 2 additions & 2 deletions src/client/User.h
Expand Up @@ -11,13 +11,13 @@ class User
{
ElevationAdmin, ElevationModerator, ElevationNone
};
int ID;
int UserID;
std::string Username;
std::string SessionID;
std::string SessionKey;
Elevation UserElevation;
User(int id, std::string username):
ID(id),
UserID(id),
Username(username),
SessionID(""),
SessionKey(""),
Expand Down
4 changes: 2 additions & 2 deletions src/client/UserInfo.h
Expand Up @@ -6,7 +6,7 @@
class UserInfo
{
public:
int ID;
int UserID;
int age;
std::string username;
std::string biography;
Expand All @@ -22,7 +22,7 @@ class UserInfo
int reputation;

UserInfo(int id, int age, std::string username, std::string biography, std::string location, std::string website, int saveCount, float averageScore, int highestScore, int topicCount, int topicReplies, int reputation):
ID(id),
UserID(id),
age(age),
username(username),
biography(biography),
Expand Down
8 changes: 4 additions & 4 deletions src/client/requestbroker/APIRequest.cpp
Expand Up @@ -98,12 +98,12 @@ RequestBroker::ProcessResponse APIRequest::Process(RequestBroker & rb)
}
postNames[i] = NULL;

if(Client::Ref().GetAuthUser().ID)
if(Client::Ref().GetAuthUser().UserID)
{
User user = Client::Ref().GetAuthUser();
char userName[12];
char *userSession = new char[user.SessionID.length() + 1];
std::strcpy(userName, format::NumberToString<int>(user.ID).c_str());
std::strcpy(userName, format::NumberToString<int>(user.UserID).c_str());
std::strcpy(userSession, user.SessionID.c_str());
HTTPContext = http_multipart_post_async((char*)URL.c_str(), postNames, postData, postLength, userName, NULL, userSession);
delete[] userSession;
Expand All @@ -117,12 +117,12 @@ RequestBroker::ProcessResponse APIRequest::Process(RequestBroker & rb)
else
{
HTTPContext = http_async_req_start(NULL, (char *)URL.c_str(), NULL, 0, 0);
if(Client::Ref().GetAuthUser().ID)
if(Client::Ref().GetAuthUser().UserID)
{
User user = Client::Ref().GetAuthUser();
char userName[12];
char *userSession = new char[user.SessionID.length() + 1];
std::strcpy(userName, format::NumberToString<int>(user.ID).c_str());
std::strcpy(userName, format::NumberToString<int>(user.UserID).c_str());
std::strcpy(userSession, user.SessionID.c_str());
http_auth_headers(HTTPContext, userName, NULL, userSession);
delete[] userSession;
Expand Down
8 changes: 4 additions & 4 deletions src/client/requestbroker/WebRequest.cpp
Expand Up @@ -98,15 +98,15 @@ RequestBroker::ProcessResponse WebRequest::Process(RequestBroker & rb)
}
postNames[i] = NULL;

if(Client::Ref().GetAuthUser().ID)
if(Client::Ref().GetAuthUser().UserID)
{
#ifdef DEBUG
std::cout << typeid(*this).name() << " Authenticated " << std::endl;
#endif
User user = Client::Ref().GetAuthUser();
char userName[12];
char *userSession = new char[user.SessionID.length() + 1];
std::strcpy(userName, format::NumberToString<int>(user.ID).c_str());
std::strcpy(userName, format::NumberToString<int>(user.UserID).c_str());
std::strcpy(userSession, user.SessionID.c_str());
HTTPContext = http_multipart_post_async((char*)URL.c_str(), postNames, postData, postLength, userName, NULL, userSession);
delete[] userSession;
Expand All @@ -120,12 +120,12 @@ RequestBroker::ProcessResponse WebRequest::Process(RequestBroker & rb)
else
{
HTTPContext = http_async_req_start(NULL, (char *)URL.c_str(), NULL, 0, 0);
if(Client::Ref().GetAuthUser().ID)
if(Client::Ref().GetAuthUser().UserID)
{
User user = Client::Ref().GetAuthUser();
char userName[12];
char *userSession = new char[user.SessionID.length() + 1];
std::strcpy(userName, format::NumberToString<int>(user.ID).c_str());
std::strcpy(userName, format::NumberToString<int>(user.UserID).c_str());
std::strcpy(userSession, user.SessionID.c_str());
http_auth_headers(HTTPContext, userName, NULL, userSession);
delete[] userSession;
Expand Down
4 changes: 2 additions & 2 deletions src/debug/DebugInfo.h
Expand Up @@ -6,9 +6,9 @@
class DebugInfo
{
public:
DebugInfo(unsigned int id):ID(id) { }
DebugInfo(unsigned int id):debugID(id) { }
virtual ~DebugInfo() { }
unsigned int ID;
unsigned int debugID;
virtual void Draw() {}
// currentMouse doesn't belong but I don't want to create more hooks at the moment
virtual bool KeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt, ui::Point currentMouse) { return true; }
Expand Down
14 changes: 7 additions & 7 deletions src/gui/game/GameController.cpp
Expand Up @@ -775,7 +775,7 @@ bool GameController::KeyPress(int key, Uint16 character, bool shift, bool ctrl,

for(std::vector<DebugInfo*>::iterator iter = debugInfo.begin(), end = debugInfo.end(); iter != end; iter++)
{
if ((*iter)->ID & debugFlags)
if ((*iter)->debugID & debugFlags)
if (!(*iter)->KeyPress(key, character, shift, ctrl, alt, gameView->GetMousePosition()))
ret = false;
}
Expand Down Expand Up @@ -842,7 +842,7 @@ void GameController::Tick()
}
for(std::vector<DebugInfo*>::iterator iter = debugInfo.begin(), end = debugInfo.end(); iter != end; iter++)
{
if ((*iter)->ID & debugFlags)
if ((*iter)->debugID & debugFlags)
(*iter)->Draw();
}
commandInterface->OnTick();
Expand Down Expand Up @@ -1301,7 +1301,7 @@ void GameController::OpenLogin()

void GameController::OpenProfile()
{
if(Client::Ref().GetAuthUser().ID)
if(Client::Ref().GetAuthUser().UserID)
{
new ProfileActivity(Client::Ref().GetAuthUser().Username);
}
Expand Down Expand Up @@ -1408,7 +1408,7 @@ void GameController::OpenSaveWindow()
c->LoadSave(&save);
}
};
if(gameModel->GetUser().ID)
if(gameModel->GetUser().UserID)
{
Simulation * sim = gameModel->GetSimulation();
GameSave * gameSave = sim->Save();
Expand Down Expand Up @@ -1455,7 +1455,7 @@ void GameController::SaveAsCurrent()
}
};

if(gameModel->GetSave() && gameModel->GetUser().ID && gameModel->GetUser().Username == gameModel->GetSave()->GetUserName())
if(gameModel->GetSave() && gameModel->GetUser().UserID && gameModel->GetUser().Username == gameModel->GetSave()->GetUserName())
{
Simulation * sim = gameModel->GetSimulation();
GameSave * gameSave = sim->Save();
Expand All @@ -1481,7 +1481,7 @@ void GameController::SaveAsCurrent()
}
}
}
else if(gameModel->GetUser().ID)
else if(gameModel->GetUser().UserID)
{
OpenSaveWindow();
}
Expand All @@ -1499,7 +1499,7 @@ void GameController::FrameStep()

void GameController::Vote(int direction)
{
if(gameModel->GetSave() && gameModel->GetUser().ID && gameModel->GetSave()->GetID() && gameModel->GetSave()->GetVote()==0)
if(gameModel->GetSave() && gameModel->GetUser().UserID && gameModel->GetSave()->GetID() && gameModel->GetSave()->GetVote()==0)
{
try
{
Expand Down
2 changes: 1 addition & 1 deletion src/gui/game/GameModel.cpp
Expand Up @@ -92,7 +92,7 @@ GameModel::GameModel():
Favorite::Ref().LoadFavoritesFromPrefs();

//Load last user
if(Client::Ref().GetAuthUser().ID)
if(Client::Ref().GetAuthUser().UserID)
{
currentUser = Client::Ref().GetAuthUser();
}
Expand Down

0 comments on commit ac24810

Please sign in to comment.