|
Max Pitre
Registered User
Join date: 19 Jul 2006
Posts: 370
|
09-17-2007 04:51
I need to take a listen that would, for example, take this info... http://64.71.145.133:8010 and turn it into two strings, one with the http://64.71.145.133 and one with the 8010 So it would be like this.. string ip = "http://64.71.145.133"; string port = "8010"; Then of course the rest of the script would go after that Thanks
|
|
Squirrel Wood
Nuteater. Beware!
Join date: 14 Jun 2006
Posts: 471
|
09-17-2007 05:21
list urldata = llParseString2List(YourString,[":"],[]); string ip = llList2String(urldata,0); string port = llList2String(urldata,1);
This should give you the wanted result. But instead of writing the resulting list to more variables you could just get the data right from the list when needed.
|
|
Simnelia Petrichor
Registered User
Join date: 10 Feb 2006
Posts: 35
|
09-17-2007 05:30
From: Squirrel Wood list urldata = llParseString2List(YourString,[":"],[]); string ip = llList2String(urldata,0); string port = llList2String(urldata,1);
This should give you the wanted result. But instead of writing the resulting list to more variables you could just get the data right from the list when needed. As I read it, this will give you a list of 3 elements rather than two, and the variables would have to be calculated as: string ip = llList2String(urldata,0) + ":" + llList2String(urldata,1); string port = llList2String(urldata,2);
|
|
Mereille Despres
Registered User
Join date: 5 Sep 2007
Posts: 79
|
09-17-2007 05:35
From: Max Pitre I need to take a listen that would, for example, take this info... http://64.71.145.133:8010 and turn it into two strings, one with the http://64.71.145.133 and one with the 8010 So it would be like this.. string ip = "http://64.71.145.133"; string port = "8010"; Then of course the rest of my script would go after that Thanks Couple things here. First, are you parsing URL's specifically for this? And are you expecting just a ip  ort format? The important function you want are llParseString2List(), and possibly llEscapeURL() string listenResult; //for arguments sake. //separate into parts using colon (  as a delimiter list url_parts = llParseString2List(listenResult,":"," "  ; //note that this will also keep spaces as separate entries! //get the first and second parts of the url string ip = llList2String(url_parts,0); string port = llList2String(url_parts,1); //the and tags are still there //now remove the url tags ip = llGetSubString(ip,4,llStringLength(ip) - 1); port = llGetSubString(port,0,llStringLength(port) - 5); That should get you to where you're going. You might need to fix the substring.I'm probably off by a character.
|
|
Max Pitre
Registered User
Join date: 19 Jul 2006
Posts: 370
|
09-17-2007 06:15
My goal is to take the free shoutcast music board and make it so I don't have to manually add the URL and port each time I change stations on my land. My radio shouts the URL and port on a channel, lets say channel -2424, so I want to pick up that channel and turn the info into the strings. Here is the original shoutcast XY text board code
// This board is designed so as link order is not important. // Each prim used for the display lines are named 1,2,3,etc and position on the line is named in the description 0,1,2,3,etc. // Lines can be added or removed, just need to be unlinked, renamed, recompile the scripts in the new lines, relink to the rest of the board.
// If you find this service useful, send an IM to Jamie Otis.
// Server details update these two lines with your shoutcast server information. // Example details suppied.
//string ip = "http://75.126.100.42";//KONA //string port = "8030";//KONA string ip = "http://64.71.145.133";//Chillout string port = "8010";//Chillout
// Do not edit below this line.
string sis_host = "http://sis.slserver.com/sis.php"; float update_time = 2.0;
integer ps = FALSE;
list gInfo;
list parseLine(string line) { list tokens; integer lineIndex = llSubStringIndex(line, "="); tokens += llGetSubString(line, 0, lineIndex - 1); tokens += llGetSubString(line, lineIndex + 1, -1); return tokens; }
list parseLines(string lines) { list tokens; integer index = llSubStringIndex(lines, "\n"); while(index != -1) { string line = llGetSubString(lines, 0, index - 1); tokens += parseLine(line); lines = llDeleteSubString(lines, 0, index); index = llSubStringIndex(lines, "\n"); } tokens += parseLine(lines); return tokens; }
string getValue(list pairs, string name) { integer length = llGetListLength(pairs); integer i; for(i = 0; i < length; i += 2) { if(llList2String(pairs, i) == name) { return llList2String(pairs, i + 1); } } return ""; }
send_message(string line, string message) { // Setup XYtext Variables integer DISPLAY_STRING = 204000; integer DISPLAY_EXTENDED = 204001; integer REMAP_INDICES = 204002; integer RESET_INDICES = 204003; integer SET_CELL_INFO = 204004; integer SET_FONT_TEXTURE = 204005; integer SET_THICKNESS = 204006; integer SET_COLOR = 204007;
llMessageLinked(LINK_SET,DISPLAY_STRING,message,line); }
clear_board() { // Clears the board down. send_message("1",""); send_message("2","Loading..."); send_message("3",""); send_message("4",""); send_message("5","Evolving Images"); send_message("6",""); }
default { state_entry() { clear_board(); string url = $sis_host+"?ip="+$ip+"&port="+$port; llHTTPRequest(url, [HTTP_METHOD,"GET"],""); llSetTimerEvent($update_time); }
timer() { string url = $sis_host+"?ip="+$ip+"&port="+$port; llHTTPRequest(url, [HTTP_METHOD,"GET"],""); }
on_rez(integer start_param) { llResetScript(); } http_response(key id, integer status, list metadata, string body) { if(status == 200) { if (llGetSubString(body, 0, 4) == "ERROR") { send_message("1",body); } else { gInfo = parseLines(body); send_message("1",(getValue(gInfo, "stream_title"))); string stream_status = getValue(gInfo, "stream_status"); integer len_stream_status = llSubStringIndex(stream_status, "("); stream_status = llGetSubString(stream_status,0,len_stream_status - 1); send_message("2",stream_status); send_message("3",(getValue(gInfo, "current_song"))); send_message("4",(getValue(gInfo, "last_song0"))); send_message("5",(getValue(gInfo, "last_song1"))); send_message("6"," Welcome to Max's Reef and Fish"); // // The below are disabled as my board only has 6 lines... // // send_message("7",(getValue(gInfo, "last_song4"))); // send_message("8",(getValue(gInfo, "last_song5"))); // // some extra information is available from the shoutcast server // however you would need a larger board to display these extra lines or modify what was shown on the available lines // // send_message("9", "Listener peak: " + getValue(gInfo, "listener_peak")); // send_message("10", "Average listen time: " + getValue(gInfo, "average_listen_time")); // send_message("11", "Server status :" + getValue(gInfo, "server_status")); // send_message("12", "Stream Genre: " + getValue(gInfo, "stream_genre")); // send_message("13", "Stream URL: " + getValue(gInfo, "stream_url")); // send_message("14", "Strean AIM: " + getValue(gInfo, "stream_aim")); // send_message("15", "Stream IRC: " + getValue(gInfo, "stream_irc")); } } else { send_message("1","ERROR: Could not connect to SIS server."); } } }
|
|
Max Pitre
Registered User
Join date: 19 Jul 2006
Posts: 370
|
09-18-2007 20:52
From: Mereille Despres Couple things here. First, are you parsing URL's specifically for this? And are you expecting just a ip  ort format? The important function you want are llParseString2List(), and possibly llEscapeURL() string listenResult; //for arguments sake. //separate into parts using colon (  as a delimiter list url_parts = llParseString2List(listenResult,":"," "  ; //note that this will also keep spaces as separate entries! //get the first and second parts of the url string ip = llList2String(url_parts,0); string port = llList2String(url_parts,1); //the and tags are still there //now remove the url tags ip = llGetSubString(ip,4,llStringLength(ip) - 1); port = llGetSubString(port,0,llStringLength(port) - 5); That should get you to where you're going. You might need to fix the substring.I'm probably off by a character. I didn't add the and tags, I guess the forum did for me.
|
|
Simnelia Petrichor
Registered User
Join date: 10 Feb 2006
Posts: 35
|
09-19-2007 01:13
From: Mereille Despres First, are you parsing URL's specifically for this? And are you expecting just a ip  ort format? I just wanted to say that the fact this serious piece of advice on scripting has got a pink smily face with its tongue sticking out in the middle has really made my day.
|
|
Qie Niangao
Coin-operated
Join date: 24 May 2006
Posts: 7,138
|
09-19-2007 01:19
Replaced the state_entry() and timer() handlers as follows: state_entry() { clear_board(); llListen(RADIO_CHANNEL, "", NULL_KEY, ""); } listen(integer channel, string name, key id, string message) { list urlParts = llParseString2List(message,[":", "/"],[]); string url = sis_host + "?ip=" + llList2String(urlParts,0) + "://" + llList2String(urlParts,1) + "&port=" + llList2String(urlParts,2); llHTTPRequest( url, [HTTP_METHOD,"GET"], ""); }
Note that unless the land radio provides a constant feed of the parcel music URL on RADIO_CHANNEL, this won't work until one changes the station after the script is reset.
|