diff --git a/server/network/packets/ChatCommand.go b/server/network/handlers/ChatCommand.go similarity index 84% rename from server/network/packets/ChatCommand.go rename to server/network/handlers/ChatCommand.go index b68e822..32b2083 100644 --- a/server/network/packets/ChatCommand.go +++ b/server/network/handlers/ChatCommand.go @@ -1,4 +1,4 @@ -package packets +package handlers import "fmt" diff --git a/server/network/packets/ChatMessage.go b/server/network/handlers/ChatMessage.go similarity index 72% rename from server/network/packets/ChatMessage.go rename to server/network/handlers/ChatMessage.go index 76b85d0..9cc7c2a 100644 --- a/server/network/packets/ChatMessage.go +++ b/server/network/handlers/ChatMessage.go @@ -1,4 +1,4 @@ -package packets +package handlers func ChatMessagePacket(content string) { } diff --git a/server/network/handlers/PlayerMovement.go b/server/network/handlers/PlayerMovement.go new file mode 100644 index 0000000..7f14a6d --- /dev/null +++ b/server/network/handlers/PlayerMovement.go @@ -0,0 +1,31 @@ +package handlers + +import ( + "github.com/aimjel/minecraft/packet" + "github.com/dynamitemc/dynamite/server/player" +) + +func PlayerMovement( + state *player.Player, + pk packet.Packet, +) { + switch pk := pk.(type) { + case *packet.PlayerPosition: + { + state.X, state.Y, state.Z, state.OnGround = pk.X, pk.FeetY, pk.Z, pk.OnGround + } + case *packet.PlayerPositionRotation: + { + state.X, state.Y, state.Z, state.Yaw, state.Pitch, state.OnGround = pk.X, pk.FeetY, pk.Z, pk.Yaw, pk.Pitch, pk.OnGround + } + case *packet.PlayerRotation: + { + state.Yaw, state.Pitch, state.OnGround = pk.Yaw, pk.Pitch, pk.OnGround + } + case *packet.PlayerMovement: + { + state.OnGround = pk.OnGround + } + } + +} diff --git a/server/player/player.go b/server/player/player.go index 61729d2..6620d58 100644 --- a/server/player/player.go +++ b/server/player/player.go @@ -7,6 +7,10 @@ type Player struct { viewDistance int32 simulationDistance int32 + + X, Y, Z float64 + Yaw, Pitch float32 + OnGround bool } func New() *Player { diff --git a/server/player_controller.go b/server/player_controller.go index 4cba242..7001ae6 100644 --- a/server/player_controller.go +++ b/server/player_controller.go @@ -2,14 +2,13 @@ package server import ( "github.com/aimjel/minecraft/packet" - "github.com/dynamitemc/dynamite/server/network" "github.com/dynamitemc/dynamite/server/player" "github.com/dynamitemc/dynamite/server/world" ) type PlayerController struct { player *player.Player - session *network.Session + session *Session UUID string } @@ -40,3 +39,15 @@ func (p *PlayerController) SendAvailableCommands(commands *packet.DeclareCommand func (p *PlayerController) SystemChatMessage(s string) error { return p.session.SendPacket(&packet.SystemChatMessage{Content: s}) } + +func (p *PlayerController) Position() (x float64, y float64, z float64) { + return p.player.X, p.player.Y, p.player.Z +} + +func (p *PlayerController) Rotation() (yaw float32, pitch float32) { + return p.player.Yaw, p.player.Pitch +} + +func (p *PlayerController) OnGround() bool { + return p.player.OnGround +} diff --git a/server/server.go b/server/server.go index 22266e0..e74ef5d 100644 --- a/server/server.go +++ b/server/server.go @@ -10,7 +10,6 @@ import ( //"github.com/dynamitemc/dynamite/web" "github.com/dynamitemc/dynamite/logger" "github.com/dynamitemc/dynamite/server/commands" - "github.com/dynamitemc/dynamite/server/network" "github.com/dynamitemc/dynamite/server/player" "github.com/dynamitemc/dynamite/server/world" ) @@ -53,7 +52,7 @@ func (srv *Server) handleNewConn(conn *minecraft.Conn) { } plyr := player.New() - sesh := network.New(conn, plyr) + sesh := New(conn, plyr) cntrl := &PlayerController{player: plyr, session: sesh} cntrl.UUID = util.AddDashesToUUID(hex.EncodeToString(conn.Info.UUID[:])) if err := cntrl.JoinDimension(srv.world.DefaultDimension()); err != nil { diff --git a/server/network/session.go b/server/session.go similarity index 75% rename from server/network/session.go rename to server/session.go index 1283b44..358afa6 100644 --- a/server/network/session.go +++ b/server/session.go @@ -1,12 +1,13 @@ -package network +package server import ( + "net" + "github.com/aimjel/minecraft" "github.com/aimjel/minecraft/packet" player2 "github.com/aimjel/minecraft/player" - "github.com/dynamitemc/dynamite/server/network/packets" + "github.com/dynamitemc/dynamite/server/network/handlers" "github.com/dynamitemc/dynamite/server/player" - "net" ) type Session struct { @@ -28,9 +29,15 @@ func (s *Session) HandlePackets() error { switch pk := p.(type) { case *packet.ChatMessageServer: - packets.ChatMessagePacket(pk.Message) + handlers.ChatMessagePacket(pk.Message) case *packet.ChatCommandServer: - packets.ChatCommandPacket(pk.Command) + handlers.ChatCommandPacket(pk.Command) + } + switch p.ID() { + case 0x14, 0x15, 0x16, 0x17: + { + handlers.PlayerMovement(s.state, p) + } } } }