本文整理汇总了C++中Session::BindNetworkObject方法的典型用法代码示例。如果您正苦于以下问题:C++ Session::BindNetworkObject方法的具体用法?C++ Session::BindNetworkObject怎么用?C++ Session::BindNetworkObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Session
的用法示例。
在下文中一共展示了Session::BindNetworkObject方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: OnRecv
void TempServerSession::OnRecv(BYTE *pMsg, WORD wSize)
{
printf(">> TempServerSession::OnRecv\n");
assert( m_bFirst == TRUE);
if ( !m_bFirst)
return;
m_bFirst = FALSE;
if ( wSize < sizeof(MSG_CONNECTION_SYN) ) {
return;
}
MSG_CONNECTION_SYN * recvMsg = (MSG_CONNECTION_SYN *)pMsg;
switch( recvMsg->ServerType )
{
case KEYV_SERVER:
{
printf("Recv KeyVServer.\n");
//ServerSession * Obj = g_pLoginServer->GetKeyvSession();
//assert( Obj );
//
//Session * pSession = this->m_pSession;
//if ( pSession != NULL )
//{
// m_pSession->UnbindNetworkObject();
// pSession->BindNetworkObject(Obj);
//
// Obj->Init();
//}
break;
}
case JSON_SERVER:
{
printf("Recv JsonServer.\n");
ServerSession * Obj = g_pLoginServer->GetJsonSession();
assert( Obj );
Session * pSession = this->m_pSession;
if ( pSession != NULL )
{
m_pSession->UnbindNetworkObject();
pSession->BindNetworkObject(Obj);
//Obj->Init();
}
break;
}
default:
{
// Connected warning.
this->Release();
return;
}
}
}
示例2: ProcessAcceptedSessionList
void SyncHandler::ProcessAcceptedSessionList()
{
SESSION_LIST_ITER it;
Session *pSession;
m_pAcceptedSessionList->Lock();
m_pTemplateList->splice( *m_pAcceptedSessionList );
m_pAcceptedSessionList->Unlock();
SESSION_LIST activeList;
while( !m_pTemplateList->empty() )
{
pSession = m_pTemplateList->pop_front();
if (m_numActiveSessions >= m_dwMaxAcceptSession) {
printf("Connection full! no available accept socket! \n");
FreeSession(pSession);
continue;
}
if (!AddEpollEvent(pSession)) {
FreeSession(pSession);
continue;
}
NetworkObject * pNet = m_fnCreateAcceptedObject();
assert(pNet);
pSession->BindNetworkObject(pNet);
pSession->OnAccept();
++m_numActiveSessions;
activeList.push_back(pSession);
}
if ( !activeList.empty() ) {
m_pActiveSessionList->Lock();
m_pActiveSessionList->splice( activeList );
m_pActiveSessionList->Unlock();
}
}
示例3: Connect
DWORD SyncHandler::Connect(NetworkObject * pNet, char *szIP, WORD wPort)
{
if (pNet->m_pSession != NULL)
return 0;
SOCKET sock = socket(AF_INET, SOCK_STREAM, 0);
SOCKADDR_IN addr;
addr.sin_family = AF_INET;
addr.sin_addr.s_addr = inet_addr( szIP );
addr.sin_port = htons( wPort );
Session * pSession = AllocConnectSession();
assert( pSession != NULL && "Connect dwMaxConnectSession");
pSession->SetSocket( sock );
pSession->SetSockAddr( addr );
pSession->BindNetworkObject(pNet);
m_pConnector->Connect(pSession);
return pSession->GetIndex();
}
示例4: OnRecv
void TempUserSession::OnRecv(BYTE *pMsg, WORD wSize)
{
printf(">>>>[TempUserSession::OnRecv]<<<<\n");
printf("Step2: <1> CA_Login_REQ\n");
assert( m_bFirst == TRUE );
if ( !m_bFirst ) {
printf("Debug m_bFirst != TRUE. So return.\n");
return;
}
MSG_CA_LOGIN_REQ * pRecvMsg = (MSG_CA_LOGIN_REQ *) pMsg;
printf("RootID = %d, UserKey = %s\n", pRecvMsg->m_uiRootID, pRecvMsg->m_byUserKey);
RootID * pRoot = RootidManager::Instance()->FindRootID( pRecvMsg->m_uiRootID );
if ( pRoot == NULL ) {
printf("\n[RootidManager::Instance()->FindRootID] Fail.\n");
// 发送出错信息 ( 还未测试 )
MSG_CA_LOGIN_NAK msgError;
msgError.m_dwParameter = pRecvMsg->m_dwParameter; // User ID
msgError.m_dwErrorCode = 1234; // ???
Session * pSession = this->m_pSession;
if ( pSession != NULL ) {
//m_pSession->UnbindNetworkObject();
pSession->BindNetworkObject(this);
}
pSession->Send( (BYTE *)&msgError, sizeof(MSG_CA_LOGIN_NAK) );
printf("\n>>>> Free TempUserSesion <<<<\n");
AgentFactory::Instance()->FreeTempUserSession(this);
return;
}
// 验证 UserKey ( MD5 )
BOOL bRet = pRoot->IsSameUserKey(pRecvMsg->m_byUserKey);
if ( !bRet ) {
printf("\n[RootidManager::Instance()->IsSameRootID] Fail.\n");
// 发送出错信息
//MSG_CA_LOGIN_NAK msgError;
return;
}
// TempUser 转变为 User
User * obj = AgentFactory::Instance()->AllocUser(); //
if ( obj == NULL) {
printf("\nAgentFactory::Instance()->AllocUser() Fail.\n");
return;
}
// 添加进 UserManager 进行管理
DWORD dwID = g_UserManager.AddUser(obj); // 返回的是 ObjKey
printf("g_UserManager AddUser, Return ObjKey = %d\n", dwID);
obj->SetUserID(dwID);
obj->SetRootID(pRecvMsg->m_uiRootID); // 保存 RootID
Session * pSession = this->m_pSession;
if ( pSession != NULL ) {
m_pSession->UnbindNetworkObject();
pSession->BindNetworkObject( obj );
}
printf("[TempUserSession] ==> [User] Success.\n");
printf("Send MSG_AG_LOGIN_REQ to [GameSrv].\n");
// 发送 AG_Login_REQ 消息包给 GameServer
MSG_AG_LOGIN_REQ msg2;
msg2.m_dwParameter = dwID; // User ID
msg2.m_uiRootID = pRecvMsg->m_uiRootID; // RootID
g_AgentServer->SendToGameServer( (BYTE *)&msg2, sizeof(msg2) );
//pSession->Send( (BYTE *)&ancMsg, sizeof( MSG_AG_LOGIN_REQ) );
printf("\n>>>> Free TempUserSesion <<<<\n");
AgentFactory::Instance()->FreeTempUserSession(this);
}