Skip to content

Commit bee2ac7

Browse files
author
Trollhunters501PC
authored
Cambiar providor de Cliente de Java a Jsoup, Añadir PHP Edition, Añadir Lua(Roblox) Edition
1 parent e97cdef commit bee2ac7

File tree

9 files changed

+336
-43
lines changed

9 files changed

+336
-43
lines changed

.github/workflows/biuldPHP.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Build PHAR
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
9+
steps:
10+
- uses: actions/checkout@v4
11+
12+
- name: Set up PHP
13+
uses: shivammathur/setup-php@v2
14+
with:
15+
php-version: '8.0'
16+
17+
- name: Build PHAR
18+
run: php -d phar.readonly=0 Build.php
19+
working-directory: ./php
20+
21+
- name: Upload PHAR
22+
uses: actions/upload-artifact@v4
23+
with:
24+
name: Example
25+
path: php/ServerWebGamePost-1.2.1.phar

.github/workflows/buildJava.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ jobs:
2424
uses: actions/upload-artifact@v4
2525
with:
2626
name: ServerWebGamePost Java Edition
27-
path: java/target/ServerWebGamePost-1.2.0.jar
27+
path: java/target/ServerWebGamePost-1.2.1.jar
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
local HttpService = game:GetService("HttpService")
2+
3+
local ServerWebGamePostClient = {}
4+
ServerWebGamePostClient.__index = ServerWebGamePostClient
5+
6+
function ServerWebGamePostClient.new(domain, port, isHttps)
7+
local self = setmetatable({}, ServerWebGamePostClient)
8+
self.domain = domain
9+
self.port = port
10+
self.isHttps = isHttps
11+
self.processDatapackspriv = nil
12+
return self
13+
end
14+
15+
function ServerWebGamePostClient:setProcessDatapacks(callback)
16+
self.processDatapackspriv = callback
17+
end
18+
19+
function ServerWebGamePostClient:getProcessDatapacks()
20+
return self.processDatapackspriv
21+
end
22+
23+
function ServerWebGamePostClient:sendDataPacket(datapack)
24+
local prefix = self.isHttps and "https://" or "http://"
25+
local url = prefix .. self.domain .. ":" .. tostring(self.port) .. "/ServerWebGamePost"
26+
local jsonData = HttpService:JSONEncode(datapack)
27+
28+
local success, response = pcall(function()
29+
return HttpService:RequestAsync({
30+
Url = url,
31+
Method = "POST",
32+
Headers = {
33+
["Content-Type"] = "application/json"
34+
},
35+
Body = jsonData
36+
})
37+
end)
38+
39+
if success then
40+
local data = HttpService:JSONDecode(response.Body)
41+
self:processSubDatapackspriv(data)
42+
else
43+
error("HTTP Request failed: " .. tostring(response))
44+
end
45+
end
46+
47+
function ServerWebGamePostClient:processSubDatapackspriv(datapacks)
48+
if datapacks and datapacks.datapacksLot then
49+
for _, dp in ipairs(datapacks.datapacksLot) do
50+
if self.processDatapackspriv then
51+
self.processDatapackspriv(dp)
52+
end
53+
end
54+
end
55+
end
56+
57+
return ServerWebGamePostClient

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
![Deno](https://shield.deno.dev/x/)
88
![Maven](https://img.shields.io/badge/apache_maven-C71A36?style=for-the-badge&logo=apachemaven&logoColor=white)
99
![Python](https://img.shields.io/badge/python-3670A0?style=for-the-badge&logo=python&logoColor=ffdd54)
10+
![Lua](https://img.shields.io/badge/lua-%232C2D72.svg?style=for-the-badge&logo=lua&logoColor=white)
11+
![PHP](https://img.shields.io/badge/php-%23777BB4.svg?style=for-the-badge&logo=php&logoColor=white)
1012

1113
[![](https://jitpack.io/v/Creadores-Program/ServerWebGamePost.svg)](https://jitpack.io/#Creadores-Program/ServerWebGamePost)
1214

@@ -23,6 +25,8 @@ This Software currently has support for:
2325
- Java
2426
- Browser
2527
- Python
28+
- PHP
29+
- Lua (Roblox)
2630

2731
# Add content
2832
If you want to add content you can do so in discussions of this repo
@@ -36,3 +40,4 @@ Please open a [Issue](https://github.com/Creadores-Program/ServerWebGamePost/iss
3640
# Credits
3741
- Java, Node.JS and Browser Edition by Trollhunters501
3842
- Python by Rext-dev & Trollhunters501
43+
- PHP, Lua(Roblox) by Github Copilot & Trollhunters501

java/pom.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xs
55
<modelVersion>4.0.0</modelVersion>
66
<groupId>org.creadoresprogram</groupId>
77
<artifactId>ServerWebGamePost</artifactId>
8-
<version>1.2.0</version>
8+
<version>1.2.1</version>
99
<properties>
1010
<maven.compiler.source>1.8</maven.compiler.source>
1111
<maven.compiler.target>1.8</maven.compiler.target>
@@ -38,6 +38,11 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xs
3838
<artifactId>spark-core</artifactId>
3939
<version>2.9.4</version>
4040
</dependency>
41+
<dependency>
42+
<groupId>org.jsoup</groupId>
43+
<artifactId>jsoup</artifactId>
44+
<version>1.19.1</version>
45+
</dependency>
4146
<dependency>
4247
<groupId>com.github.spotbugs</groupId>
4348
<artifactId>spotbugs-annotations</artifactId>
Lines changed: 26 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,51 @@
11
package org.CreadoresProgram.ServerWebGamePost.client;
2+
23
import lombok.Getter;
34
import lombok.Setter;
45
import lombok.NonNull;
56
import com.alibaba.fastjson2.JSONObject;
67
import com.alibaba.fastjson2.JSON;
7-
import java.net.HttpURLConnection;
8-
import java.net.URL;
9-
import java.io.BufferedReader;
10-
import java.io.InputStreamReader;
11-
import java.io.OutputStream;
12-
import java.io.IOException;
8+
import org.jsoup.Jsoup;
9+
import org.jsoup.Connection;
1310

14-
public final class ServerWebGamePostClient{
11+
public final class ServerWebGamePostClient {
1512
private String domain;
1613
private int port;
1714
private boolean isHttps;
15+
1816
@Getter
1917
@Setter
2018
public ProcessDatapackClient processDatapacks;
2119

2220
@Getter
2321
@Setter
24-
public String userAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36 Edg/128.0.0.0";
22+
public String userAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36 Edg/134.0.0.0";
2523

26-
public ServerWebGamePostClient(@NonNull String domain, @NonNull int port, @NonNull boolean isHttps){
24+
public ServerWebGamePostClient(@NonNull String domain, @NonNull int port, @NonNull boolean isHttps) {
2725
this.domain = domain;
2826
this.port = port;
2927
this.isHttps = isHttps;
3028
this.processDatapacks = new ProcessDatapackClient(this);
3129
}
32-
public void sendDataPacket(@NonNull JSONObject datapack){
33-
try{
34-
String prefix = "";
35-
if(this.isHttps){
36-
prefix = "https://";
37-
}else{
38-
prefix = "http://";
39-
}
40-
String datapackstr = datapack.toJSONString();
41-
HttpURLConnection serverFtch = (HttpURLConnection) new URL(prefix+this.domain+":"+this.port+"/ServerWebGamePost").openConnection();
42-
serverFtch.setRequestMethod("POST");
43-
serverFtch.setRequestProperty("User-Agent", this.userAgent);
44-
serverFtch.setRequestProperty("Content-Type", "application/json; utf-8");
45-
serverFtch.setDoOutput(true);
46-
try(OutputStream osftch = serverFtch.getOutputStream()){
47-
byte[] inputftch = datapackstr.getBytes("utf-8");
48-
osftch.write(inputftch, 0, inputftch.length);
49-
}catch(IOException e){
50-
System.err.println(e);
51-
}
52-
try(BufferedReader brftch = new BufferedReader(new InputStreamReader(serverFtch.getInputStream(), "utf-8"))){
53-
StringBuilder responseftch = new StringBuilder();
54-
String line;
55-
while((line = brftch.readLine()) != null){
56-
responseftch.append(line.trim());
57-
}
58-
this.processDatapacks.process(JSON.parseObject(responseftch.toString()));
59-
}catch(IOException e){
60-
System.err.println(e);
30+
31+
public void sendDataPacket(@NonNull JSONObject datapack) {
32+
try {
33+
String prefix = this.isHttps ? "https://" : "http://";
34+
String datapackstr = datapack.toJSONString();
35+
String url = prefix + this.domain + ":" + this.port + "/ServerWebGamePost";
36+
37+
Connection.Response response = Jsoup
38+
.connect(url)
39+
.userAgent(this.userAgent)
40+
.header("Content-Type", "application/json")
41+
.requestBody(datapackstr)
42+
.method(Connection.Method.POST)
43+
.ignoreContentType(true)
44+
.execute();
45+
46+
this.processDatapacks.process(JSON.parseObject(response.body()));
47+
} catch(Exception erd) {
48+
System.err.println(erd);
6149
}
62-
}catch(Exception erd){
63-
System.err.println(erd);
64-
}
6550
}
6651
}

php/Build.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
echo "Empaquetando PHAR...\n";
3+
$pharFile = "ServerWebGamePost-1.2.1.phar";
4+
$phar = new Phar($pharFile);
5+
$phar->setAlias("ServerWebGamePost-1.2.1.phar");
6+
$phar->buildFromDirectory(dirname(__FILE__) . '/ServerWebGamePost');
7+
if (Phar::canCompress(Phar::GZ)) {
8+
$phar->compressFiles(Phar::GZ);
9+
} elseif (Phar::canCompress(Phar::BZ2)) {
10+
$phar->compressFiles(Phar::BZ2);
11+
}
12+
$phar->setStub("<?php __HALT_COMPILER(); ?>");
13+
echo "Done!\n";
14+
?>
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
3+
final class Client {
4+
private $domain;
5+
private $port;
6+
private $isHttps;
7+
private $processDatapacksPriv;
8+
9+
public function __construct($domain, $port, $isHttps) {
10+
$this->domain = $domain;
11+
$this->port = $port;
12+
$this->isHttps = $isHttps;
13+
}
14+
15+
public function setProcessDatapacks(callable $callback) {
16+
$this->processDatapacksPriv = $callback;
17+
}
18+
19+
public function getProcessDatapacks() {
20+
return $this->processDatapacksPriv;
21+
}
22+
23+
public function sendDatapacket($datapack) {
24+
$prefix = $this->isHttps ? "https://" : "http://";
25+
$url = $prefix . $this->domain . ":" . $this->port . "/ServerWebGamePost";
26+
$jsonData = json_encode($datapack);
27+
28+
$ch = curl_init($url);
29+
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
30+
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData);
31+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
32+
curl_setopt($ch, CURLOPT_HTTPHEADER, [
33+
"Content-Type: application/json",
34+
"Content-Length: " . strlen($jsonData)
35+
]);
36+
37+
$response = curl_exec($ch);
38+
if ($response === false) {
39+
throw new Exception("cURL error: " . curl_error($ch));
40+
}
41+
curl_close($ch);
42+
43+
$decodedResponse = json_decode($response, true);
44+
if (is_array($decodedResponse)) {
45+
$this->processSubDatapacksPriv($decodedResponse);
46+
}
47+
}
48+
49+
private function processSubDatapacksPriv($datapacks) {
50+
if (isset($datapacks['datapacksLot']) && is_array($datapacks['datapacksLot'])) {
51+
foreach ($datapacks['datapacksLot'] as $data) {
52+
if (is_callable($this->processDatapacksPriv)) {
53+
call_user_func($this->processDatapacksPriv, $data);
54+
}
55+
}
56+
}
57+
}
58+
}
59+
?>

0 commit comments

Comments
 (0)