示例#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::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);
        }
}
示例#3
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();
}
示例#4
0
/**
 * 好友信息数据丢失默认处理函数.
 * 若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();
}
示例#5
0
/**
 * 好友对话框入口.
 * @param grpinf 好友群组信息
 */
void DialogPeer::PeerDialogEntry(GroupInfo *grpinf)
{
        DialogPeer *dlgpr;
        GtkWidget *window, *widget;

        dlgpr = new DialogPeer(grpinf);
        window = dlgpr->CreateMainWindow();
        gtk_container_add(GTK_CONTAINER(window), dlgpr->CreateAllArea());
        gtk_widget_show_all(window);

        /* 将焦点置于文本输入框 */
        widget = GTK_WIDGET(g_datalist_get_data(&dlgpr->widset,
                                         "input-textview-widget"));
        gtk_widget_grab_focus(widget);

        /* 从消息队列中移除 */
        pthread_mutex_lock(cthrd.GetMutex());
        if (cthrd.MsglineContainItem(grpinf)) {
                mwin.MakeItemBlinking(grpinf, FALSE);
                cthrd.PopItemFromMsgline(grpinf);
        }
        pthread_mutex_unlock(cthrd.GetMutex());

        /* delete dlgpr;//请不要这样做,此类将会在窗口被摧毁后自动释放 */
}
示例#6
0
/**
 * 发送本机共享文件信息入口.
 * @param pal class PalInfo
 */
void SendFile::SendSharedInfoEntry(PalInfo *pal)
{
        GSList *list;

        pthread_mutex_lock(cthrd.GetMutex());
        list = cthrd.GetPublicFileList();
        SendFileInfo(pal, IPTUX_SHAREDOPT, list);
        pthread_mutex_unlock(cthrd.GetMutex());
}
示例#7
0
/**
 * 好友退出.
 */
void UdpData::SomeoneExit()
{
        PalInfo *pal;

        /* 从好友链表中删除 */
        gdk_threads_enter();
        if (mwin.PaltreeContainItem(ipv4))
                mwin.DelItemFromPaltree(ipv4);
        pthread_mutex_lock(cthrd.GetMutex());
        if ( (pal = cthrd.GetPalFromList(ipv4))) {
                cthrd.DelPalFromList(ipv4);
                FLAG_CLR(pal->flags, 1);
        }
        pthread_mutex_unlock(cthrd.GetMutex());
        gdk_threads_leave();
}
示例#8
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();
        }
}
示例#9
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;
}
示例#10
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);
}
示例#11
0
/**
 * 好友广播消息.
 */
void UdpData::SomeoneBcstmsg()
{
        GroupInfo *grpinf;
        PalInfo *pal;
        uint32_t commandno, packetno;
        char *text;

        /* 如果对方兼容iptux协议,则无须再转换编码 */
        pal = cthrd.GetPalFromList(ipv4);
        if (!pal || !FLAG_ISSET(pal->flags, 0))
                ConvertEncode(pal ? pal->encode : progdt.encode);
        /* 确保好友在线,并对编码作出适当调整 */
        pal = AssertPalOnline();
        if (strcasecmp(pal->encode, encode ? encode : "utf-8") != 0) {
                g_free(pal->encode);
                pal->encode = g_strdup(encode ? encode : "utf-8");
        }

        /* 检查此消息是否过时 */
        packetno = iptux_get_dec_number(buf, ':', 1);
        if (packetno <= pal->packetn)
                return;
        pal->packetn = packetno;

        /* 插入消息&在消息队列中注册 */
        text = ipmsg_get_attach(buf, ':', 5);
        if (text && *text != '\0') {
                commandno = iptux_get_dec_number(buf, ':', 4);
                /*/* 插入消息 */
                switch (GET_OPT(commandno)) {
                case IPTUX_BROADCASTOPT:
                        InsertMessage(pal, GROUP_BELONG_TYPE_BROADCAST, text);
                        break;
                case IPTUX_GROUPOPT:
                        InsertMessage(pal, GROUP_BELONG_TYPE_GROUP, text);
                        break;
                case IPTUX_SEGMENTOPT:
                        InsertMessage(pal, GROUP_BELONG_TYPE_SEGMENT, text);
                        break;
                case IPTUX_REGULAROPT:
                default:
                        InsertMessage(pal, GROUP_BELONG_TYPE_REGULAR, text);
                        break;
                }
                /*/* 注册消息 */
                pthread_mutex_lock(cthrd.GetMutex());
                switch (GET_OPT(commandno)) {
                case IPTUX_BROADCASTOPT:
                        grpinf = cthrd.GetPalBroadcastItem(pal);
                        break;
                case IPTUX_GROUPOPT:
                        grpinf = cthrd.GetPalGroupItem(pal);
                        break;
                case IPTUX_SEGMENTOPT:
                        grpinf = cthrd.GetPalSegmentItem(pal);
                        break;
                case IPTUX_REGULAROPT:
                default:
                        grpinf = cthrd.GetPalRegularItem(pal);
                        break;
                }
                if (!grpinf->dialog && !cthrd.MsglineContainItem(grpinf))
                        cthrd.PushItemToMsgline(grpinf);
                pthread_mutex_unlock(cthrd.GetMutex());
        }
        g_free(text);

        /* 播放提示音 */
        if (FLAG_ISSET(progdt.sndfgs, 1))
                sndsys.Playing(progdt.msgtip);
}
示例#12
0
/**
 * 好友发送消息.
 *
 */
void UdpData::SomeoneSendmsg()
{
        GroupInfo *grpinf;
        PalInfo *pal;
        Command cmd;
        uint32_t commandno, packetno;
        char *text;
        pthread_t pid;
        DialogPeer *dlgpr;
        GtkWidget *window;

        /* 如果对方兼容iptux协议,则无须再转换编码 */
        pal = cthrd.GetPalFromList(ipv4);
        if (!pal || !FLAG_ISSET(pal->flags, 0))
                ConvertEncode(pal ? pal->encode : progdt.encode);
        /* 确保好友在线,并对编码作出适当调整 */
        pal = AssertPalOnline();
        if (strcasecmp(pal->encode, encode ? encode : "utf-8") != 0) {
                g_free(pal->encode);
                pal->encode = g_strdup(encode ? encode : "utf-8");
        }

        /* 回复好友并检查此消息是否过时 */
        commandno = iptux_get_dec_number(buf, ':', 4);
        packetno = iptux_get_dec_number(buf, ':', 1);
        if (commandno & IPMSG_SENDCHECKOPT)
                cmd.SendReply(cthrd.UdpSockQuote(), pal, packetno);
        if (packetno <= pal->packetn)
                return;
        pal->packetn = packetno;

        /* 插入消息&在消息队列中注册 */
        text = ipmsg_get_attach(buf, ':', 5);
        if (text && *text != '\0') {
                /*/* 插入消息 */
//                if ((commandno & IPMSG_BROADCASTOPT) || (commandno & IPMSG_MULTICASTOPT))
//                        InsertMessage(pal, GROUP_BELONG_TYPE_BROADCAST, text);
//                else
                        InsertMessage(pal, GROUP_BELONG_TYPE_REGULAR, text);
        }
        g_free(text);
        /*/* 注册消息 */
        pthread_mutex_lock(cthrd.GetMutex());
//        if ((commandno & IPMSG_BROADCASTOPT) || (commandno & IPMSG_MULTICASTOPT))
//                grpinf = cthrd.GetPalBroadcastItem(pal);
//        else
                grpinf = cthrd.GetPalRegularItem(pal);
        if (!grpinf->dialog && !cthrd.MsglineContainItem(grpinf))
                cthrd.PushItemToMsgline(grpinf);
        pthread_mutex_unlock(cthrd.GetMutex());

        /* 标记位处理 先处理底层数据,后面显示窗口*/
        if (commandno & IPMSG_FILEATTACHOPT) {
                if ((commandno & IPTUX_SHAREDOPT) && (commandno & IPTUX_PASSWDOPT)) {
                        pthread_create(&pid, NULL, ThreadFunc(ThreadAskSharedPasswd), pal);
                        pthread_detach(pid);
                } else
                        RecvPalFile();
        }
        window = GTK_WIDGET(grpinf->dialog);
        //这里不知道为什么运行时一直会提示window不是object
        dlgpr = (DialogPeer *)(g_object_get_data(G_OBJECT(window),"dialog"));
        if(grpinf->dialog)
            dlgpr->ShowDialogPeer(dlgpr);
        /* 是否直接弹出聊天窗口 */
        if (FLAG_ISSET(progdt.flags, 7)) {
                gdk_threads_enter();
                if (!(grpinf->dialog)) {
//                     switch (grpinf->type) {
//                     case GROUP_BELONG_TYPE_REGULAR:
                          DialogPeer::PeerDialogEntry(grpinf);
//                          break;
//                     case GROUP_BELONG_TYPE_SEGMENT:
//                     case GROUP_BELONG_TYPE_GROUP:
//                     case GROUP_BELONG_TYPE_BROADCAST:
//                          DialogGroup::GroupDialogEntry(grpinf);
//                     default:
//                          break;
//                     }
                } else {
                     gtk_window_present(GTK_WINDOW(grpinf->dialog));
                }
                gdk_threads_leave();
        }

        /* 播放提示音 */
        if (FLAG_ISSET(progdt.sndfgs, 1))
                sndsys.Playing(progdt.msgtip);
}