Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


  Show Posts
Pages: 1 [2] 3
16  Scripting / Script Releases / Re: [REL]PHP/Web SDK - Interact with your LU server through PHP! on: November 20, 2016, 09:45:14 pm
Updated and uploaded to GitHub. The script now includes functions to make requests from your LU server to your website, and I have made it more flexible.

Feel free to contribute!

https://github.com/Rhytz/LU-WebSDK
17  Off Topic / General Chat / Re: Bye To all My Friends And Foe ! on: November 20, 2016, 02:05:33 pm
I wonder who that single foe is
18  Liberty Unleashed / Suggestions / Re: [Request] onWheelShot( player, oldWheelHealth, newWheelHealth, damage) on: November 16, 2016, 09:30:17 pm
Updated the wiki regarding onClientVehicleShot
19  Scripting / Script Help / Re: CreateVehicle on: November 16, 2016, 05:54:08 pm
I've tested your code and it works just fine. Maybe some other script is causing trouble in combination with this one?
20  Scripting / Script Snippets / Re: Squirrel functions for encoding GET/POST data on: November 16, 2016, 12:35:16 am
To separate the HTTP header from the data returned by your webserver, you can do something like this:

Code: [Select]

function ReceiveData( socket, data ){
local newline = data.find("\r\n\r\n");
local header = data.slice(0, newline);
local content = data.slice(newline + 4, data.len());
print(content);
}
21  Scripting / Script Snippets / Squirrel functions for encoding/decoding JSON on: November 16, 2016, 12:14:09 am
These functions, which are also included with my PHP/Web SDK allow you to encode Squirrel tables/arrays into JSON, and vice versa.

Code: [Select]
/*
PHP SDK server for Liberty Unleashed, by Rhytz
json_functions.nut - Contains custom JSON encoding and decoding functions
(c) 2016
*/


/*
json_encode( table/array )

Takes a table/array and encodes it into JSON
*/
function json_encode( table ){
if(typeof(table) == "table" || typeof(table)  == "array"){
json <-  "{";
json_recurse( table );
json += "}";
return json;
}else{
return false;
}
}

/*
json_recurse( table/array )

Recursive function that loops through all layers of a table/array and encodes it.
Used by json_encode().
*/
function json_recurse( table ){
local len = table.len();
local i = 1;
local typ = typeof(table);

//Loop through all keys in the supplied table
foreach (key, value in table) {
//Switch datatype of 'value' for appropriate handling
switch (typeof(value)){
//If the datatype is another array or table, run the function again
case "array":
json += "\"" + key + "\": [";
json_recurse( value );
json += "]";
break;

case "table":
json += "\"" + key + "\": {";
json_recurse( value );
json += "}";
break;

//Handling of other datatypes
case "bool":
local boolvalue = value ? "true" : "false";
//Depending on whether the current current 'table' is an array or table, change markup.
typ == "array" ? json += boolvalue : json += "\"" + key + "\": " + boolvalue;
break;

case "integer":
typ == "array" ? json += value : json += "\"" + key + "\": " + value;
break;

case "float":
typ == "array" ? json += value : json += "\"" + key + "\": " + value;
break;

case "null":
typ == "array" ? json += "null" : json += "\"" + key + "\": " + "null";
break;

case "string":
typ == "array" ? json += "\"" + json_escape(value) + "\"" : json += "\"" + key + "\":\"" + json_escape(value) + "\"";
break;

//Return false if the datatype is unsupported
default:
typ == "array" ? json += "false" : json += "\"" + key + "\": " + "false";
break;
}

//Append a comma at the end if it isn't the last item in the current table/array
if(i < len){
json += ",";
}
i++;
}
}

/*
json_escape( unescaped string )

Puts a backslash in front of any double quotes in the input string.
*/
function json_escape( string ){

//Split the input string on any double quotes
local breaks = split( string, "\"" );
local outputstring = "";

foreach (key, value in breaks) {
if(key > 0){
//Append backslash
outputstring += "\\\"" + value;
}else{
outputstring += value;
}
}

return outputstring;
}

/*
json_decode( JSON string )

Squirrel supports JSON syntax to create tables.
This function compiles the input string to Squirrel code.
Use with EXTREME caution and properly filter any user input, because it will also compile and execute any unescaped malicious code within the string.
*/
function json_decode( string ){
string = strip( string );
local json = ::compilestring("return " + string);
return json();
}
22  Scripting / Script Snippets / Squirrel functions for encoding GET/POST data on: November 16, 2016, 12:09:19 am
My PHP/Web SDK allows you do query your server from your website. But querying your website from your LU server in real time was not yet possible. Until now!

I've written some new functions that allow you to encode Squirrel strings and tables into "GET/POST" data which your webserver can understand.

postdata_encode( table ) - Converts a Squirrel table or array to a POST-able string
urlencode( string ) - Percent-encodes reserved URI characters in given string, and returns encoded string

Sample code:

Code: [Select]
function onScriptLoad(){



dofile( "Scripts/Rhytz/phpsdk/encode_functions.nut" );

SendSocket <- NewSocket( "ReceiveData" );

SendSocket.Connect("192.168.2.243", 2037 );

//SetLostConnFunc doesn't seem to work properly now, if SetNewConnFunc is set as well. Switching them around makes only SetLostConnFunc work and vice versa.
//SendSocket.SetLostConnFunc( "Failure" );
SendSocket.SetNewConnFunc( "Connected" );

}

function Connected( socket ){
local ServerData = {
GamemodeName = GetGamemodeName(),
MapName = GetMapName(),
ServerName = GetServerName(),
MaxPlayers = GetMaxPlayers(),
Players = GetPlayers(),
Password = GetPassword(),
Port = GetPort(),
AnArray = ["test1", "test2", "test3", ["arraywithinarray1","arraywithinarray2","arraywithinarray3"]],
MTUSize = GetMTUSize(),
falsevalue = false,
nullvalue = null
}
local data = postdata_encode(ServerData);
local path = "/rhytz/lu2.class.php";

    SendSocket.Send("POST " + path + " HTTP/1.0\r\n");
    SendSocket.Send("Content-Length: " + data.len() + "\r\n");
SendSocket.Send("Content-Type: application/x-www-form-urlencoded\r\n");
SendSocket.Send("\r\n");
SendSocket.Send(data);
}

function ReceiveData( socket, data ){
print(data); //Handle the returned webserver data here
}

The scripting functions:

Code: [Select]
/*
PHP SDK server for Liberty Unleashed, by Rhytz
encode_functions.nut - Contains custom URL encoding functions
(c) 2016
*/

/*
postdata_encode( table )

Converts a Squirrel table or array to POST-able data
*/
function postdata_encode( table ) {
if(typeof(table) == "table" || typeof(table)  == "array"){
postdata <-  "";
keyname <- "";
postdata_recurse( table );

return postdata;
}else{
return false;
}
}

/*
postdata_recurse( table )

Recursive function that loops through the table/array and encodes it.
Complementary function to postdata_encode().
*/
function postdata_recurse( table, depth = 0 ) {
local len = table.len();
local i = 1;
local typ = typeof(table);
//Loop through all keys in the supplied table
foreach (key, value in table) {
//Switch datatype of 'value' for appropriate handling
switch (typeof(value)){
//If the datatype is another array or table, run the function again
case "array":
case "table":
depth == 0 ? keyname  = key : keyname += "[" + key + "]";
postdata_recurse( value , depth + 1);
break;

//Handling of other datatypes
case "bool":
local boolvalue = value ? "true" : "false";
depth == 0 ? postdata += key + "=" + boolvalue : postdata += keyname + "[" + key + "]=" + boolvalue;
break;

case "integer":
case "float":
depth == 0 ? postdata += key + "=" + value : postdata += keyname + "[" + key + "]=" + value;
break;

case "null":
depth == 0 ? postdata += key + "=0"  : postdata += keyname + "[" + key + "]=0";
break;

case "string":
depth == 0 ? postdata += key + "=" + urlencode(value) : postdata += keyname + "[" + key + "]=" + urlencode(value);
break;

//Return false if the datatype is unsupported
default:
depth == 0 ? postdata += key + "=false" : postdata += keyname + "[" + key + "]=false";
break;
}

//Append a ampersand at the end if this isnt the last item in the table
if(i < len){
postdata += "&";
}

i++;
}
}


/*
urlencode( string )

Percent-encodes reserved URI characters in given string, and returns encoded string
*/
function urlencode( string ) {
local out = "";
for(local i=0; i<string.len(); i++){
local c = string.slice(i, i+1);
switch(c){
case " ":
out += "%20";
break;
case "!":
out += "%21";
break;
case "#":
out += "%23";
break;
case "$":
out += "%24";
break;
case "&":
out += "%26";
break;
case "'":
out += "%27";
break;
case "(":
out += "%28";
break;
case ")":
out += "%29";
break;
case "*":
out += "%2A";
break;
case "+":
out += "%2B";
break;
case ",":
out += "%2C";
break;
case "/":
out += "%2F";
break;
case ":":
out += "%3A";
break;
case ";":
out += "%3B";
break;
case "=":
out += "%3D";
break;
case "?":
out += "%3F";
break;
case "@":
out += "%40";
break;
case "[":
out += "%5B";
break;
case "]":
out += "%5D";
break;
default:
out += c;
break;
}
}
return out;
}

You can now access the $_POST parameter in your PHP script and handle the data.
23  Liberty Unleashed / Suggestions / Re: [Request] onWheelShot( player, oldWheelHealth, newWheelHealth, damage) on: November 14, 2016, 07:11:28 pm
Well, there is an undocumented onClientVehicleShot...

I've tried using it but it appears never to get called, just like onClientVehicleDamage.

But onClientVehicleShot could include a parameter indicating which part of the car was shot
24  Scripting / Script Releases / Re: [REL]PHP/Web SDK 0.1 - Interact with your LU server through PHP! on: November 14, 2016, 01:03:29 pm
I've made some small changes.

  • Cleaned up some code in the JSON functions
  • Commented out the socket timeout function (because SetLostConnFunc doesnt work, and there is no way to tell if the socket was already disconnected before the timeout function runs)
  • Fixed the sample Cash() function which didn't work when a ID of 0 was supplied

For better compatibility it might be better to use fsockopen instead of socket_create in the PHP class.
25  Scripting / Script Releases / [REL]PHP/Web SDK 0.1 - Interact with your LU server through PHP! on: November 12, 2016, 03:58:42 pm
Hi guys,

The past few days I have been working on a solid way to make my LU server "talk" to my website in real time, to allow for all kinds of fun web based scripts that interact with the server.

Just think of the possibilities. You could for example:
  • Sync the login system of your server to your (WordPress?) website and vice versa
  • Create a web-based shop to buy items ingame
  • Create a web-based admin panel
  • Make a web-based map editor
  • Show a real-time map of player positions on your website
  • Show detailed realtime statistics on your website
So on and so forth...

The SDK is a simple PHP class and Squirrel script in which I have already tackled the major issues and brainteasers. I have added some sample functions to give you an idea how to use it. But it is up to you to extend the script and class, and work out your own awesome ideas.


GitHub




PHP code samples
Connecting to the server
Code: [Select]
$server = new LU("123.123.123.123", 2302, "SecureKey123");
Setting the weather ingame
Code: [Select]
$server->SetWeather(2); //Sets rainy weather
Getting details about the server
Code: [Select]
$server->ServerInfo();
Will return:
Code: [Select]
stdClass Object
(
    [MTUSize] => 576
    [MapName] => Liberty City
    [Players] => 0
    [GamemodeName] => Deathmatch
    [Port] => 2301
    [MaxPlayers] => 128
    [Password] => thepassword
    [ServerName] => Rhytz's Scripting test server
)





Setting it up

Note that some knowledge of Squirrel and PHP would be very useful...

1. Download the Squirrel script and PHP Class

2.Copy the Rhytz folder in the zip file to your Scripts folder, and edit LU/content.xml.  Include a reference to the script at the bottom of this file, like so:
Code: [Select]
<script folder="Rhytz" />
3. Open Scripts/Rhytz/server.nut and edit the following constants to your needs:

Code: [Select]
//Replace SecureKey123 with a custom hash/password to prevent others from accessing your server
const SECURE_KEY = "SecureKey123";

//Replace with the IP of your webserver
const SECURE_IP = "123.123.123.123";

//On what port should the server listen to requests from your PHP script?
const LISTEN_PORT = 2302;

//Path to the script files
const FILE_PATH = "Scripts/Rhytz/phpsdk/";

4. Be sure LISTEN_PORT is open and accepts incoming TCP traffic. It also needs to be open for outgoing traffic on your webhost, which is not always the case. You may need to contact your webhosting provider about this.

5. Copy lu.class.php to your webhosting wherever you want to use it.

6. Include the class in your PHP script. Do something like this:
Code: [Select]
require_once("lu.class.php");
7. Create a new instance of the LU class in your PHP script, like so:
Code: [Select]
$server = new LU("123.123.123.123", 2302, "SecureKey"); You obviously replace the IP with the IP of your LU server, and the Port and securekey with the values you have set up in step 3.

8. Interact with your server! If you did everything correctly, you should now be able to communicate with your server through your php script. To test your success, you could do something like this:
Code: [Select]
$serverinfo = $server->ServerInfo();
echo "<pre>";
print_r($serverinfo);
echo "</pre>";
This code should return an object with all the details about your server.







Built-in functions

Although it is up to you to extend the class to your needs, I have created some necessary and sample functions.

CallFunc - Calls a function in another Squirrel script file. Makes a call to CallFunc on your server.
Code: [Select]
CallFunc( scriptPath, funcName, array( Params ))
Sample usage:
Code: [Select]
$server->CallFunc("Scripts/Rhytz/phpsdk/remotefunc.nut", "thisIsARemoteFunc", array($param1, $param2))
CallClientFunc - Similar to CallFunc, but allows you to call a function on in a clientside script, for a specific client. Makes a call to CallClientFunc on your server.
Code: [Select]
CallClientFunc(playerID, scriptPath, funcName, array( Params ))
Sample usage:
Code: [Select]
$server->CallClientFunc($playerID, "Scripts/Rhytz/phpsdk/remotefunc.nut", "thisIsARemoteFunc", array($param1, $param2))
ServerInfo - Returns an object with details about the LU server.

Sample usage:
Code: [Select]
$serverinfo = $server->ServerInfo();
echo $serverinfo->MapName; //Returns the current map name
 

CurrentPlayers - Returns an object with player ID's and names of players currently in the server.

Sample usage:
Code: [Select]
$server->CurrentPlayers();

GetWeather/SetWeather - Gets or sets the current weather.

Sample usage:
Code: [Select]
$weatherIDs = array(
0 => "Sunny",
1 => "Cloudy",
2 => "Rainy",
3 => "Foggy"
);

$server->SetWeather(2);

echo "The weather in Rhytz's server is currently: ". $weatherIDs[$server->GetWeather()->WeatherID]; //Returns "Rainy"


Cash - Gets player Cash, or sets it when a value parameter is supplied.

Sample usage:

Code: [Select]
echo $server->Cash(1); //Returns the amount of cash of player with ID 1

foreach($server->CurrentPlayers() as $id => $name){
     $server->Cash($id, 1000); //Sets the cash of all players in the server to 1000
}


Notes
  • This will probably the first and last release of this script, unless it has some major problems. It is up to you to extend it to your needs.
  • I use PHP, but the script could easily be ported to other programming languages. The communication between the servers consists of packets containing JSON.
  • You may freely use this script, but some credit would be nice!
26  Off Topic / Spam / Re: Libert Unleashed Biggest spammer on: January 12, 2008, 10:58:39 pm
if there IS a porn forum, let me in please  ;D
27  Off Topic / Spam / Re: GTA3 MTA Mega site OMG on: January 12, 2008, 10:55:15 pm
Quote
GTA3 MTA Mega site OMG

 WITH 800 UNIQUE VISITORS!
28  Liberty Unleashed / Suggestions / Re: Steam compatibility. on: January 12, 2008, 10:53:48 pm
seems that the GTA:San Andreas version is working fine with mods
29  Liberty Unleashed / Liberty Unleashed Chat / Re: lol pretty funny story on: January 12, 2008, 10:52:24 pm
ye got own3d ;)
30  Archive / Archived Items / Re: Latest News on: January 12, 2008, 10:51:16 pm
I just have one question. When is the LU realesed? I can't wait for it too be. I have seen soo many movies about it. Then I register too Liberty-unleashed.co.uk and what? Liberty Unleashed 20%??? When :( ?? Btw I love the idea

i dont think the release date is known. a release date cant be set, because bugs will always be found at the last moment.
Pages: 1 [2] 3
© Liberty Unleashed Team.