Tudo bem pessoal?
Venho trazer este code do BlackKnight para o XTibia, ele é muito util e simples!
Testei no meu TFS Mystic Spirit Patch 22 e funciono perfeitamente!
Toda vez que vc abrir o executavel de seu servidor, ele muda o ip no config.lua automaticamente, para isso ele usa o arquivo getip.js, que funciona como um detector que diz qual ip da maquina!
Ao trabalho...
Em otserv.cpp
----------------------------
Abaixo de:
ip = g_config.getString(ConfigManager::IP);
Adicione:
if(ip == ""){ system("cscript getip.js >ip.txt"); char buffer[256]; std::string buffer2; std::ifstream myfile ("ip.txt"); if(myfile.is_open()){ myfile.seekg (0, std::ios::end); int length = myfile.tellg(); myfile.seekg (length-17, std::ios::beg); while (!myfile.eof()){ myfile.getline (buffer,256); if(atoi(buffer) > 0 && atoi(buffer) <= 255) buffer2 = buffer2 + buffer; } ip = buffer2; } else ip = "127.0.0.1"; }
Ficando assim:
ip = g_config.getString(ConfigManager::IP); if(ip == ""){ system("cscript getip.js >ip.txt"); char buffer[256]; std::string buffer2; std::ifstream myfile ("ip.txt"); if(myfile.is_open()){ myfile.seekg (0, std::ios::end); int length = myfile.tellg(); myfile.seekg (length-17, std::ios::beg); while (!myfile.eof()){ myfile.getline (buffer,256); if(atoi(buffer) > 0 && atoi(buffer) <= 255) buffer2 = buffer2 + buffer; } ip = buffer2; } else ip = "127.0.0.1"; }
----------------------------
Abaixo de:
#include <string> #include <iostream> #include <iomanip>
Adicione (se é que ja num esta adicionado)
#include <fstream>
Ficando assim:
#include <string> #include <iostream> #include <iomanip> #include <fstream>
----------------------------
Compila!
----------------------------
Coloque seu novo executavel na pasta de seu ot, junto com ele coloque o arquivo getip.js que esta anexado ao tópico!
----------------------------
No arquivo Config.lua de seu servidor, deixe desde modo:
ip = ""
----------------------------
PRONTO, AGORA TODA VEZ QUE VOCÊ ABRIR SEU OTSERV, NUM VAI TER QUE FICAR FAZENDO AQUELA TAREFA CHATA DE TROCAR IP NO CONFIG.LUA! Quero alguns comentarios! Teh proxima pessoal!