mirror of
https://github.com/WiiLink24/wfc-server.git
synced 2026-03-21 17:44:58 -05:00
- Server browser (Matchmaking) now returns a server list (although hardcoded) - GPCM now keeps track of an actual thread-safe session - Some int types were changed to reflect the actual size - Improvements made to logging in many places
33 lines
687 B
Go
33 lines
687 B
Go
package common
|
|
|
|
import (
|
|
"crypto/md5"
|
|
"encoding/binary"
|
|
"fmt"
|
|
)
|
|
|
|
func CalcFriendCode(pid uint32, gameId string) uint64 {
|
|
if pid == 0 {
|
|
return 0
|
|
}
|
|
|
|
buffer := make([]byte, 8)
|
|
binary.LittleEndian.PutUint32(buffer, pid)
|
|
buffer[4] = gameId[3]
|
|
buffer[5] = gameId[2]
|
|
buffer[6] = gameId[1]
|
|
buffer[7] = gameId[0]
|
|
|
|
digest := md5.Sum(buffer)
|
|
return uint64(pid) | (uint64(digest[0]&0xfe) << 31)
|
|
}
|
|
|
|
func CalcFriendCodeString(pid uint32, gameId string) string {
|
|
return GetRawFriendCodeString(CalcFriendCode(pid, gameId))
|
|
}
|
|
|
|
func GetRawFriendCodeString(fc uint64) string {
|
|
s := fmt.Sprintf("%012d", fc)
|
|
return s[len(s)-12:len(s)-8] + "-" + s[len(s)-8:len(s)-4] + "-" + s[len(s)-4:]
|
|
}
|