Skip to content

Commit ddfece7

Browse files
committed
first commit
0 parents  commit ddfece7

File tree

9 files changed

+393
-0
lines changed

9 files changed

+393
-0
lines changed

LICENSE.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023 FémLol Stúdió
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Gacha Club PHP API
2+
3+
This is a simple Gacha Club API. With it you can make a server for online character import-export and data transfer.
4+
5+
## Setup
6+
7+
1. Rent a web hosting *(For example here: [Contabo](https://contabo.com/en/web-hosting/))*.
8+
2.
9+
- Method 1: Download the files frim this GitHub repo.
10+
- Method 2: If the web server support Git use it to setup the server.
11+
3. Upload files into the web host.
12+
4. Create the database and run the [`database/database.sql`](database/database.sql) file. *(Recomened to use [phpMyAdmin](https://www.phpmyadmin.net/).)*
13+
5. Apply [enviorment variables](#enviorment-variables) or write them directly into the [`scripts/lib/connect.php`](scripts/lib/connect.php).
14+
- For example: `getenv("SERVER")` => `"127.0.0.1"`
15+
16+
## Enviorment variables
17+
18+
You need to setup these variables to enable connection between the PHP files and the database.
19+
20+
> - `SERVER`: mysql server address
21+
> - default: `"localhost"`
22+
> - For example: `"127.0.0.1"`, `"localhost"`
23+
> - `PORT`: mysql server port *(`1`-`65535`)*
24+
> - Default: `3306`
25+
> - `USER`: mysql username
26+
> - For example: `"root"`
27+
> - `PASSWORD`: mysql user password
28+
> - For example: `"password@123"`
29+
> - `DATABASE`: mysql database name
30+
> - For example: `"gacha-club"`
31+
32+
## License
33+
34+
[MIT](LICENSE.txt)

database/database.sql

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
2+
START TRANSACTION;
3+
4+
CREATE TABLE `oc` (
5+
`accountx` char(7) CHARACTER SET ascii COLLATE ascii_general_ci NOT NULL,
6+
`mycode` text COMPRESSED NOT NULL DEFAULT ''
7+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=COMPRESSED;
8+
9+
CREATE TABLE `transfer` (
10+
`accountx` int(10) UNSIGNED NOT NULL,
11+
`data` longtext COMPRESSED NOT NULL CHECK (json_valid(`data`))
12+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=COMPRESSED;
13+
14+
ALTER TABLE `oc`
15+
ADD PRIMARY KEY (`accountx`);
16+
17+
ALTER TABLE `transfer`
18+
ADD PRIMARY KEY (`accountx`);
19+
COMMIT;

other/test.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
// Convert $_POST to a JSON string
4+
$jsonString = json_encode($_POST);
5+
6+
// Write the JSON string to a file
7+
$file = 'test.json';
8+
file_put_contents($file, $jsonString, FILE_APPEND);

scripts/club_export.php

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
3+
//------------------------
4+
// INPUT:
5+
// accountx = <7_digit_character> // 0-9 & A-Z
6+
// mycode = <character_code>
7+
//------------------------
8+
// OUTPUT:
9+
// systemResult = 2
10+
// msg = <message>
11+
// OR
12+
// systemResult = 3
13+
// msg = <message>
14+
//------------------------
15+
16+
//--------------------------------------------------------------
17+
//header
18+
//--------------------------------------------------------------
19+
20+
header('Content-type: application/x-www-form-urlencoded; charset=utf-8');
21+
22+
//--------------------------------------------------------------
23+
//checking prerequirements
24+
//--------------------------------------------------------------
25+
26+
if (!isset($_POST["accountx"]))
27+
{
28+
$obj = (object)[];
29+
$obj->systemResult = 3;
30+
$obj->msg = "accountx error";
31+
die(http_build_query($obj));
32+
}
33+
34+
if (!isset($_POST["mycode"]) || mb_substr_count($_POST["mycode"], '|') != 444)
35+
{
36+
$obj = (object)[];
37+
$obj->systemResult = 3;
38+
$obj->msg = "mycode error";
39+
die(http_build_query($obj));
40+
}
41+
42+
//--------------------------------------------------------------
43+
//connection
44+
//--------------------------------------------------------------
45+
46+
require "lib/connect.php";
47+
48+
//--------------------------------------------------------------
49+
//work
50+
//--------------------------------------------------------------
51+
52+
// prepare and bind
53+
$stmt = $conn->prepare("INSERT INTO `oc`(`accountx`, `mycode`) VALUES (?,?)");
54+
$stmt->bind_param("ss", $accountx, $mycode);
55+
56+
// set parameters and execute
57+
$accountx = strtoupper($_POST["accountx"]);
58+
$mycode = $_POST["mycode"];
59+
$mycode = str_replace("||", "|-|", $mycode);
60+
$mycode = str_replace("||", "|-|", $mycode);
61+
$mycode = str_replace("| |", "|-|", $mycode);
62+
$mycode = str_replace("| |", "|-|", $mycode);
63+
$stmt->execute();
64+
65+
$obj = (object)[];
66+
$obj->systemResult = 2;
67+
$obj->msg = "Uploaded successfully";
68+
echo http_build_query($obj);
69+
70+
$stmt->close();
71+
$conn->close();
72+
73+
//--------------------------------------------------------------

scripts/club_import.php

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
3+
//------------------------
4+
// INPUT:
5+
// accountx = <9_digit_number>
6+
//------------------------
7+
// OUTPUT:
8+
// systemResult = 2
9+
// xmycode = <character_code>
10+
// OR
11+
// systemResult = 3
12+
// msg = <message>
13+
//------------------------
14+
15+
//--------------------------------------------------------------
16+
//header
17+
//--------------------------------------------------------------
18+
19+
header('Content-type: application/x-www-form-urlencoded; charset=utf-8');
20+
21+
//--------------------------------------------------------------
22+
//checking prerequirements
23+
//--------------------------------------------------------------
24+
25+
if (!isset($_POST["accountx"]))
26+
{
27+
$obj = (object)[];
28+
$obj->systemResult = 3;
29+
$obj->msg = "accountx error";
30+
die(http_build_query($obj));
31+
}
32+
33+
//--------------------------------------------------------------
34+
//connection
35+
//--------------------------------------------------------------
36+
37+
require "lib/connect.php";
38+
39+
//--------------------------------------------------------------
40+
//work
41+
//--------------------------------------------------------------
42+
43+
$id = strtoupper($_POST["accountx"]);
44+
45+
$stmt = $conn->prepare("SELECT `mycode` FROM `oc` WHERE `accountx` = ? LIMIT 1");
46+
$stmt->bind_param('s', $id); // 's' specifies the variable type => 'string'
47+
$stmt->execute();
48+
$result = $stmt->get_result();
49+
50+
if ($result->num_rows == 1)
51+
{
52+
$datas = $result->fetch_assoc();
53+
54+
$obj = (object)[];
55+
$obj->systemResult = 2;
56+
$obj->xmycode = $datas["mycode"];
57+
58+
echo http_build_query($obj);
59+
}
60+
else
61+
{
62+
$obj = (object)[];
63+
$obj->systemResult = 3;
64+
$obj->msg = "Character not exist in the database";
65+
echo http_build_query($obj);
66+
}
67+
$stmt->close();
68+
$conn->close();
69+
70+
//--------------------------------------------------------------

scripts/club_login.php

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
3+
//------------------------
4+
// INPUT:
5+
// accountx = <9_digit_number>
6+
//------------------------
7+
// OUTPUT:
8+
// systemResult = 2
9+
// accountx = <9_digit_number>
10+
// datastring1 = <long_string>
11+
// datastring2 = <long_string>
12+
// ...
13+
// datastring20 = <long_string>
14+
// OR
15+
// systemResult = 3
16+
// msg = <message>
17+
//------------------------
18+
19+
//--------------------------------------------------------------
20+
//header
21+
//--------------------------------------------------------------
22+
23+
header('Content-type: application/x-www-form-urlencoded; charset=utf-8');
24+
25+
//--------------------------------------------------------------
26+
//checking prerequirements
27+
//--------------------------------------------------------------
28+
29+
if (!isset($_POST["accountx"]) || !is_numeric($_POST["accountx"]) || $_POST["accountx"] < 100_000_000 || $_POST["accountx"] > 999_999_999)
30+
{
31+
$obj = (object)[];
32+
$obj->systemResult = 3;
33+
$obj->msg = "accountx error";
34+
die(http_build_query($obj));
35+
}
36+
37+
//--------------------------------------------------------------
38+
//connection
39+
//--------------------------------------------------------------
40+
41+
require "lib/connect.php";
42+
43+
//--------------------------------------------------------------
44+
//work
45+
//--------------------------------------------------------------
46+
47+
// prepare and bind
48+
$stmt = $conn->prepare("SELECT `data` FROM `transfer` WHERE `accountx` = ? LIMIT 1");
49+
$stmt->bind_param("i", $accountx);
50+
$accountx = $_POST["accountx"];
51+
$stmt->execute();
52+
$result = $stmt->get_result();
53+
54+
if ($result->num_rows == 1)
55+
{
56+
$datas = $result->fetch_assoc();
57+
$datas = json_decode($datas["data"]);
58+
$datas->systemResult = 2;
59+
echo http_build_query($datas);
60+
}
61+
else
62+
{
63+
$obj = (object)[];
64+
$obj->systemResult = 3;
65+
$obj->msg = "Transfer data not exist";
66+
echo http_build_query($obj);
67+
}
68+
69+
$stmt->close();
70+
$conn->close();
71+
72+
//--------------------------------------------------------------

scripts/club_register.php

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
3+
//------------------------
4+
// INPUT:
5+
// accountx = <9_digit_number>
6+
// datastring1 = <long_string>
7+
// datastring2 = <long_string>
8+
// ...
9+
// datastring20 = <long_string>
10+
//------------------------
11+
// OUTPUT:
12+
// systemResult = 2
13+
// msg = <message>
14+
// OR
15+
// systemResult = 3
16+
// msg = <message>
17+
//------------------------
18+
19+
//--------------------------------------------------------------
20+
//header
21+
//--------------------------------------------------------------
22+
23+
header('Content-type: application/x-www-form-urlencoded; charset=utf-8');
24+
25+
//--------------------------------------------------------------
26+
//checking prerequirements
27+
//--------------------------------------------------------------
28+
29+
if (!isset($_POST["accountx"]) || !is_numeric($_POST["accountx"]) || $_POST["accountx"] < 100_000_000 || $_POST["accountx"] > 999_999_999)
30+
{
31+
$obj = (object)[];
32+
$obj->systemResult = 3;
33+
$obj->msg = "accountx error";
34+
die(http_build_query($obj));
35+
}
36+
37+
//--------------------------------------------------------------
38+
//connection
39+
//--------------------------------------------------------------
40+
41+
require "lib/connect.php";
42+
43+
//--------------------------------------------------------------
44+
//work
45+
//--------------------------------------------------------------
46+
47+
// prepare and bind
48+
$stmt = $conn->prepare("INSERT INTO `transfer`(`accountx`, `data`) VALUES (?, ?) ON DUPLICATE KEY UPDATE `data` = ?");
49+
$stmt->bind_param("iss", $accountx, $data, $data);
50+
51+
// set parameters and execute
52+
$accountx = $_POST["accountx"];
53+
$data = json_encode($_POST);
54+
55+
$stmt->execute();
56+
57+
$obj = (object)[];
58+
$obj->systemResult = 2;
59+
$obj->msg = "Uploaded successfully";
60+
61+
echo http_build_query($obj);
62+
63+
$stmt->close();
64+
$conn->close();
65+
66+
//--------------------------------------------------------------

0 commit comments

Comments
 (0)