Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pass total_entries through lbinfo APIs #355

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions include/rc_api_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ typedef struct rc_api_fetch_leaderboard_info_response_t {
/* The number of items in the entries array */
uint32_t num_entries;

/* The total number of entries on the server */
uint32_t total_entries;

/* Common server-provided response information */
rc_api_response_t response;
}
Expand Down
1 change: 1 addition & 0 deletions include/rc_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,7 @@ typedef struct rc_client_leaderboard_entry_t {
typedef struct rc_client_leaderboard_entry_list_t {
rc_client_leaderboard_entry_t* entries;
uint32_t num_entries;
uint32_t total_entries;
int32_t user_index;
} rc_client_leaderboard_entry_list_t;

Expand Down
5 changes: 4 additions & 1 deletion src/rapi/rc_api_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,8 @@ int rc_api_process_fetch_leaderboard_info_server_response(rc_api_fetch_leaderboa
RC_JSON_NEW_FIELD("LBAuthor"),
RC_JSON_NEW_FIELD("LBCreated"),
RC_JSON_NEW_FIELD("LBUpdated"),
RC_JSON_NEW_FIELD("Entries") /* array */
RC_JSON_NEW_FIELD("Entries"), /* array */
RC_JSON_NEW_FIELD("TotalEntries")
/* unused fields
RC_JSON_NEW_FIELD("GameTitle"),
RC_JSON_NEW_FIELD("ConsoleID"),
Expand Down Expand Up @@ -235,6 +236,8 @@ int rc_api_process_fetch_leaderboard_info_server_response(rc_api_fetch_leaderboa
return RC_MISSING_VALUE;
if (!rc_json_get_required_datetime(&response->updated, &response->response, &leaderboarddata_fields[9], "LBUpdated"))
return RC_MISSING_VALUE;
if (!rc_json_get_required_unum(&response->total_entries, &response->response, &leaderboarddata_fields[11], "TotalEntries"))
return RC_MISSING_VALUE;

if (!leaderboarddata_fields[1].value_end)
return RC_MISSING_VALUE;
Expand Down
1 change: 1 addition & 0 deletions src/rc_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -4311,6 +4311,7 @@ static void rc_client_fetch_leaderboard_entries_callback(const rc_api_server_res
}

list->num_entries = lbinfo_response.num_entries;
list->total_entries = lbinfo_response.total_entries;

lbinfo_callback_data->callback(RC_OK, NULL, list, client, lbinfo_callback_data->callback_userdata);
}
Expand Down
9 changes: 6 additions & 3 deletions test/rapi/test_rc_api_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ static void test_process_fetch_leaderboard_info_response() {
const char* server_response = "{\"Success\":true,\"LeaderboardData\":{\"LBID\":1234,\"GameID\":2345,"
"\"LowerIsBetter\":1,\"LBTitle\":\"Title\",\"LBDesc\":\"Description\",\"LBFormat\":\"TIME\","
"\"LBMem\":\"STA:0xH0000=1::CAN:1=1::SUB:0xH0000=2::VAL:b0x 0004\",\"LBAuthor\":null,"
"\"LBCreated\":\"2013-10-20 22:12:21\",\"LBUpdated\":\"2021-06-14 08:18:19\","
"\"LBCreated\":\"2013-10-20 22:12:21\",\"LBUpdated\":\"2021-06-14 08:18:19\",\"TotalEntries\":12,"
"\"Entries\":[{\"User\":\"Player1\",\"Score\":8765,\"Rank\":1,\"Index\":5,\"DateSubmitted\":1615654895},"
"{\"User\":\"Player2\",\"Score\":7654,\"Rank\":2,\"Index\":6,\"DateSubmitted\":1600604303}]"
"}}";
Expand All @@ -203,6 +203,7 @@ static void test_process_fetch_leaderboard_info_response() {
ASSERT_STR_EQUALS(fetch_leaderboard_info_response.definition, "STA:0xH0000=1::CAN:1=1::SUB:0xH0000=2::VAL:b0x 0004");
ASSERT_PTR_NULL(fetch_leaderboard_info_response.author);
ASSERT_NUM_EQUALS(fetch_leaderboard_info_response.num_entries, 2);
ASSERT_NUM_EQUALS(fetch_leaderboard_info_response.total_entries, 12);
ASSERT_NUM_EQUALS(fetch_leaderboard_info_response.created, 1382307141);
ASSERT_NUM_EQUALS(fetch_leaderboard_info_response.updated, 1623658699);

Expand All @@ -228,7 +229,7 @@ static void test_process_fetch_leaderboard_info_response2() {
const char* server_response = "{\"Success\":true,\"LeaderboardData\":{\"LBID\":9999,\"GameID\":2222,"
"\"LowerIsBetter\":0,\"LBTitle\":\"Title2\",\"LBDesc\":\"Description2\",\"LBFormat\":\"SCORE\","
"\"LBMem\":\"STA:0xH0000=1::CAN:1=1::SUB:0xH0000=2::VAL:b0x 0004\",\"LBAuthor\":\"AuthorName\","
"\"LBCreated\":\"2021-06-18 15:32:16\",\"LBUpdated\":\"2021-06-18 15:32:16\","
"\"LBCreated\":\"2021-06-18 15:32:16\",\"LBUpdated\":\"2021-06-18 15:32:16\",\"TotalEntries\":12,"
"\"Entries\":[{\"User\":\"Player1\",\"Score\":1013580,\"Rank\":1,\"Index\":5,\"DateSubmitted\":1624055310},"
"{\"User\":\"Player2\",\"Score\":133340,\"Rank\":1,\"Index\":6,\"DateSubmitted\":1624166772}]"
"}}";
Expand All @@ -246,6 +247,7 @@ static void test_process_fetch_leaderboard_info_response2() {
ASSERT_STR_EQUALS(fetch_leaderboard_info_response.definition, "STA:0xH0000=1::CAN:1=1::SUB:0xH0000=2::VAL:b0x 0004");
ASSERT_STR_EQUALS(fetch_leaderboard_info_response.author, "AuthorName");
ASSERT_NUM_EQUALS(fetch_leaderboard_info_response.num_entries, 2);
ASSERT_NUM_EQUALS(fetch_leaderboard_info_response.total_entries, 12);
ASSERT_NUM_EQUALS(fetch_leaderboard_info_response.created, 1624030336);
ASSERT_NUM_EQUALS(fetch_leaderboard_info_response.updated, 1624030336);

Expand All @@ -271,7 +273,7 @@ static void test_process_fetch_leaderboard_info_response_iso8601() {
const char* server_response = "{\"Success\":true,\"LeaderboardData\":{\"LBID\":1234,\"GameID\":2345,"
"\"LowerIsBetter\":1,\"LBTitle\":\"Title\",\"LBDesc\":\"Description\",\"LBFormat\":\"TIME\","
"\"LBMem\":\"STA:0xH0000=1::CAN:1=1::SUB:0xH0000=2::VAL:b0x 0004\",\"LBAuthor\":null,"
"\"LBCreated\":\"2013-10-20T22:12:21.000000Z\",\"LBUpdated\":\"2021-06-14T08:18:19.000000Z\","
"\"LBCreated\":\"2013-10-20T22:12:21.000000Z\",\"LBUpdated\":\"2021-06-14T08:18:19.000000Z\",\"TotalEntries\":12,"
"\"Entries\":[{\"User\":\"Player1\",\"Score\":8765,\"Rank\":1,\"Index\":5,\"DateSubmitted\":1615654895},"
"{\"User\":\"Player2\",\"Score\":7654,\"Rank\":2,\"Index\":6,\"DateSubmitted\":1600604303}]"
"}}";
Expand All @@ -289,6 +291,7 @@ static void test_process_fetch_leaderboard_info_response_iso8601() {
ASSERT_STR_EQUALS(fetch_leaderboard_info_response.definition, "STA:0xH0000=1::CAN:1=1::SUB:0xH0000=2::VAL:b0x 0004");
ASSERT_PTR_NULL(fetch_leaderboard_info_response.author);
ASSERT_NUM_EQUALS(fetch_leaderboard_info_response.num_entries, 2);
ASSERT_NUM_EQUALS(fetch_leaderboard_info_response.total_entries, 12);
ASSERT_NUM_EQUALS(fetch_leaderboard_info_response.created, 1382307141);
ASSERT_NUM_EQUALS(fetch_leaderboard_info_response.updated, 1623658699);

Expand Down
8 changes: 5 additions & 3 deletions test/test_rc_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -5068,7 +5068,7 @@ static void test_leaderboard_list_hidden(void)
static const char* lbinfo_4401_top_10 = "{\"Success\":true,\"LeaderboardData\":{\"LBID\":4401,\"GameID\":1234,"
"\"LowerIsBetter\":1,\"LBTitle\":\"Leaderboard1\",\"LBDesc\":\"Desc1\",\"LBFormat\":\"SCORE\","
"\"LBMem\":\"STA:0xH000C=1::CAN:0xH000D=1::SUB:0xH000D=2::VAL:0x 000E\",\"LBAuthor\":null,"
"\"LBCreated\":\"2013-10-20 22:12:21\",\"LBUpdated\":\"2021-06-14 08:18:19\","
"\"LBCreated\":\"2013-10-20 22:12:21\",\"LBUpdated\":\"2021-06-14 08:18:19\",\"TotalEntries\":78,"
"\"Entries\":["
"{\"User\":\"PlayerG\",\"Score\":3524,\"Rank\":1,\"Index\":1,\"DateSubmitted\":1615654895},"
"{\"User\":\"PlayerB\",\"Score\":3645,\"Rank\":2,\"Index\":2,\"DateSubmitted\":1615634566},"
Expand All @@ -5086,7 +5086,7 @@ static const char* lbinfo_4401_top_10 = "{\"Success\":true,\"LeaderboardData\":{
static const char* lbinfo_4401_top_10_no_user = "{\"Success\":true,\"LeaderboardData\":{\"LBID\":4401,\"GameID\":1234,"
"\"LowerIsBetter\":1,\"LBTitle\":\"Leaderboard1\",\"LBDesc\":\"Desc1\",\"LBFormat\":\"SCORE\","
"\"LBMem\":\"STA:0xH000C=1::CAN:0xH000D=1::SUB:0xH000D=2::VAL:0x 000E\",\"LBAuthor\":null,"
"\"LBCreated\":\"2013-10-20 22:12:21\",\"LBUpdated\":\"2021-06-14 08:18:19\","
"\"LBCreated\":\"2013-10-20 22:12:21\",\"LBUpdated\":\"2021-06-14 08:18:19\",\"TotalEntries\":78,"
"\"Entries\":["
"{\"User\":\"PlayerG\",\"Score\":3524,\"Rank\":1,\"Index\":1,\"DateSubmitted\":1615654895},"
"{\"User\":\"PlayerB\",\"Score\":3645,\"Rank\":2,\"Index\":2,\"DateSubmitted\":1615634566},"
Expand All @@ -5104,7 +5104,7 @@ static const char* lbinfo_4401_top_10_no_user = "{\"Success\":true,\"Leaderboard
static const char* lbinfo_4401_near_user = "{\"Success\":true,\"LeaderboardData\":{\"LBID\":4401,\"GameID\":1234,"
"\"LowerIsBetter\":1,\"LBTitle\":\"Leaderboard1\",\"LBDesc\":\"Desc1\",\"LBFormat\":\"SCORE\","
"\"LBMem\":\"STA:0xH000C=1::CAN:0xH000D=1::SUB:0xH000D=2::VAL:0x 000E\",\"LBAuthor\":null,"
"\"LBCreated\":\"2013-10-20 22:12:21\",\"LBUpdated\":\"2021-06-14 08:18:19\","
"\"LBCreated\":\"2013-10-20 22:12:21\",\"LBUpdated\":\"2021-06-14 08:18:19\",\"TotalEntries\":78,"
"\"Entries\":["
"{\"User\":\"PlayerG\",\"Score\":3524,\"Rank\":17,\"Index\":17,\"DateSubmitted\":1615654895},"
"{\"User\":\"PlayerB\",\"Score\":3645,\"Rank\":18,\"Index\":18,\"DateSubmitted\":1615634566},"
Expand Down Expand Up @@ -5146,6 +5146,7 @@ static void test_fetch_leaderboard_entries(void)
ASSERT_PTR_NOT_NULL(g_leaderboard_entries);

ASSERT_NUM_EQUALS(g_leaderboard_entries->num_entries, 10);
ASSERT_NUM_EQUALS(g_leaderboard_entries->total_entries, 78);

entry = g_leaderboard_entries->entries;
ASSERT_STR_EQUALS(entry->user, "PlayerG");
Expand Down Expand Up @@ -5288,6 +5289,7 @@ static void test_fetch_leaderboard_entries_around_user(void)
ASSERT_PTR_NOT_NULL(g_leaderboard_entries);

ASSERT_NUM_EQUALS(g_leaderboard_entries->num_entries, 10);
ASSERT_NUM_EQUALS(g_leaderboard_entries->total_entries, 78);

entry = g_leaderboard_entries->entries;
ASSERT_STR_EQUALS(entry->user, "PlayerG");
Expand Down
Loading