Permalink
Browse files

add some defines to reduce usages of hardcoded r>>8

  • Loading branch information...
jacob1 committed Dec 28, 2017
1 parent fbf7210 commit ac24810da51db8056744ab57756adc71e5caa0b1
Showing with 632 additions and 627 deletions.
  1. +31 −31 src/client/Client.cpp
  2. +2 −2 src/client/User.h
  3. +2 −2 src/client/UserInfo.h
  4. +4 −4 src/client/requestbroker/APIRequest.cpp
  5. +4 −4 src/client/requestbroker/WebRequest.cpp
  6. +2 −2 src/debug/DebugInfo.h
  7. +7 −7 src/gui/game/GameController.cpp
  8. +1 −1 src/gui/game/GameModel.cpp
  9. +8 −8 src/gui/game/GameView.cpp
  10. +4 −4 src/gui/preview/PreviewController.cpp
  11. +3 −3 src/gui/preview/PreviewModel.cpp
  12. +5 −5 src/gui/preview/PreviewView.cpp
  13. +1 −1 src/gui/profile/ProfileActivity.cpp
  14. +3 −3 src/gui/search/SearchController.cpp
  15. +1 −1 src/gui/search/SearchModel.cpp
  16. +4 −4 src/gui/search/SearchView.cpp
  17. +1 −1 src/gui/tags/TagsView.cpp
  18. +1 −1 src/lua/LegacyLuaAPI.cpp
  19. +5 −0 src/simulation/SimulationData.h
  20. +2 −2 src/simulation/elements/ACEL.cpp
  21. +9 −9 src/simulation/elements/ACID.cpp
  22. +2 −2 src/simulation/elements/AMTR.cpp
  23. +1 −1 src/simulation/elements/ANAR.cpp
  24. +4 −4 src/simulation/elements/ARAY.cpp
  25. +1 −1 src/simulation/elements/BCLN.cpp
  26. +5 −5 src/simulation/elements/BIZR.cpp
  27. +2 −2 src/simulation/elements/BMTL.cpp
  28. +2 −2 src/simulation/elements/BOYL.cpp
  29. +3 −3 src/simulation/elements/BRMT.cpp
  30. +5 −5 src/simulation/elements/BTRY.cpp
  31. +2 −2 src/simulation/elements/C5.cpp
  32. +3 −3 src/simulation/elements/CAUS.cpp
  33. +9 −9 src/simulation/elements/CBNW.cpp
  34. +1 −1 src/simulation/elements/CLNE.cpp
  35. +2 −2 src/simulation/elements/CLST.cpp
  36. +2 −2 src/simulation/elements/CO2.cpp
  37. +2 −2 src/simulation/elements/CONV.cpp
  38. +10 −10 src/simulation/elements/CRAY.cpp
  39. +2 −2 src/simulation/elements/DCEL.cpp
  40. +5 −5 src/simulation/elements/DEST.cpp
  41. +7 −7 src/simulation/elements/DEUT.cpp
  42. +9 −9 src/simulation/elements/DLAY.cpp
  43. +3 −3 src/simulation/elements/DRAY.cpp
  44. +2 −2 src/simulation/elements/DSTW.cpp
  45. +9 −9 src/simulation/elements/DTEC.cpp
  46. +12 −12 src/simulation/elements/ELEC.cpp
  47. +2 −2 src/simulation/elements/ETRD.cpp
  48. +10 −10 src/simulation/elements/EXOT.cpp
  49. +4 −4 src/simulation/elements/Element.cpp
  50. +28 −28 src/simulation/elements/FIRE.cpp
  51. +2 −2 src/simulation/elements/FRAY.cpp
  52. +1 −1 src/simulation/elements/FRZW.cpp
  53. +2 −2 src/simulation/elements/FRZZ.cpp
  54. +15 −15 src/simulation/elements/GEL.cpp
  55. +2 −2 src/simulation/elements/GLOW.cpp
  56. +4 −4 src/simulation/elements/GOLD.cpp
  57. +3 −3 src/simulation/elements/GPMP.cpp
  58. +7 −7 src/simulation/elements/H2.cpp
  59. +8 −8 src/simulation/elements/HEAC.cpp
  60. +4 −4 src/simulation/elements/HSWC.cpp
  61. +3 −3 src/simulation/elements/ICEI.cpp
  62. +1 −1 src/simulation/elements/IGNT.cpp
  63. +2 −2 src/simulation/elements/LCRY.cpp
  64. +24 −24 src/simulation/elements/LIGH.cpp
  65. +6 −6 src/simulation/elements/LSNS.cpp
  66. +7 −7 src/simulation/elements/MERC.cpp
  67. +32 −32 src/simulation/elements/NEUT.cpp
  68. +5 −5 src/simulation/elements/O2.cpp
  69. +4 −4 src/simulation/elements/PBCN.cpp
  70. +6 −6 src/simulation/elements/PCLN.cpp
  71. +4 −4 src/simulation/elements/PHOT.cpp
  72. +27 −27 src/simulation/elements/PIPE.cpp
  73. +2 −2 src/simulation/elements/PLNT.cpp
  74. +6 −6 src/simulation/elements/POLO.cpp
  75. +6 −6 src/simulation/elements/PRTI.cpp
  76. +5 −5 src/simulation/elements/PSNS.cpp
  77. +6 −6 src/simulation/elements/PSTN.cpp
  78. +3 −3 src/simulation/elements/PUMP.cpp
  79. +5 −5 src/simulation/elements/PVOD.cpp
  80. +5 −5 src/simulation/elements/QRTZ.cpp
  81. +2 −2 src/simulation/elements/RIME.cpp
  82. +3 −3 src/simulation/elements/RPEL.cpp
  83. +2 −2 src/simulation/elements/SHLD3.cpp
  84. +2 −2 src/simulation/elements/SHLD4.cpp
  85. +7 −7 src/simulation/elements/SING.cpp
  86. +4 −4 src/simulation/elements/SLTW.cpp
  87. +1 −1 src/simulation/elements/SNOW.cpp
  88. +23 −23 src/simulation/elements/SOAP.cpp
  89. +13 −13 src/simulation/elements/SPNG.cpp
  90. +39 −39 src/simulation/elements/SPRK.cpp
  91. +11 −11 src/simulation/elements/STKM.cpp
  92. +9 −9 src/simulation/elements/STOR.cpp
  93. +5 −5 src/simulation/elements/SWCH.cpp
  94. +4 −4 src/simulation/elements/THDR.cpp
  95. +2 −2 src/simulation/elements/TRON.cpp
  96. +8 −8 src/simulation/elements/TSNS.cpp
  97. +12 −12 src/simulation/elements/VIBR.cpp
  98. +12 −12 src/simulation/elements/VIRS.cpp
  99. +6 −6 src/simulation/elements/WARP.cpp
  100. +4 −4 src/simulation/elements/WATR.cpp
  101. +5 −5 src/simulation/elements/WIFI.cpp
  102. +2 −2 src/simulation/elements/WIRE.cpp
@@ -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;
@@ -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];
@@ -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;
@@ -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())
{
@@ -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());
@@ -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 = "";
@@ -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;
@@ -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
@@ -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()) };
@@ -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
@@ -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()) };
@@ -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
@@ -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 };
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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(""),
@@ -6,7 +6,7 @@
class UserInfo
{
public:
int ID;
int UserID;
int age;
std::string username;
std::string biography;
@@ -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),
@@ -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;
@@ -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;
@@ -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;
@@ -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;
@@ -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; }
@@ -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;
}
@@ -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();
@@ -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);
}
@@ -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();
@@ -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();
@@ -1481,7 +1481,7 @@ void GameController::SaveAsCurrent()
}
}
}
else if(gameModel->GetUser().ID)
else if(gameModel->GetUser().UserID)
{
OpenSaveWindow();
}
@@ -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
{
@@ -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();
}
Oops, something went wrong.

0 comments on commit ac24810

Please sign in to comment.