Changeset 13 in chevmsgr for trunk/msgsrv.cpp


Ignore:
Timestamp:
08/30/15 16:54:31 (9 years ago)
Author:
cheese
Message:

서버 쪼끔 수정

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/msgsrv.cpp

    r7 r13  
    44#include "cf/codec.h"
    55#include "cf/file.h"
     6#include "crypto.h"
    67
    78#include "msg.hpp"
     
    283284}
    284285
    285 static bool command(const Protocol::Message & parser)
    286 {
    287     bool isContinued = true;
    288     std::string command = parser.get<std::string>("command");
    289 
    290     if (command == "logout")
    291         isContinued = false;
    292     /*
    293     else if (...)
    294     */
    295 
    296     return isContinued;
    297 }
    298 
    299286static std::string getRandomCode()
    300287{
     
    333320    throw (cf::exception)
    334321{
    335     if (sms != parser.get<std::string>("sms"))
     322    if (sms != parser.get<std::string>(ProtocolType::SMS))
    336323        THROW_EXCEPTION("SMS is not same");
    337324
    338     std::string id = parser.get<std::string>("id");
    339     std::string pw = parser.get<std::string>("pw");
     325    std::string id = parser.get<std::string>(ProtocolType::ID);
     326    std::string pw = parser.get<std::string>(ProtocolType::PW);
    340327       
    341328    return dbmgr.join(id, pw, sms, address);
     
    345332    throw (cf::exception)
    346333{
    347     std::string id = parser.get<std::string>("id");
    348     std::string pw = parser.get<std::string>("pw");
     334    std::string id = parser.get<std::string>(ProtocolType::ID);
     335    std::string pw = parser.get<std::string>(ProtocolType::PW);
    349336
    350337    return dbmgr.login(id, pw);
     
    355342{
    356343    bool result = false;
    357     std::string to = parser.get<std::string>("to");
     344    std::string to = parser.get<std::string>(ProtocolType::TO);
    358345
    359346    if (isOnline(to))
     
    366353}
    367354
     355static std::string createSessionID(std::string & idList)
     356{
     357    cf::bin sessid;
     358
     359    sessid = crypto().sha256(cf::bin(idList));
     360
     361    return cf::codec::hex::getInstance()->encode(sessid);
     362}
     363
     364static bool opensession(const Protocol::Message & parser)
     365{
     366    bool result = false;
     367    std::string sessid;
     368    std::vector<std::string> idList = parser.getList<std::string>(ProtocolType::ID_LIST);
     369    std::string concat = idList[0];
     370
     371    for (size_t iter = 1; iter < concat.size(); iter++)
     372        concat += idList[iter];
     373
     374    sessid = createSessionID(concat);
     375
     376    for (size_t iter = 0; iter < idList.size(); iter++)
     377    {
     378        if (isOnline(idList[iter]))
     379            gOnlineUsers[idList[iter]].sock->send(sessid);
     380
     381        result = true;
     382    }
     383
     384    return result;
     385}
     386
    368387static std::string keyExchange(const std::string sms, const std::string address)
    369388{
    370     std::string sessionKey;
    371 
    372 
     389    cf::bin sessKey;
     390
     391    sessKey = crypto().sha256(cf::bin(sms + address));
     392
     393    return cf::codec::hex::getInstance()->encode(sessKey);
    373394}
    374395
     
    391412            {
    392413                if (join(parser, sms, sock.peer().address()))
    393                     THROW_EXCEPTION("user(" << parser.get<std::string>("id") << ") cannot join");
     414                    THROW_EXCEPTION("user(" << parser.get<std::string>(ProtocolType::ID) << ") cannot join");
    394415            }
    395416            else if (parser.type() == "login")
    396417            {
    397418                if (login(parser))
    398                     return parser.get<std::string>("id");
    399             }
     419                    parser.get<std::string>(ProtocolType::ID);
     420            }           
    400421        }
    401422    }
     
    428449            LOG(message);
    429450
    430             if (parser.type() == "command")
    431                 result = command(parser);
    432             else if (parser.type() == "chat")
     451            if (parser.type() == "chat")
    433452                result = chat(parser, message);
     453            else if (parser.type() == "opensession")
     454                result = opensession(parser);
     455//          else if (parser.type() == "getFriendList")
     456//              result =
    434457
    435458            sock->send(response.result(parser.type(), result));
     
    481504}
    482505
    483 int createSessionID(std::string & idList)
    484 {
    485     return 0;
    486 }
    487 
    488506int main(int argc, char ** argv)
    489507{
Note: See TracChangeset for help on using the changeset viewer.