@@ -17,11 +17,11 @@ type Token_Info struct {
17
17
// Updated to the maximum(cfg.MaxNonActiveTime) value on any use of the token
18
18
countdown int
19
19
username string
20
- history [ ]Token_Usage_History
20
+ history map [ string ]Token_Usage_History
21
21
}
22
22
23
23
type Token_Usage_History struct {
24
- time int64
24
+ time int64 // First usage
25
25
ip string
26
26
useragent string
27
27
}
@@ -70,7 +70,8 @@ func newToken(username string, ip string, useragent string) string {
70
70
ip : ip ,
71
71
useragent : useragent ,
72
72
}
73
- history := []Token_Usage_History {hEntry }
73
+ history_key := ip + " " + useragent
74
+ history := map [string ]Token_Usage_History {history_key : hEntry }
74
75
tokenInfo := Token_Info {
75
76
username : username ,
76
77
countdown : cfg .MaxNonActiveTime ,
@@ -158,7 +159,7 @@ func loadTokens() error {
158
159
log .Fatal (err )
159
160
}
160
161
// Parse token history. Each entry starts with tab
161
- history := [ ]Token_Usage_History {}
162
+ history := map [ string ]Token_Usage_History {}
162
163
var hEntry Token_Usage_History
163
164
for (i + 1 < len (lines )) && (len (lines [i + 1 ]) > 0 ) && (lines [i + 1 ][0 ] == '\t' ) {
164
165
i += 1
@@ -174,7 +175,8 @@ func loadTokens() error {
174
175
}
175
176
hEntry .ip = parts [2 ]
176
177
hEntry .useragent = parts [3 ]
177
- history = append (history , hEntry )
178
+ history_key := hEntry .ip + " " + hEntry .useragent
179
+ history [history_key ] = hEntry
178
180
}
179
181
// Drop token for deleted user
180
182
in_tg := false
0 commit comments