当前位置: 首页>>代码示例>>C++>>正文


C++ PacketFunctions::ClearPacket方法代码示例

本文整理汇总了C++中PacketFunctions::ClearPacket方法的典型用法代码示例。如果您正苦于以下问题:C++ PacketFunctions::ClearPacket方法的具体用法?C++ PacketFunctions::ClearPacket怎么用?C++ PacketFunctions::ClearPacket使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PacketFunctions的用法示例。


在下文中一共展示了PacketFunctions::ClearPacket方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: GetData

int GameClient::GetData(PacketFunctions& Packet)
{
	int length = -1;
	Packet.ClearPacket();
	length = clientSocket.ReadPack((char*)Packet.Data, NETMAXBUFFERSIZE);
	return length;
}
开发者ID:augustg,项目名称:stepmania-3.9,代码行数:7,代码来源:NetworkSyncServer.cpp

示例2: WriteRoomListPacket

void SMOnlineRoom::WriteRoomListPacket(PacketFunctions &Packet) {
    unsigned int numRooms = m_joinrooms.size();
    Packet.ClearPacket();
    Packet.Write1(NSSMONL + NSServerOffset);
    Packet.Write1(1);  //Room command
    Packet.Write1(1); //Type (List Rooms)
    Packet.Write1(numRooms);
    for (unsigned int x = 0; x < numRooms; ++x) {
        if (m_joinrooms[x] != NULL) {
            Packet.WriteNT(m_joinrooms[x]->GetTitle());
            Packet.WriteNT(m_joinrooms[x]->GetDescription());
        }
    }
    //state
    for (unsigned int x = 0; x < numRooms; ++x) {
        if (m_joinrooms[x] != NULL)
        {
            //TO MAKE CHARLES HAPPY IF PASSWORDED USE 1 (UNSUSED)
            if (!m_joinrooms[x]->m_passwd.empty() && (m_joinrooms[x]->m_state == RS_OPEN))
                Packet.Write1(RS_UNUSED);
            else
                Packet.Write1(m_joinrooms[x]->m_state);
        }
    }
    //Flags
    char flags;
    for (unsigned int x = 0; x < numRooms; ++x) {
        if (m_joinrooms[x] != NULL)
        {
            flags = 0;
            //bit 1 passworded
            if (!m_joinrooms[x]->m_passwd.empty())
                flags += 1;

            Packet.Write1(flags);
        }
    }
}
开发者ID:freem,项目名称:SMOnline-v1,代码行数:38,代码来源:SMOnlineRoom.cpp

示例3: WriteChatPacket

void SMOnlineRoom::WriteChatPacket(PacketFunctions& packet, const MString& message) {
    packet.ClearPacket();
    packet.Write1(NSCCM + NSServerOffset);
    packet.WriteNT(message);
}
开发者ID:freem,项目名称:SMOnline-v1,代码行数:5,代码来源:SMOnlineRoom.cpp

示例4: AnalizeChat

void SMOnlineRoom::AnalizeChat(unsigned int clientNum, PacketFunctions& Packet)
{
    MString message = Packet.ReadNT();
    ChatCommandPack ccp = ParseCommands(message, clientNum);

    switch(ccp.cmd)
    {
    case NONE:
        RelayChat(clientNum, message);
        return;
    case ANNOUNCE:
    {
        PacketFunctions reply;
        reply.ClearPacket();
        reply.Write1(NSCSU+NSServerOffset);
        reply.WriteNT(ccp.data.front());
        SERVER->SendToAll(reply);
    }
    return;
    case KICK:
    {
        const MString& name = ccp.data.front();
        for (unsigned int x = 0; x < m_clients.size(); ++x)
            for (unsigned int y = 0; y < m_clients[x]->GetNumPlayers(); ++y)
                if (m_clients[x]->GetPlayer(y)->GetName() == name)
                {
                    LOG->Write("Kicking " + name);
                    m_kicked[ccp.data.front()] = KickClient(name);
                    ChangeRoom(1, m_joinrooms[0]->GetTitle(), x, "", true);
                    return;
                }
    }
    break;
    case BAN:
    {
        const MString& name = ccp.data.front();
        for (unsigned int x = 0; x < m_clients.size(); ++x)
            for (unsigned int y = 0; y < m_clients[x]->GetNumPlayers(); ++y)
                if (m_clients[x]->GetPlayer(y)->GetName() == name)
                {
                    LOG->Write("Banning " + name);
                    m_banned[name] = name;
                    ChangeRoom(1, m_joinrooms[0]->GetTitle(), x, "", true);
                    return;
                }
    }
    break;
    case PM:
    {
        MString user = ccp.data.front();
        ccp.data.pop();
        MString message = ccp.data.front();
        MString tmp;
        MString success = "PM Failed!";

        if ((user.length() > 0) && (message.length() > 0))
        {
            tmp = "PM from ";
            unsigned int numPlayers = m_clients[m_cNum]->GetNumPlayers();
            for (unsigned int x = 0; x < numPlayers; ++x)
            {
                tmp += m_clients[m_cNum]->GetPlayerName(x);
                if ((numPlayers > 1) && (x < (numPlayers - 1)))
                    tmp += "&";
            }
            tmp += ": " + message;
            if (SERVER->MsgPlayer(user, tmp))
                success = "PM Success!";
        }
        PacketFunctions result;
        result.ClearPacket();
        result.Write1(NSCCM + NSServerOffset);
        result.WriteNT(success);
        m_clients[m_cNum]->SendData(result);
    }
    break;
    case DROP:
    {
        SMOnlineClient* tmp = SERVER->GetPlayerClient(ccp.data.front());
        if (tmp != NULL)
            tmp->connection.close();
    }
    break;
//	case FORCESTART:
//		break;
    default:
        break;
    };
}
开发者ID:freem,项目名称:SMOnline-v1,代码行数:89,代码来源:SMOnlineRoom.cpp


注:本文中的PacketFunctions::ClearPacket方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。