public void UpdateInfoToClients() { int idt = GetTerminalId(ClientsControl.GetTerminals()); int idr = GetRemoteDevId(ClientsControl.GetDevices()); byte[] data = new DataCover128kb(new SessionInfo(Id, idt, idr, SessionMessageType.SesInformation).Pack(), DataType.sessionInfo).Pack(); foreach (Terminal term in ClientsControl.GetTerminals()) { term.Write(data); } }
public void Session(DataCover128kb data) { CreateSession si = Protocol.BufferToObject <CreateSession>(data.Data); RemoteDevice rd = ClientsControl.GetDevices().FirstOrDefault(x => x.Id.Value == si.RemDevId); if (rd != null) { string text = $"Запрос создания сессии id{Id.Value}:{Name} id{rd.Id.Value}:{rd.Name}"; LogWriter.SendLog(text); ClientsControl.SendGlobalChat(text); byte[] ip = new byte[4]; int port = si.CustomPort; string[] ipstrar = null; if (port > -1) { ipstrar = Program.GLOBALIP.Split('.'); } else { IPEndPoint ipep = (IPEndPoint)Client.RemoteEndPoint; ipstrar = ipep.Address.ToString().Split('.'); port = ipep.Port; } for (int i = 0; i < ip.Length; i += 1) { ip[i] = byte.Parse(ipstrar[i]); } byte[] pass = Guid.NewGuid().ToByteArray(); rd.Write(new DataCover128kb(new ConnectedInfo(ip, port, pass).Pack(), DataType.createSessionIpPort).Pack()); Write(new DataCover128kb(new ConnectedInfo(((IPEndPoint)rd.Client.RemoteEndPoint).Address.GetAddressBytes(), ((IPEndPoint)rd.Client.RemoteEndPoint).Port, pass).Pack(), DataType.createSessionIpPort).Pack()); } else { string text = $"В запросе создания сессии для {Id.Value}:{Name} отказано, удаленное устройство id:{si.RemDevId} не подключено"; LogWriter.SendLog(text); ClientsControl.SendGlobalChat(text); } }