Repository navigation
Expand file tree
/
Copy pathConnectSession.cs
More file actions
133 lines (110 loc) · 2.82 KB
/
Copy pathConnectSession.cs
File metadata and controls
133 lines (110 loc) · 2.82 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
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
using CSBaseLib;
using System;
using System.Threading;
namespace ChatServer;
enum SessionStatus
{
None = 0,
Logining = 1,
Login = 2,
RoomEntering = 3,
Room = 4,
}
// 연결된 세션 클래스
class ConnectSession
{
public bool IsEnable = true;
Int64 _currentState = (Int64)SessionStatus.None;
string _userID;
Int64 _roomNumber = PacketDef.InvalidRoomNumber;
public void Clear()
{
IsEnable = true;
_currentState = (Int64)SessionStatus.None;
_roomNumber = PacketDef.InvalidRoomNumber;
}
public bool IsStateNone()
{
return (IsEnable && _currentState == (Int64)SessionStatus.None);
}
public bool IsStateLogin()
{
return (IsEnable && _currentState == (Int64)SessionStatus.Login);
}
public bool IsStateRoom()
{
return (IsEnable && GetState() == SessionStatus.Room);
}
public void SetDisable()
{
IsEnable = false;
}
public void SetStateNone()
{
if (IsEnable)
{
_currentState = (int)SessionStatus.None;
}
}
public void SetStateLogin()
{
if (IsEnable)
{
_currentState = (Int64)SessionStatus.Login;
Interlocked.Exchange(ref _roomNumber, PacketDef.InvalidRoomNumber);
}
}
public void SetStatePreLogin()
{
if (IsEnable)
{
_currentState = (Int64)SessionStatus.Logining;
}
}
public void SetStateLogin(string userID)
{
if (IsEnable == false)
{
return;
}
_currentState = (Int64)SessionStatus.Login;
_userID = userID;
}
public int GetRoomNumber()
{
return (int)Interlocked.Read(ref _roomNumber);
}
SessionStatus GetState()
{
return (SessionStatus)Interlocked.Read(ref _currentState);
}
// 방에 완전 입장하기 전 상태로 변경
public bool SetPreRoomEnter(int roomNumber)
{
if (IsEnable == false)
{
return false;
}
var oldValue = Interlocked.CompareExchange(ref _currentState, (Int64)SessionStatus.RoomEntering, (Int64)SessionStatus.Login);
if (oldValue != (Int64)SessionStatus.Login)
{
return false;
}
Interlocked.Exchange(ref _roomNumber, roomNumber);
return true;
}
public bool SetRoomEntered(Int64 roomNumber)
{
if (IsEnable == false)
{
return false;
}
var oldValue = Interlocked.CompareExchange(ref _currentState, (Int64)SessionStatus.Room, (Int64)SessionStatus.RoomEntering);
if (oldValue != (Int64)SessionStatus.RoomEntering)
{
return false;
}
Interlocked.Exchange(ref _roomNumber, roomNumber);
return true;
}
}