caveful_games/handynet
v0.2.1 ยท
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 :: Enum.KeyCode -- Weird type error with enums..
})
-- 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.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.0
- Change
Packet.onServerReceivedandPacket.onClientReceivedtoPacket.event. - Change
HandyNet.defineReliablePacketandHandyNet.defineUnreliablePackettoHandyNet.definePacketand provide reliability argument. - Replace
Commands withEvents. - Remove
Namespace.clientandNamespace.server.sendTo,sendToServer, andbroadcastare replaced bysend. -
Packets are now one directional. - Add
BrickColorandEnumdata type. - Update README.md.
- Add
ServerPacketandClientPackettypes. - Test
0.2.0and fix bugs. - Release and publish into pesde.
- Add korean(ํ๊ตญ์ด) docs comments.
v0.2.1
- Fix
HandyNet.Enumtypes and documented. - Packet definitions can be nested.