Challenges + Estimated Earnings
This commit is contained in:
@@ -1,32 +1,32 @@
|
||||
import 'dart:developer';
|
||||
|
||||
class Debug{
|
||||
static bool enableLogging = true;
|
||||
static bool enableResponseLogging = true;
|
||||
static bool enableErrorLoggin = true;
|
||||
static bool enableTestLogging = true;
|
||||
|
||||
static void LogResponse(Object? response, {Object src= ''}){
|
||||
if(!enableLogging){return;}
|
||||
if(!enableResponseLogging) {return;}
|
||||
print('\x1B[32m$src response\n$response\x1B[0m');
|
||||
}
|
||||
|
||||
static void LogError(Object? msg){
|
||||
if(!enableLogging){return;}
|
||||
if(!enableErrorLoggin) {return;}
|
||||
print('\x1B[31m$msg\x1B[0m');
|
||||
}
|
||||
|
||||
static void Log(Object? msg){
|
||||
if(!enableLogging) {return;}
|
||||
print('\x1B[36m$msg\x1B[0m');
|
||||
}
|
||||
|
||||
static void LogTest(Object? msg){
|
||||
if(!enableLogging){return;}
|
||||
if(!enableTestLogging) {return;}
|
||||
print('\x1B[35m$msg\x1B[0m');
|
||||
}
|
||||
|
||||
import 'dart:developer';
|
||||
|
||||
class Debug{
|
||||
static bool enableLogging = true;
|
||||
static bool enableResponseLogging = true;
|
||||
static bool enableErrorLoggin = true;
|
||||
static bool enableTestLogging = true;
|
||||
|
||||
static void LogResponse(Object? response, {Object src= ''}){
|
||||
if(!enableLogging){return;}
|
||||
if(!enableResponseLogging) {return;}
|
||||
print('\x1B[32m$src response\n$response\x1B[0m');
|
||||
}
|
||||
|
||||
static void LogError(Object? msg){
|
||||
if(!enableLogging){return;}
|
||||
if(!enableErrorLoggin) {return;}
|
||||
print('\x1B[31m$msg\x1B[0m');
|
||||
}
|
||||
|
||||
static void Log(Object? msg){
|
||||
if(!enableLogging) {return;}
|
||||
print('\x1B[36m$msg\x1B[0m');
|
||||
}
|
||||
|
||||
static void LogTest(Object? msg){
|
||||
if(!enableLogging){return;}
|
||||
if(!enableTestLogging) {return;}
|
||||
print('\x1B[35m$msg\x1B[0m');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,75 +1,75 @@
|
||||
import 'package:faucethub/Backend/login_mgr.dart';
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_spinkit/flutter_spinkit.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import '../main.dart';
|
||||
|
||||
class Dialogs{
|
||||
|
||||
static showAlertDialog(BuildContext context, String title, String message) {
|
||||
// set up the button
|
||||
Widget okButton = TextButton(
|
||||
child: Text("OK"),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
);
|
||||
|
||||
// set up the AlertDialog
|
||||
AlertDialog alert = AlertDialog(
|
||||
backgroundColor: Color(0xFF1F1F1F),
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
|
||||
title: Text(title),
|
||||
content: Text(message),
|
||||
actions: [
|
||||
okButton,
|
||||
],
|
||||
|
||||
);
|
||||
|
||||
// show the dialog
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return alert;
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
static bool showing = false;
|
||||
static BuildContext? context;
|
||||
static waiting(){
|
||||
showing=true;
|
||||
context=navigatorKey.currentContext;
|
||||
if(context!=null) {
|
||||
return showDialog(
|
||||
context: context!,
|
||||
barrierDismissible: false,
|
||||
routeSettings: const RouteSettings(name: "Progress"),
|
||||
builder: (BuildContext context) {
|
||||
return AlertDialog(
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(30)),
|
||||
backgroundColor: Color(0xaa101010),
|
||||
title: Row(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
SpinKitChasingDots(color: Colors.green),
|
||||
Expanded(child: Text("Loading",textAlign: TextAlign.center,)),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
static hide(){
|
||||
showing=false;
|
||||
Navigator.of(navigatorKey.currentContext!).popUntil((route){
|
||||
return route.settings.name!="Progress";
|
||||
});
|
||||
}
|
||||
import 'package:faucethub/Backend/login_mgr.dart';
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_spinkit/flutter_spinkit.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import '../main.dart';
|
||||
|
||||
class Dialogs{
|
||||
|
||||
static showAlertDialog(BuildContext context, String title, String message) {
|
||||
// set up the button
|
||||
Widget okButton = TextButton(
|
||||
child: Text("OK"),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
);
|
||||
|
||||
// set up the AlertDialog
|
||||
AlertDialog alert = AlertDialog(
|
||||
backgroundColor: Color(0xFF1F1F1F),
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
|
||||
title: Text(title),
|
||||
content: Text(message),
|
||||
actions: [
|
||||
okButton,
|
||||
],
|
||||
|
||||
);
|
||||
|
||||
// show the dialog
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return alert;
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
static bool showing = false;
|
||||
static BuildContext? context;
|
||||
static waiting(){
|
||||
showing=true;
|
||||
context=navigatorKey.currentContext;
|
||||
if(context!=null) {
|
||||
return showDialog(
|
||||
context: context!,
|
||||
barrierDismissible: false,
|
||||
routeSettings: const RouteSettings(name: "Progress"),
|
||||
builder: (BuildContext context) {
|
||||
return AlertDialog(
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(30)),
|
||||
backgroundColor: Color(0xaa101010),
|
||||
title: Row(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
SpinKitChasingDots(color: Colors.green),
|
||||
Expanded(child: Text("Loading",textAlign: TextAlign.center,)),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
static hide(){
|
||||
showing=false;
|
||||
Navigator.of(navigatorKey.currentContext!).popUntil((route){
|
||||
return route.settings.name!="Progress";
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,56 +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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -1,63 +1,66 @@
|
||||
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/";
|
||||
|
||||
|
||||
static dynamic UserJson;
|
||||
|
||||
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 = [];
|
||||
|
||||
Debug.Log("Going to filter linked games from ${Hoarder.GamesJson.length} games\nmy linked game ids : ${UserJson['linkedGames']}");
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
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/";
|
||||
|
||||
|
||||
static dynamic UserJson;
|
||||
|
||||
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 = [];
|
||||
|
||||
Debug.Log("Going to filter linked games from ${Hoarder.GamesJson.length} games\nmy linked game ids : ${UserJson['linkedGames']}");
|
||||
try {
|
||||
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}");
|
||||
}catch(e){
|
||||
NonLinkedGamesJson = Hoarder.GamesJson;
|
||||
}
|
||||
Hoarder.FetchChallenges();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,33 +1,33 @@
|
||||
import 'package:firebase_auth/firebase_auth.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:google_sign_in/google_sign_in.dart';
|
||||
|
||||
class GoogleSignInProvider extends ChangeNotifier{
|
||||
final googleSignIn = GoogleSignIn();
|
||||
|
||||
GoogleSignInAccount? _user;
|
||||
GoogleSignInAuthentication? googleAuth;
|
||||
|
||||
GoogleSignInAccount get user => _user!;
|
||||
|
||||
Future googleLogin() async{
|
||||
final googleUser = await googleSignIn.signIn();
|
||||
if(googleUser==null) return;
|
||||
_user = googleUser;
|
||||
|
||||
googleAuth = await googleUser.authentication;
|
||||
|
||||
final credential = GoogleAuthProvider.credential(
|
||||
accessToken: googleAuth!.accessToken,
|
||||
idToken: googleAuth!.idToken
|
||||
);
|
||||
print('user login\nusername:${googleUser.displayName}\nemail:${googleUser.email}\nid:${googleAuth!.idToken}');
|
||||
print(googleAuth!.accessToken!.length);
|
||||
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future logout() async{
|
||||
await googleSignIn.disconnect();
|
||||
}
|
||||
import 'package:firebase_auth/firebase_auth.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:google_sign_in/google_sign_in.dart';
|
||||
|
||||
class GoogleSignInProvider extends ChangeNotifier{
|
||||
final googleSignIn = GoogleSignIn();
|
||||
|
||||
GoogleSignInAccount? _user;
|
||||
GoogleSignInAuthentication? googleAuth;
|
||||
|
||||
GoogleSignInAccount get user => _user!;
|
||||
|
||||
Future googleLogin() async{
|
||||
final googleUser = await googleSignIn.signIn();
|
||||
if(googleUser==null) return;
|
||||
_user = googleUser;
|
||||
|
||||
googleAuth = await googleUser.authentication;
|
||||
|
||||
final credential = GoogleAuthProvider.credential(
|
||||
accessToken: googleAuth!.accessToken,
|
||||
idToken: googleAuth!.idToken
|
||||
);
|
||||
print('user login\nusername:${googleUser.displayName}\nemail:${googleUser.email}\nid:${googleAuth!.idToken}');
|
||||
print(googleAuth!.accessToken!.length);
|
||||
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future logout() async{
|
||||
await googleSignIn.disconnect();
|
||||
}
|
||||
}
|
||||
@@ -1,48 +1,57 @@
|
||||
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';
|
||||
|
||||
class Helpers{
|
||||
|
||||
static IconData GetIconForCrypto(String val){
|
||||
switch(val){
|
||||
case "BTC":
|
||||
return CryptoFontIcons.BTC;
|
||||
break;
|
||||
case "ETH":
|
||||
return CryptoFontIcons.ETH;
|
||||
break;
|
||||
case "XRP":
|
||||
return CryptoFontIcons.XRP;
|
||||
break;
|
||||
case "DOGE":
|
||||
return CryptoFontIcons.DOGE;
|
||||
break;
|
||||
case "LTC":
|
||||
return CryptoFontIcons.LTC;
|
||||
break;
|
||||
}
|
||||
|
||||
return CryptoFontIcons.BTC;
|
||||
}
|
||||
|
||||
static String GetIconForGame(String name){
|
||||
Hoarder.GamesJson.forEach((element) {
|
||||
if(element['name'] == name){
|
||||
return element['thumbnail'];
|
||||
}
|
||||
});
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
static dynamic GetGameFromCode(String code){
|
||||
for (var value in Hoarder.GamesJson) {
|
||||
Debug.Log(value);
|
||||
if(code == value['code']){
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
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';
|
||||
|
||||
class Helpers{
|
||||
|
||||
static IconData GetIconForCrypto(String val){
|
||||
switch(val){
|
||||
case "BTC":
|
||||
return CryptoFontIcons.BTC;
|
||||
break;
|
||||
case "ETH":
|
||||
return CryptoFontIcons.ETH;
|
||||
break;
|
||||
case "XRP":
|
||||
return CryptoFontIcons.XRP;
|
||||
break;
|
||||
case "DOGE":
|
||||
return CryptoFontIcons.DOGE;
|
||||
break;
|
||||
case "LTC":
|
||||
return CryptoFontIcons.LTC;
|
||||
break;
|
||||
}
|
||||
|
||||
return CryptoFontIcons.BTC;
|
||||
}
|
||||
|
||||
static String GetIconForGame(String name){
|
||||
Hoarder.GamesJson.forEach((element) {
|
||||
if(element['name'] == name){
|
||||
return element['thumbnail'];
|
||||
}
|
||||
});
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
static dynamic GetGameFromCode(String code){
|
||||
for (var value in Hoarder.GamesJson) {
|
||||
Debug.Log(value);
|
||||
if(code == value['code']){
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static dynamic GetGameFromID(int id){
|
||||
for (var value in Hoarder.GamesJson) {
|
||||
Debug.Log(value);
|
||||
if(id == value['id']){
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,121 +1,155 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:faucethub/Backend/DebugHelper.dart';
|
||||
import 'package:faucethub/Backend/brains.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
class Hoarder{
|
||||
|
||||
static List<dynamic> GamesJson = [];
|
||||
|
||||
static List<List<dynamic>> Challenges= [];
|
||||
static Map<String,String> Settings = {};
|
||||
static List<dynamic> FeaturedGames = [];
|
||||
|
||||
static Future<void> GrabInitData() 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);
|
||||
print(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");
|
||||
}
|
||||
|
||||
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");
|
||||
// }
|
||||
}
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:faucethub/Backend/DebugHelper.dart';
|
||||
import 'package:faucethub/Backend/brains.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
import 'helpers.dart';
|
||||
|
||||
class Hoarder{
|
||||
|
||||
static List<dynamic> GamesJson = [];
|
||||
|
||||
static List<List<dynamic>> Challenges= [];
|
||||
static Map<String,String> Settings = {};
|
||||
static List<dynamic> FeaturedGames = [];
|
||||
|
||||
static Future<void> GrabInitData() 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);
|
||||
print(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");
|
||||
}
|
||||
|
||||
FetchChallenges();
|
||||
}
|
||||
static double currentEarnings = 0;
|
||||
static Map<String, int> ThisSeasonCryptoEarnings = {};
|
||||
static Future<void> FetchChallenges() async {
|
||||
var response = null;
|
||||
|
||||
List<List<dynamic>> _Challenges = [];
|
||||
double _currentEarnings = 0;
|
||||
Map<String,int> _ThisSeasonCryptoEarnings = {};
|
||||
|
||||
var cryptoValuesResponse = await http.get(Uri.parse('http://vps.playpoolstudios.com:2009/'));
|
||||
dynamic cryptoValues = jsonDecode(cryptoValuesResponse.body.toString());
|
||||
Debug.Log(cryptoValues);
|
||||
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());
|
||||
|
||||
dynamic GameJson = Helpers.GetGameFromCode(value['code']);
|
||||
|
||||
newChallenges.forEach((challengeJson) {
|
||||
int total = int.parse(challengeJson['total']);
|
||||
int current = int.parse(challengeJson['current']);
|
||||
int reward = int.parse(challengeJson['reward']);
|
||||
double rewardInDollars = double.parse(cryptoValues[GameJson['coin']]) * (0.00000001) * reward;
|
||||
Debug.Log("Reward is $reward ~ \$$rewardInDollars");
|
||||
|
||||
if(total <= current){
|
||||
_currentEarnings+= rewardInDollars;
|
||||
// Debug.Log(_ThisSeasonCryptoEarnings[GameJson['coin']]);
|
||||
_ThisSeasonCryptoEarnings.update(GameJson['coin'], (value) => value + reward, ifAbsent: ()=> reward);
|
||||
// Debug.Log(_ThisSeasonCryptoEarnings[GameJson['coin']]);
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
|
||||
_Challenges.add(newChallenges);
|
||||
} catch (e) {
|
||||
Debug.LogError("Error while fetching challenges $e");
|
||||
}
|
||||
}
|
||||
ThisSeasonCryptoEarnings = _ThisSeasonCryptoEarnings;
|
||||
Challenges = _Challenges;
|
||||
currentEarnings = _currentEarnings;
|
||||
|
||||
Debug.Log(ThisSeasonCryptoEarnings);
|
||||
|
||||
// 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");
|
||||
// }
|
||||
}
|
||||
}
|
||||
@@ -1,123 +1,130 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:faucethub/Backend/DebugHelper.dart';
|
||||
import 'package:faucethub/Backend/brains.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
final GlobalKey<NavigatorState> navigatorKey = new GlobalKey<NavigatorState>();
|
||||
|
||||
class LoginManager {
|
||||
|
||||
static Future<int> AutoLogin() async{
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
String username = "";
|
||||
String password= "";
|
||||
try{
|
||||
username = prefs.getString("username")!;
|
||||
password = prefs.getString("password")!;
|
||||
}catch(e){
|
||||
|
||||
}
|
||||
|
||||
if(username.length > 3 && password.length >5){
|
||||
return await Login(username, password);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static Future<int> Register (String username, String password) async{
|
||||
Debug.Log("Starting registration");
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
|
||||
var loginResponse = null;
|
||||
try {
|
||||
loginResponse = (await http.post(
|
||||
Uri.parse('${Brain.API_ENDPOINT}register.php'),
|
||||
body: <String, String>{
|
||||
"username": username,
|
||||
"password": password
|
||||
}));
|
||||
// Debug.Log("Reg response: " + loginResponse.body.toString());
|
||||
|
||||
|
||||
if (loginResponse.body.toLowerCase() == "0") {
|
||||
prefs.setString("username", username);
|
||||
prefs.setString("password", password);
|
||||
|
||||
return 0;
|
||||
|
||||
}else{
|
||||
return 5;
|
||||
}
|
||||
} catch (e) {
|
||||
Debug.LogError("Error while login $e");
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static Future<int> Login (String username, String password) async{
|
||||
Debug.Log("Logging in");
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
|
||||
var loginResponse = null;
|
||||
try {
|
||||
loginResponse = (await http.post(
|
||||
Uri.parse('${Brain.API_ENDPOINT}login.php'),
|
||||
body: <String, String>{
|
||||
"username": username,
|
||||
"password": password
|
||||
}));
|
||||
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", password);
|
||||
return 0;
|
||||
}catch(e){
|
||||
return 5;
|
||||
}
|
||||
} catch (e) {
|
||||
Debug.LogError("Error while login $e");
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:faucethub/Backend/DebugHelper.dart';
|
||||
import 'package:faucethub/Backend/brains.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
final GlobalKey<NavigatorState> navigatorKey = new GlobalKey<NavigatorState>();
|
||||
|
||||
class LoginManager {
|
||||
|
||||
static Future<int> AutoLogin() async{
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
String username = "";
|
||||
String password= "";
|
||||
try{
|
||||
if(prefs.containsKey("googleLogin")){
|
||||
if(prefs.getBool("googleLogin") ?? false){
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
username = prefs.getString("username")!;
|
||||
password = prefs.getString("password")!;
|
||||
}catch(e){
|
||||
|
||||
}
|
||||
|
||||
if(username.length > 3 && password.length >5){
|
||||
return await Login(username, password);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static Future<int> Register (String username, String password) async{
|
||||
Debug.Log("Starting registration");
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
|
||||
var loginResponse = null;
|
||||
try {
|
||||
loginResponse = (await http.post(
|
||||
Uri.parse('${Brain.API_ENDPOINT}register.php'),
|
||||
body: <String, String>{
|
||||
"username": username,
|
||||
"password": password
|
||||
}));
|
||||
// Debug.Log("Reg response: " + loginResponse.body.toString());
|
||||
|
||||
|
||||
if (loginResponse.body.toLowerCase() == "0") {
|
||||
prefs.setString("username", username);
|
||||
prefs.setString("password", password);
|
||||
|
||||
return 0;
|
||||
|
||||
}else{
|
||||
return 5;
|
||||
}
|
||||
} catch (e) {
|
||||
Debug.LogError("Error while login $e");
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static Future<int> Login (String username, String password) async{
|
||||
Debug.Log("Logging in");
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
|
||||
var loginResponse = null;
|
||||
try {
|
||||
loginResponse = (await http.post(
|
||||
Uri.parse('${Brain.API_ENDPOINT}login.php'),
|
||||
body: <String, String>{
|
||||
"username": username,
|
||||
"password": password
|
||||
}));
|
||||
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", password);
|
||||
return 0;
|
||||
}catch(e){
|
||||
return 5;
|
||||
}
|
||||
} catch (e) {
|
||||
Debug.LogError("Error while login $e");
|
||||
}
|
||||
|
||||
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);
|
||||
prefs.setBool("googleLogin", true);
|
||||
return 0;
|
||||
}catch(e){
|
||||
return 5;
|
||||
}
|
||||
} catch (e) {
|
||||
Debug.LogError("Error while login $e");
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user