/** * 好友更改个人信息. */ void UdpData::SomeoneAbsence() { PalInfo *pal; const char *ptr; /* 若好友不兼容iptux协议,则需转码 */ pal = cthrd.GetPalFromList(ipv4); //利用好友链表只增不减的特性,无须加锁 ptr = iptux_skip_string(buf, size, 3); if (!ptr || *ptr == '\0') ConvertEncode(pal ? pal->encode : progdt.encode); /* 加入或更新好友列表 */ gdk_threads_enter(); pthread_mutex_lock(cthrd.GetMutex()); if (pal) { UpdatePalInfo(pal); cthrd.UpdatePalToList(ipv4); } else { pal = CreatePalInfo(); cthrd.AttachPalToList(pal); } pthread_mutex_unlock(cthrd.GetMutex()); if (mwin.PaltreeContainItem(ipv4)) mwin.UpdateItemToPaltree(ipv4); else mwin.AttachItemToPaltree(ipv4); gdk_threads_leave(); }
/** * 好友上线. */ void UdpData::SomeoneEntry() { Command cmd; pthread_t pid; PalInfo *pal; /* 转换缓冲区数据编码 */ ConvertEncode(progdt.encode); /* 加入或更新好友列表 */ gdk_threads_enter(); pthread_mutex_lock(cthrd.GetMutex()); if ( (pal = cthrd.GetPalFromList(ipv4))) { UpdatePalInfo(pal); cthrd.UpdatePalToList(ipv4); } else { pal = CreatePalInfo(); cthrd.AttachPalToList(pal); } pthread_mutex_unlock(cthrd.GetMutex()); if (mwin.PaltreeContainItem(ipv4)) mwin.UpdateItemToPaltree(ipv4); else mwin.AttachItemToPaltree(ipv4); gdk_threads_leave(); /* 通知好友本大爷在线 */ cmd.SendAnsentry(cthrd.UdpSockQuote(), pal); if (FLAG_ISSET(pal->flags, 0)) { pthread_create(&pid, NULL, ThreadFunc(CoreThread::SendFeatureData), pal); pthread_detach(pid); } }
/** * 好友信息数据丢失默认处理函数. * 若xx并不在好友列表中,但是程序却期望能够接受xx的本次会话, * 所以必须以默认数据构建好友信息数据并插入好友列表 \n */ void UdpData::SomeoneLost() { PalInfo *pal; /* 创建好友数据 */ pal = new PalInfo; pal->ipv4 = ipv4; pal->segdes = progdt.FindNetSegDescription(ipv4); if (!(pal->version = iptux_get_section_string(buf, ':', 0))) pal->version = g_strdup("?"); if (!(pal->user = iptux_get_section_string(buf, ':', 2))) pal->user = g_strdup("???"); if (!(pal->host = iptux_get_section_string(buf, ':', 3))) pal->host = g_strdup("???"); pal->name = g_strdup(_("mysterious")); pal->group = g_strdup(_("mysterious")); pal->photo = NULL; pal->sign = NULL; pal->iconfile = g_strdup(progdt.palicon); pal->encode = g_strdup(encode ? encode : "utf-8"); FLAG_SET(pal->flags, 1); pal->packetn = 0; pal->rpacketn = 0; /* 加入好友列表 */ gdk_threads_enter(); pthread_mutex_lock(cthrd.GetMutex()); cthrd.AttachPalToList(pal); pthread_mutex_unlock(cthrd.GetMutex()); mwin.AttachItemToPaltree(ipv4); gdk_threads_leave(); }
/** * 好友在线. */ void UdpData::SomeoneAnsentry() { Command cmd; pthread_t pid; PalInfo *pal; const char *ptr; /* 若好友不兼容iptux协议,则需转码 */ ptr = iptux_skip_string(buf, size, 3); if (!ptr || *ptr == '\0') ConvertEncode(progdt.encode); /* 加入或更新好友列表 */ gdk_threads_enter(); pthread_mutex_lock(cthrd.GetMutex()); if ( (pal = cthrd.GetPalFromList(ipv4))) { UpdatePalInfo(pal); cthrd.UpdatePalToList(ipv4); } else { pal = CreatePalInfo(); cthrd.AttachPalToList(pal); } pthread_mutex_unlock(cthrd.GetMutex()); if (mwin.PaltreeContainItem(ipv4)) mwin.UpdateItemToPaltree(ipv4); else mwin.AttachItemToPaltree(ipv4); gdk_threads_leave(); /* 更新本大爷的数据信息 */ if (FLAG_ISSET(pal->flags, 0)) { pthread_create(&pid, NULL, ThreadFunc(CoreThread::SendFeatureData), pal); pthread_detach(pid); } else if (strcasecmp(progdt.encode, pal->encode) != 0) cmd.SendAnsentry(cthrd.UdpSockQuote(), pal); }