/// <summary> /// 向服务器发送客户端信息 /// </summary> /// <param name="tcpClient"></param> private void InitServerInfo(P2PTcpClient tcpClient) { Send_0x0101 sendPacket = new Send_0x0101(); LogUtils.Info($"注册客户端:{Global.ClientName}"); tcpClient.Client.Send(sendPacket.PackData()); }
/// <summary> /// 向服务器发送客户端信息 /// </summary> /// <param name="tcpClient"></param> private void InitServerInfo(P2PTcpClient tcpClient) { Send_0x0101 sendPacket = new Send_0x0101(); LogUtils.Info($"客户端名称:{ConfigCenter.Instance.ClientName}"); tcpClient.Client.Send(sendPacket.PackData()); }
public override bool Excute() { string clientName = BinaryUtils.ReadString(m_data); string authCode = BinaryUtils.ReadString(m_data); if (Global.ClientAuthList.Count == 0 || Global.ClientAuthList.Any(t => t.Match(clientName, authCode))) { bool isSuccess = true; P2PTcpItem item = new P2PTcpItem(); item.TcpClient = m_tcpClient; if (Global.TcpMap.ContainsKey(clientName)) { if (Global.TcpMap[clientName].TcpClient.IsDisConnected) { Global.TcpMap[clientName].TcpClient.Close(); Global.TcpMap[clientName] = item; } else { isSuccess = false; Send_0x0101 sendPacket = new Send_0x0101(m_tcpClient, false, $"ClientName:{clientName} 已被使用"); m_tcpClient.Client.Send(sendPacket.PackData()); m_tcpClient.Close(); try { Global.TcpMap[clientName].TcpClient.Client.Send(new Send_0x0052().PackData()); } catch (Exception) { Global.TcpMap.Remove(clientName); } } } else { Global.TcpMap.Add(clientName, item); } if (isSuccess) { m_tcpClient.ClientName = clientName; Send_0x0101 sendPacket = new Send_0x0101(m_tcpClient, true, $"客户端{clientName}认证通过"); m_tcpClient.Client.Send(sendPacket.PackData()); } } else { Send_0x0101 sendPacket = new Send_0x0101(m_tcpClient, false, $"客户端{clientName}认证失败"); m_tcpClient.Client.Send(sendPacket.PackData()); m_tcpClient.Close(); } return(true); }
public override bool Excute() { LogUtils.Trace($"开始处理消息:0x0101"); bool ret = true; string clientName = BinaryUtils.ReadString(m_data); string authCode = BinaryUtils.ReadString(m_data); if (appCenter.Config.ClientAuthList.Count == 0 || appCenter.Config.ClientAuthList.Any(t => t.Match(clientName, authCode))) { bool isSuccess = true; P2PTcpItem item = new P2PTcpItem(); item.TcpClient = m_tcpClient; if (clientCenter.TcpMap.ContainsKey(clientName)) { if (clientCenter.TcpMap[clientName].TcpClient.IsDisConnected) { clientCenter.TcpMap[clientName].TcpClient?.SafeClose(); clientCenter.TcpMap[clientName] = item; } else { isSuccess = false; Send_0x0101 sendPacket = new Send_0x0101(m_tcpClient, false, $"ClientName:{clientName} 已被使用", clientName); LogUtils.Info($"客户端【{clientName}】接入被拒绝,名称被使用,ip:{m_tcpClient.RemoteEndPoint}"); EasyOp.Do(() => m_tcpClient.BeginSend(sendPacket.PackData())); ret = false; } } else { clientCenter.TcpMap.Add(clientName, item); } if (isSuccess) { m_tcpClient.IsAuth = true; m_tcpClient.ClientName = clientName; Send_0x0101 sendPacket = new Send_0x0101(m_tcpClient, true, $"客户端{clientName}认证通过", clientName); m_tcpClient.BeginSend(sendPacket.PackData()); LogUtils.Info($"客户端【{clientName}】成功接入,ip:{m_tcpClient.RemoteEndPoint}"); } } else { Send_0x0101 sendPacket = new Send_0x0101(m_tcpClient, false, $"客户端{clientName}认证失败", clientName); LogUtils.Info($"客户端【{clientName}】接入被拒绝,授权码错误或客户端名称不在AllowClient内,ip:{m_tcpClient.RemoteEndPoint}"); m_tcpClient.BeginSend(sendPacket.PackData()); ret = false; } return(ret); }
/// <summary> /// 向服务器发送客户端信息 /// </summary> /// <param name="tcpClient"></param> private void InitServerInfo(P2PTcpClient tcpClient) { if (string.IsNullOrWhiteSpace(ConfigCenter.Instance.ClientName)) { Send_0x0104 sendPacket = new Send_0x0104(); tcpClient.Client.Send(sendPacket.PackData()); } else { Send_0x0101 sendPacket = new Send_0x0101(); LogUtils.Info($"客户端名称:{ConfigCenter.Instance.ClientName}"); tcpClient.Client.Send(sendPacket.PackData()); } }
/// <summary> /// 向服务器发送客户端信息 /// </summary> /// <param name="tcpClient"></param> private void InitServerInfo(P2PTcpClient tcpClient) { if (string.IsNullOrWhiteSpace(appCenter.Config.ClientName)) { Send_0x0104 sendPacket = new Send_0x0104(); byte[] dataAr = sendPacket.PackData(); tcpClient.GetStream().WriteAsync(dataAr, 0, dataAr.Length); } else { Send_0x0101 sendPacket = new Send_0x0101(); LogUtils.Info($"客户端名称:{appCenter.Config.ClientName}"); byte[] dataAr = sendPacket.PackData(); tcpClient.GetStream().WriteAsync(dataAr, 0, dataAr.Length); } }
public override bool Excute() { LogUtils.Trace($"开始处理消息:0x0104"); bool ret = true; string macAddress = BinaryUtils.ReadString(m_data); string clientName = clientCenter.GetClientName(macAddress); bool isSuccess = true; P2PTcpItem item = new P2PTcpItem(); item.TcpClient = m_tcpClient; if (appCenter.Config.ClientAuthList.Count == 0 || appCenter.Config.ClientAuthList.Any(t => t.Match(clientName, "auto"))) { if (clientCenter.TcpMap.ContainsKey(clientName)) { if (clientCenter.TcpMap[clientName].TcpClient.IsDisConnected) { clientCenter.TcpMap[clientName].TcpClient?.SafeClose(); clientCenter.TcpMap[clientName] = item; } else { isSuccess = false; Send_0x0101 sendPacket = new Send_0x0101(m_tcpClient, false, $"ClientName:{clientName} 已被使用", clientName); m_tcpClient.BeginSend(sendPacket.PackData()); ret = false; } } else { clientCenter.TcpMap.Add(clientName, item); } if (isSuccess) { m_tcpClient.ClientName = clientName; Send_0x0101 sendPacket = new Send_0x0101(m_tcpClient, true, $"客户端{clientName}认证通过", clientName); m_tcpClient.BeginSend(sendPacket.PackData()); } } else { Send_0x0101 sendPacket = new Send_0x0101(m_tcpClient, false, $"客户端{clientName}认证失败", clientName); m_tcpClient.BeginSend(sendPacket.PackData()); ret = false; } return(ret); }
public override bool Excute() { string macAddress = BinaryUtils.ReadString(m_data); string clientName = ClientCenter.Instance.GetClientName(macAddress); bool isSuccess = true; P2PTcpItem item = new P2PTcpItem(); item.TcpClient = m_tcpClient; if (ClientCenter.Instance.TcpMap.ContainsKey(clientName)) { if (ClientCenter.Instance.TcpMap[clientName].TcpClient.IsDisConnected) { ClientCenter.Instance.TcpMap[clientName].TcpClient.SafeClose(); ClientCenter.Instance.TcpMap[clientName] = item; } else { isSuccess = false; Send_0x0101 sendPacket = new Send_0x0101(m_tcpClient, false, $"ClientName:{clientName} 已被使用", clientName); m_tcpClient.Client.Send(sendPacket.PackData()); m_tcpClient.SafeClose(); try { ClientCenter.Instance.TcpMap[clientName].TcpClient.Client.Send(new Send_0x0052().PackData()); } catch (Exception) { ClientCenter.Instance.TcpMap.Remove(clientName); } } } else { ClientCenter.Instance.TcpMap.Add(clientName, item); } if (isSuccess) { m_tcpClient.ClientName = clientName; Send_0x0101 sendPacket = new Send_0x0101(m_tcpClient, true, $"客户端{clientName}认证通过", clientName); m_tcpClient.Client.Send(sendPacket.PackData()); } return(true); }
/// <summary> /// 向服务器发送客户端信息 /// </summary> /// <param name="tcpClient"></param> private void InitServerInfo(P2PTcpClient tcpClient) { Send_0x0101 sendPacket = new Send_0x0101(); tcpClient.Client.Send(sendPacket.PackData()); }