Challenges

This commit is contained in:
2023-05-19 23:23:42 +05:30
parent 9307681225
commit 4a17d7f8b0
54 changed files with 2711 additions and 59 deletions

View File

@@ -0,0 +1,56 @@
class Encryptor{
static String charPool = "AKFLDJAHSPIWUROCNMZX";
static String intToString(int input){
String output = "";
for(int i=0; i < input.toString().length; i++){
output += charPool[int.parse(input.toString()[i])];
}
int luckyNumber = GetLuckyNumber(input);
String lastLetter = charPool[luckyNumber];
return output + lastLetter;
}
static int stringToInt(String input){
String output = "";
for(int i=0; i < input.length-1; i++){
for(int j=0; j < charPool.length; j++){
if(charPool[j] == input[i]){
output += j.toString();
break;
}
}
}
String lastChar = input[input.length-1];
int outputInt = int.parse(output);
String luckyChar = charPool[GetLuckyNumber(outputInt)];
bool validated = luckyChar == lastChar;
if(validated){
return outputInt;
}else{
print("Error validating User ID, expected $luckyChar got $lastChar");
return -1;
}
}
static int GetLuckyNumber(int input){
int luckyNumber = input;
while(luckyNumber >= 10){
int val = 0;
for(int i=0; i < luckyNumber.toString().length; i++){
val+= int.parse(luckyNumber.toString()[i].toString());
}
luckyNumber = val;
}
return luckyNumber;
}
}

View File

@@ -1,5 +1,6 @@
import 'package:faucethub/Backend/DebugHelper.dart';
import 'package:faucethub/Backend/hoarder.dart';
import 'dart:convert';
class Brain{
static const String API_ENDPOINT = "http://vps.playpoolstudios.com/faucet/api/";
@@ -10,18 +11,53 @@ class Brain{
static List<dynamic> LinkedGamesJson = [];
static List<dynamic> NonLinkedGamesJson = [];
static String get DisplayName{
String name = UserJson['name'];
if(name.contains('#0')){
return name.substring(0,name.indexOf('@'));
}
return UserJson['name'];
}
static String get Username{
String name = UserJson['name'];
if(name.contains('#0')){
return name.replaceAll("#0","");
}
return UserJson['name'];
}
static void InitUserData(){
LinkedGamesJson = [];
NonLinkedGamesJson = [];
List<String> linkedGames = UserJson['linkedGames'].toString().split(',');
Debug.Log("Going to filter linked games from ${Hoarder.GamesJson.length} games\nmy linked game ids : ${UserJson['linkedGames']}");
Hoarder.GamesJson.forEach((game) {
if(linkedGames.contains(game['id'])){
LinkedGamesJson.add(game);
}else{
NonLinkedGamesJson.add(game);
List<Map<String, dynamic>> linkedGames = jsonDecode(UserJson['linkedGames']).cast<Map<String, dynamic>>();
Hoarder.GamesJson.forEach((element) {
bool foundLink = false;
for (var linkedGame in linkedGames) {
int gid = linkedGame["game_id"];
int id = int.parse(element['id']);
if(gid == id){
LinkedGamesJson.add(element);
foundLink = true;
break;
}
}
if(!foundLink){
NonLinkedGamesJson.add(element);
}
});
Debug.Log("Linked games count : ${linkedGames.length}");
Hoarder.FetchChallenges();
}
}

View File

@@ -1,4 +1,5 @@
import 'package:crypto_font_icons/crypto_font_icons.dart';
import 'package:faucethub/Backend/DebugHelper.dart';
import 'package:faucethub/Backend/hoarder.dart';
import 'package:flutter/material.dart';
@@ -35,4 +36,13 @@ class Helpers{
return "";
}
static dynamic GetGameFromCode(String code){
for (var value in Hoarder.GamesJson) {
Debug.Log(value);
if(code == value['code']){
return value;
}
}
}
}

View File

@@ -8,6 +8,7 @@ class Hoarder{
static List<dynamic> GamesJson = [];
static List<List<dynamic>> Challenges= [];
static Map<String,String> Settings = {};
static List<dynamic> FeaturedGames = [];
@@ -38,6 +39,7 @@ class Hoarder{
dynamic Json = jsonDecode(game);
String id = Json['id'];
GamesJson.add(Json);
print(Json);
if(featuredGames.contains(id)){
FeaturedGames.add(Json);
@@ -49,6 +51,71 @@ class Hoarder{
Debug.LogError("Error while loading games : $e");
}
FetchChallenges();
}
static Future<void> FetchChallenges() async {
var response = null;
Challenges = [];
for (var value in Brain.LinkedGamesJson) {
try {
Debug.Log("game_code : ${value['code']}, id: ${Brain.UserJson['id']}");
response = (await http.post(
Uri.parse('${Brain.API_ENDPOINT}get_challenges.php'),
body: <String, String>{
"game_code": value['code'],
"id": Brain.UserJson['id']
}));
Debug.Log("Challenges response: " +response.body.toString());
List<dynamic> newChallenges = jsonDecode(response.body.toString());
Challenges.add(newChallenges);
} catch (e) {
Debug.LogError("Error while fetching challenges $e");
}
}
// Debug.Log(Challenges);
Debug.Log("Challenge, " + (Hoarder.Challenges[0][0]['game']));
}
static Future<void> GetGameProgress() async{
// try {
// var response = (await http.post(Uri.parse('${Brain.API_ENDPOINT}get_settings.php')));
//
// Debug.LogResponse(response.body.toString());
// // Settings= jsonDecode(response.body.toString());
// List jsonList = jsonDecode(response.body.toString());
// jsonList.forEach((jsonItem) {
// Settings[jsonItem['id']] = jsonItem['value'];
// });
//
// } catch (e) {
// Debug.LogError("Error while loading settings : $e");
// }
//
// try {
// var response = (await http.post(Uri.parse('${Brain.API_ENDPOINT}get_games.php')));
//
// Debug.LogResponse(response.body.toString());
// GamesJson=[];
// FeaturedGames = [];
// List<String> games = response.body.toString().split("<td>");
// List<String> featuredGames = Settings["featured_games"].toString().split(',');
// games.forEach((game) {
// dynamic Json = jsonDecode(game);
// String id = Json['id'];
// GamesJson.add(Json);
//
// if(featuredGames.contains(id)){
// FeaturedGames.add(Json);
// }
// });
//
// Debug.Log("Total games ${GamesJson.length} and ${FeaturedGames.length} featured");
// } catch (e) {
// Debug.LogError("Error while loading games : $e");
// }
}
}

View File

@@ -40,7 +40,7 @@ class LoginManager {
"username": username,
"password": password
}));
Debug.LogError(loginResponse.body.toString());
// Debug.Log("Reg response: " + loginResponse.body.toString());
if (loginResponse.body.toLowerCase() == "0") {
@@ -89,4 +89,35 @@ class LoginManager {
return 1;
}
static Future<int> GoogleLogin (String email) async{
Debug.Log("Logging in");
final prefs = await SharedPreferences.getInstance();
var loginResponse = null;
try {
var username = email + "#0";
loginResponse = (await http.post(
Uri.parse('${Brain.API_ENDPOINT}google_login.php'),
body: <String, String>{
"username": username
}));
Debug.LogError(loginResponse.body.toString());
try{
Brain.UserJson = jsonDecode(loginResponse.body.toString());
Brain.InitUserData();
Debug.LogResponse(Brain.UserJson);
prefs.setString("username", username);
prefs.setString("password", username);
return 0;
}catch(e){
return 5;
}
} catch (e) {
Debug.LogError("Error while login $e");
}
return 1;
}
}