示例#1
0
/**
 * 好友发送个性签名.
 */
void UdpData::SomeoneSendSign()
{
        PalInfo *pal;
        char *sign;

        if (!(pal = cthrd.GetPalFromList(ipv4)))
                return;

        /* 若好友不兼容iptux协议,则需转码 */
        if (!FLAG_ISSET(pal->flags, 0))
                ConvertEncode(pal->encode);
        /* 对编码作适当调整 */
        if (strcasecmp(pal->encode, encode ? encode : "utf-8") != 0) {
                g_free(pal->encode);
                pal->encode = g_strdup(encode ? encode : "utf-8");
        }
        /* 更新 */
        if ( (sign = ipmsg_get_attach(buf, ':', 5))) {
                g_free(pal->sign);
                pal->sign = sign;
                gdk_threads_enter();
                pthread_mutex_lock(cthrd.GetMutex());
                cthrd.UpdatePalToList(ipv4);
                pthread_mutex_unlock(cthrd.GetMutex());
                mwin.UpdateItemToPaltree(ipv4);
                gdk_threads_leave();
        }
}
示例#2
0
/**
 * 好友更改个人信息.
 */
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();
}
示例#3
0
/**
 * 好友上线.
 */
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);
        }
}
示例#4
0
/**
 * 好友发送头像数据.
 */
void UdpData::SomeoneSendIcon()
{
        PalInfo *pal;
        char *iconfile;

        if (!(pal = cthrd.GetPalFromList(ipv4)) || FLAG_ISSET(pal->flags, 2))
                return;

        /* 接收并更新数据 */
        if ( (iconfile = RecvPalIcon())) {
                g_free(pal->iconfile);
                pal->iconfile = iconfile;
                gdk_threads_enter();
                pthread_mutex_lock(cthrd.GetMutex());
                cthrd.UpdatePalToList(ipv4);
                pthread_mutex_unlock(cthrd.GetMutex());
                mwin.UpdateItemToPaltree(ipv4);
                gdk_threads_leave();
        }
}
示例#5
0
/**
 * 确保好友一定在线.
 * @return 好友数据
 */
PalInfo *UdpData::AssertPalOnline()
{
        PalInfo *pal;

        if ( (pal = cthrd.GetPalFromList(ipv4))) {
                /* 既然好友不在线,那么他自然不在列表中 */
                if (!FLAG_ISSET(pal->flags, 1)) {
                        FLAG_SET(pal->flags, 1);
                        gdk_threads_enter();
                        pthread_mutex_lock(cthrd.GetMutex());
                        cthrd.UpdatePalToList(ipv4);
                        pthread_mutex_unlock(cthrd.GetMutex());
                        mwin.AttachItemToPaltree(ipv4);
                        gdk_threads_leave();
                }
        } else {
                SomeoneLost();
                pal = cthrd.GetPalFromList(ipv4);
        }

        return pal;
}
示例#6
0
/**
 * 好友在线.
 */
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);
}