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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;
using XUtliPoolLib;
namespace XMainClient
{
public abstract class Protocol
{
public EProtocolErrCode ThreadErrCode
{
get
{
return this.m_threadErrCode;
}
set
{
this.m_threadErrCode = value;
}
}
public static Dictionary<uint, Protocol.ProtocolFactry> sm_RegistProtocolFactory = new Dictionary<uint, Protocol.ProtocolFactry>(120);
protected EProtocolErrCode m_threadErrCode = EProtocolErrCode.ENoErr;
public class ProtocolFactry
{
public Protocol protocol = null;
public Queue<Protocol> queue;
public ProtocolFactry(Protocol p)
{
this.protocol = p;
this.queue = new Queue<Protocol>();
}
public Protocol Create()
{
bool flag = this.protocol != null;
Protocol result;
if (flag)
{
result = (Activator.CreateInstance(this.protocol.GetType()) as Protocol);
}
else
{
result = null;
}
return result;
}
public Protocol Get()
{
bool flag = this.queue.Count > 0;
Protocol result;
if (flag)
{
result = this.queue.Dequeue();
}
else
{
result = this.Create();
}
return result;
}
public void Return(Protocol protocol)
{
this.queue.Enqueue(protocol);
}
}
public virtual uint GetProtoType()
{
return 0u;
}
public void SerializeWithHead(MemoryStream stream)
{
long position = stream.Position;
ProtocolHead sharedHead = ProtocolHead.SharedHead;
sharedHead.Reset();
sharedHead.type = this.GetProtoType();
sharedHead.flag = 0u;
sharedHead.Serialize(stream);
this.Serialize(stream);
long position2 = stream.Position;
uint value = (uint)(position2 - position - 4L);
stream.Position = position;
stream.Write(BitConverter.GetBytes(value), 0, 4);
stream.Position = position2;
}
public abstract void Serialize(MemoryStream stream);
public abstract void DeSerialize(MemoryStream stream);
public static Protocol GetProtocolThread(uint dwType)
{
Protocol result = null;
Monitor.Enter(Protocol.sm_RegistProtocolFactory);
Protocol.ProtocolFactry protocolFactry = null;
bool flag = Protocol.sm_RegistProtocolFactory.TryGetValue(dwType, out protocolFactry);
if (flag)
{
result = protocolFactry.Get();
}
Monitor.Exit(Protocol.sm_RegistProtocolFactory);
return result;
}
public static void ReturnProtocolThread(Protocol protocol)
{
bool flag = Protocol.sm_RegistProtocolFactory != null && protocol != null;
if (flag)
{
Monitor.Enter(Protocol.sm_RegistProtocolFactory);
Protocol.ProtocolFactry protocolFactry = null;
bool flag2 = Protocol.sm_RegistProtocolFactory.TryGetValue(protocol.GetProtoType(), out protocolFactry);
if (flag2)
{
protocolFactry.Return(protocol);
}
Monitor.Exit(Protocol.sm_RegistProtocolFactory);
}
}
public static bool RegistProtocol(Protocol protocol)
{
bool flag = Protocol.sm_RegistProtocolFactory.ContainsKey(protocol.GetProtoType());
bool result;
if (flag)
{
result = false;
}
else
{
Protocol.sm_RegistProtocolFactory.Add(protocol.GetProtoType(), new Protocol.ProtocolFactry(protocol));
result = true;
}
return result;
}
public static void ManualReturn()
{
CNetProcessor.ManualReturnProtocol();
}
public virtual bool CheckPValid()
{
bool flag = this.m_threadErrCode == EProtocolErrCode.EDeSerializeErr;
bool result;
if (flag)
{
XSingleton<XDebug>.singleton.AddErrorLog("Ptc EDeSerializeErr Type:", this.GetProtoType().ToString(), null, null, null, null);
result = false;
}
else
{
result = true;
}
return result;
}
public virtual void Process()
{
}
}
}
|