Add support for channel events
This commit is contained in:
parent
07b4b785fc
commit
8301bc74f3
|
@ -52,6 +52,13 @@ SayModes = {
|
||||||
[3] = { speakTypeDesc = 'yell', icon = '/images/game/console/yell' }
|
[3] = { speakTypeDesc = 'yell', icon = '/images/game/console/yell' }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ChannelEventFormats = {
|
||||||
|
[ChannelEvent.Join] = '%s joined the channel.',
|
||||||
|
[ChannelEvent.Leave] = '%s left the channel.',
|
||||||
|
[ChannelEvent.Invite] = '%s has been invited to the channel.',
|
||||||
|
[ChannelEvent.Exclude] = '%s has been removed from the channel.',
|
||||||
|
}
|
||||||
|
|
||||||
MAX_HISTORY = 500
|
MAX_HISTORY = 500
|
||||||
MAX_LINES = 100
|
MAX_LINES = 100
|
||||||
HELP_CHANNEL = 9
|
HELP_CHANNEL = 9
|
||||||
|
@ -98,7 +105,8 @@ function init()
|
||||||
onRuleViolationCancel = onRuleViolationCancel,
|
onRuleViolationCancel = onRuleViolationCancel,
|
||||||
onRuleViolationLock = onRuleViolationLock,
|
onRuleViolationLock = onRuleViolationLock,
|
||||||
onGameStart = online,
|
onGameStart = online,
|
||||||
onGameEnd = offline
|
onGameEnd = offline,
|
||||||
|
onChannelEvent = onChannelEvent,
|
||||||
})
|
})
|
||||||
|
|
||||||
consolePanel = g_ui.loadUI('console', modules.game_interface.getBottomPanel())
|
consolePanel = g_ui.loadUI('console', modules.game_interface.getBottomPanel())
|
||||||
|
@ -240,7 +248,8 @@ function terminate()
|
||||||
onRuleViolationCancel = onRuleViolationCancel,
|
onRuleViolationCancel = onRuleViolationCancel,
|
||||||
onRuleViolationLock = onRuleViolationLock,
|
onRuleViolationLock = onRuleViolationLock,
|
||||||
onGameStart = online,
|
onGameStart = online,
|
||||||
onGameEnd = offline
|
onGameEnd = offline,
|
||||||
|
onChannelEvent = onChannelEvent,
|
||||||
})
|
})
|
||||||
|
|
||||||
if g_game.isOnline() then clear() end
|
if g_game.isOnline() then clear() end
|
||||||
|
@ -684,7 +693,7 @@ function addTabText(text, speaktype, tab, creatureName)
|
||||||
child:setSelection(string.len(child:getText()), textPos)
|
child:setSelection(string.len(child:getText()), textPos)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -857,14 +866,14 @@ function sendMessage(message, tab)
|
||||||
message = chatCommandMessage
|
message = chatCommandMessage
|
||||||
channel = 0
|
channel = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
-- player red talk on channel
|
-- player red talk on channel
|
||||||
chatCommandMessage = message:match("^%#[c|C] (.*)")
|
chatCommandMessage = message:match("^%#[c|C] (.*)")
|
||||||
if chatCommandMessage ~= nil then
|
if chatCommandMessage ~= nil then
|
||||||
chatCommandSayMode = 'channelRed'
|
chatCommandSayMode = 'channelRed'
|
||||||
message = chatCommandMessage
|
message = chatCommandMessage
|
||||||
end
|
end
|
||||||
|
|
||||||
-- player broadcast
|
-- player broadcast
|
||||||
chatCommandMessage = message:match("^%#[b|B] (.*)")
|
chatCommandMessage = message:match("^%#[b|B] (.*)")
|
||||||
if chatCommandMessage ~= nil then
|
if chatCommandMessage ~= nil then
|
||||||
|
@ -1437,3 +1446,19 @@ function offline()
|
||||||
end
|
end
|
||||||
clear()
|
clear()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function onChannelEvent(channelId, name, type)
|
||||||
|
local fmt = ChannelEventFormats[type]
|
||||||
|
if not fmt then
|
||||||
|
print(('Unknown channel event type (%d).'):format(type))
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local channel = channels[channelId]
|
||||||
|
if channel then
|
||||||
|
local tab = getTab(channel)
|
||||||
|
if tab then
|
||||||
|
addTabText(fmt:format(name), SpeakTypesSettings.channelOrange, tab)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
|
@ -333,4 +333,11 @@ SubscriptionStatus = {
|
||||||
Premium = 1,
|
Premium = 1,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ChannelEvent = {
|
||||||
|
Join = 0,
|
||||||
|
Leave = 1,
|
||||||
|
Invite = 2,
|
||||||
|
Exclude = 3,
|
||||||
|
}
|
||||||
|
|
||||||
-- @}
|
-- @}
|
||||||
|
|
|
@ -1296,7 +1296,7 @@ void ProtocolGame::parsePremiumTrigger(const InputMessagePtr& msg)
|
||||||
for(int i=0;i<triggerCount;++i) {
|
for(int i=0;i<triggerCount;++i) {
|
||||||
triggers.push_back(msg->getU8());
|
triggers.push_back(msg->getU8());
|
||||||
}
|
}
|
||||||
|
|
||||||
if(g_game.getClientVersion() <= 1096) {
|
if(g_game.getClientVersion() <= 1096) {
|
||||||
bool something = msg->getU8() == 1;
|
bool something = msg->getU8() == 1;
|
||||||
}
|
}
|
||||||
|
@ -1903,9 +1903,11 @@ void ProtocolGame::parseQuestLine(const InputMessagePtr& msg)
|
||||||
|
|
||||||
void ProtocolGame::parseChannelEvent(const InputMessagePtr& msg)
|
void ProtocolGame::parseChannelEvent(const InputMessagePtr& msg)
|
||||||
{
|
{
|
||||||
msg->getU16(); // channel id
|
uint16 channelId = msg->getU16();
|
||||||
g_game.formatCreatureName(msg->getString()); // player name
|
std::string name = g_game.formatCreatureName(msg->getString());
|
||||||
msg->getU8(); // event type
|
uint8 type = msg->getU8();
|
||||||
|
|
||||||
|
g_lua.callGlobalField("g_game", "onChannelEvent", channelId, name, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProtocolGame::parseItemInfo(const InputMessagePtr& msg)
|
void ProtocolGame::parseItemInfo(const InputMessagePtr& msg)
|
||||||
|
|
Loading…
Reference in New Issue