void client_ExpOUtPut(ConClient conClient, string Message) { SessionObj session = null; if (ConnUserList.ContainsKey(conClient.Key)) { session = ConnUserList[conClient.Key]; session.IsConnect = false; } LLOG(string.Format("客户连接断开 {0}:{1}", conClient.Host + ":" + conClient.Port, conClient.Key), ActionType.None); if (SessionDisconnect != null) { SessionDisconnect(conClient.Key, string.Format("客户连接断开 {0}:{1}", conClient.Host + ":" + conClient.Port, conClient.Key)); } }
/// <summary> /// 数据包处理 /// </summary> /// <param name="data"></param> private void BufferIn(byte[] data) { ReadBytes read = new ReadBytes(data); int length; int cmd; if (read.ReadInt32(out length) && length == read.Length && read.ReadInt32(out cmd)) { switch (cmd) { case -1000: { RegSession session; if (read.ReadObject <RegSession>(out session)) { if (session.IsSuccess) { this.Id = session.Id; this.RegPort = session.Port; LLOG("MY ID:" + this.Id, ActionType.Message); GetAllUserSession(); } else { LLOG(session.Msg, ActionType.Error); MainClient.Close(); } } } break; case -1001: { GetAllSession allsession; if (read.ReadObject <GetAllSession>(out allsession)) { if (allsession.IsSuccess && allsession.UserIds != null) { CheckDroupConnect(allsession); foreach (var Id in allsession.UserIds) { if (!ConnUserList.ContainsKey(Id)) { SessionObj tmp = new SessionObj() { Id = Id }; ConnUserList.AddOrUpdate(Id, tmp, (a, b) => tmp); UserMaskList.Enqueue(Id); } } RunQueueList(); } } } break; case -1002: { ConnectTo connto; if (read.ReadObject <ConnectTo>(out connto)) { if (connto.IsSuccess) { RegConnectTo(connto.Host, connto.Port, connto.Id); } } } break; case -1003: { LEFTConnect leftconnto; if (read.ReadObject <LEFTConnect>(out leftconnto)) { if (leftconnto.IsSuccess) { RunConnToMe(leftconnto.Host, leftconnto.Port, leftconnto.Id); } } } break; case -1004: { AddSession addsession; if (read.ReadObject <AddSession>(out addsession)) { if (addsession.Id != this.Id) { if (!ConnUserList.ContainsKey(addsession.Id)) { SessionObj tmp = new SessionObj() { Id = addsession.Id }; ConnUserList.AddOrUpdate(addsession.Id, tmp, (a, b) => tmp); LLOG("Add Session:" + addsession.Id, ActionType.Message); } } } } break; case -1005: { RemoveSession remove; if (read.ReadObject <RemoveSession>(out remove)) { if (ConnUserList.ContainsKey(remove.Id)) { DropConnUser(remove.Id); LLOG("Remove Session:" + remove.Id, ActionType.Message); } } } break; case -2000: { ProxyData proxydata; if (read.ReadObject <ProxyData>(out proxydata)) { if (DataInput != null) { DataInput(proxydata.Source, proxydata.Data); } } } break; } } }