mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-09-01 12:02:40 +02:00
fix stamp thumbnails not showing until you move the mouse, add a few new[]'s replacing some .c_str() pointers in client.cpp
This commit is contained in:
@@ -121,7 +121,12 @@ void Client::Initialise(std::string proxyString)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(proxyString.length())
|
if(proxyString.length())
|
||||||
http_init((char*)proxyString.c_str());
|
{
|
||||||
|
char *proxy = new char[proxyString.length() + 1];
|
||||||
|
std::strcpy (proxy, proxyString.c_str());
|
||||||
|
http_init(proxy);
|
||||||
|
delete[] proxy;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
http_init(NULL);
|
http_init(NULL);
|
||||||
|
|
||||||
@@ -144,7 +149,14 @@ void Client::Initialise(std::string proxyString)
|
|||||||
|
|
||||||
if(authUser.ID)
|
if(authUser.ID)
|
||||||
{
|
{
|
||||||
http_auth_headers(versionCheckRequest, (char *)format::NumberToString<int>(authUser.ID).c_str(), NULL, (char *)authUser.SessionID.c_str());
|
std::string idTempString = format::NumberToString<int>(authUser.ID);
|
||||||
|
char *id = new char[idTempString.length() + 1];
|
||||||
|
std::strcpy (id, idTempString.c_str());
|
||||||
|
char *session = new char[authUser.SessionID.length() + 1];
|
||||||
|
std::strcpy (session, authUser.SessionID.c_str());
|
||||||
|
http_auth_headers(versionCheckRequest, id, NULL, session);
|
||||||
|
delete[] id;
|
||||||
|
delete[] session;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -404,7 +416,12 @@ void Client::SetProxy(std::string proxy)
|
|||||||
{
|
{
|
||||||
http_done();
|
http_done();
|
||||||
if(proxy.length())
|
if(proxy.length())
|
||||||
http_init((char*)proxy.c_str());
|
{
|
||||||
|
char *tempproxy = new char[proxy.length() + 1];
|
||||||
|
std::strcpy (tempproxy, proxy.c_str());
|
||||||
|
http_init(tempproxy);
|
||||||
|
delete[] tempproxy;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
http_init(NULL);
|
http_init(NULL);
|
||||||
}
|
}
|
||||||
@@ -861,18 +878,24 @@ RequestStatus Client::UploadSave(SaveInfo & save)
|
|||||||
}
|
}
|
||||||
|
|
||||||
char *saveName = new char[save.GetName().length() + 1];
|
char *saveName = new char[save.GetName().length() + 1];
|
||||||
std::strcpy ( saveName, save.GetName().c_str() );
|
std::strcpy (saveName, save.GetName().c_str());
|
||||||
char *saveDescription = new char[save.GetDescription().length() + 1];
|
char *saveDescription = new char[save.GetDescription().length() + 1];
|
||||||
std::strcpy ( saveDescription, save.GetDescription().c_str() );
|
std::strcpy (saveDescription, save.GetDescription().c_str());
|
||||||
|
char *userid = new char[userIDStream.str().length() + 1];
|
||||||
|
std::strcpy (userid, userIDStream.str().c_str());
|
||||||
|
char *session = new char[authUser.SessionID.length() + 1];
|
||||||
|
std::strcpy (session, authUser.SessionID.c_str());
|
||||||
|
|
||||||
char * postNames[] = { "Name", "Description", "Data:save.bin", "Publish", NULL };
|
char * postNames[] = { "Name", "Description", "Data:save.bin", "Publish", NULL };
|
||||||
char * postDatas[] = { saveName, saveDescription, gameData, (char *)(save.GetPublished()?"Public":"Private") };
|
char * postDatas[] = { saveName, saveDescription, gameData, (char *)(save.GetPublished()?"Public":"Private") };
|
||||||
int postLengths[] = { save.GetName().length(), save.GetDescription().length(), gameDataLength, save.GetPublished()?6:7 };
|
int postLengths[] = { save.GetName().length(), save.GetDescription().length(), gameDataLength, save.GetPublished()?6:7 };
|
||||||
//std::cout << postNames[0] << " " << postDatas[0] << " " << postLengths[0] << std::endl;
|
//std::cout << postNames[0] << " " << postDatas[0] << " " << postLengths[0] << std::endl;
|
||||||
data = http_multipart_post("http://" SERVER "/Save.api", postNames, postDatas, postLengths, (char *)(userIDStream.str().c_str()), NULL, (char *)(authUser.SessionID.c_str()), &dataStatus, &dataLength);
|
data = http_multipart_post("http://" SERVER "/Save.api", postNames, postDatas, postLengths, userid, NULL, session, &dataStatus, &dataLength);
|
||||||
|
|
||||||
delete[] saveDescription;
|
delete[] saveDescription;
|
||||||
delete[] saveName;
|
delete[] saveName;
|
||||||
|
delete[] userid;
|
||||||
|
delete[] session;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -1075,17 +1098,28 @@ RequestStatus Client::ExecVote(int saveID, int direction)
|
|||||||
std::stringstream idStream;
|
std::stringstream idStream;
|
||||||
idStream << saveID;
|
idStream << saveID;
|
||||||
|
|
||||||
std::string saveIDText = format::NumberToString<int>(saveID);
|
|
||||||
std::string directionText = direction==1?"Up":"Down";
|
|
||||||
|
|
||||||
std::string userIDText = format::NumberToString<int>(authUser.ID);
|
|
||||||
if(authUser.ID)
|
if(authUser.ID)
|
||||||
{
|
{
|
||||||
|
char * directionText = direction==1?"Up":"Down";
|
||||||
|
std::string saveIDText = format::NumberToString<int>(saveID);
|
||||||
|
std::string userIDText = format::NumberToString<int>(authUser.ID);
|
||||||
|
|
||||||
|
char *id = new char[saveIDText.length() + 1];
|
||||||
|
std::strcpy (id, saveIDText.c_str());
|
||||||
|
char *userid = new char[userIDText.length() + 1];
|
||||||
|
std::strcpy (userid, userIDText.c_str());
|
||||||
|
char *session = new char[authUser.SessionID.length() + 1];
|
||||||
|
std::strcpy (session, authUser.SessionID.c_str());
|
||||||
|
|
||||||
char * postNames[] = { "ID", "Action", NULL };
|
char * postNames[] = { "ID", "Action", NULL };
|
||||||
char * postDatas[] = { (char*)(saveIDText.c_str()), (char*)(directionText.c_str()) };
|
char * postDatas[] = { id, directionText };
|
||||||
int postLengths[] = { saveIDText.length(), directionText.length() };
|
int postLengths[] = { saveIDText.length(), strlen(directionText) };
|
||||||
//std::cout << postNames[0] << " " << postDatas[0] << " " << postLengths[0] << std::endl;
|
//std::cout << postNames[0] << " " << postDatas[0] << " " << postLengths[0] << std::endl;
|
||||||
data = http_multipart_post("http://" SERVER "/Vote.api", postNames, postDatas, postLengths, (char *)(userIDText.c_str()), NULL, (char *)(authUser.SessionID.c_str()), &dataStatus, &dataLength);
|
data = http_multipart_post("http://" SERVER "/Vote.api", postNames, postDatas, postLengths, userid, NULL, session, &dataStatus, &dataLength);
|
||||||
|
|
||||||
|
delete[] id;
|
||||||
|
delete[] userid;
|
||||||
|
delete[] session;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -1127,7 +1161,11 @@ unsigned char * Client::GetSaveData(int saveID, int saveDate, int & dataLength)
|
|||||||
urlStream << "http://" << STATICSERVER << "/" << saveID << ".cps";
|
urlStream << "http://" << STATICSERVER << "/" << saveID << ".cps";
|
||||||
}
|
}
|
||||||
|
|
||||||
data = (unsigned char *)http_simple_get((char *)urlStream.str().c_str(), &dataStatus, &dataLength);
|
char *url = new char[urlStream.str().length() + 1];
|
||||||
|
std::strcpy (url, urlStream.str().c_str());
|
||||||
|
data = (unsigned char *)http_simple_get(url, &dataStatus, &dataLength);
|
||||||
|
delete[] url;
|
||||||
|
|
||||||
if(data && dataStatus == 200)
|
if(data && dataStatus == 200)
|
||||||
{
|
{
|
||||||
return data;
|
return data;
|
||||||
|
@@ -1038,21 +1038,20 @@ void GameView::OnMouseUp(int x, int y, unsigned button)
|
|||||||
{
|
{
|
||||||
if(selectMode==PlaceSave)
|
if(selectMode==PlaceSave)
|
||||||
{
|
{
|
||||||
Thumbnail * tempThumb = placeSaveThumb;
|
if(placeSaveThumb)
|
||||||
if(tempThumb)
|
|
||||||
{
|
{
|
||||||
int thumbX = selectPoint2.X - (tempThumb->Size.X/2);
|
int thumbX = selectPoint2.X - (placeSaveThumb->Size.X/2);
|
||||||
int thumbY = selectPoint2.Y - (tempThumb->Size.Y/2);
|
int thumbY = selectPoint2.Y - (placeSaveThumb->Size.Y/2);
|
||||||
|
|
||||||
if(thumbX<0)
|
if(thumbX<0)
|
||||||
thumbX = 0;
|
thumbX = 0;
|
||||||
if(thumbX+(tempThumb->Size.X)>=XRES)
|
if(thumbX+(placeSaveThumb->Size.X)>=XRES)
|
||||||
thumbX = XRES-tempThumb->Size.X;
|
thumbX = XRES-placeSaveThumb->Size.X;
|
||||||
|
|
||||||
if(thumbY<0)
|
if(thumbY<0)
|
||||||
thumbY = 0;
|
thumbY = 0;
|
||||||
if(thumbY+(tempThumb->Size.Y)>=YRES)
|
if(thumbY+(placeSaveThumb->Size.Y)>=YRES)
|
||||||
thumbY = YRES-tempThumb->Size.Y;
|
thumbY = YRES-placeSaveThumb->Size.Y;
|
||||||
|
|
||||||
c->PlaceSave(ui::Point(thumbX, thumbY));
|
c->PlaceSave(ui::Point(thumbX, thumbY));
|
||||||
}
|
}
|
||||||
@@ -1388,13 +1387,13 @@ void GameView::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool
|
|||||||
if(ctrl)
|
if(ctrl)
|
||||||
{
|
{
|
||||||
c->LoadClipboard();
|
c->LoadClipboard();
|
||||||
selectPoint2 = ui::Point(-1, -1);
|
selectPoint2 = mousePosition;
|
||||||
selectPoint1 = selectPoint2;
|
selectPoint1 = selectPoint2;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'l':
|
case 'l':
|
||||||
c->LoadStamp();
|
c->LoadStamp();
|
||||||
selectPoint2 = ui::Point(-1, -1);
|
selectPoint2 = mousePosition;
|
||||||
selectPoint1 = selectPoint2;
|
selectPoint1 = selectPoint2;
|
||||||
isMouseDown = false;
|
isMouseDown = false;
|
||||||
drawMode = DrawPoints;
|
drawMode = DrawPoints;
|
||||||
@@ -1696,6 +1695,7 @@ void GameView::NotifyPlaceSaveChanged(GameModel * sender)
|
|||||||
{
|
{
|
||||||
placeSaveThumb = SaveRenderer::Ref().Render(sender->GetPlaceSave());
|
placeSaveThumb = SaveRenderer::Ref().Render(sender->GetPlaceSave());
|
||||||
selectMode = PlaceSave;
|
selectMode = PlaceSave;
|
||||||
|
selectPoint2 = mousePosition;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -1850,27 +1850,26 @@ void GameView::OnDraw()
|
|||||||
{
|
{
|
||||||
if(selectMode==PlaceSave)
|
if(selectMode==PlaceSave)
|
||||||
{
|
{
|
||||||
Thumbnail * tempThumb = placeSaveThumb;
|
if(placeSaveThumb && selectPoint2.X!=-1)
|
||||||
if(tempThumb && selectPoint2.X!=-1)
|
|
||||||
{
|
{
|
||||||
int thumbX = selectPoint2.X - (tempThumb->Size.X/2);
|
int thumbX = selectPoint2.X - (placeSaveThumb->Size.X/2);
|
||||||
int thumbY = selectPoint2.Y - (tempThumb->Size.Y/2);
|
int thumbY = selectPoint2.Y - (placeSaveThumb->Size.Y/2);
|
||||||
|
|
||||||
ui::Point thumbPos = c->NormaliseBlockCoord(ui::Point(thumbX, thumbY));
|
ui::Point thumbPos = c->NormaliseBlockCoord(ui::Point(thumbX, thumbY));
|
||||||
|
|
||||||
if(thumbPos.X<0)
|
if(thumbPos.X<0)
|
||||||
thumbPos.X = 0;
|
thumbPos.X = 0;
|
||||||
if(thumbPos.X+(tempThumb->Size.X)>=XRES)
|
if(thumbPos.X+(placeSaveThumb->Size.X)>=XRES)
|
||||||
thumbPos.X = XRES-tempThumb->Size.X;
|
thumbPos.X = XRES-placeSaveThumb->Size.X;
|
||||||
|
|
||||||
if(thumbPos.Y<0)
|
if(thumbPos.Y<0)
|
||||||
thumbPos.Y = 0;
|
thumbPos.Y = 0;
|
||||||
if(thumbPos.Y+(tempThumb->Size.Y)>=YRES)
|
if(thumbPos.Y+(placeSaveThumb->Size.Y)>=YRES)
|
||||||
thumbPos.Y = YRES-tempThumb->Size.Y;
|
thumbPos.Y = YRES-placeSaveThumb->Size.Y;
|
||||||
|
|
||||||
ren->draw_image(tempThumb->Data, thumbPos.X, thumbPos.Y, tempThumb->Size.X, tempThumb->Size.Y, 128);
|
ren->draw_image(placeSaveThumb->Data, thumbPos.X, thumbPos.Y, placeSaveThumb->Size.X, placeSaveThumb->Size.Y, 128);
|
||||||
|
|
||||||
ren->xor_rect(thumbPos.X, thumbPos.Y, tempThumb->Size.X, tempThumb->Size.Y);
|
ren->xor_rect(thumbPos.X, thumbPos.Y, placeSaveThumb->Size.X, placeSaveThumb->Size.Y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
Reference in New Issue
Block a user