more srv stuff and packet inspetor

This commit is contained in:
adman
2026-03-25 19:00:18 +01:00
parent 23b5a5d9b7
commit df0e5e354b
6 changed files with 151 additions and 6 deletions
+1
View File
@@ -13,6 +13,7 @@ func MakeHandshakePacket(c *proto.Conn, nextState proto_base.State) (p *v1_21_8.
return MakeHandshakePacketAddr(c, nextState, c.RemoteAddr().String())
}
// MakeHandshakePacketAddr gets a custom addr
func MakeHandshakePacketAddr(s *proto.Conn, nextState proto_base.State, addr string) (p *v1_21_8.HandshakingToServerPacketSetProtocol, err error) {
p = &v1_21_8.HandshakingToServerPacketSetProtocol{NextState: int32(nextState), ProtocolVersion: s.ProtocolVersion}
var portStr string
+16 -3
View File
@@ -127,7 +127,7 @@ func (s *LoginClient) OnStart() (err error) {
return
}
func Login(c *proto.Conn, account *api.Account) (err error) {
func LoginRaw(c *proto.Conn, account *api.Account, addr string) (err error) {
lc := &LoginClient{
Conn: c,
Account: account,
@@ -159,11 +159,24 @@ func Login(c *proto.Conn, account *api.Account) (err error) {
return
}
func ConnectAndLogin(connectTo string, account *api.Account) (c *proto.Conn, err error) {
func LoginNoSrv(connectTo string, account *api.Account) (c *proto.Conn, err error) {
c, err = Connect(connectTo)
if err != nil {
return
}
err = Login(c, account)
err = LoginRaw(c, account, connectTo)
return
}
func Login(connectTo string, account *api.Account) (c *proto.Conn, err error) {
connectTo, err = DoDnsSimple(connectTo)
if err != nil {
return
}
c, err = Connect(connectTo)
if err != nil {
return
}
err = LoginRaw(c, account, connectTo)
return
}
+13 -2
View File
@@ -37,7 +37,8 @@ func (s *StatusClient) OnPong(p *v1_21_8.StatusToClientPacketPing) (err error) {
}
// StatusRaw returns a StatusClient that is not connected to a server.
// So ignore the resource leak warning. And maybe attach a warn ignore comment
// So ignore the resource leak warning. And maybe attach a warn ignore comment.
// It does not resolve SRV records.
func StatusRaw(addr string) (s *StatusClient, err error) {
c, err := ConnectVersionLess(addr)
if err != nil {
@@ -69,7 +70,8 @@ func StatusRaw(addr string) (s *StatusClient, err error) {
return
}
func Status(addr string) (status server.StatusResponse, err error) {
// StatusNoDns is like Status but does not resolve SRV records.
func StatusNoDns(addr string) (status server.StatusResponse, err error) {
s, err := StatusRaw(addr)
if err != nil {
return
@@ -77,3 +79,12 @@ func Status(addr string) (status server.StatusResponse, err error) {
err = json.Unmarshal([]byte(s.Status), &status)
return
}
// Status resolves the status of the minecraft server at the given address.
func Status(addr string) (status server.StatusResponse, err error) {
addr, err = DoDnsSimple(addr)
if err != nil {
return
}
return StatusNoDns(addr)
}