Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ru.jopacode.gameserver.utils;
- import java.sql.CallableStatement;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.util.ArrayList;
- import ru.jopacode.gameserver.Config;
- public class DataAcess {
- private static final String MYSQL_CONNECTION_STRING =
- "jdbc:mysql://ragecode.ru/licensedata?" +
- "user=root&password=njPPohV5XAFxcPrLmHtV0IKZHefgFvKx";
- /*for test, in rls fix -----------------------------------------------------------------------------------------------------------------"Вот это"--*/
- private static final String SELECT_QUERY = "SELECT license_ip, license_key ,expire_date from licensedata.licensedata WHERE client_name =\'%s\' ";
- public static ArrayList<String> validateUser(String username)
- {
- CallableStatementImp callableStatementImp = new CallableStatementImp();
- ArrayList<String> list = new ArrayList<String>();
- try (Connection connection = callableStatementImp.createConnection())
- {
- CallableStatement callableStatement = connection.prepareCall(SELECT_QUERY);
- ResultSet resultSet = callableStatement.executeQuery();
- if (!(resultSet == null))
- {
- while (resultSet.next())
- {
- for (int i = 1; i <= resultSet.getMetaData().getColumnCount(); i++)
- {
- list.add(resultSet.getString(i));
- }
- }
- return list;
- }
- }
- catch (SQLException e)
- {
- e.printStackTrace();
- }
- return list;
- }
- private static class CallableStatementImp {
- private Connection connection;
- CallableStatementImp() {
- try
- {
- // Loading the driver
- Class.forName("com.mysql.jdbc.Driver");
- }
- catch (ClassNotFoundException e)
- {
- System.out.println(e.toString());
- }
- }
- // Creating a function to get a connection
- Connection createConnection() {
- // checking connection
- if (connection != null) {
- System.out.println("Can't create a connection");
- return connection;
- } else {
- try {
- // Getting connection
- connection = DriverManager.getConnection(MYSQL_CONNECTION_STRING);
- } catch (Exception e) {
- System.out.println(e.toString());
- }
- }
- return connection;
- }
- }
- public static void LicenseCheck()
- {
- boolean acess = false;
- String username = Config.client_name;
- ArrayList<String> userList = validateUser(username);
- //0-ip, 1-key, 2-date
- if (userList.get(0).equalsIgnoreCase(Config.EXTERNAL_HOSTNAME) && userList.get(1).equalsIgnoreCase(Config.client_key))
- {
- acess = true;
- }
- if (!acess)
- {
- System.out.println("License is not valid! Acess Forbidden!");
- System.exit(1);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement