mirror of
https://github.com/Mezeporta/Erupe.git
synced 2026-03-27 10:03:06 +01:00
4
main.go
4
main.go
@@ -108,9 +108,11 @@ func main() {
|
|||||||
}
|
}
|
||||||
logger.Info("Connected to database")
|
logger.Info("Connected to database")
|
||||||
|
|
||||||
// Clear existing tokens
|
// Clear stale data
|
||||||
_ = db.MustExec("DELETE FROM sign_sessions")
|
_ = db.MustExec("DELETE FROM sign_sessions")
|
||||||
_ = db.MustExec("DELETE FROM servers")
|
_ = db.MustExec("DELETE FROM servers")
|
||||||
|
_ = db.MustExec("DELETE FROM cafe_accepted")
|
||||||
|
_ = db.MustExec("UPDATE characters SET cafe_time=0")
|
||||||
|
|
||||||
// Clean the DB if the option is on.
|
// Clean the DB if the option is on.
|
||||||
if erupeConfig.DevMode && erupeConfig.DevModeOptions.CleanDB {
|
if erupeConfig.DevMode && erupeConfig.DevModeOptions.CleanDB {
|
||||||
|
|||||||
@@ -1,15 +1,18 @@
|
|||||||
package mhfpacket
|
package mhfpacket
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
"erupe-ce/network/clientctx"
|
|
||||||
"erupe-ce/network"
|
|
||||||
"erupe-ce/common/byteframe"
|
"erupe-ce/common/byteframe"
|
||||||
|
"erupe-ce/network"
|
||||||
|
"erupe-ce/network/clientctx"
|
||||||
)
|
)
|
||||||
|
|
||||||
// MsgMhfPostCafeDurationBonusReceived represents the MSG_MHF_POST_CAFE_DURATION_BONUS_RECEIVED
|
// MsgMhfPostCafeDurationBonusReceived represents the MSG_MHF_POST_CAFE_DURATION_BONUS_RECEIVED
|
||||||
type MsgMhfPostCafeDurationBonusReceived struct{}
|
type MsgMhfPostCafeDurationBonusReceived struct {
|
||||||
|
AckHandle uint32
|
||||||
|
CafeBonusID []uint32
|
||||||
|
}
|
||||||
|
|
||||||
// Opcode returns the ID associated with this packet type.
|
// Opcode returns the ID associated with this packet type.
|
||||||
func (m *MsgMhfPostCafeDurationBonusReceived) Opcode() network.PacketID {
|
func (m *MsgMhfPostCafeDurationBonusReceived) Opcode() network.PacketID {
|
||||||
@@ -18,7 +21,12 @@ func (m *MsgMhfPostCafeDurationBonusReceived) Opcode() network.PacketID {
|
|||||||
|
|
||||||
// Parse parses the packet from binary
|
// Parse parses the packet from binary
|
||||||
func (m *MsgMhfPostCafeDurationBonusReceived) Parse(bf *byteframe.ByteFrame, ctx *clientctx.ClientContext) error {
|
func (m *MsgMhfPostCafeDurationBonusReceived) Parse(bf *byteframe.ByteFrame, ctx *clientctx.ClientContext) error {
|
||||||
return errors.New("NOT IMPLEMENTED")
|
m.AckHandle = bf.ReadUint32()
|
||||||
|
ids := int(bf.ReadUint32())
|
||||||
|
for i := 0; i < ids; i++ {
|
||||||
|
m.CafeBonusID = append(m.CafeBonusID, bf.ReadUint32())
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build builds a binary packet from the current data.
|
// Build builds a binary packet from the current data.
|
||||||
|
|||||||
@@ -1,15 +1,18 @@
|
|||||||
package mhfpacket
|
package mhfpacket
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
"erupe-ce/network/clientctx"
|
|
||||||
"erupe-ce/network"
|
|
||||||
"erupe-ce/common/byteframe"
|
"erupe-ce/common/byteframe"
|
||||||
|
"erupe-ce/network"
|
||||||
|
"erupe-ce/network/clientctx"
|
||||||
)
|
)
|
||||||
|
|
||||||
// MsgMhfStartBoostTime represents the MSG_MHF_START_BOOST_TIME
|
// MsgMhfStartBoostTime represents the MSG_MHF_START_BOOST_TIME
|
||||||
type MsgMhfStartBoostTime struct{}
|
type MsgMhfStartBoostTime struct {
|
||||||
|
AckHandle uint32
|
||||||
|
Unk0 uint32
|
||||||
|
}
|
||||||
|
|
||||||
// Opcode returns the ID associated with this packet type.
|
// Opcode returns the ID associated with this packet type.
|
||||||
func (m *MsgMhfStartBoostTime) Opcode() network.PacketID {
|
func (m *MsgMhfStartBoostTime) Opcode() network.PacketID {
|
||||||
@@ -18,7 +21,9 @@ func (m *MsgMhfStartBoostTime) Opcode() network.PacketID {
|
|||||||
|
|
||||||
// Parse parses the packet from binary
|
// Parse parses the packet from binary
|
||||||
func (m *MsgMhfStartBoostTime) Parse(bf *byteframe.ByteFrame, ctx *clientctx.ClientContext) error {
|
func (m *MsgMhfStartBoostTime) Parse(bf *byteframe.ByteFrame, ctx *clientctx.ClientContext) error {
|
||||||
return errors.New("NOT IMPLEMENTED")
|
m.AckHandle = bf.ReadUint32()
|
||||||
|
m.Unk0 = bf.ReadUint32()
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build builds a binary packet from the current data.
|
// Build builds a binary packet from the current data.
|
||||||
|
|||||||
40
patch-schema/netcafe.sql
Normal file
40
patch-schema/netcafe.sql
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
BEGIN;
|
||||||
|
|
||||||
|
ALTER TABLE IF EXISTS public.characters
|
||||||
|
ADD COLUMN IF NOT EXISTS cafe_time integer DEFAULT 0;
|
||||||
|
|
||||||
|
ALTER TABLE IF EXISTS public.characters
|
||||||
|
DROP COLUMN IF EXISTS netcafe_points;
|
||||||
|
|
||||||
|
ALTER TABLE IF EXISTS public.characters
|
||||||
|
ADD COLUMN IF NOT EXISTS netcafe_points int DEFAULT 0;
|
||||||
|
|
||||||
|
ALTER TABLE IF EXISTS public.characters
|
||||||
|
ADD COLUMN IF NOT EXISTS boost_time timestamp without time zone;
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS public.cafebonus
|
||||||
|
(
|
||||||
|
id serial NOT NULL PRIMARY KEY,
|
||||||
|
time_req integer NOT NULL,
|
||||||
|
item_type integer NOT NULL,
|
||||||
|
item_id integer NOT NULL,
|
||||||
|
quantity integer NOT NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS public.cafe_accepted
|
||||||
|
(
|
||||||
|
cafe_id integer NOT NULL,
|
||||||
|
character_id integer NOT NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
INSERT INTO public.cafebonus (time_req, item_type, item_id, quantity)
|
||||||
|
VALUES
|
||||||
|
(1800, 17, 0, 250),
|
||||||
|
(3600, 17, 0, 500),
|
||||||
|
(7200, 17, 0, 1000),
|
||||||
|
(10800, 17, 0, 1500),
|
||||||
|
(18000, 17, 0, 1750),
|
||||||
|
(28800, 17, 0, 3000),
|
||||||
|
(43200, 17, 0, 4000);
|
||||||
|
|
||||||
|
END;
|
||||||
@@ -10,16 +10,14 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"io/ioutil"
|
|
||||||
"math/bits"
|
|
||||||
"math/rand"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"erupe-ce/common/byteframe"
|
"erupe-ce/common/byteframe"
|
||||||
"erupe-ce/network/mhfpacket"
|
"erupe-ce/network/mhfpacket"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
"golang.org/x/text/encoding/japanese"
|
"golang.org/x/text/encoding/japanese"
|
||||||
"golang.org/x/text/transform"
|
"golang.org/x/text/transform"
|
||||||
|
"io/ioutil"
|
||||||
|
"math/bits"
|
||||||
|
"math/rand"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Temporary function to just return no results for a MSG_MHF_ENUMERATE* packet
|
// Temporary function to just return no results for a MSG_MHF_ENUMERATE* packet
|
||||||
@@ -192,8 +190,12 @@ func handleMsgSysLogout(s *Session, p mhfpacket.MHFPacket) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func logoutPlayer(s *Session) {
|
func logoutPlayer(s *Session) {
|
||||||
delete(s.server.sessions, s.rawConn)
|
if _, exists := s.server.sessions[s.rawConn]; exists {
|
||||||
s.rawConn.Close()
|
delete(s.server.sessions, s.rawConn)
|
||||||
|
s.rawConn.Close()
|
||||||
|
} else {
|
||||||
|
return // Prevent re-running logout logic on real logouts
|
||||||
|
}
|
||||||
|
|
||||||
_, err := s.server.db.Exec("UPDATE sign_sessions SET server_id=NULL, char_id=NULL WHERE token=$1", s.token)
|
_, err := s.server.db.Exec("UPDATE sign_sessions SET server_id=NULL, char_id=NULL WHERE token=$1", s.token)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -206,13 +208,13 @@ func logoutPlayer(s *Session) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var timePlayed int
|
var timePlayed int
|
||||||
|
var sessionTime int
|
||||||
_ = s.server.db.QueryRow("SELECT time_played FROM characters WHERE id = $1", s.charID).Scan(&timePlayed)
|
_ = s.server.db.QueryRow("SELECT time_played FROM characters WHERE id = $1", s.charID).Scan(&timePlayed)
|
||||||
|
sessionTime = int(Time_Current_Adjusted().Unix()) - int(s.sessionStart)
|
||||||
timePlayed = (int(Time_Current_Adjusted().Unix()) - int(s.sessionStart)) + timePlayed
|
timePlayed += sessionTime
|
||||||
|
|
||||||
var rpGained int
|
var rpGained int
|
||||||
|
if s.rights >= 0x40000000 { // N Course
|
||||||
if s.rights > 0x40000000 { // N Course
|
|
||||||
rpGained = timePlayed / 900
|
rpGained = timePlayed / 900
|
||||||
timePlayed = timePlayed % 900
|
timePlayed = timePlayed % 900
|
||||||
} else {
|
} else {
|
||||||
@@ -220,10 +222,10 @@ func logoutPlayer(s *Session) {
|
|||||||
timePlayed = timePlayed % 1800
|
timePlayed = timePlayed % 1800
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = s.server.db.Exec("UPDATE characters SET time_played = $1 WHERE id = $2", timePlayed, s.charID)
|
s.server.db.Exec("UPDATE characters SET time_played = $1 WHERE id = $2", timePlayed, s.charID)
|
||||||
if err != nil {
|
s.server.db.Exec("UPDATE characters SET cafe_time=cafe_time+$1 WHERE id=$2", sessionTime, s.charID)
|
||||||
panic(err)
|
|
||||||
}
|
treasureHuntUnregister(s)
|
||||||
|
|
||||||
if s.stage == nil {
|
if s.stage == nil {
|
||||||
return
|
return
|
||||||
@@ -243,7 +245,6 @@ func logoutPlayer(s *Session) {
|
|||||||
|
|
||||||
removeSessionFromSemaphore(s)
|
removeSessionFromSemaphore(s)
|
||||||
removeSessionFromStage(s)
|
removeSessionFromStage(s)
|
||||||
treasureHuntUnregister(s)
|
|
||||||
|
|
||||||
saveData, err := GetCharacterSaveData(s, s.charID)
|
saveData, err := GetCharacterSaveData(s, s.charID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -641,65 +642,6 @@ func handleMsgMhfUpdateUnionItem(s *Session, p mhfpacket.MHFPacket) {
|
|||||||
doAckSimpleSucceed(s, pkt.AckHandle, []byte{0x00, 0x00, 0x00, 0x00})
|
doAckSimpleSucceed(s, pkt.AckHandle, []byte{0x00, 0x00, 0x00, 0x00})
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleMsgMhfAcquireCafeItem(s *Session, p mhfpacket.MHFPacket) {
|
|
||||||
pkt := p.(*mhfpacket.MsgMhfAcquireCafeItem)
|
|
||||||
var netcafe_points int
|
|
||||||
err := s.server.db.QueryRow("UPDATE characters SET netcafe_points = netcafe_points - $1 WHERE id = $2 RETURNING netcafe_points", pkt.PointCost, s.charID).Scan(&netcafe_points)
|
|
||||||
if err != nil {
|
|
||||||
s.logger.Fatal("Failed to get plate data savedata from db", zap.Error(err))
|
|
||||||
}
|
|
||||||
resp := byteframe.NewByteFrame()
|
|
||||||
resp.WriteUint32(uint32(netcafe_points))
|
|
||||||
doAckSimpleSucceed(s, pkt.AckHandle, resp.Data())
|
|
||||||
}
|
|
||||||
|
|
||||||
func handleMsgMhfUpdateCafepoint(s *Session, p mhfpacket.MHFPacket) {
|
|
||||||
pkt := p.(*mhfpacket.MsgMhfUpdateCafepoint)
|
|
||||||
var netcafe_points int
|
|
||||||
err := s.server.db.QueryRow("SELECT COALESCE(netcafe_points, 0) FROM characters WHERE id = $1", s.charID).Scan(&netcafe_points)
|
|
||||||
if err != nil {
|
|
||||||
s.logger.Fatal("Failed to get plate data savedata from db", zap.Error(err))
|
|
||||||
}
|
|
||||||
resp := byteframe.NewByteFrame()
|
|
||||||
resp.WriteUint32(0)
|
|
||||||
resp.WriteUint32(uint32(netcafe_points))
|
|
||||||
doAckSimpleSucceed(s, pkt.AckHandle, resp.Data())
|
|
||||||
}
|
|
||||||
|
|
||||||
func handleMsgMhfCheckDailyCafepoint(s *Session, p mhfpacket.MHFPacket) {
|
|
||||||
pkt := p.(*mhfpacket.MsgMhfCheckDailyCafepoint)
|
|
||||||
|
|
||||||
// I am not sure exactly what this does, but all responses I have seen include this exact sequence of bytes
|
|
||||||
// 1 daily, 5 daily halk pots, 3 point boosted quests, also adds 5 netcafe points but not sent to client
|
|
||||||
// available once after midday every day
|
|
||||||
|
|
||||||
// get next midday
|
|
||||||
var t = Time_static()
|
|
||||||
year, month, day := t.Date()
|
|
||||||
midday := time.Date(year, month, day, 12, 0, 0, 0, t.Location())
|
|
||||||
if t.After(midday) {
|
|
||||||
midday = midday.Add(24 * time.Hour)
|
|
||||||
}
|
|
||||||
|
|
||||||
// get time after which daily claiming would be valid from db
|
|
||||||
var dailyTime time.Time
|
|
||||||
err := s.server.db.QueryRow("SELECT COALESCE(daily_time, $2) FROM characters WHERE id = $1", s.charID, time.Date(2000, 1, 1, 0, 0, 0, 0, time.UTC)).Scan(&dailyTime)
|
|
||||||
if err != nil {
|
|
||||||
s.logger.Fatal("Failed to get daily_time savedata from db", zap.Error(err))
|
|
||||||
}
|
|
||||||
|
|
||||||
if t.After(dailyTime) {
|
|
||||||
// +5 netcafe points and setting next valid window
|
|
||||||
_, err := s.server.db.Exec("UPDATE characters SET daily_time=$1, netcafe_points=netcafe_points::int + 5 WHERE id=$2", midday, s.charID)
|
|
||||||
if err != nil {
|
|
||||||
s.logger.Fatal("Failed to update daily_time and netcafe_points savedata in db", zap.Error(err))
|
|
||||||
}
|
|
||||||
doAckBufSucceed(s, pkt.AckHandle, []byte{0x01, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x01})
|
|
||||||
} else {
|
|
||||||
doAckBufSucceed(s, pkt.AckHandle, []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func handleMsgMhfGetCogInfo(s *Session, p mhfpacket.MHFPacket) {}
|
func handleMsgMhfGetCogInfo(s *Session, p mhfpacket.MHFPacket) {}
|
||||||
|
|
||||||
func handleMsgMhfCheckWeeklyStamp(s *Session, p mhfpacket.MHFPacket) {
|
func handleMsgMhfCheckWeeklyStamp(s *Session, p mhfpacket.MHFPacket) {
|
||||||
|
|||||||
239
server/channelserver/handlers_cafe.go
Normal file
239
server/channelserver/handlers_cafe.go
Normal file
@@ -0,0 +1,239 @@
|
|||||||
|
package channelserver
|
||||||
|
|
||||||
|
import (
|
||||||
|
"erupe-ce/common/byteframe"
|
||||||
|
ps "erupe-ce/common/pascalstring"
|
||||||
|
"erupe-ce/network/mhfpacket"
|
||||||
|
"go.uber.org/zap"
|
||||||
|
"io"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func handleMsgMhfAcquireCafeItem(s *Session, p mhfpacket.MHFPacket) {
|
||||||
|
pkt := p.(*mhfpacket.MsgMhfAcquireCafeItem)
|
||||||
|
var netcafePoints uint32
|
||||||
|
err := s.server.db.QueryRow("UPDATE characters SET netcafe_points = netcafe_points - $1 WHERE id = $2 RETURNING netcafe_points", pkt.PointCost, s.charID).Scan(&netcafePoints)
|
||||||
|
if err != nil {
|
||||||
|
s.logger.Fatal("Failed to get netcafe points from db", zap.Error(err))
|
||||||
|
}
|
||||||
|
resp := byteframe.NewByteFrame()
|
||||||
|
resp.WriteUint32(netcafePoints)
|
||||||
|
doAckSimpleSucceed(s, pkt.AckHandle, resp.Data())
|
||||||
|
}
|
||||||
|
|
||||||
|
func handleMsgMhfUpdateCafepoint(s *Session, p mhfpacket.MHFPacket) {
|
||||||
|
pkt := p.(*mhfpacket.MsgMhfUpdateCafepoint)
|
||||||
|
var netcafePoints uint32
|
||||||
|
err := s.server.db.QueryRow("SELECT COALESCE(netcafe_points, 0) FROM characters WHERE id = $1", s.charID).Scan(&netcafePoints)
|
||||||
|
if err != nil {
|
||||||
|
s.logger.Fatal("Failed to get netcate points from db", zap.Error(err))
|
||||||
|
}
|
||||||
|
resp := byteframe.NewByteFrame()
|
||||||
|
resp.WriteUint32(netcafePoints)
|
||||||
|
doAckSimpleSucceed(s, pkt.AckHandle, resp.Data())
|
||||||
|
}
|
||||||
|
|
||||||
|
func handleMsgMhfCheckDailyCafepoint(s *Session, p mhfpacket.MHFPacket) {
|
||||||
|
pkt := p.(*mhfpacket.MsgMhfCheckDailyCafepoint)
|
||||||
|
|
||||||
|
// I am not sure exactly what this does, but all responses I have seen include this exact sequence of bytes
|
||||||
|
// 1 daily, 5 daily halk pots, 3 point boosted quests, also adds 5 netcafe points but not sent to client
|
||||||
|
// available once after midday every day
|
||||||
|
|
||||||
|
// get next midday
|
||||||
|
var t = Time_static()
|
||||||
|
year, month, day := t.Date()
|
||||||
|
midday := time.Date(year, month, day, 12, 0, 0, 0, t.Location())
|
||||||
|
if t.After(midday) {
|
||||||
|
midday = midday.Add(24 * time.Hour)
|
||||||
|
}
|
||||||
|
|
||||||
|
// get time after which daily claiming would be valid from db
|
||||||
|
var dailyTime time.Time
|
||||||
|
err := s.server.db.QueryRow("SELECT COALESCE(daily_time, $2) FROM characters WHERE id = $1", s.charID, time.Date(2000, 1, 1, 0, 0, 0, 0, time.UTC)).Scan(&dailyTime)
|
||||||
|
if err != nil {
|
||||||
|
s.logger.Fatal("Failed to get daily_time savedata from db", zap.Error(err))
|
||||||
|
}
|
||||||
|
|
||||||
|
if t.After(dailyTime) {
|
||||||
|
// +5 netcafe points and setting next valid window
|
||||||
|
_, err := s.server.db.Exec("UPDATE characters SET daily_time=$1, netcafe_points=netcafe_points+5 WHERE id=$2", midday, s.charID)
|
||||||
|
if err != nil {
|
||||||
|
s.logger.Fatal("Failed to update daily_time and netcafe_points savedata in db", zap.Error(err))
|
||||||
|
}
|
||||||
|
doAckBufSucceed(s, pkt.AckHandle, []byte{0x01, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x01})
|
||||||
|
} else {
|
||||||
|
doAckBufSucceed(s, pkt.AckHandle, []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func handleMsgMhfGetCafeDuration(s *Session, p mhfpacket.MHFPacket) {
|
||||||
|
pkt := p.(*mhfpacket.MsgMhfGetCafeDuration)
|
||||||
|
bf := byteframe.NewByteFrame()
|
||||||
|
|
||||||
|
var cafeTime uint32
|
||||||
|
err := s.server.db.QueryRow("SELECT cafe_time FROM characters WHERE id = $1", s.charID).Scan(&cafeTime)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
cafeTime = uint32(Time_Current_Adjusted().Unix()) - uint32(s.sessionStart) + cafeTime
|
||||||
|
bf.WriteUint32(cafeTime) // Total cafe time
|
||||||
|
bf.WriteUint16(0)
|
||||||
|
ps.Uint16(bf, "Resets at next maintenance", true)
|
||||||
|
doAckBufSucceed(s, pkt.AckHandle, bf.Data())
|
||||||
|
}
|
||||||
|
|
||||||
|
type CafeBonus struct {
|
||||||
|
ID uint32 `db:"id"`
|
||||||
|
TimeReq uint32 `db:"time_req"`
|
||||||
|
ItemType uint32 `db:"item_type"`
|
||||||
|
ItemID uint32 `db:"item_id"`
|
||||||
|
Quantity uint32 `db:"quantity"`
|
||||||
|
Claimed bool `db:"claimed"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func handleMsgMhfGetCafeDurationBonusInfo(s *Session, p mhfpacket.MHFPacket) {
|
||||||
|
pkt := p.(*mhfpacket.MsgMhfGetCafeDurationBonusInfo)
|
||||||
|
bf := byteframe.NewByteFrame()
|
||||||
|
|
||||||
|
var count uint32
|
||||||
|
rows, err := s.server.db.Queryx(`
|
||||||
|
SELECT cb.id, time_req, item_type, item_id, quantity,
|
||||||
|
(
|
||||||
|
SELECT count(*)
|
||||||
|
FROM cafe_accepted ca
|
||||||
|
WHERE cb.id = ca.cafe_id AND ca.character_id = $1
|
||||||
|
)::int::bool AS claimed
|
||||||
|
FROM cafebonus cb ORDER BY id ASC;`, s.charID)
|
||||||
|
if err != nil {
|
||||||
|
s.logger.Error("Error getting cafebonus", zap.Error(err))
|
||||||
|
doAckBufSucceed(s, pkt.AckHandle, make([]byte, 4))
|
||||||
|
} else {
|
||||||
|
for rows.Next() {
|
||||||
|
count++
|
||||||
|
cafeBonus := &CafeBonus{}
|
||||||
|
err = rows.StructScan(&cafeBonus)
|
||||||
|
if err != nil {
|
||||||
|
s.logger.Error("Error scanning cafebonus", zap.Error(err))
|
||||||
|
}
|
||||||
|
bf.WriteUint32(cafeBonus.TimeReq)
|
||||||
|
bf.WriteUint32(cafeBonus.ItemType)
|
||||||
|
bf.WriteUint32(cafeBonus.ItemID)
|
||||||
|
bf.WriteUint32(cafeBonus.Quantity)
|
||||||
|
bf.WriteBool(cafeBonus.Claimed)
|
||||||
|
}
|
||||||
|
resp := byteframe.NewByteFrame()
|
||||||
|
resp.WriteUint32(0)
|
||||||
|
resp.WriteUint32(uint32(time.Now().Unix()))
|
||||||
|
resp.WriteUint32(count)
|
||||||
|
resp.WriteBytes(bf.Data())
|
||||||
|
doAckBufSucceed(s, pkt.AckHandle, resp.Data())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func handleMsgMhfReceiveCafeDurationBonus(s *Session, p mhfpacket.MHFPacket) {
|
||||||
|
pkt := p.(*mhfpacket.MsgMhfReceiveCafeDurationBonus)
|
||||||
|
bf := byteframe.NewByteFrame()
|
||||||
|
var count uint32
|
||||||
|
bf.WriteUint32(0)
|
||||||
|
rows, err := s.server.db.Queryx(`
|
||||||
|
SELECT c.id, time_req, item_type, item_id, quantity
|
||||||
|
FROM cafebonus c
|
||||||
|
WHERE (
|
||||||
|
SELECT count(*)
|
||||||
|
FROM cafe_accepted ca
|
||||||
|
WHERE c.id = ca.cafe_id AND ca.character_id = $1
|
||||||
|
) < 1 AND (
|
||||||
|
SELECT ch.cafe_time + $2
|
||||||
|
FROM characters ch
|
||||||
|
WHERE ch.id = $1
|
||||||
|
) >= time_req`, s.charID, Time_Current_Adjusted().Unix()-s.sessionStart)
|
||||||
|
if err != nil {
|
||||||
|
doAckBufSucceed(s, pkt.AckHandle, bf.Data())
|
||||||
|
} else {
|
||||||
|
for rows.Next() {
|
||||||
|
cafeBonus := &CafeBonus{}
|
||||||
|
err = rows.StructScan(cafeBonus)
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
count++
|
||||||
|
bf.WriteUint32(cafeBonus.ID)
|
||||||
|
bf.WriteUint32(cafeBonus.ItemType)
|
||||||
|
bf.WriteUint32(cafeBonus.ItemID)
|
||||||
|
bf.WriteUint32(cafeBonus.Quantity)
|
||||||
|
}
|
||||||
|
bf.Seek(0, io.SeekStart)
|
||||||
|
bf.WriteUint32(count)
|
||||||
|
doAckBufSucceed(s, pkt.AckHandle, bf.Data())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func handleMsgMhfPostCafeDurationBonusReceived(s *Session, p mhfpacket.MHFPacket) {
|
||||||
|
pkt := p.(*mhfpacket.MsgMhfPostCafeDurationBonusReceived)
|
||||||
|
var cafeBonus CafeBonus
|
||||||
|
for _, cbID := range pkt.CafeBonusID {
|
||||||
|
err := s.server.db.QueryRow(`
|
||||||
|
SELECT cb.id, item_type, quantity FROM cafebonus cb WHERE cb.id=$1
|
||||||
|
`, cbID).Scan(&cafeBonus.ID, &cafeBonus.ItemType, &cafeBonus.Quantity)
|
||||||
|
if err == nil {
|
||||||
|
if cafeBonus.ItemType == 17 {
|
||||||
|
s.server.db.Exec("UPDATE characters SET netcafe_points=netcafe_points+$1 WHERE id=$2", cafeBonus.Quantity, s.charID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
s.server.db.Exec("INSERT INTO public.cafe_accepted VALUES ($1, $2)", cbID, s.charID)
|
||||||
|
}
|
||||||
|
doAckSimpleSucceed(s, pkt.AckHandle, make([]byte, 4))
|
||||||
|
}
|
||||||
|
|
||||||
|
func handleMsgMhfStartBoostTime(s *Session, p mhfpacket.MHFPacket) {
|
||||||
|
pkt := p.(*mhfpacket.MsgMhfStartBoostTime)
|
||||||
|
bf := byteframe.NewByteFrame()
|
||||||
|
boostLimit := Time_Current_Adjusted().Add(100 * time.Minute)
|
||||||
|
s.server.db.Exec("UPDATE characters SET boost_time=$1 WHERE id=$2", boostLimit, s.charID)
|
||||||
|
bf.WriteUint32(uint32(boostLimit.Unix()))
|
||||||
|
doAckBufSucceed(s, pkt.AckHandle, bf.Data())
|
||||||
|
}
|
||||||
|
|
||||||
|
func handleMsgMhfGetBoostTime(s *Session, p mhfpacket.MHFPacket) {
|
||||||
|
pkt := p.(*mhfpacket.MsgMhfGetBoostTime)
|
||||||
|
doAckBufSucceed(s, pkt.AckHandle, []byte{})
|
||||||
|
}
|
||||||
|
|
||||||
|
func handleMsgMhfGetBoostTimeLimit(s *Session, p mhfpacket.MHFPacket) {
|
||||||
|
pkt := p.(*mhfpacket.MsgMhfGetBoostTimeLimit)
|
||||||
|
bf := byteframe.NewByteFrame()
|
||||||
|
var boostLimit time.Time
|
||||||
|
err := s.server.db.QueryRow("SELECT boost_time FROM characters WHERE id=$1", s.charID).Scan(&boostLimit)
|
||||||
|
if err != nil {
|
||||||
|
bf.WriteUint32(0)
|
||||||
|
} else {
|
||||||
|
bf.WriteUint32(uint32(boostLimit.Unix()))
|
||||||
|
}
|
||||||
|
doAckBufSucceed(s, pkt.AckHandle, bf.Data())
|
||||||
|
doAckSimpleSucceed(s, pkt.AckHandle, make([]byte, 4))
|
||||||
|
}
|
||||||
|
|
||||||
|
func handleMsgMhfGetBoostRight(s *Session, p mhfpacket.MHFPacket) {
|
||||||
|
pkt := p.(*mhfpacket.MsgMhfGetBoostRight)
|
||||||
|
var boostLimit time.Time
|
||||||
|
err := s.server.db.QueryRow("SELECT boost_time FROM characters WHERE id=$1", s.charID).Scan(&boostLimit)
|
||||||
|
if err != nil {
|
||||||
|
doAckBufSucceed(s, pkt.AckHandle, []byte{0x00, 0x00, 0x00, 0x00})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if boostLimit.Unix() > Time_Current_Adjusted().Unix() {
|
||||||
|
doAckBufSucceed(s, pkt.AckHandle, []byte{0x00, 0x00, 0x00, 0x01})
|
||||||
|
} else {
|
||||||
|
doAckBufSucceed(s, pkt.AckHandle, []byte{0x00, 0x00, 0x00, 0x02})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func handleMsgMhfPostBoostTimeQuestReturn(s *Session, p mhfpacket.MHFPacket) {
|
||||||
|
pkt := p.(*mhfpacket.MsgMhfPostBoostTimeQuestReturn)
|
||||||
|
doAckSimpleSucceed(s, pkt.AckHandle, []byte{0x00, 0x00, 0x00, 0x00})
|
||||||
|
}
|
||||||
|
|
||||||
|
func handleMsgMhfPostBoostTime(s *Session, p mhfpacket.MHFPacket) {}
|
||||||
|
|
||||||
|
func handleMsgMhfPostBoostTimeLimit(s *Session, p mhfpacket.MHFPacket) {}
|
||||||
@@ -303,34 +303,6 @@ func handleMsgMhfGetUdInfo(s *Session, p mhfpacket.MHFPacket) {
|
|||||||
doAckBufSucceed(s, pkt.AckHandle, resp.Data())
|
doAckBufSucceed(s, pkt.AckHandle, resp.Data())
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleMsgMhfGetBoostTime(s *Session, p mhfpacket.MHFPacket) {
|
|
||||||
pkt := p.(*mhfpacket.MsgMhfGetBoostTime)
|
|
||||||
|
|
||||||
doAckBufSucceed(s, pkt.AckHandle, []byte{})
|
|
||||||
updateRights(s)
|
|
||||||
}
|
|
||||||
|
|
||||||
func handleMsgMhfGetBoostTimeLimit(s *Session, p mhfpacket.MHFPacket) {
|
|
||||||
pkt := p.(*mhfpacket.MsgMhfGetBoostTimeLimit)
|
|
||||||
doAckBufSucceed(s, pkt.AckHandle, []byte{0x00, 0x00, 0x00, 0x00})
|
|
||||||
}
|
|
||||||
|
|
||||||
func handleMsgMhfGetBoostRight(s *Session, p mhfpacket.MHFPacket) {
|
|
||||||
pkt := p.(*mhfpacket.MsgMhfGetBoostRight)
|
|
||||||
doAckBufSucceed(s, pkt.AckHandle, []byte{0x00, 0x00, 0x00, 0x00})
|
|
||||||
}
|
|
||||||
|
|
||||||
func handleMsgMhfPostBoostTimeQuestReturn(s *Session, p mhfpacket.MHFPacket) {
|
|
||||||
pkt := p.(*mhfpacket.MsgMhfPostBoostTimeQuestReturn)
|
|
||||||
doAckSimpleSucceed(s, pkt.AckHandle, []byte{0x00, 0x00, 0x00, 0x00})
|
|
||||||
}
|
|
||||||
|
|
||||||
func handleMsgMhfStartBoostTime(s *Session, p mhfpacket.MHFPacket) {}
|
|
||||||
|
|
||||||
func handleMsgMhfPostBoostTime(s *Session, p mhfpacket.MHFPacket) {}
|
|
||||||
|
|
||||||
func handleMsgMhfPostBoostTimeLimit(s *Session, p mhfpacket.MHFPacket) {}
|
|
||||||
|
|
||||||
func handleMsgMhfGetRestrictionEvent(s *Session, p mhfpacket.MHFPacket) {}
|
func handleMsgMhfGetRestrictionEvent(s *Session, p mhfpacket.MHFPacket) {}
|
||||||
|
|
||||||
func handleMsgMhfSetRestrictionEvent(s *Session, p mhfpacket.MHFPacket) {
|
func handleMsgMhfSetRestrictionEvent(s *Session, p mhfpacket.MHFPacket) {
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package channelserver
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
|
|
||||||
"erupe-ce/network/mhfpacket"
|
"erupe-ce/network/mhfpacket"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -58,11 +57,3 @@ func handleMsgMhfGetUdTacticsRanking(s *Session, p mhfpacket.MHFPacket) {
|
|||||||
func handleMsgMhfSetUdTacticsFollower(s *Session, p mhfpacket.MHFPacket) {}
|
func handleMsgMhfSetUdTacticsFollower(s *Session, p mhfpacket.MHFPacket) {}
|
||||||
|
|
||||||
func handleMsgMhfGetUdTacticsLog(s *Session, p mhfpacket.MHFPacket) {}
|
func handleMsgMhfGetUdTacticsLog(s *Session, p mhfpacket.MHFPacket) {}
|
||||||
|
|
||||||
func handleMsgMhfGetCafeDuration(s *Session, p mhfpacket.MHFPacket) {}
|
|
||||||
|
|
||||||
func handleMsgMhfGetCafeDurationBonusInfo(s *Session, p mhfpacket.MHFPacket) {}
|
|
||||||
|
|
||||||
func handleMsgMhfReceiveCafeDurationBonus(s *Session, p mhfpacket.MHFPacket) {}
|
|
||||||
|
|
||||||
func handleMsgMhfPostCafeDurationBonusReceived(s *Session, p mhfpacket.MHFPacket) {}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user