Changeset 5 in chevmsgr


Ignore:
Timestamp:
08/27/15 00:29:54 (9 years ago)
Author:
cheese
Message:

클라이언트 메시지 추가 및 안정화

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/msg.cpp

    r4 r5  
    4040
    4141        obj["command"] = cmd;
     42
     43        return json::Serialize(obj);
     44    }
     45
     46    std::string Request::sms(const std::string & phone) const
     47    {
     48        DECLARE_TEMPLATE_OBJECT(obj, "sms");
     49
     50        obj["phone"] = phone;
     51
     52        return json::Serialize(obj);
     53    }
     54
     55    std::string Request::join(const std::string & id, const std::string & pw, const std::string & sms)
     56    {
     57        DECLARE_TEMPLATE_OBJECT(obj, "join");
     58
     59        obj["id" ] = id;
     60        obj["pw" ] = pw;
     61        obj["sms"] = sms;
    4262
    4363        return json::Serialize(obj);
  • trunk/msg.hpp

    r4 r5  
    7171        std::string command(const std::string & cmd) const;
    7272
     73        std::string sms(const std::string & phone) const;
     74
     75        std::string Request::join(const std::string & id, const std::string & pw, const std::string & sms);
     76
    7377        std::string login(const std::string & pw) const;
    7478
  • trunk/msgclnt.cpp

    r4 r5  
    1919    bool isError = false;
    2020    Message::Parser parser;
     21    cf::bin raw;
    2122
    2223    while (true)
     
    2425        try
    2526        {
    26             std::string message = inst->socket->receive().toString();
    27             parser.parse(message);
     27            raw = inst->socket->receive();
     28            parser.parse(raw.toString());
    2829
    2930            isError = false;
     
    3233        {
    3334            LOG(e.stackTrace());
     35
     36            // closed
     37            if (raw.size() == 0)
     38                break;
    3439
    3540            isError = true;
     
    8691}
    8792
     93bool chev::join(const std::string & id, const std::string & pw, const std::string & sms)
     94{
     95    try
     96    {
     97        socket.send(request.join(id, pw, sms));
     98
     99        std::string response = socket.receive().toString();
     100        Message::Parser parser;
     101        parser.parse(response);
     102
     103        return parser.get<bool>("result");
     104    }
     105    catch (cf::exception & e)
     106    {
     107        LOG(e.what());
     108
     109        return false;
     110    }
     111}
     112
    88113bool chev::login(const std::string & id, const std::string & pw)
    89114{
     
    108133}
    109134
     135bool chev::sms(const std::string & phone)
     136{
     137    try
     138    {
     139        socket.send(request.sms(phone));
     140
     141        std::string response = socket.receive().toString();
     142        Message::Parser parser;
     143        parser.parse(response);
     144
     145        return parser.get<bool>("result");
     146    }
     147    catch (cf::exception & e)
     148    {
     149        LOG(e.what());
     150
     151        return false;
     152    }
     153}
     154
    110155bool chev::runReceiver(const SCallback & cb)
    111156{
     157    if (listener.isRunning())
     158        return true;
     159
    112160    callback = cb;
    113161
  • trunk/msgclnt.h

    r4 r5  
    5454    bool connect(const std::string & host, unsigned short port);
    5555
    56     bool sms();
     56    bool sms(const std::string & phone);
    5757
    5858    bool join(const std::string & id, const std::string & pw, const std::string & sms);
Note: See TracChangeset for help on using the changeset viewer.