PDA

View Full Version : Deliver message from player to GM only



Ikael
January 24th, 2010, 21:45
Is there any decent way to deliver complete chat message from player (client) to GM (host). If I use the deliverMessage(msg, "") then the message will be delivered to host but some content of it will dissapear like the dielist, icon, diemodifier etc. I would really like to know if this is a bug or a "feature" of FG engine.

I think it would be one of the most useful features to deliver complete message from client host, especially if you want to implement decent private messaging or groupchatting.

so far I have resolved this issue by making special type of message called 'messagepacket' which is just a normal message with sender, font and text data. However, the text data wraps-up all the real message-data such as the dielist, diemodifier, icon etc in pre-formatted way. In addition sender data starts with "<packet>" prefix which is used to catch the message on receive.
When such a "<packet>" message is received it's opened and transformed to complete and real message which is just added to chat using the addMessage(msg) function.

Below are the codelines for creating such a packet, opening it to real message and catching it on chat_chat.lua's onReceiveMessage(msg) function:

creating packet -- has parameters: original message, sender-name and messagetype just for convenience


function createPacket(msg, sender, mtype)
local entry = {}
local icon = ""
local dicelist = ""
local number = ""
local text = ""
local mood = ""
if msg.icon then icon = "ICON:={[[" .. msg.icon .. "]]};" end
if msg.diemodifier then number = "NUMBER:={[[" .. msg.diemodifier .. "]]};"end
if msg.text then text = "TEXT:={[[" .. msg.text .. "]]};" end
if msg.mood then mood = "MOOD:={[[" .. msg.mood .. "]]};" end
if msg.dice then
for n = 1, table.maxn(msg.dice) do dicelist = dicelist .. "," .. msg.dice[n].type .. ":" .. msg.dice[n].result end
if #dicelist > 0 then dicelist = "DICE:={[[" .. dicelist:sub(2) .. "," .. "]]};" end
end
entry.sender = "<packet>"
if msg.sender then entry.sender = entry.sender .. msg.sender end
entry.font = msg.font
entry.text = icon .. mood .. text .. dicelist .. number .. "TYPE:={[[" .. mtype .. "]]};" .. "SENDER:={[[" .. sender .. "]]};"
return entry;
end


opening packet -- has parameters msg: packet message

function openPacket(msg)
local mtype = nil
local msender = ""
local entry = {}
entry.icon = nil
entry.font = msg.font
entry.diemodifier = nil
entry.text = ""
entry.mood = nil
entry.dice = {}
entry.sender = msg.sender:sub(9, #msg.sender-1)
entry.dicesecret = false
local message = msg.text
if msg.text then
while message:find(':={%[%[') do
local hs, he = message:find(':={%[%[')
local header = message:sub(0, hs-1)
local cs, ce = message:find('%]%]%};')
local content = message:sub(he+1, cs-1)
message = message:sub(ce+1)
if header == "ICON" then entry.icon = content
elseif header == "SENDER" then msender = content
elseif header == "TYPE" then mtype = content
elseif header == "TEXT" then entry.text = content
elseif header == "MOOD" then entry.mood = content
elseif header == "NUMBER" then entry.diemodifier = content
elseif header == "DICE" then
repeat
local f = content:find(',')
local diestr = content:sub(0,f-1)
local die = {}
local dtype, dresult = diestr:match('(d%d+):(%d+)')
die.type = dtype;
die.result = dresult;
table.insert(entry.dice, die)
content = content:sub(f+1)
until not content:find(',')
end
end
end
if not entry.diemodifier and #entry.dice < 1 then entry.dice = nil; end
addMessage(entry);
return entry, msender, mtype;
end

catching packet:

if User.isHost() and string.find(msg.sender, "<packet>") == 1 then
ChatManager.openPacket(msg);
return true;
end


However, this is not dummy-proof method and I would like to know if there is or will be decent way to do the same thing?

Foen
January 24th, 2010, 22:44
The remote message-sending mechanism only copes with a reduced message packet (most importantly, custom data is dropped), and your approach is the only way to get around it as far as I know.

Sorry

Foen