caveful_games/handynet

ByteNet fork made more handy

English ๐Ÿ‘ˆ

ํ•œ๊ตญ์–ด

HandyNet

๋” Handyํ•ด์ง„ ByteNet์˜ ํฌํฌ

ํŠน์ง•

  • ByteNet์˜ ํฌํฌ์ด๋ฉฐ ๋Œ€๋ถ€๋ถ„์˜ ๊ตฌํ˜„์„ ๊ณต์œ ํ•ฉ๋‹ˆ๋‹ค.
  • ์ฝ”๋“œ ์„ค๊ณ„ ๋ฐ ์•„์ด๋””์–ด๋Š” kitty-utils/net์—์„œ ํŒŒ์ƒ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.

์„ค์น˜ (via pesde)

pesde add caveful_games/handynet

ByteNet๊ณผ ์ฐจ์ด์ 

  • (0.2.x ๋ถ€ํ„ฐ) HandyNet.send์˜ ๋‹ค์ด๋‚˜๋ฏน ํƒ€์ž…์œผ๋กœ ์ธํ•˜์—ฌ ์ด๋ก ์ ์œผ๋กœ ์„œ๋ฒ„์—์„œ์˜ ByteNet.sendTo๊ณผ ByteNet.sendToAll๋ณด๋‹ค ์กฐ๊ธˆ ๋А๋ฆด ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. (๋Œ€์‹  ์‹ฌํ”Œํ•˜๊ณ  ํด๋ผ์ด์–ธํŠธ์—์„œ ํ”Œ๋ ˆ์ด์–ด ์ธ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ์ƒํ™ฉ ์ œ์™ธ ์กฐ๊ธˆ ๋” ํƒ€์ž…์— ์•ˆ์ „ํ•˜๋ฉฐ Namespace.server, Namespace.client๊ฐ€ ํ•„์š”์—†์–ด์กŒ์Šต๋‹ˆ๋‹ค. -> ์ ์–ด์ง„ ๋ฉ”๋ชจ๋ฆฌ ์‚ฌ์šฉ๋Ÿ‰)
  • HandyNet์€ ์†๋„๋ณด๋‹ค ๋ฉ”๋ชจ๋ฆฌ ์‚ฌ์šฉ๋Ÿ‰์— ๋” ์ดˆ์ ์„ ๋งž์ท„๊ธฐ ๋•Œ๋ฌธ์— ์ด๋ก ์ ์œผ๋กœ ByteNet์ด ๋” ๋น ๋ฅผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. (ByteNet์€ ๋” ๋น ๋ฅธ ์†๋„๋ฅผ ์œ„ํ•ด ํŽ˜ํ‚ท๋งˆ๋‹ค ๋ฉ”์†Œ๋“œ ํ•จ์ˆ˜๋ฅผ ์ƒ์„ฑํ•˜์ง€๋งŒ HandyNet์€ ๋ฉ”ํƒ€ํ…Œ์ด๋ธ”์„ ํ™œ์šฉํ•˜์—ฌ ํ•จ์ˆ˜๋ฅผ ์žฌํ™œ์šฉํ•ฉ๋‹ˆ๋‹ค.) ๋ฉ”๋ชจ๋ฆฌ ์‚ฌ์šฉ๋Ÿ‰์ด ๊ทธ๋ ‡๊ฒŒ ํฌ์ง€ ์•Š๊ณ  ์ •์ ์ธ ํฌ๊ธฐ๋ฅผ ์ฐจ์ง€ํ•˜๋ฏ€๋กœ ๊ทธ๋Œ€๋กœ ํด๋กœ์ €๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.
  • ByteNet.string ์ž๋ฃŒํ˜•์˜ ํฌ๊ธฐ๋ฅผ ์„ค์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
  • definePacket์˜ ์ธ์ˆ˜ reliablityType ์†์„ฑ์ด defineReliablePacket๊ณผ defineUnreliablePacket ๋‘๊ฐ€์ง€ ํ•จ์ˆ˜๋กœ ๋‚˜๋‰จ์— ๋”ฐ๋ผ ํ…Œ์ด๋ธ” props ์ธ์ˆ˜๋ฅผ ๋ฐ›์ง€ ์•Š๊ณ  ๊ธฐ์กด์— value ์†์„ฑ์ด์—ˆ๋˜ ๊ฐ’ ์ž๋ฃŒํ˜•๋งŒ ๋‹จ์ผ ์ธ์ˆ˜๋กœ ๋ฐ›์Šต๋‹ˆ๋‹ค. (๊ฐ„์†Œํ™”)
  • ๋ช‡๊ฐ€์ง€ ์ž๋ฃŒํ˜• ์ด๋ฆ„์ด ๋ช…ํ™•ํ•ด์กŒ์Šต๋‹ˆ๋‹ค. (ex. ByteNet.vec3 -> HandyNet.Vector3)
  • Namespace ํƒ€์ž…์— server์™€ client ์†์„ฑ์ด ์ถ”๊ฐ€๋จ์œผ๋กœ์จ ์„œ๋ฒ„/ํด๋ผ์ด์–ธํŠธ ๊ตฌ๋ถ„์„ ๋” ๋ช…ํ™•ํžˆํ•œ ํƒ€์ž…์ฒดํ‚น์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.
  • ์„œ๋ฒ„/ํด๋ผ์ด์–ธํŠธ์˜ ์˜ˆ์ธก ๋ฐ ๋™๊ธฐํ™” ๋ชจ๋ธ, ์–ด๋“œ๋ฏผ ์ปค๋งจ๋“œ๋ฅผ ๋งŒ๋“ค ๋•Œ ์œ ์šฉํ•˜๊ฒŒ ์‚ฌ์šฉ๋  ์ˆ˜ ์žˆ๋Š” Command๊ฐ€ ์ถ”๊ฐ€๋˜์—ˆ์Šต๋‹ˆ๋‹ค. (event๋กœ ๋Œ€์ฒด๋จ)
  • ์ด๋ฒคํŠธ ์‹ ํ˜ธ๋Š” LimeSignal์„ ์‚ฌ์šฉํ•˜์—ฌ ๋ฐ›์Šต๋‹ˆ๋‹ค. (๊ฒฐ๊ณผ์ ์œผ๋กœ Connection์„ disconnectํ•˜๊ธฐ ๋” ๊ฐ„ํŽธํ•ด์กŒ์œผ๋ฉฐ, ๋” ์ด์ƒ definePacket์—์„œ ์ด๋ฒคํŠธ ์‹ ํ˜ธ ๋ฐฉ์‹์„ ์„ค์ •ํ•˜์ง€ ์•Š์•„๋„๋ฉ๋‹ˆ๋‹ค.)
  • HandyNet์€ ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ ํƒ€์ž…์„ ์ง€์›ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.
  • ์ฟผํ„ฐ๋‹ˆ์–ธ์„ ์‚ฌ์šฉํ•˜์—ฌ CFrame ์—ญ/์ง๋ ฌํ™” ์••์ถ•. (HandyNet.RawCFrame์œผ๋กœ ByteNet.cframe๊ณผ ๋™์ผํ•œ ์—ญ/์ง๋ ฌํ™”๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.)
  • ๋” ๋งŽ์€ ์ž๋ฃŒํ˜• ์ง€์›.

Example Usage

-- packets.luau

return HandyNet.defineNamespace("example", function()
	return {
		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
			})
			-- default: "reliable"
		),
		countUp = HandyNet.defineEvent("unreliable")
  	}
end)
-- 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.event: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.

TO-DOs (0.2.x)

  • Change Packet.onServerReceived and Packet.onClientReceived to Packet.event.
  • Change HandyNet.defineReliablePacket and HandyNet.defineUnreliablePacket to HandyNet.definePacket and provide reliability argument.
  • Replace Commands with Events.
  • Remove Namespace.client and Namespace.server. sendTo, sendToServer, and broadcast are replaced by send.
  • Packets are now one directional.
  • Add BrickColor and Enum data type.
  • Update README.md.
  • Add ServerPacket and ClientPacket types.
  • Test 0.2.0 and fix bugs.
  • Release and publish into pesde.
  • Add korean(ํ•œ๊ตญ์–ด) docs comments.