-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser.cpp
More file actions
66 lines (55 loc) · 1.81 KB
/
user.cpp
File metadata and controls
66 lines (55 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "nskernel/connection.h"
#include "base/logger.h"
#include "cmd.h"
#include "user.h"
#include "processor.h"
#include "sproxy.h"
#include "timefuncdef.h"
using namespace std;
GameUser::GameUser(SProxy* p_proxy)
{
m_psproxy = p_proxy; //全局进程
m_pLogger = m_psproxy->getAsyncLog(); //日志
m_pConn = NULL; //连接
m_pDbMgr = &(m_psproxy->m_ar_dbMgr); //数据库
m_pFileConf = &(m_psproxy->getCfg()); //配置文件
m_pAllUsersMgr = &(m_psproxy->m_userMgr); //玩家管理器
}
void GameUser::user_login(int plat_uid, const string& strIp,Connection* p_Conn)
{
m_pConn = p_Conn;
puid = plat_uid;
m_strIP = strIp;
user_id = puid;
m_pLogger->debug ("GameUser::user_login:puid=%d from ip:%s,con:%x", puid,strIp.c_str(),p_Conn);
//回调python层通知上线
Cpp2PythonContext context;
context.puid = puid;
context.userid = user_id;
context.connection = m_pConn;
context.type = Cpp2PythonData_Type_EVENT_LOGIN;
m_psproxy->m_pPythonEngine->callPython_pythonHandler(context);
}
void GameUser::user_offline()
{
// 记录运营日志
char sLoginTime[1024],sLogoutTime[1024];
struct tm curr,tmp;
time_t logintime;//=last_login_time;
time_t logouttime;//=last_logout_time;
curr = *localtime_r(&logintime,&tmp);
strftime(sLoginTime,sizeof(sLoginTime),"%Y-%m-%d %H:%M:%S",&curr);
curr = *localtime_r(&logouttime,&tmp);
strftime(sLogoutTime,sizeof(sLogoutTime),"%Y-%m-%d %H:%M:%S",&curr);
m_pLogger->debug ("GameUser::user_offline:puid=%d from ip:%s", puid,m_strIP.c_str());
//回调python层通知下线
Cpp2PythonContext context;
context.puid = puid;
context.userid = user_id;
context.connection = m_pConn;
context.type = Cpp2PythonData_Type_EVENT_LOGOUT;
m_psproxy->m_pPythonEngine->callPython_pythonHandler(context);
user_id = -1;
puid = -1;
m_pConn = NULL;
}