Skip to content

Latest commit

 

History

History
116 lines (89 loc) · 3.28 KB

README.md

File metadata and controls

116 lines (89 loc) · 3.28 KB

한국어 👈

English

HandyNet

ByteNet fork made more handy

About

  • HandyNet is a fork of ByteNet and shares most of its implementation.
  • The code design and ideas are derived from kitty-utils/net.

Installation (via pesde)

pesde add caveful_games/handynet

Differences from ByteNet

  • (From v0.3.0) Don't have to write a function when defining namespace.
  • (From v0.2.0) Due to the dynamic typing of HandyNet.send, it can theoretically be slightly slower than ByteNet.sendTo and ByteNet.sendToAll on the server. (It is more simple and more type-safe and removes the need for Namespace.server and Namespace.client, except in cases where the player argument is used on the client.)
  • (From v0.2.0) Packets are one directional.
  • (From v0.2.1) Packet definitions can be nested for labeling purpose.
  • Resizable ByteNet.string data type.
  • Simplified definePacket API.
  • Some data type names have been made clearer.
  • Added Command, which is handier for designing a client/server synchronization model. (Replaced by events)
  • Events and connections are handled by LimeSignal which is fork of LemonSignal. (Simple event handling method)
  • HandyNet does not support TypeScript.
  • New serdes for CFrame.
  • New data types: RawCFrame(equal to ByteNet.cframe), CFrame(uses Quaternion to compress into 13~19 bytes), AlignedCFrame, UnalignedCFrame, Enum, and BrickColor

Example Usage

-- packets.luau

return HandyNet.defineNamespace("example", {
	hello = HandyNet.definePacket(
		"client->server",
		HandyNet.struct({
			message = HandyNet.string(HandyNet.u8), -- Customizable string size (defaults to u16)
			cf = HandyNet.CFrame, -- Uses quaternion to compress!
			enum = HandyNet.Enum.KeyCode :: Enum.KeyCode -- Weird type error with enums..
		})
		-- default: "reliable"
	),
	countUp = HandyNet.defineEvent("unreliable")
})
-- shared.luau

local packets = require(path.to.packets)

local counts = {}

local function countUp(player)
	local count = counts[player]
	if not count then
		count = 0
		counts[player] = count
	end

	count += 1
	counts[player] = count

	print("count:", count)
end

packets.countUp.connect(countUp)

return {}
-- client.luau

local packets = require(path.to.packets)

packets.hello.send({
	message = "hi ya",
	cf = CFrame.new(),
	enum = Enum.KeyCode.X
})

packets.countUp.fire()
-- server.luau

local packets = require(path.to.packets)

-- packets.some.send(data, player)
-- if you want 'sendToAll': packets.some.send(data)

packets.hello.event:connect(function()
	print("received hello from client")
end)

packets.countUp.connect(function()
	print("client has fired countUp event!")
end)

Credits

  • ByteNet for original source codes. (licensed under MIT license)
  • Special thanks to Mark-Marks for major feedbacks.
  • Special thanks to roasted_shrimps for new CFrame serdes idea.

TO-DOs

v0.2.3

  • Fix dependencies require error.

v0.3.0

  • Change math.sqrt into ^.5 (Slightly faster)
  • Simplify the defineNamespace (Breaking change)