Jump to: navigation, search

User System API

Revision as of 17:49, 22 October 2014 by Huangyanli (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Set Listener

The user system has received a callback message and we need to set listener class and override listener method.

class PluginChannel:public UserActionListener
{
public:
	virtual void onActionResult(ProtocolUser* pPlugin, UserActionResultCode code, const char* msg);
}
The developers need to override the onActionResult method.
 if(AgentManager::getInstance()->getUserPlugin())
    {
    	AgentManager::getInstance()->getUserPlugin()->setActionListener(this);
    }

Related APIs

Initialization

All SDKs will be initialized when loading plug-ins and need no extra effort from developers. Callback message:

Callback Message code msg
Initialization Succeeded kInitSuccess null or simple description of the error
Initialization Failed kInitFail null or simple description of the error
switch(code)
{
case kInitSuccess://Callback of SDK initialization succeeded
	//SDK initialization succeeded; the developer should deal with this accordingly
	break;
case kInitFail://Callback of SDK initialization failed
	//SDK initialization succeeded; the developer should deal with this accordingly
        break;
}

Login

1.Login Process Description
Oauth-login.jpg
1.The client calls login API (sends login request to channel server)
2.Login succeeds and channel server returns verification code
3.AnySDK framework requests game server for login verification with the verification code
4.Game server forwards the verification coade to AnySDK server
5.AnySDK server verifies user login for the channel server
6.AnySDK receives verification result
7.AnySDK forwards the result to game server
8.Game server notifies AnySDK framework with verification result
9. AnySDK recalls whether login succeeds to the game client


2. Login function
Method 1:void login();
Method 2:void login(std::string server_id);
Note: usage scene of method 2 newly added: select a server before login, passes the parameter server id and after the plug-in initialization finishes, you can start to call the login API.
Callback Info. code msg
Login Succeeds kLoginSuccess The msg from game server to client
Login failed kLoginFail null or simple description of error
Login Network Error kLoginNetworkError null or simple description of error
Already Logged in kLoginNoNeed null or simple description of error
Login Cancelled kLoginCancel null or simple description of error
Take an example
//Calls user system login function
void PluginChannel::login()
{
	if(AgentManager::getInstance()->getUserPlugin())
	{
		AgentManager::getInstance()->getUserPlugin()->login();
	}
}

//deals with callback function
switch(code)
{
case kLoginSuccess://Callback of login success
//Login succeeds and developer deals with this accordingly
     break;
case kLoginTimeOut://Callback of login failure
case kLoginCancel://Callback of login cancellation
case kLoginFail://Callback of login failure
//Login fails and developer deals with it accordingly
	break;
}
3. Current Login Status
bool isLogined()
You can verify your login status via calling this function
4. Acquiring the unique user ID
std::string getUserID()
the unique user ID

Logout

void logout();
There are two types of logout account: one can be called in any scene to logout current logged in account by developers and the other is for players to select to log out current account at the platform interface.
Callback Info.
Callback Info. code msg
Logout Succeeded kLogoutSuccess null or simple description of error
Logout Failed kLogoutFail null or simple description of error
For example:
//Call the user system logout function
void PluginChannel::logout()
{
	if(AgentManager::getInstance()->getUserPlugin())
	{
		if(isSupportFunction("logout"))
		{

			AgentManager::getInstance()->getUserPlugin()->callFuncWithParam("logout",NULL);
		}
	}
}

//Deal with callback function	
switch(code)
{
case kLogoutSuccess://Callback of user logout success
//Logout succeeds; developer deals with it accordingly
	break;
case kLogoutFail://Callback of exiting platform center
//Logout fails; developer deals with this accordingly
	break;

}

Enter the Platform Center

void enterPlatform();
Enter the homepage of the platform center
Callback info.
Callback info. code msg
Enter the platform center kPlatformEnter null or simple description of error
Exit the platform center kPlatformBack null or simple description of error
example:
//Call the user system entering platform center function
void PluginChannel::enterPlatform()
{
	if(AgentManager::getInstance()->getUserPlugin())
	{
		//isFunctionSupported can be used to verify if the plug-in supports this feature
		if(isFunctionSupported("enterPlatform"))
		{
			AgentManager::getInstance()->getUserPlugin()->callFuncWithParam("enterPlatform",NULL);
		}
	}

}

//Deal with callback function
switch(code)
{
case kPlatformEnter://Platform center enters callback
	break;
case kPlatformBack://Platform center exits callback
	break;

}

Display Floating Toolbar

void showToolBar(ToolBarPlace place)
the original location of the floating toolbar, which functions only at the first entering and afterward, the toolbar would be at the same place the last time it was left at; in total 6 values can be set.
Corresponding status code Description
ToolBarPlace.kToolBarTopLeft value=1;Upper left corner
ToolBarPlace.kToolBarTopRight value=2;Upper right corner
ToolBarPlace.kToolBarMidLeft value=3;Middle of left
ToolBarPlace.kToolBarMidRight value=4;Middle of right
ToolBarPlace.kToolBarBottomLeft value=5;Lower left corner
ToolBarPlace.kToolBarBottomRight value=6;Lower right corner
example:
@Override
protected void onResume() {
	// TODO Auto-generated method stub	
	super.onResume();
	wrapper.nativeShowToolBar();
}

void Java_com_anysdk_sample_wrapper_nativeShowToolBar(JNIEnv*  env, jobject thiz)
{
	if(AgentManager::getInstance()->getUserPlugin())
	{
		if(isSupportFunction("showToolBar"))
		{
			PluginParam paramInfo(place);
			AgentManager::getInstance()->getUserPlugin()->callFuncWithParam("showToolBar",&paramInfo,NULL);
		}
	}
}

Hide the Floating Toolbar

void hideToolBar()
The developer needs to call this API when the game is at pause or switched to backend.
example
//Hide the floating button when at pause
	@Override
	public void onPause()
	{
		super.onPause();
		wrapper.nativeHideToolBar();//call jni	
	}
void Java_com_anysdk_sample_wrapper_nativeShowToolBar(JNIEnv*  env, jobject thiz)
{
	if(AgentManager::getInstance()->getUserPlugin())
	{
		if(isSupportFunction("hideToolBar"))
		{
			AgentManager::getInstance()->getUserPlugin()->callFuncWithParam("hideToolBar",NULL);
		}

	}
}

Switch Account

void accountSwitch()
The developer needs to add a “Switch Account” API to the menu to allow users to switch accounts with convenience.
Callback Info.
Callback Info. code msg
Account switch succeeds kAccountSwitchSuccess null or simple description of error
Account switch

fails

kAccountSwitchFail null or simple description of error
example
//User system calls “switch account” function
void PluginChannel::accountSwitch()
{
	if(AgentManager::getInstance()->getUserPlugin())
	{
		if(isSupportFunction("accountSwitch"))
		{
			AgentManager::getInstance()->getUserPlugin()->callFuncWithParam("accountSwitch",NULL);
		}

	}

}


//Deal with callback function
switch(code)
{
case kAccountSwitchSuccess://Callback of account switch success
//Account switch succeeds; the developer should deal with it accordingly
	break;
case kAccountSwitchFail://Callback of account switch failure
//Account switch fails; the developer should deal with it accordingly
	break;

}

Exit Interface

void exit()
Call this function when exiting the game.
Callback Info.
Callback Info. code msg
Exit succeeds kExitPage null or simple description of error
example:
//To decide if to click return botton
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		// TODO Auto-generated method stub
		if(keyCode == KeyEvent.KEYCODE_BACK){

			if (wrapper.IsSupportFunction("exit")) {
				wrapper.nativeExit();
				
				return true;
			}
		}
		return super.onKeyDown(keyCode, event);
	}
//jni calls exit function
void Java_com_ansdk_sample_wrapper_nativeExit(JNIEnv*  env, jobject thiz)
{
		if(AgentManager::getInstance()->getUserPlugin())
	{
		if(isSupportFunction("exit"))
		{
			AgentManager::getInstance()->getUserPlugin()->callFuncWithParam("exit",NULL);
		}

	}
}

Pause Interface

void pause()
Call this function when the game pauses.
Callback Info.
Callback Info. code msg
Exiting the interface succeeds kPausePage null or simple description of error
Example
//To decide if to switch to frontend from backend
public boolean isAppOnForeground() {
			ActivityManager activityManager = (ActivityManager) getApplicationContext()
					.getSystemService(Context.ACTIVITY_SERVICE);
			String packageName = getApplicationContext().getPackageName();
			List<RunningAppProcessInfo> appProcesses = activityManager.getRunningAppProcesses();
			if (appProcesses == null)
				return false;
			for (RunningAppProcessInfo appProcess : appProcesses) {
				if (appProcess.processName.equals(packageName)
						&& appProcess.importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
					return true;
				}
			}
			return false;
		} 
	 private boolean isAppForeground = true;

	 @Override
	protected void onStop() {
		 // TODO Auto-generated method stub
		 super.onStop();
		if(!isAppOnForeground()){
			isAppForeground = false;
		}
	}	
	 
	@Override
	protected void onResume() {
		// TODO Auto-generated method stub	
		super.onResume();
		
		if(!isAppForeground){
			wrapper.nativePause();//Call destroy API through jni
			isAppForeground = true;			
		}
	}
//jni calls pause function
void Java_com_anysdk_sample_wrapper_nativePause(JNIEnv*  env, jobject thiz)
{
	if(AgentManager::getInstance()->getUserPlugin())
    {
		if(isSupportFunction(“pause"))
		{
			AgentManager::getInstance()->getUserPlugin()->callFuncWithParam("pause",NULL);
		}
	}
}

Release Resources

void destroy()
This method needs to be called before exiting the game to conduct cleaning work. If the game is exited without calling the method, unknown errors might occur and cause breakdown.
Example
//Override onDestroy function at the main activity
@Override
protected void onDestroy() {
	super.onDestroy();
	wrapper.nativeDestroy();//call destroy API via jni
};

void Java_com_anysdk_sample_wrapper_nativeDestroy(JNIEnv*  env, jobject thiz)
{
    if(AgentManager::getInstance()->getUserPlugin())
	{
		if(isSupportFunction("destroy"))
		{
			AgentManager::getInstance()->getUserPlugin()->callFuncWithParam("destroy",NULL);
		}

	}
}

Special Channel API

Real-name Registration (Qihu 360)

void realNameRegister()
Introduction:
Provides real-name registration API; when the operator calls anti-addiction API and notices a user who hasn’t filled in real-name registration info., the operator can launch real-name registration via this API.
Callback Info.
Callback Info. code msg
Real-name registration

callback

kRealNameRegister null or simple description of error
//user system calls real-name registration function
void PluginChannel::realNameRegister()
{
	if(AgentManager::getInstance()->getUserPlugin())
	{
		if(isSupportFunction("realNameRegister"))
		{
			AgentManager::getInstance()->getUserPlugin()->callFuncWithParam("realNameRegister",NULL);
		}

	}

}

//Deal with callback function	
switch(code)
{
case kRealNameRegister://Real-name registration callback
//Account switch succeeds; the developer deals with it accordingly
	break;
}

Anti-addiction Query(QiHu360)

void antiAddictionQuery()
Introduction:
Anti-addiction system is created according to China’s law and regulation about online games; a game must have anti-addiction query and real-name registration APIs integrated. Usage: the operator calls anti-addiction query API and decide if the user is an adult.
1.If yes, it allows the user to perform normally in the game without extra notice.
2.If not, the user who has not accomplish real-name registration with be restricted by the anti-addiction system.
Detailed Regulation of Development
During gaming process, it will notify players with their cumulative time spent on the game.
If the cumulative time on the game exceeds 3 hours, the income from the game (experience, coins, etc.) would be cut half. After this, players would be warned every 30 minutes. If the cumulative time on the game exceeds 5 hours, the income from the game would be reset to zero and players would be warned every 15 minutes. After the juvenile has spent 5 hours off the game, the cumulative time will be reset to zero and will re-cumulate when he/she returns to the game. For detailed development standard please refer to: http://baike.baidu.com/view/3615996.htm.
API instruction:
Anti-addiction query API can acquire a user’s anti-addiction status: 0 is the user’s information doesn’t exit and the real-name registration API needs to be called to request the user to accomplish the real-name registration. If the user refuses, he/she will be regard as a juvenile and receive restriction from the anti-addiction system.
1 stands for juveniles and when the cumulative time achieves alert status, anti-addiction notices will occur; 2 stands for adults who will not be influenced by anti-addiction system.
Callback Info
Callback Info code msg
Anti-addiction result callback kAntiAddictionQuery Result of anti-addiction query
Result returning msg
{“content”:{“ret”:[{“qid":"199062142","status":"2"}]},"error_code":"0","error_msg":""}
Character Description
error_code 0 Query succeeds and other value queries fail
error_msg Error message
content json object, including ret array
ret json object’s array
qid Qihu UserId
status 0,the user data do not exist; 1, juvenile; 2, adult
//User system calls anti-addiction query
void PluginChannel::antiAddictionQuery()
{
	if(AgentManager::getInstance()->getUserPlugin())
	{
		if(isSupportFunction("antiAddictionQuery"))
		{
			AgentManager::getInstance()->getUserPlugin()->callFuncWithParam("antiAddictionQuery",NULL);
		}

	}

}

//Deal with callback function	
switch(code)
{
case kAntiAddictionQuery://Real-name registration callback;
//Real-name registration callback; developer should deal with it accordingly
	break;
}

Submit Game Data API (UC, Shanghai Yiwan, pps, oppo, 37 Play)

void submitLoginGameRole(StringMap *data)
Function description: passes the game data to SDK server.
API description: the parameter is StringMap, the data inside the map must be character strings.
StringMap is actually a map that has recorded related informations, and developers need to provide the parameters below:
Parameter If must be submitted Parameter Note
roleId Y Role’s ID
roleName Y Role’s name
roleLevel Y Role’s nevel
zoneId Y Server ID (pps:server id’s format is ppsmobile sX, eg. as for No.1 server, X=1)
zoneName Y Server’s name
dataType Y Data type: 1 means entering the game; 2 means creating a role
ext Y Extend characters
Take an example:
void PluginChannel::submitLoginGameRole()
{
	if(AgentManager::getInstance()->getUserPlugin())
	{
		if(PluginChannel::getInstance()->isSupportFunction("submitLoginGameRole"))
		{
			StringMap userInfo;
			userInfo["roleId"] = "123456";
			userInfo["roleName"] = "test";
			userInfo["roleLevel"] = "10";
			userInfo["zoneId"] = "123";
			userInfo["zoneName"] = "test";
                        userInfo["dataType"] = "1";
                        userInfo["ext"] = "{\"balance\":\"\",\"partyName\":\"\",\"vipLevel\":\"\"}";//(37 Play needs to pass .json character strings, the key of which contains balance - the balance of game currency, partyName - the name of the party, and vipLevel - the VIP level.) 
			PluginParam data(userInfo);
			AgentManager::getInstance()->getUserPlugin()->callFuncWithParam("submitLoginGameRole",&data,NULL);
		}
	}
}