Files
minego/pkg/protocol/packet/packets.go

67 lines
1.8 KiB
Go

package packet
import (
"git.konjactw.dev/falloutBot/go-mc/data/packetid"
pk "git.konjactw.dev/falloutBot/go-mc/net/packet"
)
import loginclient "git.konjactw.dev/patyhank/minego/pkg/protocol/packet/login/client"
import gameclient "git.konjactw.dev/patyhank/minego/pkg/protocol/packet/game/client"
import configclient "git.konjactw.dev/patyhank/minego/pkg/protocol/packet/configuration/client"
import loginserver "git.konjactw.dev/patyhank/minego/pkg/protocol/packet/login/server"
import gameserver "git.konjactw.dev/patyhank/minego/pkg/protocol/packet/game/server"
import configserver "git.konjactw.dev/patyhank/minego/pkg/protocol/packet/configuration/server"
type ServerboundPacket interface {
pk.Field
PacketID() packetid.ServerboundPacketID
}
type ClientboundPacket interface {
pk.Field
PacketID() packetid.ClientboundPacketID
}
type State int32
const (
StateLogin State = iota
StateConfig
StatePlay
)
func GetClientPacket(state State, id int32) ClientboundPacket {
switch state {
case StateLogin:
return loginclient.ClientboundPackets[packetid.ClientboundPacketID(id)]()
case StateConfig:
return configclient.ClientboundPackets[packetid.ClientboundPacketID(id)]()
case StatePlay:
return gameclient.ClientboundPackets[packetid.ClientboundPacketID(id)]()
}
return nil
}
func GetServerPacket(state State, id int32) ServerboundPacket {
switch state {
case StateLogin:
creator := loginserver.ServerboundPackets[packetid.ServerboundPacketID(id)]
if creator == nil {
return nil
}
return creator()
case StateConfig:
creator := configserver.ServerboundPackets[packetid.ServerboundPacketID(id)]
if creator == nil {
return nil
}
return creator()
case StatePlay:
creator := gameserver.ServerboundPackets[packetid.ServerboundPacketID(id)]
if creator == nil {
return nil
}
return creator()
}
return nil
}