GCAskServerTime 是请求服务器时间后的结果包,会返回年月日时分秒、请求类型和 Unix 时间戳。
包信息
| 项目 |
内容 |
| 封包 ID |
334 |
| 包名 |
GCAskServerTime |
| 方向 |
Server -> Client |
| 对应请求 |
CGAskServerTime |
| 固定包长 |
15 |
| 作用 |
返回当前服务器日期时间与时间戳 |
包体结构
| 偏移 |
长度 |
字段 |
类型 |
含义 |
0x00 |
0x02 |
year |
uint16 |
年 |
0x02 |
0x01 |
month |
uint8 |
月;当前 Lua 按 0 基月值写入 |
0x03 |
0x01 |
day |
uint8 |
日 |
0x04 |
0x01 |
hour |
uint8 |
时 |
0x05 |
0x01 |
minute |
uint8 |
分 |
0x06 |
0x01 |
second |
uint8 |
秒 |
0x07 |
0x04 |
ask_type |
uint32 |
原样回传的请求类型 |
0x0B |
0x04 |
ansi_time |
uint32 |
Unix 时间戳 |
总长度:
15 字节
当前实际行为
- 当前
msgagent.lua 收到 CGAskServerTime 后,会用 os.time() 和 os.date("*t") 组包。
- 现役实现会把请求里的
ask_type 原样写回。
month 当前按 date.month - 1 写入,所以这是旧客户端风格的 0 基月份。
服务端落点
- 协议定义:
/home/ubuntu/Game2/services/game/packet.lua
- 发送点:
/home/ubuntu/Game2/services/msgagent.lua
- 对应请求文档:
/home/ubuntu/Game2/docs/07_登录_网络_封包/packet.CGAskServerTime.md
关键代码
function request:CGAskServerTime()
local ret = packet_def.GCAskServerTime.new()
ret.ask_type = self.ask_type
ret.ansi_time = os.time()
local date = os.date("*t")
ret.year = date.year
ret.month = date.month - 1
ret.day = date.day
ret.hour = date.hour
ret.minute = date.min
ret.second = date.sec
Net:send(ret)
end
结论
GCAskServerTime(334) 是服务器时间结果包。
- 结构固定 15 字节,字段已经全部明确。
- 当前最需要记住的细节,是月份按 0 基值写入。
|