Пример #1
0
void SMOnlineRoom::GenAdditionalInfo(const MString& roomname, const int clientnum)
{
    for (unsigned int x = 0; x < m_joinrooms.size(); x++) {
        if (m_joinrooms[x]->GetTitle() == roomname) {
            MString title, subtitle, artist;
            m_reply.ClearPacket();
            m_reply.Write1(NSSMONL + NSServerOffset);
            m_reply.Write1(3);

            if (m_joinrooms[x]->m_roomType == ROOMGame)
            {
                RoundInfo last = ((SMOnlineGameRoom*)m_joinrooms[x])->LastRound();
                title = last.GetTitle();
                subtitle = last.GetSubtitle();
                artist = last.GetArtist();
            }

            m_reply.WriteNT(title); //Title
            m_reply.WriteNT(subtitle); //Subtitle
            m_reply.WriteNT(artist); //Artist

            m_reply.Write1((unsigned char)(m_joinrooms[x]->GetTotalPlayers()));
            m_reply.Write1((unsigned char)m_maxPlayers);

            //Player names
            for (unsigned int i = 0; i < m_joinrooms[x]->m_clients.size(); i++)
                for (unsigned int j = 0; j < m_joinrooms[x]->m_clients[i]->GetNumPlayers(); j++)
                    m_reply.WriteNT(m_joinrooms[x]->m_clients[i]->GetPlayer(j)->GetName());

            SendDataToClient(clientnum, m_reply);
            return;
        }
    }
}
Пример #2
0
void SMOnlineRoom::SendRoomTitle(int clientnum) {
    m_reply.ClearPacket();
    m_reply.Write1(NSSMONL + NSServerOffset);
    m_reply.Write1(1); //Room Update command
    m_reply.Write1(0); //Title Update
    m_reply.WriteNT(m_title);
    m_reply.WriteNT(m_description);
    m_reply.Write1(m_roomType);
    SendDataToClient(clientnum, m_reply);
}
Пример #3
0
//Note: VersionRestriction = -1 means send to all clients, regardless.
//		Otherwise, it indicates which version to send it to.
//		VersionDirection of 0 indicates the version must match up perfectly
//		1: Must be less than or eqal to prescribed version
//		2: Must be greater than or equal to prescribed version
void SMOnlineRoom::SendToAllClients(const PacketFunctions& Packet, int VersionRestriction, int VersionDirection )
{
    unsigned int size = m_clients.size();
    for (unsigned int x = 0; x < size; ++x)
    {
        if	( ( VersionRestriction == -1 ) ||
                ( ( VersionDirection == 0 ) && ( VersionRestriction == m_clients[x]->GetVersion() ) ) ||
                ( ( VersionDirection == 1 ) && ( VersionRestriction >= m_clients[x]->GetVersion() ) ) ||
                ( ( VersionDirection == 2 ) && ( VersionRestriction <= m_clients[x]->GetVersion() ) ) )
            SendDataToClient(x, Packet);
    }
}
Пример #4
0
void WorkerThread::HandleConn(evutil_socket_t fd, short what, void* arg)
{
    WorkerThread* pwt=static_cast<WorkerThread *>(arg);
    char  buf[1];
    if(read(fd, buf, 1)!=1)//从sockpair的另一端读数据
        LOG(ERROR)<<"workerthread accept connection failed\n";
    if(buf[0]=='t')
        HandleTcpConn(pwt);
    else if(buf[0]=='u')
        HandleUdpConn(pwt);
    else if(buf[0]=='r')
    {
        SendDataToClient(pwt);
    }
    else if(buf[0]=='k'){
            KillTcpConnection(pwt);
    }
    else{
        LOG(ERROR)<<"unkonwn protocol type";
    }
}
Пример #5
0
DWORD CDBPSWorkerThread::StartWorkerThread(char *pReceiveBuf, DWORD dwByteTransferred)
{
    DWORD dwRet;
    try
    {
        ST_RECV_DATA stRecvData;
        ReceiveDataFromClient(stRecvData, pReceiveBuf);

        ST_DB_RESULT stDBResult;
        RequestDataBase(stRecvData, stDBResult);

        std::string strSendData;
        MakeSTRResData(stDBResult, strSendData);
        dwRet = SendDataToClient(strSendData);
    }
    catch (std::exception &e)
    {
        ErrorLog(e.what());
        return E_RET_FAIL;
    }
    DebugLog("Success to communicate with client");
    return E_RET_SUCCESS;
}
Пример #6
0
void SMOnlineRoom::ChatToClient(const MString& message, unsigned int clientnum) {
    m_reply.ClearPacket();
    m_reply.Write1(NSCCM + NSServerOffset);
    m_reply.WriteNT(Detranslit(message));
    SendDataToClient(clientnum, m_reply);
}
Пример #7
0
void SMOnlineRoom::SendRoomList(int clientnum) {
    WriteRoomListPacket(m_reply);
    SendDataToClient(clientnum, m_reply);
}