From 670f8f7882fb2c8c03fcf8a2719656999b3ab740 Mon Sep 17 00:00:00 2001 From: wish Date: Sun, 4 Sep 2022 18:12:51 +1000 Subject: [PATCH] update schema to merge existing data, move trophy --- patch-schema/persistent-house.sql | 20 +++++++++++++++++++- server/channelserver/handlers_house.go | 14 +++----------- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/patch-schema/persistent-house.sql b/patch-schema/persistent-house.sql index ee26333ee..43a02da91 100644 --- a/patch-schema/persistent-house.sql +++ b/patch-schema/persistent-house.sql @@ -13,7 +13,25 @@ CREATE TABLE IF NOT EXISTS public.user_binary bookshelf bytea, gallery bytea, tore bytea, - garden bytea + garden bytea, + mission bytea ); +-- Create entries for existing users +INSERT INTO public.user_binary (id) SELECT c.id FROM characters c; + +-- Copy existing data +UPDATE public.user_binary + SET house_furniture = (SELECT house FROM characters WHERE user_binary.id = characters.id); + +UPDATE public.user_binary + SET mission = (SELECT trophy FROM characters WHERE user_binary.id = characters.id); + +-- Drop old data location +ALTER TABLE public.characters + DROP COLUMN house; + +ALTER TABLE public.characters + DROP COLUMN trophy; + END; \ No newline at end of file diff --git a/server/channelserver/handlers_house.go b/server/channelserver/handlers_house.go index 7d5bda529..5236f197d 100644 --- a/server/channelserver/handlers_house.go +++ b/server/channelserver/handlers_house.go @@ -189,26 +189,18 @@ func handleMsgMhfLoadHouse(s *Session, p mhfpacket.MHFPacket) { func handleMsgMhfGetMyhouseInfo(s *Session, p mhfpacket.MHFPacket) { pkt := p.(*mhfpacket.MsgMhfGetMyhouseInfo) - var data []byte - err := s.server.db.QueryRow("SELECT trophy FROM characters WHERE id = $1", s.charID).Scan(&data) - if err != nil { - panic(err) - } + s.server.db.QueryRow(`SELECT mission FROM user_binary WHERE id=$1`, s.charID).Scan(&data) if len(data) > 0 { doAckBufSucceed(s, pkt.AckHandle, data) } else { - doAckBufSucceed(s, pkt.AckHandle, []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}) + doAckBufSucceed(s, pkt.AckHandle, make([]byte, 9)) } } func handleMsgMhfUpdateMyhouseInfo(s *Session, p mhfpacket.MHFPacket) { pkt := p.(*mhfpacket.MsgMhfUpdateMyhouseInfo) - - _, err := s.server.db.Exec("UPDATE characters SET trophy=$1 WHERE id=$2", pkt.Unk0, s.charID) - if err != nil { - panic(err) - } + s.server.db.Exec("UPDATE user_binary SET mission=$1 WHERE id=$2", pkt.Unk0, s.charID) doAckSimpleSucceed(s, pkt.AckHandle, []byte{0x00, 0x00, 0x00, 0x00}) }