implement psn linking capability

This commit is contained in:
wish
2023-04-15 11:00:49 +10:00
parent 69edc6f961
commit f5ae129cad
6 changed files with 39 additions and 3 deletions

View File

@@ -66,7 +66,7 @@ func CourseExists(ID uint16, c []Course) bool {
// GetCourseStruct returns a slice of Course(s) from a rights integer
func GetCourseStruct(rights uint32) ([]Course, uint32) {
resp := []Course{{ID: 1}}
resp := []Course{{ID: 1}, {ID: 24}}
s := Courses()
slices.SortStableFunc(s, func(i, j Course) bool {
return i.ID > j.ID

View File

@@ -72,6 +72,10 @@
"Name": "Course",
"Enabled": true,
"Prefix": "!course"
}, {
"Name": "LinkPSN",
"Enabled": true,
"Prefix": "!linkpsn"
}
],
"Courses": [

5
patch-schema/psn-id.sql Normal file
View File

@@ -0,0 +1,5 @@
BEGIN;
ALTER TABLE users ADD COLUMN IF NOT EXISTS psn_id TEXT;
END;

View File

@@ -82,6 +82,21 @@ func sendServerChatMessage(s *Session, message string) {
}
func parseChatCommand(s *Session, command string) {
if strings.HasPrefix(command, commands["LinkPSN"].Prefix) {
if commands["LinkPSN"].Enabled {
var id string
n, err := fmt.Sscanf(command, fmt.Sprintf("%s %%s", commands["LinkPSN"].Prefix), &id)
if err != nil || n != 1 {
sendServerChatMessage(s, fmt.Sprintf(s.server.dict["commandLinkPSNError"], commands["LinkPSN"].Prefix))
} else {
_, err = s.server.db.Exec(`UPDATE users u SET psn_id=$1 WHERE u.id=(SELECT c.user_id FROM characters c WHERE c.id=$2)`, id, s.charID)
if err == nil {
sendServerChatMessage(s, fmt.Sprintf(s.server.dict["commandLinkPSNSuccess"], id))
}
}
}
}
if strings.HasPrefix(command, commands["Reload"].Prefix) {
// Flush all objects and users and reload
if commands["Reload"].Enabled {

View File

@@ -20,6 +20,8 @@ func getLangStrings(s *Server) map[string]string {
strings["commandCourseLocked"] = "%sコースはロックされています"
strings["commandTeleportError"] = "テレポートコマンドエラー 構文:%s x y"
strings["commandTeleportSuccess"] = "%d %dにテレポート"
strings["commandLinkPSNError"] = "PSN連携コマンドエラー %s <psn id>"
strings["commandLinkPSNSuccess"] = "PSN「%s」が連携されています"
strings["commandRaviNoCommand"] = "ラヴィコマンドが指定されていません"
strings["commandRaviStartSuccess"] = "大討伐を開始します"
@@ -68,6 +70,8 @@ func getLangStrings(s *Server) map[string]string {
strings["commandCourseLocked"] = "%s Course is locked"
strings["commandTeleportError"] = "Error in command. Format: %s x y"
strings["commandTeleportSuccess"] = "Teleporting to %d %d"
strings["commandLinkPSNError"] = "Error in command. Format: %s <psn id>"
strings["commandLinkPSNSuccess"] = "Connected PSN ID: %s"
strings["commandRaviNoCommand"] = "No Raviente command specified!"
strings["commandRaviStartSuccess"] = "The Great Slaying will begin in a moment"

View File

@@ -102,7 +102,7 @@ func (s *Session) authenticate(username string, password string) {
bf.WriteUint8(uint8(SIGN_EABORT))
s.logger.Error("Error getting user details", zap.Error(err))
default:
if bcrypt.CompareHashAndPassword([]byte(hash), []byte(password)) == nil {
if bcrypt.CompareHashAndPassword([]byte(hash), []byte(password)) == nil || s.client == VITA {
s.logger.Debug("Passwords match!")
if newCharaReq {
err = s.server.newUserChara(username)
@@ -138,7 +138,15 @@ func (s *Session) handleVITASGN(bf *byteframe.ByteFrame) {
_ = bf.ReadNullTerminatedBytes() // 1
_ = bf.ReadBytes(82)
psnUser := string(bf.ReadNullTerminatedBytes())
s.authenticate(psnUser, "")
var reqUsername string
err := s.server.db.QueryRow(`SELECT username FROM users WHERE psn_id = $1`, psnUser).Scan(&reqUsername)
if err == sql.ErrNoRows {
resp := byteframe.NewByteFrame()
resp.WriteUint8(uint8(SIGN_ECOGLINK))
s.cryptConn.SendPacket(resp.Data())
return
}
s.authenticate(reqUsername, "")
}
func (s *Session) handleDSGN(bf *byteframe.ByteFrame) {