public CollectTransferedInformationForHub() { HubSetting settings = new HubSetting(); settings.Address = "127.0.0.1"; settings.Port = 411; settings.DisplayName = "FlowLib"; settings.Protocol = "Auto"; // Here we tell it we dont care what protocol it uses (Adc or Nmdc). Just try to connect. Hub hubConnection = new Hub(settings); // Here we bind hub to our data collector stats = new GeneralProtocolDataCollector(hubConnection); hubConnection.Connect(); General.BinaryPrefixes bp; Console.WriteLine("Press any key to update information"); do { Console.ReadKey(true); Console.Clear(); Console.WriteLine("Press any key to update information"); Console.WriteLine("=================================="); Console.WriteLine("Total data sent: " + General.FormatBytes(stats.TotalBytesSent, out bp) + bp); Console.WriteLine("Total data received: " + General.FormatBytes(stats.TotalBytesReceived, out bp) + bp); Console.WriteLine("current download speed: " + General.FormatBytes(stats.CurrentReceiveSpeed, out bp) + bp + "/s"); Console.WriteLine("current upload speed: " + General.FormatBytes(stats.CurrentSendSpeed, out bp) + bp + "/s"); Decimal d = new decimal(stats.MaximumReceiveSpeed); Console.WriteLine("Maximum download speed: " + General.FormatBytes(decimal.ToInt64(d), out bp) + bp + "/s"); d = new decimal(stats.MaximumSendSpeed); Console.WriteLine("Maximum upload speed: " + General.FormatBytes(decimal.ToInt64(d), out bp) + bp + "/s"); d = new decimal(stats.MinimumReceiveSpeed); Console.WriteLine("Minimum download speed: " + General.FormatBytes(decimal.ToInt64(d), out bp) + bp + "/s"); d = new decimal(stats.MinimumSendSpeed); Console.WriteLine("Minimum upload speed: " + General.FormatBytes(decimal.ToInt64(d), out bp) + bp + "/s"); Console.WriteLine("=================================="); } while (true); }
public SendMainChatOrPMToHub() { UpdateBase = new FlowLib.Events.FmdcEventHandler(SendMainChatOrPMToHub_UpdateBase); HubSetting settings = new HubSetting(); settings.Address = "127.0.0.1"; settings.Port = 411; settings.DisplayName = "FlowLib"; settings.Protocol = "Auto"; Hub hubConnection = new Hub(settings, this); hubConnection.Connect(); // YOU should really listen for regmode change here. // Im not doing it here to make example more easy to understand. // Wait 10 seconds and hope we are connected. System.Threading.Thread.Sleep(10 * 1000); // Create mainchat message. MainMessage msg = new MainMessage(hubConnection.Me.ID, "Testing"); // message will here be converted to right format and then be sent. UpdateBase(this, new FlowLib.Events.FmdcEventArgs(FlowLib.Events.Actions.MainMessage, msg)); // Create private message. PrivateMessage privMsg = new PrivateMessage("DCpp706", hubConnection.Me.ID, "Testing"); // message will here be converted to right format and then be sent. UpdateBase(this, new FlowLib.Events.FmdcEventArgs(FlowLib.Events.Actions.PrivateMessage, privMsg)); }
public HubNmdcProtocol(Hub hub, bool isSecure) : this(hub) { // We are doing this to keep a good HubSettings if (isSecure) Name = Name + "Secure"; }
public MultiConnections() { UpdateBase = new FmdcEventHandler(PassiveConnectToUser_UpdateBase); // Creates a empty share Share share = new Share("Testing"); // Port to listen for incomming connections on share.Port = 12345; incomingConnectionListener = new TcpConnectionListener(share.Port); incomingConnectionListener.Update += new FmdcEventHandler(Connection_Update); incomingConnectionListener.Start(); // Adds common filelist to share AddFilelistsToShare(share); HubSetting setting = new HubSetting(); setting.Address = "127.0.0.1"; setting.Port = 411; setting.DisplayName = "FlowLib"; setting.Protocol = "Auto"; hub = new Hub(setting, this); hub.ProtocolChange += new FmdcEventHandler(hubConnection_ProtocolChange); // Adds share to hub hub.Share = share; hub.Me.Mode = FlowLib.Enums.ConnectionTypes.Direct; hub.Connect(); last = System.DateTime.Now.Ticks; timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed); timer.AutoReset = true; timer.Interval = 1000; timer.Start(); }
public CollectTransferedInformationFromFilelistDownload() { UpdateBase = new FmdcEventHandler(PassiveConnectToUser_UpdateBase); // Creates a empty share Share share = new Share("Testing"); // Port to listen for incomming connections on share.Port = 12345; incomingConnectionListener = new TcpConnectionListener(share.Port); incomingConnectionListener.Update += new FmdcEventHandler(Connection_Update); incomingConnectionListener.Start(); // Adds common filelist to share AddFilelistsToShare(share); HubSetting setting = new HubSetting(); setting.Address = "127.0.0.1"; setting.Port = 411; setting.DisplayName = "FlowLib"; setting.Protocol = "Auto"; Hub hubConnection = new Hub(setting, this); hubConnection.ProtocolChange += new FmdcEventHandler(hubConnection_ProtocolChange); // Adds share to hub hubConnection.Share = share; //hubConnection.Me.Mode = FlowLib.Enums.ConnectionTypes.Direct; hubConnection.Me.TagInfo.Slots = 2; hubConnection.Connect(); FlowLib.Utils.Convert.General.BinaryPrefixes bp; Console.WriteLine("Press any key to update information"); do { Console.ReadKey(true); Console.Clear(); Console.WriteLine("Press any key to update information"); Console.WriteLine("=================================="); if (stats != null) { Console.WriteLine("Total data sent: " + FlowLib.Utils.Convert.General.FormatBytes(stats.TotalBytesSent, out bp) + bp); Console.WriteLine("Total data received: " + FlowLib.Utils.Convert.General.FormatBytes(stats.TotalBytesReceived, out bp) + bp); Console.WriteLine("current download speed: " + FlowLib.Utils.Convert.General.FormatBytes(stats.CurrentReceiveSpeed, out bp) + bp + "/s"); Console.WriteLine("current upload speed: " + FlowLib.Utils.Convert.General.FormatBytes(stats.CurrentSendSpeed, out bp) + bp + "/s"); Decimal d = new decimal(stats.MaximumReceiveSpeed); Console.WriteLine("Maximum download speed: " + FlowLib.Utils.Convert.General.FormatBytes(decimal.ToInt64(d), out bp) + bp + "/s"); d = new decimal(stats.MaximumSendSpeed); Console.WriteLine("Maximum upload speed: " + FlowLib.Utils.Convert.General.FormatBytes(decimal.ToInt64(d), out bp) + bp + "/s"); d = new decimal(stats.MinimumReceiveSpeed); Console.WriteLine("Minimum download speed: " + FlowLib.Utils.Convert.General.FormatBytes(decimal.ToInt64(d), out bp) + bp + "/s"); d = new decimal(stats.MinimumSendSpeed); Console.WriteLine("Minimum upload speed: " + FlowLib.Utils.Convert.General.FormatBytes(decimal.ToInt64(d), out bp) + bp + "/s"); } else { Console.WriteLine("No transfer has started yet."); } Console.WriteLine("=================================="); } while (true); }
public ActiveSearch() { UpdateBase = new FmdcEventHandler(ActiveSearch_UpdateBase); HubSetting settings = new HubSetting(); settings.Address = "127.0.0.1"; settings.Port = 411; settings.DisplayName = "FlowLib"; settings.Protocol = "Auto"; hubConnection = new Hub(settings, this); hubConnection.ProtocolChange += new FmdcEventHandler(hubConnection_ProtocolChange); hubConnection.Connect(); Share share = new Share("Test"); share.Port = 1000; // Telling that we are listening on port 1000 for incomming search results (Any means from everyone) UdpConnection udp = new UdpConnection(new IPEndPoint(IPAddress.Any, share.Port)); udp.Protocol = new FlowLib.Protocols.UdpNmdcProtocol(); udp.Protocol.MessageReceived += new FmdcEventHandler(Protocol_MessageReceived); // Enable Active searching hubConnection.Me.Mode = FlowLib.Enums.ConnectionTypes.Direct; hubConnection.Share = share; }
public ActiveEmptySharingUsingTLS() { // Creates a empty share Share share = new Share("Testing"); // Port to listen for incomming connections on share.Port = 12345; AddFilelistsToShare(share); incomingConnectionListener = new TcpConnectionListener(share.Port); incomingConnectionListener.Update += new FmdcEventHandler(Connection_Update); incomingConnectionListener.Start(); // TLS listener incomingConnectionListenerTLS = new TcpConnectionListener(tlsport); incomingConnectionListenerTLS.Update += new FmdcEventHandler(Connection_UpdateTLS); incomingConnectionListenerTLS.Start(); HubSetting setting = new HubSetting(); setting.Address = "127.0.0.1"; setting.Port = 411; setting.DisplayName = "FlowLibActiveTLS"; setting.Protocol = "Auto"; Hub hubConnection = new Hub(setting); hubConnection.ProtocolChange += new FmdcEventHandler(hubConnection_ProtocolChange); hubConnection.Share = share; hubConnection.Me.Mode = FlowLib.Enums.ConnectionTypes.Direct; #if !COMPACT_FRAMEWORK // Security, Windows Mobile doesnt support SSLStream so we disable this feature for it. hubConnection.Me.Set(UserInfo.SECURE, tlsport.ToString()); #endif hubConnection.Connect(); }
public ActiveDownloadFilelistFromUser() { UpdateBase = new FmdcEventHandler(PassiveConnectToUser_UpdateBase); // Creates a empty share Share share = new Share("Testing"); // Port to listen for incomming connections on share.Port = 12345; incomingConnectionListener = new TcpConnectionListener(share.Port); incomingConnectionListener.Update += new FmdcEventHandler(Connection_Update); incomingConnectionListener.Start(); // Adds common filelist to share AddFilelistsToShare(share); HubSetting setting = new HubSetting(); setting.Address = "127.0.0.1"; setting.Port = 411; setting.DisplayName = "FlowLib"; setting.Protocol = "Auto"; Hub hubConnection = new Hub(setting, this); hubConnection.ProtocolChange += new FmdcEventHandler(hubConnection_ProtocolChange); // Adds share to hub hubConnection.Share = share; hubConnection.Me.Mode = FlowLib.Enums.ConnectionTypes.Direct; hubConnection.Connect(); }
void buttonConnect_OnSelect(object sender, EventArgs e) { hub = new FlowLib.Connections.Hub(setting, this); hub.ConnectionStatusChange += new FmdcEventHandler(hub_ConnectionStatusChange); hub.ProtocolChange += new FmdcEventHandler(hub_ProtocolChange); hub.Connect(); // TODO : Do connect here }
/// <summary> /// Creates a Transfer request /// </summary> /// <param name="pKey">Unique key that identifies this request</param> /// <param name="pHub">Hub where request came from</param> /// <param name="pUser">User that transfer request is for</param> /// <param name="download">telling if we know that _we_ will download</param> public TransferRequest(string pKey, Hub pHub, UserInfo pUser, bool download) : this(pKey, pHub, pUser) { if (download) meDownload = 1; else meDownload = 0; }
void hubConnection_ProtocolChange(object sender, FlowLib.Events.FmdcEventArgs e) { hubConnection = sender as Hub; IProtocol prot = e.Data as IProtocol; if (prot != null) { prot.MessageReceived -= Protocol_MessageReceived; } hubConnection.Protocol.MessageReceived += new FlowLib.Events.FmdcEventHandler(Protocol_MessageReceived); }
public ReceiveMainChatOrPMFromHub() { HubSetting settings = new HubSetting(); settings.Address = "127.0.0.1"; settings.Port = 411; settings.DisplayName = "FlowLib"; settings.Protocol = "Auto"; Hub hubConnection = new Hub(settings); hubConnection.ProtocolChange += new FmdcEventHandler(hubConnection_ProtocolChange); hubConnection.Connect(); }
public DisplayRawMessages() { HubSetting settings = new HubSetting(); settings.Address = "127.0.0.1"; settings.Port = 411; settings.DisplayName = "FlowLib"; settings.Protocol = "Auto"; Hub hubConnection = new Hub(settings); hubConnection.ProtocolChange += new FlowLib.Events.FmdcEventHandler(hubConnection_ProtocolChange); hubConnection.Connect(); }
public bool ConnectToHub(string ip) { HubSetting settings = new HubSetting(); settings.Address = ip; settings.Protocol = "Zpoc"; settings.DisplayName = prefs.Nick; Hub hub = new Hub(settings); hub.Me.TagInfo.Version = "ZPoc V:3.00a"; hub.ProtocolChange += new FmdcEventHandler(protUpdate); hub.Connect(); return true; }
public RetrievingUserInfoWhenReceivingPrivateMessage() { UpdateBase = new FlowLib.Events.FmdcEventHandler(OnUpdateBase); HubSetting settings = new HubSetting(); settings.Address = "127.0.0.1"; settings.Port = 411; settings.DisplayName = "FlowLib"; settings.Protocol = "Nmdc"; Hub hubConnection = new Hub(settings, this); hubConnection.ProtocolChange += new FlowLib.Events.FmdcEventHandler(hubConnection_ProtocolChange); hubConnection.Connect(); }
public HubNmdcProtocol(Hub hub) { this.hub = hub; hub.ConnectionStatusChange += new FmdcEventHandler(hub_ConnectionStatusChange); if (hub.Share != null) hub.Share.LastModifiedChanged += new FmdcEventHandler(Share_LastModifiedChanged); Hub.RegModeUpdated += new FmdcEventHandler(Hub_RegModeUpdated); TimerCallback updateCallback = new TimerCallback(OnUpdateMyInfo); updateMyInfoTimer = new Timer(updateCallback, this, Timeout.Infinite, Timeout.Infinite); MessageReceived = new FmdcEventHandler(OnMessageReceived); MessageToSend = new FmdcEventHandler(OnMessageToSend); }
public ConnectToMe(string toNick, int port, Hub hub, Enums.SecureProtocols secProt) : base(hub, null) { this.to = toNick; this.port = port; this.address = hub.LocalAddress.Address.ToString(); if (hub.Me.ContainsKey(UserInfo.IP)) this.address = hub.Me.Get(UserInfo.IP); if ((Enums.SecureProtocols.TLS & secProt) == FlowLib.Enums.SecureProtocols.TLS) tls = true; Raw = "$ConnectToMe "+this.to+" " + this.address + ":" + (tls ? hub.Me.Get(UserInfo.SECURE) + "S" : this.port.ToString()) + "|"; if (!string.IsNullOrEmpty(to) && port > 0 && port < 65535 && !string.IsNullOrEmpty(address)) IsValid = true; }
public ConnectToHub() { HubSetting settings = new HubSetting(); settings.Address = "127.0.0.1"; settings.Port = 411; settings.DisplayName = "FlowLib"; // The below is one way to say what protocol we should use when connecting to hub. //settings.Protocol = "Nmdc"; // Here we are saying we know it is a Nmdc hub //settings.Protocol = "Adc"; // Here we are saying we know it is a Adc hub //settings.Protocol = "Auto"; // Here we tell it we dont care what protocol it uses (Adc or Nmdc). Just try to connect. Hub hubConnection = new Hub(settings); // This is a other way to say what protocol we should use when connecting hubConnection.Protocol = new FlowLib.Protocols.HubNmdcProtocol(hubConnection); hubConnection.Connect(); }
public PassiveEmptySharing() { // Creates a empty share Share share = new Share("Testing"); // Adds common filelist to share AddFilelistsToShare(share); HubSetting setting = new HubSetting(); setting.Address = "127.0.0.1"; setting.Port = 411; setting.DisplayName = "FlowLib"; setting.Protocol = "Auto"; Hub hubConnection = new Hub(setting); hubConnection.ProtocolChange += new FmdcEventHandler(hubConnection_ProtocolChange); // Adds share to hub hubConnection.Share = share; hubConnection.Connect(); }
public ChangeBotUserInfo() { HubSetting settings = new HubSetting(); settings.Address = "127.0.0.1"; settings.Port = 411; settings.DisplayName = "FlowLib"; settings.Protocol = "Auto"; Hub hubConnection = new Hub(settings); // Connection mode in UserInfo. Direct/Passive/Socket5 hubConnection.Me.Mode = FlowLib.Enums.ConnectionTypes.Direct; // Client/Bot name and version in UserInfo. hubConnection.Me.TagInfo.Version = "SpeedBot V:2.0"; // Connection in UserInfo hubConnection.Me.Connection = "104KiB/s"; // User Description in UserInfo hubConnection.Me.Description = "Testing you for a better feature"; hubConnection.Connect(); }
public ConnectToMe(Hub hub, string raw) : base(hub, raw) { // $ConnectToMe FMDC 82.182.95.201:6900 string[] sections = raw.Split(' '); if (sections.Length != 3) return; to = sections[1]; string[] address = sections[2].Split(':'); if (address.Length != 2) return; this.address = address[0]; try { if ((tls = address[1].EndsWith("S", System.StringComparison.OrdinalIgnoreCase))) address[1] = address[1].TrimEnd('S'); port = int.Parse(address[1]); } catch { } if (!string.IsNullOrEmpty(to) && !string.IsNullOrEmpty(this.address) && port > 0 && port < 65535) IsValid = true; }
public PassiveDownloadFilelistFromUserUsingTLS() { UpdateBase = new FmdcEventHandler(PassiveConnectToUser_UpdateBase); // Creates a empty share Share share = new Share("Testing"); // Adds common filelist to share AddFilelistsToShare(share); HubSetting setting = new HubSetting(); setting.Address = "127.0.0.1"; setting.Port = 411; setting.DisplayName = "FlowLibPassiveTLS"; setting.Protocol = "Auto"; Hub hubConnection = new Hub(setting, this); hubConnection.ProtocolChange += new FmdcEventHandler(hubConnection_ProtocolChange); // Adds share to hub hubConnection.Share = share; hubConnection.Me.Set(UserInfo.SECURE, ""); hubConnection.Connect(); }
public PassiveSearch() { UpdateBase = new FlowLib.Events.FmdcEventHandler(PassiveSearch_UpdateBase); HubSetting settings = new HubSetting(); settings.Address = "127.0.0.1"; settings.Port = 411; settings.DisplayName = "FlowLib"; settings.Protocol = "Auto"; Hub hubConnection = new Hub(settings,this); hubConnection.ProtocolChange += new FmdcEventHandler(hubConnection_ProtocolChange); hubConnection.Connect(); // Wait 5 seconds (We should really listen on ConnectionStatusChange instead. System.Threading.Thread.Sleep(5 * 1000); // Send Search SearchInfo searchInfo = new SearchInfo(); searchInfo.Set(SearchInfo.SEARCH, "Ubuntu"); UpdateBase(this, new FlowLib.Events.FmdcEventArgs(Actions.Search, searchInfo)); }
public Search(Hub hub, SearchInfo info) : base(hub,null) { this.info = info; #region Id string id = null; switch (hub.Me.Mode) { case FlowLib.Enums.ConnectionTypes.Direct: case FlowLib.Enums.ConnectionTypes.UPnP: case FlowLib.Enums.ConnectionTypes.Forward: string port = hub.Share.Port.ToString(); if (hub.Me.ContainsKey(UserInfo.UDPPORT)) port = hub.Me.Get(UserInfo.UDPPORT); if (hub.Me.ContainsKey(UserInfo.IP)) { id = string.Format("{0}:{1}", hub.Me.Get(UserInfo.IP), port); } else { id = string.Format("{0}:{1}", hub.LocalAddress.Address, port); } break; default: id = string.Format("Hub:{0}", hub.Me.ID); break; } #endregion string search = string.Empty; #region Size string size = "F?F?0"; if (info.ContainsKey(SearchInfo.SIZETYPE)) { switch (info.Get(SearchInfo.SIZETYPE)) { case "1": // Min Size size = "T?F" + info.Get(SearchInfo.SIZE); break; case "2": // Max Size size = "T:T" + info.Get(SearchInfo.SIZE); break; } } #endregion #region Extention string type = "?1"; switch (info.Get(SearchInfo.EXTENTION)) { case "mp3": case "mp2": case "wav": case "au": case "rm": case "mid": case "sm": type = "?2"; break; case "zip": case "arj": case "rar": case "lzh": case "gz": case "z": case "arc": case "pak": type = "?3"; break; case "doc": case "txt": case "wri": case "pdf": case "ps": case "tex": type = "?4"; break; case "pm": case "exe": case "bat": case "com": type = "?5"; break; case "gif": case "jpg": case "jpeg": case "bmp": case "pcx": case "png": case "wmf": case "psd": type = "?6"; break; case "mpg": case "mpeg": case "avi": case "asf": case "mov": type = "?7"; break; case "$0": type = "?8"; break; case "$1": type = "?9"; break; } #endregion string schStr = info.Get(SearchInfo.SEARCH); schStr = schStr.Replace(" ", "$"); #region Is TTH Search? switch (info.Get(SearchInfo.TYPE)) { case "1": // Directory type = "?8"; break; case "2": // TTH type = "?9"; schStr = "TTH:" + schStr; break; } #endregion search = string.Format("{0}{1}?{2}", size, type, schStr); Raw = string.Format("$Search {0} {1}|", id, search); }
/// <summary> /// Creates a Transfer request /// </summary> /// <param name="pKey">Unique key that identifies this request</param> /// <param name="pHub">Hub where request came from</param> /// <param name="pUser">User that transfer request is for</param> public TransferRequest(string pKey, Hub pHub, UserInfo pUser) { key = pKey; hub = pHub; user = pUser; }
public Search(Hub hub, string raw) : base(hub, raw) { bool validAddress = false; int searchPos = 0; #region Get From int pos1 =0, pos2 = 0; if (Utils.StringOperations.Find(raw, "Hub:", " ", ref pos1, ref pos2)) { searchPos = pos2; pos1 += 4; pos2 -= 1; from = raw.Substring(pos1, pos2 - pos1); validAddress = true; } else if (((pos1=0) == 0) && Utils.StringOperations.Find(raw, "$Search ", " ", ref pos1, ref pos2)) { searchPos = pos2; pos1 += 8; pos2 -= 1; string[] tmp = raw.Substring(pos1, pos2 - pos1).Split(':'); if (tmp.Length == 2) { System.Net.IPAddress ip = null; int port = -1; try { ip = System.Net.IPAddress.Parse(tmp[0]); } catch { } int.TryParse(tmp[1], out port); //if (port < || port > System.Net.IPEndPoint.MaxPort) // port = -1; if (ip != null && (System.Net.IPEndPoint.MinPort <= port && port <= System.Net.IPEndPoint.MaxPort)) { address = new System.Net.IPEndPoint(ip, port); validAddress = true; } } } #endregion #region Search Info if (searchPos != 0) { info = new SearchInfo(); string[] sections = raw.Substring(searchPos).Split('?'); if (sections.Length == 5) { #region Size Info info.Set(SearchInfo.SIZETYPE, "0"); if (sections[0] == "T") { info.Set(SearchInfo.SIZETYPE, (sections[1] == "F" ? "1" : "2")); } long size = 0; try { size = long.Parse(sections[2]); } catch { size = 0; } info.Set(SearchInfo.SIZE, size.ToString()); #endregion #region Extention string ext = string.Empty; System.Text.StringBuilder sb = new System.Text.StringBuilder(7); switch (sections[3]) { case "2": // Audio sb.Append("mp3 "); sb.Append("mp2 "); sb.Append("wav "); sb.Append("au "); sb.Append("rm "); sb.Append("mid "); sb.Append("sm"); break; case "3": // Compressed sb.Append("zip "); sb.Append("arj "); sb.Append("rar "); sb.Append("lzh "); sb.Append("gz "); sb.Append("z "); sb.Append("arc "); sb.Append("pak"); break; case "4": // Documents sb.Append("doc "); sb.Append("txt "); sb.Append("wri "); sb.Append("pdf "); sb.Append("ps "); sb.Append("tex"); break; case "5": // Executables sb.Append("exe "); sb.Append("pm "); sb.Append("bat "); sb.Append("com"); break; case "6": // Pictures sb.Append("gif "); sb.Append("jpg "); sb.Append("jpeg "); sb.Append("bmp "); sb.Append("pcx "); sb.Append("png "); sb.Append("wmf "); sb.Append("psd"); break; case "7": // Videos sb.Append("mpg "); sb.Append("mpeg "); sb.Append("avi "); sb.Append("asf "); sb.Append("mov"); break; case "8": // Folders sb.Append("$0"); info.Set(SearchInfo.TYPE, "1"); break; case "9": // TTH Search sb.Append("$1"); info.Set(SearchInfo.TYPE, "2"); break; } info.Set(SearchInfo.EXTENTION, sb.ToString()); #endregion #region Search String if (sections[4].StartsWith("TTH:")) info.Set(SearchInfo.SEARCH, sections[4].Substring(4)); else info.Set(SearchInfo.SEARCH, sections[4]); #endregion // A search is only valid if it has a valid Adress if (validAddress) { valid = true; } } } #endregion }
public void Hub_Update(object sender, FlowLib.Events.FmdcEventArgs e) { Hub hub = (Hub)sender; this.hub = hub; string str = string.Empty; switch (e.Action) { case Actions.TransferStarted: if (e.Data is ITransfer) { ITransfer trans = (ITransfer)e.Data; transferManager.StartTransfer(trans); } break; case Actions.TransferRequest: if (e.Data is TransferRequest) { TransferRequest req = (TransferRequest)e.Data; transferManager.AddTransferReq(req); } break; #region MainMessage case Actions.MainMessage: if (e.Data is MainMessage) { MainMessage mainchat = (MainMessage)e.Data; if (mainchat.From == null) str = mainchat.Content; else { User u = hub.GetUserById(mainchat.From); if (u == null) str = "<" + mainchat.From + "> " + mainchat.Content; else str = "<" + u.DisplayName + "> " + mainchat.Content; } // Test : Start user = hub.GetUserById("DC++0.699"); //User user = hub.GetUserById("DCDM++0.0495"); if (user != null && hub.Share != null) { ContentInfo ci = new ContentInfo(ContentInfo.FILELIST, FlowLib.Utils.FileLists.BaseFilelist.UNKNOWN); ci.Set(ContentInfo.STORAGEPATH, @"C:\Private\FMDC\PiP\FlowLibDemo\ConsoleDemo\bin\Debug\FileLists\" + user.ID + ".xml.bz2"); DownloadItem di = new DownloadItem(ci); downloadManager.AddDownload(di, new Source(null, user.ID)); downloadManager.DownloadCompleted += new FmdcEventHandler(DownloadManager_DownloadCompleted); this.Hub_Update(null, new FmdcEventArgs(Actions.TransferRequest, new TransferRequest(user.ID, hub, user.UserInfo))); //TransferManager.AddTransferReq(user.ID, hub, user.UserInfo); hub.Send(new FlowLib.Protocols.HubNmdc.ConnectToMe(user.ID, hub.Share.Port, hub)); } // Test : End } else str = e.Data.ToString(); Console.WriteLine(str); break; #endregion #region PrivateMessage case Actions.PrivateMessage: PrivateMessage to = (PrivateMessage)e.Data; Console.WriteLine("*** PM From: " + to.From + ", To: " + to.To + " " + to.Content); break; #endregion #region RegMode case Actions.RegMode: break; #endregion #region Status case Actions.StatusChange: HubStatus status = (HubStatus)e.Data; switch (status.Code) { case HubStatus.Codes.Disconnected: Console.WriteLine("*** Hub Disconnected"); if (status.Exception != null) { #if DEBUG if (status.Exception is System.Net.Sockets.SocketException) { System.Net.Sockets.SocketException se = (System.Net.Sockets.SocketException)status.Exception; StringBuilder sb = new StringBuilder(); sb.Append("\r\n"); sb.Append("\tErrorCode: " + se.ErrorCode + "\r\n"); sb.Append("\tMessage: " + se.Message + "\r\n"); sb.Append("\tStackTrace: " + se.StackTrace); Console.WriteLine(sb.ToString()); } #else Console.WriteLine(" : " + status.Exception.Message); //richTextBox1.AppendText(status.Exception.StackTrace); #endif } Console.WriteLine("\r\n"); break; case HubStatus.Codes.Connected: Console.WriteLine("*** Hub Connected"); break; case HubStatus.Codes.Connecting: Console.WriteLine("*** Hub Connecting"); break; } break; #endregion default: Console.WriteLine(e.Data); break; } }
/// <summary> /// Creating HubMessage /// </summary> /// <param name="hub">Hub that this message is related to</param> /// <param name="raw">raw message</param> /// <param name="from">User id of the user message was from</param> /// <param name="to">User id of the user message is to</param> public HubMessage(Hub hub, string raw, string from, string to) : base(hub,raw) { this.from = from; this.to = to; }
protected string to = null; // User ID #endregion Fields #region Constructors /// <summary> /// Creating HubMessage /// </summary> /// <param name="hub">Hub that this message is related to</param> /// <param name="raw">raw message</param> public HubMessage(Hub hub, string raw) : this(hub, raw, null, null) { }
public DcBot(HubSetting settings) { UpdateBase = new FlowLib.Events.FmdcEventHandler(DcBot_UpdateBase); downloadManager.DownloadCompleted += new FmdcEventHandler(downloadManager_DownloadCompleted); // Creates a empty share Share share = new Share("Testing"); // Do we want bot to be active? if (Program.USE_ACTIVE_MODE) { if (Program.PORT_TLS > 0) { share.Port = Program.PORT_TLS; } else { share.Port = Program.PORT_ACTIVE; } incomingConnectionListener = new TcpConnectionListener(Program.PORT_ACTIVE); incomingConnectionListener.Update += new FmdcEventHandler(Connection_Update); incomingConnectionListener.Start(); // TLS listener incomingConnectionListenerTLS = new TcpConnectionListener(Program.PORT_TLS); incomingConnectionListenerTLS.Update += new FmdcEventHandler(Connection_UpdateTLS); incomingConnectionListenerTLS.Start(); } // Adds common filelist to share AddFilelistsToShare(share); hubConnection = new Hub(settings, this); hubConnection.Me.TagInfo.Version = "Serie V:20101125"; hubConnection.Me.TagInfo.Slots = 2; // DO NOT CHANGE THIS LINE! hubConnection.Me.Set(UserInfo.PID, "7OP7K374IKV7YMEYUI5F5R4YICFT36M7FL64AWY"); // Adds share to hub hubConnection.Share = share; // Do we want bot to be active? if (Program.USE_ACTIVE_MODE) { hubConnection.Me.TagInfo.Mode = FlowLib.Enums.ConnectionTypes.Direct; hubConnection.Me.Set(UserInfo.SECURE, Program.PORT_TLS.ToString()); } else { hubConnection.Me.TagInfo.Mode = FlowLib.Enums.ConnectionTypes.Passive; hubConnection.Me.Set(UserInfo.SECURE, ""); } hubConnection.ConnectionStatusChange += new FmdcEventHandler(hubConnection_ConnectionStatusChange); hubConnection.ProtocolChange += new FmdcEventHandler(hubConnection_ProtocolChange); hubConnection.SecureUpdate += new FmdcEventHandler(hubConnection_SecureUpdate); }
public void Dispose() { if (!disposed) { hub.ConnectionStatusChange -= hub_ConnectionStatusChange; if (hub.Share != null) hub.Share.LastModifiedChanged -= Share_LastModifiedChanged; Hub.RegModeUpdated -= Hub_RegModeUpdated; hub = null; updateMyInfoTimer.Dispose(); updateMyInfoTimer = null; disposed = true; } }