Skip to content

Instantly share code, notes, and snippets.

@rschulman
Created March 19, 2013 20:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rschulman/5199790 to your computer and use it in GitHub Desktop.
Save rschulman/5199790 to your computer and use it in GitHub Desktop.
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