@@ -170,7 +170,7 @@ protected function post(ServerRequestInterface|string $request, int|string &$res
170170 switch ($ methodType ) {
171171 case 'delete ' :
172172 $ this ->delete (
173- $ this ->getIndex ($ ckey , $ discord ),
173+ $ this ->getIndex ($ discord , $ ckey ),
174174 $ list ,
175175 $ response ,
176176 $ headers ,
@@ -207,16 +207,16 @@ protected function post(ServerRequestInterface|string $request, int|string &$res
207207 */
208208 protected function __post (array &$ list , string $ ckey , string $ discord , int |string &$ response , array &$ headers , string &$ body ): void
209209 {
210- $ existingCkeyIndex = array_search ($ ckey , array_column ($ list , 'ss13 ' ));
211210 $ 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 ) {
213213 $ response = Response::STATUS_FORBIDDEN ;
214214 $ headers = ['Content-Type ' => 'text/plain ' ];
215215 $ body = 'Forbidden ' ;
216216 return ;
217217 }
218218
219- $ this ->add ($ ckey , $ discord );
219+ $ this ->add ($ discord , $ ckey );
220220
221221 $ headers = ['Content-Type ' => 'application/json ' ];
222222 $ headers ['Content-Length ' ] = ($ body = $ this ->__content ())
@@ -251,30 +251,30 @@ protected function delete(int|string|false $existingIndex, array &$list, int|str
251251 : 0 ;
252252 }
253253
254- public function add (string $ ckey , string $ discord ): void
254+ public function add (string $ discord , string $ ckey ): void
255255 {
256256 $ list = &$ this ->state ->getVerifyList ();
257257 $ list [] = [
258- 'ss13 ' => $ ckey ,
259258 'discord ' => $ discord ,
259+ 'ss13 ' => $ ckey ,
260260 'create_time ' => date ('Y-m-d H:i:s ' )
261261 ];
262262 $ this ->state ::writeJson ($ this ->state ->getJsonPath (), $ list );
263263 $ this ->state ->setVerifyList ($ list );
264264 }
265265
266- public function remove (string $ ckey , string $ discord ): ?array
266+ public function remove (string $ discord , string $ ckey = '' ): ?array
267267 {
268- $ existingIndex = $ this ->getIndex ($ ckey , $ discord );
268+ $ existingIndex = $ this ->getIndex ($ discord , $ ckey );
269269 if ($ existingIndex === false ) return null ;
270270 return $ this ->removeIndex ($ existingIndex );
271271 }
272272
273- public function getIndex (string $ ckey , string $ discord ): int |string |false
273+ public function getIndex (string $ discord , string $ ckey = '' ): int |string |false
274274 {
275275 $ list = &$ this ->state ->getVerifyList ();
276276 $ 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 ' ));
278278 return $ existingIndex ;
279279 }
280280
0 commit comments