mirror of
https://github.com/Mezeporta/Erupe.git
synced 2025-12-14 07:55:33 +01:00
Merge remote-tracking branch 'origin/main' into feature/psn-link
# Conflicts: # server/signserver/dbutils.go # server/signserver/dsgn_resp.go # server/signserver/session.go
This commit is contained in:
@@ -12,15 +12,9 @@ import (
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
)
|
||||
|
||||
func (s *Server) newUserChara(username string) error {
|
||||
var id int
|
||||
err := s.db.QueryRow("SELECT id FROM users WHERE username = $1", username).Scan(&id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *Server) newUserChara(uid int) error {
|
||||
var numNewChars int
|
||||
err = s.db.QueryRow("SELECT COUNT(*) FROM characters WHERE user_id = $1 AND is_new_character = true", id).Scan(&numNewChars)
|
||||
err := s.db.QueryRow("SELECT COUNT(*) FROM characters WHERE user_id = $1 AND is_new_character = true", uid).Scan(&numNewChars)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -35,7 +29,7 @@ func (s *Server) newUserChara(username string) error {
|
||||
user_id, is_female, is_new_character, name, unk_desc_string,
|
||||
hrp, gr, weapon_type, last_login)
|
||||
VALUES($1, False, True, '', '', 0, 0, 0, $2)`,
|
||||
id,
|
||||
uid,
|
||||
uint32(time.Now().Unix()),
|
||||
)
|
||||
if err != nil {
|
||||
@@ -60,19 +54,6 @@ func (s *Server) registerDBAccount(username string, password string) (uint32, er
|
||||
return 0, err
|
||||
}
|
||||
|
||||
// Create a base new character.
|
||||
_, err = s.db.Exec(`
|
||||
INSERT INTO characters (
|
||||
user_id, is_female, is_new_character, name, unk_desc_string,
|
||||
hrp, gr, weapon_type, last_login)
|
||||
VALUES($1, False, True, '', '', 0, 0, 0, $2)`,
|
||||
uid,
|
||||
uint32(time.Now().Unix()),
|
||||
)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return uid, nil
|
||||
}
|
||||
|
||||
@@ -90,7 +71,7 @@ type character struct {
|
||||
|
||||
func (s *Server) getCharactersForUser(uid uint32) ([]character, error) {
|
||||
characters := make([]character, 0)
|
||||
err := s.db.Select(&characters, "SELECT id, is_female, is_new_character, name, unk_desc_string, hrp, gr, weapon_type, last_login FROM characters WHERE user_id = $1 AND deleted = false ORDER BY id ASC", uid)
|
||||
err := s.db.Select(&characters, "SELECT id, is_female, is_new_character, name, unk_desc_string, hrp, gr, weapon_type, last_login FROM characters WHERE user_id = $1 AND deleted = false ORDER BY id", uid)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -158,9 +139,6 @@ func (s *Server) getFriendsForCharacters(chars []character) []members {
|
||||
}
|
||||
friends = append(friends, charFriends...)
|
||||
}
|
||||
if len(friends) > 255 { // Uint8
|
||||
friends = friends[:255]
|
||||
}
|
||||
return friends
|
||||
}
|
||||
|
||||
@@ -180,15 +158,12 @@ func (s *Server) getGuildmatesForCharacters(chars []character) []members {
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
for i, _ := range charGuildmates {
|
||||
for i := range charGuildmates {
|
||||
charGuildmates[i].CID = char.ID
|
||||
}
|
||||
guildmates = append(guildmates, charGuildmates...)
|
||||
}
|
||||
}
|
||||
if len(guildmates) > 255 { // Uint8
|
||||
guildmates = guildmates[:255]
|
||||
}
|
||||
return guildmates
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"erupe-ce/common/byteframe"
|
||||
ps "erupe-ce/common/pascalstring"
|
||||
"erupe-ce/common/stringsupport"
|
||||
_config "erupe-ce/config"
|
||||
"erupe-ce/server/channelserver"
|
||||
"fmt"
|
||||
"go.uber.org/zap"
|
||||
@@ -13,6 +14,12 @@ import (
|
||||
func (s *Session) makeSignResponse(uid uint32) []byte {
|
||||
// Get the characters from the DB.
|
||||
chars, err := s.server.getCharactersForUser(uid)
|
||||
if len(chars) == 0 {
|
||||
err = s.server.newUserChara(uid)
|
||||
if err == nil {
|
||||
chars, err = s.server.getCharactersForUser(uid)
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
s.logger.Warn("Error getting characters from DB", zap.Error(err))
|
||||
}
|
||||
@@ -30,7 +37,7 @@ func (s *Session) makeSignResponse(uid uint32) []byte {
|
||||
return bf.Data()
|
||||
}
|
||||
|
||||
bf.WriteUint8(1) // resp_code
|
||||
bf.WriteUint8(uint8(SIGN_SUCCESS)) // resp_code
|
||||
if (s.server.erupeConfig.PatchServerManifest != "" && s.server.erupeConfig.PatchServerFile != "") || s.client == PS3 {
|
||||
bf.WriteUint8(2)
|
||||
} else {
|
||||
@@ -78,15 +85,23 @@ func (s *Session) makeSignResponse(uid uint32) []byte {
|
||||
bf.WriteBool(true) // Use uint16 GR, no reason not to
|
||||
bf.WriteBytes(stringsupport.PaddedString(char.Name, 16, true)) // Character name
|
||||
bf.WriteBytes(stringsupport.PaddedString(char.UnkDescString, 32, false)) // unk str
|
||||
bf.WriteUint16(char.GR)
|
||||
bf.WriteUint16(0) // Unk
|
||||
if s.server.erupeConfig.RealClientMode >= _config.G7 {
|
||||
bf.WriteUint16(char.GR)
|
||||
bf.WriteUint8(0) // Unk
|
||||
bf.WriteUint8(0) // Unk
|
||||
}
|
||||
}
|
||||
|
||||
friends := s.server.getFriendsForCharacters(chars)
|
||||
if len(friends) == 0 {
|
||||
bf.WriteUint8(0)
|
||||
} else {
|
||||
bf.WriteUint8(uint8(len(friends)))
|
||||
if len(friends) > 255 {
|
||||
bf.WriteUint8(255)
|
||||
bf.WriteUint16(uint16(len(friends)))
|
||||
} else {
|
||||
bf.WriteUint8(uint8(len(friends)))
|
||||
}
|
||||
for _, friend := range friends {
|
||||
bf.WriteUint32(friend.CID)
|
||||
bf.WriteUint32(friend.ID)
|
||||
@@ -98,7 +113,12 @@ func (s *Session) makeSignResponse(uid uint32) []byte {
|
||||
if len(guildmates) == 0 {
|
||||
bf.WriteUint8(0)
|
||||
} else {
|
||||
bf.WriteUint8(uint8(len(guildmates)))
|
||||
if len(guildmates) > 255 {
|
||||
bf.WriteUint8(255)
|
||||
bf.WriteUint16(uint16(len(guildmates)))
|
||||
} else {
|
||||
bf.WriteUint8(uint8(len(guildmates)))
|
||||
}
|
||||
for _, guildmate := range guildmates {
|
||||
bf.WriteUint32(guildmate.CID)
|
||||
bf.WriteUint32(guildmate.ID)
|
||||
@@ -107,12 +127,12 @@ func (s *Session) makeSignResponse(uid uint32) []byte {
|
||||
}
|
||||
|
||||
if s.server.erupeConfig.HideLoginNotice {
|
||||
bf.WriteUint8(0)
|
||||
bf.WriteBool(false)
|
||||
} else {
|
||||
bf.WriteUint8(uint8(len(s.server.erupeConfig.LoginNotices)))
|
||||
for _, notice := range s.server.erupeConfig.LoginNotices {
|
||||
ps.Uint32(bf, notice, true)
|
||||
}
|
||||
bf.WriteBool(true)
|
||||
bf.WriteUint8(0)
|
||||
bf.WriteUint8(0)
|
||||
ps.Uint16(bf, strings.Join(s.server.erupeConfig.LoginNotices[:], "<PAGE>"), true)
|
||||
}
|
||||
|
||||
bf.WriteUint32(s.server.getLastCID(uid))
|
||||
@@ -132,35 +152,37 @@ func (s *Session) makeSignResponse(uid uint32) []byte {
|
||||
bf.WriteUint16(0x4E20)
|
||||
ps.Uint16(bf, "", false) // unk ipv4
|
||||
bf.WriteUint32(uint32(s.server.getReturnExpiry(uid).Unix()))
|
||||
bf.WriteUint32(0x00000000)
|
||||
bf.WriteUint32(0x0A5197DF) // unk id
|
||||
bf.WriteUint32(0)
|
||||
|
||||
mezfes := s.server.erupeConfig.DevModeOptions.MezFesEvent
|
||||
alt := s.server.erupeConfig.DevModeOptions.MezFesAlt
|
||||
if mezfes {
|
||||
// We can just use the start timestamp as the event ID
|
||||
bf.WriteUint32(uint32(channelserver.TimeWeekStart().Unix()))
|
||||
// Start time
|
||||
bf.WriteUint32(uint32(channelserver.TimeWeekStart().Unix()))
|
||||
// End time
|
||||
bf.WriteUint32(uint32(channelserver.TimeWeekNext().Unix()))
|
||||
bf.WriteUint8(2) // Unk
|
||||
bf.WriteUint32(20) // Single tickets
|
||||
bf.WriteUint32(10) // Group tickets
|
||||
bf.WriteUint8(8) // Stalls open
|
||||
bf.WriteUint8(0xA) // Unk
|
||||
bf.WriteUint8(0x3) // Pachinko
|
||||
bf.WriteUint8(0x6) // Nyanrendo
|
||||
bf.WriteUint8(0x9) // Point stall
|
||||
bf.WriteUint8(2) // Unk
|
||||
bf.WriteUint32(s.server.erupeConfig.GameplayOptions.MezfesSoloTickets)
|
||||
bf.WriteUint32(s.server.erupeConfig.GameplayOptions.MezfesGroupTickets)
|
||||
bf.WriteUint8(8) // Stalls open
|
||||
bf.WriteUint8(10) // Stall Map
|
||||
bf.WriteUint8(3) // Pachinko
|
||||
bf.WriteUint8(6) // Nyanrendo
|
||||
bf.WriteUint8(9) // Point stall
|
||||
if alt {
|
||||
bf.WriteUint8(0x2) // Tokotoko
|
||||
bf.WriteUint8(2) // Tokotoko Partnya
|
||||
} else {
|
||||
bf.WriteUint8(0x4) // Volpakkun
|
||||
bf.WriteUint8(4) // Volpakkun Together
|
||||
}
|
||||
bf.WriteUint8(0x8) // Battle cats
|
||||
bf.WriteUint8(0x5) // Gook
|
||||
bf.WriteUint8(0x7) // Honey
|
||||
bf.WriteUint8(8) // Dokkan Battle Cats
|
||||
bf.WriteUint8(5) // Goocoo Scoop
|
||||
bf.WriteUint8(7) // Honey Panic
|
||||
} else {
|
||||
bf.WriteUint32(0)
|
||||
bf.WriteUint32(0)
|
||||
bf.WriteUint32(0)
|
||||
}
|
||||
return bf.Data()
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ func (s *Session) handlePacket(pkt []byte) error {
|
||||
case "VITASGN:100":
|
||||
s.client = VITA
|
||||
s.handlePSSGN(bf)
|
||||
case "WIIUSGN:100":
|
||||
case "WIIUSGN:100", "WIIUSGN:000":
|
||||
s.client = WIIU
|
||||
s.handleWIIUSGN(bf)
|
||||
case "VITACOGLNK:100":
|
||||
@@ -124,6 +124,13 @@ func (s *Session) handleWIIUSGN(bf *byteframe.ByteFrame) {
|
||||
}
|
||||
|
||||
func (s *Session) handlePSSGN(bf *byteframe.ByteFrame) {
|
||||
// Prevent reading malformed request
|
||||
if len(bf.DataFromCurrent()) < 128 {
|
||||
resp := byteframe.NewByteFrame()
|
||||
resp.WriteUint8(uint8(SIGN_EABORT))
|
||||
s.cryptConn.SendPacket(resp.Data())
|
||||
return
|
||||
}
|
||||
_ = bf.ReadNullTerminatedBytes() // VITA = 0000000256, PS3 = 0000000255
|
||||
_ = bf.ReadBytes(2) // VITA = 1, PS3 = !
|
||||
_ = bf.ReadBytes(82)
|
||||
|
||||
@@ -16,14 +16,14 @@ import (
|
||||
type Config struct {
|
||||
Logger *zap.Logger
|
||||
DB *sqlx.DB
|
||||
ErupeConfig *config.Config
|
||||
ErupeConfig *_config.Config
|
||||
}
|
||||
|
||||
// Server is a MHF sign server.
|
||||
type Server struct {
|
||||
sync.Mutex
|
||||
logger *zap.Logger
|
||||
erupeConfig *config.Config
|
||||
erupeConfig *_config.Config
|
||||
sessions map[int]*Session
|
||||
db *sqlx.DB
|
||||
listener net.Listener
|
||||
|
||||
Reference in New Issue
Block a user