Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
6.6 kB
4
Indexable
package server.itsmerjc;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Process;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.Toast;
import com.itsmerjc.AuthResponse;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

public class MainActivity extends Activity implements AuthResponse.LibraryManagerListener {

    public String GameActivity = "com.tencent.tmgp.cod.CODMPrivatePermissionActivity";
    public native String URL();

    static {
        System.loadLibrary("RJC+");
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initializeApp();
    }

    private void initializeApp() {
        // Display the login menu
        showLoginMenu();
    }

    @Override
    public void onLibraryLoaded(boolean success) {
        if (success) {
            Toast.makeText(this, "Library loaded successfully", Toast.LENGTH_SHORT).show();
            try {
                MainActivity.this.startActivity(new Intent(MainActivity.this, Class.forName(MainActivity.this.GameActivity)));
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
                return;
            }
        } else {
            Toast.makeText(this, "Error loading library", Toast.LENGTH_SHORT).show();
            Process.killProcess(Process.myPid());
        }
    }

    private class LicenseCheckTask extends AsyncTask<String, Void, String> {

        @Override
        protected String doInBackground(String... params) {
            try {
                URL url = new URL(params[0]);
                HttpURLConnection connection = (HttpURLConnection) url.openConnection();
                connection.setRequestMethod("POST");
                connection.setDoOutput(true);

                // Send the key to the server
                String postData = "key=" + params[1];
                connection.getOutputStream().write(postData.getBytes("UTF-8"));

                // Read the response from the server
                BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
                StringBuilder response = new StringBuilder();
                String line;

                while ((line = reader.readLine()) != null) {
                    response.append(line);
                }

                reader.close();
                return response.toString();
            } catch (Exception e) {
                e.printStackTrace();
                return null;
            }
        }

        @Override
        protected void onPostExecute(String result) {
            // Handle the response from the server
            if (result != null) {
                try {
                    JSONObject jsonObject = new JSONObject(result);

                    // Check the status of the response
                    if (jsonObject.getString("status").equals("success")) {
                        // License check successful, proceed with library download
                        AuthResponse downloadLib = new AuthResponse(MainActivity.this, MainActivity.this);
                        downloadLib.execute(URL());
                    } else {
                        // License check failed, show an error message or take appropriate action
                        Toast.makeText(MainActivity.this, jsonObject.getString("message"), Toast.LENGTH_SHORT).show();
                        Process.killProcess(Process.myPid());
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            } else {
                // Handle network or server errors
                Toast.makeText(MainActivity.this, "Error checking license", Toast.LENGTH_SHORT).show();
                Process.killProcess(Process.myPid());
            }
        }
    }

    private void showLoginMenu() {
        // Display a login dialog
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("Login");
        builder.setMessage("Enter your key");

        // Set up the input field in the dialog
        final EditText inputKey = new EditText(this);
        inputKey.setHint("Key");

        // Add the input field to the dialog
        LinearLayout layout = new LinearLayout(this);
        layout.setOrientation(LinearLayout.VERTICAL);
        layout.addView(inputKey);
        builder.setView(layout);

        // Set up the buttons in the dialog
        builder.setPositiveButton("Login", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    // Retrieve the entered key
                    String key = inputKey.getText().toString();

                    // Validate key and proceed to check license
                    if (isValidKey(key)) {
                        checkLicense();
                    } else {
                        // Display an error message or handle invalid key
                        Toast.makeText(MainActivity.this, "Invalid key", Toast.LENGTH_SHORT).show();
                    }
                }
            });

        builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    // Handle cancel action if needed
                    dialog.cancel();
                }
            });

        // Show the login dialog
        builder.show();
    }

    private void checkLicense() {
        // Replace "your_server_url/check_license.php" with the actual URL of your PHP script
        String serverUrl = "https://oasismod.site/check_license.php";
        String userEnteredKey = "user_entered_key";  // Get this from your login UI

        // Make an asynchronous HTTP request to check the license
        new LicenseCheckTask().execute(serverUrl, userEnteredKey);
    }

    
        
    // Add your key validation logic here
    private boolean isValidKey(String key) {
        // Replace this with your actual key validation logic
        return !key.isEmpty();
    }
   }
   
   
Leave a Comment