Skip to content

Commit

Permalink
增加logout接口,让客户端可以主动退出服务器
Browse files Browse the repository at this point in the history
  • Loading branch information
kebiao committed Jul 21, 2018
1 parent ffc60f5 commit 2200a82
Show file tree
Hide file tree
Showing 11 changed files with 116 additions and 6 deletions.
8 changes: 7 additions & 1 deletion kbe/res/client/sdk_templates/js/README.md
Expand Up @@ -312,7 +312,6 @@ KBE-Plugin fire-in events(Unity => KBE):
Data will be recorded into the KBE account database, you can access the datas through the script layer.
If you use third-party account system, datas will be submitted to the third-party system.

login
Description:
Login to server.
Expand All @@ -325,6 +324,13 @@ KBE-Plugin fire-in events(Unity => KBE):
Data will be recorded into the KBE account database, you can access the datas through the script layer.
If you use third-party account system, datas will be submitted to the third-party system.

logout
Description:
Logout to baseapp, called when exiting the client.

Event-datas:
No datas.

reloginBaseapp
Description:
Relogin to baseapp.
Expand Down
17 changes: 15 additions & 2 deletions kbe/res/client/sdk_templates/js/kbengine.js
Expand Up @@ -2470,16 +2470,20 @@ KBEngine.KBEngineApp = function(kbengineArgs)
{
KBEngine.Event.register("createAccount", KBEngine.app, "createAccount");
KBEngine.Event.register("login", KBEngine.app, "login");
KBEngine.Event.register("logout", KBEngine.app, "logout");
KBEngine.Event.register("reloginBaseapp", KBEngine.app, "reloginBaseapp");
KBEngine.Event.register("bindAccountEmail", KBEngine.app, "bindAccountEmail");
KBEngine.Event.register("newPassword", KBEngine.app, "newPassword");
}

this.uninstallEvents = function()
{
KBEngine.Event.deregister("reloginBaseapp", KBEngine.app);
KBEngine.Event.deregister("login", KBEngine.app);
KBEngine.Event.deregister("createAccount", KBEngine.app);
KBEngine.Event.deregister("login", KBEngine.app);
KBEngine.Event.deregister("logout", KBEngine.app);
KBEngine.Event.deregister("reloginBaseapp", KBEngine.app);
KBEngine.Event.deregister("bindAccountEmail", KBEngine.app);
KBEngine.Event.deregister("newPassword", KBEngine.app);
}

this.hello = function()
Expand Down Expand Up @@ -3184,6 +3188,15 @@ KBEngine.KBEngineApp = function(kbengineArgs)
KBEngine.app.login_loginapp(true);
}

this.logout = function()
{
var bundle = new KBEngine.Bundle();
bundle.newMessage(KBEngine.messages.Baseapp_logoutBaseapp);
bundle.writeUint64(KBEngine.app.entity_uuid);
bundle.writeInt32(KBEngine.app.entity_id);
bundle.send(KBEngine.app);
}

this.login_loginapp = function(noconnect)
{
if(noconnect)
Expand Down
10 changes: 8 additions & 2 deletions kbe/res/client/sdk_templates/ue4/README.md
Expand Up @@ -315,8 +315,7 @@ KBE-Plugin fire-in events(UE4 => KBE):
bytes: datas
Datas by user defined.
Data will be recorded into the KBE account database, you can access the datas through the script layer.
If you use third-party account system, datas will be submitted to the third-party system.
If you use third-party account system, datas will be submitted to the third-party system.

login
Description:
Expand All @@ -330,6 +329,13 @@ KBE-Plugin fire-in events(UE4 => KBE):
Data will be recorded into the KBE account database, you can access the datas through the script layer.
If you use third-party account system, datas will be submitted to the third-party system.

logout
Description:
Logout to baseapp, called when exiting the client.

Event-datas:
No datas.

reloginBaseapp
Description:
Relogin to baseapp.
Expand Down
Expand Up @@ -136,6 +136,11 @@ void KBEngineApp::installEvents()
login(data.username, data.password, data.datas);
});

KBENGINE_REGISTER_EVENT_OVERRIDE_FUNC("logout", "logout", [this](const UKBEventData* pEventData)
{
logout();
});

KBENGINE_REGISTER_EVENT_OVERRIDE_FUNC("createAccount", "createAccount", [this](const UKBEventData* pEventData)
{
const UKBEventData_createAccount& data = static_cast<const UKBEventData_createAccount&>(*pEventData);
Expand Down Expand Up @@ -553,6 +558,19 @@ bool KBEngineApp::login(const FString& username, const FString& password, const
return true;
}

void KBEngineApp::logout()
{
if (currserver_ != TEXT("baseapp"))
return;

INFO_MSG("KBEngineApp::logout()");
Bundle* pBundle = Bundle::createObject();
pBundle->newMessage(Messages::messages[TEXT("Baseapp_logoutBaseapp"]));
(*pBundle) << entity_uuid_;
(*pBundle) << entity_id_;
pBundle->send(pNetworkInterface_);
}

void KBEngineApp::login_loginapp(bool noconnect)
{
if (noconnect)
Expand Down
Expand Up @@ -113,6 +113,11 @@ class KBENGINEPLUGINS_API KBEngineApp : public InterfaceConnect
bool login(const FString& username, const FString& password, const TArray<uint8>& datas);
virtual void onConnectCallback(FString ip, uint16 port, bool success, int userdata) override;

/**
登录出baseapp
*/
bool logout();

/*
账号创建返回结果
*/
Expand Down
Expand Up @@ -127,6 +127,14 @@ class KBENGINEPLUGINS_API UKBEventData_login : public UKBEventData
TArray<uint8> datas;
};

UCLASS(Blueprintable, BlueprintType)
class KBENGINEPLUGINS_API UKBEventData_logout : public UKBEventData
{
GENERATED_BODY()

public:
};

UCLASS(Blueprintable, BlueprintType)
class KBENGINEPLUGINS_API UKBEventData_onLoginFailed : public UKBEventData
{
Expand Down
13 changes: 13 additions & 0 deletions kbe/res/client/sdk_templates/unity/KBEngine.cs
Expand Up @@ -159,6 +159,7 @@ void installEvents()
{
Event.registerIn("createAccount", this, "createAccount");
Event.registerIn("login", this, "login");
Event.registerIn("logout", this, "logout");
Event.registerIn("reloginBaseapp", this, "reloginBaseapp");
Event.registerIn("resetPassword", this, "resetPassword");
Event.registerIn("bindAccountEmail", this, "bindAccountEmail");
Expand Down Expand Up @@ -589,6 +590,18 @@ private void onReConnectTo_baseapp_callback(string ip, int port, bool success, o
_lastTickCBTime = System.DateTime.Now;
}

/*
登出baseapp
*/
public void logout()
{
Bundle bundle = Bundle.createObject();
bundle.newMessage(Messages.messages["Baseapp_logoutBaseapp"]);
bundle.writeUint64(entity_uuid);
bundle.writeInt32(entity_id);
bundle.send(_networkInterface);
}

/*
通过错误id得到错误描述
*/
Expand Down
8 changes: 7 additions & 1 deletion kbe/res/client/sdk_templates/unity/README.md
Expand Up @@ -310,7 +310,6 @@ KBE-Plugin fire-in events(Unity => KBE):
Datas by user defined.
Data will be recorded into the KBE account database, you can access the datas through the script layer.
If you use third-party account system, datas will be submitted to the third-party system.

login
Description:
Expand All @@ -324,6 +323,13 @@ KBE-Plugin fire-in events(Unity => KBE):
Data will be recorded into the KBE account database, you can access the datas through the script layer.
If you use third-party account system, datas will be submitted to the third-party system.

logout
Description:
Logout to baseapp, called when exiting the client.

Event-datas:
No datas.

reloginBaseapp
Description:
Relogin to baseapp.
Expand Down
24 changes: 24 additions & 0 deletions kbe/src/server/baseapp/baseapp.cpp
Expand Up @@ -3846,6 +3846,30 @@ void Baseapp::loginBaseapp(Network::Channel* pChannel,
ptinfos->addr = pChannel->addr();
}

//-------------------------------------------------------------------------------------
void Baseapp::logoutBaseapp(Network::Channel* pChannel, uint64 key, ENTITY_ID entityID)
{
INFO_MSG(fmt::format("Baseapp::logoutBaseapp: key={}, entityID={}.\n", key, entityID));

Entity* pEntity = findEntity(entityID);
if (pEntity == NULL || !PyObject_TypeCheck(pEntity, Proxy::getScriptType()) || pEntity->isDestroyed())
{
return;
}

Proxy* proxy = static_cast<Proxy*>(pEntity);

if (key == 0 || proxy->rndUUID() != key)
{
return;
}

if (pChannel && !pChannel->isDestroyed())
{
pChannel->condemn();
}
}

//-------------------------------------------------------------------------------------
void Baseapp::reloginBaseapp(Network::Channel* pChannel, std::string& accountName,
std::string& password, uint64 key, ENTITY_ID entityID)
Expand Down
5 changes: 5 additions & 0 deletions kbe/src/server/baseapp/baseapp.h
Expand Up @@ -299,6 +299,11 @@ class Baseapp : public EntityApp<Entity>,
*/
void loginBaseapp(Network::Channel* pChannel, std::string& accountName, std::string& password);

/** 网络接口
到网关上登出,仅仅断开连接并触发实体的onClientDead,实体销毁由用户决定
*/
void logoutBaseapp(Network::Channel* pChannel, uint64 key, ENTITY_ID entityID);

/**
踢出一个Channel
*/
Expand Down
6 changes: 6 additions & 0 deletions kbe/src/server/baseapp/baseapp_interface.h
Expand Up @@ -164,6 +164,12 @@ NETWORK_INTERFACE_DECLARE_BEGIN(BaseappInterface)
std::string, accountName,
std::string, password)

// 前端请求从网关登出。
BASEAPP_MESSAGE_EXPOSED(logoutBaseapp)
BASEAPP_MESSAGE_DECLARE_ARGS2(logoutBaseapp, NETWORK_FIXED_MESSAGE,
uint64, key,
ENTITY_ID, entityID)

// 前端请求重新登录到网关上。
BASEAPP_MESSAGE_EXPOSED(reloginBaseapp)
BASEAPP_MESSAGE_DECLARE_ARGS4(reloginBaseapp, NETWORK_VARIABLE_MESSAGE,
Expand Down

0 comments on commit 2200a82

Please sign in to comment.