Move custom kick and ban error messages to error.go

This commit is contained in:
ppeb 2025-03-03 20:23:48 -06:00
parent 3144bd7cf8
commit 95360023a5
No known key found for this signature in database
GPG Key ID: CC147AD1B3D318D0
5 changed files with 30 additions and 33 deletions

View File

@ -91,16 +91,7 @@ func handleBanImpl(r *http.Request) (bool, string, int) {
return false, "Failed to ban user", http.StatusInternalServerError
}
gpcm.KickPlayerCustomMessage(req.Pid, req.Reason, gpcm.WWFCErrorMessage{
ErrorCode: 22002,
MessageRMC: map[byte]string{
gpcm.LangEnglish: "" +
"You have been banned from WiiLink WFC\n" +
"Reason: " + req.Reason + "\n" +
"Error Code: %[1]d\n" +
"Support Info: NG%08[2]x",
},
})
gpcm.KickPlayerCustomMessage(req.Pid, req.Reason, gpcm.WWFCMsgProfileRestrictedCustom)
return true, "", http.StatusOK
}

View File

@ -67,16 +67,7 @@ func handleKickImpl(r *http.Request) (bool, string, int) {
return false, "Missing kick reason in request", http.StatusBadRequest
}
gpcm.KickPlayerCustomMessage(req.Pid, "moderator_kick", gpcm.WWFCErrorMessage{
ErrorCode: 22004,
MessageRMC: map[byte]string{
gpcm.LangEnglish: "" +
"You have been kicked from\n" +
"WiiLink WFC by a moderator.\n" +
"Reason: " + req.Reason + "\n" +
"Error Code: %[1]d",
},
})
gpcm.KickPlayerCustomMessage(req.Pid, req.Reason, gpcm.WWFCMsgKickedCustom)
return true, "", http.StatusOK
}

View File

@ -35,6 +35,7 @@ type GPError struct {
ErrorString string
Fatal bool
WWFCMessage WWFCErrorMessage
Reason string
}
func MakeGPError(errorCode int, errorString string, fatal bool) GPError {
@ -247,6 +248,17 @@ var (
},
}
WWFCMsgProfileRestrictedCustom = WWFCErrorMessage{
ErrorCode: 22002,
MessageRMC: map[byte]string{
LangEnglish: "" +
"You have been banned from WiiLink WFC\n" +
"Error Code: %[1]d\n" +
"Support Info: NG%08[2]x\n" +
"Reason: %s",
},
}
WWFCMsgKickedGeneric = WWFCErrorMessage{
ErrorCode: 22004,
MessageRMC: map[byte]string{
@ -281,6 +293,17 @@ var (
},
}
WWFCMsgKickedCustom = WWFCErrorMessage{
ErrorCode: 22002,
MessageRMC: map[byte]string{
LangEnglish: "" +
"You have been kicked from WiiLink WFC\n" +
"Error Code: %[1]d\n" +
"Support Info: NG%08[2]x\n" +
"Reason: %s",
},
}
WWFCMsgConsoleMismatch = WWFCErrorMessage{
ErrorCode: 22005,
MessageRMC: map[byte]string{
@ -405,7 +428,7 @@ func (err GPError) GetMessageTranslate(gameName string, region byte, lang byte,
errMsg = err.WWFCMessage.MessageRMC[LangEnglish]
}
errMsg = fmt.Sprintf(errMsg, err.WWFCMessage.ErrorCode, ngid)
errMsg = fmt.Sprintf(errMsg, err.WWFCMessage.ErrorCode, ngid, err.Reason)
errMsgUTF16 := utf16.Encode([]rune(errMsg))
errMsgByteArray := common.UTF16ToByteArray(errMsgUTF16)

View File

@ -50,7 +50,6 @@ func KickPlayer(profileID uint32, reason string) {
kickPlayer(profileID, reason)
}
// Exists because the above function is used in too many places to be updated easily
func KickPlayerCustomMessage(profileID uint32, reason string, message WWFCErrorMessage) {
mutex.Lock()
defer mutex.Unlock()
@ -61,6 +60,7 @@ func KickPlayerCustomMessage(profileID uint32, reason string, message WWFCErrorM
ErrorString: "The player was kicked from the server. Reason: " + reason,
Fatal: true,
WWFCMessage: message,
Reason: reason,
})
}
}

View File

@ -474,18 +474,10 @@ func (g *GameSpySession) performLoginWithDatabase(userId uint64, gsbrCode string
} else if err == database.ErrProfileBannedTOS {
g.replyError(GPError{
ErrorCode: ErrLogin.ErrorCode,
ErrorString: "The profile is banned from the service.",
ErrorString: "The profile is banned from the service. Reason: " + user.BanReason,
Fatal: true,
WWFCMessage: WWFCErrorMessage{
ErrorCode: 22002,
MessageRMC: map[byte]string{
LangEnglish: "" +
"You are banned from WiiLink WFC\n" +
"Reason: " + user.BanReason + "\n" +
"Error Code: %[1]d\n" +
"Support Info: NG%08[2]x",
},
},
WWFCMessage: WWFCMsgKickedCustom,
Reason: user.BanReason,
})
} else {
g.replyError(GPError{