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"` Name string `db:"name"`
} }
func (s *Server) getFriendsForCharacters(chars []character) ([]members, error) { func (s *Server) getFriendsForCharacters(chars []character) ([]members) {
friends := make([]members, 0) friends := make([]members, 0)
for _, char := range chars { for _, char := range chars {
friendsCSV := "" friendsCSV := ""
@@ -139,27 +139,35 @@ func (s *Server) getFriendsForCharacters(chars []character) ([]members, error) {
if len(friends) > 255 { // Uint8 if len(friends) > 255 { // Uint8
friends = friends[:255] friends = friends[:255]
} }
return friends, nil return friends
} }
func (s *Server) getGuildmatesForCharacter(cid uint32) ([]members, error) { func (s *Server) getGuildmatesForCharacters(chars []character) ([]members) {
guildmates := []members{} guildmates := make([]members, 0)
for _, char := range chars {
var inGuild int var inGuild int
_ = s.db.QueryRow("SELECT count(*) FROM guild_characters WHERE character_id=$1", cid).Scan(&inGuild) _ = s.db.QueryRow("SELECT count(*) FROM guild_characters WHERE character_id=$1", char.ID).Scan(&inGuild)
if inGuild > 0 { if inGuild > 0 {
var guildID int var guildID int
err := s.db.QueryRow("SELECT guild_id FROM guild_characters WHERE character_id=$1", cid).Scan(&guildID) err := s.db.QueryRow("SELECT guild_id FROM guild_characters WHERE character_id=$1", char.ID).Scan(&guildID)
if err != nil { if err != nil {
return nil, err continue
} }
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) 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 { if err != nil {
return nil, err continue
} }
return guildmates, nil for i, _ := range charGuildmates {
} else { charGuildmates[i].CID = char.ID
return nil, nil
} }
guildmates = append(guildmates, charGuildmates...)
}
}
if len(guildmates) > 255 { // Uint8
guildmates = guildmates[:255]
}
return guildmates
} }
func (s *Server) deleteCharacter(cid int, token string) error { 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 bf.WriteUint16(0) // Unk
} }
friends, err := s.server.getFriendsForCharacters(chars) friends := s.server.getFriendsForCharacters(chars)
if err != nil || len(friends) == 0 { if len(friends) == 0 {
bf.WriteUint8(0) bf.WriteUint8(0)
} else { } else {
bf.WriteUint8(uint8(len(friends))) bf.WriteUint8(uint8(len(friends)))
@@ -87,8 +87,8 @@ func (s *Session) makeSignInResp(uid int) []byte {
} }
} }
guildmates, err := s.server.getGuildmatesForCharacters(chars) guildmates := s.server.getGuildmatesForCharacters(chars)
if err != nil || len(guildmates) == 0 { if len(guildmates) == 0 {
bf.WriteUint8(0) bf.WriteUint8(0)
} else { } else {
bf.WriteUint8(uint8(len(guildmates))) bf.WriteUint8(uint8(len(guildmates)))