hash fixes

This commit is contained in:
Michael Wain 2024-04-07 18:34:53 +03:00
parent 81b7a02d23
commit b8ba7922af
3 changed files with 21 additions and 13 deletions

View File

@ -513,9 +513,9 @@ public class BunkerBot extends TelegramLongPollingBot {
update.getCallbackQuery().getId()
)
);
if( update.getCallbackQuery().getData().equals(HashUtils.bytesToHex(Constants.JOIN_GAME_BTN.getBytes())) ) {
if( update.getCallbackQuery().getData().equals(HashUtils.getCRC32(Constants.JOIN_GAME_BTN.getBytes())) ) {
joinGame(update.getCallbackQuery().getFrom(), 0);
} else if( update.getCallbackQuery().getData().equals(HashUtils.bytesToHex(Constants.START_GAME_BTN.getBytes())) ) {
} else if( update.getCallbackQuery().getData().equals(HashUtils.getCRC32(Constants.START_GAME_BTN.getBytes())) ) {
if( isAdmin(update.getCallbackQuery().getFrom()) ) {
startGame();
return;

View File

@ -18,13 +18,13 @@ public class BotUtils {
List<List<InlineKeyboardButton>> columns = new ArrayList<>();
InlineKeyboardButton inlineKeyboardButton = new InlineKeyboardButton();
inlineKeyboardButton.setText(Constants.JOIN_GAME_BTN);
inlineKeyboardButton.setCallbackData(HashUtils.bytesToHex(Constants.JOIN_GAME_BTN.getBytes()));
inlineKeyboardButton.setCallbackData(HashUtils.getCRC32(Constants.JOIN_GAME_BTN.getBytes()));
List<InlineKeyboardButton> keyboardButtonsRow1 = new ArrayList<>();
keyboardButtonsRow1.add(inlineKeyboardButton);
columns.add(keyboardButtonsRow1);
InlineKeyboardButton inlineKeyboardButton1 = new InlineKeyboardButton();
inlineKeyboardButton1.setText(Constants.START_GAME_BTN);
inlineKeyboardButton1.setCallbackData(HashUtils.bytesToHex(Constants.START_GAME_BTN.getBytes()));
inlineKeyboardButton1.setCallbackData(HashUtils.getCRC32(Constants.START_GAME_BTN.getBytes()));
List<InlineKeyboardButton> keyboardButtonsRow2 = new ArrayList<>();
keyboardButtonsRow2.add(inlineKeyboardButton1);
columns.add(keyboardButtonsRow2);
@ -38,37 +38,37 @@ public class BotUtils {
if( !infoSections.getIsHobbyShowed() ) {
InlineKeyboardButton inlineKeyboardButton = new InlineKeyboardButton();
inlineKeyboardButton.setText(Constants.HOBBY_BTN);
inlineKeyboardButton.setCallbackData(HashUtils.bytesToHex(Constants.HOBBY_BTN.getBytes()));
inlineKeyboardButton.setCallbackData(HashUtils.getCRC32(Constants.HOBBY_BTN.getBytes()));
columns.add(Collections.singletonList(inlineKeyboardButton));
}
if( !infoSections.getIsAgeShowed() ) {
InlineKeyboardButton inlineKeyboardButton = new InlineKeyboardButton();
inlineKeyboardButton.setText(Constants.AGE_BTN);
inlineKeyboardButton.setCallbackData(HashUtils.bytesToHex(Constants.AGE_BTN.getBytes()));
inlineKeyboardButton.setCallbackData(HashUtils.getCRC32(Constants.AGE_BTN.getBytes()));
columns.add(Collections.singletonList(inlineKeyboardButton));
}
if( !infoSections.getIsGenderShowed() ) {
InlineKeyboardButton inlineKeyboardButton = new InlineKeyboardButton();
inlineKeyboardButton.setText(Constants.GENDER_BTN);
inlineKeyboardButton.setCallbackData(HashUtils.bytesToHex(Constants.GENDER_BTN.getBytes()));
inlineKeyboardButton.setCallbackData(HashUtils.getCRC32(Constants.GENDER_BTN.getBytes()));
columns.add(Collections.singletonList(inlineKeyboardButton));
}
if( !infoSections.getIsHealthShowed() ) {
InlineKeyboardButton inlineKeyboardButton = new InlineKeyboardButton();
inlineKeyboardButton.setText(Constants.HEALTH_BTN);
inlineKeyboardButton.setCallbackData(HashUtils.bytesToHex(Constants.HEALTH_BTN.getBytes()));
inlineKeyboardButton.setCallbackData(HashUtils.getCRC32(Constants.HEALTH_BTN.getBytes()));
columns.add(Collections.singletonList(inlineKeyboardButton));
}
if( !infoSections.getIsWorkShowed() ) {
InlineKeyboardButton inlineKeyboardButton = new InlineKeyboardButton();
inlineKeyboardButton.setText(Constants.WORK_BTN);
inlineKeyboardButton.setCallbackData(HashUtils.bytesToHex(Constants.WORK_BTN.getBytes()));
inlineKeyboardButton.setCallbackData(HashUtils.getCRC32(Constants.WORK_BTN.getBytes()));
columns.add(Collections.singletonList(inlineKeyboardButton));
}
if( !infoSections.getIsLuggageShowed() ) {
InlineKeyboardButton inlineKeyboardButton = new InlineKeyboardButton();
inlineKeyboardButton.setText(Constants.LUGG_BTN);
inlineKeyboardButton.setCallbackData(HashUtils.bytesToHex(Constants.LUGG_BTN.getBytes()));
inlineKeyboardButton.setCallbackData(HashUtils.getCRC32(Constants.LUGG_BTN.getBytes()));
columns.add(Collections.singletonList(inlineKeyboardButton));
}
inlineKeyboardMarkup.setKeyboard(columns);
@ -81,7 +81,7 @@ public class BotUtils {
.map(s -> {
InlineKeyboardButton inlineKeyboardButton = new InlineKeyboardButton();
inlineKeyboardButton.setText(textDataValService.getTextDataValById(s.getTextNameId()).getText());
inlineKeyboardButton.setCallbackData(HashUtils.bytesToHex(textDataValService.getTextDataValById(s.getTextNameId()).getText().getBytes()));
inlineKeyboardButton.setCallbackData(HashUtils.getCRC32(textDataValService.getTextDataValById(s.getTextNameId()).getText().getBytes()));
return Collections.singletonList(inlineKeyboardButton);
}).collect(Collectors.toList()));
return inlineKeyboardMarkup;
@ -92,13 +92,13 @@ public class BotUtils {
List<List<InlineKeyboardButton>> columns = new ArrayList<>();
InlineKeyboardButton inlineKeyboardButton = new InlineKeyboardButton();
inlineKeyboardButton.setText(Constants.PROBABILITY);
inlineKeyboardButton.setCallbackData(HashUtils.bytesToHex(Constants.PROBABILITY.getBytes()));
inlineKeyboardButton.setCallbackData(HashUtils.getCRC32(Constants.PROBABILITY.getBytes()));
List<InlineKeyboardButton> keyboardButtonsRow1 = new ArrayList<>();
keyboardButtonsRow1.add(inlineKeyboardButton);
columns.add(keyboardButtonsRow1);
InlineKeyboardButton inlineKeyboardButton1 = new InlineKeyboardButton();
inlineKeyboardButton1.setText(Constants.DEATHMATCH);
inlineKeyboardButton1.setCallbackData(HashUtils.bytesToHex(Constants.DEATHMATCH.getBytes()));
inlineKeyboardButton1.setCallbackData(HashUtils.getCRC32(Constants.DEATHMATCH.getBytes()));
List<InlineKeyboardButton> keyboardButtonsRow2 = new ArrayList<>();
keyboardButtonsRow2.add(inlineKeyboardButton1);
columns.add(keyboardButtonsRow2);

View File

@ -4,6 +4,8 @@ import lombok.extern.slf4j.Slf4j;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.util.Locale;
import java.util.zip.CRC32;
@Slf4j
public class HashUtils {
@ -56,4 +58,10 @@ public class HashUtils {
}
return new String(hexChars, StandardCharsets.UTF_8);
}
public static String getCRC32(byte[] data){
CRC32 fileCRC32 = new CRC32();
fileCRC32.update(data);
return String.format(Locale.US,"%08X", fileCRC32.getValue());
}
}