diff --git a/BrainCloudCpp.podspec b/BrainCloudCpp.podspec index d94fb094..cda591cd 100644 --- a/BrainCloudCpp.podspec +++ b/BrainCloudCpp.podspec @@ -11,7 +11,7 @@ Pod::Spec.new do |s| s.name = "BrainCloudCpp" - s.version = "5.2.0" + s.version = "5.3.0" s.summary = "The C++ client library for brainCloud" s.homepage = "http://getbraincloud.com/" diff --git a/CMakeLists.txt b/CMakeLists.txt index e40f630b..133e64e1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -594,11 +594,6 @@ if (USE_LIBWEBSOCKETS) endif() -if (XCODE) - # removing warning in clang 15, safe to ignore - target_link_options(brainCloud PUBLIC "LINKER:-no_warn_duplicate_libraries") -endif() - # Setup includes and linked libraries target_include_directories(brainCloud PUBLIC "include" ${includes}) target_link_libraries(brainCloud PUBLIC ${libs}) diff --git a/include/braincloud/BrainCloudAsyncMatch.h b/include/braincloud/BrainCloudAsyncMatch.h index 4677f457..afc89b41 100644 --- a/include/braincloud/BrainCloudAsyncMatch.h +++ b/include/braincloud/BrainCloudAsyncMatch.h @@ -118,7 +118,23 @@ namespace BrainCloud { const char * in_jsonSummary = NULL, const char * in_jsonStatistics = NULL, IServerCallback * in_callback = NULL ); - + + /** + * Allows the current player in the game to overwrite the matchState and + * statistics without completing their turn or adding to matchHistory. + * + * Service Name - AsyncMatch + * Service Operation - UpdateMatchStateCurrentTurn + * * + * @param in_ownerId Match owner identifier + * @param in_matchId Match identifier + * @param in_version Game state version being updated, to ensure data integrity + * @param in_jsonMatchState JSON string provided by the caller Required. + * @param in_jsonStatistics Optional JSON string provided by the caller. + * @param in_callback + */ + void updateMatchStateCurrentTurn( const char * in_ownerId, const char * in_matchId, uint64_t in_version, const char * in_jsonMatchState, const char * in_jsonStatistics, IServerCallback * in_callback = NULL ); + /** * Allows the current player (only) to update Summary data without having to submit a whole turn. * diff --git a/include/braincloud/BrainCloudGroup.h b/include/braincloud/BrainCloudGroup.h index 8c9529b1..a9302a4b 100644 --- a/include/braincloud/BrainCloudGroup.h +++ b/include/braincloud/BrainCloudGroup.h @@ -212,6 +212,17 @@ namespace BrainCloud */ void deleteGroupEntity(const char* in_groupId, const char* in_entityId, int32_t in_version, IServerCallback* in_callback = NULL); + /** + * Delete an outstanding request to join the group. + * + * Service Name - group + * Service Operation - DELETE_GROUP_JOIN_REQUEST + * + * @param in_groupId ID of the group. + * @param in_callback The method to be invoked when the server response is received + */ + void deleteGroupJoinRequest(const char* in_groupId, IServerCallback* in_callback = NULL); + /** * Read information on groups to which the current user belongs. * @@ -395,17 +406,17 @@ namespace BrainCloud */ void rejectGroupInvitation(const char* in_groupId, IServerCallback* in_callback = NULL); - /** - * Reject an outstanding request to join the group. - * - * Service Name - group - * Service Operation - REJECT_GROUP_JOIN_REQUEST - * - * @param in_groupId ID of the group. - * @param in_profileId Profile ID of the invitation being deleted. - * @param in_callback The method to be invoked when the server response is received - */ - void rejectGroupJoinRequest(const char* in_groupId, const char* in_profileId, IServerCallback* in_callback = NULL); + /** + * Reject an outstanding request to join the group. + * + * Service Name - group + * Service Operation - REJECT_GROUP_JOIN_REQUEST + * + * @param in_groupId ID of the group. + * @param in_profileId Profile ID of the invitation being deleted. + * @param in_callback The method to be invoked when the server response is received + */ + void rejectGroupJoinRequest(const char* in_groupId, const char* in_profileId, IServerCallback* in_callback = NULL); /** * Remove a member from the group. diff --git a/include/braincloud/BrainCloudWrapper.h b/include/braincloud/BrainCloudWrapper.h index 049ef240..11ccca7f 100644 --- a/include/braincloud/BrainCloudWrapper.h +++ b/include/braincloud/BrainCloudWrapper.h @@ -757,7 +757,13 @@ namespace BrainCloud { */ void resetUniversalIdPasswordAdvancedWithExpiry(const char * in_emailAddress, std::string in_serviceParams, int in_tokenTtlInMinutes , IServerCallback * in_callback = NULL); - /** + /** + * Returns true IF both Profile ID and Anonymous ID are stored - meaning reconnect possible + * @return true if reconnect possible + */ + bool canReconnect(); + + /** * Re-authenticates the user with brainCloud * * @param in_callback The method to be invoked when the server response is received @@ -798,6 +804,14 @@ namespace BrainCloud { return client; } + + /** + * Clears Profile Id and Anonymous Id and deletes data entry on device + * Use Logout + * NOTE: If this is called when AnonymousAuthentication is used, the portal user cannot be reconnected or recovered! + */ + void clearIds(); + /** * Returns the stored profile id * @return The stored profile id @@ -832,6 +846,7 @@ namespace BrainCloud { */ void resetStoredAnonymousId(); + /** * For non-anonymous authentication methods, a profile id will be passed in * when this value is set to false. This will generate an error on the server @@ -849,6 +864,12 @@ namespace BrainCloud { */ bool getAlwaysAllowProfileSwitch(); + /** + * Logs user out of playerState and optionally clears the profile id (eg. shared computer) + * NOTE: if forgetUser is true for an AuthenticateAnonymous THEN the user data will be in-accessible and non-recoverable + * @param forgetUser true if user profile should be deleted from device on logout, false to allow reconnect + * @param in_callback + */ void logout(bool forgetUser, IServerCallback * in_callback); virtual void serverCallback(BrainCloud::ServiceName serviceName, BrainCloud::ServiceOperation serviceOperation, std::string const & jsonData); diff --git a/include/braincloud/ServiceOperation.h b/include/braincloud/ServiceOperation.h index 1043da3c..536c7632 100644 --- a/include/braincloud/ServiceOperation.h +++ b/include/braincloud/ServiceOperation.h @@ -206,6 +206,7 @@ namespace BrainCloud { static const ServiceOperation DeleteMatch; static const ServiceOperation CompleteMatchWithSummaryData; static const ServiceOperation AbandonMatchWithSummaryData; + static const ServiceOperation UpdateMatchStateCurrentTurn; static const ServiceOperation LastUploadStatus; @@ -341,7 +342,8 @@ namespace BrainCloud { static const ServiceOperation CreateGroupEntity; static const ServiceOperation DeleteGroup; static const ServiceOperation DeleteGroupEntity; - static const ServiceOperation DeleteGroupMemeber; + static const ServiceOperation DeleteGroupMember; + static const ServiceOperation DeleteGroupJoinRequest; static const ServiceOperation GetMyGroups; static const ServiceOperation IncrementGroupData; static const ServiceOperation IncrementGroupEntityData; @@ -358,7 +360,7 @@ namespace BrainCloud { static const ServiceOperation ReadGroupEntity; static const ServiceOperation ReadGroupMembers; static const ServiceOperation RejectGroupInvitation; - static const ServiceOperation RejectGroupJoinRequest; + static const ServiceOperation RejectGroupJoinRequest; static const ServiceOperation RemoveGroupMember; static const ServiceOperation UpdateGroupData; static const ServiceOperation UpdateGroupEntity; @@ -517,4 +519,4 @@ namespace BrainCloud { ServiceOperation(const char * value); }; -} \ No newline at end of file +} diff --git a/src/BrainCloudAsyncMatch.cpp b/src/BrainCloudAsyncMatch.cpp index e2208400..0766063d 100644 --- a/src/BrainCloudAsyncMatch.cpp +++ b/src/BrainCloudAsyncMatch.cpp @@ -82,6 +82,30 @@ namespace BrainCloud m_client->getBrainCloudComms()->addToQueue(sc); } + void BrainCloudAsyncMatch::updateMatchStateCurrentTurn( + const char * in_ownerId, + const char * in_matchId, + uint64_t in_version, + const char * in_jsonMatchState, + const char * in_jsonStatistics, + IServerCallback * in_callback) + { + Json::Value message; + message[OperationParam::AsyncMatchServiceOwnerId.getValue()] = in_ownerId; + message[OperationParam::AsyncMatchServiceMatchId.getValue()] = in_matchId; + message[OperationParam::AsyncMatchServiceVersion.getValue()] = (Json::UInt64) in_version; + + if (StringUtil::IsOptionalParameterValid(in_jsonMatchState)) { + message[OperationParam::AsyncMatchServiceMatchState.getValue()] = JsonUtil::jsonStringToValue(in_jsonMatchState); + } + if (StringUtil::IsOptionalParameterValid(in_jsonStatistics)) { + message[OperationParam::AsyncMatchServiceStatistics.getValue()] = JsonUtil::jsonStringToValue(in_jsonStatistics); + } + + ServerCall * sc = new ServerCall(ServiceName::AsyncMatch, ServiceOperation::UpdateMatchStateCurrentTurn, message, in_callback); + m_client->getBrainCloudComms()->addToQueue(sc); + } + void BrainCloudAsyncMatch::updateMatchSummaryData(const char * in_ownerId, const char * in_matchId, uint64_t in_version, const char * in_jsonSummary, IServerCallback * in_callback) { Json::Value message; diff --git a/src/BrainCloudClient.cpp b/src/BrainCloudClient.cpp index 4aedf667..e4c79ac2 100644 --- a/src/BrainCloudClient.cpp +++ b/src/BrainCloudClient.cpp @@ -27,7 +27,7 @@ namespace BrainCloud "Singleton usage is disabled. If called by mistake, use your own variable that holds an instance of the bcWrapper/bcClient."; BrainCloudClient * BrainCloudClient::_instance = NULL; - std::string BrainCloudClient::s_brainCloudClientVersion = "5.2.0"; + std::string BrainCloudClient::s_brainCloudClientVersion = "5.3.0"; const char* BC_SERVER_URL = "https://api.braincloudservers.com/dispatcherv2"; /** diff --git a/src/BrainCloudGroup.cpp b/src/BrainCloudGroup.cpp index c26a6e80..f013a108 100644 --- a/src/BrainCloudGroup.cpp +++ b/src/BrainCloudGroup.cpp @@ -346,13 +346,22 @@ namespace BrainCloud m_client->getBrainCloudComms()->addToQueue(sc); } - void BrainCloudGroup::rejectGroupJoinRequest(const char * in_groupId, const char * in_profileId, IServerCallback * in_callback) + void BrainCloudGroup::rejectGroupJoinRequest(const char * in_groupId, const char * in_profileId, IServerCallback * in_callback) + { + Json::Value message; + message[OperationParam::GroupId.getValue()] = in_groupId; + message[OperationParam::GroupProfileId.getValue()] = in_profileId; + + ServerCall * sc = new ServerCall(ServiceName::Group, ServiceOperation::RejectGroupJoinRequest, message, in_callback); + m_client->getBrainCloudComms()->addToQueue(sc); + } + + void BrainCloudGroup::deleteGroupJoinRequest(const char * in_groupId, IServerCallback * in_callback) { Json::Value message; message[OperationParam::GroupId.getValue()] = in_groupId; - message[OperationParam::GroupProfileId.getValue()] = in_profileId; - - ServerCall * sc = new ServerCall(ServiceName::Group, ServiceOperation::RejectGroupJoinRequest, message, in_callback); + + ServerCall * sc = new ServerCall(ServiceName::Group, ServiceOperation::DeleteGroupJoinRequest, message, in_callback); m_client->getBrainCloudComms()->addToQueue(sc); } diff --git a/src/BrainCloudWrapper.cpp b/src/BrainCloudWrapper.cpp index 028a0043..2447827a 100644 --- a/src/BrainCloudWrapper.cpp +++ b/src/BrainCloudWrapper.cpp @@ -357,12 +357,6 @@ namespace BrainCloud { BrainCloudWrapper * wrapper; IServerCallback * callback; - void clearIds() { - wrapper->resetStoredAnonymousId(); - wrapper->resetStoredProfileId(); - wrapper->client->getAuthenticationService()->clearSavedProfileId(); - } - void serverError(ServiceName serviceName, ServiceOperation serviceOperation, int statusCode, int reasonCode, const std::string & jsonError) { callback->serverError(serviceName, serviceOperation, statusCode, reasonCode, jsonError); @@ -385,7 +379,7 @@ namespace BrainCloud { void serverCallback(ServiceName serviceName, ServiceOperation serviceOperation, std::string const & jsonData) { - clearIds(); + wrapper->clearIds(); wrapper->client->getAuthenticationService()->authenticateEmailPassword(email, password, forceCreate, callback); delete this; } @@ -411,7 +405,7 @@ namespace BrainCloud { void serverCallback(ServiceName serviceName, ServiceOperation serviceOperation, std::string const & jsonData) { - clearIds(); + wrapper->clearIds(); wrapper->client->getAuthenticationService()->authenticateExternal(userid, token, externalAuthName, forceCreate, callback); delete this; } @@ -436,7 +430,7 @@ namespace BrainCloud { void serverCallback(ServiceName serviceName, ServiceOperation serviceOperation, std::string const & jsonData) { - clearIds(); + wrapper->clearIds(); wrapper->client->getAuthenticationService()->authenticateFacebook(fbUserId, fbAuthToken, forceCreate, callback); delete this; } @@ -461,7 +455,7 @@ namespace BrainCloud { void serverCallback(ServiceName serviceName, ServiceOperation serviceOperation, std::string const & jsonData) { - clearIds(); + wrapper->clearIds(); wrapper->client->getAuthenticationService()->authenticateOculus(oculusUserId, oculusNonce, forceCreate, callback); delete this; } @@ -485,7 +479,7 @@ namespace BrainCloud { void serverCallback(ServiceName serviceName, ServiceOperation serviceOperation, std::string const & jsonData) { - clearIds(); + wrapper->clearIds(); wrapper->client->getAuthenticationService()->authenticateGameCenter(gameCenterId, forceCreate, callback); delete this; } @@ -510,7 +504,7 @@ namespace BrainCloud { void serverCallback(ServiceName serviceName, ServiceOperation serviceOperation, std::string const & jsonData) { - clearIds(); + wrapper->clearIds(); wrapper->client->getAuthenticationService()->authenticateGoogle(userid, token, forceCreate, callback); delete this; } @@ -535,7 +529,7 @@ namespace BrainCloud { void serverCallback(ServiceName serviceName, ServiceOperation serviceOperation, std::string const & jsonData) { - clearIds(); + wrapper->clearIds(); wrapper->client->getAuthenticationService()->authenticateGoogle(userid, token, forceCreate, callback); delete this; } @@ -560,7 +554,7 @@ namespace BrainCloud { void serverCallback(ServiceName serviceName, ServiceOperation serviceOperation, std::string const & jsonData) { - clearIds(); + wrapper->clearIds(); wrapper->client->getAuthenticationService()->authenticateApple(userid, token, forceCreate, callback); delete this; } @@ -585,7 +579,7 @@ namespace BrainCloud { void serverCallback(ServiceName serviceName, ServiceOperation serviceOperation, std::string const & jsonData) { - clearIds(); + wrapper->clearIds(); wrapper->client->getAuthenticationService()->authenticateSteam(userid, sessionticket, forceCreate, callback); delete this; } @@ -611,7 +605,7 @@ namespace BrainCloud { void serverCallback(ServiceName serviceName, ServiceOperation serviceOperation, std::string const & jsonData) { - clearIds(); + wrapper->clearIds(); wrapper->client->getAuthenticationService()->authenticateTwitter(userid, token, secret, forceCreate, callback); delete this; } @@ -636,7 +630,7 @@ namespace BrainCloud { void serverCallback(ServiceName serviceName, ServiceOperation serviceOperation, std::string const & jsonData) { - clearIds(); + wrapper->clearIds(); wrapper->client->getAuthenticationService()->authenticateUniversal(userid, password, forceCreate, callback); delete this; } @@ -661,7 +655,7 @@ namespace BrainCloud { void serverCallback(ServiceName serviceName, ServiceOperation serviceOperation, std::string const & jsonData) { - clearIds(); + wrapper->clearIds(); wrapper->client->getAuthenticationService()->authenticateUltra(ultraUsername, ultraIdToken, forceCreate, callback); delete this; } @@ -690,7 +684,7 @@ namespace BrainCloud { void serverCallback(ServiceName serviceName, ServiceOperation serviceOperation, std::string const & jsonData) { - clearIds(); + wrapper->clearIds(); wrapper->client->getAuthenticationService()->authenticateAdvanced(authenticationType, ids, forceCreate, extraJson, callback); delete this; } @@ -718,7 +712,7 @@ namespace BrainCloud { if (forgetUser) { resetStoredProfileId(); } - client->getPlayerStateService()->logout(in_callback); + client->getPlayerStateService()->logout(in_callback); } void BrainCloudWrapper::resetEmailPassword(const char * in_externalId, IServerCallback * in_callback) @@ -766,6 +760,17 @@ namespace BrainCloud { authenticateAnonymous(in_callback, false); } + bool BrainCloudWrapper::canReconnect() + { + return getStoredProfileId() != "" && getStoredAnonymousId() != ""; + } + + void BrainCloudWrapper::clearIds() + { + resetStoredProfileId(); + resetStoredAnonymousId(); + } + void BrainCloudWrapper::runCallbacks() { client->runCallbacks(); @@ -781,11 +786,6 @@ namespace BrainCloud { SaveDataHelper::getInstance()->saveData(PROFILE_ID_KEY, profileId); } - void BrainCloudWrapper::resetStoredProfileId() - { - SaveDataHelper::getInstance()->deleteData(PROFILE_ID_KEY); - } - std::string BrainCloudWrapper::getStoredAnonymousId() { return SaveDataHelper::getInstance()->readData(ANONYMOUS_ID_KEY); @@ -799,6 +799,13 @@ namespace BrainCloud { void BrainCloudWrapper::resetStoredAnonymousId() { SaveDataHelper::getInstance()->deleteData(ANONYMOUS_ID_KEY); + client->getAuthenticationService()->setAnonymousId(""); + } + + void BrainCloudWrapper::resetStoredProfileId() + { + SaveDataHelper::getInstance()->deleteData(PROFILE_ID_KEY); + client->getAuthenticationService()->setProfileId(""); } std::string BrainCloudWrapper::getStoredAuthenticationType() @@ -816,7 +823,6 @@ namespace BrainCloud { SaveDataHelper::getInstance()->deleteData(AUTHENTICATION_TYPE_KEY); } - void BrainCloudWrapper::setAlwaysAllowProfileSwitch(bool in_alwaysAllow) { m_alwaysAllowProfileSwitch = in_alwaysAllow; diff --git a/src/DefaultGUID.cpp b/src/DefaultGUID.cpp index d73680f1..669bd566 100644 --- a/src/DefaultGUID.cpp +++ b/src/DefaultGUID.cpp @@ -6,12 +6,14 @@ namespace BrainCloud { std::string GUID::generateGUID() { + srand(time(0)); // should only call one time + unsigned char buffer[16] = { 0 }; // This is not great. See BCLD-3069 for (int i = 0; i < 16; ++i) { - buffer[i] = (unsigned char)(rand() % 255); + buffer[i] = static_cast(rand()/static_cast(RAND_MAX) * 256.0f); } return GUIDToString(buffer); diff --git a/src/ServiceOperation.cpp b/src/ServiceOperation.cpp index a279363e..d1122614 100644 --- a/src/ServiceOperation.cpp +++ b/src/ServiceOperation.cpp @@ -188,6 +188,7 @@ namespace BrainCloud const ServiceOperation ServiceOperation::FindPlayersUsingFilter = ServiceOperation("FIND_PLAYERS_USING_FILTER"); const ServiceOperation ServiceOperation::SubmitTurn = ServiceOperation("SUBMIT_TURN"); + const ServiceOperation ServiceOperation::UpdateMatchStateCurrentTurn = ServiceOperation("UPDATE_MATCH_STATE_CURRENT_TURN"); const ServiceOperation ServiceOperation::UpdateMatchSummary = ServiceOperation("UPDATE_SUMMARY"); const ServiceOperation ServiceOperation::Abandon = ServiceOperation("ABANDON"); const ServiceOperation ServiceOperation::Complete = ServiceOperation("COMPLETE"); @@ -320,7 +321,8 @@ namespace BrainCloud const ServiceOperation ServiceOperation::CreateGroupEntity = ServiceOperation("CREATE_GROUP_ENTITY"); const ServiceOperation ServiceOperation::DeleteGroup = ServiceOperation("DELETE_GROUP"); const ServiceOperation ServiceOperation::DeleteGroupEntity = ServiceOperation("DELETE_GROUP_ENTITY"); - const ServiceOperation ServiceOperation::DeleteGroupMemeber = ServiceOperation("DELETE_MEMBER_FROM_GROUP"); + const ServiceOperation ServiceOperation::DeleteGroupJoinRequest = ServiceOperation("DELETE_GROUP_JOIN_REQUEST"); + const ServiceOperation ServiceOperation::DeleteGroupMember = ServiceOperation("DELETE_MEMBER_FROM_GROUP"); const ServiceOperation ServiceOperation::GetMyGroups = ServiceOperation("GET_MY_GROUPS"); const ServiceOperation ServiceOperation::IncrementGroupData = ServiceOperation("INCREMENT_GROUP_DATA"); const ServiceOperation ServiceOperation::IncrementGroupEntityData = ServiceOperation("INCREMENT_GROUP_ENTITY_DATA"); diff --git a/src/android/AndroidDevice.cpp b/src/android/AndroidDevice.cpp index b936b45d..1639bee4 100644 --- a/src/android/AndroidDevice.cpp +++ b/src/android/AndroidDevice.cpp @@ -1,4 +1,8 @@ #include "braincloud/internal/Device.h" +#include "braincloud/internal/android/AndroidGlobals.h" + +#include +#include static const std::string PLATFORM_NAME("ANG"); @@ -11,10 +15,51 @@ namespace BrainCloud return PLATFORM_NAME; } - void getLocale(float* out_timezoneOffset, std::string* out_languageCode, std::string* out_countryCode) - { - // do NOT set countryCode etc here as the android - // java layer is responsible for setting it. + void getLocale(float* out_timezoneOffset, std::string* out_languageCode, std::string* out_countryCode) { + + // check for AndroidBridge class, if it exists assume java activity will initialize + jclass jcAndroidBridge = appEnv->FindClass("com/bitheads/braincloud/AndroidBridge"); + if (!appEnv->ExceptionCheck()) { + // do NOT set countryCode etc here as the android + // java layer is responsible for setting it. + return; + } + appEnv->ExceptionClear(); + + jclass jcLocale = appEnv->FindClass("java/util/Locale"); + jmethodID jmDefault = appEnv->GetStaticMethodID(jcLocale, "getDefault", + "()Ljava/util/Locale;"); + + jobject joLocale = appEnv->CallStaticObjectMethod(jcLocale, jmDefault); + + jmethodID jmCountry = appEnv->GetMethodID(jcLocale, "getCountry", + "()Ljava/lang/String;"); + auto value = (jstring) (appEnv->CallObjectMethod(joLocale, jmCountry)); + const char *valueP = appEnv->GetStringUTFChars(value, nullptr); + *out_countryCode = std::string(valueP); + appEnv->ReleaseStringUTFChars(value, valueP); + + jmethodID jmLanguage = appEnv->GetMethodID(jcLocale, "getLanguage", + "()Ljava/lang/String;"); + value = (jstring) (appEnv->CallObjectMethod(joLocale, jmLanguage)); + valueP = appEnv->GetStringUTFChars(value, nullptr); + *out_languageCode = std::string(valueP); + appEnv->ReleaseStringUTFChars(value, valueP); + + jclass jcDateType = appEnv->FindClass("java/util/Date"); + jmethodID jmDateInit= appEnv->GetMethodID(jcDateType, "", "()V"); + jobject joDateObject= appEnv->NewObject(jcDateType , jmDateInit); + jmethodID jmDateTime= appEnv->GetMethodID(jcDateType, "getTime", "()J"); + + jlong currtime = appEnv->CallLongMethod(joDateObject, jmDateTime); + + jclass jcTimeZone = appEnv->FindClass("java/util/TimeZone"); + jmDefault = appEnv->GetStaticMethodID(jcTimeZone, "getDefault", + "()Ljava/util/TimeZone;"); + jobject joTimeZone = appEnv->CallStaticObjectMethod(jcTimeZone, jmDefault); + jmethodID jmTimeZone = appEnv->GetMethodID(jcTimeZone, "getOffset", "(J)I"); + + *out_timezoneOffset = appEnv->CallIntMethod(joTimeZone, jmTimeZone, currtime) / static_cast(60 * 60 * 1000); } } } diff --git a/tests/src/TestBCAsyncMatch.cpp b/tests/src/TestBCAsyncMatch.cpp index 949fc658..f4b3fc62 100644 --- a/tests/src/TestBCAsyncMatch.cpp +++ b/tests/src/TestBCAsyncMatch.cpp @@ -71,7 +71,7 @@ TEST_F(TestBCAsyncMatch, SubmitTurn) { TestBCAsyncMatch::CreateMatch(); TestResult tr; - + Json::Value matchState; matchState["map"] = "level01"; Json::FastWriter fw; @@ -89,6 +89,25 @@ TEST_F(TestBCAsyncMatch, SubmitTurn) TestBCAsyncMatch::AbandonMatch(); } +TEST_F(TestBCAsyncMatch, UpdateMatchStateCurrentTurn) +{ + TestBCAsyncMatch::CreateMatch(); + TestResult tr; + + Json::Value matchState; + matchState["map"] = "level01"; + Json::FastWriter fw; + + m_bc->getAsyncMatchService()->updateMatchStateCurrentTurn(GetUser(UserA)->m_profileId, + m_matchId.c_str(), + 0, + fw.write(matchState).c_str(), + fw.write(matchState).c_str(), + &tr); + tr.run(m_bc); + TestBCAsyncMatch::AbandonMatch(); +} + TEST_F(TestBCAsyncMatch, UpdateMatchSummaryData) { TestBCAsyncMatch::CreateMatch(); diff --git a/tests/src/TestBCGroup.cpp b/tests/src/TestBCGroup.cpp index 82aecaf6..c9103de5 100644 --- a/tests/src/TestBCGroup.cpp +++ b/tests/src/TestBCGroup.cpp @@ -194,6 +194,38 @@ TEST_F(TestBCGroup, DeleteGroupEntity) Logout(); } + +TEST_F(TestBCGroup, DeleteGroupJoinRequest) +{ + CreateGroupAsUserA(); + Authenticate(UserB); + + TestResult tr; + m_bc->getGroupService()->joinGroup( + _groupId.c_str(), + &tr); + tr.run(m_bc); + + m_bc->getGroupService()->getMyGroups(&tr); + tr.run(m_bc); + Json::Value groups = tr.m_response["data"]["requested"]; + + ASSERT_FALSE(groups.empty()); + + m_bc->getGroupService()->deleteGroupJoinRequest( + _groupId.c_str(), + &tr); + tr.run(m_bc); + + m_bc->getGroupService()->getMyGroups(&tr); + tr.run(m_bc); + groups = tr.m_response["data"]["requested"]; + + ASSERT_TRUE(groups.empty()); + + DeleteGroupAsUserA(); +} + TEST_F(TestBCGroup, GetMyGroups) { Authenticate(UserA); @@ -662,7 +694,7 @@ void TestBCGroup::DeleteGroupAsUserA() void TestBCGroup::Authenticate(Users user) { TestResult tr; - m_bc->getAuthenticationService()->authenticateUniversal( + m_bcWrapper->authenticateUniversal( GetUser(user)->m_id, GetUser(user)->m_password, true, diff --git a/tests/src/TestBCGroupFile.cpp b/tests/src/TestBCGroupFile.cpp index 731226bb..b14d9905 100644 --- a/tests/src/TestBCGroupFile.cpp +++ b/tests/src/TestBCGroupFile.cpp @@ -349,7 +349,7 @@ TEST_F(TestBCGroupFile, testUpdateFileInfo) void TestBCGroupFile::Authenticate() { TestResult tr; - m_bc->getAuthenticationService()->authenticateEmailPassword( + m_bcWrapper->authenticateEmailPassword( "cpp-tester", "cpp-tester", true, @@ -455,7 +455,7 @@ void TestBCGroupFile::SetUpTestCase() wrapper->initializeWithApps(m_serverUrl.c_str(), m_appId.c_str(), secretMap, m_version.c_str(), "", ""); TestResult tr; - wrapper->getBCClient()->getAuthenticationService()->authenticateEmailPassword( + wrapper->authenticateEmailPassword( "cpp-tester", "cpp-tester", false, @@ -471,8 +471,9 @@ void TestBCGroupFile::SetUpTestCase() std::string uploadId; if (!simpleUpload(wrapper->getBCClient(), 5, "TestFolder", filename.c_str(), uploadId)) { + wrapper->logout(true, &tr); + tr.run(wrapper->client); wrapper->getBCClient()->resetCommunication(); - wrapper->getBCClient()->getAuthenticationService()->clearSavedProfileId(); delete wrapper; wrapper = nullptr; return; @@ -489,9 +490,9 @@ void TestBCGroupFile::SetUpTestCase() /* Save group file ID for tests */ groupFileId = tr.m_response["data"]["fileDetails"]["fileId"].asString(); + wrapper->logout(true, &tr); + tr.run(wrapper->client); wrapper->getBCClient()->resetCommunication(); - wrapper->getBCClient()->getAuthenticationService()->clearSavedProfileId(); - delete wrapper; wrapper = nullptr; } diff --git a/tests/src/TestBCLobby.cpp b/tests/src/TestBCLobby.cpp index 6ddb93da..bf48e92e 100644 --- a/tests/src/TestBCLobby.cpp +++ b/tests/src/TestBCLobby.cpp @@ -119,8 +119,7 @@ TEST_F(TestBCLobbyNoAuth, CreateAndJoinLobby) } // TearDown - bc->getPlayerStateService()->logout(&tr); - tr.run(bc); + Logout(); delete wrapper; }); @@ -189,8 +188,7 @@ TEST_F(TestBCLobbyNoAuth, CreateAndJoinLobby) } // TearDown - bc->getPlayerStateService()->logout(&tr); - tr.run(bc); + Logout(); }); // Join threads diff --git a/tests/src/TestBCPlayerState.cpp b/tests/src/TestBCPlayerState.cpp index 766733a1..04da54bb 100644 --- a/tests/src/TestBCPlayerState.cpp +++ b/tests/src/TestBCPlayerState.cpp @@ -166,7 +166,7 @@ TEST_F(TestBCPlayerState, SetUserStatus) void TestBCPlayerState::Authenticate() { TestResult tr; - m_bc->getAuthenticationService()->authenticateUniversal(GetUser(UserA)->m_id, GetUser(UserA)->m_password, true, &tr); + m_bcWrapper->authenticateUniversal(GetUser(UserA)->m_id, GetUser(UserA)->m_password, true, &tr); tr.run(m_bc); } diff --git a/tests/src/TestBCWrapper.cpp b/tests/src/TestBCWrapper.cpp index 1937d72f..c12db98b 100644 --- a/tests/src/TestBCWrapper.cpp +++ b/tests/src/TestBCWrapper.cpp @@ -8,7 +8,6 @@ // Build machines dislike this :-) // However you can uncomment to verify the wrapper is working. -#ifndef __APPLE__ TEST_F(TestBCWrapper, AaaRunFirst) { @@ -20,8 +19,7 @@ TEST_F(TestBCWrapper, AaaRunFirst) #endif // this forces us to create a new anonymous account - m_bcWrapper->setStoredAnonymousId(""); - m_bcWrapper->setStoredProfileId(""); + m_bcWrapper->clearIds(); } TEST_F(TestBCWrapper, AuthenticateAnonymous) @@ -31,7 +29,7 @@ TEST_F(TestBCWrapper, AuthenticateAnonymous) TestResult tr; m_bcWrapper->authenticateAnonymous(&tr); tr.run(m_bc); - + Logout(); } @@ -42,14 +40,14 @@ TEST_F(TestBCWrapper, ManualRedirect) // Redirects to the same environement, dif TestResult tr; m_bcWrapper->authenticateAnonymous(&tr); tr.run(m_bc); - + Logout(); } TEST_F(TestBCWrapper, AuthenticateEmailPassword) { m_bcWrapper->initialize(m_serverUrl.c_str(), m_secret.c_str(), m_appId.c_str(), m_version.c_str(), "wrapper", "unittest"); - + std::string email = GetUser(UserA)->m_email; size_t pos = email.find('@'); if(pos > 0) @@ -58,20 +56,20 @@ TEST_F(TestBCWrapper, AuthenticateEmailPassword) TestResult tr; m_bcWrapper->authenticateEmailPassword(email.c_str(), GetUser(UserA)->m_password, true, &tr); tr.run(m_bc); - + Logout(); } TEST_F(TestBCWrapper, AuthenticateUniversal) { m_bcWrapper->initialize(m_serverUrl.c_str(), m_secret.c_str(), m_appId.c_str(), m_version.c_str(), "wrapper", "unittest"); - + TestResult tr; std::string uid = GetUser(UserA)->m_id; uid.append("_wrapper"); m_bcWrapper->authenticateUniversal(uid.c_str(), GetUser(UserA)->m_password, true, &tr); tr.run(m_bc); - + Logout(); } @@ -81,8 +79,7 @@ TEST_F(TestBCWrapper, VerifyAlwaysAllowProfileFalse) m_bcWrapper->setAlwaysAllowProfileSwitch(false); // this forces us to create a new anonymous account - m_bcWrapper->setStoredAnonymousId(""); - m_bcWrapper->setStoredProfileId(""); + m_bcWrapper->clearIds(); TestResult tr; m_bcWrapper->authenticateAnonymous(&tr); @@ -96,8 +93,8 @@ TEST_F(TestBCWrapper, VerifyAlwaysAllowProfileFalse) m_bcWrapper->getIdentityService()->attachUniversalIdentity(uid.c_str(), GetUser(UserA)->m_password, &tr); tr.run(m_bc); - Logout(); - m_bcWrapper->getBCClient()->getAuthenticationService()->clearSavedProfileId(); + m_bcWrapper->logout(false, &tr); + tr.run(m_bc); m_bcWrapper->authenticateUniversal(uid.c_str(), GetUser(UserA)->m_password, true, &tr); tr.run(m_bc); @@ -125,6 +122,8 @@ TEST_F(TestBCWrapper, ResetEmailPassword) m_bcWrapper->resetEmailPassword(email, &tr); tr.run(m_bc); + + Logout(); } TEST_F(TestBCWrapper, ResetEmailPasswordAdvanced) @@ -141,21 +140,11 @@ TEST_F(TestBCWrapper, ResetEmailPasswordAdvanced) &tr ); tr.run(m_bc); - + m_bcWrapper->resetEmailPasswordAdvanced(email, content, &tr); tr.runExpectFail(m_bc, HTTP_BAD_REQUEST, INVALID_FROM_ADDRESS); -} - -TEST_F(TestBCWrapper, Reconnect) -{ - TestResult tr; - - m_bcWrapper->initialize(m_serverUrl.c_str(), m_secret.c_str(), m_appId.c_str(), m_version.c_str(), "wrapper", "unittest"); - m_bcWrapper->resetStoredAnonymousId(); - m_bcWrapper->reconnect(&tr); - tr.runExpectFail(m_bc, HTTP_ACCEPTED, MISSING_PROFILE_ERROR); - Logout(); + Logout(); } TEST_F(TestBCWrapper, LogoutRememberUser) @@ -174,8 +163,10 @@ TEST_F(TestBCWrapper, LogoutRememberUser) #ifdef __linux__ EXPECT_TRUE(m_bcWrapper->getStoredProfileId()==""); #else - EXPECT_FALSE(m_bcWrapper->getStoredProfileId()==""); + EXPECT_TRUE(m_bcWrapper->canReconnect()); #endif + + Logout(); } TEST_F(TestBCWrapper, LogoutForgetUser) @@ -192,31 +183,52 @@ TEST_F(TestBCWrapper, LogoutForgetUser) tr.run(m_bc); EXPECT_TRUE(m_bcWrapper->getStoredProfileId()==""); + + Logout(); } -TEST_F(TestBCWrapper, SmartSwitchAnonToUniversal) +TEST_F(TestBCWrapper, Reconnect) { - //need to separate these tests for windows and linux for the time being. - #ifdef __linux__ - std::string uid = GetUser(UserA)->m_id; - uid.append("_wrapper"); + TestResult tr; - m_bcWrapper->setStoredAnonymousId(m_bcWrapper->client->getAuthenticationService()->generateAnonymousId().c_str()); - m_bcWrapper->resetStoredProfileId(); + m_bcWrapper->initialize(m_serverUrl.c_str(), m_secret.c_str(), m_appId.c_str(), m_version.c_str(), "wrapper", "unittest"); + m_bcWrapper->authenticateAnonymous(&tr); + tr.run(m_bc); - TestResult tr; + m_bcWrapper->logout(false, &tr); + tr.run(m_bc); - m_bcWrapper->authenticateAnonymous(&tr); - tr.run(m_bc); + m_bcWrapper->reconnect(&tr); - std::string profileId = m_bcWrapper->getStoredProfileId(); + //WE WILL NOT HAVE A SAVED PROFILE ID, so reconnect will not work +#ifdef __linux__ + tr.runExpectFail(m_bc, HTTP_ACCEPTED, MISSING_PROFILE_ERROR); +#else + tr.run(m_bc); +#endif - m_bcWrapper->smartSwitchAuthenticateUniversal(uid.c_str(), GetUser(UserA)->m_password, true, &tr); - tr.run(m_bc); + Logout(); +} - //WE WILL NOT HAVE A SAVED ANON ID, <> the switchauthentication call works. - EXPECT_FALSE(profileId.compare(m_bcWrapper->getStoredAnonymousId()) != 0); - #else +TEST_F(TestBCWrapper, ReconnectMissingProfile) +{ + TestResult tr; + + m_bcWrapper->initialize(m_serverUrl.c_str(), m_secret.c_str(), m_appId.c_str(), m_version.c_str(), "wrapper", "unittest"); + m_bcWrapper->authenticateAnonymous(&tr); + tr.run(m_bc); + + m_bcWrapper->logout(true, &tr); + tr.run(m_bc); + + m_bcWrapper->reconnect(&tr); + tr.runExpectFail(m_bc, HTTP_ACCEPTED, MISSING_PROFILE_ERROR); + + Logout(); +} + +TEST_F(TestBCWrapper, SmartSwitchAnonToUniversal) +{ std::string uid = GetUser(UserA)->m_id; uid.append("_wrapper"); @@ -224,16 +236,13 @@ TEST_F(TestBCWrapper, SmartSwitchAnonToUniversal) std::string anonIdtest = "\n STORED ID: " + m_bcWrapper->getStoredAnonymousId() + "\n"; std::cout<< anonIdtest; - //after testing and test cases it's noticeable that this fucntion does not work for linux. + //after testing and test cases it's noticeable that this fucntion does not work for linux. m_bcWrapper->setStoredAnonymousId(m_bcWrapper->client->getAuthenticationService()->generateAnonymousId().c_str()); - + std::string anonIdtest1 = "\n STORED ID: " + m_bcWrapper->getStoredAnonymousId() + "\n"; std::cout<< anonIdtest1; */ - //CONFIRMED : setStoredAnonymousId uses a pure virtual method save data helper, which is only implemented for Windows. Due to this it will not work on linux. - - m_bcWrapper->setStoredAnonymousId(m_bcWrapper->client->getAuthenticationService()->generateAnonymousId().c_str()); - m_bcWrapper->resetStoredProfileId(); + //CONFIRMED : setStoredAnonymousId uses a pure virtual method save data helper, which is only implemented for Windows. Due to this it will not work on linux. TestResult tr; @@ -245,42 +254,25 @@ TEST_F(TestBCWrapper, SmartSwitchAnonToUniversal) m_bcWrapper->smartSwitchAuthenticateUniversal(uid.c_str(), GetUser(UserA)->m_password, true, &tr); tr.run(m_bc); - EXPECT_TRUE(profileId.compare(m_bcWrapper->getStoredAnonymousId()) != 0); + std::string profileIdNew = m_bcWrapper->getStoredProfileId(); + + //WE WILL NOT HAVE A SAVED ANON ID, <> the switchauthentication call works. +#ifdef __linux__ + //makes it through until failure here. + EXPECT_FALSE(profileId.compare(profileIdNew) != 0); +#else + EXPECT_TRUE(profileId.compare(profileIdNew) != 0); +#endif - #endif + Logout(); } TEST_F(TestBCWrapper, SmartSwitchUniversalToEmail) { - //same reason, we have no way to properly store an anon id in linux yet - #ifdef __linux__ - std::string email = GetUser(UserA)->m_email; - size_t pos = email.find('@'); - if(pos > 0) - email.insert(pos, "_wrapper"); - m_bcWrapper->setStoredAnonymousId(m_bcWrapper->client->getAuthenticationService()->generateAnonymousId().c_str()); - m_bcWrapper->resetStoredProfileId(); - - TestResult tr; - std::string uid = GetUser(UserA)->m_id; - uid.append("_wrapper"); - m_bcWrapper->authenticateUniversal(uid.c_str(), GetUser(UserA)->m_password, true, &tr); - tr.run(m_bc); - - std::string profileId = m_bcWrapper->getStoredProfileId(); - - m_bcWrapper->smartSwitchAuthenticateEmailPassword(email.c_str(), GetUser(UserA)->m_password, true, &tr); - tr.run(m_bc); - - //makes it through until failure here. - EXPECT_FALSE(profileId.compare(m_bcWrapper->getStoredProfileId()) != 0); - #else std::string email = GetUser(UserA)->m_email; size_t pos = email.find('@'); if(pos > 0) email.insert(pos, "_wrapper"); - m_bcWrapper->setStoredAnonymousId(m_bcWrapper->client->getAuthenticationService()->generateAnonymousId().c_str()); - m_bcWrapper->resetStoredProfileId(); TestResult tr; std::string uid = GetUser(UserA)->m_id; @@ -293,9 +285,16 @@ TEST_F(TestBCWrapper, SmartSwitchUniversalToEmail) m_bcWrapper->smartSwitchAuthenticateEmailPassword(email.c_str(), GetUser(UserA)->m_password, true, &tr); tr.run(m_bc); - EXPECT_TRUE(profileId.compare(m_bcWrapper->getStoredProfileId()) != 0); + std::string profileIdNew = m_bcWrapper->getStoredProfileId(); - #endif + //same reason, we have no way to properly store an anon id in linux yet +#ifdef __linux__ + //makes it through until failure here. + EXPECT_FALSE(profileId.compare(profileIdNew) != 0); +#else + EXPECT_TRUE(profileId.compare(profileIdNew) != 0); +#endif + Logout(); } TEST_F(TestBCWrapper, ReInit) @@ -315,7 +314,7 @@ TEST_F(TestBCWrapper, ReInit) assert(initCounter == 3); initCounter++; - //case 2 + //case 2 //auth TestResult tr1; m_bcWrapper->authenticateAnonymous(&tr1); @@ -334,6 +333,3 @@ TEST_F(TestBCWrapper, ReInit) m_bc->getTimeService()->readServerTime(&tr3); tr3.runExpectFail(m_bc, HTTP_FORBIDDEN, NO_SESSION); } - -#endif - diff --git a/tests/src/TestFixtureBase.cpp b/tests/src/TestFixtureBase.cpp index fea0afcd..6435ec36 100644 --- a/tests/src/TestFixtureBase.cpp +++ b/tests/src/TestFixtureBase.cpp @@ -57,7 +57,7 @@ void TestFixtureBase::SetUp() if (!ShouldSkipAuthenticate()) { TestResult tr; - m_bc->getAuthenticationService()->authenticateUniversal(GetUser(UserA)->m_id, GetUser(UserA)->m_password, true, &tr); + m_bcWrapper->authenticateUniversal(GetUser(UserA)->m_id, GetUser(UserA)->m_password, true, &tr); tr.run(m_bc); } @@ -71,11 +71,11 @@ void TestFixtureBase::TearDown() if (!ShouldSkipAuthenticate()) { TestResult tr; - m_bc->getPlayerStateService()->logout(&tr); + m_bcWrapper->logout(true, &tr); // clears profile id tr.run(m_bc); } m_bc->resetCommunication(); - m_bc->getAuthenticationService()->clearSavedProfileId(); + m_bc->deregisterEventCallback(); m_bc->deregisterRewardCallback(); @@ -108,7 +108,7 @@ void TestFixtureBase::Init() printf("Creating test users"); for (int i = 0; i < USERS_MAX; i++) { - m_testUsers.push_back(new TestUser(Users_names[i], rand() % 100000000, m_bc)); + m_testUsers.push_back(new TestUser(Users_names[i], rand() % 100000000, m_bcWrapper)); printf("..%i", i + 1); } printf("..completed\n\n"); @@ -244,11 +244,10 @@ bool TestFixtureBase::DetachPeer() void TestFixtureBase::Logout() { TestResult tr; - m_bc->getPlayerStateService()->logout(&tr); + m_bcWrapper->logout(true, &tr); // clears saved profile id tr.run(m_bc, true); m_bc->resetCommunication(); - m_bc->getAuthenticationService()->clearSavedProfileId(); // preston - in bccomms2 (win c++) the internal thread is killed during resetCommunication. // for consistency, we re-initialize the comms to re-create the thread in case any further diff --git a/tests/src/TestUser.cpp b/tests/src/TestUser.cpp index 49bf90a9..de609512 100644 --- a/tests/src/TestUser.cpp +++ b/tests/src/TestUser.cpp @@ -4,8 +4,8 @@ using namespace std; -TestUser::TestUser(std::string prefix, int suffix, BrainCloudClient* client) : - m_client(client) +TestUser::TestUser(std::string prefix, int suffix, BrainCloudWrapper* wrapper) : + m_bcWrapper(wrapper) { std::string id = prefix + "_CPP_" + std::to_string(suffix); std::string password = id; @@ -21,19 +21,17 @@ void TestUser::Authenticate() { TestResult tr; - m_client->getAuthenticationService()->authenticateUniversal(m_id, m_password, true, &tr); - tr.run(m_client); - std::strcpy(m_profileId, m_client->getAuthenticationService()->getProfileId().c_str()); + m_bcWrapper->authenticateUniversal(m_id, m_password, true, &tr); + tr.run(m_bcWrapper->client); + std::strcpy(m_profileId, m_bcWrapper->client->getAuthenticationService()->getProfileId().c_str()); - m_client->getPlayerStateService()->updateUserName(m_id, &tr); - tr.run(m_client); + m_bcWrapper->client->getPlayerStateService()->updateUserName(m_id, &tr); + tr.run(m_bcWrapper->client); - m_client->getPlayerStateService()->updateContactEmail("braincloudunittest@gmail.com", &tr); - tr.run(m_client); + m_bcWrapper->client->getPlayerStateService()->updateContactEmail("braincloudunittest@gmail.com", &tr); + tr.run(m_bcWrapper->client); - m_client->getPlayerStateService()->logout(&tr); - tr.run(m_client); - - m_client->getAuthenticationService()->clearSavedProfileId(); + m_bcWrapper->logout(true, &tr); + tr.run(m_bcWrapper->client); } diff --git a/tests/src/TestUser.h b/tests/src/TestUser.h index e6a43913..af9147e8 100644 --- a/tests/src/TestUser.h +++ b/tests/src/TestUser.h @@ -2,7 +2,7 @@ #define _TESTUSER_H_ #include -#include "braincloud/BrainCloudClient.h" +#include "braincloud/BrainCloudWrapper.h" using namespace BrainCloud; @@ -14,7 +14,7 @@ class TestUser char m_profileId[256]; char m_email[256]; - BrainCloudClient *m_client; + BrainCloudWrapper *m_bcWrapper; TestUser() { @@ -23,7 +23,7 @@ class TestUser m_profileId[0] = '\0'; m_email[0] = '\0'; } - TestUser(std::string prefix, int suffix, BrainCloudClient *client); + TestUser(std::string prefix, int suffix, BrainCloudWrapper *wrapper); private: void Authenticate();