Exemple #1
0
void SMOnlineRoom::CreateRoom(PacketFunctions& Packet) {
    bool origional_name = true;
    SMOnlineRoom* tmp = NULL;
    int type = Packet.Read1();
    MString title = Packet.ReadNT();
    MString sub = Packet.ReadNT();
    MString passwd = Packet.ReadNT();

    if (!title.empty())
    {
        if (title.size() > m_roomNameLength)
            title = title.substr(0, m_roomNameLength);

        for (unsigned int x = 0; (x < m_joinrooms.size()) && origional_name; ++x)
            if (title == m_joinrooms[x]->m_title)
                origional_name = false;

        if (origional_name) {
            if (type) {
                tmp = new SMOnlineGameRoom(title, sub);
            } else {
                tmp = new SMOnlineRoom(title, sub);
            }

            if (tmp) {
                LOG->Write("Created room");
                if (!passwd.empty())
                    tmp->m_passwd = passwd;
                SERVER->GetRooms().push_back(tmp);
                JoinToRoom(tmp);
                SendRoomList();
            }
        }
    }
}
int BlsHttpClient::run()
{
    int ret = E_SUCCESS;
    MString body;

    if ((ret = readHttpHeader(*m_parser, body, *m_socket)) != E_SUCCESS) {
        log_error("BlsHttpClient read Http Header failed, ret=%d", ret);
        return ret;
    }

    // get http host
    MString host = m_parser->host();
    if (host.empty()) {
        log_error("BlsHttpClient Http Header error");\
        return -1;
    }

    MString vhost;
    MString tempStr = "HTTP://" + host + "" + m_parser->url();
    MUrl tempUrl(tempStr);

    if (MUrl::stringIsIp(host)) {
        vhost = tempUrl.queryByKey("vhost");
    }

    if (vhost.empty()) {
        vhost = tempUrl.host();
    }

    if (tempUrl.path().endWith(HTTP_LIVE_FLV_SUFFIX)) {
        MString rtmpStr = "rtmp://" + vhost + ":1935" + tempUrl.path();
        int suffixLen = sizeof(HTTP_LIVE_FLV_SUFFIX);
        rtmpStr = rtmpStr.substr(0, rtmpStr.size() - suffixLen + 1);

        int ret = sendHttpLiveFlv(rtmpStr);
        if (ret != E_SUCCESS) {
            log_trace("Http Live Flv finished.");
        }
    }

    else {

    }

end:
    clean();

    return ret;
}
int BlsChild::processCommand(MString &line)
{
    if (line.empty()) return E_SUCCESS;

    if (line.endWith("\n")) {
        line.erase(line.size()-1, 1);
    }
    log_trace("BlsMasterChannel get line %s", line.c_str());

    MStringList temp = line.split(Internal_CMD_Delimer);
    MString key = temp.at(0);
    MString value = temp.at(1);

    if (key == Internal_CMD_PID) {
        m_pid = value.toInt();
        gs_childs[m_pid] = this;
    } else if (key == Internal_CMD_InternalPort) {
        m_internalPort = value.toInt();
    } else if (key == Internal_CMD_WhoHasBackSource) {
        MRtmpUrl rtmpUrl(value);
        MString url = rtmpUrl.url();

        int port = 0;
        if (gs_sources.contains(url)) {
            port = gs_sources[url]->internalPort();
        }

        if (sendLine(Internal_CMD_WhoHasBackSourceRes, MString::number(port)) != E_SUCCESS) {
            return -1;
        }

        log_trace("--%s:%d", url.c_str(), port);

        if (port == 0) {
            gs_sources[url] = this;
        }
    } else if (key == Internal_CMD_IHasBackSourced) {
        log_warn("%s insert into backsource queue", value.c_str());
        gs_sources[value] = this;
    } else if (key == Internal_CMD_RemoveHasBackSourceRes) {
        log_warn("%s removed from backsource queue", value.c_str());
        gs_sources.erase(value);
    }

    return E_SUCCESS;
}