Skip to content

Commit 91d60b2

Browse files
authored
Merge pull request #76 from ppebb/main
Make all time.Now() usage UTC
2 parents 9d5913b + 3722170 commit 91d60b2

File tree

13 files changed

+21
-21
lines changed

13 files changed

+21
-21
lines changed

common/auth_token.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func appendString(blob []byte, value string, maxlen int) []byte {
4747
}
4848

4949
func MarshalNASAuthToken(gamecd string, userid uint64, gsbrcd string, cfc uint64, region byte, lang byte, ingamesn string, unitcd byte, isLocalhost bool) (string, string) {
50-
blob := binary.LittleEndian.AppendUint64([]byte{}, uint64(time.Now().Unix()))
50+
blob := binary.LittleEndian.AppendUint64([]byte{}, uint64(time.Now().UTC().Unix()))
5151

5252
blob = appendString(blob, gamecd, 4)
5353

@@ -129,7 +129,7 @@ func UnmarshalNASAuthToken(token string) (gamecd string, issuetime time.Time, us
129129
}
130130

131131
func MarshalGPCMLoginTicket(profileId uint32) string {
132-
blob := binary.LittleEndian.AppendUint64([]byte{}, uint64(time.Now().Unix()))
132+
blob := binary.LittleEndian.AppendUint64([]byte{}, uint64(time.Now().UTC().Unix()))
133133
blob = binary.LittleEndian.AppendUint32(blob, profileId)
134134
blob = append(blob, loginTicketMagic...)
135135

database/login.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ func LoginUserToGPCM(pool *pgxpool.Pool, ctx context.Context, userId uint64, gsb
172172
var bannedDeviceIdList []uint32
173173
var banReason string
174174

175-
timeNow := time.Now()
175+
timeNow := time.Now().UTC()
176176
err = pool.QueryRow(ctx, SearchUserBan, user.NgDeviceId, user.ProfileId, ipAddress, *lastIPAddress, timeNow).Scan(&banExists, &banTOS, &bannedDeviceIdList, &banReason)
177177

178178
if err != nil {

database/user.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ func ClearProfile(pool *pgxpool.Pool, ctx context.Context, profileId uint32) (Us
155155
}
156156

157157
func BanUser(pool *pgxpool.Pool, ctx context.Context, profileId uint32, tos bool, length time.Duration, reason string, reasonHidden string, moderator string) bool {
158-
_, err := pool.Exec(ctx, UpdateUserBan, profileId, time.Now(), time.Now().Add(length), reason, reasonHidden, moderator, tos)
158+
_, err := pool.Exec(ctx, UpdateUserBan, profileId, time.Now().UTC(), time.Now().UTC().Add(length), reason, reasonHidden, moderator, tos)
159159
return err == nil
160160
}
161161

gamestats/auth.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func (g *GameStatsSession) authp(command common.GameSpyCommand) {
7070
return
7171
}
7272

73-
currentTime := time.Now()
73+
currentTime := time.Now().UTC()
7474
if issueTime.Before(currentTime.Add(-10*time.Minute)) || issueTime.After(currentTime) {
7575
logging.Error(g.ModuleName, "Authtoken has expired")
7676
g.Write(errorCmd)

gpcm/login.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ func (g *GameSpySession) login(command common.GameSpyCommand) {
167167
return
168168
}
169169

170-
currentTime := time.Now()
170+
currentTime := time.Now().UTC()
171171
if issueTime.Before(currentTime.Add(-10*time.Minute)) || issueTime.After(currentTime) {
172172
g.replyError(ErrLoginLoginTicketExpired)
173173
return

nas/auth.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,6 @@ func isValidRhgamecd(rhgamecd string) bool {
408408
}
409409

410410
func getDateTime() string {
411-
t := time.Now()
411+
t := time.Now().UTC()
412412
return fmt.Sprintf("%04d%02d%02d%02d%02d%02d", t.Year(), t.Month(), t.Day(), t.Hour(), t.Minute(), t.Second())
413413
}

nas/https.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func startHTTPSProxy(config common.Config) {
8686
go func() {
8787
moduleName := "NAS-TLS:" + conn.RemoteAddr().String()
8888

89-
conn.SetDeadline(time.Now().Add(25 * time.Second))
89+
conn.SetDeadline(time.Now().UTC().Add(25 * time.Second))
9090

9191
handleRealTLS(moduleName, conn, nasAddr)
9292
}()
@@ -241,7 +241,7 @@ func startHTTPSProxy(config common.Config) {
241241

242242
moduleName := "NAS-TLS:" + conn.RemoteAddr().String()
243243

244-
conn.SetDeadline(time.Now().Add(5 * time.Second))
244+
conn.SetDeadline(time.Now().UTC().Add(5 * time.Second))
245245

246246
handleTLS(moduleName, conn, nasAddr, serverCertsRecordWii, rsaKeyWii, serverCertsRecordDS, rsaKeyDS)
247247
}()
@@ -316,7 +316,7 @@ func handleTLS(moduleName string, rawConn net.Conn, nasAddr string, serverCertsR
316316
}
317317
}
318318

319-
conn.SetDeadline(time.Now().Add(25 * time.Second))
319+
conn.SetDeadline(time.Now().UTC().Add(25 * time.Second))
320320

321321
// logging.Info(moduleName, "Forwarding client hello:", aurora.Cyan(fmt.Sprintf("% X ", helloBytes)))
322322
handleRealTLS(moduleName, conn, nasAddr)

nhttp/buffer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ func (cw *chunkWriter) writeHeader(p []byte) {
415415
}
416416

417417
//if !header.has("Date") {
418-
setHeader.date = appendTime(cw.res.dateBuf[:0], time.Now())
418+
setHeader.date = appendTime(cw.res.dateBuf[:0], time.Now().UTC())
419419
//}
420420

421421
if hasCL && hasTE && te != "identity" {

nhttp/server.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ func (s *Server) closeIdleConns() bool {
211211
// Issue 22682: treat StateNew connections as if
212212
// they're idle if we haven't read the first request's
213213
// header in over 5 seconds.
214-
if st == _http.StateNew && unixSec < time.Now().Unix()-5 {
214+
if st == _http.StateNew && unixSec < time.Now().UTC().Unix()-5 {
215215
st = _http.StateIdle
216216
}
217217
if st != _http.StateIdle || unixSec == 0 {
@@ -385,7 +385,7 @@ func (c *conn) setState(nc net.Conn, state _http.ConnState) {
385385
if state > 0xff || state < 0 {
386386
panic("internal error")
387387
}
388-
packedState := uint64(time.Now().Unix()<<8) | uint64(state)
388+
packedState := uint64(time.Now().UTC().Unix()<<8) | uint64(state)
389389
c.curState.Store(packedState)
390390
}
391391

@@ -525,15 +525,15 @@ func (c *conn) serve(ctx context.Context) {
525525
}
526526

527527
if d := c.server.idleTimeout(); d != 0 {
528-
c.rwc.SetReadDeadline(time.Now().Add(d))
528+
c.rwc.SetReadDeadline(time.Now().UTC().Add(d))
529529
if _, err := c.bufr.Peek(4); err != nil {
530530
return
531531
}
532532
}
533533

534534
c.curReq.Store((*response)(nil))
535535
if d := c.server.idleTimeout(); d != 0 {
536-
c.rwc.SetReadDeadline(time.Now().Add(d))
536+
c.rwc.SetReadDeadline(time.Now().UTC().Add(d))
537537
if _, err := c.bufr.Peek(4); err != nil {
538538
return
539539
}

qr2/challenge.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func sendChallenge(conn net.PacketConn, addr net.UDPAddr, session Session, looku
5454

5555
mutex.Lock()
5656
session, ok := sessions[lookupAddr]
57-
if !ok || session.Authenticated || session.LastKeepAlive < time.Now().Unix()-60 {
57+
if !ok || session.Authenticated || session.LastKeepAlive < time.Now().UTC().Unix()-60 {
5858
mutex.Unlock()
5959
return
6060
}

0 commit comments

Comments
 (0)