public void initUserConnection(TcpConnection _conn, string[] _formatData) { _disabledConnections.Remove(_conn); NetworkUser user = new NetworkUser(_conn); _userConnections.Add(user); _conn.OnRecieveTcpPackage += (string _data) => { string[] formatData = _data.Split(';'); Console.WriteLine(string.Format("[SERVER] USER[{0}] recieved data: {1}", _conn.networkId, _data)); if (formatData[0] == "GETDEV") { user.updateDevices(_enabledConnections.ToArray()); } else if (formatData[0] == "DEVSEN") { string command = ""; for (int i = 2; i < formatData.Length; i++) { command += formatData[i]; if (i < formatData.Length - 1) { command += ";"; } } NetworkDevice device = _enabledConnections.Find(x => x.id == formatData[1]); if (device != null) { device.send(command); } } else if (formatData[0] == "RESYNCSET") { if (formatData[1] == "info") { SettingsController.resyncInfo(formatData[2]); } else if (formatData[1] == "tree") { SettingsController.resyncTree(formatData[2]); } else if (formatData[1] == "commands") { SettingsController.resyncCommands(formatData[2]); } } }; _conn.OnConnectionClosed += () => { _userConnections.Remove(user); }; Thread th = new Thread(new ParameterizedThreadStart(_syncSettings)); th.Start(_conn); }