mirror of
https://github.com/Mezeporta/Erupe.git
synced 2026-03-28 10:32:55 +01:00
12
patch-schema/login-boost.sql
Normal file
12
patch-schema/login-boost.sql
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
BEGIN;
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS public.login_boost_state;
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS public.login_boost (
|
||||||
|
char_id INTEGER,
|
||||||
|
week_req INTEGER,
|
||||||
|
expiration TIMESTAMP WITH TIME ZONE,
|
||||||
|
reset TIMESTAMP WITH TIME ZONE
|
||||||
|
);
|
||||||
|
|
||||||
|
END;
|
||||||
69
patch-schema/time-fix.sql
Normal file
69
patch-schema/time-fix.sql
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
BEGIN;
|
||||||
|
|
||||||
|
ALTER TABLE IF EXISTS public.characters
|
||||||
|
ALTER COLUMN daily_time TYPE TIMESTAMP WITH TIME ZONE;
|
||||||
|
|
||||||
|
ALTER TABLE IF EXISTS public.characters
|
||||||
|
ALTER COLUMN guild_post_checked TYPE TIMESTAMP WITH TIME ZONE;
|
||||||
|
|
||||||
|
ALTER TABLE IF EXISTS public.characters
|
||||||
|
ALTER COLUMN boost_time TYPE TIMESTAMP WITH TIME ZONE;
|
||||||
|
|
||||||
|
ALTER TABLE IF EXISTS public.characters
|
||||||
|
ALTER COLUMN cafe_reset TYPE TIMESTAMP WITH TIME ZONE;
|
||||||
|
|
||||||
|
ALTER TABLE IF EXISTS public.distribution
|
||||||
|
ALTER COLUMN deadline TYPE TIMESTAMP WITH TIME ZONE;
|
||||||
|
|
||||||
|
ALTER TABLE IF EXISTS public.events
|
||||||
|
ALTER COLUMN start_time TYPE TIMESTAMP WITH TIME ZONE;
|
||||||
|
|
||||||
|
ALTER TABLE IF EXISTS public.feature_weapon
|
||||||
|
ALTER COLUMN start_time TYPE TIMESTAMP WITH TIME ZONE;
|
||||||
|
|
||||||
|
ALTER TABLE IF EXISTS public.guild_alliances
|
||||||
|
ALTER COLUMN created_at TYPE TIMESTAMP WITH TIME ZONE;
|
||||||
|
|
||||||
|
ALTER TABLE IF EXISTS public.guild_applications
|
||||||
|
ALTER COLUMN created_at TYPE TIMESTAMP WITH TIME ZONE;
|
||||||
|
|
||||||
|
ALTER TABLE IF EXISTS public.guild_characters
|
||||||
|
ALTER COLUMN joined_at TYPE TIMESTAMP WITH TIME ZONE;
|
||||||
|
|
||||||
|
ALTER TABLE IF EXISTS public.guild_posts
|
||||||
|
ALTER COLUMN created_at TYPE TIMESTAMP WITH TIME ZONE;
|
||||||
|
|
||||||
|
ALTER TABLE IF EXISTS public.characters
|
||||||
|
ALTER COLUMN daily_time TYPE TIMESTAMP WITH TIME ZONE;
|
||||||
|
|
||||||
|
ALTER TABLE IF EXISTS public.guilds
|
||||||
|
ALTER COLUMN created_at TYPE TIMESTAMP WITH TIME ZONE;
|
||||||
|
|
||||||
|
ALTER TABLE IF EXISTS public.mail
|
||||||
|
ALTER COLUMN created_at TYPE TIMESTAMP WITH TIME ZONE;
|
||||||
|
|
||||||
|
ALTER TABLE IF EXISTS public.stamps
|
||||||
|
ALTER COLUMN hl_next TYPE TIMESTAMP WITH TIME ZONE;
|
||||||
|
|
||||||
|
ALTER TABLE IF EXISTS public.stamps
|
||||||
|
ALTER COLUMN ex_next TYPE TIMESTAMP WITH TIME ZONE;
|
||||||
|
|
||||||
|
ALTER TABLE IF EXISTS public.titles
|
||||||
|
ALTER COLUMN unlocked_at TYPE TIMESTAMP WITH TIME ZONE;
|
||||||
|
|
||||||
|
ALTER TABLE IF EXISTS public.titles
|
||||||
|
ALTER COLUMN updated_at TYPE TIMESTAMP WITH TIME ZONE;
|
||||||
|
|
||||||
|
ALTER TABLE IF EXISTS public.users
|
||||||
|
ALTER COLUMN last_login TYPE TIMESTAMP WITH TIME ZONE;
|
||||||
|
|
||||||
|
ALTER TABLE IF EXISTS public.users
|
||||||
|
ALTER COLUMN return_expires TYPE TIMESTAMP WITH TIME ZONE;
|
||||||
|
|
||||||
|
ALTER TABLE IF EXISTS public.guild_meals
|
||||||
|
DROP COLUMN expires;
|
||||||
|
|
||||||
|
ALTER TABLE IF EXISTS public.guild_meals
|
||||||
|
ADD COLUMN created_at TIMESTAMP WITH TIME ZONE;
|
||||||
|
|
||||||
|
END;
|
||||||
@@ -144,7 +144,7 @@ func handleMsgSysLogin(s *Session, p mhfpacket.MHFPacket) {
|
|||||||
|
|
||||||
updateRights(s)
|
updateRights(s)
|
||||||
bf := byteframe.NewByteFrame()
|
bf := byteframe.NewByteFrame()
|
||||||
bf.WriteUint32(uint32(Time_Current_Adjusted().Unix())) // Unix timestamp
|
bf.WriteUint32(uint32(TimeAdjusted().Unix())) // Unix timestamp
|
||||||
|
|
||||||
_, err := s.server.db.Exec("UPDATE servers SET current_players=$1 WHERE server_id=$2", len(s.server.sessions), s.server.ID)
|
_, err := s.server.db.Exec("UPDATE servers SET current_players=$1 WHERE server_id=$2", len(s.server.sessions), s.server.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -156,7 +156,7 @@ func handleMsgSysLogin(s *Session, p mhfpacket.MHFPacket) {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = s.server.db.Exec("UPDATE characters SET last_login=$1 WHERE id=$2", Time_Current().Unix(), s.charID)
|
_, err = s.server.db.Exec("UPDATE characters SET last_login=$1 WHERE id=$2", TimeAdjusted().Unix(), s.charID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
@@ -216,7 +216,7 @@ func logoutPlayer(s *Session) {
|
|||||||
var timePlayed int
|
var timePlayed int
|
||||||
var sessionTime 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)
|
sessionTime = int(TimeAdjusted().Unix()) - int(s.sessionStart)
|
||||||
timePlayed += sessionTime
|
timePlayed += sessionTime
|
||||||
|
|
||||||
var rpGained int
|
var rpGained int
|
||||||
@@ -276,7 +276,7 @@ func handleMsgSysTime(s *Session, p mhfpacket.MHFPacket) {
|
|||||||
|
|
||||||
resp := &mhfpacket.MsgSysTime{
|
resp := &mhfpacket.MsgSysTime{
|
||||||
GetRemoteTime: false,
|
GetRemoteTime: false,
|
||||||
Timestamp: uint32(Time_Current_Adjusted().Unix()), // JP timezone
|
Timestamp: uint32(TimeAdjusted().Unix()), // JP timezone
|
||||||
}
|
}
|
||||||
s.QueueSendMHF(resp)
|
s.QueueSendMHF(resp)
|
||||||
}
|
}
|
||||||
@@ -1505,7 +1505,7 @@ func handleMsgMhfGetEtcPoints(s *Session, p mhfpacket.MHFPacket) {
|
|||||||
|
|
||||||
var dailyTime time.Time
|
var dailyTime time.Time
|
||||||
_ = 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)
|
_ = 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 Time_Current_Adjusted().After(dailyTime) {
|
if TimeAdjusted().After(dailyTime) {
|
||||||
s.server.db.Exec("UPDATE characters SET bonus_quests = 0, daily_quests = 0 WHERE id=$1", s.charID)
|
s.server.db.Exec("UPDATE characters SET bonus_quests = 0, daily_quests = 0 WHERE id=$1", s.charID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -37,11 +37,8 @@ func handleMsgMhfUpdateCafepoint(s *Session, p mhfpacket.MHFPacket) {
|
|||||||
func handleMsgMhfCheckDailyCafepoint(s *Session, p mhfpacket.MHFPacket) {
|
func handleMsgMhfCheckDailyCafepoint(s *Session, p mhfpacket.MHFPacket) {
|
||||||
pkt := p.(*mhfpacket.MsgMhfCheckDailyCafepoint)
|
pkt := p.(*mhfpacket.MsgMhfCheckDailyCafepoint)
|
||||||
|
|
||||||
// get next midday
|
midday := TimeMidnight().Add(12 * time.Hour)
|
||||||
var t = Time_static()
|
if TimeAdjusted().After(midday) {
|
||||||
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)
|
midday = midday.Add(24 * time.Hour)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,7 +51,7 @@ func handleMsgMhfCheckDailyCafepoint(s *Session, p mhfpacket.MHFPacket) {
|
|||||||
|
|
||||||
var bondBonus, bonusQuests, dailyQuests uint32
|
var bondBonus, bonusQuests, dailyQuests uint32
|
||||||
bf := byteframe.NewByteFrame()
|
bf := byteframe.NewByteFrame()
|
||||||
if t.After(dailyTime) {
|
if midday.After(dailyTime) {
|
||||||
addPointNetcafe(s, 5)
|
addPointNetcafe(s, 5)
|
||||||
bondBonus = 5 // Bond point bonus quests
|
bondBonus = 5 // Bond point bonus quests
|
||||||
bonusQuests = 3 // HRP bonus quests?
|
bonusQuests = 3 // HRP bonus quests?
|
||||||
@@ -80,7 +77,7 @@ func handleMsgMhfGetCafeDuration(s *Session, p mhfpacket.MHFPacket) {
|
|||||||
cafeReset = TimeWeekNext()
|
cafeReset = TimeWeekNext()
|
||||||
s.server.db.Exec(`UPDATE characters SET cafe_reset=$1 WHERE id=$2`, cafeReset, s.charID)
|
s.server.db.Exec(`UPDATE characters SET cafe_reset=$1 WHERE id=$2`, cafeReset, s.charID)
|
||||||
}
|
}
|
||||||
if Time_Current_Adjusted().After(cafeReset) {
|
if TimeAdjusted().After(cafeReset) {
|
||||||
cafeReset = TimeWeekNext()
|
cafeReset = TimeWeekNext()
|
||||||
s.server.db.Exec(`UPDATE characters SET cafe_time=0, cafe_reset=$1 WHERE id=$2`, cafeReset, s.charID)
|
s.server.db.Exec(`UPDATE characters SET cafe_time=0, cafe_reset=$1 WHERE id=$2`, cafeReset, s.charID)
|
||||||
s.server.db.Exec(`DELETE FROM cafe_accepted WHERE character_id=$1`, s.charID)
|
s.server.db.Exec(`DELETE FROM cafe_accepted WHERE character_id=$1`, s.charID)
|
||||||
@@ -92,7 +89,7 @@ func handleMsgMhfGetCafeDuration(s *Session, p mhfpacket.MHFPacket) {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
if s.FindCourse("NetCafe").ID != 0 || s.FindCourse("N").ID != 0 {
|
if s.FindCourse("NetCafe").ID != 0 || s.FindCourse("N").ID != 0 {
|
||||||
cafeTime = uint32(Time_Current_Adjusted().Unix()) - uint32(s.sessionStart) + cafeTime
|
cafeTime = uint32(TimeAdjusted().Unix()) - uint32(s.sessionStart) + cafeTime
|
||||||
}
|
}
|
||||||
bf.WriteUint32(cafeTime) // Total cafe time
|
bf.WriteUint32(cafeTime) // Total cafe time
|
||||||
bf.WriteUint16(0)
|
bf.WriteUint16(0)
|
||||||
@@ -142,7 +139,7 @@ func handleMsgMhfGetCafeDurationBonusInfo(s *Session, p mhfpacket.MHFPacket) {
|
|||||||
}
|
}
|
||||||
resp := byteframe.NewByteFrame()
|
resp := byteframe.NewByteFrame()
|
||||||
resp.WriteUint32(0)
|
resp.WriteUint32(0)
|
||||||
resp.WriteUint32(uint32(time.Now().Unix()))
|
resp.WriteUint32(uint32(TimeAdjusted().Unix()))
|
||||||
resp.WriteUint32(count)
|
resp.WriteUint32(count)
|
||||||
resp.WriteBytes(bf.Data())
|
resp.WriteBytes(bf.Data())
|
||||||
doAckBufSucceed(s, pkt.AckHandle, resp.Data())
|
doAckBufSucceed(s, pkt.AckHandle, resp.Data())
|
||||||
@@ -165,7 +162,7 @@ func handleMsgMhfReceiveCafeDurationBonus(s *Session, p mhfpacket.MHFPacket) {
|
|||||||
SELECT ch.cafe_time + $2
|
SELECT ch.cafe_time + $2
|
||||||
FROM characters ch
|
FROM characters ch
|
||||||
WHERE ch.id = $1
|
WHERE ch.id = $1
|
||||||
) >= time_req`, s.charID, Time_Current_Adjusted().Unix()-s.sessionStart)
|
) >= time_req`, s.charID, TimeAdjusted().Unix()-s.sessionStart)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
doAckBufSucceed(s, pkt.AckHandle, bf.Data())
|
doAckBufSucceed(s, pkt.AckHandle, bf.Data())
|
||||||
} else {
|
} else {
|
||||||
@@ -222,7 +219,7 @@ func addPointNetcafe(s *Session, p int) error {
|
|||||||
func handleMsgMhfStartBoostTime(s *Session, p mhfpacket.MHFPacket) {
|
func handleMsgMhfStartBoostTime(s *Session, p mhfpacket.MHFPacket) {
|
||||||
pkt := p.(*mhfpacket.MsgMhfStartBoostTime)
|
pkt := p.(*mhfpacket.MsgMhfStartBoostTime)
|
||||||
bf := byteframe.NewByteFrame()
|
bf := byteframe.NewByteFrame()
|
||||||
boostLimit := Time_Current_Adjusted().Add(100 * time.Minute)
|
boostLimit := TimeAdjusted().Add(120 * time.Minute)
|
||||||
s.server.db.Exec("UPDATE characters SET boost_time=$1 WHERE id=$2", boostLimit, s.charID)
|
s.server.db.Exec("UPDATE characters SET boost_time=$1 WHERE id=$2", boostLimit, s.charID)
|
||||||
bf.WriteUint32(uint32(boostLimit.Unix()))
|
bf.WriteUint32(uint32(boostLimit.Unix()))
|
||||||
doAckBufSucceed(s, pkt.AckHandle, bf.Data())
|
doAckBufSucceed(s, pkt.AckHandle, bf.Data())
|
||||||
@@ -255,7 +252,7 @@ func handleMsgMhfGetBoostRight(s *Session, p mhfpacket.MHFPacket) {
|
|||||||
doAckBufSucceed(s, pkt.AckHandle, []byte{0x00, 0x00, 0x00, 0x00})
|
doAckBufSucceed(s, pkt.AckHandle, []byte{0x00, 0x00, 0x00, 0x00})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if boostLimit.Unix() > Time_Current_Adjusted().Unix() {
|
if boostLimit.After(TimeAdjusted()) {
|
||||||
doAckBufSucceed(s, pkt.AckHandle, []byte{0x00, 0x00, 0x00, 0x01})
|
doAckBufSucceed(s, pkt.AckHandle, []byte{0x00, 0x00, 0x00, 0x01})
|
||||||
} else {
|
} else {
|
||||||
doAckBufSucceed(s, pkt.AckHandle, []byte{0x00, 0x00, 0x00, 0x02})
|
doAckBufSucceed(s, pkt.AckHandle, []byte{0x00, 0x00, 0x00, 0x02})
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ func cleanupDiva(s *Session) {
|
|||||||
|
|
||||||
func generateDivaTimestamps(s *Session, start uint32, debug bool) []uint32 {
|
func generateDivaTimestamps(s *Session, start uint32, debug bool) []uint32 {
|
||||||
timestamps := make([]uint32, 6)
|
timestamps := make([]uint32, 6)
|
||||||
midnight := Time_Current_Midnight()
|
midnight := TimeMidnight()
|
||||||
if debug && start <= 3 {
|
if debug && start <= 3 {
|
||||||
midnight := uint32(midnight.Unix())
|
midnight := uint32(midnight.Unix())
|
||||||
switch start {
|
switch start {
|
||||||
@@ -43,7 +43,7 @@ func generateDivaTimestamps(s *Session, start uint32, debug bool) []uint32 {
|
|||||||
}
|
}
|
||||||
return timestamps
|
return timestamps
|
||||||
}
|
}
|
||||||
if start == 0 || Time_Current_Adjusted().Unix() > int64(start)+2977200 {
|
if start == 0 || TimeAdjusted().Unix() > int64(start)+2977200 {
|
||||||
cleanupDiva(s)
|
cleanupDiva(s)
|
||||||
// Generate a new diva defense, starting midnight tomorrow
|
// Generate a new diva defense, starting midnight tomorrow
|
||||||
start = uint32(midnight.Add(24 * time.Hour).Unix())
|
start = uint32(midnight.Add(24 * time.Hour).Unix())
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ func handleMsgMhfGetWeeklySchedule(s *Session, p mhfpacket.MHFPacket) {
|
|||||||
pkt := p.(*mhfpacket.MsgMhfGetWeeklySchedule)
|
pkt := p.(*mhfpacket.MsgMhfGetWeeklySchedule)
|
||||||
|
|
||||||
var features []activeFeature
|
var features []activeFeature
|
||||||
rows, _ := s.server.db.Queryx(`SELECT start_time, featured FROM feature_weapon WHERE start_time=$1 OR start_time=$2`, Time_Current_Midnight().Add(-24*time.Hour), Time_Current_Midnight())
|
rows, _ := s.server.db.Queryx(`SELECT start_time, featured FROM feature_weapon WHERE start_time=$1 OR start_time=$2`, TimeMidnight(), TimeMidnight().Add(24*time.Hour))
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var feature activeFeature
|
var feature activeFeature
|
||||||
rows.StructScan(&feature)
|
rows.StructScan(&feature)
|
||||||
@@ -71,19 +71,19 @@ func handleMsgMhfGetWeeklySchedule(s *Session, p mhfpacket.MHFPacket) {
|
|||||||
if len(features) < 2 {
|
if len(features) < 2 {
|
||||||
if len(features) == 0 {
|
if len(features) == 0 {
|
||||||
feature := generateFeatureWeapons(s.server.erupeConfig.FeaturedWeapons)
|
feature := generateFeatureWeapons(s.server.erupeConfig.FeaturedWeapons)
|
||||||
feature.StartTime = Time_Current_Midnight().Add(-24 * time.Hour)
|
feature.StartTime = TimeMidnight()
|
||||||
features = append(features, feature)
|
features = append(features, feature)
|
||||||
s.server.db.Exec(`INSERT INTO feature_weapon VALUES ($1, $2)`, feature.StartTime, feature.ActiveFeatures)
|
s.server.db.Exec(`INSERT INTO feature_weapon VALUES ($1, $2)`, feature.StartTime, feature.ActiveFeatures)
|
||||||
}
|
}
|
||||||
feature := generateFeatureWeapons(s.server.erupeConfig.FeaturedWeapons)
|
feature := generateFeatureWeapons(s.server.erupeConfig.FeaturedWeapons)
|
||||||
feature.StartTime = Time_Current_Midnight()
|
feature.StartTime = TimeMidnight().Add(24 * time.Hour)
|
||||||
features = append(features, feature)
|
features = append(features, feature)
|
||||||
s.server.db.Exec(`INSERT INTO feature_weapon VALUES ($1, $2)`, feature.StartTime, feature.ActiveFeatures)
|
s.server.db.Exec(`INSERT INTO feature_weapon VALUES ($1, $2)`, feature.StartTime, feature.ActiveFeatures)
|
||||||
}
|
}
|
||||||
|
|
||||||
bf := byteframe.NewByteFrame()
|
bf := byteframe.NewByteFrame()
|
||||||
bf.WriteUint8(2)
|
bf.WriteUint8(2)
|
||||||
bf.WriteUint32(uint32(Time_Current_Adjusted().Add(-5 * time.Minute).Unix()))
|
bf.WriteUint32(uint32(TimeAdjusted().Add(-5 * time.Minute).Unix()))
|
||||||
for _, feature := range features {
|
for _, feature := range features {
|
||||||
bf.WriteUint32(uint32(feature.StartTime.Unix()))
|
bf.WriteUint32(uint32(feature.StartTime.Unix()))
|
||||||
bf.WriteUint32(feature.ActiveFeatures)
|
bf.WriteUint32(feature.ActiveFeatures)
|
||||||
@@ -119,129 +119,97 @@ func generateFeatureWeapons(count int) activeFeature {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type loginBoost struct {
|
type loginBoost struct {
|
||||||
WeekReq, WeekCount uint8
|
WeekReq uint8 `db:"week_req"`
|
||||||
Available bool
|
WeekCount uint8
|
||||||
Expiration uint32
|
Active bool
|
||||||
|
Expiration time.Time `db:"expiration"`
|
||||||
|
Reset time.Time `db:"reset"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleMsgMhfGetKeepLoginBoostStatus(s *Session, p mhfpacket.MHFPacket) {
|
func handleMsgMhfGetKeepLoginBoostStatus(s *Session, p mhfpacket.MHFPacket) {
|
||||||
pkt := p.(*mhfpacket.MsgMhfGetKeepLoginBoostStatus)
|
pkt := p.(*mhfpacket.MsgMhfGetKeepLoginBoostStatus)
|
||||||
|
|
||||||
var loginBoostStatus []loginBoost
|
bf := byteframe.NewByteFrame()
|
||||||
insert := false
|
|
||||||
boostState, err := s.server.db.Query("SELECT week_req, week_count, available, end_time FROM login_boost_state WHERE char_id=$1 ORDER BY week_req ASC", s.charID)
|
var loginBoosts []loginBoost
|
||||||
|
rows, err := s.server.db.Queryx("SELECT week_req, expiration, reset FROM login_boost WHERE char_id=$1 ORDER BY week_req", s.charID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
doAckBufSucceed(s, pkt.AckHandle, make([]byte, 35))
|
||||||
|
return
|
||||||
}
|
}
|
||||||
for boostState.Next() {
|
for rows.Next() {
|
||||||
var boost loginBoost
|
var temp loginBoost
|
||||||
err = boostState.Scan(&boost.WeekReq, &boost.WeekCount, &boost.Available, &boost.Expiration)
|
rows.StructScan(&temp)
|
||||||
if err != nil {
|
loginBoosts = append(loginBoosts, temp)
|
||||||
panic(err)
|
|
||||||
}
|
}
|
||||||
loginBoostStatus = append(loginBoostStatus, boost)
|
if len(loginBoosts) == 0 {
|
||||||
|
temp := TimeWeekStart()
|
||||||
|
loginBoosts = []loginBoost{
|
||||||
|
{WeekReq: 1, Expiration: temp},
|
||||||
|
{WeekReq: 2, Expiration: temp},
|
||||||
|
{WeekReq: 3, Expiration: temp},
|
||||||
|
{WeekReq: 4, Expiration: temp},
|
||||||
|
{WeekReq: 5, Expiration: temp},
|
||||||
}
|
}
|
||||||
if len(loginBoostStatus) == 0 {
|
for _, boost := range loginBoosts {
|
||||||
// create default Entries (should only been week 1 with )
|
s.server.db.Exec(`INSERT INTO login_boost VALUES ($1, $2, $3, $4)`, s.charID, boost.WeekReq, boost.Expiration, time.Time{})
|
||||||
insert = true
|
|
||||||
loginBoostStatus = []loginBoost{
|
|
||||||
{
|
|
||||||
WeekReq: 1, // weeks needed
|
|
||||||
WeekCount: 0, // weeks passed
|
|
||||||
Available: true, // available
|
|
||||||
Expiration: 0, //uint32(t.Add(120 * time.Minute).Unix()), // uncomment to enable permanently
|
|
||||||
},
|
|
||||||
{
|
|
||||||
WeekReq: 2,
|
|
||||||
WeekCount: 0,
|
|
||||||
Available: true,
|
|
||||||
Expiration: 0,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
WeekReq: 3,
|
|
||||||
WeekCount: 0,
|
|
||||||
Available: true,
|
|
||||||
Expiration: 0,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
WeekReq: 4,
|
|
||||||
WeekCount: 0,
|
|
||||||
Available: true,
|
|
||||||
Expiration: 0,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
WeekReq: 5,
|
|
||||||
WeekCount: 0,
|
|
||||||
Available: true,
|
|
||||||
Expiration: 0,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
resp := byteframe.NewByteFrame()
|
|
||||||
CurrentWeek := Time_Current_Week_uint8()
|
for _, boost := range loginBoosts {
|
||||||
for d := range loginBoostStatus {
|
// Reset if next week
|
||||||
if CurrentWeek == 1 && loginBoostStatus[d].WeekCount <= 5 {
|
if !boost.Reset.IsZero() && boost.Reset.Before(TimeAdjusted()) {
|
||||||
loginBoostStatus[d].WeekCount = 0
|
boost.Expiration = TimeWeekStart()
|
||||||
|
boost.Reset = time.Time{}
|
||||||
|
s.server.db.Exec(`UPDATE login_boost SET expiration=$1, reset=$2 WHERE char_id=$3 AND week_req=$4`, boost.Expiration, boost.Reset, s.charID, boost.WeekReq)
|
||||||
}
|
}
|
||||||
if loginBoostStatus[d].WeekReq == CurrentWeek || loginBoostStatus[d].WeekCount != 0 {
|
|
||||||
loginBoostStatus[d].WeekCount = CurrentWeek
|
boost.WeekCount = uint8((TimeAdjusted().Unix()-boost.Expiration.Unix())/604800 + 1)
|
||||||
|
|
||||||
|
if boost.WeekCount >= boost.WeekReq {
|
||||||
|
boost.Active = true
|
||||||
|
boost.WeekCount = boost.WeekReq
|
||||||
}
|
}
|
||||||
if !loginBoostStatus[d].Available && loginBoostStatus[d].WeekCount >= loginBoostStatus[d].WeekReq && uint32(time.Now().In(time.FixedZone("UTC+1", 1*60*60)).Unix()) >= loginBoostStatus[d].Expiration {
|
|
||||||
loginBoostStatus[d].Expiration = 1
|
// Show reset timer on expired boosts
|
||||||
|
if boost.Reset.After(TimeAdjusted()) {
|
||||||
|
boost.Active = true
|
||||||
|
boost.WeekCount = 0
|
||||||
}
|
}
|
||||||
if !insert {
|
|
||||||
_, err := s.server.db.Exec(`UPDATE login_boost_state SET week_count=$1, end_time=$2 WHERE char_id=$3 AND week_req=$4`, loginBoostStatus[d].WeekCount, loginBoostStatus[d].Expiration, s.charID, loginBoostStatus[d].WeekReq)
|
bf.WriteUint8(boost.WeekReq)
|
||||||
if err != nil {
|
bf.WriteBool(boost.Active)
|
||||||
panic(err)
|
bf.WriteUint8(boost.WeekCount)
|
||||||
|
if !boost.Reset.IsZero() {
|
||||||
|
bf.WriteUint32(uint32(boost.Expiration.Unix()))
|
||||||
|
} else {
|
||||||
|
bf.WriteUint32(0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
for _, v := range loginBoostStatus {
|
doAckBufSucceed(s, pkt.AckHandle, bf.Data())
|
||||||
if insert {
|
|
||||||
_, err := s.server.db.Exec(`INSERT INTO login_boost_state (char_id, week_req, week_count, available, end_time) VALUES ($1,$2,$3,$4,$5)`, s.charID, v.WeekReq, v.WeekCount, v.Available, v.Expiration)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
resp.WriteUint8(v.WeekReq)
|
|
||||||
resp.WriteUint8(v.WeekCount)
|
|
||||||
resp.WriteBool(v.Available)
|
|
||||||
resp.WriteUint32(v.Expiration)
|
|
||||||
}
|
|
||||||
doAckBufSucceed(s, pkt.AckHandle, resp.Data())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleMsgMhfUseKeepLoginBoost(s *Session, p mhfpacket.MHFPacket) {
|
func handleMsgMhfUseKeepLoginBoost(s *Session, p mhfpacket.MHFPacket) {
|
||||||
// Directly interacts with MhfGetKeepLoginBoostStatus
|
|
||||||
// TODO: make these states persistent on a per character basis
|
|
||||||
pkt := p.(*mhfpacket.MsgMhfUseKeepLoginBoost)
|
pkt := p.(*mhfpacket.MsgMhfUseKeepLoginBoost)
|
||||||
var t = time.Now().In(time.FixedZone("UTC+1", 1*60*60))
|
var expiration time.Time
|
||||||
resp := byteframe.NewByteFrame()
|
bf := byteframe.NewByteFrame()
|
||||||
resp.WriteUint8(0)
|
bf.WriteUint8(0)
|
||||||
|
|
||||||
// response is end timestamp based on input
|
|
||||||
switch pkt.BoostWeekUsed {
|
switch pkt.BoostWeekUsed {
|
||||||
case 1:
|
case 1:
|
||||||
t = t.Add(120 * time.Minute)
|
fallthrough
|
||||||
resp.WriteUint32(uint32(t.Unix()))
|
|
||||||
case 2:
|
|
||||||
t = t.Add(240 * time.Minute)
|
|
||||||
resp.WriteUint32(uint32(t.Unix()))
|
|
||||||
case 3:
|
case 3:
|
||||||
t = t.Add(120 * time.Minute)
|
expiration = TimeAdjusted().Add(120 * time.Minute)
|
||||||
resp.WriteUint32(uint32(t.Unix()))
|
|
||||||
case 4:
|
case 4:
|
||||||
t = t.Add(180 * time.Minute)
|
expiration = TimeAdjusted().Add(180 * time.Minute)
|
||||||
resp.WriteUint32(uint32(t.Unix()))
|
case 2:
|
||||||
|
fallthrough
|
||||||
case 5:
|
case 5:
|
||||||
t = t.Add(240 * time.Minute)
|
expiration = TimeAdjusted().Add(240 * time.Minute)
|
||||||
resp.WriteUint32(uint32(t.Unix()))
|
|
||||||
}
|
}
|
||||||
_, err := s.server.db.Exec(`UPDATE login_boost_state SET available='false', end_time=$1 WHERE char_id=$2 AND week_req=$3`, uint32(t.Unix()), s.charID, pkt.BoostWeekUsed)
|
bf.WriteUint32(uint32(expiration.Unix()))
|
||||||
if err != nil {
|
s.server.db.Exec(`UPDATE login_boost SET expiration=$1, reset=$2 WHERE char_id=$3 AND week_req=$4`, expiration, TimeWeekNext(), s.charID, pkt.BoostWeekUsed)
|
||||||
panic(err)
|
doAckBufSucceed(s, pkt.AckHandle, bf.Data())
|
||||||
}
|
|
||||||
doAckBufSucceed(s, pkt.AckHandle, resp.Data())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleMsgMhfGetRestrictionEvent(s *Session, p mhfpacket.MHFPacket) {}
|
func handleMsgMhfGetRestrictionEvent(s *Session, p mhfpacket.MHFPacket) {}
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ func handleMsgMhfEnumerateRanking(s *Session, p mhfpacket.MHFPacket) {
|
|||||||
// Unk
|
// Unk
|
||||||
// Start?
|
// Start?
|
||||||
// End?
|
// End?
|
||||||
midnight := Time_Current_Midnight()
|
midnight := TimeMidnight()
|
||||||
switch state {
|
switch state {
|
||||||
case 1:
|
case 1:
|
||||||
bf.WriteUint32(uint32(midnight.Unix()))
|
bf.WriteUint32(uint32(midnight.Unix()))
|
||||||
@@ -60,13 +60,13 @@ func handleMsgMhfEnumerateRanking(s *Session, p mhfpacket.MHFPacket) {
|
|||||||
bf.WriteUint32(uint32(midnight.Add(7 * 24 * time.Hour).Unix()))
|
bf.WriteUint32(uint32(midnight.Add(7 * 24 * time.Hour).Unix()))
|
||||||
default:
|
default:
|
||||||
bf.WriteBytes(make([]byte, 16))
|
bf.WriteBytes(make([]byte, 16))
|
||||||
bf.WriteUint32(uint32(Time_Current_Adjusted().Unix())) // TS Current Time
|
bf.WriteUint32(uint32(TimeAdjusted().Unix())) // TS Current Time
|
||||||
bf.WriteUint8(3)
|
bf.WriteUint8(3)
|
||||||
bf.WriteBytes(make([]byte, 4))
|
bf.WriteBytes(make([]byte, 4))
|
||||||
doAckBufSucceed(s, pkt.AckHandle, bf.Data())
|
doAckBufSucceed(s, pkt.AckHandle, bf.Data())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
bf.WriteUint32(uint32(Time_Current_Adjusted().Unix())) // TS Current Time
|
bf.WriteUint32(uint32(TimeAdjusted().Unix())) // TS Current Time
|
||||||
bf.WriteUint8(3)
|
bf.WriteUint8(3)
|
||||||
ps.Uint8(bf, "", false)
|
ps.Uint8(bf, "", false)
|
||||||
bf.WriteUint16(0) // numEvents
|
bf.WriteUint16(0) // numEvents
|
||||||
@@ -101,7 +101,7 @@ func cleanupFesta(s *Session) {
|
|||||||
|
|
||||||
func generateFestaTimestamps(s *Session, start uint32, debug bool) []uint32 {
|
func generateFestaTimestamps(s *Session, start uint32, debug bool) []uint32 {
|
||||||
timestamps := make([]uint32, 5)
|
timestamps := make([]uint32, 5)
|
||||||
midnight := Time_Current_Midnight()
|
midnight := TimeMidnight()
|
||||||
if debug && start <= 3 {
|
if debug && start <= 3 {
|
||||||
midnight := uint32(midnight.Unix())
|
midnight := uint32(midnight.Unix())
|
||||||
switch start {
|
switch start {
|
||||||
@@ -126,7 +126,7 @@ func generateFestaTimestamps(s *Session, start uint32, debug bool) []uint32 {
|
|||||||
}
|
}
|
||||||
return timestamps
|
return timestamps
|
||||||
}
|
}
|
||||||
if start == 0 || Time_Current_Adjusted().Unix() > int64(start)+2977200 {
|
if start == 0 || TimeAdjusted().Unix() > int64(start)+2977200 {
|
||||||
cleanupFesta(s)
|
cleanupFesta(s)
|
||||||
// Generate a new festa, starting midnight tomorrow
|
// Generate a new festa, starting midnight tomorrow
|
||||||
start = uint32(midnight.Add(24 * time.Hour).Unix())
|
start = uint32(midnight.Add(24 * time.Hour).Unix())
|
||||||
@@ -170,7 +170,7 @@ func handleMsgMhfInfoFesta(s *Session, p mhfpacket.MHFPacket) {
|
|||||||
timestamps = generateFestaTimestamps(s, start, false)
|
timestamps = generateFestaTimestamps(s, start, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
if timestamps[0] > uint32(Time_Current_Adjusted().Unix()) {
|
if timestamps[0] > uint32(TimeAdjusted().Unix()) {
|
||||||
doAckBufSucceed(s, pkt.AckHandle, make([]byte, 4))
|
doAckBufSucceed(s, pkt.AckHandle, make([]byte, 4))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -183,7 +183,7 @@ func handleMsgMhfInfoFesta(s *Session, p mhfpacket.MHFPacket) {
|
|||||||
for _, timestamp := range timestamps {
|
for _, timestamp := range timestamps {
|
||||||
bf.WriteUint32(timestamp)
|
bf.WriteUint32(timestamp)
|
||||||
}
|
}
|
||||||
bf.WriteUint32(uint32(Time_Current_Adjusted().Unix()))
|
bf.WriteUint32(uint32(TimeAdjusted().Unix()))
|
||||||
bf.WriteUint8(4)
|
bf.WriteUint8(4)
|
||||||
ps.Uint8(bf, "", false)
|
ps.Uint8(bf, "", false)
|
||||||
bf.WriteUint32(0)
|
bf.WriteUint32(0)
|
||||||
|
|||||||
@@ -1735,54 +1735,56 @@ type GuildMeal struct {
|
|||||||
ID uint32 `db:"id"`
|
ID uint32 `db:"id"`
|
||||||
MealID uint32 `db:"meal_id"`
|
MealID uint32 `db:"meal_id"`
|
||||||
Level uint32 `db:"level"`
|
Level uint32 `db:"level"`
|
||||||
Expires uint32 `db:"expires"`
|
CreatedAt time.Time `db:"created_at"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleMsgMhfLoadGuildCooking(s *Session, p mhfpacket.MHFPacket) {
|
func handleMsgMhfLoadGuildCooking(s *Session, p mhfpacket.MHFPacket) {
|
||||||
pkt := p.(*mhfpacket.MsgMhfLoadGuildCooking)
|
pkt := p.(*mhfpacket.MsgMhfLoadGuildCooking)
|
||||||
|
|
||||||
guild, _ := GetGuildInfoByCharacterId(s, s.charID)
|
guild, _ := GetGuildInfoByCharacterId(s, s.charID)
|
||||||
data, err := s.server.db.Queryx("SELECT id, meal_id, level, expires FROM guild_meals WHERE guild_id = $1", guild.ID)
|
data, err := s.server.db.Queryx("SELECT id, meal_id, level, created_at FROM guild_meals WHERE guild_id = $1", guild.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.logger.Error("Failed to get guild meals from db", zap.Error(err))
|
s.logger.Error("Failed to get guild meals from db", zap.Error(err))
|
||||||
doAckBufSucceed(s, pkt.AckHandle, make([]byte, 2))
|
doAckBufSucceed(s, pkt.AckHandle, make([]byte, 2))
|
||||||
|
return
|
||||||
}
|
}
|
||||||
temp := byteframe.NewByteFrame()
|
var meals []GuildMeal
|
||||||
count := 0
|
var temp GuildMeal
|
||||||
for data.Next() {
|
for data.Next() {
|
||||||
mealData := &GuildMeal{}
|
err = data.StructScan(&temp)
|
||||||
err = data.StructScan(&mealData)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if mealData.Expires > uint32(Time_Current_Adjusted().Add(-60*time.Minute).Unix()) {
|
if temp.CreatedAt.Add(60 * time.Minute).After(TimeAdjusted()) {
|
||||||
count++
|
meals = append(meals, temp)
|
||||||
temp.WriteUint32(mealData.ID)
|
|
||||||
temp.WriteUint32(mealData.MealID)
|
|
||||||
temp.WriteUint32(mealData.Level)
|
|
||||||
temp.WriteUint32(mealData.Expires)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bf := byteframe.NewByteFrame()
|
bf := byteframe.NewByteFrame()
|
||||||
bf.WriteUint16(uint16(count))
|
bf.WriteUint16(uint16(len(meals)))
|
||||||
bf.WriteBytes(temp.Data())
|
for _, meal := range meals {
|
||||||
|
bf.WriteUint32(meal.ID)
|
||||||
|
bf.WriteUint32(meal.MealID)
|
||||||
|
bf.WriteUint32(meal.Level)
|
||||||
|
bf.WriteUint32(uint32(meal.CreatedAt.Unix()))
|
||||||
|
}
|
||||||
doAckBufSucceed(s, pkt.AckHandle, bf.Data())
|
doAckBufSucceed(s, pkt.AckHandle, bf.Data())
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleMsgMhfRegistGuildCooking(s *Session, p mhfpacket.MHFPacket) {
|
func handleMsgMhfRegistGuildCooking(s *Session, p mhfpacket.MHFPacket) {
|
||||||
pkt := p.(*mhfpacket.MsgMhfRegistGuildCooking)
|
pkt := p.(*mhfpacket.MsgMhfRegistGuildCooking)
|
||||||
guild, _ := GetGuildInfoByCharacterId(s, s.charID)
|
guild, _ := GetGuildInfoByCharacterId(s, s.charID)
|
||||||
|
currentTime := TimeAdjusted()
|
||||||
if pkt.OverwriteID != 0 {
|
if pkt.OverwriteID != 0 {
|
||||||
_, err := s.server.db.Exec("DELETE FROM guild_meals WHERE id = $1", pkt.OverwriteID)
|
s.server.db.Exec("UPDATE guild_meals SET meal_id = $1, level = $2, created_at = $3 WHERE id = $4", pkt.MealID, pkt.Success, currentTime, pkt.OverwriteID)
|
||||||
if err != nil {
|
} else {
|
||||||
s.logger.Error("Failed to delete meal in db", zap.Error(err))
|
s.server.db.QueryRow("INSERT INTO guild_meals (guild_id, meal_id, level, created_at) VALUES ($1, $2, $3, $4) RETURNING id", guild.ID, pkt.MealID, pkt.Success, currentTime).Scan(&pkt.OverwriteID)
|
||||||
}
|
}
|
||||||
}
|
bf := byteframe.NewByteFrame()
|
||||||
_, err := s.server.db.Exec("INSERT INTO guild_meals (guild_id, meal_id, level, expires) VALUES ($1, $2, $3, $4)", guild.ID, pkt.MealID, pkt.Success, Time_Current_Adjusted().Add(30*time.Minute).Unix())
|
bf.WriteUint16(1)
|
||||||
if err != nil {
|
bf.WriteUint32(pkt.OverwriteID)
|
||||||
s.logger.Error("Failed to register meal in db", zap.Error(err))
|
bf.WriteUint32(uint32(pkt.MealID))
|
||||||
}
|
bf.WriteUint32(uint32(pkt.Success))
|
||||||
doAckSimpleSucceed(s, pkt.AckHandle, []byte{0x01, 0x00})
|
bf.WriteUint32(uint32(currentTime.Unix()))
|
||||||
|
doAckBufSucceed(s, pkt.AckHandle, bf.Data())
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleMsgMhfGetGuildWeeklyBonusMaster(s *Session, p mhfpacket.MHFPacket) {
|
func handleMsgMhfGetGuildWeeklyBonusMaster(s *Session, p mhfpacket.MHFPacket) {
|
||||||
@@ -1840,7 +1842,7 @@ func handleMsgMhfEnumerateGuildMessageBoard(s *Session, p mhfpacket.MHFPacket) {
|
|||||||
doAckBufSucceed(s, pkt.AckHandle, make([]byte, 4))
|
doAckBufSucceed(s, pkt.AckHandle, make([]byte, 4))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
s.server.db.Exec("UPDATE characters SET guild_post_checked = $1 WHERE id = $2", time.Now(), s.charID)
|
s.server.db.Exec("UPDATE characters SET guild_post_checked = now() WHERE id = $1", s.charID)
|
||||||
bf := byteframe.NewByteFrame()
|
bf := byteframe.NewByteFrame()
|
||||||
var postCount uint32
|
var postCount uint32
|
||||||
for msgs.Next() {
|
for msgs.Next() {
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ func handleMsgMhfLoadGuildAdventure(s *Session, p mhfpacket.MHFPacket) {
|
|||||||
func handleMsgMhfRegistGuildAdventure(s *Session, p mhfpacket.MHFPacket) {
|
func handleMsgMhfRegistGuildAdventure(s *Session, p mhfpacket.MHFPacket) {
|
||||||
pkt := p.(*mhfpacket.MsgMhfRegistGuildAdventure)
|
pkt := p.(*mhfpacket.MsgMhfRegistGuildAdventure)
|
||||||
guild, _ := GetGuildInfoByCharacterId(s, s.charID)
|
guild, _ := GetGuildInfoByCharacterId(s, s.charID)
|
||||||
_, err := s.server.db.Exec("INSERT INTO guild_adventures (guild_id, destination, depart, return) VALUES ($1, $2, $3, $4)", guild.ID, pkt.Destination, Time_Current_Adjusted().Unix(), Time_Current_Adjusted().Add(6*time.Hour).Unix())
|
_, err := s.server.db.Exec("INSERT INTO guild_adventures (guild_id, destination, depart, return) VALUES ($1, $2, $3, $4)", guild.ID, pkt.Destination, TimeAdjusted().Unix(), TimeAdjusted().Add(6*time.Hour).Unix())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.logger.Error("Failed to register guild adventure", zap.Error(err))
|
s.logger.Error("Failed to register guild adventure", zap.Error(err))
|
||||||
}
|
}
|
||||||
@@ -87,7 +87,7 @@ func handleMsgMhfChargeGuildAdventure(s *Session, p mhfpacket.MHFPacket) {
|
|||||||
func handleMsgMhfRegistGuildAdventureDiva(s *Session, p mhfpacket.MHFPacket) {
|
func handleMsgMhfRegistGuildAdventureDiva(s *Session, p mhfpacket.MHFPacket) {
|
||||||
pkt := p.(*mhfpacket.MsgMhfRegistGuildAdventureDiva)
|
pkt := p.(*mhfpacket.MsgMhfRegistGuildAdventureDiva)
|
||||||
guild, _ := GetGuildInfoByCharacterId(s, s.charID)
|
guild, _ := GetGuildInfoByCharacterId(s, s.charID)
|
||||||
_, err := s.server.db.Exec("INSERT INTO guild_adventures (guild_id, destination, charge, depart, return) VALUES ($1, $2, $3, $4, $5)", guild.ID, pkt.Destination, pkt.Charge, Time_Current_Adjusted().Unix(), Time_Current_Adjusted().Add(1*time.Hour).Unix())
|
_, err := s.server.db.Exec("INSERT INTO guild_adventures (guild_id, destination, charge, depart, return) VALUES ($1, $2, $3, $4, $5)", guild.ID, pkt.Destination, pkt.Charge, TimeAdjusted().Unix(), TimeAdjusted().Add(1*time.Hour).Unix())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.logger.Error("Failed to register guild adventure", zap.Error(err))
|
s.logger.Error("Failed to register guild adventure", zap.Error(err))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ func handleMsgMhfEnumerateGuildTresure(s *Session, p mhfpacket.MHFPacket) {
|
|||||||
}
|
}
|
||||||
bf := byteframe.NewByteFrame()
|
bf := byteframe.NewByteFrame()
|
||||||
hunts := 0
|
hunts := 0
|
||||||
rows, _ := s.server.db.Queryx("SELECT id, host_id, destination, level, return, acquired, claimed, hunters, treasure, hunt_data FROM guild_hunts WHERE guild_id=$1 AND $2 < return+604800", guild.ID, Time_Current_Adjusted().Unix())
|
rows, _ := s.server.db.Queryx("SELECT id, host_id, destination, level, return, acquired, claimed, hunters, treasure, hunt_data FROM guild_hunts WHERE guild_id=$1 AND $2 < return+604800", guild.ID, TimeAdjusted().Unix())
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
hunt := &TreasureHunt{}
|
hunt := &TreasureHunt{}
|
||||||
err = rows.StructScan(&hunt)
|
err = rows.StructScan(&hunt)
|
||||||
@@ -101,7 +101,7 @@ func handleMsgMhfRegistGuildTresure(s *Session, p mhfpacket.MHFPacket) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
_, err = s.server.db.Exec("INSERT INTO guild_hunts (guild_id, host_id, destination, level, return, hunt_data, cats_used) VALUES ($1, $2, $3, $4, $5, $6, $7)",
|
_, err = s.server.db.Exec("INSERT INTO guild_hunts (guild_id, host_id, destination, level, return, hunt_data, cats_used) VALUES ($1, $2, $3, $4, $5, $6, $7)",
|
||||||
guild.ID, s.charID, destination, level, Time_Current_Adjusted().Unix(), huntData.Data(), catsUsed)
|
guild.ID, s.charID, destination, level, TimeAdjusted().Unix(), huntData.Data(), catsUsed)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,9 +43,9 @@ func handleMsgMhfLoadLegendDispatch(s *Session, p mhfpacket.MHFPacket) {
|
|||||||
Unk uint32
|
Unk uint32
|
||||||
Timestamp uint32
|
Timestamp uint32
|
||||||
}{
|
}{
|
||||||
{0, uint32(Time_Current_Midnight().Add(-12 * time.Hour).Unix())},
|
{0, uint32(TimeMidnight().Add(-12 * time.Hour).Unix())},
|
||||||
{0, uint32(Time_Current_Midnight().Add(12 * time.Hour).Unix())},
|
{0, uint32(TimeMidnight().Add(12 * time.Hour).Unix())},
|
||||||
{0, uint32(Time_Current_Midnight().Add(36 * time.Hour).Unix())},
|
{0, uint32(TimeMidnight().Add(36 * time.Hour).Unix())},
|
||||||
}
|
}
|
||||||
bf.WriteUint8(uint8(len(legendDispatch)))
|
bf.WriteUint8(uint8(len(legendDispatch)))
|
||||||
for _, dispatch := range legendDispatch {
|
for _, dispatch := range legendDispatch {
|
||||||
@@ -164,8 +164,8 @@ func handleMsgMhfReadMercenaryW(s *Session, p mhfpacket.MHFPacket) {
|
|||||||
bf.WriteUint32(pactID)
|
bf.WriteUint32(pactID)
|
||||||
bf.WriteUint32(cid)
|
bf.WriteUint32(cid)
|
||||||
bf.WriteBool(false) // ?
|
bf.WriteBool(false) // ?
|
||||||
bf.WriteUint32(uint32(Time_Current_Adjusted().Add(time.Hour * 24 * -8).Unix()))
|
bf.WriteUint32(uint32(TimeAdjusted().Add(time.Hour * 24 * -8).Unix()))
|
||||||
bf.WriteUint32(uint32(Time_Current_Adjusted().Add(time.Hour * 24 * -1).Unix()))
|
bf.WriteUint32(uint32(TimeAdjusted().Add(time.Hour * 24 * -1).Unix()))
|
||||||
bf.WriteBytes(stringsupport.PaddedString(name, 18, true))
|
bf.WriteBytes(stringsupport.PaddedString(name, 18, true))
|
||||||
} else {
|
} else {
|
||||||
bf.WriteUint8(0)
|
bf.WriteUint8(0)
|
||||||
@@ -180,8 +180,8 @@ func handleMsgMhfReadMercenaryW(s *Session, p mhfpacket.MHFPacket) {
|
|||||||
rows.Scan(&name, &cid, &pactID)
|
rows.Scan(&name, &cid, &pactID)
|
||||||
temp.WriteUint32(pactID)
|
temp.WriteUint32(pactID)
|
||||||
temp.WriteUint32(cid)
|
temp.WriteUint32(cid)
|
||||||
temp.WriteUint32(uint32(Time_Current_Adjusted().Add(time.Hour * 24 * -8).Unix()))
|
temp.WriteUint32(uint32(TimeAdjusted().Add(time.Hour * 24 * -8).Unix()))
|
||||||
temp.WriteUint32(uint32(Time_Current_Adjusted().Add(time.Hour * 24 * -1).Unix()))
|
temp.WriteUint32(uint32(TimeAdjusted().Add(time.Hour * 24 * -1).Unix()))
|
||||||
temp.WriteBytes(stringsupport.PaddedString(name, 18, true))
|
temp.WriteBytes(stringsupport.PaddedString(name, 18, true))
|
||||||
}
|
}
|
||||||
bf.WriteUint8(loans)
|
bf.WriteUint8(loans)
|
||||||
@@ -346,7 +346,7 @@ func getGuildAirouList(s *Session) []CatDefinition {
|
|||||||
FROM guild_hunts gh
|
FROM guild_hunts gh
|
||||||
INNER JOIN characters c
|
INNER JOIN characters c
|
||||||
ON gh.host_id = c.id
|
ON gh.host_id = c.id
|
||||||
WHERE c.id=$1 AND gh.return+$2>$3`, s.charID, tempBanDuration, Time_Current_Adjusted().Unix())
|
WHERE c.id=$1 AND gh.return+$2>$3`, s.charID, tempBanDuration, TimeAdjusted().Unix())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.logger.Warn("Failed to get recently used airous", zap.Error(err))
|
s.logger.Warn("Failed to get recently used airous", zap.Error(err))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -517,7 +517,7 @@ func handleMsgMhfGetStepupStatus(s *Session, p mhfpacket.MHFPacket) {
|
|||||||
}
|
}
|
||||||
bf := byteframe.NewByteFrame()
|
bf := byteframe.NewByteFrame()
|
||||||
bf.WriteUint8(step)
|
bf.WriteUint8(step)
|
||||||
bf.WriteUint32(uint32(Time_Current_Adjusted().Unix()))
|
bf.WriteUint32(uint32(TimeAdjusted().Unix()))
|
||||||
doAckBufSucceed(s, pkt.AckHandle, bf.Data())
|
doAckBufSucceed(s, pkt.AckHandle, bf.Data())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ func handleMsgMhfInfoTournament(s *Session, p mhfpacket.MHFPacket) {
|
|||||||
|
|
||||||
switch pkt.Unk0 {
|
switch pkt.Unk0 {
|
||||||
case 0:
|
case 0:
|
||||||
bf.WriteUint32(uint32(Time_Current_Adjusted().Unix()))
|
bf.WriteUint32(uint32(TimeAdjusted().Unix()))
|
||||||
bf.WriteUint32(0) // Tied to schedule ID?
|
bf.WriteUint32(0) // Tied to schedule ID?
|
||||||
case 1:
|
case 1:
|
||||||
|
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ func NewSession(server *Server, conn net.Conn) *Session {
|
|||||||
cryptConn: network.NewCryptConn(conn),
|
cryptConn: network.NewCryptConn(conn),
|
||||||
sendPackets: make(chan packet, 20),
|
sendPackets: make(chan packet, 20),
|
||||||
clientContext: &clientctx.ClientContext{}, // Unused
|
clientContext: &clientctx.ClientContext{}, // Unused
|
||||||
sessionStart: Time_Current_Adjusted().Unix(),
|
sessionStart: TimeAdjusted().Unix(),
|
||||||
stageMoveStack: stringstack.New(),
|
stageMoveStack: stringstack.New(),
|
||||||
}
|
}
|
||||||
return s
|
return s
|
||||||
|
|||||||
25
server/channelserver/sys_time.go
Normal file
25
server/channelserver/sys_time.go
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
package channelserver
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TimeAdjusted() time.Time {
|
||||||
|
baseTime := time.Now().In(time.FixedZone("UTC+9", 9*60*60))
|
||||||
|
return time.Date(baseTime.Year(), baseTime.Month(), baseTime.Day(), baseTime.Hour(), baseTime.Minute(), baseTime.Second(), baseTime.Nanosecond(), baseTime.Location())
|
||||||
|
}
|
||||||
|
|
||||||
|
func TimeMidnight() time.Time {
|
||||||
|
baseTime := time.Now().In(time.FixedZone("UTC+9", 9*60*60))
|
||||||
|
return time.Date(baseTime.Year(), baseTime.Month(), baseTime.Day(), 0, 0, 0, 0, baseTime.Location())
|
||||||
|
}
|
||||||
|
|
||||||
|
func TimeWeekStart() time.Time {
|
||||||
|
midnight := TimeMidnight()
|
||||||
|
offset := (int(midnight.Weekday()) - 1) * -24
|
||||||
|
return midnight.Add(time.Hour * time.Duration(offset))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TimeWeekNext() time.Time {
|
||||||
|
return TimeWeekStart().Add(time.Hour * 24 * 7)
|
||||||
|
}
|
||||||
@@ -1,58 +0,0 @@
|
|||||||
package channelserver
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
Offset = 9
|
|
||||||
YearAdjust = -7
|
|
||||||
MonthAdjust = 0
|
|
||||||
DayAdjust = 0
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
TimeStatic = time.Time{}
|
|
||||||
)
|
|
||||||
|
|
||||||
func Time_Current() time.Time {
|
|
||||||
baseTime := time.Now().In(time.FixedZone(fmt.Sprintf("UTC+%d", Offset), Offset*60*60))
|
|
||||||
return baseTime
|
|
||||||
}
|
|
||||||
|
|
||||||
func Time_Current_Adjusted() time.Time {
|
|
||||||
baseTime := time.Now().In(time.FixedZone(fmt.Sprintf("UTC+%d", Offset), Offset*60*60)).AddDate(YearAdjust, MonthAdjust, DayAdjust)
|
|
||||||
return time.Date(baseTime.Year(), baseTime.Month(), baseTime.Day(), baseTime.Hour(), baseTime.Minute(), baseTime.Second(), baseTime.Nanosecond(), baseTime.Location())
|
|
||||||
}
|
|
||||||
|
|
||||||
func Time_Current_Midnight() time.Time {
|
|
||||||
baseTime := time.Now().In(time.FixedZone(fmt.Sprintf("UTC+%d", Offset), Offset*60*60)).AddDate(YearAdjust, MonthAdjust, DayAdjust)
|
|
||||||
return time.Date(baseTime.Year(), baseTime.Month(), baseTime.Day(), 0, 0, 0, 0, baseTime.Location())
|
|
||||||
}
|
|
||||||
|
|
||||||
func TimeWeekStart() time.Time {
|
|
||||||
midnight := Time_Current_Midnight()
|
|
||||||
offset := (int(midnight.Weekday()) - 1) * -24
|
|
||||||
return midnight.Add(time.Hour * time.Duration(offset))
|
|
||||||
}
|
|
||||||
|
|
||||||
func TimeWeekNext() time.Time {
|
|
||||||
return TimeWeekStart().Add(time.Hour * 24 * 7)
|
|
||||||
}
|
|
||||||
|
|
||||||
func Time_Current_Week_uint8() uint8 {
|
|
||||||
baseTime := time.Now().In(time.FixedZone(fmt.Sprintf("UTC+%d", Offset), Offset*60*60)).AddDate(YearAdjust, MonthAdjust, DayAdjust)
|
|
||||||
|
|
||||||
_, thisWeek := baseTime.ISOWeek()
|
|
||||||
_, beginningOfTheMonth := time.Date(baseTime.Year(), baseTime.Month(), 1, 0, 0, 0, 0, baseTime.Location()).ISOWeek()
|
|
||||||
|
|
||||||
return uint8(1 + thisWeek - beginningOfTheMonth)
|
|
||||||
}
|
|
||||||
|
|
||||||
func Time_static() time.Time {
|
|
||||||
if TimeStatic.IsZero() {
|
|
||||||
TimeStatic = Time_Current_Adjusted()
|
|
||||||
}
|
|
||||||
return TimeStatic
|
|
||||||
}
|
|
||||||
@@ -66,7 +66,7 @@ func encodeServerInfo(config *config.Config, s *Server, local bool) []byte {
|
|||||||
bf.WriteUint16(0x3039)
|
bf.WriteUint16(0x3039)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bf.WriteUint32(uint32(channelserver.Time_Current_Adjusted().Unix()))
|
bf.WriteUint32(uint32(channelserver.TimeAdjusted().Unix()))
|
||||||
bf.WriteUint32(0x0000003C)
|
bf.WriteUint32(0x0000003C)
|
||||||
return bf.Data()
|
return bf.Data()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -127,12 +127,7 @@ func (s *Session) makeSignInResp(uid int) []byte {
|
|||||||
bf.WriteUint16(0x0001)
|
bf.WriteUint16(0x0001)
|
||||||
bf.WriteUint16(0x4E20)
|
bf.WriteUint16(0x4E20)
|
||||||
ps.Uint16(bf, "", false) // unk ipv4
|
ps.Uint16(bf, "", false) // unk ipv4
|
||||||
if returnExpiry.Before(time.Now()) {
|
|
||||||
// Hack to make Return work while having a non-adjusted expiry
|
|
||||||
bf.WriteUint32(0)
|
|
||||||
} else {
|
|
||||||
bf.WriteUint32(uint32(returnExpiry.Unix()))
|
bf.WriteUint32(uint32(returnExpiry.Unix()))
|
||||||
}
|
|
||||||
bf.WriteUint32(0x00000000)
|
bf.WriteUint32(0x00000000)
|
||||||
bf.WriteUint32(0x0A5197DF) // unk id
|
bf.WriteUint32(0x0A5197DF) // unk id
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user