Changeset 25 in chevmsgr


Ignore:
Timestamp:
11/29/15 18:04:32 (8 years ago)
Author:
cheese
Message:

UI
친구목록 가져오기

Location:
trunk
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • trunk/msgclnt.cpp

    r24 r25  
    217217    {
    218218        LOG(e.what());
    219 
     219        error = e.stackTrace();
    220220        return false;
    221221    }
     
    236236    {
    237237        LOG(e.what());
    238 
     238        error = e.stackTrace();
    239239        return false;
    240240    }
     
    271271    {
    272272        LOG(e.what());
    273 
     273        error = e.stackTrace();
    274274        return false;
    275275    }
     
    285285    {
    286286        LOG(e.what());
    287 
     287        error = e.stackTrace();
    288288        return false;
    289289    }
     
    301301    {
    302302        LOG(e.what());
    303 
    304         return false;
    305     }
    306 }
    307 
    308 std::vector<SFriend> chev::getFriendList()
     303        error = e.stackTrace();
     304        return false;
     305    }
     306}
     307
     308bool chev::getFriendList(std::vector<SFriend> & friends)
    309309{
    310310    std::vector<SFriend> friendList;
     
    314314        secureSocket.send(request.getFriendList());
    315315
    316         friendList = messageQ.pop(ProtocolType::FRIEND_LIST).getFriendList();
    317     }
    318     catch (cf::exception & e)
    319     {
    320         LOG(e.what());
    321     }
    322 
    323     return friendList;
     316        friends = messageQ.pop(ProtocolType::FRIEND_LIST).getFriendList();
     317
     318        return messageQ.pop(ProtocolType::GET_FRIEND_LIST).get<bool>(ProtocolType::RESULT);
     319    }
     320    catch (cf::exception & e)
     321    {
     322        LOG(e.what());
     323        error = e.stackTrace();
     324        return false;
     325    }
    324326}
    325327
     
    351353    {
    352354        LOG(e.what());
    353 
     355        error = e.stackTrace();
    354356        return "";
    355357    }
     
    372374    {
    373375        LOG(e.what());
    374 
     376        error = e.stackTrace();
    375377        return false;
    376378    }
  • trunk/msgclnt.h

    r24 r25  
    7676    bool addFriend(const std::string & id);
    7777
    78     std::vector<SFriend> getFriendList();
     78    bool getFriendList(std::vector<SFriend> & friends);
    7979
    8080    std::string getSessionID(const std::vector<std::string> & idList);
  • trunk/msgsrv.cpp

    r23 r25  
    2323int cb_getFriendList(void * userArg, int argc, char ** argv, char ** colName)
    2424{
    25     std::string * friendList = (std::string *) userArg;
    26 
    27     *friendList = argv[1];
     25    std::vector<std::string> * friendList = (std::vector<std::string> *) userArg;
     26
     27    friendList->push_back(argv[1]);
    2828
    2929    return 0;
     
    195195    {
    196196        int result = 0;
    197         std::string friendList;
     197        std::vector<std::string> friendList;
    198198
    199199        try
     
    202202
    203203            this->exec(query, cb_getFriendList, &friendList);
     204
     205            return friendList;
    204206        }
    205207        catch (cf::exception & e)
    206208        {
    207209            FORWARD_EXCEPTION(e);
    208         }   
     210        }
    209211    }
    210212
     
    424426}
    425427
     428static std::vector<SFriend> getFriendList(const Protocol::Message & parser)
     429    throw (cf::exception)
     430{
     431    std::string id = parser.get<std::string>(ProtocolType::ID);
     432    std::vector<std::string> fl = dbmgr.getFriendList(id);
     433    std::vector<SFriend> fv;
     434
     435    for (size_t iter = 0; iter < fl.size(); iter++)
     436    {
     437        SFriend s;
     438        s.id = fl[iter];
     439        s.name = fl[iter]; // username?
     440        fv.push_back(s);
     441    }
     442
     443    return fv;
     444}
     445
    426446static std::string createSessionID(std::string & idList)
    427447{
     
    484504        {
    485505            result = false;
    486             parser.parse(sock.receive().toString());
     506            std::string message = sock.receive().toString();
     507            if (message[0] != '{')
     508                THROW_EXCEPTION("unknown message");
     509
     510            parser.parse(message);
     511
     512            LOG(message);
    487513
    488514            if (parser.type() == ProtocolType::SMS)
     
    535561    {
    536562        id = authenticator(*sock);
    537 
    538         Protocol::Response response;
    539         bool result = true;
    540 
    541         while (result)
    542         {
    543             std::string message = gOnlineUsers[id].receive();
     563        SecureSocket * secsock = &gOnlineUsers[id];
     564
     565        while (true)
     566        {
     567            bool result = true;
     568            Protocol::Response response;
     569            std::string message = secsock->receive();
    544570            Protocol::Message parser;
    545571            parser.parse(message);
     
    559585                result = addFriend(parser);
    560586            }
    561 
    562             gOnlineUsers[id].send(response.result(parser.type(), result));
     587            else if (parser.type() == ProtocolType::GET_FRIEND_LIST)
     588            {
     589                try
     590                {
     591                    std::vector<SFriend> fl = getFriendList(parser);
     592                    secsock->send(response.friendList(fl));
     593                } catch (cf::exception & e)
     594                {
     595                    LOG(e.stackTrace());
     596                    result = false;
     597                }
     598            }
     599
     600            secsock->send(response.result(parser.type(), result));
    563601        }
    564602    }
  • trunk/msvc14/ChevMsgrClient_MFC/ChevMsgrClient_MFC.h

    r24 r25  
    3333#include <string>
    3434
    35 static std::string wstr2str(const std::wstring & wstr)
     35static std::string cstr2str(const CString & cstr)
    3636{
    37     return std::string().assign(wstr.begin(), wstr.end());
     37    return std::string(CT2A(cstr));
    3838}
    3939
    40 static std::wstring str2wstr(const std::string & str)
     40static CString str2cstr(const std::string & str)
    4141{
    42     return std::wstring().assign(str.begin(), str.end());
     42    return CString(str.c_str());
    4343}
  • trunk/msvc14/ChevMsgrClient_MFC/ChevMsgrClient_MFC.vcxproj

    r24 r25  
    218218    <ClInclude Include="..\..\msg.hpp" />
    219219    <ClInclude Include="..\..\msgclnt.h" />
     220    <ClInclude Include="AddFriendDlg.h" />
     221    <ClInclude Include="AddGroupChat.h" />
    220222    <ClInclude Include="ChevMsgrClient_MFC.h" />
    221223    <ClInclude Include="ChevMsgrClient_MFCDlg.h" />
     
    246248    <ClCompile Include="..\..\msg.cpp" />
    247249    <ClCompile Include="..\..\msgclnt.cpp" />
     250    <ClCompile Include="AddFriendDlg.cpp" />
     251    <ClCompile Include="AddGroupChat.cpp" />
    248252    <ClCompile Include="ChevMsgrClient_MFC.cpp" />
    249253    <ClCompile Include="ChevMsgrClient_MFCDlg.cpp" />
  • trunk/msvc14/ChevMsgrClient_MFC/ChevMsgrClient_MFC.vcxproj.filters

    r24 r25  
    7979      <Filter>crypto</Filter>
    8080    </ClInclude>
     81    <ClInclude Include="AddFriendDlg.h">
     82      <Filter>헤더 파일</Filter>
     83    </ClInclude>
     84    <ClInclude Include="AddGroupChat.h">
     85      <Filter>헤더 파일</Filter>
     86    </ClInclude>
    8187  </ItemGroup>
    8288  <ItemGroup>
     
    153159      <Filter>crypto</Filter>
    154160    </ClCompile>
     161    <ClCompile Include="AddFriendDlg.cpp">
     162      <Filter>소스 파일</Filter>
     163    </ClCompile>
     164    <ClCompile Include="AddGroupChat.cpp">
     165      <Filter>소스 파일</Filter>
     166    </ClCompile>
    155167  </ItemGroup>
    156168  <ItemGroup>
  • trunk/msvc14/ChevMsgrClient_MFC/ChevMsgrClient_MFCDlg.cpp

    r24 r25  
    1212#include "RegisterDlg.h"
    1313#include "SMSDlg.h"
     14#include "AddFriendDlg.h"
     15#include "AddGroupChat.h"
    1416
    1517#ifdef _DEBUG
     
    8082    ON_WM_QUERYDRAGICON()
    8183    ON_BN_CLICKED(IDC_BTN_SEND, &CChevMsgrClient_MFCDlg::OnBnClickedBtnSend)
     84    ON_BN_CLICKED(IDC_BTN_ADD_FRIEND, &CChevMsgrClient_MFCDlg::OnBnClickedBtnAddFriend)
     85    ON_BN_CLICKED(IDC_BTN_ADD_CHAT, &CChevMsgrClient_MFCDlg::OnBnClickedBtnAddChat)
    8286END_MESSAGE_MAP()
    8387
     
    116120    // TODO: ¿©±â¿¡ Ãß°¡ ÃʱâÈ­ ÀÛ¾÷À» Ãß°¡ÇÕ´Ï´Ù.
    117121
     122    std::ifstream f("cnct2srv.ini");
     123    if (!f)
     124    {
     125        AfxMessageBox(_T("¼­¹ö Á¤º¸ ÆÄÀÏÀ» ãÀ» ¼ö ¾øÀ½"));
     126        ::SendMessage(GetSafeHwnd(), WM_QUIT, NULL, NULL);
     127    }
     128    std::string ip;
     129    std::string port;
     130
     131    std::getline(f, ip);
     132    std::getline(f, port);
     133
     134    if (!chev.connect(ip, atoi(port.c_str())))
     135    {
     136        AfxMessageBox(str2cstr(chev.getLastError()));
     137        ::SendMessage(GetSafeHwnd(), WM_QUIT, NULL, NULL);
     138    }
     139
    118140    CLoginDlg loginDlg;
    119141    loginDlg.chev = &this->chev;
    120     loginDlg.DoModal();
    121 
    122     std::ifstream f("cnct2srv.ini");
    123     std::string ip;
    124     std::string port;
    125 
    126     std::getline(f, ip);
    127     std::getline(f, port);
    128 
    129     if (!chev.connect(ip, atoi(port.c_str())))
    130     {
    131         AfxMessageBox(_T("connect error"));
    132         PostQuitMessage(1);
    133     }
     142    if (loginDlg.DoModal() != 0)
     143    {
     144        AfxMessageBox(_T("login failed"));
     145        ::SendMessage(GetSafeHwnd(), WM_QUIT, NULL, NULL);
     146    }
     147
     148    this->mId = loginDlg.mId;
    134149
    135150    SCallback cb;
     
    140155    chev.listen(cb);
    141156
    142     //this->mFriendListBox.InsertString(this->mFriendListBox.GetCount(), Ä£±¸¾ÆÀ̵𸮽ºÆ®);
     157    CString cstrId;
     158    if (!chev.getFriendList(idList))
     159    {
     160        AfxMessageBox(_T("cannot get friend list"));
     161        ::SendMessage(GetSafeHwnd(), WM_QUIT, NULL, NULL);
     162    }
     163
     164    for (size_t iter = 0; iter < idList.size(); iter++)
     165    {
     166        cstrId = str2cstr(idList[iter].id);
     167        this->mFriendListBox.InsertString(this->mFriendListBox.GetCount(), cstrId);
     168    }
    143169
    144170    return TRUE;  // Æ÷Ä¿½º¸¦ ÄÁÆ®·Ñ¿¡ ¼³Á¤ÇÏÁö ¾ÊÀ¸¸é TRUE¸¦ ¹ÝȯÇÕ´Ï´Ù.
     
    211237    // TODO: ¿©±â¿¡ ÄÁÆ®·Ñ ¾Ë¸² 󸮱â Äڵ带 Ãß°¡ÇÕ´Ï´Ù.
    212238    CString chat;
    213     CString sender;
     239    CString receiver;
    214240    SConversation conversation;
    215241
    216     mFriendListBox.GetText(mFriendListBox.GetCurSel(), sender);
    217     conversation.from = wstr2str((std::wstring)sender);
     242    mFriendListBox.GetText(mFriendListBox.GetCurSel(), receiver);
     243    conversation.from = this->mId;
    218244
    219245    GetDlgItemText(IDC_EDIT_INPUT, chat);
    220     conversation.message = wstr2str((std::wstring)chat);
     246    conversation.message = cstr2str(chat);
    221247
    222248    UpdateData(TRUE);
     
    226252    //conversation.sessid = chev.getSessionID( ´ëÈ­¹æ ÃÊ´ëÇÑ ¾ÆÀ̵𸮽ºÆ® );
    227253
    228     chev.tell(conversation);
    229 }
     254    if (chev.tell(conversation))
     255        mChatListBox.InsertString(mChatListBox.GetCount(), chat);
     256}
     257
     258void CChevMsgrClient_MFCDlg::OnBnClickedBtnAddFriend()
     259{
     260    // TODO: ¿©±â¿¡ ÄÁÆ®·Ñ ¾Ë¸² 󸮱â Äڵ带 Ãß°¡ÇÕ´Ï´Ù.
     261    //chev.addFriend();
     262    CAddFriendDlg AFDlg;
     263
     264    AFDlg.chev = &this->chev;
     265
     266    AFDlg.DoModal();
     267}
     268
     269
     270void CChevMsgrClient_MFCDlg::OnBnClickedBtnAddChat()
     271{
     272    // TODO: ¿©±â¿¡ ÄÁÆ®·Ñ ¾Ë¸² 󸮱â Äڵ带 Ãß°¡ÇÕ´Ï´Ù.
     273    CAddGroupChatDlg AGCDlg;
     274
     275    AGCDlg.chev = &this->chev;
     276
     277    AGCDlg.DoModal();
     278}
  • trunk/msvc14/ChevMsgrClient_MFC/ChevMsgrClient_MFCDlg.h

    r24 r25  
    3838    CListBox mFriendListBox;
    3939    BOOL mCheckedSensitive;
     40    std::vector<SFriend> idList;
     41    std::string mId;
    4042    afx_msg void OnBnClickedBtnSend();
     43    afx_msg void OnBnClickedBtnAddFriend();
     44    afx_msg void OnBnClickedBtnAddChat();
    4145};
  • trunk/msvc14/ChevMsgrClient_MFC/LoginDlg.cpp

    r24 r25  
    77#include "afxdialogex.h"
    88#include "RegisterDlg.h"
     9#include "fstream"
     10#include "cf/codec.h"
     11#include "crypto.h"
    912
    1013
     
    3134BEGIN_MESSAGE_MAP(CLoginDlg, CDialogEx)
    3235    ON_BN_CLICKED(IDC_BTN_LOGIN_REGISTER, &CLoginDlg::OnBnClickedBtnLoginRegister)
     36    ON_BN_CLICKED(IDC_BTN_LOGIN_LOGIN, &CLoginDlg::OnBnClickedBtnLoginLogin)
    3337END_MESSAGE_MAP()
    3438
     
    4145    // TODO: ¿©±â¿¡ ÄÁÆ®·Ñ ¾Ë¸² 󸮱â Äڵ带 Ãß°¡ÇÕ´Ï´Ù.
    4246    CRegisterDlg regiDlg;
    43 
     47    regiDlg.chev = this->chev;
    4448    regiDlg.DoModal();
    4549}
     50
     51
     52void CLoginDlg::OnBnClickedBtnLoginLogin()
     53{
     54    // TODO: ¿©±â¿¡ ÄÁÆ®·Ñ ¾Ë¸² 󸮱â Äڵ带 Ãß°¡ÇÕ´Ï´Ù.
     55    CString id, pw;
     56    cf::bin decoded;
     57    crypto c;
     58    std::string str;
     59
     60    GetDlgItemText(IDC_EDIT_LOGIN_ID, id);
     61    std::string name = cf::codec::hex::getInstance()->encode(c.sha256(cf::bin(cstr2str(id))));
     62    std::ifstream f(name);
     63    if(!f)
     64    {
     65        AfxMessageBox(_T("FILE OPEN FAILED ( LOGIN )"));
     66        EndDialog(1);
     67    }
     68
     69    this->mId = cstr2str(id);
     70
     71    GetDlgItemText(IDC_EDIT_LOGIN_PW, pw);
     72    f >> str;
     73    decoded = cf::codec::hex::getInstance()->decode(str);
     74
     75    c.setKey(cf::bin(cstr2str(pw)));
     76    str = c.decrypt(decoded).toString();
     77
     78    if (str.size() == 6)
     79    {
     80        for (size_t iter = 0; iter < str.size(); iter++)
     81        {
     82            if (!(str[iter] >= '0' && str[iter] <= '9'))
     83            {
     84                AfxMessageBox(_T("Decrypt Error"));
     85                EndDialog(2);
     86            }
     87        }
     88    }
     89    else
     90    {
     91        AfxMessageBox(_T("Decrypt Error"));
     92        EndDialog(3);
     93    }
     94
     95    if (!chev->login(cstr2str(id), cstr2str(pw), str))
     96        AfxMessageBox(_T("Login Failed"));
     97    else
     98        EndDialog(0);
     99}
  • trunk/msvc14/ChevMsgrClient_MFC/LoginDlg.h

    r24 r25  
    1212    virtual ~CLoginDlg();
    1313    chev *chev;
     14    std::string mId;
    1415
    1516// ´ëÈ­ »óÀÚ µ¥ÀÌÅÍÀÔ´Ï´Ù.
     
    2425public:
    2526    afx_msg void OnBnClickedBtnLoginRegister();
     27    afx_msg void OnBnClickedBtnLoginLogin();
    2628};
  • trunk/msvc14/ChevMsgrClient_MFC/RegisterDlg.cpp

    r24 r25  
    77#include "afxdialogex.h"
    88#include "SMSDlg.h"
    9 
     9#include "crypto.h"
     10#include "fstream"
     11#include "cf/codec.h"
    1012
    1113// CRegisterDlg ´ëÈ­ »óÀÚÀÔ´Ï´Ù.
     
    3941{
    4042    // TODO: ¿©±â¿¡ ÄÁÆ®·Ñ ¾Ë¸² 󸮱â Äڵ带 Ãß°¡ÇÕ´Ï´Ù.
     43    CString id, pw, pw2;
    4144    CSMSDlg smsDlg;
     45    crypto c;
     46    cf::bin key;
     47   
     48    smsDlg.chev = this->chev;
     49    if (smsDlg.DoModal() != 0)
     50    {
     51        AfxMessageBox(_T("no sms"));
     52        return;
     53    }
     54    this->authsms = cstr2str(smsDlg.sms);
     55    GetDlgItemText(IDC_EDIT_REG_ID, id);
     56    GetDlgItemText(IDC_EDIT_REG_PW, pw);
     57    GetDlgItemText(IDC_EDIT_REG_PW2, pw2);
    4258
    43     smsDlg.DoModal();
     59    std::ofstream f(cf::codec::hex::getInstance()->encode(c.sha256(cf::bin(cstr2str(id)))));
     60
     61    if (pw != pw2)
     62    {
     63        AfxMessageBox(_T("Æнº¿öµå¸¦ È®ÀÎÇØÁÖ¼¼¿ä."));
     64    }
     65    else
     66    {
     67        if (chev->join(cstr2str(id), cstr2str(pw), this->authsms))
     68        {
     69            AfxMessageBox(_T("ȸ¿ø°¡ÀÔ ¼º°ø"));
     70            c.setKey(cf::bin(cstr2str(pw)));
     71            f << cf::codec::hex::getInstance()->encode(c.encrypt(cf::bin(authsms)));
     72            f.close();
     73            EndDialog(0);
     74        }
     75        else
     76            AfxMessageBox(_T("ȸ¿ø°¡ÀÔ ½ÇÆÐ"));
     77    }
    4478}
  • trunk/msvc14/ChevMsgrClient_MFC/RegisterDlg.h

    r24 r25  
    11#pragma once
    2 
     2#include "msgclnt.h"
    33
    44// CRegisterDlg ´ëÈ­ »óÀÚÀÔ´Ï´Ù.
     
    1111    CRegisterDlg(CWnd* pParent = NULL);   // Ç¥ÁØ »ý¼ºÀÚÀÔ´Ï´Ù.
    1212    virtual ~CRegisterDlg();
     13    chev *chev;
     14    std::string authsms;
    1315
    1416// ´ëÈ­ »óÀÚ µ¥ÀÌÅÍÀÔ´Ï´Ù.
  • trunk/msvc14/ChevMsgrClient_MFC/SMSDlg.cpp

    r24 r25  
    1717    , sms(_T(""))
    1818{
    19 
    2019}
    2120
     
    4544    // TODO: ¿©±â¿¡ ÄÁÆ®·Ñ ¾Ë¸² 󸮱â Äڵ带 Ãß°¡ÇÕ´Ï´Ù.
    4645    GetDlgItemText(IDC_EDIT_SMS_PHONE, phone);
    47 
    48 
     46    if (!chev->sms(cstr2str(phone)))
     47        AfxMessageBox(_T("cannot request sms"));
    4948}
    5049
     
    5453    // TODO: ¿©±â¿¡ ÄÁÆ®·Ñ ¾Ë¸² 󸮱â Äڵ带 Ãß°¡ÇÕ´Ï´Ù.
    5554    GetDlgItemText(IDC_EDIT_SMS_SMS, sms);
     55    EndDialog(0);
    5656}
  • trunk/msvc14/ChevMsgrClient_MFC/SMSDlg.h

    r24 r25  
    11#pragma once
    2 
     2#include "msgclnt.h"
    33
    44// CSMSDlg ´ëÈ­ »óÀÚÀÔ´Ï´Ù.
     
    1111    CSMSDlg(CWnd* pParent = NULL);   // Ç¥ÁØ »ý¼ºÀÚÀÔ´Ï´Ù.
    1212    virtual ~CSMSDlg();
     13    chev *chev;
    1314
    1415// ´ëÈ­ »óÀÚ µ¥ÀÌÅÍÀÔ´Ï´Ù.
Note: See TracChangeset for help on using the changeset viewer.