提交 c4150a00 编写于 作者: xengine-qyt's avatar xengine-qyt

modify:saved user info table for session module when client create

上级 ade752c6
......@@ -9,5 +9,6 @@ EXPORTS
SessionModule_Client_Delete
SessionModule_Client_GetUser
SessionModule_Client_GetAddr
SessionModule_Client_GetInfoByUser
SessionModule_Client_GetType
SessionModule_Client_Heart
\ No newline at end of file
......@@ -83,11 +83,11 @@ bool CSessionModule_Client::SessionModule_Client_Destory()
类型:常量字符指针
可空:N
意思:输入客户端地址
参数.二:lpszUserName
参数.二:pSt_UserInfo
In/Out:In
类型:常量字符指针
类型:数据结构指针
可空:N
意思:输入用户
意思:输入用户信息
参数.三:nNetType
In/Out:In
类型:整数型
......@@ -98,7 +98,7 @@ bool CSessionModule_Client::SessionModule_Client_Destory()
意思:是否成功
备注:
*********************************************************************/
bool CSessionModule_Client::SessionModule_Client_Create(LPCXSTR lpszClientAddr, LPCXSTR lpszUserName, int nNetType)
bool CSessionModule_Client::SessionModule_Client_Create(LPCXSTR lpszClientAddr, XENGINE_PROTOCOL_USERINFO *pSt_UserInfo, int nNetType)
{
Session_IsErrorOccur = false;
......@@ -113,7 +113,7 @@ bool CSessionModule_Client::SessionModule_Client_Create(LPCXSTR lpszClientAddr,
st_SessionInfo.nNetType = nNetType;
st_SessionInfo.nTimeStart = time(NULL);
_tcsxcpy(st_SessionInfo.tszUserName, lpszUserName);
st_SessionInfo.st_UserInfo = *pSt_UserInfo;
_tcsxcpy(st_SessionInfo.tszUserAddr, lpszClientAddr);
st_Locker.lock();
......@@ -187,7 +187,7 @@ bool CSessionModule_Client::SessionModule_Client_GetUser(LPCXSTR lpszSessionStr,
}
if (NULL != ptszUserName)
{
_tcsxcpy(ptszUserName, stl_MapIterator->second.tszUserName);
_tcsxcpy(ptszUserName, stl_MapIterator->second.st_UserInfo.tszUserName);
}
st_Locker.unlock_shared();
return true;
......@@ -224,7 +224,7 @@ bool CSessionModule_Client::SessionModule_Client_GetAddr(LPCXSTR lpszUserName, X
st_Locker.lock_shared();
for (auto stl_MapIterator = stl_MapSession.begin(); stl_MapIterator != stl_MapSession.end(); stl_MapIterator++)
{
if (0 == _tcsxncmp(lpszUserName, stl_MapIterator->second.tszUserName, _tcsxlen(lpszUserName)))
if (0 == _tcsxncmp(lpszUserName, stl_MapIterator->second.st_UserInfo.tszUserName, _tcsxlen(lpszUserName)))
{
bFound = true;
if (NULL != ptszUserAddr)
......@@ -245,6 +245,55 @@ bool CSessionModule_Client::SessionModule_Client_GetAddr(LPCXSTR lpszUserName, X
return true;
}
/********************************************************************
函数名称:SessionModule_Client_GetInfoByUser
函数功能:通过用户名获取用户信息
参数.一:lpszUserName
In/Out:In
类型:常量字符指针
可空:N
意思:输入用户名
参数.二:pSt_UserInfo
In/Out:Out
类型:数据结构指针
可空:N
意思:输出用户信息
返回值
类型:逻辑型
意思:是否成功
备注:
*********************************************************************/
bool CSessionModule_Client::SessionModule_Client_GetInfoByUser(LPCXSTR lpszUserName, XENGINE_PROTOCOL_USERINFO* pSt_UserInfo)
{
Session_IsErrorOccur = false;
if (NULL == lpszUserName)
{
Session_IsErrorOccur = true;
Session_dwErrorCode = ERROR_MQ_MODULE_SESSION_PARAMENT;
return false;
}
bool bFound = false;
st_Locker.lock_shared();
for (auto stl_MapIterator = stl_MapSession.begin(); stl_MapIterator != stl_MapSession.end(); stl_MapIterator++)
{
if (0 == _tcsxncmp(lpszUserName, stl_MapIterator->second.st_UserInfo.tszUserName, _tcsxlen(lpszUserName)))
{
bFound = true;
*pSt_UserInfo = stl_MapIterator->second.st_UserInfo;
break;
}
}
st_Locker.unlock_shared();
if (!bFound)
{
Session_IsErrorOccur = true;
Session_dwErrorCode = ERROR_MQ_MODULE_SESSION_NOTFOUND;
return false;
}
return true;
}
/********************************************************************
函数名称:SessionModule_Client_GetType
函数功能:通过客户端获得连接的网络类型
参数.一:lpszSessionStr
......@@ -349,7 +398,7 @@ XHTHREAD CALLBACK CSessionModule_Client::SessionModule_Client_Thread(XPVOID lPar
{
for (auto stl_ListIterator = stl_ListClient.begin(); stl_ListIterator != stl_ListClient.end(); stl_ListIterator++)
{
pClass_This->lpCall_Timeout(stl_ListIterator->tszUserAddr, stl_ListIterator->tszUserName, (ENUM_MQCORE_SESSION_CLIENT_TYPE)stl_ListIterator->nNetType, pClass_This->m_lParam);
pClass_This->lpCall_Timeout(stl_ListIterator->tszUserAddr, stl_ListIterator->st_UserInfo.tszUserName, (ENUM_MQCORE_SESSION_CLIENT_TYPE)stl_ListIterator->nNetType, pClass_This->m_lParam);
}
}
std::this_thread::sleep_for(std::chrono::seconds(1));
......
......@@ -12,8 +12,8 @@
*********************************************************************/
typedef struct
{
XENGINE_PROTOCOL_USERINFO st_UserInfo; //用户登录信息
XCHAR tszUserAddr[128]; //用户地址
XCHAR tszUserName[128]; //登录的用户名
time_t nTimeStart; //时间
int nNetType; //网络类型
}XENGINE_SESSIONINFO, * LPXENGINE_SESSIONINFO;
......@@ -26,10 +26,11 @@ public:
public:
bool SessionModule_Client_Init(int nSessionTime, CALLBACK_MESSAGEQUEUE_SESSIONMODULE_CLIENT_TIMEOUT fpCall_Timeout, XPVOID lParam = NULL);
bool SessionModule_Client_Destory();
bool SessionModule_Client_Create(LPCXSTR lpszClientAddr, LPCXSTR lpszUserName, int nNetType);
bool SessionModule_Client_Create(LPCXSTR lpszClientAddr, XENGINE_PROTOCOL_USERINFO *pSt_UserInfo, int nNetType);
bool SessionModule_Client_Delete(LPCXSTR lpszClientAddr);
bool SessionModule_Client_GetUser(LPCXSTR lpszSessionStr, XCHAR* ptszUserName = NULL);
bool SessionModule_Client_GetAddr(LPCXSTR lpszUserName, XCHAR* ptszUserAddr = NULL);
bool SessionModule_Client_GetInfoByUser(LPCXSTR lpszUserName, XENGINE_PROTOCOL_USERINFO* pSt_UserInfo);
bool SessionModule_Client_GetType(LPCXSTR lpszSessionStr, int* pInt_NetType);
bool SessionModule_Client_Heart(LPCXSTR lpszClientAddr);
protected:
......
......@@ -72,11 +72,11 @@ extern "C" bool SessionModule_Client_Destory();
类型:常量字符指针
可空:N
意思:输入客户端地址
参数.二:lpszUserName
参数.二:pSt_UserInfo
In/Out:In
类型:常量字符指针
类型:数据结构指针
可空:N
意思:输入用户
意思:输入用户信息
参数.三:nNetType
In/Out:In
类型:整数型
......@@ -87,7 +87,7 @@ extern "C" bool SessionModule_Client_Destory();
意思:是否成功
备注:
*********************************************************************/
extern "C" bool SessionModule_Client_Create(LPCXSTR lpszClientAddr, LPCXSTR lpszUserName, int nNetType);
extern "C" bool SessionModule_Client_Create(LPCXSTR lpszClientAddr, XENGINE_PROTOCOL_USERINFO * pSt_UserInfo, int nNetType);
/********************************************************************
函数名称:SessionModule_Client_Delete
函数功能:删除一个用户
......@@ -141,6 +141,25 @@ extern "C" bool SessionModule_Client_GetUser(LPCXSTR lpszSessionStr, XCHAR* ptsz
*********************************************************************/
extern "C" bool SessionModule_Client_GetAddr(LPCXSTR lpszUserName, XCHAR* ptszUserAddr = NULL);
/********************************************************************
函数名称:SessionModule_Client_GetInfoByUser
函数功能:通过用户名获取用户信息
参数.一:lpszUserName
In/Out:In
类型:常量字符指针
可空:N
意思:输入用户名
参数.二:pSt_UserInfo
In/Out:Out
类型:数据结构指针
可空:N
意思:输出用户信息
返回值
类型:逻辑型
意思:是否成功
备注:
*********************************************************************/
extern "C" bool SessionModule_Client_GetInfoByUser(LPCXSTR lpszUserName, XENGINE_PROTOCOL_USERINFO* pSt_UserInfo);
/********************************************************************
函数名称:SessionModule_Client_GetType
函数功能:通过客户端获得连接的网络类型
参数.一:lpszSessionStr
......
......@@ -37,9 +37,9 @@ extern "C" bool SessionModule_Client_Destory()
{
return m_SessionClient.SessionModule_Client_Destory();
}
extern "C" bool SessionModule_Client_Create(LPCXSTR lpszClientAddr, LPCXSTR lpszUserName, int nNetType)
extern "C" bool SessionModule_Client_Create(LPCXSTR lpszClientAddr, XENGINE_PROTOCOL_USERINFO * pSt_UserInfo, int nNetType)
{
return m_SessionClient.SessionModule_Client_Create(lpszClientAddr, lpszUserName, nNetType);
return m_SessionClient.SessionModule_Client_Create(lpszClientAddr, pSt_UserInfo, nNetType);
}
extern "C" bool SessionModule_Client_Delete(LPCXSTR lpszClientAddr)
{
......@@ -53,6 +53,10 @@ extern "C" bool SessionModule_Client_GetAddr(LPCXSTR lpszUserName, XCHAR * ptszU
{
return m_SessionClient.SessionModule_Client_GetAddr(lpszUserName, ptszUserAddr);
}
extern "C" bool SessionModule_Client_GetInfoByUser(LPCXSTR lpszUserName, XENGINE_PROTOCOL_USERINFO * pSt_UserInfo)
{
return m_SessionClient.SessionModule_Client_GetInfoByUser(lpszUserName, pSt_UserInfo);
}
extern "C" bool SessionModule_Client_GetType(LPCXSTR lpszSessionStr, int* pInt_NetType)
{
return m_SessionClient.SessionModule_Client_GetType(lpszSessionStr, pInt_NetType);
......
......@@ -21,17 +21,17 @@
#include <shared_mutex>
#include <unordered_map>
#include <XEngine_Include/XEngine_CommHdr.h>
#include <XEngine_Include/XEngine_ProtocolHdr.h>
#include <XEngine_Include/XEngine_Types.h>
#include "../XQueue_ProtocolHdr.h"
#include "Session_Define.h"
#include "Session_Error.h"
using namespace std;
#ifdef _UNICODE
typedef std::wstring tstring;
#else
typedef std::string tstring;
#endif
#include "../XQueue_ProtocolHdr.h"
#include "Session_Define.h"
#include "Session_Error.h"
/********************************************************************
// Created: 2021/07/02 10:16:47
// File Name: D:\XEngine_MQService\XEngine_Source\MQCore_SessionModule\pch.h
......
......@@ -104,7 +104,6 @@ bool MessageQueue_TCP_Handle(XENGINE_PROTOCOLHDR* pSt_ProtocolHdr, LPCXSTR lpszC
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("%s客户端:%s,请求登录到服务失败,因为用户已经登录了"), lpszClientType, lpszClientAddr);
return false;
}
_tcsxcpy(st_UserInfo.tszUserName, st_ProtocolAuth.tszUserName);
_tcsxcpy(st_UserInfo.tszUserPass, st_ProtocolAuth.tszUserPass);
......@@ -151,11 +150,11 @@ bool MessageQueue_TCP_Handle(XENGINE_PROTOCOLHDR* pSt_ProtocolHdr, LPCXSTR lpszC
//HTTP使用SESSION
BaseLib_OperatorHandle_Create(&pSt_ProtocolHdr->xhToken);
_xstprintf(tszSessionStr, _X("%lld"), pSt_ProtocolHdr->xhToken);
SessionModule_Client_Create(tszSessionStr, st_UserInfo.tszUserName, nNetType);
SessionModule_Client_Create(tszSessionStr, &st_UserInfo, nNetType);
}
else
{
SessionModule_Client_Create(lpszClientAddr, st_UserInfo.tszUserName, nNetType);
SessionModule_Client_Create(lpszClientAddr, &st_UserInfo, nNetType);
}
pSt_ProtocolHdr->wReserve = 0;
ProtocolModule_Packet_Common(nNetType, pSt_ProtocolHdr, NULL, tszSDBuffer, &nSDLen);
......@@ -165,9 +164,11 @@ bool MessageQueue_TCP_Handle(XENGINE_PROTOCOLHDR* pSt_ProtocolHdr, LPCXSTR lpszC
else if (XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_MQ_REQUSEROUT == pSt_ProtocolHdr->unOperatorCode)
{
XENGINE_PROTOCOL_USERAUTH st_ProtocolAuth;
XENGINE_PROTOCOL_USERINFO st_ProtocolInfo;
memset(&st_ProtocolAuth, '\0', sizeof(XENGINE_PROTOCOL_USERAUTH));
memset(&st_ProtocolInfo, '\0', sizeof(XENGINE_PROTOCOL_USERINFO));
memcpy(&st_ProtocolAuth, lpszMsgBuffer, sizeof(XENGINE_PROTOCOL_USERAUTH));
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("%s客户端:%s,用户登出成功,暂时没有作用,用户名:%s,密码:%s"), lpszClientType, lpszClientAddr, st_ProtocolAuth.tszUserName, st_ProtocolAuth.tszUserPass);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册