Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Using a webserver with SLS?

Sollie Villota
Registered User
Join date: 22 Jun 2007
Posts: 46
08-18-2007 14:16
I am interested in writing up a script for my HUD that will send kill/death data about each player in my sim and will store a leader board about each player. I am wondering what exactly would I require to do this? I figured it was possible so I decided to throw my question out.
Chaz Longstaff
Registered User
Join date: 11 Oct 2006
Posts: 685
08-18-2007 14:29
I think the first point to consider is not a technical one but a strategic one -- how long a commitment are you willing to make to keep the webserver end up and running so the feature remains a viable one? I mean, if you sell someone, say, a poofer in SL, they can keep on using it if you get hit by a car in RL, or long after you have lost interest in SL and moved onto Third L or whatever. But with anything dependent on an external resource that must be maintained, it's a different story. I know, boring old-fashioned consideration -- thinking longer term.
Sollie Villota
Registered User
Join date: 22 Jun 2007
Posts: 46
08-18-2007 14:36
I understand what you are saying. My commitment with SL is to be sure a LONG one, and judging by how you are putting this, setting up a webserver and script for something like this would probably take a while then? Also, back to my first question: What would it require? I'd like to see either a checklist or a list of thigns that I need. I have lots of resources, and time is plentiful...
Osgeld Barmy
Registered User
Join date: 22 Mar 2005
Posts: 3,336
08-18-2007 16:16
1 a webserver that does not force ad's or any other bits of information onto your pages

2 a server side scripting language such as php asp ruby ect

you will probably want a database but you could also accomplish this using text files (which is kinda cheap and really not all that secure)
Sollie Villota
Registered User
Join date: 22 Jun 2007
Posts: 46
08-18-2007 16:34
Awesome. I can do that then, I just gotta learn more, thanks very much. Any tutorials or free scripts that maybe show exactly how its done or something i could at least base my scripts off of?
Osgeld Barmy
Registered User
Join date: 22 Mar 2005
Posts: 3,336
08-18-2007 19:27
heres a simple "flat file" (stuff written in a text file on my server) guest book

in the lsl side of things its pretty simple
From: someone

string url = "http://cheesefactory.us/searchdata.php?search=";
string current_av = "";

end() // end routine - user defined function
{
current_av = "";
llSetTimerEvent(0);
}

default
{
touch_start(integer total_number)
{
if (current_av == "";)
{
current_av = llDetectedName(0);
llSetTimerEvent(10);
// send data to the webpage
llHTTPRequest(url + current_av,[HTTP_METHOD,"GET"],"";);
}
}
// get data back and process it
http_response(key request_id, integer status, list metadata, string body)
{
if (body == "Error: Cannot open file.";)
{
llOwnerSay(body + " please check your webserver and logfile";);
}

else if (body == "on list";)
{
llSay(0,"You are already in the guestbook " + current_av);
}

else if (body == "new user added";)
{
llSay(0,"Thank you signing my guestbook " + current_av);
}

end();
}

timer()
{
llSay(0,"server timeout, please try again in a moment";);
end();
}
}


on the webserver ive got ... (in php)

From: someone

<?php
$filename = "userlog.dta";
$search = $_GET["search"];
$user_data = file($filename);

// trim whitespace from the strings
for($x = 0; $x < count($user_data); $x++)
{
$user_data[$x] = trim($user_data[$x]);
}
// see if its in the file
$on_list = array_search($search,$user_data);

if ($on_list != "";)
{
echo "on list";
}
// if its not write the name in the file
else
{
$fp = fopen($filename,"a";);

// if your server cannot access the file error
// almomst any php server can make a file if one does not exist
// even if your server will not create a file for you
// you can place an empty file for the script to use
// you really have to screw up to get this error
if(!$fp)
{
echo "Error: Cannot open file.";
exit;
}

fwrite($fp,$search."\n";);
fclose($fp);
echo "new user added";
}
?>


now the only security is the fact noone knows exactly where to look (till now) and if this still existed on my website there would be nothing to stop anyone from putting

cheesefactory.us/searchdata.php?search=Osgeld Barmy
or
cheesefactory.us/searchdata.php?search=JACK ASS

into their browser and adding something to my text file so this is very simplistic and totally unadvised for anything but a learning experiance
Benja Kepler
Registered User
Join date: 16 Dec 2006
Posts: 53
08-30-2007 07:36
also see Zero Linden's SILO:-

/54/69/119570/1.html

and in

http://wiki.secondlife.com/wiki/Category:LSL_Library
Sollie Villota
Registered User
Join date: 22 Jun 2007
Posts: 46
08-31-2007 09:38
I am making extremely good progress on this, learning lots of MySQL and PHP info since yesterday. I got it taking information from SL and succesffully saving it to my database. But here's my problem now: How do i make it so if that information is ALREADY there, it wont add another line for it? So that way, if someone dies in the place, the scoreboard will contact the MySQL server and check if the name and avatar key is already there. If it aint, it will add a new entry for it. But if it is there, it will only update that line 'WHERE name = $name and avkey = $avkey' basically.

Here's what I am thinking: When someone dies and sends the information of the killer and the dead person to the scoreboard, the scoreboard sends those individually to the database but follows several different scripts. The first script will check to see if both avatar names and keys are in the database, and if it returns as FALSE or NO, the scoreboard will send the information to another PHP script that will ADD the names. If the first PHP script returns TRUE or YES, it will just UPDATE the two lines with the appropriate kills/deaths.

Is this at all correct at what I am trying to accomplish?

Also, is it possible to just ADD to a line instead of updating to a brand new number? Like Player A killed Player B, add one kill to kills for Player A and then add one death to deaths for Player B. Possible?
Chaz Longstaff
Registered User
Join date: 11 Oct 2006
Posts: 685
08-31-2007 10:04
That's great you're getting so far, congrats! But I wonder if this hasn't moved beyond LSL and maybe should be moved to a PHP forum somewhere?
Django Yifu
Beat Island Gaffer
Join date: 7 May 2007
Posts: 189
10-28-2007 05:17
I'm very new to PHP but it seems to me this script will continue to write any name to the list regardless as to whether they are on it or not due to the section

if ($on_list != "";)
{
echo "on list";
}
// if its not write the name in the file
else
{
$fp = fopen($filename,"a";);

Doesn't this segment say if the name isn't on the list say it's on the list otherwise add them to the list or am I wrong. When testing it just seemed to continue adding my name to the list.

However if I changed it for

if ($on_list == "";)
{
echo "on list";
}
// if its not write the name in the file
else
{
$fp = fopen($filename,"a";);


Nothing happened.

So i Tried swapping the lines round as so;

f ($on_list == "";)
{
$fp = fopen($filename,"a";);
}
// if its not write the name in the file
else
{
echo "on list";

and still nothing.

Anyone care to shed some light on the issue for a noobie PHP scripter
_____________________
Tread softly upon the Earth for you walk on my face.
Daten Thielt
Registered User
Join date: 1 Dec 2006
Posts: 104
10-28-2007 09:25
If ur using mysql u need to make the row on your table unique
Django Yifu
Beat Island Gaffer
Join date: 7 May 2007
Posts: 189
10-28-2007 09:45
my understanding was this just vreated a .dta text file that was written to and read from but I'm guessing I got that wrong.
_____________________
Tread softly upon the Earth for you walk on my face.