diff --git a/network/mhfpacket/msg_mhf_apply_campaign.go b/network/mhfpacket/msg_mhf_apply_campaign.go index 6df266f40..8ff93665a 100644 --- a/network/mhfpacket/msg_mhf_apply_campaign.go +++ b/network/mhfpacket/msg_mhf_apply_campaign.go @@ -3,6 +3,7 @@ package mhfpacket import ( "errors" "erupe-ce/common/byteframe" + "erupe-ce/common/stringsupport" "erupe-ce/network" "erupe-ce/network/clientctx" ) @@ -12,7 +13,7 @@ type MsgMhfApplyCampaign struct { AckHandle uint32 CampaignID uint32 NullPadding uint16 // set as 0 in z2 - CodeString []byte + CodeString string } // Opcode returns the ID associated with this packet type. @@ -25,7 +26,8 @@ func (m *MsgMhfApplyCampaign) Parse(bf *byteframe.ByteFrame, ctx *clientctx.Clie m.AckHandle = bf.ReadUint32() m.CampaignID = bf.ReadUint32() m.NullPadding = bf.ReadUint16() - m.CodeString = bf.ReadBytes(16) + m.CodeString = stringsupport.SJISToUTF8(bf.ReadNullTerminatedBytes()) + bf.ReadInt8() return nil } diff --git a/schemas/patch-schema/22-campaign.sql b/schemas/patch-schema/22-campaign.sql index 205fd3718..94fcf2966 100644 --- a/schemas/patch-schema/22-campaign.sql +++ b/schemas/patch-schema/22-campaign.sql @@ -58,7 +58,8 @@ CREATE TABLE IF NOT EXISTS public.campaign_category_links ( id SERIAL PRIMARY KEY, campaign_id INTEGER, state INTEGER, - character_id INTEGER + character_id INTEGER, + code TEXT ); INSERT INTO public.campaign_state diff --git a/server/channelserver/handlers_campaign.go b/server/channelserver/handlers_campaign.go index 929cb2f4c..a38b4a214 100644 --- a/server/channelserver/handlers_campaign.go +++ b/server/channelserver/handlers_campaign.go @@ -1,11 +1,14 @@ package channelserver import ( + "database/sql" "erupe-ce/common/byteframe" ps "erupe-ce/common/pascalstring" "erupe-ce/common/stringsupport" _config "erupe-ce/config" "erupe-ce/network/mhfpacket" + "fmt" + "log" "time" ) @@ -172,18 +175,25 @@ func handleMsgMhfStateCampaign(s *Session, p mhfpacket.MHFPacket) { func handleMsgMhfApplyCampaign(s *Session, p mhfpacket.MHFPacket) { pkt := p.(*mhfpacket.MsgMhfApplyCampaign) - // Check campaign ID - // Check code against campaign list of codes to see if valid.... - //checkCode(pkt.CodeString,pkt.CampaignID) + var result string - validCode := true - if validCode { - s.server.db.Exec(`UPDATE public.campaign_state SET state = $3 WHERE campaign_id = $1 AND character_id =$2`, pkt.CampaignID, s.charID, 1) + // Query to check if the event code exists in the database + err := s.server.db.QueryRow("SELECT code FROM public.campaign_state WHERE code = $1", pkt.CodeString).Scan(&result) + + switch { + case err == sql.ErrNoRows: + fmt.Println("Event code does not exist in the database.") + s.server.db.Exec(`UPDATE public.campaign_state SET state = $3, code = $4 WHERE campaign_id = $1 AND character_id =$2`, pkt.CampaignID, s.charID, 1, pkt.CodeString) doAckSimpleSucceed(s, pkt.AckHandle, make([]byte, 4)) - } else { + case err != nil: + log.Fatal(err) + default: + fmt.Printf("Event code '%s' exists in the database.\n", result) doAckSimpleFail(s, pkt.AckHandle, make([]byte, 4)) + } + } func handleMsgMhfEnumerateItem(s *Session, p mhfpacket.MHFPacket) { diff --git a/server/channelserver/handlers_quest.go b/server/channelserver/handlers_quest.go index a9063efc9..f0cc6b40e 100644 --- a/server/channelserver/handlers_quest.go +++ b/server/channelserver/handlers_quest.go @@ -275,7 +275,7 @@ func makeEventQuest(s *Session, rows *sql.Rows) ([]byte, error) { } bf.WriteUint8(questType) if questType == 9 { - var state int16 + var state int s.server.db.QueryRow(`SELECT state FROM campaign_state WHERE character_id = $2