Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //integer PRIM_GLOW = 25;
- integer steps = 2;
- integer counter = 0;
- vector my_position = <0,0,0>;
- string api_url = "http://www.bhr.vivox.com/api2/";
- string access_code = "787705"; // set me to 0 on production model, default access code for now
- string dial_in_number = "1-301-789-0017";
- string cur_state = "disabled";
- string cur_channel = "";
- //war was begining
- integer SL_COM_CHANNEL = 2101;
- //Admin login
- string userid = "viv_hud_admin";
- string pwd = "vivox123";
- string auth_token = "";
- // HTTP request variables
- // number of items in stored http requests
- integer requestStrideLength = 4; // request id, user, request type,request
- // identifier for a unique http request
- key requestid;
- // list of active http requests
- list requestList;
- //Object Display
- vector color_on = <0,1,0>;
- vector color_off = <1,0,0>;
- //user info
- string agent = "";
- string username = "";
- init_access()
- {
- llOwnerSay("verifying access");
- agent = (string)llGetOwner();
- mangle_uuid(agent);
- string result;
- string request = api_url+"viv_signin.php?userid="+userid+"&pwd="+pwd;
- result = llHTTPRequest(request, [HTTP_METHOD,"GET"],"");
- //llOwnerSay("access result = " + result);
- //llOwnerSay("checking and setting cur font id");
- request = api_url+"viv_acct.php?username="+username+"&mode=update&auth_token="+auth_token;
- //http://www.bhd.vivox.com/api2/viv_acct.php?username=xNjm8h8bgRLePQgqafhaCqw==&font_default=37&mode=update&userid=viv_hud_admin&pwd=vivox123
- result = llHTTPRequest(request, [HTTP_METHOD,"GET"],"");
- vivox_channel();
- my_position = vivox_coords();
- }
- mangle_uuid(string acctname) {
- string result;
- string request = "http://vir5ag.vivox.com/dave/jon/sl/mangle_uuid.php?uuid=" + agent; //Move this file and change me please!
- result = llHTTPRequest(request, [HTTP_METHOD,"GET"],"");
- }
- vector vivox_coords()
- {
- vector vivox_coords;
- vector vregion = llGetRegionCorner();
- vector vlocal = llGetPos();
- vivox_coords.x = vregion.x + vlocal.x;
- vivox_coords.z = -(vregion.y + vlocal.y);
- vivox_coords.y = 30;
- llOwnerSay((string)vivox_coords);
- return vivox_coords;
- }
- vivox_channel()
- {
- //TODO: this shouldn't commented out, it needs to be fixed!
- //string result;
- //string request = api_url+"viv_chan_cmd.php?mode=find_user&extended=1&user_name="+username+"auth_token="+auth_token;
- //result = llHTTPRequest(request, [HTTP_METHOD,"GET"],"");
- string region = llGetRegionName();
- if(region == "Suzume")
- {
- cur_channel = "sip:confctl-40358127@bhr.vivox.com";
- }
- if(region == "Ambrosia")
- {
- cur_channel = "sip:confctl-6481071@bhr.vivox.com";
- }
- if(region == "Linden Estate Services" || region == "Linden Estate Services4")
- {
- cur_channel = "sip:confctl-55696976@bhr.vivox.com";
- }
- }
- //set_font(string fid)
- //{
- //llOwnerSay("Setting Font ID now...");
- //if(fid == cur_font_id)
- //{ return; }
- //string result;
- //string request = api_url+"viv_acct.php?username="+username+"&font_default="+fid+"&mode=update&auth_token="+auth_token;
- //http://www.bhd.vivox.com/api2/viv_acct.php?username=xNjm8h8bgRLePQgqafhaCqw==&font_default=37&mode=update&userid=viv_hud_admin&pwd=vivox123
- //result = llHTTPRequest(request, [HTTP_METHOD,"GET"],"");
- //llOwnerSay("Request token: " + result);
- //}
- Activate_Speakerphone(vector location, string code)
- {
- if(code == "" || code == "0")
- {
- // object not initialized with an access code, throw error/message user to buy an access code
- llOwnerSay("Looks like you don't have an access code set, you should probably fix that!");
- }
- if(location.x != 0.0 && location.z != 0.0)
- {
- //hey, new location set
- string result;
- string request = api_url+"viv_adm_access_code_activation.php?mode=activate&code="+code+"&x_pos="+(string)location.x+"&y_pos=30.00000&z_pos="+(string)location.z+"&chan_uri="+cur_channel+"&auth_token="+auth_token;
- result = llHTTPRequest(request, [HTTP_METHOD,"GET"], "");
- }
- else{
- // we're just turning it back on, don't move it
- string result;
- string request = api_url+"viv_adm_access_code_activation.php?mode=activate&code="+code+"&auth_token="+auth_token;
- result = llHTTPRequest(request, [HTTP_METHOD,"GET"], "");
- }
- }
- Deactivate_Speakerphone(string code)
- {
- string result;
- string request = api_url+"viv_adm_access_code_activation.php?mode=activate&code="+code+"&auth_token="+auth_token;
- result = llHTTPRequest(request, [HTTP_METHOD,"GET"], "");
- }
- // return the value for the passed xml element
- // returns the first instance of the element found
- // method currently fails to find element if passed element contains attributes
- string getXMLValue(string xmlstring, string element)
- {
- // llOwnerSay("getxmlvalue ...element: " + element + ", xmlstring: " + xmlstring);
- string value = "";
- string elementopen = "<" + element + ">";
- string elementclose = "</" + element + ">";
- integer elementstart = llSubStringIndex(xmlstring, elementopen);
- if(elementstart == -1){
- // element not found
- // llOwnerSay("did not find " + element + " in xml");
- return NULL_KEY;
- }
- integer valuestart = elementstart + llStringLength(elementopen);
- integer valueend = llSubStringIndex(xmlstring, elementclose) - 1;
- value = llGetSubString(xmlstring, valuestart, valueend);
- // llOwnerSay("found value = " + value);
- return value;
- }
- Set_Display(string message, vector color)
- {
- llSetText(message, color, 1); //Update display
- }
- default
- {
- on_rez(integer start_param)
- {
- //reset object
- llResetScript();
- llOwnerSay((string)vivox_coords());
- //get the auth token
- init_access();
- //get the user's access code, when that functionality comes along
- //get the objects coordinates and set them
- my_position = vivox_coords();
- //set state to off and reset object
- cur_state = "disabled";
- Set_Display("Not Broadcasting", color_off);
- llWhisper(0, "Thanks for using the Vivox dial-in speakerphone! Touch me to get started.");
- }
- state_entry()
- {
- //Set up listens for HUD control
- llListen(SL_COM_CHANNEL, "", "", ""); //This can be imrpoved, but for the moment this will work
- init_access();
- }
- listen( integer channel, string name, key id, string message )
- {
- if(auth_token == "")
- {
- //llOwnerSay("calling init access");
- init_access();
- }
- if(message == "SPEAKERPHONE")
- {
- if(cur_state == "enabled")
- {
- Activate_Speakerphone(my_position, access_code);
- Set_Display("Not Broadcasting", color_off);
- llWhisper(0, "Speakerphone disabled to new calls");
- cur_state = "disabled";
- }
- else if(cur_state == "disabled")
- {
- Activate_Speakerphone(my_position, access_code);
- Set_Display("(((Broadcasting ON)))", color_on);
- llWhisper(0, "Speakerphone enabled, your conversations can be heard!");
- llWhisper(0, "To dial in, call " + dial_in_number + " with access code " + access_code);
- cur_state = "enabled";
- }
- }
- }
- touch_start(integer total_number)
- {
- if(auth_token == "")
- {
- //llOwnerSay("calling init access");
- init_access();
- }
- if(cur_state == "enabled")
- {
- Activate_Speakerphone(my_position, access_code);
- Set_Display("Not Broadcasting", color_off);
- llWhisper(0, "Speakerphone disabled to new calls");
- cur_state = "disabled";
- }
- else if(cur_state == "disabled")
- {
- Activate_Speakerphone(my_position, access_code);
- Set_Display("(((Broadcasting ON)))", color_on);
- llWhisper(0, "Speakerphone enabled, your conversations can be heard!" + " Position = " + (string)my_position);
- llWhisper(0, "To dial in, call " + dial_in_number + " with access code " + access_code);
- cur_state = "enabled";
- }
- //llOwnerSay("Auth Token: " + auth_token);
- //llSetPrimitiveParams( [ PRIM_GLOW, ALL_SIDES, counter/ (steps - 1.0) ] );
- //if setting to on, set message to on and whisper dial in info
- //else set it to off
- }
- //http_response is called when llHTTPRequest is called
- http_response(key request_id, integer status, list metadata, string body)
- {
- integer i;
- // find the request entry corresponding to this response
- integer requestIndex = llListFindList(requestList, [request_id]);
- list requestEntry = llList2List(requestList, requestIndex, requestStrideLength);
- //hey we got an auth_token, update it
- if(getXMLValue(body, "auth_token") != NULL_KEY)
- {
- auth_token = getXMLValue(body, "auth_token");
- //TODO: remove debug
- //llOwnerSay("Auth Token: " + auth_token);
- }
- //hey we got a font id, update it
- //hey we got a translated user, update it
- if(getXMLValue(body, "translated_username") != NULL_KEY)
- {
- username = getXMLValue(body, "translated_username");
- //llOwnerSay((string)username);
- }
- // check the response body for an error code
- if ( ( i = llSubStringIndex(body,"ERR") ) != -1 ){
- //llWhisper(0, "An error occurred on a http request");
- //llWhisper(0, "Request was " + llList2String(requestEntry, 3));
- // llWhisper(0, "Response was " + body);
- llOwnerSay("Something didn't happen as expected! Try again, but if this problem persists contact a member of the Vivox Second Life group with a description of the problem " + (string)my_position);
- string code = getXMLValue(body, "code");
- string msg = getXMLValue(body, "msg");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement