2014-02-10 02:10:30 +01:00
|
|
|
/*************************************************************************/
|
|
|
|
/* game_center.mm */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 14:16:55 +02:00
|
|
|
/* https://godotengine.org */
|
2014-02-10 02:10:30 +01:00
|
|
|
/*************************************************************************/
|
2020-01-01 11:16:22 +01:00
|
|
|
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
|
2014-02-10 02:10:30 +01:00
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
2018-01-05 00:50:27 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
#ifdef GAME_CENTER_ENABLED
|
|
|
|
|
|
|
|
#include "game_center.h"
|
|
|
|
|
2015-11-16 02:31:44 +01:00
|
|
|
#ifdef __IPHONE_9_0
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
#import <GameKit/GameKit.h>
|
2015-11-16 01:07:21 +01:00
|
|
|
extern "C" {
|
2015-11-16 02:31:44 +01:00
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
#import <GameKit/GameKit.h>
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2015-05-23 12:17:52 +02:00
|
|
|
#import "app_delegate.h"
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
2020-07-15 20:59:57 +02:00
|
|
|
#import "view_controller.h"
|
|
|
|
|
2017-04-09 14:18:49 +02:00
|
|
|
GameCenter *GameCenter::instance = NULL;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
void GameCenter::_bind_methods() {
|
2020-07-22 03:35:50 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("authenticate"), &GameCenter::authenticate);
|
2017-10-19 06:15:59 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("is_authenticated"), &GameCenter::is_authenticated);
|
2017-04-09 13:22:40 +02:00
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("post_score"), &GameCenter::post_score);
|
2020-07-15 20:59:57 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("award_achievement", "achievement"), &GameCenter::award_achievement);
|
2017-04-09 13:22:40 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("reset_achievements"), &GameCenter::reset_achievements);
|
|
|
|
ClassDB::bind_method(D_METHOD("request_achievements"), &GameCenter::request_achievements);
|
|
|
|
ClassDB::bind_method(D_METHOD("request_achievement_descriptions"), &GameCenter::request_achievement_descriptions);
|
|
|
|
ClassDB::bind_method(D_METHOD("show_game_center"), &GameCenter::show_game_center);
|
2017-10-19 06:15:59 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("request_identity_verification_signature"), &GameCenter::request_identity_verification_signature);
|
2017-04-09 13:22:40 +02:00
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("get_pending_event_count"), &GameCenter::get_pending_event_count);
|
|
|
|
ClassDB::bind_method(D_METHOD("pop_pending_event"), &GameCenter::pop_pending_event);
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
2020-07-22 03:35:50 +02:00
|
|
|
Error GameCenter::authenticate() {
|
2015-05-23 12:17:52 +02:00
|
|
|
//if this class isn't available, game center isn't implemented
|
|
|
|
if ((NSClassFromString(@"GKLocalPlayer")) == nil) {
|
2020-07-22 03:35:50 +02:00
|
|
|
return ERR_UNAVAILABLE;
|
2015-05-23 12:17:52 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-04-09 14:18:49 +02:00
|
|
|
GKLocalPlayer *player = [GKLocalPlayer localPlayer];
|
2020-07-22 03:35:50 +02:00
|
|
|
ERR_FAIL_COND_V(![player respondsToSelector:@selector(authenticateHandler)], ERR_UNAVAILABLE);
|
2015-05-23 12:17:52 +02:00
|
|
|
|
2017-04-09 14:18:49 +02:00
|
|
|
ViewController *root_controller = (ViewController *)((AppDelegate *)[[UIApplication sharedApplication] delegate]).window.rootViewController;
|
2020-07-22 03:35:50 +02:00
|
|
|
ERR_FAIL_COND_V(!root_controller, FAILED);
|
2015-05-23 12:17:52 +02:00
|
|
|
|
2017-04-09 14:18:49 +02:00
|
|
|
// This handler is called several times. First when the view needs to be shown, then again
|
|
|
|
// after the view is cancelled or the user logs in. Or if the user's already logged in, it's
|
|
|
|
// called just once to confirm they're authenticated. This is why no result needs to be specified
|
|
|
|
// in the presentViewController phase. In this case, more calls to this function will follow.
|
2020-10-01 21:18:39 +02:00
|
|
|
_weakify(root_controller);
|
|
|
|
_weakify(player);
|
2015-05-23 12:17:52 +02:00
|
|
|
player.authenticateHandler = (^(UIViewController *controller, NSError *error) {
|
2020-10-01 21:18:39 +02:00
|
|
|
_strongify(root_controller);
|
|
|
|
_strongify(player);
|
|
|
|
|
2017-04-09 13:22:40 +02:00
|
|
|
if (controller) {
|
|
|
|
[root_controller presentViewController:controller animated:YES completion:nil];
|
|
|
|
} else {
|
|
|
|
Dictionary ret;
|
|
|
|
ret["type"] = "authentication";
|
|
|
|
if (player.isAuthenticated) {
|
|
|
|
ret["result"] = "ok";
|
2020-07-15 20:59:57 +02:00
|
|
|
if (@available(iOS 13, *)) {
|
|
|
|
ret["player_id"] = [player.teamPlayerID UTF8String];
|
|
|
|
#if !defined(TARGET_OS_SIMULATOR) || !TARGET_OS_SIMULATOR
|
|
|
|
} else {
|
|
|
|
ret["player_id"] = [player.playerID UTF8String];
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2017-10-19 06:15:59 +02:00
|
|
|
GameCenter::get_singleton()->authenticated = true;
|
2017-04-09 13:22:40 +02:00
|
|
|
} else {
|
|
|
|
ret["result"] = "error";
|
2017-10-02 17:01:43 +02:00
|
|
|
ret["error_code"] = (int64_t)error.code;
|
2017-04-09 13:22:40 +02:00
|
|
|
ret["error_description"] = [error.localizedDescription UTF8String];
|
2017-10-19 06:15:59 +02:00
|
|
|
GameCenter::get_singleton()->authenticated = false;
|
2017-04-09 13:22:40 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
pending_events.push_back(ret);
|
|
|
|
};
|
2015-05-23 12:17:52 +02:00
|
|
|
});
|
2020-07-22 03:35:50 +02:00
|
|
|
|
|
|
|
return OK;
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
2017-10-19 06:15:59 +02:00
|
|
|
bool GameCenter::is_authenticated() {
|
|
|
|
return authenticated;
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
2020-07-15 20:59:57 +02:00
|
|
|
Error GameCenter::post_score(Dictionary p_score) {
|
|
|
|
ERR_FAIL_COND_V(!p_score.has("score") || !p_score.has("category"), ERR_INVALID_PARAMETER);
|
|
|
|
float score = p_score["score"];
|
|
|
|
String category = p_score["category"];
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2020-10-01 21:18:39 +02:00
|
|
|
NSString *cat_str = [[NSString alloc] initWithUTF8String:category.utf8().get_data()];
|
|
|
|
GKScore *reporter = [[GKScore alloc] initWithLeaderboardIdentifier:cat_str];
|
2014-02-10 02:10:30 +01:00
|
|
|
reporter.value = score;
|
|
|
|
|
2015-05-23 12:17:52 +02:00
|
|
|
ERR_FAIL_COND_V([GKScore respondsToSelector:@selector(reportScores)], ERR_UNAVAILABLE);
|
|
|
|
|
2017-04-09 14:18:49 +02:00
|
|
|
[GKScore reportScores:@[ reporter ]
|
|
|
|
withCompletionHandler:^(NSError *error) {
|
|
|
|
Dictionary ret;
|
|
|
|
ret["type"] = "post_score";
|
|
|
|
if (error == nil) {
|
|
|
|
ret["result"] = "ok";
|
|
|
|
} else {
|
|
|
|
ret["result"] = "error";
|
2017-10-02 17:01:43 +02:00
|
|
|
ret["error_code"] = (int64_t)error.code;
|
2017-04-09 14:18:49 +02:00
|
|
|
ret["error_description"] = [error.localizedDescription UTF8String];
|
|
|
|
};
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-04-09 14:18:49 +02:00
|
|
|
pending_events.push_back(ret);
|
|
|
|
}];
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
return OK;
|
|
|
|
};
|
|
|
|
|
2020-07-15 20:59:57 +02:00
|
|
|
Error GameCenter::award_achievement(Dictionary p_params) {
|
|
|
|
ERR_FAIL_COND_V(!p_params.has("name") || !p_params.has("progress"), ERR_INVALID_PARAMETER);
|
|
|
|
String name = p_params["name"];
|
|
|
|
float progress = p_params["progress"];
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2020-10-01 21:18:39 +02:00
|
|
|
NSString *name_str = [[NSString alloc] initWithUTF8String:name.utf8().get_data()];
|
|
|
|
GKAchievement *achievement = [[GKAchievement alloc] initWithIdentifier:name_str];
|
2014-02-10 02:10:30 +01:00
|
|
|
ERR_FAIL_COND_V(!achievement, FAILED);
|
|
|
|
|
2015-05-23 12:17:52 +02:00
|
|
|
ERR_FAIL_COND_V([GKAchievement respondsToSelector:@selector(reportAchievements)], ERR_UNAVAILABLE);
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
achievement.percentComplete = progress;
|
2015-05-23 12:17:52 +02:00
|
|
|
achievement.showsCompletionBanner = NO;
|
2020-07-15 20:59:57 +02:00
|
|
|
if (p_params.has("show_completion_banner")) {
|
|
|
|
achievement.showsCompletionBanner = p_params["show_completion_banner"] ? YES : NO;
|
2015-05-23 12:17:52 +02:00
|
|
|
}
|
2016-04-02 20:26:12 +02:00
|
|
|
|
2017-04-09 14:18:49 +02:00
|
|
|
[GKAchievement reportAchievements:@[ achievement ]
|
|
|
|
withCompletionHandler:^(NSError *error) {
|
|
|
|
Dictionary ret;
|
|
|
|
ret["type"] = "award_achievement";
|
|
|
|
if (error == nil) {
|
|
|
|
ret["result"] = "ok";
|
|
|
|
} else {
|
|
|
|
ret["result"] = "error";
|
2017-10-02 17:01:43 +02:00
|
|
|
ret["error_code"] = (int64_t)error.code;
|
2017-04-09 14:18:49 +02:00
|
|
|
};
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-04-09 14:18:49 +02:00
|
|
|
pending_events.push_back(ret);
|
|
|
|
}];
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
return OK;
|
|
|
|
};
|
|
|
|
|
2015-05-23 12:17:52 +02:00
|
|
|
void GameCenter::request_achievement_descriptions() {
|
|
|
|
[GKAchievementDescription loadAchievementDescriptionsWithCompletionHandler:^(NSArray *descriptions, NSError *error) {
|
|
|
|
Dictionary ret;
|
|
|
|
ret["type"] = "achievement_descriptions";
|
|
|
|
if (error == nil) {
|
|
|
|
ret["result"] = "ok";
|
2020-02-22 06:01:34 +01:00
|
|
|
PackedStringArray names;
|
|
|
|
PackedStringArray titles;
|
|
|
|
PackedStringArray unachieved_descriptions;
|
|
|
|
PackedStringArray achieved_descriptions;
|
2020-02-25 18:10:58 +01:00
|
|
|
PackedInt32Array maximum_points;
|
2015-05-24 04:04:02 +02:00
|
|
|
Array hidden;
|
|
|
|
Array replayable;
|
2016-04-02 20:26:12 +02:00
|
|
|
|
2020-07-15 20:59:57 +02:00
|
|
|
for (NSUInteger i = 0; i < [descriptions count]; i++) {
|
2017-04-09 14:18:49 +02:00
|
|
|
GKAchievementDescription *description = [descriptions objectAtIndex:i];
|
2016-04-02 20:26:12 +02:00
|
|
|
|
2017-04-09 14:18:49 +02:00
|
|
|
const char *str = [description.identifier UTF8String];
|
2015-05-23 12:17:52 +02:00
|
|
|
names.push_back(String::utf8(str != NULL ? str : ""));
|
2016-04-02 20:26:12 +02:00
|
|
|
|
2015-05-23 12:17:52 +02:00
|
|
|
str = [description.title UTF8String];
|
|
|
|
titles.push_back(String::utf8(str != NULL ? str : ""));
|
2016-04-02 20:26:12 +02:00
|
|
|
|
2015-05-23 12:17:52 +02:00
|
|
|
str = [description.unachievedDescription UTF8String];
|
|
|
|
unachieved_descriptions.push_back(String::utf8(str != NULL ? str : ""));
|
2016-04-02 20:26:12 +02:00
|
|
|
|
2015-05-23 12:17:52 +02:00
|
|
|
str = [description.achievedDescription UTF8String];
|
|
|
|
achieved_descriptions.push_back(String::utf8(str != NULL ? str : ""));
|
2016-04-02 20:26:12 +02:00
|
|
|
|
2015-05-23 12:17:52 +02:00
|
|
|
maximum_points.push_back(description.maximumPoints);
|
2016-04-02 20:26:12 +02:00
|
|
|
|
2015-05-24 04:04:02 +02:00
|
|
|
hidden.push_back(description.hidden == YES);
|
2016-04-02 20:26:12 +02:00
|
|
|
|
2015-05-24 04:04:02 +02:00
|
|
|
replayable.push_back(description.replayable == YES);
|
2015-05-23 12:17:52 +02:00
|
|
|
}
|
2016-04-02 20:26:12 +02:00
|
|
|
|
2015-05-23 12:17:52 +02:00
|
|
|
ret["names"] = names;
|
2015-05-24 04:04:02 +02:00
|
|
|
ret["titles"] = titles;
|
|
|
|
ret["unachieved_descriptions"] = unachieved_descriptions;
|
|
|
|
ret["achieved_descriptions"] = achieved_descriptions;
|
|
|
|
ret["maximum_points"] = maximum_points;
|
|
|
|
ret["hidden"] = hidden;
|
|
|
|
ret["replayable"] = replayable;
|
2016-04-02 20:26:12 +02:00
|
|
|
|
2015-05-23 12:17:52 +02:00
|
|
|
} else {
|
|
|
|
ret["result"] = "error";
|
2017-10-02 17:01:43 +02:00
|
|
|
ret["error_code"] = (int64_t)error.code;
|
2015-05-23 12:17:52 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
pending_events.push_back(ret);
|
|
|
|
}];
|
|
|
|
};
|
|
|
|
|
|
|
|
void GameCenter::request_achievements() {
|
|
|
|
[GKAchievement loadAchievementsWithCompletionHandler:^(NSArray *achievements, NSError *error) {
|
|
|
|
Dictionary ret;
|
|
|
|
ret["type"] = "achievements";
|
|
|
|
if (error == nil) {
|
|
|
|
ret["result"] = "ok";
|
2020-02-22 06:01:34 +01:00
|
|
|
PackedStringArray names;
|
2020-02-25 18:10:58 +01:00
|
|
|
PackedFloat32Array percentages;
|
2016-04-02 20:26:12 +02:00
|
|
|
|
2020-07-15 20:59:57 +02:00
|
|
|
for (NSUInteger i = 0; i < [achievements count]; i++) {
|
2017-04-09 14:18:49 +02:00
|
|
|
GKAchievement *achievement = [achievements objectAtIndex:i];
|
|
|
|
const char *str = [achievement.identifier UTF8String];
|
2015-05-23 12:17:52 +02:00
|
|
|
names.push_back(String::utf8(str != NULL ? str : ""));
|
2016-04-02 20:26:12 +02:00
|
|
|
|
2015-05-23 12:17:52 +02:00
|
|
|
percentages.push_back(achievement.percentComplete);
|
|
|
|
}
|
2016-04-02 20:26:12 +02:00
|
|
|
|
2015-05-23 12:17:52 +02:00
|
|
|
ret["names"] = names;
|
2015-05-24 04:04:02 +02:00
|
|
|
ret["progress"] = percentages;
|
2016-04-02 20:26:12 +02:00
|
|
|
|
2015-05-23 12:17:52 +02:00
|
|
|
} else {
|
|
|
|
ret["result"] = "error";
|
2017-10-02 17:01:43 +02:00
|
|
|
ret["error_code"] = (int64_t)error.code;
|
2015-05-23 12:17:52 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
pending_events.push_back(ret);
|
|
|
|
}];
|
|
|
|
};
|
|
|
|
|
|
|
|
void GameCenter::reset_achievements() {
|
2017-04-09 13:22:40 +02:00
|
|
|
[GKAchievement resetAchievementsWithCompletionHandler:^(NSError *error) {
|
2015-05-23 12:17:52 +02:00
|
|
|
Dictionary ret;
|
|
|
|
ret["type"] = "reset_achievements";
|
|
|
|
if (error == nil) {
|
|
|
|
ret["result"] = "ok";
|
|
|
|
} else {
|
|
|
|
ret["result"] = "error";
|
2017-10-02 17:01:43 +02:00
|
|
|
ret["error_code"] = (int64_t)error.code;
|
2015-05-23 12:17:52 +02:00
|
|
|
};
|
2016-04-02 20:26:12 +02:00
|
|
|
|
2015-05-23 12:17:52 +02:00
|
|
|
pending_events.push_back(ret);
|
|
|
|
}];
|
|
|
|
};
|
|
|
|
|
2020-07-15 20:59:57 +02:00
|
|
|
Error GameCenter::show_game_center(Dictionary p_params) {
|
2015-05-23 12:17:52 +02:00
|
|
|
ERR_FAIL_COND_V(!NSProtocolFromString(@"GKGameCenterControllerDelegate"), FAILED);
|
|
|
|
|
|
|
|
GKGameCenterViewControllerState view_state = GKGameCenterViewControllerStateDefault;
|
2020-07-15 20:59:57 +02:00
|
|
|
if (p_params.has("view")) {
|
|
|
|
String view_name = p_params["view"];
|
2015-05-23 12:17:52 +02:00
|
|
|
if (view_name == "default") {
|
|
|
|
view_state = GKGameCenterViewControllerStateDefault;
|
2017-04-09 13:22:40 +02:00
|
|
|
} else if (view_name == "leaderboards") {
|
2015-05-23 12:17:52 +02:00
|
|
|
view_state = GKGameCenterViewControllerStateLeaderboards;
|
2017-04-09 13:22:40 +02:00
|
|
|
} else if (view_name == "achievements") {
|
2015-05-23 12:17:52 +02:00
|
|
|
view_state = GKGameCenterViewControllerStateAchievements;
|
2017-04-09 13:22:40 +02:00
|
|
|
} else if (view_name == "challenges") {
|
2015-05-23 12:17:52 +02:00
|
|
|
view_state = GKGameCenterViewControllerStateChallenges;
|
2017-04-09 13:22:40 +02:00
|
|
|
} else {
|
2015-05-23 12:17:52 +02:00
|
|
|
return ERR_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-01 21:18:39 +02:00
|
|
|
GKGameCenterViewController *controller = [[GKGameCenterViewController alloc] init];
|
2015-05-23 12:17:52 +02:00
|
|
|
ERR_FAIL_COND_V(!controller, FAILED);
|
|
|
|
|
2017-04-09 14:18:49 +02:00
|
|
|
ViewController *root_controller = (ViewController *)((AppDelegate *)[[UIApplication sharedApplication] delegate]).window.rootViewController;
|
2015-05-23 12:17:52 +02:00
|
|
|
ERR_FAIL_COND_V(!root_controller, FAILED);
|
2016-04-02 20:26:12 +02:00
|
|
|
|
2015-05-23 12:17:52 +02:00
|
|
|
controller.gameCenterDelegate = root_controller;
|
|
|
|
controller.viewState = view_state;
|
|
|
|
if (view_state == GKGameCenterViewControllerStateLeaderboards) {
|
|
|
|
controller.leaderboardIdentifier = nil;
|
2020-07-15 20:59:57 +02:00
|
|
|
if (p_params.has("leaderboard_name")) {
|
|
|
|
String name = p_params["leaderboard_name"];
|
2020-10-01 21:18:39 +02:00
|
|
|
NSString *name_str = [[NSString alloc] initWithUTF8String:name.utf8().get_data()];
|
2015-05-23 12:17:52 +02:00
|
|
|
controller.leaderboardIdentifier = name_str;
|
|
|
|
}
|
|
|
|
}
|
2016-04-02 20:26:12 +02:00
|
|
|
|
2017-04-09 14:18:49 +02:00
|
|
|
[root_controller presentViewController:controller animated:YES completion:nil];
|
2016-04-02 20:26:12 +02:00
|
|
|
|
|
|
|
return OK;
|
2015-05-23 12:17:52 +02:00
|
|
|
};
|
|
|
|
|
2017-10-19 06:15:59 +02:00
|
|
|
Error GameCenter::request_identity_verification_signature() {
|
|
|
|
ERR_FAIL_COND_V(!is_authenticated(), ERR_UNAUTHORIZED);
|
|
|
|
|
|
|
|
GKLocalPlayer *player = [GKLocalPlayer localPlayer];
|
|
|
|
[player generateIdentityVerificationSignatureWithCompletionHandler:^(NSURL *publicKeyUrl, NSData *signature, NSData *salt, uint64_t timestamp, NSError *error) {
|
|
|
|
Dictionary ret;
|
|
|
|
ret["type"] = "identity_verification_signature";
|
|
|
|
if (error == nil) {
|
|
|
|
ret["result"] = "ok";
|
|
|
|
ret["public_key_url"] = [publicKeyUrl.absoluteString UTF8String];
|
|
|
|
ret["signature"] = [[signature base64EncodedStringWithOptions:0] UTF8String];
|
|
|
|
ret["salt"] = [[salt base64EncodedStringWithOptions:0] UTF8String];
|
|
|
|
ret["timestamp"] = timestamp;
|
2020-07-15 20:59:57 +02:00
|
|
|
if (@available(iOS 13, *)) {
|
|
|
|
ret["player_id"] = [player.teamPlayerID UTF8String];
|
|
|
|
#if !defined(TARGET_OS_SIMULATOR) || !TARGET_OS_SIMULATOR
|
|
|
|
} else {
|
|
|
|
ret["player_id"] = [player.playerID UTF8String];
|
|
|
|
#endif
|
|
|
|
}
|
2017-10-19 06:15:59 +02:00
|
|
|
} else {
|
|
|
|
ret["result"] = "error";
|
2017-10-02 17:01:43 +02:00
|
|
|
ret["error_code"] = (int64_t)error.code;
|
2017-10-19 06:15:59 +02:00
|
|
|
ret["error_description"] = [error.localizedDescription UTF8String];
|
|
|
|
};
|
|
|
|
|
|
|
|
pending_events.push_back(ret);
|
|
|
|
}];
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
};
|
|
|
|
|
2015-05-24 08:22:20 +02:00
|
|
|
void GameCenter::game_center_closed() {
|
|
|
|
Dictionary ret;
|
2017-04-09 14:18:49 +02:00
|
|
|
ret["type"] = "show_game_center";
|
2015-05-24 08:22:20 +02:00
|
|
|
ret["result"] = "ok";
|
|
|
|
pending_events.push_back(ret);
|
|
|
|
}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
int GameCenter::get_pending_event_count() {
|
|
|
|
return pending_events.size();
|
|
|
|
};
|
|
|
|
|
|
|
|
Variant GameCenter::pop_pending_event() {
|
|
|
|
Variant front = pending_events.front()->get();
|
|
|
|
pending_events.pop_front();
|
|
|
|
|
|
|
|
return front;
|
|
|
|
};
|
|
|
|
|
2017-04-09 14:18:49 +02:00
|
|
|
GameCenter *GameCenter::get_singleton() {
|
2014-02-10 02:10:30 +01:00
|
|
|
return instance;
|
|
|
|
};
|
|
|
|
|
|
|
|
GameCenter::GameCenter() {
|
|
|
|
ERR_FAIL_COND(instance != NULL);
|
|
|
|
instance = this;
|
2017-10-19 06:15:59 +02:00
|
|
|
authenticated = false;
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
2020-05-12 17:01:17 +02:00
|
|
|
GameCenter::~GameCenter() {}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
#endif
|