Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

How to: lsl for programmers of advanced languges (PHP, and C++)

Nynthan Folsom
Registered User
Join date: 29 Aug 2006
Posts: 70
12-05-2006 17:44
From: Script Su
This would raise the speed of casino scripts. They would no longer need to do all the memory intensive stuff and make the user wait 3 minutes. PHP is uber fast and it could easily do this. I still have no clue how to do any of this stuff from the lsl side but I dont have to. The point of it is for independent developers who make casinos to use it. It would aslo make it easier to track commissions for people who provide their casinos on an affiliate basis.
Oh, incidentally. llHTTPRequests are throttled to a rate of 20 per 100 seconds per owner per region. So if you have 20 ppl all make a bet at the same time. The next person would have to wait 100 seconds to make the next one. You might be able to sync llHTTPRequests to the SL wallclock to ensure that they only get called once every 5 seconds. That may make for an artificially sluggish feel to user interaction, but it would be better than having every 20th customer lag 100 seconds.
Script Su
Professional SOA Designer
Join date: 23 Aug 2006
Posts: 79
My first lsl related PHP script.....lol good first step
12-05-2006 19:46
What do you think about this script? It is a modified version of the orbit42 base class.

CODE
<?php
/**
* Copyright 2006, ADULLAM LIMITED.
*
* orbit_base - Easy edit class foundation for building extensible loose coupled systems.
*
* orbit_base class and methods.
*
* @author $Author: Matthew Brown $
* @version $Revision: 1.10 $
*
* @package orbit_base
*/

// parts of this class were inspired by NucleusCMS
//parts of this script modified for LSL by aceofspades
class orbit_lsl {

var $callback = array('class' => 'responder', 'function' => 'notify', 'instence'=>'instance');
// assumed pattern of data to pass =>= ($event, $data=array(), $debug_info="")
// also we assume this call back thing has a singleton "instance" function

// track out connection
var $db_conn = 'none'; //string for storing the connection object
var $db_used = 'none';

var $debug_on = true;
var $debug_level = 1;
/*
Debug levels

1: Basic Error Messages and Similar (BEMS)
2: As 1 good for class testing
3: As 2 but more so, good for class development
4: As 3 but really verbose includes a lot of core stuff
5: AS 4 but really really talkative
...increase if needed.
*/


// http://uk2.php.net/manual/en/function.get-parent-class.php
function get_ancestors ($class = '') {
if ($class == ''){
$class = $this;
}
$classes = array($class);
while($class = get_parent_class($class)) {
$classes[] = $class;
}
return $classes;
}

// this allows basic classes to set aside user functions
// and have those functions used by successive generations
// of class without tripping over each otehr.
function extender_call($func, $data=''){
foreach($this->get_ancestors($this) as $classname){
if(is_callable(array($this, $func.$classname))){
call_user_func(array(&$this, $func.$classname), $data);
}
}
}

function debug($out, $array="", $level = 1){
if (($this->debug_on === true) AND ($level <= $this->debug_level)) {
echo "<p>DEBUG ($level): ";
echo $out;
if ((is_array($array)) OR (is_object($array))){
echo "<pre>";
print_r($array);
echo "</pre>";
}
echo " -=ENDS=- </p>";
}
}

// this allows all objects to trigger events in any of it's aprents
// it also allows all children to call an event manager.
function callback($event, $data=array(), $debug_info=""){

$localvar = '';

// internal
$this->extender_call($event, $data);

// external

if (!class_exists($this->callback['class'])){
$this->debug("callback: callback class was not loaded. Loading...", '', 4); // core level debug
@include_once $this->callback['class'] . ".php";
}

if (class_exists($this->callback['class'])){
$evalcode = '$localvar = ' . $this->callback['class'] . '::' . $this->callback['instence'] . '();';
$this->debug("EVAL CODE: " . $evalcode, '', 5); // core level debug
eval($evalcode);
if(is_callable(array($localvar, $this->callback['function']))){
call_user_func(array(&$localvar, $this->callback['function']), $event, $data, $debug_info);
}
}else{
$this->debug("Error: could not find callback class '" . $callback['class'] ."'."); // gen debug
}
$this->debug("$event -> $debug_info", $localvar, 4); // deep debug
}


//function db_sql_return($data, &$obj = ''){
function db_sql_return($data, $obj = ''){
// this function must be written for your DB engine
$obj = mysql_query($data);
}
//function db_sql_return($data, &$obj = ''){
function db_sql_return2($obj = '', $settings = array()){
// this function must be written for your DB engine

$data = $_REQUEST['data'];
$obj = mysql_query($data);
If ($settings['echo'] != "")
{
If ($settings['echo'] != "false")
{
echo $obj;
}
}
}


function db_sql_return_array($data, $arr = array(), $formof = 'assoc'){
// this function must be written for your DB engine
$this->db_sql_return($data, $obj);
if(mysql_num_rows($obj) > 0){
if ($formof == "assoc"){
while($arr[] = mysql_fetch_assoc($obj)){}
}else{
while($arr[] = mysql_fetch_row($obj)){}
}
}
return $arr;
}

// currently we have a connection for every object how do I recycle?
function db_connect(){
// this function must be written for your DB engine
if ($this->db_conn == 'none'){
$this->db_conn = mysql_connect('localhost', 'username', 'password');
if (!$this->db_conn) {
die('Could not connect: ' . mysql_error());
}
}
if ($this->db_used == 'none'){
$this->db_used = mysql_select_db('database', $this->db_conn);
}
// mysql_close($link);
}
function db_connect2(){
// this function must be written for your DB engine
/*
if ($_REQUEST['host'] == "localhost")
{
die("we do not allow connection to local host");
}
*/
if ($this->db_conn == 'none'){
$this->db_conn = mysql_connect($_REQUEST['host'], $_REQUEST['user'], $_REQUEST['pass']);
if (!$this->db_conn) {
die('Could not connect: ' . mysql_error());
}
}
if ($this->db_used == 'none'){
$this->db_used = mysql_select_db($_REQUEST['db'], $this->db_conn);
}
// mysql_close($link);
}


function db_disconnect(){
mysql_close($this->db_conn);
$this->db_conn = 'none';
$this->db_used = 'none';
}

}

?>


It has two modified functions. These two take request variables instead of passed variables. I just have to figure out how to pass more lsl friendly stuff. Tell me if i did anythin wrong. Also one tip, NEVER use <? ?> it is not XHTML compatible and can cause an error when interacting with XML files. always use <?php ?> becuase that is a proper PI.

Btw thanks for the vars i already put it in an include file besides the guy who posted about how to use llHTTPRequest

OMG that was probly the most helpful post so far.

By incrypted i didnt mean the connection (although that is great thx). I meant i have to obsugate the code if im going to distribute it (aka sell it). I already have a fellow bluehoster who has really good software (and affordable) for PHP encyption. Or i might just use a simple obstugator that turns the code into a confusing unreadable mess.
-----
I have something coming I won't tell you what but all I will give you is two letters, S&F.

If you can guess correctly I will give you a cookie


Script Su
Professional SOA Designer
Join date: 23 Aug 2006
Posts: 79
New Update
12-05-2006 22:01
Ok new update. I just finished it is their anything wrong with this.

First person to write an lsl script to interface with it gets a cookie.

I just cant help but be without OOP ^_^.

Here it is

Alright my first rest service. Test it with your server. I tested it with mine!
Script Su
Professional SOA Designer
Join date: 23 Aug 2006
Posts: 79
12-06-2006 06:12
Great it didnt work. Wat did I do wrong????
Nynthan Folsom
Registered User
Join date: 29 Aug 2006
Posts: 70
12-06-2006 06:23
From: Script Su
Also one tip, NEVER use <? ?> it is not XHTML compatible and can cause an error when interacting with XML files. always use <?php ?> becuase that is a proper PI.
Bah, XML. Don't care. Don't like <?php ?>. Period.
Script Su
Professional SOA Designer
Join date: 23 Aug 2006
Posts: 79
12-06-2006 06:31
it really doesnt matter. But if you ever handle or parse XML you need to use <?php because it will cause terrible bugs.


Just do a find and replace in notepad++ or whatever u use (i like eclipse)
Mintopia Ambassador
Registered User
Join date: 18 Mar 2005
Posts: 4
12-06-2006 12:38
From: Nynthan Folsom
/me drops to the floor, shaking and frothing at the mouth. Java, my cryptonite.


Eclipse is a good IDE that can be used for many languages. For example, I use it for Python. However, the Java language is horrible and should die in a very deep hole.

From: Nynthan Folsom
NEVAH! <? if(strlen("?php";) > strlen("?";)) { carpal_tunnel >>= 1; } ?>


http://uk.php.net/manual/en/language.basic-syntax.php says BAD!

From: Nynthan Folsom
Maybe because get variables are displayed on the address bar for all to see? There are other significant differences between GET and POST:
http://www.w3.org/2001/tag/doc/whenToUseGet.html#uris


All well and good in a traditional web server environment, admittedly using POST disguises the mechanics to the end user. HOWEVER, This isn't a traditional environment. The server at Linden Labs is making the request and it doesn't care what the URI looks like :). Thus, in this situation, POST is no more secure than GET.
Masakazu Kojima
ケロ
Join date: 23 Apr 2004
Posts: 232
12-06-2006 14:16
From: Nynthan Folsom
llHTTPRequests are throttled to a rate of 20 per 100 seconds per owner per region.
The throttle was relaxed to 10 requests per 10 seconds per prim in 1.12.1.
Nynthan Folsom
Registered User
Join date: 29 Aug 2006
Posts: 70
12-06-2006 14:27
From: Masakazu Kojima
The throttle was relaxed to 10 requests per 10 seconds per prim in 1.12.1.
Ah. Good to know! Thanks.
Script Su
Professional SOA Designer
Join date: 23 Aug 2006
Posts: 79
12-06-2006 14:37
ah sweet that means 1 per second. That is still faster than lsl scripts.
_____________________
The LSL Repository @ sf.net. The LSL Repository is dedicated to bring open source lsl programmers together and develop the best service oriented scripts. Gridworks gives you the whole package. We also have in-house builders, scripters, web programmers, and salesmen. Premium Account||Age Verified||Gridworks Executive
Boris Oconner
Registered User
Join date: 21 Jul 2006
Posts: 16
12-06-2006 18:52
a = a programmer who is having trouble programming in LSL
b = an advanced programmer
a != b
Script Su
Professional SOA Designer
Join date: 23 Aug 2006
Posts: 79
LOL ill make a service next time
12-06-2006 19:40
From: someone
a = a programmer who is having trouble programming in LSL
b = an advanced programmer
a != b

my reply
CODE
 <?php

class lol {
protected $orbit_local = new orbit_lsl;
var $host;
var $user;
var $pass;
var $db;
var $avatar;

function __contruct($host,$user,$pass,$db,$avatar) {
include("orbit.lsl.class.php");
$this->avatar = $avatar;
$this->orbit_local = new orbit_lsl;
$this->host = $host;
$this->user = $user;
$this->pass = $pass;
$this->pass = $db;
$this->orbit_local->db_connect($this->host,$this->user,$this->pass,$this->db);
$this->connect();

}
function simple_dis() {
$data = "SELECT * FROM lol WHERE avatar=" . $this->avatar . "";
$this->orbit_local->db_sql_return($data, $obj);
$smarty->assign('say',$obj);
$smarty->display('diss.tpl');
}
} ?>

Index.php
CODE

<?php
define('SMARTY_DIR','./libs');
define('INCLUDE_DIR','./includes');
include(SMARTY_DIR.'Smarty.class.php');
$smarty = new smarty;
include(INCLUDE_DIR.'lol.class.php');
$host = "localhost";
$user = "someone";
$pass = "somepass";
$db = "thrtmwon_stupid_comments";
$lol = new lol($host,$user,$pass,$db);
?>



Output
CODE

<strong>Please Reconsider ur comment </strong>


edit:

What are you talking about i never said that >.>

LOL sorry. Changed it.
_____________________
The LSL Repository @ sf.net. The LSL Repository is dedicated to bring open source lsl programmers together and develop the best service oriented scripts. Gridworks gives you the whole package. We also have in-house builders, scripters, web programmers, and salesmen. Premium Account||Age Verified||Gridworks Executive
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
12-06-2006 20:47
We keep it freindly in this forum and PG. More then a little heavy reply to a light hearted comment. "STFU Noob" and "retard". Not nice.
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime.
From: someone
I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
12-07-2006 02:06
Funny I thought this was an LSL forum not PHP?
Boris Oconner
Registered User
Join date: 21 Jul 2006
Posts: 16
12-07-2006 13:39
if (my_3_lines_of_pseudo_code >= your_50_Lines_of_pointless_code) {
me.pwned.add(you);
}
Script Su
Professional SOA Designer
Join date: 23 Aug 2006
Posts: 79
12-07-2006 19:25
Where is your uber advanced mysql abstration layer, OOP, reusability, smarty templating engine, and dual layer objects. ^_^

You guys just don't get it. It isn't only about just doing it, it is about doing it in an efficient, reusable, and encapsulated manner.
_____________________
The LSL Repository @ sf.net. The LSL Repository is dedicated to bring open source lsl programmers together and develop the best service oriented scripts. Gridworks gives you the whole package. We also have in-house builders, scripters, web programmers, and salesmen. Premium Account||Age Verified||Gridworks Executive
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
12-07-2006 20:53
From: Script Su
Where is your uber advanced mysql abstration layer, OOP, reusability, smarty templating engine, and dual layer objects. ^_^

You guys just don't get it. It isn't only about just doing it, it is about doing it in an efficient, reusable, and encapsulated manner.

Well that's the thing. The efficiency and encapsulated part. It's not just the script memory limits that have to be taken into account but sim resources also. I have seen some wonderful creations that were done through the server to an outside server doing all the hardwork. BUT OMG they were seriously laggy too at .2-.4 ms, which is very, very bad. Anything around .1 ms script time is considered laggy and I try to set my benchmark much lower. Not saying that going out of world is always that bad, but it is one more thing to be considered.

BTW Boris, actually he beat you hands down. I saw his posting before he editted it to keep it PG and his 50 lines weren't pointless ;-)

EDIT forgot decimal points
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime.
From: someone
I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
Script Su
Professional SOA Designer
Join date: 23 Aug 2006
Posts: 79
12-07-2006 21:24
From: Jesse Barnett
Well that's the thing. The efficiency and encapsulated part. It's not just the script memory limits that have to be taken into account but sim resources also. I have seen some wonderful creations that were done through the server to an outside server doing all the hardwork. BUT OMG they were seriously laggy too at .2-.4 ms, which is very, very bad. Anything around .1 ms script time is considered laggy and I try to set my benchmark much lower. Not saying that going out of world is always that bad, but it is one more thing to be considered.

BTW Boris, actually he beat you hands down. I saw his posting before he editted it to keep it PG and his 50 lines weren't pointless ;-)

EDIT forgot decimal points


LOL Thanks

I have one question which is faster, RPC or HTTP-POST? How would it take the sims resources? Isnt that the entire point of outsourcing.

I am still trying to figure out how to use RPC and I always just prefer a good old fashioned piped list. When it comes to simple servicess and ajax piped lists usually work better.

Anyways I have still been playing with a few things and I have learned a lot from programming on sourceforge. Like that orbit class is actually a project that an admin from Open Educate CMS made. I also learned Smarty just so I could make this project becuase a lot of uber cool CMSs use Smarty (such as tikiwiki).

Anyways PHP seems to e the best languge for interfacing with LSL because it is so bloody simple. I am still working on a few thing and me and Nathan are working on a cool, innovative project.
_____________________
The LSL Repository @ sf.net. The LSL Repository is dedicated to bring open source lsl programmers together and develop the best service oriented scripts. Gridworks gives you the whole package. We also have in-house builders, scripters, web programmers, and salesmen. Premium Account||Age Verified||Gridworks Executive
Eloise Pasteur
Curious Individual
Join date: 14 Jul 2004
Posts: 1,952
12-08-2006 01:57
From: Script Su
LOL Thanks

I have one question which is faster, RPC or HTTP-POST? How would it take the sims resources? Isnt that the entire point of outsourcing.


At the moment this question is kind of irrelevant, because they fire in opposite directions. RPC fires requests from outside in, llHTTPRequest fires requests from inside out.

You must open your RPC channel inside SL, but it can't initiate communication, only reply.
_____________________
Eloise's MiniMall
Visit Eloise's Minimall
New, smaller footprint, same great materials.

Check out the new blog
Script Su
Professional SOA Designer
Join date: 23 Aug 2006
Posts: 79
Thanks
12-08-2006 06:15
From: Eloise Pasteur
At the moment this question is kind of irrelevant, because they fire in opposite directions. RPC fires requests from outside in, llHTTPRequest fires requests from inside out.

You must open your RPC channel inside SL, but it can't initiate communication, only reply.


Therefore HTTP is the same as RPC without the complexity. Because right now the only way to give sl a message is for the client to check the server. If I use RPC I would have the cpu inteniveness of RPC and the in weaknesses of HTTP which is that it isnt very good for responding. So i guess ill stick with HTTP. I had thought that there was a way for a server to send an object a request.

Thanks a lot. I have spent so much time trying to figure out HTTP because of this.
_____________________
The LSL Repository @ sf.net. The LSL Repository is dedicated to bring open source lsl programmers together and develop the best service oriented scripts. Gridworks gives you the whole package. We also have in-house builders, scripters, web programmers, and salesmen. Premium Account||Age Verified||Gridworks Executive
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
12-08-2006 06:35
From: Script Su
LOL Thanks

I have one question which is faster, RPC or HTTP-POST? How would it take the sims resources? Isnt that the entire point of outsourcing.

I am still trying to figure out how to use RPC and I always just prefer a good old fashioned piped list. When it comes to simple servicess and ajax piped lists usually work better.

Anyways I have still been playing with a few things and I have learned a lot from programming on sourceforge. Like that orbit class is actually a project that an admin from Open Educate CMS made. I also learned Smarty just so I could make this project becuase a lot of uber cool CMSs use Smarty (such as tikiwiki).

Anyways PHP seems to e the best languge for interfacing with LSL because it is so bloody simple. I am still working on a few thing and me and Nathan are working on a cool, innovative project.


It would be very interesting to see a heads up comparison between two scripts. One done totally in LSL and the other outsourced. With the laggy ones I saw it may have been a simple matter of there was absolutely no way to do it in any fashion quickly.

There is a group who should have more information. Our reputation has been muddied recently but the majority of us care for and help SL. We have had a flood of new programmers join now after all of the bad press. Get on EFNET on irc and join channel #libsl. Plenty of people there to talk to all day. I am in the minority there. All I know is LSL and am just now learning a little C#. libsl uses C#, NUnit & MySQL but most are knowledegable in several languages. A good program to see the potential is SLEEK. You can either download an exe or the source files and compile it yourself. With it you can log into SL, chat with freinds, IM, teleport and some more, you just don't have sight. BUT you can do all of that with a program that is only 100 KB.
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime.
From: someone
I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
Script Su
Professional SOA Designer
Join date: 23 Aug 2006
Posts: 79
12-08-2006 07:33
From: Jesse Barnett
It would be very interesting to see a heads up comparison between two scripts. One done totally in LSL and the other outsourced. With the laggy ones I saw it may have been a simple matter of there was absolutely no way to do it in any fashion quickly.

There is a group who should have more information. Our reputation has been muddied recently but the majority of us care for and help SL. We have had a flood of new programmers join now after all of the bad press. Get on EFNET on irc and join channel #libsl. Plenty of people there to talk to all day. I am in the minority there. All I know is LSL and am just now learning a little C#. libsl uses C#, NUnit & MySQL but most are knowledegable in several languages. A good program to see the potential is SLEEK. You can either download an exe or the source files and compile it yourself. With it you can log into SL, chat with freinds, IM, teleport and some more, you just don't have sight. BUT you can do all of that with a program that is only 100 KB.


C# is supposed to be good but I am used to PHP, I cant use .Net languges (shared host), and it is made by microsoft and I dont do any properitary languges (except lsl). Only open source for me. That sleek thing sounds pretty cool. I cant use IRC on this network anyways.
_____________________
The LSL Repository @ sf.net. The LSL Repository is dedicated to bring open source lsl programmers together and develop the best service oriented scripts. Gridworks gives you the whole package. We also have in-house builders, scripters, web programmers, and salesmen. Premium Account||Age Verified||Gridworks Executive
Boris Oconner
Registered User
Join date: 21 Jul 2006
Posts: 16
12-08-2006 13:52
From: Jesse Barnett
BTW Boris, actually he beat you hands down. I saw his posting before he editted it to keep it PG and his 50 lines weren't pointless ;-)


Jesse - for that you are going on my pwned list:

me.pwned.add(jesse);

me.pwned.print =

script su
jesse
Learjeff Innis
musician & coder
Join date: 27 Nov 2006
Posts: 817
12-08-2006 14:05
From: Script Su
It isn't only about just doing it, it is about doing it in an efficient, reusable, and encapsulated manner.

Right -- the closest you come to that in LSL is writing a script to embody a behavior and dropping that script into an object.

Love LSL for what it is, and try not to hate it for what it isn't.

And please don't feed the trolls. ;)
Script Su
Professional SOA Designer
Join date: 23 Aug 2006
Posts: 79
12-08-2006 14:17
i never said you cant do that in lsl >.<. I was generalizing. Anyways I like lsl. It is simple to the point and as EXACTLY like javascript. People keep saying that it isnt but the way it handles the variables, the enviorment which it runs, the "alax" if you will. It really is nice.
From: someone
Right -- the closest you come to that in LSL is writing a script to embody a behavior and dropping that script into an object.

Love LSL for what it is, and try not to hate it for what it isn't.

And please don't feed the trolls. ;)
_____________________
The LSL Repository @ sf.net. The LSL Repository is dedicated to bring open source lsl programmers together and develop the best service oriented scripts. Gridworks gives you the whole package. We also have in-house builders, scripters, web programmers, and salesmen. Premium Account||Age Verified||Gridworks Executive
1 2