Common: Apply lint suggestions

This commit is contained in:
Palapeli
2026-04-06 07:05:08 -04:00
parent 7af300510e
commit ca525e9f61
3 changed files with 18 additions and 9 deletions

View File

@@ -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)
}

View File

@@ -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)

View File

@@ -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)