int MRTMeeting::Start(const char*pConnIp, unsigned short usConnPort, const char*pDispIp, unsigned short usDispPort, const char* pHttpIp, unsigned short usHttpPort) { Assert(g_inited); Assert(pConnIp != NULL && strlen(pConnIp)>0); Assert(pDispIp != NULL && strlen(pDispIp)>0); Assert(pHttpIp != NULL && strlen(pHttpIp)>0); char hh[24] = {0}; sprintf(hh, "%s:%u", pHttpIp, usHttpPort); std::string mid; GenericSessionId(mid); MRTConnManager::Instance().SetMeetingId(mid); LI("[][]MeetingId:%s\n", mid.c_str()); char addr[24] = {0}; sprintf(addr, "%s %u", pConnIp, usConnPort); MRTConnManager::Instance().GetAddrsList()->push_front(addr); if (!(MRTConnManager::Instance().ConnectConnector())) { LE("Start to ConnectConnector failed\n"); return -1; } if (!(MRTRoomManager::Instance().Init(pDispIp, usDispPort, pHttpIp, usHttpPort, hh))) { LE("Start to RoomManager Init failed\n"); return -1; } return 0; }
//* For RTConnHttp void CRTConnection::OnLogin(const char* pUserid, const char* pPass, const char* pNname) { bool ok = false; { //check & auth #if 0 std::string pass; RTHiredisRemote::Instance().CmdGet(pUserid, pass); if (pass.compare(pPass)!=0) { LE("OnLogin pass not same redis error\n"); return; } #endif m_userId = pUserid; m_token = pPass; m_nname = pNname; } //if (ok) { if (false) { std::string sid; //store userid & pass CRTConnManager::ConnectionInfo* pci = new CRTConnManager::ConnectionInfo(); if (pci) { GenericSessionId(sid); m_connectorId = CRTConnManager::Instance().ConnectorId(); pci->_connId = sid; pci->_connAddr = CRTConnManager::Instance().ConnectorIp(); pci->_connPort = CRTConnManager::Instance().ConnectorPort(); pci->_userId = pUserid; pci->_token = pPass; pci->_pConn = NULL; pci->_connType = CONNECTIONTYPE::_chttp; pci->_flag = 1; std::string uid(pUserid); CRTConnManager::Instance().AddUser(CONNECTIONTYPE::_chttp, uid, pci); } else { LE("new ConnectionInfo error!!!\n"); } } else { std::string uid(pUserid); CRTConnManager::ConnectionInfo* pci = NULL; CRTConnManager::Instance().AddUser(CONNECTIONTYPE::_chttp, uid, pci); } { // send response rapidjson::Document jsonDoc; rapidjson::StringBuffer jsonStr; rapidjson::Writer<rapidjson::StringBuffer> jsonWriter(jsonStr); jsonDoc.SetObject(); if (ok) { jsonDoc.AddMember("login", "success", jsonDoc.GetAllocator()); } else { jsonDoc.AddMember("login", "failed", jsonDoc.GetAllocator()); } jsonDoc.Accept(jsonWriter); SendResponse(HPS_OK, jsonStr.GetString()); } }
void LRTGroupSession::OnLogin(pms::EServerCmd cmd, pms::EModuleType module, const std::string& msg) { LI("%s was called\n", __FUNCTION__); pms::Login login; if (!login.ParseFromString(msg)) { LE("login.ParseFromString error\n"); } m_userid = login.usr_from(); m_token = login.usr_token(); LI("Onlogin user:%s login\n", m_userid.c_str()); std::string sid; { //store userid & pass LRTConnManager::ConnectionInfo* pci = new LRTConnManager::ConnectionInfo(); if (pci) { GenericSessionId(sid); pci->_connId = sid; pci->_userId = m_userid; pci->_token = m_token; pci->_pConn = this; pci->_connType = pms::EConnType::TTCP; pci->_flag = 1; LRTConnManager::Instance().AddUser(pms::EConnType::TTCP, m_userid, pci); //LRTConnManager::Instance().ConnectionConnNotify(m_userId, m_token); // send response std::string resp; GenericResponse(pms::EServerCmd::CLOGIN, module, 0, resp); SendResponse(0, resp.c_str()); m_login = true; return; } else { LE("new ConnectionInfo error userid:%s\n", m_userid.c_str()); std::string resp; GenericResponse(pms::EServerCmd::CLOGIN, module, 101, resp); SendResponse(0, resp.c_str()); m_login = false; return; } } }
void CRTTransferSession::OnTypeConn(TRANSFERMODULE fmodule, const std::string& str) { CONNMSG c_msg; std::string err; c_msg.GetMsg(str, err); if (err.length()>0) { LE("CRTTransferSession::OnTypeConn GetMsg err:%s\n", err.c_str()); return; } if ((c_msg._tag == CONNTAG::co_msg) && c_msg._msg.compare("hello") == 0) { // when other connect to ME: // generate TransferSessionId // send self ModuleId and TransferSessionId to other TRANSFERMSG t_msg; std::string trid; GenericSessionId(trid); m_transferSessId = trid; t_msg._action = TRANSFERACTION::req; //this is for transfer t_msg._fmodule = TRANSFERMODULE::mconnector; t_msg._type = TRANSFERTYPE::conn; t_msg._trans_seq = GenericTransSeq(); t_msg._trans_seq_ack = 0; t_msg._valid = 1; c_msg._tag = CONNTAG::co_id; c_msg._id = trid; //send self connector to other c_msg._moduleid = CRTConnManager::Instance().ConnectorId(); t_msg._content = c_msg.ToJson(); std::string s = t_msg.ToJson(); SendTransferData(s.c_str(), (int)s.length()); } else if ((c_msg._tag == CONNTAG::co_msgid) && c_msg._msgid.compare("ok") == 0) { // when other connect to ME: //get other's TransferSessionId and ModuleId if (m_transferSessId.compare(c_msg._id)==0) { CRTConnManager::ModuleInfo* pmi = new CRTConnManager::ModuleInfo(); if (pmi) { pmi->flag = 1; //store other's module type pmi->othModuleType = fmodule; pmi->othModuleId = m_transferSessId; pmi->pModule = this; //bind session and transfer id CRTConnManager::Instance().AddModuleInfo(pmi, m_transferSessId); //store which moudle connect to this connector //c_msg._moduleid: store other's module id CRTConnManager::Instance().AddTypeModuleSession(fmodule, c_msg._moduleid, m_transferSessId); LI("store the other's module fmodule:%d, id:%s, transfersessid:%s\n", (int)fmodule, c_msg._moduleid.c_str(), c_msg._id.c_str()); } else { LE("new ModuleInfo error!!!\n"); } } } else if (c_msg._tag == CONNTAG::co_keepalive) { this->RTTcp::UpdateTimer(); } else { LE("%s invalid msg tag\n", __FUNCTION__); } }