Merge branch 'master' of https://github.com/edubart/otclient into mobile_port

This commit is contained in:
Túlio Henrique 2015-08-13 10:05:00 -03:00
commit 01992aae7e
12 changed files with 337 additions and 50 deletions

View File

@ -19,7 +19,7 @@ function AddServer.add()
local added, error = ServerList.add(host, port, protocol)
if not added then
displayErrorBox(tr('Add Error'), tr(error))
displayErrorBox(tr('Error'), tr(error))
else
AddServer.hide()
end

View File

@ -12,7 +12,9 @@ function ServerList.init()
serverTextList = serverListWindow:getChildById('serverList')
servers = g_settings.getNode('ServerList') or {}
ServerList.load()
if servers then
ServerList.load()
end
end
function ServerList.terminate()
@ -24,8 +26,8 @@ function ServerList.terminate()
end
function ServerList.load()
for k,server in pairs(servers) do
ServerList.add(k, server.port, server.protocol, true)
for host, server in pairs(servers) do
ServerList.add(host, server.port, server.protocol, true)
end
end
@ -43,7 +45,9 @@ function ServerList.select()
end
function ServerList.add(host, port, protocol, load)
if not load and servers[host] then
if not host or not port or not protocol then
return false, 'Failed to load settings'
elseif not load and servers[host] then
return false, 'Server already exists'
elseif host == '' or port == '' then
return false, 'Required fields are missing'

View File

@ -38,6 +38,7 @@ SpeakTypes = {
[MessageModes.RVRChannel] = SpeakTypesSettings.channelWhite,
[MessageModes.RVRContinue] = SpeakTypesSettings.rvrContinue,
[MessageModes.RVRAnswer] = SpeakTypesSettings.rvrAnswerFrom,
[MessageModes.NpcFromStartBlock] = SpeakTypesSettings.privateNpcToPlayer,
-- ignored types
[MessageModes.Spell] = SpeakTypesSettings.none,
@ -1020,21 +1021,21 @@ function onTalk(name, level, mode, message, channelId, creaturePos)
if (mode == MessageModes.Say or mode == MessageModes.Whisper or mode == MessageModes.Yell or
mode == MessageModes.Spell or mode == MessageModes.MonsterSay or mode == MessageModes.MonsterYell or
mode == MessageModes.NpcFrom or mode == MessageModes.BarkLow or mode == MessageModes.BarkLoud) and
creaturePos then
-- Remove curly braces from screen message
local staticMessage = message
if mode == MessageModes.NpcFrom then
local highlightData = getHighlightedText(staticMessage)
if #highlightData > 0 then
for i = 1, #highlightData / 3 do
local dataBlock = { _start = highlightData[(i-1)*3+1], _end = highlightData[(i-1)*3+2], words = highlightData[(i-1)*3+3] }
staticMessage = staticMessage:gsub("{"..dataBlock.words.."}", dataBlock.words)
end
mode == MessageModes.NpcFrom or mode == MessageModes.BarkLow or mode == MessageModes.BarkLoud or
mode == MessageModes.NpcFromStartBlock) and creaturePos then
local staticText = StaticText.create()
-- Remove curly braces from screen message
local staticMessage = message
if mode == MessageModes.NpcFrom or mode == MessageModes.NpcFromStartBlock then
local highlightData = getHighlightedText(staticMessage)
if #highlightData > 0 then
for i = 1, #highlightData / 3 do
local dataBlock = { _start = highlightData[(i-1)*3+1], _end = highlightData[(i-1)*3+2], words = highlightData[(i-1)*3+3] }
staticMessage = staticMessage:gsub("{"..dataBlock.words.."}", dataBlock.words)
end
end
local staticText = StaticText.create()
staticText:setColor(speaktype.color)
end
staticText:addMessage(name, mode, staticMessage)
g_map.addThing(staticText, creaturePos, -1)
end

View File

@ -27,6 +27,15 @@ function init()
onLoginAdvice = onLoginAdvice,
}, true)
-- Call load AFTER game window has been created and
-- resized to a stable state, otherwise the saved
-- settings can get overridden by false onGeometryChange
-- events
connect(g_app, {
onRun = load,
onExit = save
})
gameRootPanel = g_ui.displayUI('gameinterface')
gameRootPanel:hide()
gameRootPanel:lower()
@ -49,7 +58,6 @@ function init()
setupViewMode(0)
bindKeys()
load()
if g_game.isOnline() then
show()
@ -102,7 +110,6 @@ function unbindWalkKey(key)
end
function terminate()
save()
hide()
hookedMenuOptions = {}

View File

@ -38,6 +38,7 @@ currentOffersPanel = nil
offerHistoryPanel = nil
itemsPanel = nil
selectedOffer = {}
selectedMyOffer = {}
nameLabel = nil
feeLabel = nil
@ -64,6 +65,11 @@ detailsTable = nil
buyStatsTable = nil
sellStatsTable = nil
buyCancelButton = nil
sellCancelButton = nil
buyMyOfferTable = nil
sellMyOfferTable = nil
offerExhaust = {}
marketOffers = {}
marketItems = {}
@ -134,6 +140,13 @@ local function clearOffers()
sellOfferTable:clearData()
end
local function clearMyOffers()
marketOffers[MarketAction.Buy] = {}
marketOffers[MarketAction.Sell] = {}
buyMyOfferTable:clearData()
sellMyOfferTable:clearData()
end
local function clearFilters()
for _, filter in pairs(filterButtons) do
if filter and filter:isChecked() ~= filter.default then
@ -167,25 +180,38 @@ local function addOffer(offer, offerType)
local amount = offer:getAmount()
local price = offer:getPrice()
local timestamp = offer:getTimeStamp()
local itemName = offer:getItem():getMarketData().name
buyOfferTable:toggleSorting(false)
sellOfferTable:toggleSorting(false)
buyMyOfferTable:toggleSorting(false)
sellMyOfferTable:toggleSorting(false)
if amount < 1 then return false end
if offerType == MarketAction.Buy then
local data = {
{text = player},
{text = amount},
{text = price*amount},
{text = price},
{text = string.gsub(os.date('%c', timestamp), " ", " ")}
}
if offer.warn then
buyOfferTable:setColumnStyle('OfferTableWarningColumn', true)
end
local row = buyOfferTable:addRow(data)
local row = nil
if offer.var == MarketRequest.MyOffers then
row = buyMyOfferTable:addRow({
{text = itemName},
{text = price*amount},
{text = price},
{text = amount},
{text = string.gsub(os.date('%c', timestamp), " ", " "), sortvalue = timestamp}
})
else
row = buyOfferTable:addRow({
{text = player},
{text = amount},
{text = price*amount},
{text = price},
{text = string.gsub(os.date('%c', timestamp), " ", " ")}
})
end
row.ref = id
if offer.warn then
@ -193,19 +219,28 @@ local function addOffer(offer, offerType)
buyOfferTable:setColumnStyle('OfferTableColumn', true)
end
else
local data = {
{text = player},
{text = amount},
{text = price*amount},
{text = price},
{text = string.gsub(os.date('%c', timestamp), " ", " "), sortvalue = timestamp}
}
if offer.warn then
sellOfferTable:setColumnStyle('OfferTableWarningColumn', true)
end
local row = sellOfferTable:addRow(data)
local row = nil
if offer.var == MarketRequest.MyOffers then
row = sellMyOfferTable:addRow({
{text = itemName},
{text = price*amount},
{text = price},
{text = amount},
{text = string.gsub(os.date('%c', timestamp), " ", " "), sortvalue = timestamp}
})
else
row = sellOfferTable:addRow({
{text = player},
{text = amount},
{text = price*amount},
{text = price},
{text = string.gsub(os.date('%c', timestamp), " ", " "), sortvalue = timestamp}
})
end
row.ref = id
if offer.warn then
@ -219,6 +254,11 @@ local function addOffer(offer, offerType)
buyOfferTable:sort()
sellOfferTable:sort()
buyMyOfferTable:toggleSorting(false)
sellMyOfferTable:toggleSorting(false)
buyMyOfferTable:sort()
sellMyOfferTable:sort()
return true
end
@ -277,6 +317,9 @@ local function updateOffers(offers)
selectedOffer[MarketAction.Buy] = nil
selectedOffer[MarketAction.Sell] = nil
selectedMyOffer[MarketAction.Buy] = nil
selectedMyOffer[MarketAction.Sell] = nil
-- clear existing offer data
buyOfferTable:clearData()
buyOfferTable:setSorting(4, TABLE_SORTING_DESC)
@ -286,6 +329,9 @@ local function updateOffers(offers)
sellButton:setEnabled(false)
buyButton:setEnabled(false)
buyCancelButton:setEnabled(false)
sellCancelButton:setEnabled(false)
for _, offer in pairs(offers) do
mergeOffer(offer)
end
@ -438,6 +484,12 @@ local function destroyAmountWindow()
end
end
local function cancelMyOffer(actionType)
local offer = selectedMyOffer[actionType]
MarketProtocol.sendMarketCancelOffer(offer:getTimeStamp(), offer:getCounter())
Market.refreshMyOffers()
end
local function openAmountWindow(callback, actionType, actionText)
if not Market.isOfferSelected(actionType) then
return
@ -546,6 +598,24 @@ local function onSelectBuyOffer(table, selectedRow, previousSelectedRow)
end
end
local function onSelectMyBuyOffer(table, selectedRow, previousSelectedRow)
for _, offer in pairs(marketOffers[MarketAction.Buy]) do
if offer:isEqual(selectedRow.ref) then
selectedMyOffer[MarketAction.Buy] = offer
buyCancelButton:setEnabled(true)
end
end
end
local function onSelectMySellOffer(table, selectedRow, previousSelectedRow)
for _, offer in pairs(marketOffers[MarketAction.Sell]) do
if offer:isEqual(selectedRow.ref) then
selectedMyOffer[MarketAction.Sell] = offer
sellCancelButton:setEnabled(true)
end
end
end
local function onChangeCategory(combobox, option)
local id = getMarketCategoryId(option)
if id == MarketCategory.MetaWeapons then
@ -787,12 +857,28 @@ local function initInterface()
buyOfferTable.onSelectionChange = onSelectBuyOffer
sellOfferTable.onSelectionChange = onSelectSellOffer
-- setup my offers
buyMyOfferTable = currentOffersPanel:recursiveGetChildById('myBuyingTable')
sellMyOfferTable = currentOffersPanel:recursiveGetChildById('mySellingTable')
buyMyOfferTable.onSelectionChange = onSelectMyBuyOffer
sellMyOfferTable.onSelectionChange = onSelectMySellOffer
buyCancelButton = currentOffersPanel:getChildById('buyCancelButton')
buyCancelButton.onClick = function() cancelMyOffer(MarketAction.Buy) end
sellCancelButton = currentOffersPanel:getChildById('sellCancelButton')
sellCancelButton.onClick = function() cancelMyOffer(MarketAction.Sell) end
buyStatsTable:setColumnWidth({120, 270})
sellStatsTable:setColumnWidth({120, 270})
detailsTable:setColumnWidth({80, 330})
buyOfferTable:setSorting(4, TABLE_SORTING_DESC)
sellOfferTable:setSorting(4, TABLE_SORTING_ASC)
buyMyOfferTable:setSorting(3, TABLE_SORTING_DESC)
sellMyOfferTable:setSorting(3, TABLE_SORTING_DESC)
end
function init()
@ -836,6 +922,7 @@ function Market.reset()
categoryList:setCurrentOption(getMarketCategoryName(MarketCategory.First))
searchEdit:setText('')
clearFilters()
clearMyOffers()
if not table.empty(information) then
Market.updateCurrentItems()
end
@ -903,8 +990,8 @@ function Market.close(notify)
if not marketWindow:isHidden() then
marketWindow:hide()
marketWindow:unlock()
Market.clearSelectedItem(
) Market.reset()
Market.clearSelectedItem()
Market.reset()
if notify then
MarketProtocol.sendMarketLeave()
end
@ -990,9 +1077,16 @@ end
function Market.refreshOffers()
if Market.isItemSelected() then
Market.onItemBoxChecked(selectedItem.ref)
else
Market.refreshMyOffers()
end
end
function Market.refreshMyOffers()
clearMyOffers()
MarketProtocol.sendMarketBrowseMyOffers()
end
function Market.loadMarketItems(category)
clearItems()

View File

@ -4,7 +4,7 @@ MarketOffer.__index = MarketOffer
local OFFER_TIMESTAMP = 1
local OFFER_COUNTER = 2
MarketOffer.new = function(offerId, t, item, amount, price, playerName, state)
MarketOffer.new = function(offerId, t, item, amount, price, playerName, state, var)
local offer = {
id = {},
type = nil,
@ -12,7 +12,8 @@ MarketOffer.new = function(offerId, t, item, amount, price, playerName, state)
amount = 0,
price = 0,
player = '',
state = 0
state = 0,
var = nil
}
if not offerId or type(offerId) ~= 'table' then
@ -41,6 +42,7 @@ MarketOffer.new = function(offerId, t, item, amount, price, playerName, state)
g_logger.error('MarketOffer.new - invalid state provided.')
end
offer.state = state
offer.var = var
setmetatable(offer, MarketOffer)
return offer
@ -153,4 +155,4 @@ function MarketOffer:getCounter()
return
end
return self.id[OFFER_COUNTER]
end
end

View File

@ -29,11 +29,12 @@ local function readMarketOffer(msg, action, var)
local state = MarketOfferState.Active
if var == MarketRequest.MyHistory then
state = msg:getU8()
elseif var == MarketRequest.MyOffers then
else
playerName = msg:getString()
end
return MarketOffer.new({timestamp, counter}, action, Item.create(itemId), amount, price, playerName, state)
return MarketOffer.new({timestamp, counter}, action, Item.create(itemId), amount, price, playerName, state, var)
end
-- parsing protocols
@ -201,6 +202,10 @@ function MarketProtocol.sendMarketBrowse(browseId)
end
end
function MarketProtocol.sendMarketBrowseMyOffers()
MarketProtocol.sendMarketBrowse(MarketRequest.MyOffers)
end
function MarketProtocol.sendMarketCreateOffer(type, spriteId, amount, price, anonymous)
if g_game.getFeature(GamePlayerMarket) then
local msg = OutputMessage.create()

View File

@ -1,9 +1,176 @@
OfferTableRow < TableRow
font: verdana-11px-monochrome
color: #cccccc
height: 15
OfferTableColumn < TableColumn
font: verdana-11px-monochrome
background-color: alpha
text-offset: 5 0
color: #cccccc
width: 80
OfferTableWarningColumn < OfferTableColumn
color: #e03d3d
OfferTableHeaderRow < TableHeaderRow
font: verdana-11px-monochrome
color: #cccccc
height: 20
OfferTableHeaderColumn < SortableTableHeaderColumn
font: verdana-11px-monochrome
text-offset: 2 0
color: #cccccc
$focus:
background-color: #294f6d
color: #ffffff
Panel
background-color: #22283399
margin: 1
Button
id: sellCancelButton
!text: tr('Cancel')
anchors.right: parent.right
anchors.bottom: next.bottom
margin-right: 6
width: 80
enabled: false
Label
!text: tr('Current Offers')
!text: tr('Sell Offers')
font: verdana-11px-rounded
text-offset: 0 2
anchors.top: parent.top
anchors.left: parent.left
margin-left: 10
margin-top: 44
margin-left: 6
Table
id: mySellingTable
anchors.top: prev.bottom
anchors.left: prev.left
anchors.right: parent.right
height: 150
margin-top: 5
margin-bottom: 5
margin-right: 6
padding: 1
focusable: false
background-color: #222833
border-width: 1
border-color: #191f27
table-data: mySellingTableData
row-style: OfferTableRow
column-style: OfferTableColumn
header-column-style: false
header-row-style: false
OfferTableHeaderRow
id: header
OfferTableHeaderColumn
!text: tr('Item Name')
width: 160
OfferTableHeaderColumn
!text: tr('Total Price')
width: 125
OfferTableHeaderColumn
!text: tr('Piece Price')
width: 125
OfferTableHeaderColumn
!text: tr('Amount')
width: 110
OfferTableHeaderColumn
!text: tr('Auction End')
width: 110
TableData
id: mySellingTableData
anchors.bottom: mySellingTable.bottom
anchors.left: mySellingTable.left
anchors.right: mySellingTable.right
margin-top: 2
vertical-scrollbar: mySellingTableScrollBar
VerticalScrollBar
id: mySellingTableScrollBar
anchors.top: mySellingTable.top
anchors.bottom: mySellingTable.bottom
anchors.right: mySellingTable.right
step: 28
pixels-scroll: true
Button
id: buyCancelButton
!text: tr('Cancel')
anchors.right: parent.right
anchors.top: prev.bottom
margin-top: 5
margin-right: 6
width: 80
enabled: false
Label
!text: tr('Buy Offers')
font: verdana-11px-rounded
text-offset: 0 2
anchors.top: prev.top
anchors.left: parent.left
margin-top: 9
margin-left: 6
Table
id: myBuyingTable
anchors.top: prev.bottom
anchors.left: prev.left
anchors.right: parent.right
margin-top: 5
margin-bottom: 5
margin-right: 6
height: 150
padding: 1
focusable: false
background-color: #222833
border-width: 1
border-color: #191f27
table-data: myBuyingTableData
row-style: OfferTableRow
column-style: OfferTableColumn
header-column-style: false
header-row-style: false
OfferTableHeaderRow
id: header
OfferTableHeaderColumn
!text: tr('Item Name')
width: 160
OfferTableHeaderColumn
!text: tr('Total Price')
width: 125
OfferTableHeaderColumn
!text: tr('Piece Price')
width: 125
OfferTableHeaderColumn
!text: tr('Amount')
width: 110
OfferTableHeaderColumn
!text: tr('Auction End')
width: 110
TableData
id: myBuyingTableData
anchors.bottom: myBuyingTable.bottom
anchors.left: myBuyingTable.left
anchors.right: myBuyingTable.right
vertical-scrollbar: myBuyingTableScrollBar
VerticalScrollBar
id: myBuyingTableScrollBar
anchors.top: myBuyingTable.top
anchors.bottom: myBuyingTable.bottom
anchors.right: myBuyingTable.right
step: 28
pixels-scroll: true

View File

@ -1439,7 +1439,7 @@ bool Game::canPerformGameAction()
// - we have a game protocol
// - the game protocol is connected
// - its not a bot action
return m_online && m_localPlayer && !m_dead && m_protocolGame && m_protocolGame->isConnected() && checkBotProtection();
return m_online && m_localPlayer && !m_localPlayer->isDead() && !m_dead && m_protocolGame && m_protocolGame->isConnected() && checkBotProtection();
}
void Game::setProtocolVersion(int version)

View File

@ -132,9 +132,10 @@ void StaticText::compose()
text += m_name;
text += " yells:\n";
m_color = Color(239, 239, 0);
} else if(m_mode == Otc::MessageMonsterSay || m_mode == Otc::MessageMonsterYell || m_mode == Otc::MessageSpell || m_mode == Otc::MessageBarkLow || m_mode == Otc::MessageBarkLoud) {
} else if(m_mode == Otc::MessageMonsterSay || m_mode == Otc::MessageMonsterYell || m_mode == Otc::MessageSpell
|| m_mode == Otc::MessageBarkLow || m_mode == Otc::MessageBarkLoud) {
m_color = Color(254, 101, 0);
} else if(m_mode == Otc::MessageNpcFrom) {
} else if(m_mode == Otc::MessageNpcFrom || m_mode == Otc::MessageNpcFromStartBlock) {
text += m_name;
text += " says:\n";
m_color = Color(95, 247, 247);

View File

@ -74,6 +74,8 @@ void EventDispatcher::poll()
event->execute();
}
m_pollEventsSize = m_eventList.size();
loops++;
}
}

View File

@ -307,13 +307,17 @@ std::string Crypt::sha512Encode(const std::string& decoded_string, bool upperCas
void Crypt::rsaGenerateKey(int bits, int e)
{
RSA *rsa = RSA_generate_key(bits, e, nullptr, nullptr);
RSA *rsa = RSA_new();
BIGNUM *ebn = BN_new();
BN_set_word(ebn, e);
RSA_generate_key_ex(rsa, bits, ebn, nullptr);
g_logger.info(stdext::format("%d bits (%d bytes) RSA key generated", bits, bits / 8));
g_logger.info(std::string("p = ") + BN_bn2dec(m_rsa->p));
g_logger.info(std::string("q = ") + BN_bn2dec(m_rsa->q));
g_logger.info(std::string("d = ") + BN_bn2dec(m_rsa->d));
g_logger.info(std::string("n = ") + BN_bn2dec(m_rsa->n));
g_logger.info(std::string("e = ") + BN_bn2dec(m_rsa->e));
BN_clear_free(ebn);
RSA_free(rsa);
}