extended opcode disabled by default. current locale is sent to server on login, bot protection exception
This commit is contained in:
parent
6162d51958
commit
4f90783789
|
@ -7,7 +7,7 @@ local callbacks = {}
|
|||
local function onExtendedOpcode(protocol, opcode, buffer)
|
||||
local callback = callbacks[opcode]
|
||||
if callback then
|
||||
callback(opcode, buffer)
|
||||
callback(protocol, opcode, buffer)
|
||||
end
|
||||
end
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
Module
|
||||
name: gamelib_extended
|
||||
description: Manage client extended messages
|
||||
name: client_extended
|
||||
description: Manage client extended messages callbacks
|
||||
author: baxnie
|
||||
website: www.otclient.info
|
||||
|
|
@ -10,11 +10,34 @@ local currentLocale
|
|||
local localeComboBox
|
||||
|
||||
-- private functions
|
||||
local function sendLocale(localeName)
|
||||
local protocolGame = g_game.getProtocolGame()
|
||||
if protocolGame then
|
||||
protocolGame:sendExtendedOpcode(0, localeName)
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
local function onLocaleComboBoxOptionChange(self, optionText, optionData)
|
||||
Locales.setLocale(optionData)
|
||||
if Locales.setLocale(optionData) then
|
||||
Settings.set('locale', optionData)
|
||||
sendLocale(currentLocale.name)
|
||||
reloadModules()
|
||||
end
|
||||
end
|
||||
|
||||
-- hooked functions
|
||||
local function onGameStart()
|
||||
sendLocale(currentLocale.name)
|
||||
end
|
||||
|
||||
local function onServerSetLocale(protocol, opcode, buffer)
|
||||
local locale = installedLocales[buffer]
|
||||
if locale then
|
||||
localeComboBox:setCurrentOption(locale.languageName)
|
||||
end
|
||||
end
|
||||
|
||||
-- public functions
|
||||
function Locales.init()
|
||||
|
@ -24,9 +47,9 @@ function Locales.init()
|
|||
|
||||
local userLocaleName = Settings.get('locale')
|
||||
if userLocaleName and Locales.setLocale(userLocaleName)then
|
||||
print('Using configured locale: ' .. userLocaleName)
|
||||
info('Using configured locale: ' .. userLocaleName)
|
||||
else
|
||||
print('Using default locale: ' .. defaultLocaleName)
|
||||
info('Using default locale: ' .. defaultLocaleName)
|
||||
Locales.setLocale(defaultLocaleName)
|
||||
Settings.set('locale', defaultLocaleName)
|
||||
end
|
||||
|
@ -39,12 +62,17 @@ function Locales.init()
|
|||
localeComboBox:setCurrentOption(currentLocale.languageName)
|
||||
localeComboBox.onOptionChange = onLocaleComboBoxOptionChange
|
||||
end, false)
|
||||
|
||||
Extended.register(0, onServerSetLocale)
|
||||
connect(g_game, { onGameStart = onGameStart })
|
||||
end
|
||||
|
||||
function Locales.terminate()
|
||||
installedLocales = nil
|
||||
currentLocale = nil
|
||||
localeComboBox = nil
|
||||
Extended.unregister(0)
|
||||
disconnect(g_game, { onGameStart = onGameStart })
|
||||
end
|
||||
|
||||
function Locales.installLocale(locale)
|
||||
|
|
|
@ -5,6 +5,7 @@ Module
|
|||
website: www.otclient.info
|
||||
|
||||
dependencies:
|
||||
- client_extended
|
||||
- client_topmenu
|
||||
|
||||
@onLoad: |
|
||||
|
|
|
@ -5,7 +5,7 @@ Module
|
|||
website: www.otclient.info
|
||||
|
||||
dependencies:
|
||||
- gamelib_extended
|
||||
- client_extended
|
||||
- game_tibiafiles
|
||||
- client_background
|
||||
//- game_shaders
|
||||
|
|
|
@ -5,6 +5,7 @@ ENDIF(${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 6)
|
|||
|
||||
# otclient options
|
||||
OPTION(BOT_PROTECTION "Enable bot protection" ON)
|
||||
OPTION(EXTENDED_OPCODE "Enable extended opcode" OFF)
|
||||
SET(PROTOCOL 860 CACHE "Protocol version" STRING)
|
||||
OPTION(CIPSOFT_RSA "Use cipsoft RSA to login into original tibia" OFF)
|
||||
ADD_DEFINITIONS(-DPROTOCOL=${PROTOCOL})
|
||||
|
@ -24,6 +25,13 @@ ELSE(BOT_PROTECTION)
|
|||
MESSAGE(STATUS "Bot protection: OFF")
|
||||
ENDIF(BOT_PROTECTION)
|
||||
|
||||
IF(EXTENDED_OPCODE)
|
||||
ADD_DEFINITIONS(-DEXTENDED_OPCODE)
|
||||
MESSAGE(STATUS "Extended opcode: ON")
|
||||
ELSE(EXTENDED_OPCODE)
|
||||
MESSAGE(STATUS "Extended opcode: OFF")
|
||||
ENDIF(EXTENDED_OPCODE)
|
||||
|
||||
SET(otclient_SOURCES ${otclient_SOURCES}
|
||||
# otclient
|
||||
${CMAKE_CURRENT_LIST_DIR}/otclient.cpp
|
||||
|
|
|
@ -42,6 +42,11 @@ Game::Game()
|
|||
|
||||
void Game::resetGameStates()
|
||||
{
|
||||
#ifdef BOT_PROTECTION
|
||||
m_denyBotCall = true;
|
||||
#else
|
||||
m_denyBotCall = false;
|
||||
#endif
|
||||
m_dead = false;
|
||||
m_serverBeat = 50;
|
||||
m_canReportBugs = false;
|
||||
|
@ -114,8 +119,10 @@ void Game::processGameStart(const LocalPlayerPtr& localPlayer, int serverBeat, b
|
|||
// synchronize fight modes with the server
|
||||
m_protocolGame->sendChangeFightModes(m_fightMode, m_chaseMode, m_safeFight);
|
||||
|
||||
// NOTE: the entire map description and local player information is not known yet
|
||||
// NOTE: the entire map description and local player information is not known yet (bot call is allowed here)
|
||||
enableBotCall();
|
||||
g_lua.callGlobalField("g_game", "onGameStart");
|
||||
disableBotCall();
|
||||
}
|
||||
|
||||
void Game::processGameEnd()
|
||||
|
@ -991,14 +998,12 @@ void Game::mount(bool mount)
|
|||
|
||||
bool Game::checkBotProtection()
|
||||
{
|
||||
#ifdef BOT_PROTECTION
|
||||
// accepts calls comming from a stacktrace containing only C++ functions,
|
||||
// if the stacktrace contains a lua function, then only accept if the engine is processing an input event
|
||||
if(g_lua.isInCppCallback() && !g_app->isOnInputEvent()) {
|
||||
if(g_lua.isInCppCallback() && !g_app->isOnInputEvent() && m_denyBotCall) {
|
||||
logError(g_lua.traceback("caught a lua call to a bot protected game function, the call was canceled"));
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -232,6 +232,8 @@ public:
|
|||
bool canPerformGameAction();
|
||||
bool canReportBugs() { return m_canReportBugs; }
|
||||
bool checkBotProtection();
|
||||
void enableBotCall() { m_denyBotCall = false; }
|
||||
void disableBotCall() { m_denyBotCall = true; }
|
||||
|
||||
bool isOnline() { return !!m_localPlayer; }
|
||||
bool isDead() { return m_dead; }
|
||||
|
@ -261,6 +263,7 @@ private:
|
|||
std::map<int, ContainerPtr> m_containers;
|
||||
std::map<int, Vip> m_vips;
|
||||
|
||||
bool m_denyBotCall;
|
||||
bool m_dead;
|
||||
int m_serverBeat;
|
||||
Otc::FightModes m_fightMode;
|
||||
|
|
|
@ -1212,11 +1212,13 @@ void ProtocolGame::parseExtendedOpcode(const InputMessagePtr& msg)
|
|||
int opcode = msg->getU8();
|
||||
std::string buffer = msg->getString();
|
||||
|
||||
#ifdef EXTENDED_OPCODE
|
||||
try {
|
||||
callLuaField("onExtendedOpcode", opcode, buffer);
|
||||
} catch(Exception& e) {
|
||||
logError("Network exception in extended opcode ", opcode, ": ", e.what());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void ProtocolGame::setMapDescription(const InputMessagePtr& msg, int x, int y, int z, int width, int height)
|
||||
|
|
|
@ -33,11 +33,13 @@ void ProtocolGame::safeSend(const OutputMessagePtr& outputMessage)
|
|||
|
||||
void ProtocolGame::sendExtendedOpcode(uint8 opcode, const std::string& buffer)
|
||||
{
|
||||
#ifdef EXTENDED_OPCODE
|
||||
OutputMessagePtr msg(new OutputMessage);
|
||||
msg->addU8(Proto::ClientExtendedOpcode);
|
||||
msg->addU8(opcode);
|
||||
msg->addString(buffer);
|
||||
safeSend(msg);
|
||||
#endif
|
||||
}
|
||||
|
||||
void ProtocolGame::sendLoginPacket(uint challangeTimestamp, uint8 challangeRandom)
|
||||
|
|
Loading…
Reference in New Issue