private static void LeafLogin(Leaf leaf, TCPPacketReader packet, ulong time, LinkMode mode) { if (leaf.LoginPhase != LinkLogin.AwaitingLogin) { leaf.SendPacket(HubOutbound.LinkError(LinkError.BadProtocol)); leaf.Disconnect(); return; } byte[] credentials = packet.ReadBytes(20); leaf.Protocol = packet; leaf.Port = packet; Leaf existing = LeafPool.Leaves.Find(x => x.ExternalIP.Equals(leaf.ExternalIP) && x.Port == leaf.Port && x.Ident != leaf.Ident); if (existing != null) { existing.Disconnect(); } TrustedLeafItem item = TrustedLeavesManager.GetTrusted(leaf.ExternalIP, leaf.Port, credentials); if (item == null) { leaf.SendPacket(HubOutbound.LinkError(LinkError.Untrusted)); leaf.Disconnect(); return; } if (mode != LinkMode.Hub) { leaf.SendPacket(HubOutbound.LinkError(LinkError.Unavailable)); leaf.Disconnect(); return; } leaf.Name = item.Name; leaf.Guid = item.Guid; if (leaf.Protocol < Settings.LINK_PROTO) { leaf.SendPacket(HubOutbound.LinkError(LinkError.ExpiredProtocol)); leaf.Disconnect(); return; } leaf.LoginPhase = LinkLogin.AwaitingUserlist; leaf.Key = Crypto.CreateKey; leaf.IV = Crypto.CreateIV; leaf.SendPacket(HubOutbound.HubAck(leaf)); }
private static void InstallScript(DwmForm form, String filename) { if (form.InvokeRequired) { form.BeginInvoke(new InstallScriptHandler(InstallScript), form, filename); } else { if (!form.Visible) { form.Show(); } if (form.WindowState == FormWindowState.Minimized) { form.WindowState = FormWindowState.Normal; } form.Activate(); if (Settings.IsAway) { if (form.OverlayIcon != null) { form.OverlayIcon.Show(); } } DialogResult result = MessageBox.Show(form, "Confirm you would like to install the script: " + filename, "cb0t script installer", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { bool install_success = false; try { String url = "http://chatrooms.marsproject.net/cb0t/" + filename; byte[] data = null; WebRequest request = WebRequest.Create(url); using (WebResponse response = request.GetResponse()) using (Stream stream = response.GetResponseStream()) { List <byte> list = new List <byte>(); int size = 0; byte[] buffer = new byte[1024]; while ((size = stream.Read(buffer, 0, 1024)) > 0) { list.AddRange(buffer.Take(size)); } if (list.Count > 0) { data = list.ToArray(); } } if (data != null) { data = Zip.Decompress(data); if (data != null) { if (data.Length > 0) { TCPPacketReader reader = new TCPPacketReader(data); String dir_path = Path.Combine(Settings.ScriptPath, filename); if (!Directory.Exists(dir_path)) { Directory.CreateDirectory(dir_path); } String data_path = Path.Combine(dir_path, "data"); if (!Directory.Exists(data_path)) { Directory.CreateDirectory(data_path); } while (reader.Remaining > 0) { String name = reader.ReadString(); byte type = reader; uint size = reader; byte[] buffer = reader.ReadBytes((int)size); if (type == 1) { File.WriteAllBytes(Path.Combine(data_path, name), buffer); } else if (type == 0) { File.WriteAllBytes(Path.Combine(dir_path, name), buffer); } } AddToAutoLoad(filename); install_success = true; } } } } catch { } if (install_success) { MessageBox.Show(form, filename + " was installed successfully. Please complete the installation by restarting cb0t now.", "cb0t script installer", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show(form, filename + " was unable to be installed at this time.", "cb0t script installer", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }