62 lines
1.8 KiB
Go
62 lines
1.8 KiB
Go
package gameserver
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"math"
|
|
"time"
|
|
|
|
"ananta-ps/pkg/protocol"
|
|
)
|
|
|
|
func (s *Server) SetWorldWeather(weatherId uint32) error {
|
|
log.Printf("[WEATHER] Setting world weather to %d", weatherId)
|
|
w := protocol.NewUxWriter()
|
|
w.U32(weatherId).U32(weatherId).U32(0)
|
|
payload := w.Bytes()
|
|
|
|
methodID := protocol.MethodGetMethodIDDefault("SyncPlayerWeather", 68712141)
|
|
for _, sess := range s.GetActiveSessions() {
|
|
if err := sess.NotifyData(methodID, payload); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (s *Server) SetWorldTimeOfDay(hour float32) error {
|
|
if math.IsNaN(float64(hour)) || math.IsInf(float64(hour), 0) || hour < 0 || hour >= 24 {
|
|
return fmt.Errorf("hour must be in [0,24)")
|
|
}
|
|
log.Printf("[WEATHER] Setting world time of day to %.1f:00", hour)
|
|
w := protocol.NewUxWriter()
|
|
w.U32(uint32(time.Now().Unix())).U32(uint32(hour * 3600)).Bool(true).Bool(false).U32(0).I32(0).I32(0)
|
|
payload := w.Bytes()
|
|
|
|
methodID := protocol.MethodGetMethodIDDefault("SyncPlayerCurrentTime", 68337673)
|
|
for _, sess := range s.GetActiveSessions() {
|
|
if err := sess.NotifyData(methodID, payload); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (s *Server) handleGmUnlockAllFogMap(sess *Session, pkt *protocol.RpcPacket) error {
|
|
log.Printf("[FOG] GmUnlockAllFogMap requested")
|
|
if err := sess.ReturnEmptyOk(pkt.InvokeID, pkt.MethodID); err != nil {
|
|
return err
|
|
}
|
|
|
|
wFog := protocol.NewUxWriter()
|
|
wFog.U32(uint32(sess.activeScene)).Bool(true)
|
|
return sess.NotifyData(protocol.MethodSyncSceneFogMapAllUnlock, wFog.Bytes())
|
|
}
|
|
|
|
func (s *Server) handleGmSetAmbianceEnabled(sess *Session, pkt *protocol.RpcPacket) error {
|
|
r := protocol.NewUxReader(pkt.Body)
|
|
enabled, _ := r.Bool()
|
|
log.Printf("[AMBIENCE] SetAmbianceEnabled = %v", enabled)
|
|
return sess.ReturnEmptyOk(pkt.InvokeID, pkt.MethodID)
|
|
}
|