extended opcode disabled by default. current locale is sent to server on login, bot protection exception

This commit is contained in:
Henrique Santiago 2012-05-16 17:09:37 -03:00
parent 6162d51958
commit 4f90783789
10 changed files with 62 additions and 13 deletions

View File

@ -7,7 +7,7 @@ local callbacks = {}
local function onExtendedOpcode(protocol, opcode, buffer) local function onExtendedOpcode(protocol, opcode, buffer)
local callback = callbacks[opcode] local callback = callbacks[opcode]
if callback then if callback then
callback(opcode, buffer) callback(protocol, opcode, buffer)
end end
end end

View File

@ -1,6 +1,6 @@
Module Module
name: gamelib_extended name: client_extended
description: Manage client extended messages description: Manage client extended messages callbacks
author: baxnie author: baxnie
website: www.otclient.info website: www.otclient.info

View File

@ -10,10 +10,33 @@ local currentLocale
local localeComboBox local localeComboBox
-- private functions -- 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) local function onLocaleComboBoxOptionChange(self, optionText, optionData)
Locales.setLocale(optionData) if Locales.setLocale(optionData) then
Settings.set('locale', optionData) Settings.set('locale', optionData)
reloadModules() 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 end
-- public functions -- public functions
@ -24,9 +47,9 @@ function Locales.init()
local userLocaleName = Settings.get('locale') local userLocaleName = Settings.get('locale')
if userLocaleName and Locales.setLocale(userLocaleName)then if userLocaleName and Locales.setLocale(userLocaleName)then
print('Using configured locale: ' .. userLocaleName) info('Using configured locale: ' .. userLocaleName)
else else
print('Using default locale: ' .. defaultLocaleName) info('Using default locale: ' .. defaultLocaleName)
Locales.setLocale(defaultLocaleName) Locales.setLocale(defaultLocaleName)
Settings.set('locale', defaultLocaleName) Settings.set('locale', defaultLocaleName)
end end
@ -39,12 +62,17 @@ function Locales.init()
localeComboBox:setCurrentOption(currentLocale.languageName) localeComboBox:setCurrentOption(currentLocale.languageName)
localeComboBox.onOptionChange = onLocaleComboBoxOptionChange localeComboBox.onOptionChange = onLocaleComboBoxOptionChange
end, false) end, false)
Extended.register(0, onServerSetLocale)
connect(g_game, { onGameStart = onGameStart })
end end
function Locales.terminate() function Locales.terminate()
installedLocales = nil installedLocales = nil
currentLocale = nil currentLocale = nil
localeComboBox = nil localeComboBox = nil
Extended.unregister(0)
disconnect(g_game, { onGameStart = onGameStart })
end end
function Locales.installLocale(locale) function Locales.installLocale(locale)

View File

@ -5,6 +5,7 @@ Module
website: www.otclient.info website: www.otclient.info
dependencies: dependencies:
- client_extended
- client_topmenu - client_topmenu
@onLoad: | @onLoad: |

View File

@ -5,7 +5,7 @@ Module
website: www.otclient.info website: www.otclient.info
dependencies: dependencies:
- gamelib_extended - client_extended
- game_tibiafiles - game_tibiafiles
- client_background - client_background
//- game_shaders //- game_shaders

View File

@ -5,6 +5,7 @@ ENDIF(${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 6)
# otclient options # otclient options
OPTION(BOT_PROTECTION "Enable bot protection" ON) OPTION(BOT_PROTECTION "Enable bot protection" ON)
OPTION(EXTENDED_OPCODE "Enable extended opcode" OFF)
SET(PROTOCOL 860 CACHE "Protocol version" STRING) SET(PROTOCOL 860 CACHE "Protocol version" STRING)
OPTION(CIPSOFT_RSA "Use cipsoft RSA to login into original tibia" OFF) OPTION(CIPSOFT_RSA "Use cipsoft RSA to login into original tibia" OFF)
ADD_DEFINITIONS(-DPROTOCOL=${PROTOCOL}) ADD_DEFINITIONS(-DPROTOCOL=${PROTOCOL})
@ -24,6 +25,13 @@ ELSE(BOT_PROTECTION)
MESSAGE(STATUS "Bot protection: OFF") MESSAGE(STATUS "Bot protection: OFF")
ENDIF(BOT_PROTECTION) 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} SET(otclient_SOURCES ${otclient_SOURCES}
# otclient # otclient
${CMAKE_CURRENT_LIST_DIR}/otclient.cpp ${CMAKE_CURRENT_LIST_DIR}/otclient.cpp

View File

@ -42,6 +42,11 @@ Game::Game()
void Game::resetGameStates() void Game::resetGameStates()
{ {
#ifdef BOT_PROTECTION
m_denyBotCall = true;
#else
m_denyBotCall = false;
#endif
m_dead = false; m_dead = false;
m_serverBeat = 50; m_serverBeat = 50;
m_canReportBugs = false; m_canReportBugs = false;
@ -114,8 +119,10 @@ void Game::processGameStart(const LocalPlayerPtr& localPlayer, int serverBeat, b
// synchronize fight modes with the server // synchronize fight modes with the server
m_protocolGame->sendChangeFightModes(m_fightMode, m_chaseMode, m_safeFight); 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"); g_lua.callGlobalField("g_game", "onGameStart");
disableBotCall();
} }
void Game::processGameEnd() void Game::processGameEnd()
@ -991,14 +998,12 @@ void Game::mount(bool mount)
bool Game::checkBotProtection() bool Game::checkBotProtection()
{ {
#ifdef BOT_PROTECTION
// accepts calls comming from a stacktrace containing only C++ functions, // 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 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")); logError(g_lua.traceback("caught a lua call to a bot protected game function, the call was canceled"));
return false; return false;
} }
#endif
return true; return true;
} }

View File

@ -232,6 +232,8 @@ public:
bool canPerformGameAction(); bool canPerformGameAction();
bool canReportBugs() { return m_canReportBugs; } bool canReportBugs() { return m_canReportBugs; }
bool checkBotProtection(); bool checkBotProtection();
void enableBotCall() { m_denyBotCall = false; }
void disableBotCall() { m_denyBotCall = true; }
bool isOnline() { return !!m_localPlayer; } bool isOnline() { return !!m_localPlayer; }
bool isDead() { return m_dead; } bool isDead() { return m_dead; }
@ -261,6 +263,7 @@ private:
std::map<int, ContainerPtr> m_containers; std::map<int, ContainerPtr> m_containers;
std::map<int, Vip> m_vips; std::map<int, Vip> m_vips;
bool m_denyBotCall;
bool m_dead; bool m_dead;
int m_serverBeat; int m_serverBeat;
Otc::FightModes m_fightMode; Otc::FightModes m_fightMode;

View File

@ -1212,11 +1212,13 @@ void ProtocolGame::parseExtendedOpcode(const InputMessagePtr& msg)
int opcode = msg->getU8(); int opcode = msg->getU8();
std::string buffer = msg->getString(); std::string buffer = msg->getString();
#ifdef EXTENDED_OPCODE
try { try {
callLuaField("onExtendedOpcode", opcode, buffer); callLuaField("onExtendedOpcode", opcode, buffer);
} catch(Exception& e) { } catch(Exception& e) {
logError("Network exception in extended opcode ", opcode, ": ", e.what()); 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) void ProtocolGame::setMapDescription(const InputMessagePtr& msg, int x, int y, int z, int width, int height)

View File

@ -33,11 +33,13 @@ void ProtocolGame::safeSend(const OutputMessagePtr& outputMessage)
void ProtocolGame::sendExtendedOpcode(uint8 opcode, const std::string& buffer) void ProtocolGame::sendExtendedOpcode(uint8 opcode, const std::string& buffer)
{ {
#ifdef EXTENDED_OPCODE
OutputMessagePtr msg(new OutputMessage); OutputMessagePtr msg(new OutputMessage);
msg->addU8(Proto::ClientExtendedOpcode); msg->addU8(Proto::ClientExtendedOpcode);
msg->addU8(opcode); msg->addU8(opcode);
msg->addString(buffer); msg->addString(buffer);
safeSend(msg); safeSend(msg);
#endif
} }
void ProtocolGame::sendLoginPacket(uint challangeTimestamp, uint8 challangeRandom) void ProtocolGame::sendLoginPacket(uint challangeTimestamp, uint8 challangeRandom)