void convSetPresence_MsgRcv(object sender, ConversationArgs e) { SipMessage sipPacket = PacketFactory.PGSetPresence(); this.convMgr.SendRawPacket(sipPacket); this.convMgr.Remove(int.Parse(e.RawPacket.CallID.Value)); }
void fetion_DeleteBuddyResult(object sender, ConversationArgs e) { if (e.Text == "200") { Console.WriteLine("删除好友成功"); } }
private void ConvGetContactInfo_MsgRcv(object sender, ConversationArgs e) { SipResponse rsp = e.RawPacket as SipResponse; if (rsp.StatusCode != 200) { Log.WriteLog(LogFile.Trace, "未能获取该好友详细信息"); return; } XDocument doc = XDocument.Parse(e.Text); if (doc.Element("results").Elements("contact").Count() > 0) { foreach (var c in doc.Element("results").Elements("contact")) { SipUri uri = new SipUri(c.Attribute("uri").Value); string userid = c.Attribute("user-id").Value; string mobile = c.Attribute("mobile-no") != null?c.Attribute("mobile-no").Value : string.Empty; string name = c.Attribute("name").Value; string nickname = c.Attribute("nickname").Value; string impresa = c.Attribute("impresa").Value; Contact contact = new Contact(uri, userid, string.Empty, nickname, ContactType.Buddy); if (!string.IsNullOrEmpty(mobile)) { contact.MobileNo = long.Parse(mobile); } contact.Impresa = impresa; this.user.ContactsManager.Add(contact); } this.convGetContactInfo.MsgRcv -= new EventHandler <ConversationArgs>(this.ConvGetContactInfo_MsgRcv); } }
public virtual void RaiseSyncUserInfo(object sender, ConversationArgs e) { if (SyncUserInfo != null) { this.SyncUserInfo(this, e); } }
private void ConvAddBuddy_MsgRcv(object sender, ConversationArgs e) { SipMessage sipMsg = e.RawPacket; SipResponse rsp = sipMsg as SipResponse; string result = string.Empty; if (rsp != null) { Log.WriteLog(LogFile.Debug, string.Format("addbuddy result:{0}", e.RawPacket)); if (rsp.StatusCode == 200) { XDocument doc = XDocument.Parse(e.Text); if (doc.Element("results").Element("contacts") != null) { var buddies = doc.Element("results").Element("contacts").Element("buddies").Elements("buddy"); foreach (var buddy in buddies) { string localname = buddy.Attribute("local-name").Value; string userid = buddy.Attribute("user-id").Value; string uri = buddy.Attribute("uri").Value; result = uri; } } } if (this.AddBuddyResult != null) { ConversationArgs resultArg = new ConversationArgs(IMType.AddBuddyResult, rsp); resultArg.Text = result; this.AddBuddyResult(this, resultArg); this.convAddBuddy.MsgRcv -= new EventHandler <ConversationArgs>(this.ConvAddBuddy_MsgRcv); } } }
public virtual void RaisePresenceNotify(object send, ConversationArgs e) { if (PresenceNotify != null) { this.PresenceNotify(this, e); } }
private void fetion_DeleteBuddyResult(object sender, ConversationArgs e) { if (e.Text == "200") { notify.ShowBalloonTip(100, "", "删除好友成功", ToolTipIcon.Info); } }
public virtual void RaiseAddBuddyApplication(object send, ConversationArgs e) { if (AddBuddyRequest != null) { this.AddBuddyRequest(send, e); } }
public virtual void RaiseMsgRcv(object sender, ConversationArgs e) { if (this.MsgReceived != null) { this.MsgReceived(sender, e); } }
void fetion_AddBuddyRequest(object sender, ConversationArgs e) { XDocument doc = XDocument.Parse(e.Text); string uri = doc.Element("events").Element("event").Element("application").Attribute("uri").Value; string desc = doc.Element("events").Element("event").Element("application").Attribute("desc").Value; string userid = doc.Element("events").Element("event").Element("application").Attribute("user-id").Value; fetion.SendToSelf(uri + "添加你为好友"); fetion.AgreeAddBuddy(new SipUri(uri), userid); }
void ConvRegSipcStep1_OnMsgRcv(object sender, ConversationArgs e) { string nonce; string rsaKey; this.GetNonceAndRSAKey(e.RawPacket.WWWAuthenticate.Value, out nonce, out rsaKey); this.convRegSipcStep1.MsgRcv -= new EventHandler <ConversationArgs>(this.ConvRegSipcStep1_OnMsgRcv); this.convMgr.Remove(this.convRegSipcStep1.CallID); this.SingInSipcStep2(nonce, rsaKey); }
void fetion_MsgReceived(object sender, ConversationArgs e) { if (sender != null) { Conversation conv = (Conversation)sender; if (e.MsgType == IMType.Text || e.MsgType == IMType.SMS) { } } }
private void fetion_AddBuddyApplication(object sender, ConversationArgs e) { XDocument doc = XDocument.Parse(e.Text); string uri = doc.Element("events").Element("event").Element("application").Attribute("uri").Value; string desc = doc.Element("events").Element("event").Element("application").Attribute("desc").Value; string userid = doc.Element("events").Element("event").Element("application").Attribute("user-id").Value; fetion.SendToSelf(uri + "添加你为好友"); fetion.AgreeAddBuddy(new SipUri(uri), userid); RobotCore.SendEMail("HaozesFx Robot Message", uri.ToString() + " 添加你的机器人为好友,机器人已自动添加他为好友"); }
private void convMgr_SyncUserInfo(object sender, ConversationArgs e) { XDocument doc = XDocument.Parse(e.Text); //忽略了其他消息,如用户等级等 if (doc.Element("events") .Element("event") .Element("user-info") .Element("contact-list") == null) { return; } var buddylist = doc.Element("events") .Element("event") .Element("user-info") .Element("contact-list") .Element("buddies") .Elements("buddy"); if (buddylist != null) { foreach (var buddy in buddylist) { var action = buddy.Attribute("action").Value; var userid = buddy.Attribute("user-id").Value; switch (action.ToLower()) { case "remove": this.user.ContactsManager.Delete(userid); break; case "add": var localName = buddy.Attribute("local-name").Value; var uri = buddy.Attribute("uri").Value; this.user.ContactsManager.Add(new Contact(new SipUri(uri), localName, ContactType.Buddy)); break; case "update": var c = this.user.ContactsManager.GetContact(userid); if (c != null) { this.GetContactInfo(c.Uri, c.UserId); } break; default: break; } } } }
private void fetion_AddBuddyResult(object sender, ConversationArgs e) { string result = e.Text; if (!string.IsNullOrEmpty(result)) { notify.ShowBalloonTip(100, "", string.Format("添加好友:{0}成功!", result), ToolTipIcon.Info); } else { notify.ShowBalloonTip(100, "", "添加好友失败!", ToolTipIcon.Info); } }
void fetion_AddBuddyResult(object sender, ConversationArgs e) { string result = e.Text; if (!string.IsNullOrEmpty(result)) { Console.WriteLine(string.Format("添加好友:{0}成功!", result)); } else { Console.WriteLine("添加好友失败!"); } }
private void ConvHandleContactRequest_MsgRcv(object sender, ConversationArgs e) { XDocument doc = XDocument.Parse(e.Text); if (doc.Element("results").Element("contacts") != null) { var buddies = doc.Element("results").Element("contacts").Element("buddies").Elements("buddy"); foreach (var buddy in buddies) { string localname = buddy.Attribute("local-name").Value; string userid = buddy.Attribute("user-id").Value; Contact c = this.user.ContactsManager.GetContact(userid); if (c != null) { c.LocalName = localname; this.user.ContactsManager.Update(c); } } this.convHandleContactRequest.MsgRcv -= new EventHandler <ConversationArgs>(this.ConvHandleContactRequest_MsgRcv); } }
private void ConvDeleteBuddy_MsgRcv(object sender, ConversationArgs e) { SipResponse rsp = e.RawPacket as SipResponse; if (rsp != null) { XmlDocument document = new XmlDocument(); document.LoadXml(rsp.Body); XmlNode node = document.SelectSingleNode("results/contacts/buddies/buddy"); if (node != null) { string uri = XmlHelper.ReadXmlAttributeString(node, "uri"); if (!string.IsNullOrEmpty(uri)) { this.user.ContactsManager.Delete(new SipUri(uri)); } } ConversationArgs resultArg = new ConversationArgs(IMType.DeleteBuddyResult, rsp); resultArg.Text = rsp.StatusCode.ToString(); this.DeleteBuddyResult(this, resultArg); this.convDeleteBuddy.MsgRcv -= new EventHandler <ConversationArgs>(this.ConvDeleteBuddy_MsgRcv); } }
void convRegSipcStep2_MsgRcv(object sender, ConversationArgs e) { SipResponse rsp = e.RawPacket as SipResponse; if (rsp != null && rsp.StatusCode == 200) { Log.WriteLog(LogFile.Debug, "step2:Sign in SIPC Server Successful!"); this.user.CreatePersonalInfo(rsp.Body); this.user.ContactsManager.InitContactList(rsp.Body); EventHandler <LoginEventArgs> handlerSuccess = this.LoginSucceed; if (handlerSuccess != null) { handlerSuccess(this, null); this.convRegSipcStep2.MsgRcv -= new EventHandler <ConversationArgs>(this.convRegSipcStep2_MsgRcv); this.convMgr.Remove(this.convRegSipcStep2.CallID); } } else if (rsp != null && rsp.StatusCode == 421) {//需要验证码 string wwwAuth = rsp.WWWAuthenticate.Value.Trim(); IDictionary <string, string> hash = GetKeyValueList(wwwAuth); string algorithm = hash["Verify algorithm"]; string type = hash["type"]; var doc = XDocument.Parse(rsp.Body); string reason = doc.Element("results").Element("reason").Attribute("text").Value; byte[] picBuffer; string chid; HttpHelper.GetPicCodeV4(algorithm, out picBuffer, out chid); string picRsp = this.VerifyCodeRequired(reason, picBuffer); SipMessage step2data = PacketFactory.RegSipcStep2(this.sipcResponse, algorithm, type, picRsp, chid); this.user.Conncetion.Send(step2data); } else if (rsp != null && rsp.StatusCode == 401) { this.LoginFailed(this, new LoginEventArgs("密码错误")); } else if (rsp != null && rsp.StatusCode == 420) { this.LoginFailed(this, new LoginEventArgs("输入验证码错误")); } else if (rsp != null && rsp.StatusCode == 424) { this.LoginFailed(this, new LoginEventArgs("登陆次数超过限制")); } else if (rsp != null && rsp.StatusCode == 431) { this.LoginFailed(this, new LoginEventArgs("用户正在更换飞信号,暂时无法登陆")); } else if (rsp != null && rsp.StatusCode == 432) { this.LoginFailed(this, new LoginEventArgs("当前飞信号已停止使用")); } else if (rsp != null && rsp.StatusCode == 435) { this.LoginFailed(this, new LoginEventArgs("您未绑定安全邮箱或手机号")); } else { this.LoginFailed(this, new LoginEventArgs("step2:Sign in SIPC Server failed!")); } }
void convMgr_PresenceNotify(object sender, ConversationArgs e) { this.user.ContactsManager.PresenceNotify(e.Text); }
public void ReceiveSipMessage(object sender, ConversationArgs e) { SipMessage packet = e.RawPacket; DebugWriter.WriteRCVPacket(packet); SipRequest req = packet as SipRequest; Conversation conv = this.convMgr.Find(packet); if (conv != null) { conv.RcvPacket(packet); } if (req != null) { string sipMethod = req.Method; int callID = int.Parse(req.CallID.Value); switch (sipMethod) { case SipMethodName.Invite: this.StartChat(req); break; case SipMethodName.Message: //haozes 11/25 手机客户端发来的ContentType为空 if (req.ContentType == null || string.Compare(req.ContentType.Value, "text/plain") == 0 || string.Compare(req.ContentType.Value, "text/html-fragment") == 0) { //短信 if (this.convMgr.Find(req) == null) { Conversation newSMSConv = this.convMgr.Create(req); if (newSMSConv != null) { newSMSConv.MsgRcv += new EventHandler <ConversationArgs>(this.convMgr.RaiseMsgRcv); newSMSConv.RcvPacket(req); } } } break; case SipMethodName.Bye: this.convMgr.Remove(callID); break; case SipMethodName.Benotify: if (string.Equals(req.Event.Value, SipEvent.PresenceV4.ToString(), StringComparison.OrdinalIgnoreCase)) { this.convMgr.RaisePresenceNotify(this, e); } else if (string.Equals(req.Event.Value, SipEvent.Registration.ToString(), StringComparison.OrdinalIgnoreCase)) { //registration if (req.Body.IndexOf("deregistered") > 0) { this.convMgr.RaiseDeregistered(this, null); } } else if (string.Equals(req.Event.Value, SipEvent.SyncUserInfoV4.ToString(), StringComparison.OrdinalIgnoreCase)) { this.convMgr.RaiseSyncUserInfo(this, e); } else if (string.Equals(req.Event.Value, SipEvent.Contact.ToString(), StringComparison.OrdinalIgnoreCase)) { //contact string eventType = this.GetEventType(e.Text); if (string.Equals(eventType, "AddBuddyApplication", StringComparison.OrdinalIgnoreCase)) { convMgr.RaiseAddBuddyApplication(this, new ConversationArgs(IMType.AddBuddyRequest, req)); } } else if (string.Equals(req.Event.Value, SipEvent.Conversation.ToString(), StringComparison.CurrentCultureIgnoreCase)) { string eventType = GetEventType(e.Text); if (string.Equals(eventType, "UserLeft", StringComparison.CurrentCultureIgnoreCase)) { Log.WriteLog(LogFile.Debug, "UserLeft raised!"); this.convMgr.UserLeftConvsersation(callID, GetMember(e.Text)); } } break; default: break; } //switch end } }