Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
tohash := []byte(p.host.id)
tohash = append(tohash, p.sharedsecret...)
tohash = append(tohash, p.host.keypacked...)
resp, err := http.Get(fmt.Sprintf("http://session.minecraft.net/game/checkserver.jsp?user=%v&serverId=%v", p.name, hash(tohash)))
func hash(data []byte) string {
h := sha1.New()
h.Write(data)
hashed := h.Sum(nil)
zeroes, err := regexp.Compile("^0+")
if err != nil {
fmt.Println(err)
}
negative := false
if hashed[0]&0x08 == 0 { //two's complement
negative = true
carry := true
for i := len(hashed) - 1; i >= 0; i-- {
hashed[i] = ^hashed[i]
if carry {
carry = hashed[i] == 0xFF
hashed[i]++
}
}
}
stringhash := fmt.Sprintf("%x", hashed)
stringhash = zeroes.ReplaceAllLiteralString(stringhash, "")
if negative {
stringhash = "-" + stringhash
}
return stringhash
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.