File tree Expand file tree Collapse file tree 4 files changed +16
-11
lines changed Expand file tree Collapse file tree 4 files changed +16
-11
lines changed Original file line number Diff line number Diff line change @@ -174,6 +174,7 @@ void installEvents()
174174 Event . registerIn ( "createAccount" , this , "createAccount" ) ;
175175 Event . registerIn ( "login" , this , "login" ) ;
176176 Event . registerIn ( "relogin_baseapp" , this , "relogin_baseapp" ) ;
177+ Event . registerIn ( "_closeNetwork" , this , "_closeNetwork" ) ;
177178 }
178179
179180 public KBEngineArgs getInitArgs ( )
@@ -265,14 +266,14 @@ public static bool validEmail(string strEmail)
265266 */
266267 public virtual void process ( )
267268 {
269+ // 处理网络
270+ _networkInterface . process ( ) ;
271+
268272 // 处理外层抛入的事件
269273 Event . processInEvents ( ) ;
270274
271275 // 向服务端发送心跳以及同步角色信息到服务端
272276 sendTick ( ) ;
273-
274- // 处理网络
275- _networkInterface . process ( ) ;
276277 }
277278
278279 /*
@@ -287,6 +288,11 @@ public Entity player()
287288 return null ;
288289 }
289290
291+ public void _closeNetwork ( NetworkInterface networkInterface )
292+ {
293+ networkInterface . close ( ) ;
294+ }
295+
290296 /*
291297 向服务端发送心跳以及同步角色信息到服务端
292298 */
Original file line number Diff line number Diff line change @@ -188,9 +188,8 @@ public bool send(byte[] datas)
188188
189189 public void process ( )
190190 {
191- // 避免close后一些消息没有得到处理,将这里屏蔽
192- // if(!valid())
193- // return;
191+ if ( ! valid ( ) )
192+ return ;
194193
195194 if ( _packetReceiver != null )
196195 _packetReceiver . process ( ) ;
Original file line number Diff line number Diff line change @@ -119,7 +119,7 @@ public void startRecv()
119119 catch ( Exception e )
120120 {
121121 Dbg . ERROR_MSG ( "PacketReceiver::startRecv(): call ReceiveAsync() is err: " + e . ToString ( ) ) ;
122- _networkInterface . close ( ) ;
122+ Event . fireIn ( "_closeNetwork" , new object [ ] { _networkInterface } ) ;
123123 }
124124 }
125125
@@ -151,7 +151,7 @@ private static void _onRecv(IAsyncResult ar)
151151 if ( bytesRead == 0 )
152152 {
153153 Dbg . WARNING_MSG ( string . Format ( "PacketReceiver::_processRecved(): disconnect!" ) ) ;
154- state . networkInterface ( ) . close ( ) ;
154+ Event . fireIn ( "_closeNetwork" , new object [ ] { state . networkInterface ( ) } ) ;
155155 return ;
156156 }
157157 else
@@ -163,7 +163,7 @@ private static void _onRecv(IAsyncResult ar)
163163 catch ( Exception e )
164164 {
165165 Dbg . ERROR_MSG ( string . Format ( "PacketReceiver::_processRecved(): is error({0})!" , e . ToString ( ) ) ) ;
166- state . networkInterface ( ) . close ( ) ;
166+ Event . fireIn ( "_closeNetwork" , new object [ ] { state . networkInterface ( ) } ) ;
167167 }
168168 }
169169 }
Original file line number Diff line number Diff line change @@ -118,7 +118,7 @@ void _startSend()
118118 catch ( Exception e )
119119 {
120120 Dbg . ERROR_MSG ( "PacketSender::startSend(): is err: " + e . ToString ( ) ) ;
121- _networkInterface . close ( ) ;
121+ Event . fireIn ( "_closeNetwork" , new object [ ] { _networkInterface } ) ;
122122 }
123123 }
124124
@@ -155,7 +155,7 @@ private static void _onSent(IAsyncResult ar)
155155 catch ( Exception e )
156156 {
157157 Dbg . ERROR_MSG ( string . Format ( "PacketSender::_processSent(): is error({0})!" , e . ToString ( ) ) ) ;
158- state . networkInterface ( ) . close ( ) ;
158+ Event . fireIn ( "_closeNetwork" , new object [ ] { state . networkInterface ( ) } ) ;
159159 Interlocked . Exchange ( ref state . _sending , 0 ) ;
160160 }
161161 }
You can’t perform that action at this time.
0 commit comments