sign server utilities

This commit is contained in:
wish
2022-07-17 04:14:39 +10:00
parent d95e39ed1b
commit 9370a4bd45
4 changed files with 26 additions and 5 deletions

View File

@@ -175,6 +175,11 @@ func handleMsgSysLogin(s *Session, p mhfpacket.MHFPacket) {
panic(err)
}
_, err = s.server.db.Exec("UPDATE users SET last_character=$1 FROM users u INNER JOIN characters c ON c.user_id = u.id WHERE c.id=$1", s.charID)
if err != nil {
panic(err)
}
s.server.BroadcastMHF(&mhfpacket.MsgSysInsertUser {
CharID: s.charID,
}, s)

View File

@@ -95,6 +95,18 @@ func (s *Server) getCharactersForUser(uid int) ([]character, error) {
return characters, nil
}
func (s *Server) getLastCID(uid int) uint32 {
var lastPlayed uint32
_ = s.db.QueryRow("SELECT last_character FROM users WHERE id=$1", uid).Scan(&lastPlayed)
return lastPlayed
}
func (s *Server) getUserRights(uid int) uint32 {
var rights uint32
_ = s.db.QueryRow("SELECT rights FROM users WHERE id=$1", uid).Scan(&rights)
return rights
}
type members struct {
CID uint32 // Local character ID
ID uint32 `db:"id"`

View File

@@ -87,12 +87,13 @@ func (s *Session) makeSignInResp(uid int) []byte {
}
}
guildmates, err := s.server.getGuildmatesForCharacter(lastPlayed)
if err != nil || guildmates == nil {
guildmates, err := s.server.getGuildmatesForCharacters(chars)
if err != nil || len(guildmates) == 0 {
bf.WriteUint8(0)
} else {
bf.WriteUint8(uint8(len(guildmates)))
for _, guildmate := range guildmates {
bf.WriteUint32(lastPlayed)
bf.WriteUint32(guildmate.CID)
bf.WriteUint32(guildmate.ID)
ps.Uint8(bf, guildmate.Name, true)
}
@@ -103,8 +104,8 @@ func (s *Session) makeSignInResp(uid int) []byte {
// noticeText := "<BODY><CENTER><SIZE_3><C_4>Welcome to Erupe SU9!<BR><BODY><LEFT><SIZE_2><C_5>Erupe is experimental software<C_7>, we are not liable for any<BR><BODY>issues caused by installing the software!<BR><BODY><BR><BODY><C_4>■Report bugs on Discord!<C_7><BR><BODY><BR><BODY><C_4>■Test everything!<C_7><BR><BODY><BR><BODY><C_4>■Don't talk to softlocking NPCs!<C_7><BR><BODY><BR><BODY><C_4>■Fork the code on GitHub!<C_7><BR><BODY><BR><BODY>Thank you to all of the contributors,<BR><BODY><BR><BODY>this wouldn't exist without you."
// ps.Uint32(bf, noticeText, true)
bf.WriteUint32(lastPlayed) // last played character id
bf.WriteUint32(14) // course bitfield
bf.WriteUint32(s.server.getLastCID(uid)) // last played character id
bf.WriteUint32(s.server.getUserRights(uid)) // course bitfield
ps.Uint16(bf, "", false) // filters
bf.WriteUint32(0xCA104E20)
ps.Uint16(bf, "", false) // encryption

View File

@@ -23,4 +23,7 @@ ALTER TABLE IF EXISTS public.characters
ALTER TABLE IF EXISTS public.characters
ADD COLUMN friends text NOT NULL DEFAULT '';
ALTER TABLE IF EXISTS public.users
ADD COLUMN last_character int DEFAULT 0;
END;