/*---------------------------------------------------------------------------* Project: RevolutionDWC Demos File: ./ranking/src/main.c Copyright 2005-2008 Nintendo. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo of America Inc. and/or Nintendo Company Ltd., and are protected by Federal copyright law. They may not be disclosed to third parties or copied or duplicated in any form, in whole or in part, without the prior written consent of Nintendo. *---------------------------------------------------------------------------*/ /** * * * Brief comment: This is a general-purpose ranking sample. * * This is a general-purpose ranking sample. * This sample performs three processes in order: uploading of scores, retrieval of one's own ranking, and retrieval of the top ranking list. * The program ends either when all three processes finish or when an error occurs while processing. * * Version: 1.4.10: Timeouts were implemented internally in the library. */ #include "../../common/include/common.h" // Constant definitions //--------------------------------------------------------- #define RANKING_INITDATA "hxBfMOkOvlOHpUGfQlOb0001ed350000685d0040000037012e6bdwctest" /** * Main */ void DWCDemoMain() { DWCAccUserData userdata; // DWC user data DWCRnkError res; // For ranking library error acquisition DWCRnkGetParam param; // Parameters for acquiring ranking u32 order; u32 count; int i; //--------------------------------- // Login process //--------------------------------- // // Perform the user data acquisition process here. // Because the ranking library is dependent on GameSpy, the initialization will fail unless the user data shows it has successfully logged in at least once and has a valid GameSpyProfileID. // // A temporary ID is not valid. // // If a user data obtained from a previous login is saved as a backup, this can be used. // However, as set down in the guidelines, be aware that you will always need to log in each time you connect to the Internet. // // // // When an external authentication server is used, a valid GameSpyProfileID cannot be acquired, so the ranking library cannot be used. // In such a case, the GameSpy server resources cannot be used. // // // // // For the sake of simplicity in this sample, we are forcing the user data to be generated, but you should actually use the proper user data acquired by logging in. // // When any other data is passed, while the ranking module initialization may be successful, the operation will be undefined. // // { u32 dummyuserdata[] = { 0x00000040,0x12345678,0x87654321,0xabcdef12, 0x00000996,0xfedcba34,0x12345678,0x000186a0, 0x87654321,0xabcdef12,0xfedcba34,0x12345678, 0x87654321,0xabcdef12,0xfedcba34,0x7861237f }; DWCi_Np_CpuCopy8( dummyuserdata, &userdata, DWC_ACC_USERDATA_BUFSIZE ); } //--------------------------------- // Ranking Module Process //--------------------------------- // Ranking Module Initialization //------------------------------ res = DWC_RnkInitialize( RANKING_INITDATA, &userdata ); switch ( res ) { case DWC_RNK_SUCCESS: DWCDemoPrintf("DWC_RnkInitialize success\n"); break; case DWC_RNK_ERROR_INIT_ALREADYINITIALIZED: DWCDemoPrintf("[err]DWC_RnkInitialize already initialized\n"); goto exit; case DWC_RNK_ERROR_INIT_INVALID_INITDATASIZE: DWCDemoPrintf("[err]DWC_RnkInitialize invalid init data size\n"); goto exit; case DWC_RNK_ERROR_INIT_INVALID_INITDATA: DWCDemoPrintf("[err]DWC_RnkInitialize invalid init data\n"); goto exit; case DWC_RNK_ERROR_INIT_INVALID_USERDATA: DWCDemoPrintf("[err]DWC_RnkInitialize invaild user data\n"); goto exit; } // Upload //------------------------------ // Start score upload request res = DWC_RnkPutScoreAsync( 10, // category DWC_RNK_REGION_JP, // region 1234, // score (void*)"test data", // user defined data strlen("test data") + 1 ); switch ( res ) { case DWC_RNK_SUCCESS: DWCDemoPrintf("DWC_RnkPutScoreAsync success\n"); break; case DWC_RNK_IN_ERROR: DWCDemoPrintf("[err]DWC_RnkPutScoreAsync in error\n"); goto exit; case DWC_RNK_ERROR_PUT_NOTREADY: DWCDemoPrintf("[err]DWC_RnkPutScoreAsync not initialized\n"); goto exit; case DWC_RNK_ERROR_INVALID_PARAMETER: DWCDemoPrintf("[err]DWC_RnkPutScoreAsync invalid parameter\n"); goto exit; case DWC_RNK_ERROR_PUT_INVALID_KEY: DWCDemoPrintf("[err]DWC_RnkPutScoreAsync invalid key\n"); goto exit; case DWC_RNK_ERROR_PUT_NOMEMORY: DWCDemoPrintf("[err]DWC_RnkPutScoreAsync nomemory\n"); goto exit; } // Asynchronous process while ( (res = DWC_RnkProcess()) == DWC_RNK_SUCCESS ) { DWCDemoUpdate(); } switch ( res ) { case DWC_RNK_PROCESS_TIMEOUT: DWCDemoPrintf("Timed out!!\n"); goto exit; case DWC_RNK_IN_ERROR: DWCDemoPrintf("[err]DWC_RnkProcess in error [code:%d]\n", DWC_GetLastError( NULL ) ); goto exit; case DWC_RNK_PROCESS_NOTASK: DWCDemoPrintf("DWC_RnkProcess done\n"); break; } // Get network communications results switch ( DWC_RnkGetState() ) { case DWC_RNK_STATE_COMPLETED: DWCDemoPrintf("DWC_RnkProcess Succeeded \n"); break; case DWC_RNK_STATE_ERROR: DWCDemoPrintf("[err]DWC_RnkGetState [code:%d]\n", DWC_RnkGetState() ); goto exit; } // Get own ranking //------------------------------ // Start the request for ranking param.size = sizeof( param.order ); param.order.since = 0; param.order.sort = DWC_RNK_ORDER_ASC; res = DWC_RnkGetScoreAsync( DWC_RNK_GET_MODE_ORDER, // mode 10, // category DWC_RNK_REGION_JP, // region ¶m ); // parameter switch ( res ) { case DWC_RNK_SUCCESS: DWCDemoPrintf("DWC_RnkGetScoreAsync success\n"); break; case DWC_RNK_IN_ERROR: DWCDemoPrintf("[err]DWC_RnkGetScoreAsync in error\n"); goto exit; case DWC_RNK_ERROR_GET_NOTREADY: DWCDemoPrintf("[err]DWC_RnkGetScoreAsync not initialized\n"); goto exit; case DWC_RNK_ERROR_INVALID_PARAMETER: DWCDemoPrintf("[err]DWC_RnkGetScoreAsync invalid parameter\n"); goto exit; case DWC_RNK_ERROR_GET_INVALID_KEY: DWCDemoPrintf("[err]DWC_RnkGetScoreAsync invalid key\n"); goto exit; case DWC_RNK_ERROR_GET_NOMEMORY: DWCDemoPrintf("[err]DWC_RnkGetScoreAsync nomemory\n"); goto exit; } // Asynchronous process while ( (res = DWC_RnkProcess()) == DWC_RNK_SUCCESS ) { DWCDemoUpdate(); } switch ( res ) { case DWC_RNK_PROCESS_TIMEOUT: DWCDemoPrintf("Timed out!!\n"); goto exit; case DWC_RNK_IN_ERROR: DWCDemoPrintf("[err]DWC_RnkProcess in error [code:%d]\n", DWC_GetLastError( NULL ) ); goto exit; case DWC_RNK_PROCESS_NOTASK: DWCDemoPrintf("DWC_RnkProcess done\n"); break; } // Get network communications results switch ( DWC_RnkGetState() ) { case DWC_RNK_STATE_COMPLETED: DWCDemoPrintf("DWC_RnkProcess success \n"); break; case DWC_RNK_STATE_ERROR: DWCDemoPrintf("[err]DWC_RnkGetState [code:%d]\n", DWC_GetLastError( NULL ) ); goto exit; } // Display res = DWC_RnkResGetOrder( &order ); switch ( res ) { case DWC_RNK_SUCCESS: break; case DWC_RNK_IN_ERROR: DWCDemoPrintf("[err]DWC_RnkResGetOrder in error [code:%d]\n", DWC_GetLastError( NULL ) ); goto exit; case DWC_RNK_ERROR_INVALID_MODE: DWCDemoPrintf("[err]DWC_RnkResGetOrder invalid mode\n"); goto exit; case DWC_RNK_ERROR_INVALID_PARAMETER: DWCDemoPrintf("[err]DWC_RnkResGetOrder invalid parameter\n"); goto exit; case DWC_RNK_ERROR_NOTCOMPLETED: DWCDemoPrintf("[err]DWC_RnkResGetOrder not completed\n"); goto exit; case DWC_RNK_ERROR_EMPTY_RESPONSE: DWCDemoPrintf("[err]DWC_RnkResGetOrder empty response\n"); goto exit; } DWCDemoPrintf("order=%d\n", order); // Get ranking //------------------------------ // Start top ranking acquisition request param.size = sizeof( param.toplist ); param.toplist.sort = DWC_RNK_ORDER_DES; param.toplist.limit = 10; param.toplist.since = 0; res = DWC_RnkGetScoreAsync( DWC_RNK_GET_MODE_TOPLIST, // mode 10, // category DWC_RNK_REGION_JP, // region ¶m ); // parameter switch ( res ) { case DWC_RNK_SUCCESS: DWCDemoPrintf("DWC_RnkGetScoreAsync success\n"); break; case DWC_RNK_IN_ERROR: DWCDemoPrintf("[err]DWC_RnkGetScoreAsync in error\n"); goto exit; case DWC_RNK_ERROR_GET_NOTREADY: DWCDemoPrintf("[err]DWC_RnkGetScoreAsync not initialized\n"); goto exit; case DWC_RNK_ERROR_INVALID_PARAMETER: DWCDemoPrintf("[err]DWC_RnkGetScoreAsync invalid parameter\n"); goto exit; case DWC_RNK_ERROR_GET_INVALID_KEY: DWCDemoPrintf("[err]DWC_RnkGetScoreAsync invalid key\n"); goto exit; case DWC_RNK_ERROR_GET_NOMEMORY: DWCDemoPrintf("[err]DWC_RnkGetScoreAsync nomemory\n"); goto exit; } // Asynchronous process while ( (res = DWC_RnkProcess()) == DWC_RNK_SUCCESS ) { DWCDemoUpdate(); } switch ( res ) { case DWC_RNK_PROCESS_TIMEOUT: DWCDemoPrintf("Timed out!!\n"); goto exit; case DWC_RNK_IN_ERROR: DWCDemoPrintf("[err]DWC_RnkProcess in error [code:%d]\n", DWC_GetLastError( NULL ) ); goto exit; case DWC_RNK_PROCESS_NOTASK: DWCDemoPrintf("DWC_RnkProcess done\n"); break; } // Get network communications results switch ( DWC_RnkGetState() ) { case DWC_RNK_STATE_COMPLETED: DWCDemoPrintf("DWC_RnkProcess success \n"); break; case DWC_RNK_STATE_ERROR: DWCDemoPrintf("[err]DWC_RnkGetState [code:%d]\n", DWC_GetLastError( NULL ) ); goto exit; } // Get list res = DWC_RnkResGetRowCount( &count ); switch ( res ) { case DWC_RNK_SUCCESS: break; case DWC_RNK_IN_ERROR: DWCDemoPrintf("[err]DWC_RnkResGetRowCount in error [code:%d]\n", DWC_GetLastError( NULL ) ); goto exit; case DWC_RNK_ERROR_INVALID_MODE: DWCDemoPrintf("[err]DWC_RnkResGetRowCount invalid mode\n"); goto exit; case DWC_RNK_ERROR_INVALID_PARAMETER: DWCDemoPrintf("[err]DWC_RnkResGetRowCount invalid parameter\n"); goto exit; case DWC_RNK_ERROR_NOTCOMPLETED: DWCDemoPrintf("[err]DWC_RnkResGetRowCount not completed\n"); goto exit; case DWC_RNK_ERROR_EMPTY_RESPONSE: DWCDemoPrintf("[err]DWC_RnkResGetRowCount empty response\n"); goto exit; } for ( i=0; i<(int)count; i++ ) { DWCRnkData data; if ( DWC_RnkResGetRow( &data, (u32)i ) != DWC_RNK_SUCCESS ) { DWCDemoPrintf("[err]DWC_RnkResGetRow()\n"); break; } // // NOTE // Ranking is detected by one's own self. // Refer to the Programming Manual for conditions on placing a value in data.order. // DWCDemoPrintf("%dth score=%d pid=%d region=%d usrdatalen=%d\n", i + 1, // * Not data.order data.score, data.pid, data.region, data.size ); } DWCDemoUpdate(); exit: // End ranking module DWC_RnkShutdown(); // If an error has occurred, clear it. { int errorCode; DWCErrorType errorType; if ( DWC_GetLastErrorEx( &errorCode, &errorType ) != DWC_ERROR_NONE ) { DWCDemoPrintf( "DWC_GetLastErrorEx ErrorCode:%d ErrorType:%d\n", errorCode, (int)errorType ); // Clear the errors. DWC_ClearError(); } } }