mirror of
https://github.com/edubart/otclient.git
synced 2025-10-15 20:14:54 +02:00
Multi-protocol
Lots of chagnes to add multi protocol flexibility, not really completed yet, still have to rework text messages opcodes and other stuff, so this still a working in progress feature * Rework dat reader, the dat reader can now * dinamically detect dat version * Split game into gamelib and game_interface * Lots of other minor changes
This commit is contained in:
@@ -4,9 +4,6 @@ Module
|
||||
author: BeniS
|
||||
website: www.otclient.info
|
||||
|
||||
dependencies:
|
||||
- game
|
||||
|
||||
@onLoad: |
|
||||
dofile 'marketoffer'
|
||||
dofile 'marketprotocol'
|
||||
|
@@ -32,7 +32,7 @@ MarketOffer.new = function(offerId, action, itemId, amount, price, playerName, s
|
||||
offer.player = playerName
|
||||
|
||||
state = tonumber(state)
|
||||
if state ~= MarketOfferState.Active and state ~= MarketOfferState.Cancelled
|
||||
if state ~= MarketOfferState.Active and state ~= MarketOfferState.Cancelled
|
||||
and state ~= MarketOfferState.Expired and state ~= MarketOfferState.Accepted then
|
||||
g_logger.error('MarketOffer.new - invalid state provided.')
|
||||
end
|
||||
|
@@ -3,27 +3,6 @@ MarketProtocol = {}
|
||||
local market
|
||||
|
||||
-- private functions
|
||||
|
||||
local function parseOpcode(protocol, opcode, msg)
|
||||
if not g_game.getFeature(GamePlayerMarket) then
|
||||
return false
|
||||
end
|
||||
|
||||
-- process msg
|
||||
if opcode == GameServerOpcodes.GameServerMarketEnter then
|
||||
parseMarketEnter(msg)
|
||||
elseif opcode == GameServerOpcodes.GameServerMarketLeave then
|
||||
parseMarketLeave(msg)
|
||||
elseif opcode == GameServerOpcodes.GameServerMarketDetail then
|
||||
parseMarketDetail(msg)
|
||||
elseif opcode == GameServerOpcodes.GameServerMarketBrowse then
|
||||
parseMarketBrowse(msg)
|
||||
else
|
||||
return false
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
local function send(msg)
|
||||
print(msg:getMessageSize())
|
||||
g_game.getProtocolGame():safeSend(msg)
|
||||
@@ -49,12 +28,11 @@ local function readMarketOffer(msg, action, var)
|
||||
else
|
||||
playerName = msg:getString()
|
||||
end
|
||||
|
||||
|
||||
return MarketOffer.new({timestamp, counter}, action, itemId, amount, price, playerName, state)
|
||||
end
|
||||
|
||||
-- parsing protocols
|
||||
|
||||
local function parseMarketEnter(msg)
|
||||
local balance = msg:getU32()
|
||||
local offers = msg:getU8()
|
||||
@@ -128,14 +106,18 @@ local function parseMarketBrowse(msg)
|
||||
end
|
||||
|
||||
-- public functions
|
||||
|
||||
function MarketProtocol.init()
|
||||
connect(ProtocolGame, { onOpcode = parseOpcode } )
|
||||
|
||||
ProtocolGame.registerOpcode(GameServerOpcodes.GameServerMarketEnter, parseMarketEnter)
|
||||
ProtocolGame.registerOpcode(GameServerOpcodes.GameServerMarketLeave, parseMarketLeave)
|
||||
ProtocolGame.registerOpcode(GameServerOpcodes.GameServerMarketDetail, parseMarketDetail)
|
||||
ProtocolGame.registerOpcode(GameServerOpcodes.GameServerMarketBrowse, parseMarketBrowse)
|
||||
end
|
||||
|
||||
function MarketProtocol.terminate()
|
||||
disconnect(ProtocolGame, { onOpcode = parseOpcode } )
|
||||
ProtocolGame.unregisterOpcode(GameServerOpcodes.GameServerMarketEnter, parseMarketEnter)
|
||||
ProtocolGame.unregisterOpcode(GameServerOpcodes.GameServerMarketLeave, parseMarketLeave)
|
||||
ProtocolGame.unregisterOpcode(GameServerOpcodes.GameServerMarketDetail, parseMarketDetail)
|
||||
ProtocolGame.unregisterOpcode(GameServerOpcodes.GameServerMarketBrowse, parseMarketBrowse)
|
||||
|
||||
market = nil
|
||||
MarketProtocol = nil
|
||||
|
Reference in New Issue
Block a user