Postado Fevereiro 28, 2024 2 anos O propósito é criar uma nova função em creaturescripts que será acionada toda vez que um novo report (CTRL + R) for aberto. Eu implementei para enviar uma notificação no grupo do Telegram, contendo os dados do report. Isso garantirá que os GMs tenham acesso aos reports dos jogadores mesmo quando não estiverem logados, e também evitará que algum report seja perdido caso o jogador saia do servidor. A parte do Telegram é apenas um exemplo. Você pode ajustar o script para executar outras ações desejadas. creatureevent.cpp: Dentro deste arquivo, localize a função: uint32_t CreatureEvent::executeChannelLeave(Player* player, uint16_t channelId, UsersMap usersMap) abaixo dela, adicione: uint32_t CreatureEvent::executeOpenRuleViolation(Player* player, std::string message) { if (!m_interface->reserveEnv()) { std::clog << "[Error - CreatureEvent::executeOpenRuleViolation] Call stack overflow." << std::endl; return 0; } ScriptEnviroment* env = m_interface->getEnv(); env->setScriptId(m_scriptId, m_interface); lua_State* L = m_interface->getState(); m_interface->pushFunction(m_scriptId); lua_pushnumber(L, env->addThing(player)); lua_pushstring(L, message.c_str()); bool result = m_interface->callFunction(2); m_interface->releaseEnv(); return result; } Após, procure por: std::string CreatureEvent::getScriptEventName() const abaixo de: case CREATURE_EVENT_CHANNEL_LEAVE: return "onLeaveChannel"; adicione: case CREATURE_EVENT_OPEN_RULE_VIOLATION: return "onOpenRuleViolation"; Agora, procure por: std::string CreatureEvent::getScriptEventParams() const abaixo de: case CREATURE_EVENT_CHANNEL_LEAVE: return "cid, channel, users"; adicione: case CREATURE_EVENT_OPEN_RULE_VIOLATION: return "cid, message"; Procure por: bool CreatureEvent::configureEvent(xmlNodePtr p) abaixo de: else if(tmpStr == "leavechannel") m_type = CREATURE_EVENT_CHANNEL_LEAVE; adicione: else if(tmpStr == "openruleviolation") m_type = CREATURE_EVENT_OPEN_RULE_VIOLATION; creatureevent.h: Dentro deste arquivo, localize: enum CreatureEventType_t adicione "CREATURE_EVENT_OPEN_RULE_VIOLATION" como o último item de enum CreatureEventType_t Exemplo: enum CreatureEventType_t { // ... CREATURE_EVENT_OPEN_RULE_VIOLATION }; Agora, procure por: uint32_t executeChannelLeave(Player* player, uint16_t channelId, UsersMap usersMap); abaixo dela, adicione: uint32_t executeOpenRuleViolation(Player* player, std::string message); game.cpp: Dentro deste arquivo, localize: bool Game::playerReportRuleViolation(Player* player, const std::string& text) e substitua por: bool Game::playerReportRuleViolation(Player* player, const std::string& text) { //Do not allow reports on multiclones worlds since reports are name-based if(g_config.getNumber(ConfigManager::ALLOW_CLONES)) { player->sendTextMessage(MSG_INFO_DESCR, "Rule violation reports are disabled."); return false; } cancelRuleViolation(player); boost::shared_ptr<RuleViolation> rvr(new RuleViolation(player, text, time(NULL))); ruleViolations[player->getID()] = rvr; ChatChannel* channel = g_chat.getChannelById(CHANNEL_RVR); if(!channel) return false; for(UsersMap::const_iterator it = channel->getUsers().begin(); it != channel->getUsers().end(); ++it) it->second->sendToChannel(player, SPEAK_RVR_CHANNEL, text, CHANNEL_RVR, rvr->time); CreatureEventList joinEvents = player->getCreatureEvents(CREATURE_EVENT_OPEN_RULE_VIOLATION); for(CreatureEventList::iterator it = joinEvents.begin(); it != joinEvents.end(); ++it) (*it)->executeOpenRuleViolation(player, text); return true; } Agora é só compilar a source. depois em "data > creaturescripts > creaturescripts.xml", adicione: <event type="login" name="loginNotifyRuleViolation" script="notifyRuleViolation.lua"/> <event type="openruleviolation" name="openNotifyRuleViolation" script="notifyRuleViolation.lua"/> em "data > creaturescripts > scripts", crie um arquivo notifyRuleViolation.lua e adicione: function onOpenRuleViolation(cid, message) local config = { token = "", -- Token do seu BOT no Telegram chatId = "" -- ID do chat do Telegram que será enviado a notificação. } local message = "Player: "..getCreatureName(cid).."\n\nReport:\n"..message.."" message = string.gsub(message, "\n", "%%0A") local url = "https://api.telegram.org/bot"..config.token.."/sendMessage" local data = "chat_id="..config.chatId.."&text="..message.."" local curl = io.popen('curl -d "'..data..'" "'..url..'"'):read("*a") return true end function onLogin(cid) registerCreatureEvent(cid, "openNotifyRuleViolation") return true end Demonstração: 1. Jogador abre um novo report (CTRL + R) 2. notifyRuleViolation.lua, definido em creaturescripts.xml, é acionado para enviar uma notificação ao grupo do Telegram.
Postado Fevereiro 29, 2024 2 anos Top no final pra deixar melhorzinha explicado function onOpenRuleViolation(cid, message) -- Configuração do Telegram local config = { token = "", -- Token do seu BOT no Telegram chatId = "" -- ID do chat do Telegram que receberá a notificação. } -- Construção da mensagem com o nome do jogador e o relatório local playerName = getCreatureName(cid) local formattedMessage = "Player: " .. playerName .. "\n\nReport:\n" .. message -- Substitui quebras de linha por '%0A' para o formato adequado na URL formattedMessage = string.gsub(formattedMessage, "\n", "%%0A") -- Construção da URL de requisição para o Telegram local apiUrl = "https://api.telegram.org/bot" .. config.token .. "/sendMessage" local requestData = "chat_id=" .. config.chatId .. "&text=" .. formattedMessage -- Execução da requisição usando o comando 'curl' local curlCommand = io.popen('curl -d "' .. requestData .. '" "' .. apiUrl .. '"'):read("*a") return true end function onLogin(cid) -- Registro do evento para notificação de violação de regra registerCreatureEvent(cid, "openNotifyRuleViolation") return true end Eu sou um entusiasta da programação apaixonado por ajudar a comunidade open source a crescer. Sempre em busca de novos desafios e oportunidades para contribuir com meu código. #OpenSource #Programação #Contribuição
Postado Março 1, 2024 2 anos 1 hora atrás, Mateus Robeerto disse: Bem interessante, mas é possível para o TFS 1.x? sim, teria que mudar umas coisas Eu sou um entusiasta da programação apaixonado por ajudar a comunidade open source a crescer. Sempre em busca de novos desafios e oportunidades para contribuir com meu código. #OpenSource #Programação #Contribuição
Participe da conversa
Você pode postar agora e se cadastrar mais tarde. Se você tem uma conta, faça o login para postar com sua conta.