@@ -170,7 +170,7 @@ protected function post(ServerRequestInterface|string $request, int|string &$res
170
170
switch ($ methodType ) {
171
171
case 'delete ' :
172
172
$ this ->delete (
173
- $ this ->getIndex ($ ckey , $ discord ),
173
+ $ this ->getIndex ($ discord , $ ckey ),
174
174
$ list ,
175
175
$ response ,
176
176
$ headers ,
@@ -207,16 +207,16 @@ protected function post(ServerRequestInterface|string $request, int|string &$res
207
207
*/
208
208
protected function __post (array &$ list , string $ ckey , string $ discord , int |string &$ response , array &$ headers , string &$ body ): void
209
209
{
210
- $ existingCkeyIndex = array_search ($ ckey , array_column ($ list , 'ss13 ' ));
211
210
$ existingDiscordIndex = array_search ($ discord , array_column ($ list , 'discord ' ));
212
- if ($ existingCkeyIndex !== false || $ existingDiscordIndex !== false ) {
211
+ $ existingCkeyIndex = array_search ($ ckey , array_column ($ list , 'ss13 ' ));
212
+ if ($ existingDiscordIndex !== false || $ existingCkeyIndex !== false ) {
213
213
$ response = Response::STATUS_FORBIDDEN ;
214
214
$ headers = ['Content-Type ' => 'text/plain ' ];
215
215
$ body = 'Forbidden ' ;
216
216
return ;
217
217
}
218
218
219
- $ this ->add ($ ckey , $ discord );
219
+ $ this ->add ($ discord , $ ckey );
220
220
221
221
$ headers = ['Content-Type ' => 'application/json ' ];
222
222
$ headers ['Content-Length ' ] = ($ body = $ this ->__content ())
@@ -251,30 +251,30 @@ protected function delete(int|string|false $existingIndex, array &$list, int|str
251
251
: 0 ;
252
252
}
253
253
254
- public function add (string $ ckey , string $ discord ): void
254
+ public function add (string $ discord , string $ ckey ): void
255
255
{
256
256
$ list = &$ this ->state ->getVerifyList ();
257
257
$ list [] = [
258
- 'ss13 ' => $ ckey ,
259
258
'discord ' => $ discord ,
259
+ 'ss13 ' => $ ckey ,
260
260
'create_time ' => date ('Y-m-d H:i:s ' )
261
261
];
262
262
$ this ->state ::writeJson ($ this ->state ->getJsonPath (), $ list );
263
263
$ this ->state ->setVerifyList ($ list );
264
264
}
265
265
266
- public function remove (string $ ckey , string $ discord ): ?array
266
+ public function remove (string $ discord , string $ ckey = '' ): ?array
267
267
{
268
- $ existingIndex = $ this ->getIndex ($ ckey , $ discord );
268
+ $ existingIndex = $ this ->getIndex ($ discord , $ ckey );
269
269
if ($ existingIndex === false ) return null ;
270
270
return $ this ->removeIndex ($ existingIndex );
271
271
}
272
272
273
- public function getIndex (string $ ckey , string $ discord ): int |string |false
273
+ public function getIndex (string $ discord , string $ ckey = '' ): int |string |false
274
274
{
275
275
$ list = &$ this ->state ->getVerifyList ();
276
276
$ existingIndex = array_search ($ ckey , array_column ($ list , 'ss13 ' ));
277
- if ($ existingIndex === false ) $ existingIndex = array_search ($ discord , array_column ($ list , 'discord ' ));
277
+ if ($ ckey && $ existingIndex === false ) $ existingIndex = array_search ($ discord , array_column ($ list , 'discord ' ));
278
278
return $ existingIndex ;
279
279
}
280
280
0 commit comments