/// <summary> /// 断开成功通知函数 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void SocketClosed(object sender, SocketAsyncEventArgs e) { SocketListener sl = sender as SocketListener; Socket s = (e.UserToken as AsyncUserToken).CurrentSocket; //将接收的缓冲删除 lock (dictInPackets) { if (dictInPackets.ContainsKey(s)) { TCPInPacket tcpInPacket = dictInPackets[s]; tcpInPacketPool.Push(tcpInPacket); //缓冲回收 dictInPackets.Remove(s); } } //断开连接时,清除会话实例 lock (gameServerClients) { GameServerClient client = null; if (gameServerClients.TryGetValue(s, out client)) { client.release(); gameServerClients.Remove(s); } } //通知主窗口显示连接数 //RootWindow.Dispatcher.BeginInvoke((MethodInvoker)delegate //{ RootWindow.TotalConnections = sl.ConnectedSocketsCount; //}); }
/// <summary> /// 关闭某个socket对应的角色连接 /// </summary> /// <param name="s"></param> public void ForceCloseSocket(TMSKSocket s) { //删除延迟关闭的TMSKSocket信息 DelayForceClosingMgr.RemoveDelaySocket(s); //将接收的缓冲删除 lock (dictInPackets) { if (dictInPackets.ContainsKey(s)) { TCPInPacket tcpInPacket = dictInPackets[s]; tcpInPacketPool.Push(tcpInPacket); //缓冲回收 dictInPackets.Remove(s); } } //删除客户端信息 GameClient gameClient = GameManager.ClientMgr.FindClient(s); if (null != gameClient) { //客户端离线 GameManager.ClientMgr.Logout(Global._TCPManager.MySocketListener, Global._TCPManager.TcpOutPacketPool, gameClient); gameClient = null; } string userID = GameManager.OnlineUserSession.FindUserID(s); //添加到在线回话中 GameManager.OnlineUserSession.RemoveSession(s); //删除用户名称 GameManager.OnlineUserSession.RemoveUserName(s); //删除用户是否成人标志 GameManager.OnlineUserSession.RemoveUserAdult(s); //注销UserID, 放到最后,但是获取userID放前边 if ("" != userID) { Global.RegisterUserIDToDBServer(userID, 0); } //已经关闭之后再调用一次 Global._SendBufferManager.Remove(s); //通知主窗口显示连接数 //RootWindow.Dispatcher.BeginInvoke((MethodInvoker)delegate //{ // // 通知界面修改连接数 // RootWindow.textBlock1.Text = string.Format("{0}/{1}", GameManager.ClientMgr.GetClientCount(), socketListener.ConnectedSocketsCount); //}); }