Skip to content

Commit

Permalink
Track client platform version
Browse files Browse the repository at this point in the history
Client platform version can be retrieved live with /ids and is also
recorded in the playerdetail module.
  • Loading branch information
N104 committed Sep 1, 2016
1 parent 87e212c commit d6b301c
Show file tree
Hide file tree
Showing 35 changed files with 288 additions and 40 deletions.
9 changes: 5 additions & 4 deletions game/Shell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@ class MainMenuForm : public ShellForm
if (idc == kidcLeaderboard) {
LoginHandler handler;
std::string d = base::StringEncoder::QueryEncode(gszDeviceId);
std::string o(base::StringEncoder::QueryEncode(HostGetPlatformString()));
const char *url;
if (strlen(handler.StatsUsername()) == 0) {
url = base::Format::ToString("%s?d=%s", kszLeaderboardUrl,
d.c_str());
url = base::Format::ToString("%s?d=%s&o=%s", kszLeaderboardUrl,
d.c_str(), o.c_str());
} else {
std::string q = base::StringEncoder::QueryEncode(
handler.StatsUsername());
url = base::Format::ToString("%s?p=%s&d=%s", kszLeaderboardUrl,
q.c_str(), d.c_str());
url = base::Format::ToString("%s?p=%s&d=%s&o=%s", kszLeaderboardUrl,
q.c_str(), d.c_str(), o.c_str());
}
HostInitiateWebView("Hostile Takeover Statistics", url);
return;
Expand Down
9 changes: 5 additions & 4 deletions game/chooseserverform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,17 +370,18 @@ std::string ChooseServerForm::GetServiceUrl() {
// protocol version

std::string deviceid(base::StringEncoder::QueryEncode(gszDeviceId));
std::string os(base::StringEncoder::QueryEncode(HostGetPlatformString()));

const char *url;
LoginHandler handler;
if (handler.anonymous()) {
url = base::Format::ToString("%s?x=%d&d=%s", kszServerInfoUrl,
kdwProtocolCurrent, deviceid.c_str());
url = base::Format::ToString("%s?x=%d&d=%s&o=%s", kszServerInfoUrl,
kdwProtocolCurrent, deviceid.c_str(), os.c_str());
} else {
std::string player(base::StringEncoder::QueryEncode(
handler.username()));
url = base::Format::ToString("%s?x=%d&p=%s&d=%s", kszServerInfoUrl,
kdwProtocolCurrent, player.c_str(), deviceid.c_str());
url = base::Format::ToString("%s?x=%d&p=%s&d=%s&o=%s", kszServerInfoUrl,
kdwProtocolCurrent, player.c_str(), deviceid.c_str(), os.c_str());
}

return url;
Expand Down
1 change: 1 addition & 0 deletions game/ht.h
Original file line number Diff line number Diff line change
Expand Up @@ -8822,6 +8822,7 @@ IChatController *HostGetChatController();

void HostInitiateWebView(const char *title, const char *url);
const char *HostGenerateDeviceId();
const char *HostGetPlatformString();

// Date

Expand Down
4 changes: 4 additions & 0 deletions game/iphone/host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ const char *HostGenerateDeviceId() {
return base::Format::ToHex(hash, 16);
}

const char *HostGetPlatformString() {
return IPhone::GetPlatformString();
}

void HostInitiateWebView(const char *title, const char *url) {
return IPhone::InitiateWebView(title, url);
}
Expand Down
1 change: 1 addition & 0 deletions game/iphone/iphone.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class IPhone
static const char *GetTempDir();
static const char *GetCompletesDir();
static const char *GetStaticUUID();
static const char *GetPlatformString();
static void InitiateAsk(const char *title, int max, const char *def,
int keyboard, bool secure);
static void GetAskString(char *psz, int cb);
Expand Down
20 changes: 20 additions & 0 deletions game/iphone/iphone.mm
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ @interface IPhoneAppDelegate : NSObject <UIApplicationDelegate>
char *m_pszTempDir;
char *m_pszCompletesDir;
char *m_pszUUID;
char *m_pszPlatform;
}
@end

Expand Down Expand Up @@ -193,6 +194,15 @@ - (void)applicationDidFinishLaunching:(UIApplication *)application
strcpy(m_pszUUID, pszUUID);
CFRelease(strUUID);

// Get the device platform string
NSString *strPlatform = [NSString stringWithFormat:@"iOS %@",
[[UIDevice currentDevice] systemVersion]];
const char *pszPlatform = [strPlatform cStringUsingEncoding:
[NSString defaultCStringEncoding]];
m_pszPlatform = (char *)malloc(strlen(pszPlatform) + 1);
strcpy(m_pszPlatform, pszPlatform);
CFRelease(strPlatform);

// Set up a notification to restore sound when interrupted
[[NSNotificationCenter defaultCenter] addObserver: self
selector: @selector(handleAudioInterruption:)
Expand Down Expand Up @@ -255,6 +265,11 @@ - (const char *)staticUUID
return m_pszUUID;
}

- (const char *)platformString
{
return m_pszPlatform;
}

- (bool)isExiting
{
return m_fExiting;
Expand Down Expand Up @@ -463,6 +478,11 @@ - (void)setPalette:(wi::Palette *)ppal
return [g_appDelegate staticUUID];
}

const char *IPhone::GetPlatformString()
{
return [g_appDelegate platformString];
}

bool IPhone::IsExiting()
{
return [g_appDelegate isExiting];
Expand Down
5 changes: 4 additions & 1 deletion game/loginhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,10 @@ dword LoginHandler::GetToken() {
// Submit a simple blocking request to get the token

SimpleRequest req(gphttp);
const char *url = base::Format::ToString("%s?a=%s&d=%s", kszAuthUrl, output, gszDeviceId);
std::string d = base::StringEncoder::QueryEncode(gszDeviceId);
std::string o(base::StringEncoder::QueryEncode(HostGetPlatformString()));
const char *url = base::Format::ToString("%s?a=%s&d=%s&o=%s", kszAuthUrl, output,
d.c_str(), o.c_str());
req.SetTimeout(60);

char result[kcbTokenMax];
Expand Down
7 changes: 7 additions & 0 deletions game/sdl/android/jni/ht/hosthelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ static jmethodID getAndroidIDMethod;
static jmethodID initiateAskMethod;
static jmethodID initiateWebViewMethod;
static jmethodID getAskStringMethod;
static jmethodID getPlatformStringMethod;

namespace wi {

Expand Down Expand Up @@ -71,6 +72,7 @@ jint JNI_OnLoad(JavaVM* vm, void* reserved) {
initiateWebViewMethod = env->GetStaticMethodID(NativeLibClass, "initiateWebView", "(Ljava/lang/String;)V");
getAskStringMethod = env->GetStaticMethodID(NativeLibClass, "getAskString", "()Ljava/lang/String;");
initiateAskMethod = env->GetStaticMethodID(NativeLibClass, "initiateAsk", "(Ljava/lang/String;ILjava/lang/String;II)V");
getPlatformStringMethod = env->GetStaticMethodID(NativeLibClass, "getPlatformString", "()Ljava/lang/String;");

return JNI_VERSION_1_4;
}
Expand Down Expand Up @@ -335,6 +337,11 @@ void HostHelpers::InitiateWebView(const char *title, const char *url) {
g_env->CallStaticVoidMethod(NativeLibClass, initiateWebViewMethod, jstrUrl);
}

const char *HostHelpers::GetPlatformString() {
jobject jstr = g_env->CallStaticObjectMethod(NativeLibClass, getPlatformStringMethod);
return g_env->GetStringUTFChars((jstring)jstr, NULL);
}

/*
void HostHelpers::GameThreadStart(void *pv) {
Log("Starting game...");
Expand Down
4 changes: 4 additions & 0 deletions game/sdl/android/src/com/spiffcode/ht/NativeLib.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,8 @@ public void run() {
static String getAskString() {
return askString;
}

static String getPlatformString() {
return "Android " + android.os.Build.VERSION.RELEASE;
}
}
4 changes: 4 additions & 0 deletions game/sdl/host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ const char *HostGenerateDeviceId() {
return base::Format::ToHex(hash, 16);
}

const char *HostGetPlatformString() {
return HostHelpers::GetPlatformString();
}

void HostInitiateWebView(const char *title, const char *url) {
return HostHelpers::InitiateWebView(title, url);
}
Expand Down
1 change: 1 addition & 0 deletions game/sdl/hosthelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class HostHelpers
static bool IsExiting();
static void GameThreadStart(void *pv);
static void DisplayInitComplete();
static const char *GetPlatformString();

// TODO(darrinm): unused?
static int main(int argc, char **argv);
Expand Down
4 changes: 4 additions & 0 deletions game/sdl/ios/hosthelpers.mm
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,10 @@
[iphone initiateWebView:[NSString stringWithUTF8String:url] title:[NSString stringWithUTF8String:title]];
}

const char *HostHelpers::GetPlatformString() {
return [[iphone getPlatformString] cStringUsingEncoding:NSASCIIStringEncoding];
}

void HostHelpers::GameThreadStart(void *pv) {
Log("Starting game...");
wi::GameMain((char *)"");
Expand Down
1 change: 1 addition & 0 deletions game/sdl/ios/iphone.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@
+ (void)presentView:(UIView *)view;
- (void)forceDeviceIntoLandscape;
- (int)deviceOS;
- (NSString *)getPlatformString;
@end
5 changes: 5 additions & 0 deletions game/sdl/ios/iphone.mm
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,9 @@ - (void)forceDeviceIntoLandscape {
- (int)deviceOS {
return DEVICE_OS;
}

- (NSString *)getPlatformString {
return [NSString stringWithFormat:@"iOS %@", [[UIDevice currentDevice] systemVersion]];
}

@end
8 changes: 8 additions & 0 deletions game/sdl/mac/hosthelpers.mm
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,14 @@
HostHelpers::OpenUrl(url);
}

const char *HostHelpers::GetPlatformString() {
NSOperatingSystemVersion version = [[NSProcessInfo processInfo] operatingSystemVersion];
NSString *versionString = [NSString stringWithFormat:@"MacOS %ld.%ld.%ld",
version.majorVersion, version.minorVersion, version.patchVersion];

return [versionString cStringUsingEncoding:NSASCIIStringEncoding];
}

void HostHelpers::GameThreadStart(void *pv) {
Log("Starting game...");
wi::GameMain((char *)"");
Expand Down
2 changes: 1 addition & 1 deletion game/xtransport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ dword XTransport::Login(const char *username, const char *token) {

// Login and wait synchronously for reply.
SetState(XTS_LOGGINGIN);
xpump_.Send(XMsgLogin::ToBuffer(username, token, gszDeviceId));
xpump_.Send(XMsgLogin::ToBuffer(username, token, gszDeviceId, HostGetPlatformString()));

if (!WaitForStateChange()) {
LOG() << "Timed out waiting for Login";
Expand Down
2 changes: 1 addition & 1 deletion mpshared/messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ typedef XMsg2<XMSG_HANDSHAKE> XMsgHandshake;
typedef XMsg2<XMSG_HANDSHAKERESULT> XMsgHandshakeResult;
typedef XMsg0<XMSG_ECHO> XMsgEcho;
typedef XMsg1<XMSG_PROTOCOLERROR> XMsgProtocolError;
typedef XMsgS3<XMSG_LOGIN, kcbUsernameMax, kcbTokenMax, kcbDidMax> XMsgLogin;
typedef XMsgS4<XMSG_LOGIN, kcbUsernameMax, kcbTokenMax, kcbDidMax, kcbPlatformMax> XMsgLogin;
typedef XMsg1<XMSG_LOGINRESULT> XMsgLoginResult;
typedef XMsg0<XMSG_SIGNOUT> XMsgSignOut;
typedef XMsg1<XMSG_SIGNOUTRESULT> XMsgSignOutResult;
Expand Down
1 change: 1 addition & 0 deletions mpshared/mpht.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const int kcbTokenMax = 256;
const int kcbDidMax = 34;
const int kcbChatMax = 1024;
const int kcbShowMessageMax = 512;
const int kcbPlatformMax = 32;

// Side masks

Expand Down
Loading

0 comments on commit d6b301c

Please sign in to comment.