enumerate guild members on sign server

This commit is contained in:
wish
2022-07-17 04:52:36 +10:00
parent b0b39eb4f8
commit 92687a9fd6
2 changed files with 31 additions and 23 deletions

View File

@@ -113,7 +113,7 @@ type members struct {
Name string `db:"name"`
}
func (s *Server) getFriendsForCharacters(chars []character) ([]members, error) {
func (s *Server) getFriendsForCharacters(chars []character) ([]members) {
friends := make([]members, 0)
for _, char := range chars {
friendsCSV := ""
@@ -139,27 +139,35 @@ func (s *Server) getFriendsForCharacters(chars []character) ([]members, error) {
if len(friends) > 255 { // Uint8
friends = friends[:255]
}
return friends, nil
return friends
}
func (s *Server) getGuildmatesForCharacter(cid uint32) ([]members, error) {
guildmates := []members{}
var inGuild int
_ = s.db.QueryRow("SELECT count(*) FROM guild_characters WHERE character_id=$1", cid).Scan(&inGuild)
if inGuild > 0 {
var guildID int
err := s.db.QueryRow("SELECT guild_id FROM guild_characters WHERE character_id=$1", cid).Scan(&guildID)
if err != nil {
return nil, err
}
err = s.db.Select(&guildmates, "SELECT character_id AS id, c.name FROM guild_characters gc JOIN characters c ON c.id = gc.character_id WHERE guild_id=$1 AND character_id!=$2", guildID, cid)
if err != nil {
return nil, err
}
return guildmates, nil
} else {
return nil, nil
func (s *Server) getGuildmatesForCharacters(chars []character) ([]members) {
guildmates := make([]members, 0)
for _, char := range chars {
var inGuild int
_ = s.db.QueryRow("SELECT count(*) FROM guild_characters WHERE character_id=$1", char.ID).Scan(&inGuild)
if inGuild > 0 {
var guildID int
err := s.db.QueryRow("SELECT guild_id FROM guild_characters WHERE character_id=$1", char.ID).Scan(&guildID)
if err != nil {
continue
}
charGuildmates := []members{}
err = s.db.Select(&charGuildmates, "SELECT character_id AS id, c.name FROM guild_characters gc JOIN characters c ON c.id = gc.character_id WHERE guild_id=$1 AND character_id!=$2", guildID, char.ID)
if err != nil {
continue
}
for i, _ := range charGuildmates {
charGuildmates[i].CID = char.ID
}
guildmates = append(guildmates, charGuildmates...)
}
}
if len(guildmates) > 255 { // Uint8
guildmates = guildmates[:255]
}
return guildmates
}
func (s *Server) deleteCharacter(cid int, token string) error {

View File

@@ -75,8 +75,8 @@ func (s *Session) makeSignInResp(uid int) []byte {
bf.WriteUint16(0) // Unk
}
friends, err := s.server.getFriendsForCharacters(chars)
if err != nil || len(friends) == 0 {
friends := s.server.getFriendsForCharacters(chars)
if len(friends) == 0 {
bf.WriteUint8(0)
} else {
bf.WriteUint8(uint8(len(friends)))
@@ -87,8 +87,8 @@ func (s *Session) makeSignInResp(uid int) []byte {
}
}
guildmates, err := s.server.getGuildmatesForCharacters(chars)
if err != nil || len(guildmates) == 0 {
guildmates := s.server.getGuildmatesForCharacters(chars)
if len(guildmates) == 0 {
bf.WriteUint8(0)
} else {
bf.WriteUint8(uint8(len(guildmates)))