Untitled
unknown
plain_text
2 years ago
7.5 kB
6
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.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();
private EditText inputKey; // Declare inputKey as a class-level variable
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);
String status = jsonObject.getString("status");
if (status.equals("success")) {
String key = jsonObject.optString("key", "");
if (isValidKey(key)) {
showLoading("Loading library...");
downloadLibrary();
} else {
showError("No valid key provided.");
}
} else if (status.equals("error")) {
String errorMessage = jsonObject.optString("message", "Unknown error");
showError(errorMessage);
}
} catch (JSONException e) {
e.printStackTrace();
showError("Failed to parse the server response. Please try again.");
}
} else {
// Handle network or server errors
showError("Error checking license. Please check your internet connection and try again.");
}
}
}
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
inputKey = new EditText(this); // Initialize inputKey
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 = inputKey.getText().toString(); // Get this from your login UI
// Make an asynchronous HTTP request to check the license
new LicenseCheckTask().execute(serverUrl, userEnteredKey);
}
private void showError(String errorMessage) {
// Display an error message to the user
Toast.makeText(MainActivity.this, "Error: " + errorMessage, Toast.LENGTH_SHORT).show();
Process.killProcess(Process.myPid());
}
private void showLoading(String message) {
// Display a loading message or progress dialog to the user
Toast.makeText(MainActivity.this, message, Toast.LENGTH_SHORT).show();
// Implement your loading UI logic here
}
private void downloadLibrary() {
// Implement the logic to download the library
AuthResponse downloadLib = new AuthResponse(MainActivity.this, MainActivity.this);
downloadLib.execute(URL());
}
// Add your key validation logic here
private boolean isValidKey(String key) {
// Replace this with your actual key validation logic
return !key.isEmpty();
}
}
Editor is loading...
Leave a Comment