From 86cade0aa95d8ff9ebaa4f5bc9d3ea35f1ea97d8 Mon Sep 17 00:00:00 2001 From: Henrique Santiago Date: Tue, 5 Jun 2012 20:46:36 -0300 Subject: [PATCH] waiting list, u16 effects feature, protocolsend uses clientversion --- modules/client_entergame/characterlist.lua | 86 ++++++++++++++++++---- modules/client_entergame/waitinglist.otui | 44 +++++++++++ src/otclient/const.h | 1 + src/otclient/net/protocolgameparse.cpp | 6 +- src/otclient/net/protocolgamesend.cpp | 2 +- 5 files changed, 124 insertions(+), 15 deletions(-) create mode 100644 modules/client_entergame/waitinglist.otui diff --git a/modules/client_entergame/characterlist.lua b/modules/client_entergame/characterlist.lua index 2887353f..b580d837 100644 --- a/modules/client_entergame/characterlist.lua +++ b/modules/client_entergame/characterlist.lua @@ -5,21 +5,9 @@ local charactersWindow local loadBox local characterList local errorBox +local waitingWindow -- private functions -local function onCharactersWindowKeyPress(self, keyCode, keyboardModifiers) - if keyboardModifiers == KeyboardNoModifier then - if keyCode == KeyUp then - characterList:focusPreviousChild(KeyboardFocusReason) - return true - elseif keyCode == KeyDown or keyCode == KeyTab then - characterList:focusNextChild(KeyboardFocusReason) - return true - end - end - return false -end - local function tryLogin(charInfo, tries) tries = tries or 1 @@ -53,6 +41,67 @@ local function tryLogin(charInfo, tries) Settings.set('lastUsedCharacter', charInfo.characterName) end +local function updateWait() + if waitingWindow then + if waitingWindow.elapsedTime <= waitingWindow.totalTime then + local percent = (waitingWindow.elapsedTime / waitingWindow.totalTime) * 100 + local timeStr = string.format("%.0f", (waitingWindow.totalTime - waitingWindow.elapsedTime)) + + local progressBar = waitingWindow:getChildById('progressBar') + progressBar:setPercent(percent) + + local label = waitingWindow:getChildById('timeLabel') + label:setText('Trying to reconnect in ' .. timeStr .. ' seconds.') + + waitingWindow.elapsedTime = waitingWindow.elapsedTime + (waitingWindow.totalTime / 100) + scheduleEvent(updateWait, (waitingWindow.totalTime / 100) * 1000) + end + end +end + +local function resendWait() + if waitingWindow then + waitingWindow:destroy() + waitingWindow = nil + + if charactersWindow then + local selected = charactersWindow:getChildById('characterList'):getFocusedChild() + if selected then + local charInfo = { worldHost = selected.worldHost, + worldPort = selected.worldPort, + characterName = selected.characterName } + tryLogin(charInfo) + end + end + end +end + +local function onLoginWait(message, time) + waitingWindow = displayUI('waitinglist.otui') + + local label = waitingWindow:getChildById('infoLabel') + label:setText(message) + + waitingWindow.elapsedTime = 0 + waitingWindow.totalTime = time + + scheduleEvent(updateWait, 0) + scheduleEvent(resendWait, time * 1000) +end + +local function onCharactersWindowKeyPress(self, keyCode, keyboardModifiers) + if keyboardModifiers == KeyboardNoModifier then + if keyCode == KeyUp then + characterList:focusPreviousChild(KeyboardFocusReason) + return true + elseif keyCode == KeyDown or keyCode == KeyTab then + characterList:focusNextChild(KeyboardFocusReason) + return true + end + end + return false +end + function onGameLoginError(message) CharacterList.destroyLoadBox() errorBox = displayErrorBox(tr("Login Error"), message) @@ -80,6 +129,7 @@ function CharacterList.init() connect(g_game, { onLoginError = onGameLoginError }) connect(g_game, { onConnectionError = onGameConnectionError }) connect(g_game, { onGameStart = CharacterList.destroyLoadBox }) + connect(g_game, { onLoginWait = onLoginWait }) connect(g_game, { onGameEnd = CharacterList.showAgain }) if G.characters then @@ -91,6 +141,7 @@ function CharacterList.terminate() disconnect(g_game, { onLoginError = onGameLoginError }) disconnect(g_game, { onConnectionError = onGameConnectionError }) disconnect(g_game, { onGameStart = CharacterList.destroyLoadBox }) + disconnect(g_game, { onLoginWait = onLoginWait }) disconnect(g_game, { onGameEnd = CharacterList.showAgain }) characterList = nil charactersWindow:destroy() @@ -189,3 +240,12 @@ function CharacterList.destroyLoadBox() loadBox = nil end end + +function CharacterList.cancelWait() + if waitingWindow then + waitingWindow:destroy() + waitingWindow = nil + CharacterList.destroyLoadBox() + CharacterList.showAgain() + end +end diff --git a/modules/client_entergame/waitinglist.otui b/modules/client_entergame/waitinglist.otui new file mode 100644 index 00000000..185a7584 --- /dev/null +++ b/modules/client_entergame/waitinglist.otui @@ -0,0 +1,44 @@ +MainWindow + id: waitingWindow + !text: tr('Waiting List') + size: 260 160 + @onEscape: CharacterList.cancelWait() + + Label + id: infoLabel + anchors.top: parent.top + anchors.bottom: progressBar.top + anchors.left: parent.left + anchors.right: parent.right + text-wrap: true + + ProgressBar + id: progressBar + height: 15 + background-color: #4444ff + anchors.bottom: timeLabel.top + anchors.left: parent.left + anchors.right: parent.right + margin-bottom: 10 + + Label + id: timeLabel + anchors.bottom: separator.bottom + anchors.left: parent.left + anchors.right: parent.right + margin-bottom: 10 + + HorizontalSeparator + id: separator + anchors.left: parent.left + anchors.right: parent.right + anchors.bottom: next.top + margin-bottom: 10 + + Button + id: buttonCancel + !text: tr('Cancel') + width: 64 + anchors.right: parent.right + anchors.bottom: parent.bottom + @onClick: CharacterList.cancelWait() \ No newline at end of file diff --git a/src/otclient/const.h b/src/otclient/const.h index 3fe4f4ed..373db62d 100644 --- a/src/otclient/const.h +++ b/src/otclient/const.h @@ -312,6 +312,7 @@ namespace Otc GameItemAnimationPhase, GameTrucatedPingOpcode, GameReverseCreatureStack, + GameMagicEffectU16, LastGameFeature }; } diff --git a/src/otclient/net/protocolgameparse.cpp b/src/otclient/net/protocolgameparse.cpp index cd8ff487..4354f68a 100644 --- a/src/otclient/net/protocolgameparse.cpp +++ b/src/otclient/net/protocolgameparse.cpp @@ -659,7 +659,11 @@ void ProtocolGame::parseWorldLight(const InputMessagePtr& msg) void ProtocolGame::parseMagicEffect(const InputMessagePtr& msg) { Position pos = getPosition(msg); - int effectId = msg->getU8(); + int effectId; + if(g_game.getFeature(Otc::GameMagicEffectU16)) + effectId = msg->getU16(); + else + effectId = msg->getU8(); EffectPtr effect = EffectPtr(new Effect()); effect->setId(effectId); diff --git a/src/otclient/net/protocolgamesend.cpp b/src/otclient/net/protocolgamesend.cpp index b1e2efc6..dcc1324e 100644 --- a/src/otclient/net/protocolgamesend.cpp +++ b/src/otclient/net/protocolgamesend.cpp @@ -50,7 +50,7 @@ void ProtocolGame::sendLoginPacket(uint challangeTimestamp, uint8 challangeRando msg->addU8(Proto::ClientEnterGame); msg->addU16(Proto::ClientOs); - msg->addU16(Proto::ClientVersion); + msg->addU16(g_game.getClientVersion()); int paddingBytes = 128; msg->addU8(0); // first RSA byte must be 0