diff --git a/network/mhfpacket/msg_mhf_enumerate_house.go b/network/mhfpacket/msg_mhf_enumerate_house.go index 9bd1f30ef..da6a25de7 100644 --- a/network/mhfpacket/msg_mhf_enumerate_house.go +++ b/network/mhfpacket/msg_mhf_enumerate_house.go @@ -29,8 +29,10 @@ func (m *MsgMhfEnumerateHouse) Parse(bf *byteframe.ByteFrame, ctx *clientctx.Cli m.CharID = bf.ReadUint32() m.Method = bf.ReadUint8() m.Unk = bf.ReadUint16() - _ = bf.ReadUint8() // len - m.Name = stringsupport.SJISToUTF8(bf.ReadNullTerminatedBytes()) + lenName := bf.ReadUint8() + if lenName > 0 { + m.Name = stringsupport.SJISToUTF8(bf.ReadNullTerminatedBytes()) + } return nil } diff --git a/server/channelserver/handlers_house.go b/server/channelserver/handlers_house.go index 5236f197d..03d961ef3 100644 --- a/server/channelserver/handlers_house.go +++ b/server/channelserver/handlers_house.go @@ -140,18 +140,55 @@ func handleMsgMhfUpdateHouse(s *Session, p mhfpacket.MHFPacket) { func handleMsgMhfLoadHouse(s *Session, p mhfpacket.MHFPacket) { pkt := p.(*mhfpacket.MsgMhfLoadHouse) bf := byteframe.NewByteFrame() + + var state uint8 + var password string + s.server.db.QueryRow(`SELECT COALESCE(house_state, 2) as house_state, COALESCE(house_password, '') as house_password FROM user_binary WHERE id=$1 + `, pkt.CharID).Scan(&state, &password) + if pkt.Destination != 9 && len(pkt.Password) > 0 && pkt.CheckPass { - var password string - err := s.server.db.Get(&password, `SELECT house_password FROM user_binary WHERE id=$1`, pkt.CharID) - if err != nil { - panic(err) - } if pkt.Password != password { doAckSimpleFail(s, pkt.AckHandle, make([]byte, 4)) return } } + if pkt.Destination != 9 && state > 2 { + allowed := false + + // Friends list verification + if state == 3 || state == 5 { + var friendsList string + s.server.db.QueryRow(`SELECT friends FROM characters WHERE id=$1`, pkt.CharID).Scan(&friendsList) + cids := stringsupport.CSVElems(friendsList) + for _, cid := range cids { + if uint32(cid) == s.charID { + allowed = true + break + } + } + } + + // Guild verification + if state > 3 { + ownGuild, err := GetGuildInfoByCharacterId(s, s.charID) + isApplicant, _ := ownGuild.HasApplicationForCharID(s, s.charID) + if err == nil && ownGuild != nil { + othersGuild, err := GetGuildInfoByCharacterId(s, pkt.CharID) + if err == nil && othersGuild != nil { + if othersGuild.ID == ownGuild.ID && !isApplicant { + allowed = true + } + } + } + } + + if !allowed { + doAckSimpleFail(s, pkt.AckHandle, make([]byte, 4)) + return + } + } + var houseTier, houseData, houseFurniture, bookshelf, gallery, tore, garden []byte s.server.db.QueryRow(`SELECT house_tier, house_data, house_furniture, bookshelf, gallery, tore, garden FROM user_binary WHERE id=$1 `, pkt.CharID).Scan(&houseTier, &houseData, &houseFurniture, &bookshelf, &gallery, &tore, &garden)