From 8dca98f64616fb77acf12b673c4da813b8b402a5 Mon Sep 17 00:00:00 2001 From: "sewmina7@gmail.com" Date: Wed, 17 Jul 2024 16:31:39 +0530 Subject: [PATCH] m --- lib/Backend/Backend.dart | 85 +++++- lib/home.dart | 2 +- lib/login.dart | 268 ++++++++++++++---- macos/Flutter/GeneratedPluginRegistrant.swift | 2 + pubspec.lock | 88 +++++- pubspec.yaml | 1 + .../flutter/generated_plugin_registrant.cc | 3 + windows/flutter/generated_plugins.cmake | 1 + 8 files changed, 381 insertions(+), 69 deletions(-) diff --git a/lib/Backend/Backend.dart b/lib/Backend/Backend.dart index a1d1a10..1ce681a 100644 --- a/lib/Backend/Backend.dart +++ b/lib/Backend/Backend.dart @@ -11,13 +11,14 @@ class Backend{ static const String API_ENDPOINT = "https://vps.playpoolstudios.com/metahunt/api/launcher/"; static List Games = [ - GameData(0,"mhunt","Metahunt", "High-Stake Battle Royale game with Play to earn abilities", "images/mhunt_thumbnail.png", true,"CRPB.exe"), + GameData(0,"mhunt","Metahunt", "High-Stake Battle Royale game with Play to earn abilities", "images/mhunt_thumbnail.png", true,"METAHUNT.exe"), GameData(1,"pop3d","Pop3D", "a game I dont know much about xD", "images/pop3d_thumbnail.png", false, "pop3d.exe"), ]; static SharedPreferences? prefs; static Directory? docPath; static String Username=""; + static Map UserJson = {'username':'test', 'passwd':'test123'}; static Future Login(String username, String password) async{ var loginResponse = null; @@ -29,6 +30,8 @@ class Backend{ try { Username=username; + SetUsernamePassword(username, password); + return true; } catch (e) { } @@ -43,16 +46,17 @@ class Backend{ docPath = await getDownloadsDirectory(); } - static Future Register(String username, String password) async{ + static Future Register(String username, String password, String displayname) async{ var loginResponse = null; init(); try { loginResponse = (await http.post(Uri.parse('${API_ENDPOINT}register.php'), - body: {"username": username, "password": password})); + body: {"username": username, "password": password, "display_name": displayname})); Debug.LogResponse(loginResponse.body.toString(),src: '${API_ENDPOINT}register.php'); try { + SetUsernamePassword(username, password); return true; } catch (e) { } @@ -63,6 +67,10 @@ class Backend{ return false; } + static void SetUsernamePassword(String username, String passwd){ + UserJson = {'username':username, 'passwd':passwd}; + } + static Future> GetLeaderboard(String gameCode) async{ String url = '${API_ENDPOINT}/${gameCode}/get_leaderboard.php'; var leaderboardResponse = await http.get(Uri.parse(url)); @@ -105,6 +113,77 @@ class Backend{ return {}; } + + static Future CreateRequest() async{ + var loginResponse = null; + + try { + String url = '${API_ENDPOINT}create_request.php'; + loginResponse = await http.get(Uri.parse(url)); + Debug.LogResponse(loginResponse.body.toString(),src: url); + + return loginResponse.body.toString(); + } catch (e) { + Debug.LogError("Error while login $e"); + } + + return "-1"; + } + + static Future GetRequestResponse(String id) async{ + var loginResponse = null; + + try { + String url = '${API_ENDPOINT}get_request_response.php'; + loginResponse = (await http.post(Uri.parse(url), + body: {"id":id.toString()})); + Debug.LogResponse(loginResponse.body.toString(),src: url); + + return loginResponse.body; + } catch (e) { + Debug.LogError("Error while login $e"); + } + + return "-1"; + } + + static Future GetDisplayName(String id) async{ + var response = null; + + try { + String url = '${API_ENDPOINT}get_display_name.php'; + response = (await http.post(Uri.parse(url), + body: {"id":id.toString()})); + Debug.LogResponse(response.body.toString(),src: url); + + return response.body; + } catch (e) { + Debug.LogError("Error while login $e"); + } + + return "-1"; + } + + static Future GetUsernameValidation(String username) async{ + var loginResponse = null; + + try { + String url = '${API_ENDPOINT}validate_username.php'; + loginResponse = (await http.post(Uri.parse(url), + body: {"username":username})); + Debug.LogResponse(loginResponse.body.toString(),src: url); + + if(loginResponse.body == "0"){ + return true; + }else{ + return false; + } + } catch (e) { + Debug.LogError("Error while login $e"); + } + + return false; + } } diff --git a/lib/home.dart b/lib/home.dart index 2e33c00..c462ec4 100644 --- a/lib/home.dart +++ b/lib/home.dart @@ -395,7 +395,7 @@ class _HomePageState extends State { if(runningProcs.containsKey(id)){return;} String exePath = InstallHelper.GetExeFilePath(dashboardSelectedGameIndex); // Process proc = await run(exePath,); - runningProcs.putIfAbsent(id, ()=> run(exePath)); + runningProcs.putIfAbsent(id, ()=> run(exePath + " username ${Backend.UserJson['username']} password ${Backend.UserJson['passwd']}")); setState(() { }); diff --git a/lib/login.dart b/lib/login.dart index 400a46e..389df3d 100644 --- a/lib/login.dart +++ b/lib/login.dart @@ -1,9 +1,11 @@ +import 'package:flutter/cupertino.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:mhunt_launcher/Backend/Backend.dart'; import 'package:mhunt_launcher/Widgets/CustomWidgets.dart'; import 'package:mhunt_launcher/home.dart'; import 'package:shared_preferences/shared_preferences.dart'; +import 'package:url_launcher/url_launcher.dart'; class LoginPage extends StatefulWidget { const LoginPage({super.key}); @@ -13,7 +15,6 @@ class LoginPage extends StatefulWidget { } class _LoginPageState extends State { - bool isReg = false; @override @@ -23,15 +24,14 @@ class _LoginPageState extends State { kickstartAnimations(); - autoLogin(); + //autoLogin(); } - - void autoLogin()async{ + void autoLogin() async { SharedPreferences prefs = await SharedPreferences.getInstance(); - if(prefs.containsKey("username") && prefs.containsKey("password")){ - usernameController.text = prefs.getString("username")??''; - passwordController.text = prefs.getString("password")??''; + if (prefs.containsKey("username") && prefs.containsKey("password")) { + usernameController.text = prefs.getString("username") ?? ''; + passwordController.text = prefs.getString("password") ?? ''; LoginOrReg(); } @@ -50,72 +50,234 @@ class _LoginPageState extends State { TextEditingController usernameController = TextEditingController(); TextEditingController passwordController = TextEditingController(); - - @override Widget build(BuildContext context) { - - const Color backgroundColor = Color(0xFF111111); const Color modalColor = Color(0xFFFFFFFF); return Scaffold( backgroundColor: Colors.transparent, body: CustomBody( - context: context, - onAnimEnd: () { - // kickstartAnimations(); - setState(() {}); - }, - child: Center( - child: GlassCard(child: - Container( - padding: EdgeInsets.all(25), - width: 600, - height: 400, - child: Column( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Text("Welcome to W3B Launcher", style: TextStyle(fontSize: 25,fontWeight: FontWeight.bold),), - Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Row(children: [Text("Username "), SizedBox(width: 300,child: TextField(controller: usernameController,))], mainAxisAlignment: MainAxisAlignment.center,), - Row(children: [Text("Password "), SizedBox(width: 300,child: TextField(controller: passwordController,))], mainAxisAlignment: MainAxisAlignment.center), - SizedBox(height: 30,), - GlassButton(onTap: LoginOrReg, child: Text(isReg? "Register":"Login"),width: 150,height: 40), - ], - ), - Row(children: [Text(isReg? "Already have an Account? ":"Don't have an Account? "), InkWell(child: Text(isReg? "Login Here":"Register Here",style: TextStyle(color: Colors.blue),),onTap: (){setState(() { - isReg = !isReg; - });},)], mainAxisAlignment: MainAxisAlignment.center) - ], - ), - )), - ) - ), + context: context, + onAnimEnd: () { + // kickstartAnimations(); + setState(() {}); + }, + child: Center( + child: web3LoginCard() + )) ); } + Widget web3LoginCardContent0(){ + return Column( + mainAxisSize: MainAxisSize.min, + children: [ + const Text( + "Welcome to W3B Launcher", + style: TextStyle(fontSize: 25, fontWeight: FontWeight.bold), + ), + SizedBox(height: 50,), + GlassButton(onTap: loginWeb3, child: Text("Loing / Signup"), width: 250,height: 50) + ], + ); + } - void LoginOrReg() async{ + Widget web3LoginCardContent1(){ + return Column( + mainAxisSize: MainAxisSize.min, + children: [ + Padding( + padding: const EdgeInsets.all(18.0), + child: const Text( + "Complete logging in on your browser", + style: TextStyle(fontSize: 25, fontWeight: FontWeight.bold), + ), + ) + ], + ); + } + TextEditingController usernameEditingController= TextEditingController(); + Widget web3LoginCardNewUsername(){ + return Column( + mainAxisSize: MainAxisSize.min, + children: [ + const Text( + "Enter a username", + style: TextStyle(fontSize: 25, fontWeight: FontWeight.bold), + ), + SizedBox(height: 50,), + SizedBox(width: 250,child: TextField(controller: usernameEditingController,textAlign: TextAlign.center,)), + SizedBox(width: 250,child:usernameExists ? Text("Username is taken",style: TextStyle(color: Colors.red),) : Container()), + SizedBox(height: 20,), + + !web3loginworking ? GlassButton(onTap: completeweb3, child: Text("Complete"), width: 250,height: 50) : GlassButton(onTap: (){}, child: Text("Loading"), width: 250,height: 50) + ], + ); + } + + Widget web3LoginCardContent(){ + switch(web3loginState){ + case 1: + return web3LoginCardContent1(); + break; + + case 2: + return web3LoginCardNewUsername(); + break; + + default: + return web3LoginCardContent0(); + break; + } + } + + Widget web3LoginCard(){ + return GlassCard(child: Padding(padding: EdgeInsets.all(20),child: + web3LoginCardContent() + ) + ); + } + int web3loginState = 0; + String web3id = ""; + void loginWeb3() async{ + String requestId = await Backend.CreateRequest(); + setState(() { + web3loginState = 1; + }); + launchUrl(Uri.parse('https://auth.playpoolstudios.com/?request_id=${requestId}')); + String requestResponse = "-1"; + while(requestResponse == "-1"){ + await Future.delayed(const Duration(seconds: 1)); + requestResponse = await Backend.GetRequestResponse(requestId); + } + + web3id = requestResponse; + String dispName = await Backend.GetDisplayName(web3id); + if(dispName == "-1"){ + setState(() { + web3loginState = 2; + }); + }else{ + usernameEditingController.text = dispName; + completeweb3(); + } + + // await Backend.Login(requestResponse, requestResponse); + // OnLoginSuccess(); + } + + bool usernameExists = false; + bool web3loginworking = false; + void completeweb3() async{ + if(web3id.length < 3){ + setState(() { + web3loginState=0; + }); + return; + } + + if(usernameEditingController.text.isEmpty){return;} + setState((){ web3loginworking=true; }); + bool usernameValidated = await Backend.GetUsernameValidation(usernameEditingController.text); + if(!usernameValidated){ + setState(() { + usernameExists = true; + }); + setState((){ web3loginworking=false; }); + + return; + } + + await Backend.Register(web3id,web3id,usernameEditingController.text); + await Backend.Login(usernameEditingController.text, web3id); + + OnLoginSuccess(); + } + + + Widget TraditionalLoginCard(){ + return GlassCard( + child: Container( + padding: EdgeInsets.all(25), + width: 600, + height: 400, + child: Column( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + const Text( + "Welcome to W3B Launcher", + style: TextStyle(fontSize: 25, fontWeight: FontWeight.bold), + ), + Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Row( + children: [ + Text("Username "), + SizedBox( + width: 300, + child: TextField( + controller: usernameController, + )) + ], + mainAxisAlignment: MainAxisAlignment.center, + ), + Row(children: [ + Text("Password "), + SizedBox( + width: 300, + child: TextField( + controller: passwordController, + )) + ], mainAxisAlignment: MainAxisAlignment.center), + SizedBox( + height: 30, + ), + GlassButton(onTap: LoginOrReg, child: Text(isReg ? "Register" : "Login"), width: 150, height: 40), + ], + ), + Row(children: [ + Text(isReg ? "Already have an Account? " : "Don't have an Account? "), + InkWell( + child: Text( + isReg ? "Login Here" : "Register Here", + style: TextStyle(color: Colors.blue), + ), + onTap: () { + setState(() { + isReg = !isReg; + }); + }, + ) + ], mainAxisAlignment: MainAxisAlignment.center) + ], + ), + )); + } + + void LoginOrReg() async { // if(kDebugMode){ // Navigator.of(context).push(MaterialPageRoute(builder: (context)=>HomePage())); // return; // } bool success = false; - if(isReg){ - success = await Backend.Register(usernameController.text, passwordController.text); - }else{ + if (isReg) { + success = await Backend.Register(usernameController.text, passwordController.text, usernameController.text); + } else { success = await Backend.Login(usernameController.text, passwordController.text); } - if(success){ - SharedPreferences prefs = await SharedPreferences.getInstance(); - prefs.setString('username', usernameController.text); - prefs.setString('password', passwordController.text); - - Navigator.of(context).push(MaterialPageRoute(builder: (context)=>HomePage())); + if (success) { + OnLoginSuccess(); } } + + void OnLoginSuccess() async{ + SharedPreferences prefs = await SharedPreferences.getInstance(); + prefs.setString('username', usernameController.text); + prefs.setString('password', passwordController.text); + + Navigator.of(context).push(MaterialPageRoute(builder: (context) => HomePage())); + } } diff --git a/macos/Flutter/GeneratedPluginRegistrant.swift b/macos/Flutter/GeneratedPluginRegistrant.swift index b8e2b22..b19945c 100644 --- a/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/macos/Flutter/GeneratedPluginRegistrant.swift @@ -7,8 +7,10 @@ import Foundation import path_provider_foundation import shared_preferences_foundation +import url_launcher_macos func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin")) SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin")) + UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin")) } diff --git a/pubspec.lock b/pubspec.lock index 240f4b3..62a4ab3 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -148,26 +148,26 @@ packages: dependency: transitive description: name: leak_tracker - sha256: "7f0df31977cb2c0b88585095d168e689669a2cc9b97c309665e3386f3e9d341a" + sha256: "78eb209deea09858f5269f5a5b02be4049535f568c07b275096836f01ea323fa" url: "https://pub.dev" source: hosted - version: "10.0.4" + version: "10.0.0" leak_tracker_flutter_testing: dependency: transitive description: name: leak_tracker_flutter_testing - sha256: "06e98f569d004c1315b991ded39924b21af84cf14cc94791b8aea337d25b57f8" + sha256: b46c5e37c19120a8a01918cfaf293547f47269f7cb4b0058f21531c2465d6ef0 url: "https://pub.dev" source: hosted - version: "3.0.3" + version: "2.0.1" leak_tracker_testing: dependency: transitive description: name: leak_tracker_testing - sha256: "6ba465d5d76e67ddf503e1161d1f4a6bc42306f9d66ca1e8f079a47290fb06d3" + sha256: a597f72a664dbd293f3bfc51f9ba69816f84dcd403cdac7066cb3f6003f3ab47 url: "https://pub.dev" source: hosted - version: "3.0.1" + version: "2.0.1" lints: dependency: transitive description: @@ -204,10 +204,10 @@ packages: dependency: transitive description: name: meta - sha256: "7687075e408b093f36e6bbf6c91878cc0d4cd10f409506f7bc996f68220b9136" + sha256: d584fa6707a52763a52446f02cc621b077888fb63b93bbcb1143a7be5a0c0c04 url: "https://pub.dev" source: hosted - version: "1.12.0" + version: "1.11.0" mime: dependency: transitive description: @@ -417,10 +417,10 @@ packages: dependency: transitive description: name: test_api - sha256: "9955ae474176f7ac8ee4e989dadfb411a58c30415bcfb648fa04b2b8a03afa7f" + sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b" url: "https://pub.dev" source: hosted - version: "0.7.0" + version: "0.6.1" typed_data: dependency: transitive description: @@ -429,6 +429,70 @@ packages: url: "https://pub.dev" source: hosted version: "1.3.2" + url_launcher: + dependency: "direct main" + description: + name: url_launcher + sha256: "6ce1e04375be4eed30548f10a315826fd933c1e493206eab82eed01f438c8d2e" + url: "https://pub.dev" + source: hosted + version: "6.2.6" + url_launcher_android: + dependency: transitive + description: + name: url_launcher_android + sha256: "17cd5e205ea615e2c6ea7a77323a11712dffa0720a8a90540db57a01347f9ad9" + url: "https://pub.dev" + source: hosted + version: "6.3.2" + url_launcher_ios: + dependency: transitive + description: + name: url_launcher_ios + sha256: "7068716403343f6ba4969b4173cbf3b84fc768042124bc2c011e5d782b24fe89" + url: "https://pub.dev" + source: hosted + version: "6.3.0" + url_launcher_linux: + dependency: transitive + description: + name: url_launcher_linux + sha256: ab360eb661f8879369acac07b6bb3ff09d9471155357da8443fd5d3cf7363811 + url: "https://pub.dev" + source: hosted + version: "3.1.1" + url_launcher_macos: + dependency: transitive + description: + name: url_launcher_macos + sha256: "9a1a42d5d2d95400c795b2914c36fdcb525870c752569438e4ebb09a2b5d90de" + url: "https://pub.dev" + source: hosted + version: "3.2.0" + url_launcher_platform_interface: + dependency: transitive + description: + name: url_launcher_platform_interface + sha256: "552f8a1e663569be95a8190206a38187b531910283c3e982193e4f2733f01029" + url: "https://pub.dev" + source: hosted + version: "2.3.2" + url_launcher_web: + dependency: transitive + description: + name: url_launcher_web + sha256: "8d9e750d8c9338601e709cd0885f95825086bd8b642547f26bda435aade95d8a" + url: "https://pub.dev" + source: hosted + version: "2.3.1" + url_launcher_windows: + dependency: transitive + description: + name: url_launcher_windows + sha256: ecf9725510600aa2bb6d7ddabe16357691b6d2805f66216a97d1b881e21beff7 + url: "https://pub.dev" + source: hosted + version: "3.1.1" vector_math: dependency: transitive description: @@ -441,10 +505,10 @@ packages: dependency: transitive description: name: vm_service - sha256: "3923c89304b715fb1eb6423f017651664a03bf5f4b29983627c4da791f74a4ec" + sha256: b3d56ff4341b8f182b96aceb2fa20e3dcb336b9f867bc0eafc0de10f1048e957 url: "https://pub.dev" source: hosted - version: "14.2.1" + version: "13.0.0" web: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 4881f27..c666e22 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -42,6 +42,7 @@ dependencies: crypto: ^3.0.3 process_run: ^0.14.2 background_downloader: ^8.5.2 + url_launcher: ^6.2.6 dev_dependencies: flutter_test: diff --git a/windows/flutter/generated_plugin_registrant.cc b/windows/flutter/generated_plugin_registrant.cc index 8b6d468..4f78848 100644 --- a/windows/flutter/generated_plugin_registrant.cc +++ b/windows/flutter/generated_plugin_registrant.cc @@ -6,6 +6,9 @@ #include "generated_plugin_registrant.h" +#include void RegisterPlugins(flutter::PluginRegistry* registry) { + UrlLauncherWindowsRegisterWithRegistrar( + registry->GetRegistrarForPlugin("UrlLauncherWindows")); } diff --git a/windows/flutter/generated_plugins.cmake b/windows/flutter/generated_plugins.cmake index b93c4c3..88b22e5 100644 --- a/windows/flutter/generated_plugins.cmake +++ b/windows/flutter/generated_plugins.cmake @@ -3,6 +3,7 @@ # list(APPEND FLUTTER_PLUGIN_LIST + url_launcher_windows ) list(APPEND FLUTTER_FFI_PLUGIN_LIST