From 97bf9a517e63e87eebeedd6a6d393e83f6354a23 Mon Sep 17 00:00:00 2001 From: Simon Robertshaw Date: Sun, 22 Jul 2012 18:51:05 +0100 Subject: Snapshot checking diff --git a/SConscript b/SConscript index 015fe88..f70fa89 100644 --- a/SConscript +++ b/SConscript @@ -1,4 +1,4 @@ -import os, sys, subprocess +import os, sys, subprocess, time ##Fix for long command line - http://scons.org/wiki/LongCmdLinesOnWin32 class ourSpawn: @@ -93,6 +93,7 @@ env.Append(CPPPATH=['src/', 'data/', 'generated/']) env.Append(CCFLAGS=['-w', '-std=c99', '-fkeep-inline-functions']) env.Append(LIBS=['pthread', 'm', 'bz2']) env.Append(CPPDEFINES={"_POSIX_C_SOURCE": "200112L"}) +env.Append(CPPDEFINES={"SNAPSHOT_ID": int(time.time())}) env.Append(CPPDEFINES=["USE_SDL", "LUACONSOLE", "GRAVFFT", "_GNU_SOURCE", "USE_STDINT"]) if GetOption("ptw32-static"): diff --git a/src/Config.h b/src/Config.h index 5bf10cc..1ad3e09 100644 --- a/src/Config.h +++ b/src/Config.h @@ -21,6 +21,10 @@ #define BETA #define SNAPSHOT #define BUILD_NUM 155 + +#ifndef SNAPSHOT_ID +#define SNAPSHOT_ID 0 +#endif //VersionInfoEnd #if defined(SNAPSHOT) diff --git a/src/client/Client.cpp b/src/client/Client.cpp index 116fa02..de37a6c 100644 --- a/src/client/Client.cpp +++ b/src/client/Client.cpp @@ -155,9 +155,7 @@ void Client::Tick() json::Number betaBuild = betaVersion["Build"]; json::String betaFile = betaVersion["File"]; - json::Number snapshotMajor = snapshotVersion["Major"]; - json::Number snapshotMinor = snapshotVersion["Minor"]; - json::Number snapshotBuild = snapshotVersion["Build"]; + json::Number snapshotSnapshot = snapshotVersion["Snapshot"]; json::String snapshotFile = snapshotVersion["File"]; if(stableMajor.Value()>SAVE_VERSION || (stableMinor.Value()>MINOR_VERSION && stableMajor.Value()==SAVE_VERSION) || stableBuild.Value()>BUILD_NUM) @@ -175,10 +173,10 @@ void Client::Tick() #endif #ifdef SNAPSHOT - if(snapshotMajor.Value()>SAVE_VERSION || (snapshotMinor.Value()>MINOR_VERSION && snapshotMajor.Value()==SAVE_VERSION) || snapshotBuild.Value()>BUILD_NUM) + if(snapshotSnapshot.Value() > SNAPSHOT_ID) { updateAvailable = true; - updateInfo = UpdateInfo(snapshotMajor.Value(), snapshotMinor.Value(), snapshotBuild.Value(), snapshotFile.Value(), UpdateInfo::Snapshot); + updateInfo = UpdateInfo(snapshotSnapshot.Value(), snapshotFile.Value(), UpdateInfo::Snapshot); } #endif diff --git a/src/client/Client.h b/src/client/Client.h index a2d8720..cb39f2e 100644 --- a/src/client/Client.h +++ b/src/client/Client.h @@ -35,9 +35,11 @@ public: int Major; int Minor; int Build; + int Time; BuildType Type; - UpdateInfo() : Major(0), Minor(0), Build(0), File(""), Type(Stable) {} - UpdateInfo(int major, int minor, int build, std::string file, BuildType type) : Major(major), Minor(minor), Build(build), File(file), Type(type) {} + UpdateInfo() : Major(0), Minor(0), Build(0), Time(0), File(""), Type(Stable) {} + UpdateInfo(int major, int minor, int build, std::string file, BuildType type) : Major(major), Minor(minor), Build(build), Time(0), File(file), Type(type) {} + UpdateInfo(int time, std::string file, BuildType type) : Major(0), Minor(0), Build(0), Time(time), File(file), Type(type) {} }; class ClientListener; diff --git a/src/client/HTTP.cpp b/src/client/HTTP.cpp index d622a81..686a6ee 100644 --- a/src/client/HTTP.cpp +++ b/src/client/HTTP.cpp @@ -20,6 +20,8 @@ */ +#include +#include #include #include #include @@ -68,6 +70,7 @@ #define PCLOSE close #endif +char * userAgent; static int http_up = 0; static long http_timeout = 15; static int http_use_proxy = 0; @@ -180,6 +183,15 @@ void http_init(char *proxy) free(host); free(port); } + std::stringstream userAgentBuilder; + userAgentBuilder << "PowderToy/" << SAVE_VERSION << "." << MINOR_VERSION << " "; + userAgentBuilder << "(" << IDENT_PLATFORM << "; " << IDENT_BUILD << "; M0) "; + userAgentBuilder << "TPTPP/" << SAVE_VERSION << "." << MINOR_VERSION << "." << BUILD_NUM << IDENT_RELTYPE << "." << SNAPSHOT_ID; + std::string newUserAgent = userAgentBuilder.str(); + userAgent = new char[newUserAgent.length()+1]; + std::copy(newUserAgent.begin(), newUserAgent.end(), userAgent); + userAgent[newUserAgent.length()] = 0; + //"User-Agent: PowderToy/%d.%d (%s; %s; M%d) TPTPP/%d.%d.%d%s.%d\n", SAVE_VERSION, MINOR_VERSION, IDENT_PLATFORM, IDENT_BUILD, 0, SAVE_VERSION, MINOR_VERSION, BUILD_NUM, IDENT_RELTYPE, SNAPSHOT_ID } void http_done(void) @@ -468,7 +480,7 @@ int http_async_req_status(void *ctx) if (cx->txdl) { // generate POST - cx->tbuf = (char *)malloc(strlen(cx->host) + strlen(cx->path) + 141 + 128 + cx->txdl + cx->thlen); + cx->tbuf = (char *)malloc(strlen(cx->host) + strlen(cx->path) + 126 + strlen(userAgent) + cx->txdl + cx->thlen); cx->tptr = 0; cx->tlen = 0; cx->tlen += sprintf(cx->tbuf+cx->tlen, "POST %s HTTP/1.1\n", cx->path); @@ -484,7 +496,7 @@ int http_async_req_status(void *ctx) cx->thlen = 0; } cx->tlen += sprintf(cx->tbuf+cx->tlen, "Content-Length: %d\n", cx->txdl); - cx->tlen += sprintf(cx->tbuf+cx->tlen, "User-Agent: PowderToy/%d.%d (%s; %s; M%d) TPTPP/%d.%d.%d%s\n", SAVE_VERSION, MINOR_VERSION, IDENT_PLATFORM, IDENT_BUILD, 0, SAVE_VERSION, MINOR_VERSION, BUILD_NUM, IDENT_RELTYPE); + cx->tlen += sprintf(cx->tbuf+cx->tlen, "User-Agent: %s\n", userAgent); cx->tlen += sprintf(cx->tbuf+cx->tlen, "\n"); memcpy(cx->tbuf+cx->tlen, cx->txd, cx->txdl); cx->tlen += cx->txdl; @@ -495,7 +507,7 @@ int http_async_req_status(void *ctx) else { // generate GET - cx->tbuf = (char *)malloc(strlen(cx->host) + strlen(cx->path) + 100 + 128 + cx->thlen); + cx->tbuf = (char *)malloc(strlen(cx->host) + strlen(cx->path) + 93 + strlen(userAgent) + cx->thlen); cx->tptr = 0; cx->tlen = 0; cx->tlen += sprintf(cx->tbuf+cx->tlen, "GET %s HTTP/1.1\n", cx->path); @@ -510,7 +522,7 @@ int http_async_req_status(void *ctx) } if (!cx->keep) cx->tlen += sprintf(cx->tbuf+cx->tlen, "Connection: close\n"); - cx->tlen += sprintf(cx->tbuf+cx->tlen, "User-Agent: PowderToy/%d.%d (%s; %s; M%d) TPTPP/%d.%d.%d%s\n", SAVE_VERSION, MINOR_VERSION, IDENT_PLATFORM, IDENT_BUILD, 0, SAVE_VERSION, MINOR_VERSION, BUILD_NUM, IDENT_RELTYPE); + cx->tlen += sprintf(cx->tbuf+cx->tlen, "User-Agent: %s\n", userAgent); cx->tlen += sprintf(cx->tbuf+cx->tlen, "\n"); } cx->state = HTS_XMIT; diff --git a/src/dialogues/ConfirmPrompt.cpp b/src/dialogues/ConfirmPrompt.cpp index 93ef06a..ed53800 100644 --- a/src/dialogues/ConfirmPrompt.cpp +++ b/src/dialogues/ConfirmPrompt.cpp @@ -28,7 +28,7 @@ ConfirmPrompt::ConfirmPrompt(std::string title, std::string message, ConfirmDial messageLabel->Appearance.VerticalAlign = ui::Appearance::AlignTop; AddComponent(messageLabel); - Size.Y += messageLabel->Size.Y; + Size.Y += messageLabel->Size.Y+12; Position.Y = (ui::Engine::Ref().GetHeight()-Size.Y)/2; class CloseAction: public ui::ButtonAction -- cgit v0.9.2-21-gd62e