diff --git a/common/auth_token.go b/common/auth_token.go index a780e1e..85a0c42 100644 --- a/common/auth_token.go +++ b/common/auth_token.go @@ -85,8 +85,6 @@ func MarshalNASAuthToken(gamecd string, userid uint64, gsbrcd string, cfc uint64 } func UnmarshalNASAuthToken(token string) (gamecd string, issuetime time.Time, userid uint64, gsbrcd string, cfc uint64, region byte, lang byte, ingamesn string, challenge string, unitcd byte, isLocalhost bool, err error) { - err = nil - if !strings.HasPrefix(token, "NDS") { err = errors.New("invalid auth token prefix") return @@ -143,9 +141,8 @@ func MarshalGPCMLoginTicket(profileId uint32) string { } func UnmarshalGPCMLoginTicket(ticket string) (profileId uint32, issuetime time.Time, err error) { - err = nil - - blob, err := Base64DwcEncoding.DecodeString(ticket) + var blob []byte + blob, err = Base64DwcEncoding.DecodeString(ticket) if err != nil { return } @@ -155,7 +152,8 @@ func UnmarshalGPCMLoginTicket(ticket string) (profileId uint32, issuetime time.T return } - block, err := aes.NewCipher(loginTicketKey) + var block cipher.Block + block, err = aes.NewCipher(loginTicketKey) if err != nil { panic(err) } diff --git a/common/match_command.go b/common/match_command.go index 94c6e07..6402d6d 100644 --- a/common/match_command.go +++ b/common/match_command.go @@ -560,7 +560,8 @@ func EncodeMatchCommand(command byte, data MatchCommandData) ([]byte, bool) { message = binary.BigEndian.AppendUint32(message, data.Reservation.PublicIP) message = binary.LittleEndian.AppendUint32(message, uint32(data.Reservation.PublicPort)) - if version == 11 { + switch version { + case 11: isFriendInt := uint32(0) if data.Reservation.IsFriend { isFriendInt = 1 @@ -568,7 +569,7 @@ func EncodeMatchCommand(command byte, data MatchCommandData) ([]byte, bool) { message = binary.LittleEndian.AppendUint32(message, isFriendInt) message = binary.LittleEndian.AppendUint32(message, data.Reservation.LocalPlayerCount) - } else if version == 90 { + case 90: message = binary.BigEndian.AppendUint32(message, data.Reservation.LocalIP) message = binary.LittleEndian.AppendUint32(message, uint32(data.Reservation.LocalPort)) message = binary.LittleEndian.AppendUint32(message, data.Reservation.Unknown) diff --git a/common/misc.go b/common/misc.go index d640695..1403477 100644 --- a/common/misc.go +++ b/common/misc.go @@ -2,9 +2,19 @@ package common import "reflect" -func MaybeUnused(v ...interface{}) { +// MaybeUnused is a helper function to mark variables as used to avoid compiler warnings. +func MaybeUnused(v ...interface{}) struct{} { + return struct{}{} } +// ShouldNotError panics if the error is not nil. +func ShouldNotError(err error) { + if err != nil { + panic(err) + } +} + +// ReverseMap takes a map and returns a new map with the keys and values reversed. func ReverseMap(m interface{}) interface{} { inputType := reflect.TypeOf(m) inputValue := reflect.ValueOf(m)