public void ParseRaw(byte[] b, int length, IPEndPoint point) { string raw = Encoding.GetString(b, 0, length); if (raw == null) { return; } // If raw lenght is 0. Ignore if (raw.Length == 0) { return; } ConMessage msg = null; switch (raw[0]) { case '$': // Nmdc int pos; string cmd = null; if ((pos = raw.IndexOf(' ')) != -1) { cmd = raw.Substring(0, pos).ToLower(); } else { if (raw.Length >= 10) { break; } cmd = raw.ToLower(); } if (cmd == null || cmd.Equals(string.Empty)) { break; } switch (cmd) { case "$sr": msg = new ConMessage(null, b); break; } break; case 'U': // Adc Adc.AdcBaseMessage adc = null; if (!(adc = new Adc.RES(null, raw)).IsValid) { adc = null; } if (adc == null && !(adc = new Adc.RES(null, raw)).IsValid) { adc = null; } msg = adc; break; } // Do we support message type? if (msg == null) { return; } // Plugin handling here FmdcEventArgs e = new FmdcEventArgs(Actions.CommandIncomming, msg); MessageReceived(this, e); if (!e.Handled) { ActOnInMessage(msg); } }
protected void SendRES(SearchInfo info, UserInfo usr) { IShare share = null; if (hub != null || hub.Share != null || usr != null) { share = hub.Share; } else if (trans != null || trans.Share != null || usr != null) { share = trans.Share; } else { return; } // If we dont have a share object. break here. if (share == null) return; int maxReturns = 10; string token = null; if (info.ContainsKey(SearchInfo.TOKEN)) token = info.Get(SearchInfo.TOKEN); System.Collections.Generic.List<ContentInfo> ret = new System.Collections.Generic.List<ContentInfo>(maxReturns); // TODO : This lookup can be done nicer lock (share) { foreach (System.Collections.Generic.KeyValuePair<string, Containers.ContentInfo> var in share) { if (var.Value == null) continue; bool foundEnough = false; string ext = info.Get(SearchInfo.EXTENTION); string sch = info.Get(SearchInfo.SEARCH); if (ext != null && sch != null) { ContentInfo contentInfo = new ContentInfo(); if (info.ContainsKey(SearchInfo.TYPE)) { switch (info.Get(SearchInfo.TYPE)) { case "2": contentInfo.Set(ContentInfo.TTH, info.Get(SearchInfo.SEARCH)); if (hub.Share.ContainsContent(ref contentInfo)) { ret.Add(contentInfo); } // We are looking through whole share here. // If no TTH matching. Ignore. foundEnough = true; break; case "1": default: if (var.Value.ContainsKey(ContentInfo.VIRTUAL) && (System.IO.Path.GetDirectoryName(var.Value.Get(ContentInfo.VIRTUAL)).IndexOf(sch, System.StringComparison.OrdinalIgnoreCase) != -1)) ret.Add(var.Value); break; } } if (!foundEnough) { string infoExt = System.IO.Path.GetExtension(var.Value.Get(ContentInfo.VIRTUAL)).TrimStart('.'); if ( var.Value.ContainsKey(ContentInfo.VIRTUAL) && (var.Value.Get(ContentInfo.VIRTUAL).IndexOf(sch, System.StringComparison.OrdinalIgnoreCase) != -1) && (ext.Length == 0 || ext.Contains(infoExt)) ) ret.Add(var.Value); } } if (foundEnough || ret.Count >= maxReturns) break; } } int x = 0; // Test against size restrictions for (int i = 0; i < ret.Count; i++) { bool send = true; long size = -1; try { size = long.Parse(info.Get(SearchInfo.SIZE)); } catch { } if (info.ContainsKey(SearchInfo.SIZETYPE) && size != -1) { switch (info.Get(SearchInfo.SIZETYPE)) { case "1": // Min Size send = (size <= ret[i].Size); break; case "2": // Max Size send = (size >= ret[i].Size); break; case "3": // Equal Size send = (size == ret[i].Size); break; } } // Should this be sent? if (send) { RES res = new RES(con, ret[i], token, usr); if (res.Address != null && hub != null) { if (10 > x++) { // Send with UDP try { UdpConnection.Send(res, res.Address); } catch { } } } else { if (5 > x++) { if (hub != null) { // Send through hub hub.Send(res); } else if (trans != null) { trans.Send(res); } } } } } }
public void ParseRaw(byte[] b, int length, IPEndPoint point) { string raw = Encoding.GetString(b, 0, length); if (raw == null) return; // If raw lenght is 0. Ignore if (raw.Length == 0) return; ConMessage msg = null; switch (raw[0]) { case '$': // Nmdc int pos; string cmd = null; if ((pos = raw.IndexOf(' ')) != -1) cmd = raw.Substring(0, pos).ToLower(); else { if (raw.Length >= 10) break; cmd = raw.ToLower(); } if (cmd == null || cmd.Equals(string.Empty)) break; switch (cmd) { case "$sr": msg = new ConMessage(null, b); break; } break; case 'U': // Adc Adc.AdcBaseMessage adc = null; if (!(adc = new Adc.RES(null, raw)).IsValid) adc = null; if (adc == null && !(adc = new Adc.RES(null, raw)).IsValid) adc = null; msg = adc; break; } // Do we support message type? if (msg == null) return; // Plugin handling here FmdcEventArgs e = new FmdcEventArgs(Actions.CommandIncomming, msg); MessageReceived(this, e); if (!e.Handled) ActOnInMessage(msg); }
protected StrMessage ParseMessage(string raw) { raw = raw.Replace(this.Seperator, ""); AdcBaseMessage msg = new AdcBaseMessage(con, raw); switch (msg.Action) { case "SUP": msg = new SUP(con, raw); break; case "SID": msg = new SID(con, raw); break; case "MSG": msg = new MSG(con, raw); break; case "INF": msg = new INF(con, raw); break; case "STA": msg = new STA(con, raw); break; case "QUI": msg = new QUI(con, raw); break; case "GPA": msg = new GPA(con, raw); break; case "CTM": msg = new CTM(con, raw); break; case "SND": msg = new SND(con, raw); break; case "GFI": msg = new GFI(con, raw); break; case "GET": msg = new GET(con, raw); break; case "RCM": msg = new RCM(con, raw); break; case "SCH": msg = new SCH(con, raw); break; case "RES": msg = new RES(con, raw); break; case "PAS": msg = new PAS(con, raw); break; } return msg; }