Changeset 13 in chevmsgr for trunk/msgsrv.cpp
- Timestamp:
- 08/30/15 16:54:31 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/msgsrv.cpp
r7 r13 4 4 #include "cf/codec.h" 5 5 #include "cf/file.h" 6 #include "crypto.h" 6 7 7 8 #include "msg.hpp" … … 283 284 } 284 285 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 299 286 static std::string getRandomCode() 300 287 { … … 333 320 throw (cf::exception) 334 321 { 335 if (sms != parser.get<std::string>( "sms"))322 if (sms != parser.get<std::string>(ProtocolType::SMS)) 336 323 THROW_EXCEPTION("SMS is not same"); 337 324 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); 340 327 341 328 return dbmgr.join(id, pw, sms, address); … … 345 332 throw (cf::exception) 346 333 { 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); 349 336 350 337 return dbmgr.login(id, pw); … … 355 342 { 356 343 bool result = false; 357 std::string to = parser.get<std::string>( "to");344 std::string to = parser.get<std::string>(ProtocolType::TO); 358 345 359 346 if (isOnline(to)) … … 366 353 } 367 354 355 static 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 364 static 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 368 387 static std::string keyExchange(const std::string sms, const std::string address) 369 388 { 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); 373 394 } 374 395 … … 391 412 { 392 413 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"); 394 415 } 395 416 else if (parser.type() == "login") 396 417 { 397 418 if (login(parser)) 398 return parser.get<std::string>("id");399 } 419 parser.get<std::string>(ProtocolType::ID); 420 } 400 421 } 401 422 } … … 428 449 LOG(message); 429 450 430 if (parser.type() == "command") 431 result = command(parser); 432 else if (parser.type() == "chat") 451 if (parser.type() == "chat") 433 452 result = chat(parser, message); 453 else if (parser.type() == "opensession") 454 result = opensession(parser); 455 // else if (parser.type() == "getFriendList") 456 // result = 434 457 435 458 sock->send(response.result(parser.type(), result)); … … 481 504 } 482 505 483 int createSessionID(std::string & idList)484 {485 return 0;486 }487 488 506 int main(int argc, char ** argv) 489 507 {
Note:
See TracChangeset
for help on using the changeset viewer.