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


C++ CCharacter::LoadFromStream方法代码示例

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


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

示例1: SV_ReturnCharacter

bool SV_ReturnCharacter(ServerConnection* conn, Packet& pack)
{
    uint8_t packet_id;
    pack >> packet_id;

    if(packet_id != 0xCF) return false;

    uint32_t p_size;
    uint32_t p_id1, p_id2, p_loglen, p_chrlen;
    pack >> p_size >> p_id1 >> p_id2 >> p_loglen >> p_chrlen;
    if(!p_chrlen)
    {
        Printf(LOG_Error, "[SV] Received NULL character from server ID %u!\n", conn->ID);
        return true;
    }

    char* p_logname_c = new char[p_loglen + 1];
    p_logname_c[p_loglen] = 0;
    char* p_chrdata = new char[p_chrlen];
    pack.GetData((uint8_t*)p_chrdata, p_chrlen);
    pack.GetData((uint8_t*)p_logname_c, p_loglen);
    std::string p_logname(p_logname_c);
    delete[] p_logname_c;

    CCharacter chr;
    BinaryStream bs;
    std::vector<uint8_t>& bsb = bs.GetBuffer();
    for(uint32_t i = 0; i < p_chrlen; i++)
        bsb.push_back(p_chrdata[i]);

    delete[] p_chrdata;

    if(!chr.LoadFromStream(bs))
    {
        Printf(LOG_Error, "[SV] Received bad character from server ID %u!\n", conn->ID);
        return true;
    }

    if(!Login_Exists(p_logname))
    {
        Printf(LOG_Error, "[SV] Received character \"%s\" for non-existent login \"%s\" from server ID %u!\n", chr.Nick.c_str(), p_logname.c_str(), conn->ID);
        delete[] p_chrdata;
        return true;
    }

    bool sent_s = true;

    if(!Login_CharExists(p_logname, chr.Id1, chr.Id2, true))
    {
        if (conn->Parent->Info.GameMode == GAMEMODE_Softcore)
            chr.HatId = Config::HatIDSoftcore;
        else if (conn->Parent->Info.GameMode == GAMEMODE_Sandbox)
            chr.HatId = Config::HatIDSandbox;
        else chr.HatId = Config::HatID;
    }

    bool should_unlock = true;
    bool should_save = true;
    if(should_save && ((chr.Id2 & 0x3F000000) != 0x3F000000))
    {
        int srvHatId;
        if (conn->Parent->Info.GameMode == GAMEMODE_Softcore)
            srvHatId = Config::HatIDSoftcore;
        else if (conn->Parent->Info.GameMode == GAMEMODE_Sandbox)
            srvHatId = Config::HatIDSandbox;
        else srvHatId = Config::HatID;

        bool server_nosaving = ((conn->Parent->Info.ServerMode & SVF_NOSAVING) == SVF_NOSAVING);

        if(server_nosaving)
        {
            should_save = false;
            Printf(LOG_Trivial, "[SV] Not saving login \"%s\" (SVG_NOSAVING is set, flags %08X).\n", p_logname.c_str(), conn->Parent->Info.ServerMode);
        }
        else if(conn->Parent->Info.GameMode == GAMEMODE_Arena)
        {
            should_save = false;
            Printf(LOG_Trivial, "[SV] Not saving login \"%s\" (Arena).\n", p_logname.c_str());
        }
        else if(chr.HatId != srvHatId)
        {
            //should_save = false;
            //Printf(LOG_Trivial, "[SV] Not saving login \"%s\" (chr.HatId==%d != srvHatId==%d; GameMode=%d)\n", chr.HatId, srvHatId, conn->Parent->Info.GameMode);
            Printf(LOG_Error, "[SV] Server ID %u sent login \"%s\" with bad HatID (chr.HatId==%d != srvHatId==%d; GameMode==%d); saving with srvHatId.\n",
                conn->ID, p_logname.c_str(), chr.HatId, srvHatId, conn->Parent->Info.GameMode);
            chr.HatId = srvHatId;
        }
    }

    BinaryStream obs;
    if(!chr.SaveToStream(obs))
    {
        Printf(LOG_Error, "[SV] Internal error: unable to save A2C for character \"%s\", login \"%s\" from server ID %u!\n", chr.Nick.c_str(), p_logname.c_str(), conn->ID);
        return true;
    }

    std::vector<uint8_t>& obsb = obs.GetBuffer();
    p_chrdata = new char[obsb.size()];
    for(uint32_t i = 0; i < obsb.size(); i++)
        p_chrdata[i] = obsb[i];
//.........这里部分代码省略.........
开发者ID:,项目名称:,代码行数:101,代码来源:


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