示例#1
0
int StateGame::OnStatsStrInc (IPacket &packet)
{
    if (!packet.EndOfStream())
        return MSG_ERROR_SIZE;

    boost::shared_ptr<Player> player = static_cast<srv::Connection*>(m_connection)->GetPlayer();

    if (!player)
        return MSG_ERROR;

    if  (player->get_stat())
    {
        player->inc_str();

        DB::PLAYER::Stats query;
        query(m_server->DBConnection(),player);

        boost::shared_ptr<OPacket> pkt(new OPacket);
        srv_pkt::IncStr(pkt);
        m_connection->Send(pkt);

        boost::shared_ptr<Party> party = player->get_party();

        if (party)
        {
            party->SendHPMPNotification(player->GetUniqueID(),player->hp(),player->max_hp(),player->mp(),
                player->max_mp());
        }
    }

    return MSG_SUCCESS;
}
示例#2
0
int StateLobby::OnRestoreCharacter (IPacket &packet)
{
    if (!m_loaded)
        return MSG_ERROR_ORDER;

    std::string name = packet.Read();

    if (!packet.EndOfStream())
        return MSG_ERROR_SIZE;

    player_iterator i = FindCharacterIndex(name);

    if ( i != m_player_list.end() )
    {
        (*i)->restore();
        (*i)->set_timeleft(0);

        boost::shared_ptr<OPacket> pkt(new OPacket);
        srv_pkt::Lobby(pkt,srv_pkt::LOBBY_ACTION_RESTORE);
        m_connection->Send(pkt);

        DB::PLAYER::Restore query;
        query(m_server->DBConnection(),(*i)->ID());
    }
    else
        return MSG_ERROR_ARG;

    return MSG_SUCCESS;
}
示例#3
0
int StateGame::OnExchangeConfirm (IPacket &packet)
{
    if (!packet.EndOfStream())
        return MSG_ERROR_SIZE;

    boost::shared_ptr<Player> player = static_cast<srv::Connection*>(m_connection)->GetPlayer();

    if (!player)
        return MSG_ERROR;

    boost::shared_ptr<Player> target = get_invitation_player(player);

    if(!target)
        return MSG_SUCCESS;

    boost::shared_ptr<OPacket> pkt(new OPacket);
    srv_pkt::ExchangeConfirm(pkt);
    m_connection->Send(pkt);

    pkt.reset(new OPacket);

    srv_pkt::ExchangePlayerConfirm(pkt);
    m_server->Send(pkt,target->ConnectionID());

    return MSG_SUCCESS;
}
示例#4
0
int IStateHandshake::OnHandshake_Signature (const IPacket &packet)
{
    uint8_t signature[KEY_LENGTH] = { 0 };

    for (int i=0; i < KEY_LENGTH; ++i)
        signature[i] = packet.Read<uint8_t>();

    if (!packet.EndOfStream())
        return MSG_ERROR_SIZE;

    /// Simple check to see if the handshake is good
    if(memcmp(m_srv_signature,signature,KEY_LENGTH))
    {
#if defined DEBUG
        syslog(LOG_DEBUG,"clt::IStateHandshake::OnHandshake_Signature - Invalid Server Signature.");
        syslog(LOG_DEBUG,"Server Key = %i %i, Client Key = %i %i",m_srv_signature[0],m_srv_signature[1],
            signature[0],signature[1]);
#endif
        return MSG_ERROR_ARG;
    }

    Func_X_2(m_base_key, m_S, 0x3);

    boost::shared_ptr<SROAuth> auth =
            boost::shared_static_cast<SROAuth,Authentication>(m_connection->getAuthentication());

    auth->setKey(m_base_key,KEY_LENGTH);

    SendID();

    return MSG_SUCCESS;
}
示例#5
0
int StateGame::OnExchangeRequest (IPacket &packet)
{
    uint32_t targetID = packet.Read<uint32_t>();

    if (!packet.EndOfStream())
        return MSG_ERROR_SIZE;

    World *world = m_server->GetWorld();

    boost::shared_ptr<Player> player = static_cast<srv::Connection*>(m_connection)->GetPlayer();

    if (!player)
        return MSG_ERROR;

    if (player->get_selected_object() != targetID)
        return MSG_ERROR_ARG;

    boost::shared_ptr<Player> target = world->FindPlayer_ByID(targetID);

    if(!target)
        return MSG_SUCCESS;

    player->set_invitation_player(targetID);

    target->set_invitation_player(player->GetUniqueID());
    target->set_invitation(INVITATION_EXCHANGE);

    boost::shared_ptr<OPacket> pkt(new OPacket);
    srv_pkt::Invite(pkt,INVITATION_EXCHANGE,player->GetUniqueID());
    m_server->Send(pkt,target->ConnectionID());

    return MSG_SUCCESS;
}
示例#6
0
int StateGame::OnGMCommand_SpawnAllUniques (IPacket &packet)
{
    if (!packet.EndOfStream())
        return MSG_ERROR_SIZE;

    return MSG_SUCCESS;
}
示例#7
0
int StateCertify::OnCertify (const IPacket &packet)
{
    uint8_t ret = packet.Read<uint8_t>();

    if (!packet.EndOfStream())
        return MSG_ERROR_SIZE;

    if (ret > ANSWER_ERROR)
        return MSG_ERROR_ARG;

    if (ret == ANSWER_ACCEPT)
    {
        syslog(LOG_INFO,"Certification Successfull.");

        m_service->runServer();

        m_connection->stop();
    }
    else
    {
        syslog(LOG_INFO,"Certification failed.");

        m_service->stop();
    }

    return MSG_SUCCESS;
}
示例#8
0
int StateGlobal::OnTicket (const IPacket &packet)
{
    Ticket ticket;

    ticket.ID = packet.Read<uint32_t>();

    ticket.usr = packet.Read();

    ticket.pw = packet.Read();

    ticket.IP = packet.Read();

    ticket.AccountID = packet.Read<uint32_t>();

    ticket.access_lv  = packet.Read<uint8_t>();

    ticket.sec_lv = packet.Read<uint8_t>();

    ticket.silk = packet.Read<uint32_t>();

    if (!packet.EndOfStream())
        return MSG_ERROR_SIZE;

    m_service->addTicket(ticket);

    return MSG_SUCCESS;
}
示例#9
0
int StateGame::OnGMCommand_AllowLogout (IPacket &packet)
{
    std::string playerName = packet.Read();

    if (!packet.EndOfStream())
        return MSG_ERROR_SIZE;

    return MSG_SUCCESS;
}
示例#10
0
int StateGame::OnGMCommand_LieName (IPacket &packet)
{
    std::string name = packet.Read();

    if (!packet.EndOfStream())
        return MSG_ERROR_SIZE;

    return MSG_SUCCESS;
}
示例#11
0
int IStateHandshake::OnHandshake_Clean (const IPacket &packet)
{
    if (!packet.EndOfStream())
        return MSG_ERROR_SIZE;

    SendID();

    return MSG_SUCCESS;
}
示例#12
0
int StateGame::OnGMCommand_CreateItem (IPacket &packet)
{
    uint32_t itemID = packet.Read<uint32_t>();

    uint8_t arg = packet.Read<uint8_t>();

    if (!packet.EndOfStream())
        return MSG_ERROR_SIZE;

    boost::shared_ptr<Player> player = static_cast<srv::Connection*>(m_connection)->GetPlayer();

    if (!player)
        return MSG_ERROR;

    World *world = m_server->GetWorld();

    if (!world)
        return MSG_ERROR;

    boost::shared_ptr<OPacket> pkt(new OPacket);

    try
    {
        Item item = world->GetItemFactory()->Create(itemID);

        boost::shared_ptr<Storage> inv = player->get_storage(STORAGE_INVENTORY);

        uint8_t pos = inv->get_empty_position(13);

        if (pos == 255)
        {
            srv_pkt::ItemMove(pkt,srv_pkt::ITEM_ERROR_INVENTORY_FULL);
            m_connection->Send(pkt);
            return MSG_SUCCESS;
        }

        item.set_quantity(1);
        item.set_position(pos);
        item.set_place(STORAGE_INVENTORY);

        if (item.IsWeapon() || item.IsShield() || item.IsArmor() || item.IsAccessory())
            item.set_enchant_lv(arg);
        else
            item.set_quantity(arg);

        inv->InsertItem(item);

        srv_pkt::Item(pkt,srv_pkt::ITEM_MOVE_PICKUP,item);
        m_connection->Send(pkt);
    }
    catch (const Exception::InvalidItemID &error)
    {
        syslog(LOG_INFO,"Failed to create item with ID = %i",itemID);
    }

    return MSG_SUCCESS;
}
示例#13
0
int StateGame::OnGMCommand_RecallGuild (IPacket &packet)
{
    std::string guildName = packet.Read();

    if (!packet.EndOfStream())
        return MSG_ERROR_SIZE;

    return MSG_SUCCESS;
}
示例#14
0
int StateLobby::OnValidateCharacterName (IPacket &packet)
{
    std::string name = packet.Read();

    if (!packet.EndOfStream())
        return MSG_ERROR_SIZE;

    if (IsNameValid(name))
    {
        boost::shared_ptr<OPacket> pkt(new OPacket);
        srv_pkt::Lobby(pkt,srv_pkt::LOBBY_ACTION_VALIDATE_NAME);
        m_connection->Send(pkt);
    }

    return MSG_SUCCESS;
}
示例#15
0
int IStateHandshake::OnWhoIs (const IPacket &packet)
{
    std::string srvID = packet.Read();

    uint8_t resv = packet.Read<uint8_t>();

    if (!packet.EndOfStream())
        return MSG_ERROR_SIZE;

    if (resv || srvID != m_SrvID)
        return MSG_ERROR_ARG;

    OnConfig();

    return MSG_SUCCESS;
}
示例#16
0
int StateGame::OnGMCommand_LoadMonster (IPacket &packet)
{
    uint32_t ID = packet.Read<uint32_t>();

    uint8_t quantity = packet.Read<uint8_t>();

    uint8_t type = packet.Read<uint8_t>();

    if (!packet.EndOfStream())
        return MSG_ERROR_SIZE;

    if (!quantity)
        quantity = 1;

    boost::shared_ptr<Player> player = static_cast<srv::Connection*>(m_connection)->GetPlayer();

    if (!player)
        return MSG_ERROR;

    if(m_server->GetWorld()->IsInsideTown(player->get_position()))
        return MSG_SUCCESS;

    boost::shared_ptr<NPC> mob;
    std::vector<boost::shared_ptr<NPC> > list;

    World *world = m_server->GetWorld();

    for (uint16_t i = 0; i < quantity; ++i)
    {
        mob = world->GetCharacterFactory()->Create(ID);

        if (!mob)
        {
            syslog(LOG_INFO,"Failed to create NPC with ID = %i",ID);
            return MSG_SUCCESS;
        }

        mob->set_position(player->get_position());

        list.push_back(mob);
    }

    world->InsertNPC(list,player->get_position());

    return MSG_SUCCESS;
}
示例#17
0
int StateLobby::OnListCharacter (IPacket &packet)
{
    if (!packet.EndOfStream())
        return MSG_ERROR_SIZE;

    if (!m_loaded)
    {
        LoadCharacters();
        m_loaded = true;
    }

    boost::shared_ptr<OPacket> pkt(new OPacket);
    srv_pkt::Lobby(pkt,m_player_list);
    m_connection->Send(pkt);

    return MSG_SUCCESS;
}
示例#18
0
int StateGame::OnGMCommand_ClearInventory (IPacket &packet)
{
    if (!packet.EndOfStream())
        return MSG_ERROR_SIZE;

//    boost::shared_ptr<Storage> inv = m_player->get_storage(STORAGE_INVENTORY);
//
//    for (Storage::iterator iter = inv->begin(); iter != inv->end(); ++iter)
//    {
//        if (iter->first >= Item::MAX_EQUIPMENT_SLOT)
//        {
//            send(packet::ItemEnchant(iter->first)); ///REMOVE ITEM FROM INVENTORY
//
//            inv->RemoveItem(iter->first);
//        }
//    }

    return MSG_SUCCESS;
}
示例#19
0
int StateGame::OnSetHotkey (IPacket &packet)
{
    Hotkey hotkey;

    hotkey.pos = packet.Read<uint8_t>();

    hotkey.type = packet.Read<uint8_t>();

    hotkey.id = packet.Read<uint32_t>();

    if (!packet.EndOfStream())
        return MSG_ERROR_SIZE;

    boost::shared_ptr<Player> player = static_cast<srv::Connection*>(m_connection)->GetPlayer();

    if (!player)
        return MSG_ERROR;

    if (hotkey.type)
    {
        player->m_Hotkeys.push_back(hotkey);

        DB::HOTKEY::Insert query;
        query(m_server->DBConnection(),player->ID(),hotkey);
    }
    else
    {
        for (std::vector<Hotkey>::iterator i = player->m_Hotkeys.begin(); i != player->m_Hotkeys.end(); ++i)
        {
            if (i->pos == hotkey.pos)
            {
                player->m_Hotkeys.erase(i);
                break;
            }
        }

        DB::HOTKEY::Remove query;
        query(m_server->DBConnection(),player->ID(),hotkey.pos);
    }

    return MSG_SUCCESS;
}
示例#20
0
int StateGame::OnExchangeClose (IPacket &packet)
{
    if (!packet.EndOfStream())
        return MSG_ERROR_SIZE;

    bool closed = false;

    boost::shared_ptr<Player> player = static_cast<srv::Connection*>(m_connection)->GetPlayer();

    if (!player)
        return MSG_ERROR;

    if (closed)
    {
        player->set_invitation_player(0);

        player->close_exchange();
    }

    boost::shared_ptr<OPacket> pkt(new OPacket);

    srv_pkt::ExchangeClose(pkt,closed);
    m_connection->Send(pkt);

    boost::shared_ptr<Player> target = get_invitation_player(player);

    if (target)
    {
        target->set_invitation_player(0);

        target->close_exchange();

        pkt.reset(new OPacket);

        srv_pkt::ExchangeClose(pkt,closed);
        m_server->Send(pkt,target->ConnectionID());
    }

    return MSG_SUCCESS;
}
示例#21
0
int StateGame::OnSetAutopot (IPacket &packet)
{
    uint8_t hp_bar_slot = packet.Read<uint8_t>();
    uint8_t hp_active_value = packet.Read<uint8_t>();

    uint8_t mp_bar_slot = packet.Read<uint8_t>();
    uint8_t mp_active_value = packet.Read<uint8_t>();

    uint8_t pill_bar_slot = packet.Read<uint8_t>();
    uint8_t pill_active = packet.Read<uint8_t>();

    uint8_t delay_active_value = packet.Read<uint8_t>();

    if (!packet.EndOfStream())
        return MSG_ERROR_SIZE;

    boost::shared_ptr<Player> player = static_cast<srv::Connection*>(m_connection)->GetPlayer();

    if (!player)
        return MSG_ERROR;

    player->m_Autopot.hp_bar = (hp_bar_slot & 0xF0) >> 4;
    player->m_Autopot.hp_slot = (hp_bar_slot & 0x0F);
    player->m_Autopot.hp_active = (hp_active_value & 0x80) >> 7;
    player->m_Autopot.hp_value = (hp_active_value) & 0x7F;
    player->m_Autopot.mp_bar = (mp_bar_slot & 0xF0) >> 4;
    player->m_Autopot.mp_slot = (mp_bar_slot & 0x0F);
    player->m_Autopot.mp_active = (mp_active_value & 0x80) >> 7;
    player->m_Autopot.mp_value = (mp_active_value) & 0x7F;
    player->m_Autopot.pill_bar = (pill_bar_slot & 0xF0) >> 4;
    player->m_Autopot.pill_slot = (pill_bar_slot & 0x0F);
    player->m_Autopot.pill_active = pill_active >>= 7;
    player->m_Autopot.delay_active = (delay_active_value & 0x80) >> 7;
    player->m_Autopot.delay_value = (delay_active_value) & 0x7F;

    DB::PLAYER::Autopot query;
    query(m_server->DBConnection(),player->ID(),player->m_Autopot);

    return MSG_SUCCESS;
}
示例#22
0
int StateGame::OnGMCommand_MoveToUser (IPacket &packet)
{
    std::string name = packet.Read();

    if (!packet.EndOfStream())
        return MSG_ERROR_SIZE;

    boost::shared_ptr<Player> player = static_cast<srv::Connection*>(m_connection)->GetPlayer();

    if (!player)
        return MSG_ERROR;

    boost::shared_ptr<Player> target = m_server->GetWorld()->FindPlayer_ByName(name);

    if (target)
    {
        player->SetCurrentTask(PLAYER_TASK_TELEPORT);
        m_server->GetWorld()->InitTaskTeleport(player->GetUniqueID(),target->get_position(),0);
    }

    return MSG_SUCCESS;
}
示例#23
0
int StateGame::OnGMCommand_Kill (IPacket &packet)
{
    uint32_t entityID = packet.Read<uint32_t>();

    uint16_t action = packet.Read<uint16_t>();

    if (!packet.EndOfStream())
        return MSG_ERROR_SIZE;

    if (action)
    {
        boost::shared_ptr<Player> player = static_cast<srv::Connection*>(m_connection)->GetPlayer();

        if (!player)
            return MSG_ERROR;

        boost::shared_ptr<NPC> npc = m_server->GetWorld()->FindNPC_CloseToPosition(entityID,player->get_position());

        if (npc)
            npc->consume_hp(npc->hp());
    }

    return MSG_SUCCESS;
}
示例#24
0
int StateGame::OnExchangeApprove (IPacket &packet)
{
    if (!packet.EndOfStream())
        return MSG_ERROR_SIZE;

    boost::shared_ptr<Player> player = static_cast<srv::Connection*>(m_connection)->GetPlayer();

    if (!player)
        return MSG_ERROR;
    
    boost::shared_ptr<Player> target = get_invitation_player(player);

    if(!target)
        return MSG_SUCCESS;

    boost::shared_ptr<OPacket> pkt(new OPacket);

    srv_pkt::ExchangeApprove(pkt);
    m_connection->Send(pkt);

    player->set_exchange_approval(true);

    if (target->is_exchange_approved())
    {
        pkt.reset(new OPacket);

        srv_pkt::ExchangeCompleted(pkt);

        m_connection->Send(pkt,false,false);
        m_server->Send(pkt,target->ConnectionID());

        boost::shared_ptr<Storage> my_inv = player->get_storage(STORAGE_INVENTORY);

        boost::shared_ptr<ExchangeWnd> my_exchange = player->get_exchange_window();

        boost::shared_ptr<Storage> other_inv = target->get_storage(STORAGE_INVENTORY);

        boost::shared_ptr<ExchangeWnd> other_exchange = target->get_exchange_window();

        //Exchange players gold.
        player->gain_gold(other_exchange->get_gold_amount());
        player->spend_gold(my_exchange->get_gold_amount());

        target->gain_gold(my_exchange->get_gold_amount());
        target->spend_gold(other_exchange->get_gold_amount());

        //Exchange players items.
        ExchangeWnd::iterator iter;

        for (iter = my_exchange->begin(); iter != my_exchange->end(); ++iter)
            my_inv->RemoveItem(iter->second.get_alt_position());

        for (iter = other_exchange->begin(); iter != other_exchange->end(); ++iter)
            other_inv->RemoveItem(iter->second.get_alt_position());

        uint8_t new_pos;

        for (iter = my_exchange->begin(); iter != my_exchange->end(); ++iter)
        {
            new_pos = other_inv->get_empty_position(13);

            iter->second.set_position(new_pos);

            other_inv->InsertItem(iter->second);
        }

        for (iter = other_exchange->begin(); iter != other_exchange->end(); ++iter)
        {
            new_pos = my_inv->get_empty_position(13);

            iter->second.set_position(new_pos);

            my_inv->InsertItem(iter->second);
        }
    }

    return MSG_SUCCESS;
}
示例#25
0
int IStateHandshake::OnHandshake_Security (const IPacket &packet)
{
    boost::shared_ptr<SROAuth> auth =
            boost::shared_static_cast<SROAuth,Authentication>(m_connection->getAuthentication());

    uint8_t mode = auth->getMode();

    if (mode & SECURITY_ENCRYPTION)
    {
        uint8_t public_key[KEY_LENGTH];

        for (int i = 0; i < KEY_LENGTH; ++i)
            public_key[i] = packet.Read<uint8_t>();

        auth->setKey(public_key,KEY_LENGTH);
    }

    if (mode & SECURITY_CRC)
    {
        uint32_t count = packet.Read<uint32_t>();

        uint32_t crc = packet.Read<uint32_t>();

        auth->initializeCount(count);

        auth->initializeCRC(crc);
    }

    if (mode & SECURITY_DH)
    {
        for (int i = 0; i < KEY_LENGTH; ++i)
            m_base_key[i] = packet.Read<uint8_t>();

        uint32_t G = packet.Read<uint32_t>();

        uint32_t P = packet.Read<uint32_t>();

        uint32_t A = packet.Read<uint32_t>();

        if (!packet.EndOfStream())
            return MSG_ERROR_SIZE;

        uint32_t b = rand();

        uint8_t keyByte = 0;
        uint32_t B = ModExp(P,b,G);
        m_S = ModExp(P,b,A);

        uint8_t priv_key[KEY_LENGTH] = { 0 };
        memcpy(priv_key,&A,sizeof(A));
        memcpy(priv_key+4,&B,sizeof(B));

        keyByte = LOBYTE(LOWORD(m_S)) & 0x03;
        Func_X_2(priv_key, m_S, keyByte);

        auth->setKey(priv_key,KEY_LENGTH);

        /// Generate the private blowfish data
        uint8_t signature[KEY_LENGTH] = { 0 };
        memcpy(signature,&B,sizeof(B));
        memcpy(signature+4,&A,sizeof(A));

        keyByte = LOBYTE(LOWORD(B)) & 0x07;
        Func_X_2(signature, m_S, keyByte);

        auth->encrypt(signature,signature,KEY_LENGTH);

        OPacket pkt;
        clt_pkt::Signature(&pkt,B,signature,KEY_LENGTH);
        m_connection->send(&pkt);

        memcpy(m_srv_signature,&A,sizeof(A));
        memcpy(m_srv_signature+4,&B,sizeof(B));

        keyByte = LOBYTE(LOWORD(A)) & 0x07;
        Func_X_2(m_srv_signature,m_S, keyByte);

        auth->encrypt(m_srv_signature,m_srv_signature,KEY_LENGTH);
    }

    if (!packet.EndOfStream())
        return MSG_ERROR_SIZE;

    if (!(mode & SECURITY_DH))
        SendID();

    return MSG_SUCCESS;
}
示例#26
0
int StateLobby::OnCreateCharacter (IPacket &packet)
{
    /**
     *
     *  BASIC ITEMS ID'S
     *  (THE ID MIGHT CHANGE ON FUTURE UPDATES SO IT NEEDS TO BE CHECKED)
     *
     **/

    enum
    {
        /**
         *
         *  CHINESE BASIC ITEMS.
         *
         **/

        ITEM_CH_SWORD_01_A_DEF	= 3632,
        ITEM_CH_BLADE_01_A_DEF,
        ITEM_CH_SPEAR_01_A_DEF,
        ITEM_CH_TBLADE_01_A_DEF,
        ITEM_CH_BOW_01_A_DEF,

        ITEM_CH_M_HEAVY_01_BA_A_DEF,
        ITEM_CH_M_HEAVY_01_LA_A_DEF,
        ITEM_CH_M_HEAVY_01_FA_A_DEF,
        ITEM_CH_M_LIGHT_01_BA_A_DEF,
        ITEM_CH_M_LIGHT_01_LA_A_DEF,
        ITEM_CH_M_LIGHT_01_FA_A_DEF,
        ITEM_CH_M_CLOTHES_01_BA_A_DEF,
        ITEM_CH_M_CLOTHES_01_LA_A_DEF,
        ITEM_CH_M_CLOTHES_01_FA_A_DEF,
        ITEM_CH_W_HEAVY_01_BA_A_DEF,
        ITEM_CH_W_HEAVY_01_LA_A_DEF,
        ITEM_CH_W_HEAVY_01_FA_A_DEF,
        ITEM_CH_W_LIGHT_01_BA_A_DEF,
        ITEM_CH_W_LIGHT_01_LA_A_DEF,
        ITEM_CH_W_LIGHT_01_FA_A_DEF,
        ITEM_CH_W_CLOTHES_01_BA_A_DEF,
        ITEM_CH_W_CLOTHES_01_LA_A_DEF,
        ITEM_CH_W_CLOTHES_01_FA_A_DEF,
        ITEM_CH_SHIELD_01_A_DEF = 10488,

        ITEM_ETC_AMMO_ARROW_01_DEF = 3655,
        ITEM_ETC_AMMO_BOLT_01_DEF = 10487,

        /**
         *
         *  EUROPEAN BASIC ITEMS.
         *
         **/

        ITEM_EU_DAGGER_01_A_DEF = 10489,
        ITEM_EU_SWORD_01_A_DEF,
        ITEM_EU_TSWORD_01_A_DEF,
        ITEM_EU_AXE_01_A_DEF,
        ITEM_EU_CROSSBOW_01_A_DEF,
        ITEM_EU_DARKSTAFF_01_A_DEF,
        ITEM_EU_TSTAFF_01_A_DEF,
        ITEM_EU_HARP_01_A_DEF,
        ITEM_EU_STAFF_01_A_DEF,
        ITEM_EU_SHIELD_01_A_DEF,

        ITEM_EU_M_HEAVY_01_BA_A_DEF = 11219,
        ITEM_EU_M_HEAVY_01_LA_A_DEF,
        ITEM_EU_M_HEAVY_01_FA_A_DEF,
        ITEM_EU_M_LIGHT_01_BA_A_DEF,
        ITEM_EU_M_LIGHT_01_LA_A_DEF,
        ITEM_EU_M_LIGHT_01_FA_A_DEF,
        ITEM_EU_M_CLOTHES_01_BA_A_DEF,
        ITEM_EU_M_CLOTHES_01_LA_A_DEF,
        ITEM_EU_M_CLOTHES_01_FA_A_DEF,
        ITEM_EU_W_HEAVY_01_BA_A_DEF,
        ITEM_EU_W_HEAVY_01_LA_A_DEF,
        ITEM_EU_W_HEAVY_01_FA_A_DEF,
        ITEM_EU_W_LIGHT_01_BA_A_DEF,
        ITEM_EU_W_LIGHT_01_LA_A_DEF,
        ITEM_EU_W_LIGHT_01_FA_A_DEF,
        ITEM_EU_W_CLOTHES_01_BA_A_DEF,
        ITEM_EU_W_CLOTHES_01_LA_A_DEF,
        ITEM_EU_W_CLOTHES_01_FA_A_DEF
    };

    enum
    {
        POS_CHEST,
        POS_LEG,
        POS_FOOT,
        POS_WEAPON
    };

    if (!m_loaded || m_player_list.size() >= MAX_PLAYER_COUNT)
    {
        boost::shared_ptr<OPacket> pkt(new OPacket);
        
        if (!pkt)
            return MSG_ERROR_MEMORY;

        srv_pkt::Lobby(pkt,srv_pkt::LOBBY_ACTION_CREATE,srv_pkt::LOBBY_ERROR_MAX_CHARACTERS);
        m_connection->Send(pkt);
        return MSG_SUCCESS;
    }

    std::string name = packet.Read();

    uint32_t model = packet.Read<uint32_t>();

    uint8_t volume = packet.Read<uint8_t>();

    uint32_t items[4];

    for (int i = 0; i < 4; ++i)
        items[i] = packet.Read<uint32_t>();

    if (!packet.EndOfStream())
        return MSG_ERROR_SIZE;

    /// Validate data sent

    if (!IsNameValid(name))
        return MSG_SUCCESS;

    ///CHECK IF THE ARMOR IS OF THE SAME TYPE
    if (items[0]+1 != items[1] || items[1] +1 != items[2])
        return MSG_ERROR_ARG;

    World *world = m_server->GetWorld();

    ///CHECK THAT THE ITEMS CORRESPOND TO THE RACE,GENDER AND WEAPON
    if ( model >= 1907 && model <= 1932 )
    {
        ///CHINESE MODEL
        if (!world->IsChineseAllowed())
        {
            syslog(LOG_INFO,"This server dont allow creating ch characters.");
            return MSG_ERROR;
        }

        ///CHECK FOR VALID CHINESE WEAPONS
        switch(items[POS_WEAPON])
        {
        case ITEM_CH_SWORD_01_A_DEF:
        case ITEM_CH_BLADE_01_A_DEF:
        case ITEM_CH_SPEAR_01_A_DEF:
        case ITEM_CH_TBLADE_01_A_DEF:
        case ITEM_CH_BOW_01_A_DEF:
            break;
        default:
            return MSG_ERROR_ARG;
        }

        if (model >= 1907 && model <= 1919)
        {
            ///CHECK FOR MEN MODEL AND ITEMS
            if (items[0] > ITEM_CH_M_CLOTHES_01_FA_A_DEF)
                return MSG_ERROR_ARG;
        }
        else
        {
            ///CHECK FOR WOMEN MODEL AND ITEMS
            if (items[0] < ITEM_CH_W_HEAVY_01_BA_A_DEF)
                return MSG_ERROR_ARG;
        }
    }
    else if ( model >= 14477 && model <= 14502 )
    {
        if (!world->IsEuropeanAllowed())
        {
            syslog(LOG_INFO,"This server dont allow creating eu characters.");
            return MSG_ERROR;
        }

         ///CHECK FOR VALID CHINESE WEAPONS
        switch(items[POS_WEAPON])
        {
        case ITEM_EU_DAGGER_01_A_DEF:
        case ITEM_EU_SWORD_01_A_DEF:
        case ITEM_EU_TSWORD_01_A_DEF:
        case ITEM_EU_AXE_01_A_DEF:
        case ITEM_EU_CROSSBOW_01_A_DEF:
        case ITEM_EU_DARKSTAFF_01_A_DEF:
        case ITEM_EU_TSTAFF_01_A_DEF:
        case ITEM_EU_HARP_01_A_DEF:
        case ITEM_EU_STAFF_01_A_DEF:
            break;
        default:
            return MSG_ERROR_ARG;
        }

        if (model >= 14477 && model <= 14489)
        {
            ///CHECK FOR MEN MODEL AND ITEMS
            if (items[0] > ITEM_EU_M_CLOTHES_01_FA_A_DEF)
                return MSG_ERROR_ARG;
        }
        else
        {
            ///CHECK FOR WOMEN MODEL AND ITEMS
            if (items[0] < ITEM_EU_W_HEAVY_01_BA_A_DEF)
                return MSG_ERROR_ARG;
        }
    }
    else
        return MSG_ERROR_ARG;

    std::vector<Item> item_list;
    for (int i = 0; i < 4; ++i)
    {
        Item itm = world->GetItemFactory()->Create(items[i]);
        item_list.push_back(itm);
    }

    ///Look if the initial weapon requires a shield or bolt or arrows.
    uint32_t extraID = 0;

    switch(items[POS_WEAPON])
    {
    case ITEM_CH_SWORD_01_A_DEF:
    case ITEM_CH_BLADE_01_A_DEF:
        extraID = ITEM_CH_SHIELD_01_A_DEF;
        break;
    case ITEM_EU_SWORD_01_A_DEF:
    case ITEM_EU_DARKSTAFF_01_A_DEF:
    case ITEM_EU_STAFF_01_A_DEF:
        extraID = ITEM_EU_SHIELD_01_A_DEF;
        break;
    case ITEM_EU_CROSSBOW_01_A_DEF:
        extraID = ITEM_ETC_AMMO_BOLT_01_DEF;
        break;
    case ITEM_CH_BOW_01_A_DEF:
        extraID = ITEM_ETC_AMMO_ARROW_01_DEF;
        break;
    default:
        break;
    }

    if (extraID)
    {
        try
        {
            Item extra = world->GetItemFactory()->Create(extraID);

            if (extraID == ITEM_ETC_AMMO_ARROW_01_DEF || extraID == ITEM_ETC_AMMO_BOLT_01_DEF)
                extra.set_quantity(extra.get_max_stack());

            item_list.push_back(extra);
        }
        catch (const Exception::InvalidItemID &error)
        {
            syslog(LOG_INFO,"Failed to create item with ID = %i",extraID);
        }
    }

    std::for_each(item_list.begin(),item_list.end(),boost::bind(&set_default_position,_1));

    boost::shared_ptr<Player> player = world->GetCharacterFactory()->Create(model, volume, name, item_list);

    if (!player)
    {
        syslog(LOG_INFO,"Failed to create player with model %i",model);
        return MSG_ERROR;
    }

    m_player_list.push_back(player);

    DB::PLAYER::Create create;
    create(m_server->DBConnection(),static_cast<srv::Connection*>(m_connection)->AccountID(),player,name);

    boost::shared_ptr<OPacket> pkt(new OPacket);

    if (!pkt)
        return MSG_ERROR_MEMORY;

    srv_pkt::Lobby(pkt,srv_pkt::LOBBY_ACTION_CREATE);
    m_connection->Send(pkt);

    return MSG_SUCCESS;
}
示例#27
0
int StateGlobal::OnConfig (const IPacket &packet)
{
    uint16_t ID = packet.Read<uint16_t>();

    uint8_t locale = packet.Read<uint8_t>();

    uint8_t race = packet.Read<uint8_t>();

    uint32_t version = packet.Read<uint32_t>();

    std::string chFilter = packet.Read();

    size_t size = packet.Read<size_t>();

    std::string tmp;
    std::vector<std::string> strFilter;
    for (size_t i=0; i < size; ++i)
    {
        tmp = packet.Read();
        strFilter.push_back(tmp);
    }

    int area_count = packet.Read<uint16_t>();

    Area area;
    std::vector<Area> world;

    uint16_t zoneID = 0;

    int zone_count = 0;

    for (int i = 0; i < area_count; ++i)
    {
        area.ID = packet.Read<uint16_t>();

        area.Instanced = packet.Read<uint8_t>();

        zone_count = packet.Read<uint16_t>();

        for (int j = 0; j < zone_count; ++j)
        {
            zoneID = packet.Read<uint16_t>();

            area.Zones.push_back(zoneID);
        }

        world.push_back(area);

        area.Zones.clear();
    }

    if (!packet.EndOfStream())
        return MSG_ERROR_SIZE;

    m_service->setShardID(ID);

    m_service->setLocale(locale);

    m_service->setRace(race);

    m_service->setVersion(version);

    m_service->setFilter(chFilter,strFilter);

    m_service->setWorld(world);

    m_service->runServer();

    return MSG_SUCCESS;
}
示例#28
0
int StateLobby::OnSelectCharacter (IPacket &packet)
{
    std::string name = packet.Read();

    if (!packet.EndOfStream())
        return MSG_ERROR_SIZE;

    World *world = m_server->GetWorld();

    player_iterator i = FindCharacterIndex(name);

    if ( i != m_player_list.end() )
    {
        boost::shared_ptr<Player> player = *i;

        if (!player)
            return MSG_ERROR;

        DB::MASTERY::Select mselect;
        MasteryTree tree = mselect(m_server->DBConnection(),player->ID(),player->level(),player->race());

        player->set_mastery_tree(tree);

        DB::SKILL::Select sselect;
        std::set<uint32_t> skill_list = sselect(m_server->DBConnection(),player->ID());

        player->set_skill_list(skill_list);

        boost::shared_ptr<Storage> ml = player->get_storage(STORAGE_MAIN);

        DB::ITEM::Select iobj;
        std::vector<Item::extended_type> item_list = iobj(m_server->DBConnection(),player->ID(),STORAGE_MAIN);

        for (std::vector<Item::extended_type>::const_iterator i = item_list.begin(); i != item_list.end(); ++i)
        {
            try
            {
                ml->InsertItem(world->GetItemFactory()->Create(i->id,*i));
            }
            catch (Exception::InvalidItemID &error)
            {
                syslog(LOG_INFO,"Lobby::LoadCharacters() - Error while cloning item with ID = %i",i->id);
            }
        }

        DB::JOB::Select jb_sl_query;
        Job job = jb_sl_query(m_server->DBConnection(),player->ID());

        player->set_job(job);

        boost::shared_ptr<OPacket> pkt(new OPacket);
        srv_pkt::RequestIngame(pkt);
        m_connection->Send(pkt);

        DB::PLAYER::State st_query;
        st_query(m_server->DBConnection(),player->ID(),true);

        pkt.reset(new OPacket);

        srv_pkt::InitScreen(pkt);
        m_connection->Send(pkt);

        DB::HOTKEY::Select hotkey_query;
        player->m_Hotkeys = hotkey_query(m_server->DBConnection(),player->ID());

        DB::BLOCK::Select block_query;
        player->m_BlockList = block_query(m_server->DBConnection(),player->ID());

        DB::PLAYER::Autopot autopot_query;
        player->m_Autopot = autopot_query(m_server->DBConnection(),player->ID());

        if (player->IsDead())
        {
            player->resurrect(false,false,0,false);

            Teleport tlp = m_server->GetWorld()->FindTeleport(player->get_return_point());

            if (!tlp.ID)
            {
                syslog(LOG_INFO,"Invalid Return Point - %i",player->get_return_point());
                return MSG_ERROR;
            }

            player->set_position(Coord(tlp.x,tlp.y,tlp.z,tlp.Zone));
        }

        pkt.reset(new OPacket);

        srv_pkt::PlayerInfo(pkt,player,static_cast<srv::Connection*>(m_connection)->AccountID());
        m_connection->Send(pkt);

        pkt.reset(new OPacket);

        srv_pkt::EndScreen(pkt);
        m_connection->Send(pkt);

        pkt.reset(new OPacket);

        srv_pkt::PlayerID(pkt,player);
        m_connection->Send(pkt);

        /// ADD SKILL PASSIVES

        boost::shared_ptr<Skill> skill;
        for (std::set<uint32_t>::const_iterator it = skill_list.begin(); it != skill_list.end(); ++it)
        {
            skill = m_server->GetWorld()->GetSkillManager()->find(*it);

            if (skill && skill->type() == SKT_PASSIVE)
            {
                Buff buff;
                buff.passive = true;
                buff.persistent = true;
                buff.Level = skill->level();
                buff.GroupID = skill->group_id();
                buff.Effects = skill->buff_list();

                buff.ReqShield = skill->require_shield();
                buff.ReqDevil = skill->require_devil();
                buff.ReqWeapon = skill->required_weapons();

                if (player->is_buff_stackable(buff))
                {
                    player->RemoveLesserBuffs(buff);
                    player->insert_buff(buff);
                }
            }
        }

        m_connection->SetState(srv::STATE_GAME);
        static_cast<srv::Connection*>(m_connection)->SetPlayer(player);
    }
    else
        return MSG_ERROR_ARG;

    return MSG_SUCCESS;
}
示例#29
0
    int StateVersion::OnVersionInfo (const IPacket &packet)
    {
        uint8_t locale = packet.Read<uint8_t>();

        std::string ID = packet.Read();

        uint32_t version = packet.Read<uint32_t>();

        if (!packet.EndOfStream())
            return MSG_ERROR_SIZE;

        boost::shared_ptr<Server> server = m_service->getServer();

        if (!server)
            return MSG_ERROR;

        if (locale != server->Locale() || ID != server->ClientID())
        {
            syslog(LOG_INFO,"Trying to log with a different locale");
            return MSG_ERROR_ARG;
        }

        if (version == server->ClientVersion())
        {
            m_connection->setState(srv::STATE_LOGIN);

            OPacket pkt;

            srv_pkt::WriteVersionE(&pkt);
            m_connection->send(&pkt);

            pkt.Clear();

            srv_pkt::WriteVersionF(&pkt);   ///PERFORM UPDATE PACKET!!
            m_connection->send(&pkt);
        }
        else if (version < server->ClientVersion())
        {
            OPacket pkt(0x600D);
            pkt.Write<uint8_t>(1);
            pkt.Write<uint16_t>(1);
            pkt.Write<uint16_t>(0xA100);
            m_connection->send(&pkt);

            pkt.Clear();

            pkt.WriteOpcode(0x600D);
            pkt.Write<uint8_t>(0);
            pkt.Write<uint8_t>(2);
            pkt.Write<uint8_t>(5);
            m_connection->send(&pkt);
    //		///REDIRECT TO UPDATE SERVER!!!
    //		m_connection->Stop();
        }
        else
        {
            /// TOO NEW
            OPacket pkt(0x600D);
            pkt.Write<uint8_t>(1);
            pkt.Write<uint16_t>(1);
            pkt.Write<uint16_t>(0xA100);
            m_connection->send(&pkt);

            pkt.Clear();

            pkt.WriteOpcode(0x600D);
            pkt.Write<uint8_t>(0);
            pkt.Write<uint8_t>(2);
            pkt.Write<uint8_t>(1);
            m_connection->send(&pkt);
        }

        return MSG_SUCCESS;
    }