sock.lua
sock.lua copied to clipboard
Server:sendToPeer() Gets Serialized Twice
Server:sendToPeer() passes serialized data to Client:send(), which serializes it again. Causing event to not fire client side since they receive the serialized data as the event name. Easy fix:
function Server:sendToPeer(peer, event, data) peer:send(event, data) end
Still not fixed
~It is updated in the latest master, but not in the release 0.3.0~ It was updated, but is still not fixed, try the solution @LazyInn suggested, by changing sendToPeer as follows:
--- Send a message to a single peer. Useful to send data to a newly connected player
-- without sending to everyone who already received it.
-- @tparam enet_peer peer The enet peer to receive the message.
-- @tparam string event The event to trigger with this message.
-- @param data data to send to the peer.
--@usage
--server:sendToPeer(peer, "initialGameInfo", {...})
function Server:sendToPeer(peer, event, data)
--local serializedMessage = self:__pack(event, data)
self.packetsSent = self.packetsSent + 1
peer:send(event, data)
--peer:send(serializedMessage, self.sendChannel, self.sendMode)
self:resetSendSettings()
end