mirror of
https://github.com/Mezeporta/Erupe.git
synced 2025-12-23 20:35:04 +01:00
enumerate guild members on sign server
This commit is contained in:
@@ -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 {
|
||||||
|
|||||||
@@ -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)))
|
||||||
|
|||||||
Reference in New Issue
Block a user