From c09a6cfd2518b50b38fd7c4d62f96914f0a87749 Mon Sep 17 00:00:00 2001 From: CPunch Date: Sun, 25 Jun 2023 18:29:31 -0500 Subject: [PATCH] fixed sent server time --- core/protocol/cnpeer.go | 5 +++++ login/login.go | 3 +-- shard/join.go | 3 +-- shard/movement.go | 14 ++++++-------- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/core/protocol/cnpeer.go b/core/protocol/cnpeer.go index 2c19d66..83d00f0 100644 --- a/core/protocol/cnpeer.go +++ b/core/protocol/cnpeer.go @@ -6,6 +6,7 @@ import ( "io" "log" "net" + "time" "github.com/CPunch/gopenfusion/core/protocol/pool" ) @@ -28,6 +29,10 @@ type CNPeer struct { alive bool } +func GetTime() uint64 { + return uint64(time.Now().UnixMilli()) +} + func NewCNPeer(eRecv chan *Event, conn net.Conn) *CNPeer { return &CNPeer{ conn: conn, diff --git a/login/login.go b/login/login.go index dbf1016..502402d 100644 --- a/login/login.go +++ b/login/login.go @@ -5,7 +5,6 @@ import ( "fmt" "log" "math/rand" - "time" "github.com/CPunch/gopenfusion/config" "github.com/CPunch/gopenfusion/core/db" @@ -34,7 +33,7 @@ func (server *LoginServer) AcceptLogin(peer *protocol.CNPeer, SzID string, IClie ISlotNum: ISlotNum, IPaymentFlag: 1, IOpenBetaFlag: 0, - UiSvrTime: uint64(time.Now().Unix()), + UiSvrTime: protocol.GetTime(), } if err := peer.Send(protocol.P_LS2CL_REP_LOGIN_SUCC, resp); err != nil { diff --git a/shard/join.go b/shard/join.go index 4faca25..b507506 100644 --- a/shard/join.go +++ b/shard/join.go @@ -3,7 +3,6 @@ package shard import ( "fmt" "log" - "time" "github.com/CPunch/gopenfusion/core/entity" "github.com/CPunch/gopenfusion/core/protocol" @@ -47,7 +46,7 @@ func (server *ShardServer) RequestEnter(peer *protocol.CNPeer, pkt protocol.Pack resp := &protocol.SP_FE2CL_REP_PC_ENTER_SUCC{ IID: int32(plr.PlayerID), PCLoadData2CL: plr.ToPCLoadData2CL(), - UiSvrTime: uint64(time.Now().Unix()), + UiSvrTime: protocol.GetTime(), } // setup peer diff --git a/shard/movement.go b/shard/movement.go index 260e249..76a0079 100644 --- a/shard/movement.go +++ b/shard/movement.go @@ -1,8 +1,6 @@ package shard import ( - "time" - "github.com/CPunch/gopenfusion/core/entity" "github.com/CPunch/gopenfusion/core/protocol" ) @@ -32,7 +30,7 @@ func (server *ShardServer) playerMove(peer *protocol.CNPeer, pkt protocol.Packet } return server.sendOthersPacket(plr, protocol.P_FE2CL_PC_MOVE, protocol.SP_FE2CL_PC_MOVE{ - ICliTime: uint64(time.Now().Unix()), + ICliTime: move.ICliTime, IX: move.IX, IY: move.IY, IZ: move.IZ, @@ -43,7 +41,7 @@ func (server *ShardServer) playerMove(peer *protocol.CNPeer, pkt protocol.Packet CKeyValue: move.CKeyValue, ISpeed: move.ISpeed, IID: int32(plr.PlayerID), - ISvrTime: uint64(time.Now().Unix()), + ISvrTime: protocol.GetTime(), }) } @@ -63,12 +61,12 @@ func (server *ShardServer) playerStop(peer *protocol.CNPeer, pkt protocol.Packet } return server.sendOthersPacket(plr, protocol.P_FE2CL_PC_STOP, protocol.SP_FE2CL_PC_STOP{ - ICliTime: uint64(time.Now().Unix()), + ICliTime: stop.ICliTime, IX: stop.IX, IY: stop.IY, IZ: stop.IZ, IID: int32(plr.PlayerID), - ISvrTime: uint64(time.Now().Unix()), + ISvrTime: protocol.GetTime(), }) } @@ -88,7 +86,7 @@ func (server *ShardServer) playerJump(peer *protocol.CNPeer, pkt protocol.Packet } return server.sendOthersPacket(plr, protocol.P_FE2CL_PC_JUMP, protocol.SP_FE2CL_PC_JUMP{ - ICliTime: uint64(time.Now().Unix()), + ICliTime: jump.ICliTime, IX: jump.IX, IY: jump.IY, IZ: jump.IZ, @@ -99,6 +97,6 @@ func (server *ShardServer) playerJump(peer *protocol.CNPeer, pkt protocol.Packet CKeyValue: jump.CKeyValue, ISpeed: jump.ISpeed, IID: int32(plr.PlayerID), - ISvrTime: uint64(time.Now().Unix()), + ISvrTime: protocol.GetTime(), }) }