Ir para conteúdo
Entre para seguir isso  
Raphael Carnaúba

[7.92] Teleport Library XML

Recommended Posts

Raphael Carnaúba    1
Raphael Carnaúba

Bom, estou liberando minha versão do Teleport Recorded em XML.

 

 

 

São 3 comandos:

 

 

/dests place name -- adiciona o nome a lista de destinations

/dests rem name -- remove o nome da lista

/dests name -- vai a posição que se encontra em esse nome na lista

/dests -- Mostra a lista de lugares...

 

 

 

commands.cpp

 

Abaixo de:

 

{"/raid",&Commands::forceRaid},

 

Adicione:

 

{"/dests",&Commands::goToDest},

 

No final de commands.cpp adicione:

 

bool Commands::destinationManager(Creature* creature, const std::string& cmd, const std::string& param)
{
        
    Player* player = creature->getPlayer();
    if(!player)
       return false;

    boost::char_separator<char> sep(" ");
    tokenizer cmdtokens(param, sep);
    tokenizer::iterator cmdit = cmdtokens.begin();
    
    if(cmdit != cmdtokens.end() && *cmdit == "add")
        {
        
    std::string param1 = parseParams(cmdit, cmdtokens.end());
        Position pos = player->getPosition();
    
        if(param1.size() > 0)
        {
            for(DestinationList::iterator it = g_game.destinationList.begin(); it != g_game.destinationList.end(); it++)
            {
                if((*it).name == param1)
                {
                   player->sendTextMessage(MSG_STATUS_CONSOLE_BLUE, "This place name already exists.");
                   return false;
                }
                if((*it).pos == pos)
                {
                   player->sendTextMessage(MSG_STATUS_CONSOLE_BLUE, "This place name already exists.");
                   return false;
                }
            }
            std::transform(param1.begin(), param1.end(), param1.begin(), tolower);
            DestinationStruct dests;
            dests.name = param1;
            dests.pos = pos;
            g_game.destinationList.push_back(dests);
            player->sendTextMessage(MSG_STATUS_CONSOLE_BLUE, "Added succesfully.");
        }
        else{
             player->sendTextMessage(MSG_STATUS_CONSOLE_BLUE, "Please enter a destination to be placed.");
             return false;
        }
     }
     else if(cmdit != cmdtokens.end() && *cmdit == "rem")
     {
       
      std::string param1 = parseParams(cmdit, cmdtokens.end());
          std::transform(param1.begin(), param1.end(), param1.begin(), tolower);
          if(param1.length() > 0)
          {
              for(DestinationList::iterator it = g_game.destinationList.begin(); it != g_game.destinationList.end(); it++)
              {
                  if((*it).name == param1)
                  {
                     g_game.destinationList.erase(it);
                     std::string msg = "Destination ";
                     msg += param1;
                     msg += " deleted.";
                     player->sendTextMessage(MSG_STATUS_CONSOLE_BLUE, msg.c_str());
                     return true;
                  }
              }
           }
          else{
              player->sendTextMessage(MSG_STATUS_CONSOLE_BLUE, "Please enter a destination to be removed.");
              return false;
          }
     }
     else 
     {
            std::stringstream ss;
            uint32_t id = 1;
            ss << " Destinations : \n";
            for( DestinationList::iterator it = g_game.destinationList.begin(); it != g_game.destinationList.end(); it++)
            {
                 ss << id << "- " << (*it).name << "\n Pos: " << (*it).pos << "\n";
                 id++;
            }
            player->sendTextWindow(1949, ss.str().c_str());
            return true;
     }
    
    return true;
}

 

commands.h abaixo de:

 

bool forceRaid(Creature* creature, const std::string& cmd, const std::string& param);

 

Adicione:

 

bool Commands::destinationManager(Creature* creature, const std::string& cmd, const std::string& param);

 

 

Agora em game.cpp

 

 

Se você usa The Forgotten Server procure por:

 

void Game::SaveData(bool kickPlayers)

 

abaixo de:

 

  map->saveMap("");

 

adicione:

 

saveDests();

 

Se você usa evolutions

Procure por:

 

void Game::saveServer()

 

abaixo de:

 

if(!map->saveMap("")){
        message += "\nfailed to save map";
    }

 

adicione:

 

saveDests();

 

 

No final adicione:

 

bool Game::loadDests()
{
    std::string filename = "data/destinations.xml";
    xmlDocPtr doc = xmlParseFile(filename.c_str());
    if(doc)
    {
        xmlNodePtr root, p;
        root = xmlDocGetRootElement(doc);
        if(xmlStrcmp(root->name,(const xmlChar*)"dests") != 0)
        {    
            std::cout << "Malformuled destinations.xml" << std::endl;
            return false;
        }
            int32_t intValue;
            std::string strValue;
            
            p = root->children;
            while(p)
            {
                if(xmlStrcmp(p->name, (const xmlChar*)"dest") == 0)
                {
                    std::string name;
                    Position pos;
                    if(readXMLString(p, "name", strValue))
                    {
                        name = strValue;
                    }    
                    if(readXMLInteger(p, "x", intValue))
                    {
                        pos.x = intValue;
                    }
                    if(readXMLInteger(p, "y", intValue))
                    {
                        pos.y = intValue;
                    }
                    if(readXMLInteger(p, "z", intValue))
                    {
                        pos.z = intValue;
                    }
                    
                    DestinationStruct dests;
                    dests.name = name;
                    dests.pos = pos;
                    destinationList.push_back(dests);
                }
               p = p->next;
            }
            xmlFreeDoc(doc);
            return true;
         }
       return false;
}
bool Game::saveDests()
{
     std::string filename = "data/destinations.xml";
     xmlDocPtr doc = xmlNewDoc((xmlChar*) "1.0");
     xmlNodePtr node = xmlNewNode(NULL, (xmlChar*)"dests");
     xmlDocSetRootElement(doc, node);
     
     for(DestinationList::iterator it = destinationList.begin(); it != destinationList.end(); it++)
     {
         xmlNodePtr p = xmlNewChild(node, NULL, (xmlChar*) "dest", NULL);
         
         std::stringstream ss;
         ss << (*it).name;
         xmlNewProp(p, (xmlChar*)"name", (xmlChar*)ss.str().c_str());
         ss.str("");
         
         ss << (*it).pos.x;
         xmlNewProp(p, (xmlChar*)"x", (xmlChar*) ss.str().c_str());
         ss.str("");
         
         ss << (*it).pos.y;
         xmlNewProp(p, (xmlChar*)"y", (xmlChar*) ss.str().c_str());
         ss.str("");
         
         ss << (*it).pos.z;
         xmlNewProp(p, (xmlChar*)"z", (xmlChar*) ss.str().c_str());
         ss.str("");
         
         xmlAddChild(node, p);
     }
     if( xmlSaveFile( filename.c_str() , doc ) != 0 )
        std::cout << "Saved a new place succesfully!" << std::endl;
     else
         std::cout << "Failed to save a new place!" << std::endl; 
     
     xmlFreeDoc(doc);
     
     return true;
}

 

game.h

 

abaixo de:

 

enum LightState_t {
    LIGHT_STATE_DAY,
    LIGHT_STATE_NIGHT,
    LIGHT_STATE_SUNSET,
    LIGHT_STATE_SUNRISE,
};

 

 

Adicione:

 

 

struct DestinationStruct
{
    std::string name;
    Position pos;
};

typedef std::list<DestinationStruct> DestinationList;

 

Agora em public abaixo de:

 

~Game();

 

Adicione:

 

    DestinationList destinationList;
    bool loadDests();
    bool saveDests();

 

 

otserv.cpp

 

acima de:

 

    std::cout << "[done]" << std::endl;
    std::string worldType = g_config.getString(ConfigManager::WORLD_TYPE);
    std::transform(worldType.begin(), worldType.end(), worldType.begin(), upchar);

 

Adicione:

 

    filename.str("");
    filename << g_config.getString(ConfigManager::DATA_DIRECTORY) << "destinations.xml";
    std::cout << ":: Loading destinations.xml... ";
    if(!g_game.loadDests()){
        std::stringstream errormsg;
        errormsg << "Unable to load " << filename.str() << "!";
        ErrorMessage(errormsg.str().c_str());
        return -1;
    }

 

 

Compartilhar este post


Link para o post
Dr0p    0
Dr0p

Oi, vc eh gay e nem quer ot$ ¬¬¬

e mais uma coisa, eu tinha esse code antes de todo mundo hahaha ;**

e mais uma coisa, ta muito bom! :D

Compartilhar este post


Link para o post
Jackson Zani    1
Jackson Zani

Hehehe nem vou falar nada!

O code ta exelente :P

Só falta eu testar ele ^^

 

Abraços rapha!

Compartilhar este post


Link para o post
Raphael Carnaúba    1
Raphael Carnaúba

Código atualizado!

 

Espero que gostem smile.gif

Compartilhar este post


Link para o post
Jackson Zani    1
Jackson Zani
Código atualizado!

 

Espero que gostem smile.gif[/b]

 

Fico bem irado agora!

Ainda mais que agora tu feiz uma sendTextWindow ;D

Não precisa abrir o xml para verificar hahaha.

 

Abraços rapha!

Compartilhar este post


Link para o post
Visitante
Este tópico está impedido de receber novos posts.
Entre para seguir isso  
  • Quem Está Navegando   0 membros estão online

    Nenhum usuário registrado visualizando esta página.

×