-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCNetworkSession.h
136 lines (109 loc) · 2.63 KB
/
CNetworkSession.h
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#ifndef H_CLASS_NETWORK_SESSION___
#define H_CLASS_NETWORK_SESSION___
#include <windows.h>
#include "TCHAR.h"
#include "util.h"
#include "../common/CPacketQueue.h"
#include "../common/common.h"
#include "ext.h"
class CNetworkSession
{
public:
CNetworkSession()
{
};
virtual ~CNetworkSession()
{
ClearAllSession();
};
// 関数
// ソケット初期化
BOOL InitSock();
// 接続セッションの配列初期化
void InitSesssionArray();
void InitSession(ptype_session psession);
void ResetSession(WORD idx);
inline ptype_session GetSessionFromIndex(int index)
{
if(index>=g_nMaxLoginNum || index < 0) return NULL;
return &m_SessionArray[index].s;
};
inline ptype_session GetSessionFromUserNo(int userNo)
{
if(userNo>=MAXUSERNUM || userNo < 0) return NULL;
for (int i=0;i<g_nMaxLoginNum;i++)
{
if (m_SessionArray[i].s.obj_no ==userNo)
return &m_SessionArray[i].s;
}
return NULL;
}
inline ptype_session GetSessionFromSockNo(int sockNo)
{
if(sockNo>=g_nMaxLoginNum || sockNo < 0) return NULL;
return (&m_SessionArray[SockNoToUserNo[sockNo]].s);
}
// セッション情報用のテーブルの先頭ポインタを取得
t_sessionInfo* GetSessionTable(){ return &m_SessionArray[0]; };
ptype_session GetSessionFirst(int* pFirstIndex);
ptype_session GetSessionNext(int* pSearchIndex);
ptype_session CreateSession(int sock, INT addr, WORD port);
void ClearSession(ptype_session psession);
void ClearAllSession();
int SetConnectUserName(ptype_session session, char* msg, int len);
int GetConnectUserCount()
{ return m_dwUserCount; };
int CalcAuthedUserCount()
{
int ret =0;
for (int i=0;i<g_nMaxLoginNum;i++)
{
if (m_SessionArray[i].s.connect_state == CONN_STATE_AUTHED)
ret ++;
}
return ret;
};
char GetFlag(int nIndex)
{
if (nIndex<g_nMaxLoginNum && nIndex>= 0)
return m_SessionArray[nIndex].flag;
return 0;
};
int CalcEntityUserCount()
{
int ret =0;
for (int i=0;i<g_nMaxLoginNum;i++)
{
if (m_SessionArray[i].s.entity)
ret ++;
}
return ret;
};
int CalcMainStageUserCount()
{
int ret =0;
for (int i=0;i<g_nMaxLoginNum;i++)
{
if (m_SessionArray[i].s.obj_state & OBJ_STATE_GAME)
ret ++;
}
return ret;
};
int GetSockListener()
{ return sockListener; };
BOOL IsUniqueUserName(WCHAR* name);
t_sessionInfo m_SessionArray[MAXLOGINUSER];
protected:
private:
// DWORD m_dwArrayIndex;
// DWORD m_dwArrayCount;
int m_dwUserCount;
SOCKET sockListener;
SOCKADDR_IN svrAddr;
type_queue* GetLast();
/* 受信パケット処理 */
// BOOL ProcPK_CMD_MV(BYTE *data, ptype_session sess); // PK_CMD_MV
// ソケット番号順の配列にUserNoの値が入ってる
int SockNoToUserNo[MAXLOGINUSER];
};
#endif