Adds logic for making folders
This commit is contained in:
parent
e71f55cbc4
commit
c1dd5e1957
6 changed files with 210 additions and 5 deletions
|
@ -8,7 +8,7 @@ class Constants {
|
||||||
static const DRAWER_COLOR = Color.fromARGB(148, 0, 97, 97);
|
static const DRAWER_COLOR = Color.fromARGB(148, 0, 97, 97);
|
||||||
static const PORTFOLIO_CARD_COLOR = Color.fromARGB(255, 0, 71, 97);
|
static const PORTFOLIO_CARD_COLOR = Color.fromARGB(255, 0, 71, 97);
|
||||||
|
|
||||||
static const VERSION = "Version 1.0.051624.0410";
|
static const VERSION = "Version 1.0.051624.1730";
|
||||||
static const COPYRIGHT = "Copyright 2024 - Tara Piccari. All rights Reserved";
|
static const COPYRIGHT = "Copyright 2024 - Tara Piccari. All rights Reserved";
|
||||||
static const CLIENTPSK =
|
static const CLIENTPSK =
|
||||||
"f5c6caf3efe1ec5aa4b7c572f92aa14782b7be34b4c7844fa9c6d47fdf94246";
|
"f5c6caf3efe1ec5aa4b7c572f92aa14782b7be34b4c7844fa9c6d47fdf94246";
|
||||||
|
|
|
@ -374,3 +374,55 @@ class S2CSessionCheckPacket extends IPacket {
|
||||||
valid: id == Hashing.md5Hash(Settings().currentUser!.ID.toString()));
|
valid: id == Hashing.md5Hash(Settings().currentUser!.ID.toString()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class C2SCreateFolderPacket extends IPacket {
|
||||||
|
UUID ParentFolder;
|
||||||
|
UUID ID;
|
||||||
|
String Name;
|
||||||
|
int Type;
|
||||||
|
UUID Owner;
|
||||||
|
String client;
|
||||||
|
|
||||||
|
C2SCreateFolderPacket(
|
||||||
|
{required this.ParentFolder,
|
||||||
|
required this.ID,
|
||||||
|
required this.Name,
|
||||||
|
required this.Type,
|
||||||
|
required this.Owner,
|
||||||
|
required this.client});
|
||||||
|
|
||||||
|
@override
|
||||||
|
HTTPMethod method() {
|
||||||
|
return HTTPMethod.Post;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
String getType() {
|
||||||
|
return "C2SCreateFolder";
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
String encode() {
|
||||||
|
return json.encode({
|
||||||
|
"parent": ParentFolder.toString(),
|
||||||
|
"id": ID.toString(),
|
||||||
|
"name": Name,
|
||||||
|
"type": getType(),
|
||||||
|
"invType": Type,
|
||||||
|
"owner": Owner.toString(),
|
||||||
|
"client": Hashing.md5Hash(client)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
String encodeSafe() {
|
||||||
|
return json.encode({
|
||||||
|
"parent": ParentFolder.toString(),
|
||||||
|
"id": ID.toString(),
|
||||||
|
"name": Name,
|
||||||
|
"type": getType(),
|
||||||
|
"invType": Type,
|
||||||
|
"owner": Owner.toString(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -15,7 +15,8 @@ enum APIEndpoint {
|
||||||
Register(script: "Register.php", path: "/ac/home/supports/"),
|
Register(script: "Register.php", path: "/ac/home/supports/"),
|
||||||
Logout(script: "Logout.php", path: "/ac/home/supports/"),
|
Logout(script: "Logout.php", path: "/ac/home/supports/"),
|
||||||
Login(script: "Login.php", path: "/ac/home/supports/"),
|
Login(script: "Login.php", path: "/ac/home/supports/"),
|
||||||
ValidateSession(script: "ValidateToken.php", path: "/ac/home/supports/");
|
ValidateSession(script: "ValidateToken.php", path: "/ac/home/supports/"),
|
||||||
|
MakeFolder(script: "MakeFolder.php", path: "/ac/home/supports/");
|
||||||
|
|
||||||
final String script;
|
final String script;
|
||||||
final String path;
|
final String path;
|
||||||
|
|
|
@ -13,6 +13,7 @@ import 'package:shared_preferences/shared_preferences.dart';
|
||||||
import 'package:zontreck/Constants.dart';
|
import 'package:zontreck/Constants.dart';
|
||||||
import 'package:zontreck/Packets.dart';
|
import 'package:zontreck/Packets.dart';
|
||||||
import 'package:zontreck/Settings.dart';
|
import 'package:zontreck/Settings.dart';
|
||||||
|
import 'package:zontreck/pages/opensim/Inventory.dart';
|
||||||
|
|
||||||
class User {
|
class User {
|
||||||
UUID ID;
|
UUID ID;
|
||||||
|
@ -51,7 +52,7 @@ class User {
|
||||||
"rez": createdAt,
|
"rez": createdAt,
|
||||||
"title": userTitle,
|
"title": userTitle,
|
||||||
"active": active,
|
"active": active,
|
||||||
"token": loginToken
|
"token": loginToken.toString()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,9 +116,11 @@ class OpenSimPageState extends State<OpenSimPage> {
|
||||||
SharedPreferences prefs = await SharedPreferences.getInstance();
|
SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||||
if (prefs.containsKey("settings")) {
|
if (prefs.containsKey("settings")) {
|
||||||
String encoded = prefs.getString("settings")!;
|
String encoded = prefs.getString("settings")!;
|
||||||
CompoundTag tag = NbtIo.readBase64String(encoded) as CompoundTag;
|
CompoundTag tag = await NbtIo.readBase64String(encoded) as CompoundTag;
|
||||||
if (tag.contains("user"))
|
if (tag.contains("user")) {
|
||||||
settings.currentUser = User.load(tag.get("user") as CompoundTag);
|
settings.currentUser = User.load(tag.get("user") as CompoundTag);
|
||||||
|
settings.loggedIn = true;
|
||||||
|
}
|
||||||
|
|
||||||
// Validate current session
|
// Validate current session
|
||||||
var reply = await settings.sendPacketToEndpoint(
|
var reply = await settings.sendPacketToEndpoint(
|
||||||
|
@ -147,6 +150,14 @@ class OpenSimPageState extends State<OpenSimPage> {
|
||||||
setState(() {
|
setState(() {
|
||||||
polling = false;
|
polling = false;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (settings.loggedIn && !settings.currentUser!.active) {
|
||||||
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (B) {
|
||||||
|
return CreateInventoryPopup();
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
|
@ -1,3 +1,11 @@
|
||||||
|
import 'dart:async';
|
||||||
|
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:libac_flutter/utils/uuid/UUID.dart';
|
||||||
|
import 'package:zontreck/Constants.dart';
|
||||||
|
import 'package:zontreck/Packets.dart';
|
||||||
|
import 'package:zontreck/Settings.dart';
|
||||||
|
|
||||||
enum InventoryFolder {
|
enum InventoryFolder {
|
||||||
Texture(id: 0, name: "Textures"),
|
Texture(id: 0, name: "Textures"),
|
||||||
Sound(id: 1, name: "Sounds"),
|
Sound(id: 1, name: "Sounds"),
|
||||||
|
@ -32,3 +40,105 @@ enum InventoryFolder {
|
||||||
final String name;
|
final String name;
|
||||||
const InventoryFolder({required this.id, required this.name});
|
const InventoryFolder({required this.id, required this.name});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class CreateInventoryPopup extends StatefulWidget {
|
||||||
|
@override
|
||||||
|
State<StatefulWidget> createState() => CreateInventoryState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class CreateInventoryState extends State<CreateInventoryPopup> {
|
||||||
|
double getProgress() {
|
||||||
|
double percent = (value * 100 / total);
|
||||||
|
return percent / 100;
|
||||||
|
}
|
||||||
|
|
||||||
|
int value = 0;
|
||||||
|
int total = 100;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void didChangeDependencies() {
|
||||||
|
startProcessing();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> startProcessing() async {
|
||||||
|
total = InventoryFolder.values.length;
|
||||||
|
await Future.delayed(Duration(seconds: 5));
|
||||||
|
|
||||||
|
UUID rootFolder = UUID.generate(4);
|
||||||
|
|
||||||
|
Settings settings = Settings();
|
||||||
|
Future<void> createFolder(Timer timer) async {
|
||||||
|
if (getProgress() >= 1) {
|
||||||
|
timer.cancel();
|
||||||
|
Navigator.pop(context);
|
||||||
|
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
||||||
|
content: Text(
|
||||||
|
"Inventory successfully created. Your account is now active")));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
UUID parent = rootFolder;
|
||||||
|
UUID id = UUID.generate(4);
|
||||||
|
UUID owner = settings.currentUser!.ID;
|
||||||
|
int type = InventoryFolder.values[value].id;
|
||||||
|
String name = InventoryFolder.values[value].name;
|
||||||
|
|
||||||
|
if (type == InventoryFolder.ROOT.id) {
|
||||||
|
parent = UUID.ZERO;
|
||||||
|
id = rootFolder;
|
||||||
|
}
|
||||||
|
|
||||||
|
C2SCreateFolderPacket makeFolder = C2SCreateFolderPacket(
|
||||||
|
ParentFolder: parent,
|
||||||
|
ID: id,
|
||||||
|
Name: name,
|
||||||
|
Type: type,
|
||||||
|
Owner: owner,
|
||||||
|
client: Constants.CLIENTPSK);
|
||||||
|
|
||||||
|
var reply = await settings.sendPacketToEndpoint(
|
||||||
|
APIEndpoint.MakeFolder, makeFolder) as S2CSimpleReplyPacket;
|
||||||
|
if (!reply.done) {
|
||||||
|
timer.cancel();
|
||||||
|
Navigator.pop(context);
|
||||||
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (V) {
|
||||||
|
return AlertDialog(
|
||||||
|
title: Text("FATAL ERROR"),
|
||||||
|
content: Text(
|
||||||
|
"For an unknown reason, we failed to create the inventory folders. Some may have been created, but there was an error while processing: ${makeFolder.encodeSafe()}"),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
value++;
|
||||||
|
|
||||||
|
setState(() {});
|
||||||
|
}
|
||||||
|
|
||||||
|
Timer.periodic(Duration(milliseconds: 500), createFolder);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return AlertDialog(
|
||||||
|
icon: Icon(Icons.folder_copy),
|
||||||
|
title: Text("Please Wait... Activating Account"),
|
||||||
|
content: SizedBox(
|
||||||
|
height: 75,
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
Text("Creating necessary Inventory Folders"),
|
||||||
|
Divider(),
|
||||||
|
LinearProgressIndicator(
|
||||||
|
value: getProgress(),
|
||||||
|
color: Constants.PORTFOLIO_CARD_COLOR,
|
||||||
|
minHeight: 10,
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
31
php/MakeFolder.php
Normal file
31
php/MakeFolder.php
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
if(!defined("COMMON"))
|
||||||
|
require("Common.php");
|
||||||
|
|
||||||
|
$js = getJsonizedInput();
|
||||||
|
$DB = get_DB();
|
||||||
|
|
||||||
|
$clientKey = $js['client'];
|
||||||
|
|
||||||
|
$complete=false;
|
||||||
|
if($clientKey == md5(CLIENTPSK)) {
|
||||||
|
// Authorized
|
||||||
|
$complete=true;
|
||||||
|
$name = $js['name'];
|
||||||
|
$type = $js['invType'];
|
||||||
|
$parent = $js['parent'];
|
||||||
|
$owner = $js['owner'];
|
||||||
|
$id = $js['id'];
|
||||||
|
|
||||||
|
$res = $DB->query("INSERT INTO `inventoryFolders` (folderName, type, version, folderID, agentID, parentFolderID ) VALUES ('$name', '$type', 0, '$id', '$owner', '$parent');");
|
||||||
|
|
||||||
|
if(!$res) $complete=false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
die(json_encode(array(
|
||||||
|
"done" => $complete,
|
||||||
|
"type" => "S2CSimpleReply"
|
||||||
|
)));
|
||||||
|
?>
|
Loading…
Add table
Add a link
Reference in a new issue