diff --git a/common/mhfcourse/mhfcourse.go b/common/mhfcourse/mhfcourse.go index 62b8d171f..13496119b 100644 --- a/common/mhfcourse/mhfcourse.go +++ b/common/mhfcourse/mhfcourse.go @@ -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 diff --git a/config.json b/config.json index 5571a2890..c29b0f31e 100644 --- a/config.json +++ b/config.json @@ -72,6 +72,10 @@ "Name": "Course", "Enabled": true, "Prefix": "!course" + }, { + "Name": "LinkPSN", + "Enabled": true, + "Prefix": "!linkpsn" } ], "Courses": [ diff --git a/patch-schema/psn-id.sql b/patch-schema/psn-id.sql new file mode 100644 index 000000000..49ae1bdd8 --- /dev/null +++ b/patch-schema/psn-id.sql @@ -0,0 +1,5 @@ +BEGIN; + +ALTER TABLE users ADD COLUMN IF NOT EXISTS psn_id TEXT; + +END; \ No newline at end of file diff --git a/server/channelserver/handlers_cast_binary.go b/server/channelserver/handlers_cast_binary.go index 1b6b9a6ba..5db1e846f 100644 --- a/server/channelserver/handlers_cast_binary.go +++ b/server/channelserver/handlers_cast_binary.go @@ -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 { diff --git a/server/channelserver/sys_language.go b/server/channelserver/sys_language.go index 5de05923f..4246a929a 100644 --- a/server/channelserver/sys_language.go +++ b/server/channelserver/sys_language.go @@ -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 " + 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 " + strings["commandLinkPSNSuccess"] = "Connected PSN ID: %s" strings["commandRaviNoCommand"] = "No Raviente command specified!" strings["commandRaviStartSuccess"] = "The Great Slaying will begin in a moment" diff --git a/server/signserver/session.go b/server/signserver/session.go index 3e35708a6..a3906481e 100644 --- a/server/signserver/session.go +++ b/server/signserver/session.go @@ -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) {