Send packets to player
#1
How to send packets to player ?

Sorry for my bad english, I'm from Poland.
Reply
Thanks given by:
#2
Which packets and what is you're overall goal? The lua API generally isn't that low level so we can keep server state syncronised.
Reply
Thanks given by:
#3
Czesc, welcome to the forum.

We don't allow plugins to send packets because we support multiple protocol versions (from current 1.7.9 all the way down to 1.2.5) so it would be difficult for a plugin to provide all those versions.

You can send most packets indirectly by doing the actions that send those packets. You want to send a player position packet? Set the player's position. You want an "update sign text" packet? Update the sign's text.

Then there's the special "Plugin message" packet, that one can be sent and received by plugins directly, using cClientHandle:SendPluginMessage() function and HOOK_PLUGIN_MESSAGE hook. There's (currently) no way to register for the channels, though. If you want a working example, have a look at the WorldEdit plugin, it communicates with the WECUI client-side mod to provide visualisation for the player's selection.
https://github.com/mc-server/WorldEdit/b...#L250-L276
Reply
Thanks given by: artur9010
#4
You could always use the cWorld::BroadcastX() exported functions if you feel that all players in a world need to know about something.
Reply
Thanks given by:
#5
There are only a few broadcast functions, not every packet could be sent that way. I'm thinking about actually exporting the cClientHandle sending functions, too, so that the plugins can send packets to individual players.
Reply
Thanks given by:
#6
(07-05-2014, 12:29 AM)xoft Wrote: ... I'm thinking about actually exporting the cClientHandle sending functions, too ...
Yea that makes sense.
Reply
Thanks given by:
#7
I don't think it makes sense to export the sending functions. Makes it too easy for a plugin to cause desyncs. What if a Plugin sends the update block packet?
Reply
Thanks given by:
#8
Some plugins want the client and server to desync. For example my attempt at an anti-xray plugin. It sends an update block packet(already exported) to the client making it think it's an ore. It only does this to blocks that aren't visible.
Reply
Thanks given by: LO1ZB
#9
I think we should bring this question back.

Maybe we should allow Lua to send packets if we want to support mods. (No idea what mod but I'm sure some mods add new packets)

We could export the cPacketizer class. Then add a cClientHandle function called something like "SendPacket". With 2 parameters. The packet type and a callback function.
pseudo-code:
// The send packet function in clienthandle.
void cClientHandle::SendPacket(Byte a_Packet, cLuaPacketCallback a_Callback)
{
   m_Protocol->SendLuaPacket(a_Packet, a_Callback);
}



// The function that will actualy create the cPacketizer and call the Lua function.
void cProtocol172::SendLuaPacket(Byte a_Packet, cLuaPacketCallback a_Callback)
{
   cPacketizer Pkt(*this, a_Packet);
   a_Callback->Item(Pkt);
}

Thoughts??
Reply
Thanks given by:
#10
This could work with a single protocol, but it doesn't work for multiprotocol.
Reply
Thanks given by:




Users browsing this thread: 10 Guest(s)