Difference between revisions of "User:Niaht Nakamichi"

From Second Life Wiki
Jump to navigation Jump to search
m (Object Rezzing)
m
 
(10 intermediate revisions by the same user not shown)
Line 2: Line 2:


==About Me==
==About Me==
I am a generalist. I was once a systems engineer and the head of an IT department.
I do what it is that I do.


Boredom comes easily to me.
I am a mentor/teacher. This means I will answer specific questions about scripting, or guide you through specific subjects. This does not mean I will write your code for you. Please do not ask me to unless you intend to hire me (see below), or inspire me.


Every now and again I build a website for someone; I do not have my own.
Sure, I can do work for hire, at L$27,000/hr. :P
 
I like SecondLife.
 
==XXTEA Cipher==
 
This is something I decided to do for no good reason. It probably isn't optimal, and it probably needs work, but it works. At some point it might want to be integrated into the XTEA page, or get its own page. Feel free to comment on my [[User_talk:Niaht_Nakamichi|Talk Page]]
 
Code references used:
* {{Wikipedia|XXTEA}}
* [http://www.movable-type.co.uk/scripts/tea-block.html JS Implementation (Chris Veness)]
* [http://www.pear.php.net/package/Crypt_XXTEA PHP Implementation (PEAR)]
* [[XTEA_Strong_Encryption_Implementation|XTEA SL Implementation]]
 
 
'''Note: I can not take any real credit for this work. I just made the pre-existing code function in LSL.'''
 
<lsl>
  // Code coming later...
</lsl>


==Data type Tests==
==Data type Tests==
Here are some quick and dirty data type tests.. so far they work for me. They have not been optimized.
Here are some quick and dirty data type tests.. so far they work for me. They have not been optimized, most need to be replaced with *far* better methods.


===isKey===
===isKey===
Line 98: Line 79:
     return FALSE;
     return FALSE;
}
}
</lsl>
==Looping==
These are some examples of fancy looping. This is hardly a complete or even best set of examples.
This example might be used in the case of processing a list in reverse.
<lsl>
integer i = 10;
while(~(i = ~ -i)) {
  // Do something
}
</lsl>
The same thing as a do-while
<lsl>
integer i = 10 - 1;
do {
  // Do something
} while (i = ~ -i);
</lsl>
</lsl>


==Object Rezzing==
==Object Rezzing==


===Z-Pointed===
===X-Pointed===
<lsl>
        string obj = "My Object";
        vector offset = <0.75, 0.0, 0.0>;
        float velocity = 10.0;
        integer start_param = 0;
 
        rotation rot = llGetRot();
        llRezAtRoot(obj, llGetPos() + offset * rot, llRot2Fwd(rot) * velocity, rot, start_param);
</lsl>
 
===Y-Pointed===
<lsl>
<lsl>
         string obj = "My Object";
         string obj = "My Object";
         vector offset = <0.0, 0.0, 0.75>;
         vector offset = <0.0, 0.75, 0.0>;
         float velocity = 10.0;
         float velocity = 10.0;
         integer start_param = 0;
         integer start_param = 0;


         rotation rot = llGetRot();
         rotation rot = llGetRot();
         llRezAtRoot(obj, llGetPos() + offset * rot, llRot2Up(rot) * velocity, rot, start_param);
         llRezAtRoot(obj, llGetPos() + offset * rot, llRot2Left(rot) * velocity, rot, start_param);
</lsl>
</lsl>


===X-Pointed===
===Z-Pointed===
<lsl>
<lsl>
         string obj = "My Object";
         string obj = "My Object";
         vector offset = <0.75, 0.0, 0.0>;
         vector offset = <0.0, 0.0, 0.75>;
         float velocity = 10.0;
         float velocity = 10.0;
         integer start_param = 0;
         integer start_param = 0;


         rotation rot = llGetRot();
         rotation rot = llGetRot();
         llRezAtRoot(obj, llGetPos() + offset * rot, llRot2Fwd(rot) * velocity, rot, start_param);
         llRezAtRoot(obj, llGetPos() + offset * rot, llRot2Up(rot) * velocity, rot, start_param);
</lsl>
 
==Rotations==
 
===Global To Local===
To convert the global rotation of a child to a local rotation
<lsl>
        integer link = 2;
        rotation child_rot_local = (rotation)((string)llGetLinkPrimitiveParams(link, [PRIM_ROTATION])) / llGetRootRotation();
</lsl>
 
=== Local To Global ===
To convert a local rotation to a global rotation
<lsl>
        rotation child_rot_global = child_rot_local * llGetRootRotation();
</lsl>
 
==Random Number Generation==
 
The following code handles both positive and negative numbers. Your min should be the number closest to zero, however you can span negative and positive.
<lsl>
integer rand_between(integer min, integer max) {
    max += (max >= 0) - (max < 0);
    return (integer)llFrand(max - min) + min;
}
</lsl>
 
===Random Listen Channels===
Generate a positive random channel excluding the debug channel and a bottom series of commonly used channels. Though there really isn't a good reason to do so, you may include the debug channel, or channels down to zero, but not both or you will experience an "integer overflow" with unexpected results.
<lsl>
integer chan = rand_between(6000, 2147483646);
</lsl>
 
Generate a negative random channel excluding a bottom series of commonly used channels. You may include channel zero if you drop channel max down to no more than -2147483647 (You probably don't want to do that).
<lsl>
integer chan = rand_between(-6000, -2147483648);
</lsl>
</lsl>


==Simple PHP Code==
==Simple PHP Code==
Someone asked for this once. It's old, lacking, but should work.
<php>
<php>
<?php
<?php
/**
/**
  Simple PHP Form Mailer
  Simple PHP Form Mailer
  Written by Niaht Nakamichi (2008)
  Written by Niaht Nakamichi (2008-2010)
You are free to do whatever you want with this.
*/


/*
/**
* Form field names (fill these in to match your html form)
* Message Configuration
*/
*/
$to        = 'nobody@example.com';                // Were to send the message too.
$from      = 'webmaster@example.com';            // Who the message is from.
$reply_to  = 'nobody@example.com';                // Who to reply to.
$subject    = 'Message sent from your website';    // The default Subject (if none is provided in the form).
$thanks    = 'Thanks for your message!';          // Message given after submitting the form.
$thanks_url = ''                                  // Set this to a valid URL if you want a redirect.
/**
* Form settings
*/
$display_form = true;                            // Set this to false if this page should not display a form
$form_title = "Contact Me";
/**
* Form field names (fill these in to match your html form if using an external form)
*/
$subject_field = 'subject';                      // Leave this blank to ONLY use default subject.
$message_field = 'message';
$message_field = 'message';


// Leave this blank if no subject is provided in the form.
/**
$subject_field = '';   
* Form templates
* If you know what you are doing, you can customize these.
*/


if ($_POST['message']) {
// Thank you message template
     /*
function print_thanks($title, $message) { ?>
    * Message Configuration
  <html>
     */
  <head>
     $to      = 'nobody@example.com';           // Were to send the message too.
     <title><?php echo $title; ?></title>
     $from    = 'webmaster@example.com';        // Who the message is from.
  </head>
    $reply_to = 'nobody@example.com';           // Who to reply to.
  <body>
    $subject  = 'the subject';                 // The default Subject (if none is provided in the form).
     <?php echo $message; ?>
   
  </body>
    if ($subject_field != '' && $_POST['subject']) $subject = strip_tags($_POST['subject']);
  </html>
<?php }
 
// Form template
function print_form($title, $subject_field, $message_field) { ?>
  <html>
  <head>
     <title><?php echo $title; ?></title>
  </head>
  <html>
     <form id="mailer" method="post">
      <?php if (!empty($subject_field)): ?>
        <label for="<?php echo $subject_field ?>">Subject: </label>
        <input type="text" id="<?php echo $subject_field; ?>" name="<?php echo $subject_field; ?>"><br/>
      <?php endif; ?>
      <label for="<?php echo $message_field; ?>">Message: </label>
      <textarea id="<?php echo $message_field; ?>" name="<?php echo $message_field; ?>"></textarea><br/>
      <input type="submit" id="submit" name="submit" value="Submit">
      <input type="reset" id="reset">
    </form>
<?php }
 
//*************************************************************
// You probably don't need to change anything below here.
//*************************************************************
 
// Process the post
if ($_POST[$message_field]) {


     $headers = 'From: ' . $from . "\r\n" .
     $headers = 'From: ' . $from . "\r\n" .
         'Reply-To: ' . $reply_to . "\r\n" .
         'Reply-To: ' . $reply_to . "\r\n" .
         'X-Mailer: PHP/' . phpversion();
         'X-Mailer: PHP/' . phpversion();
          
   
     $message = strip_tags($_POST['message']);
    if ($subject_field != '' && isset($_POST[$subject_field])) {
         $subject = strip_tags($_POST[$subject_field]);
    }
     $message = strip_tags($_POST[$message_field]);
 
     mail($to, $subject, $message, $headers);
     mail($to, $subject, $message, $headers);
    print("Thank you for your message.");
} else {
  print("<form id=\"mailer\" method=\"post\">\n");
  if ($subject_field != '')
    print("<LABEL for=\"" . $subject_field . "\">Subject: </LABEL>\n"
        . "      <INPUT type=\"text\" id=\"" . $subject_field . "\" name=\"" . $subject_field . "\"><BR>\n");
  print("<LABEL for=\"" . $message_field . "\">Message: </LABEL>\n"
        . "      <textarea id = \"" . $message_field . "\" name=\"" . $message_field . "\"></textarea><BR>\n");
  print("<INPUT type=\"submit\" id=\"submit\" name=\"submit\" value =\"Submit\">\n");
  print("<INPUT type=\"reset\" id=\"reset\">");
  print ("</FORM>\n");
 
}
</php>


==Client Library Changes==
    // Perform a redirect
    if (!empty($thanks_url)) {
        header('Location: ' . $thanks_url);
    }


These are the changes to the SL client libraries since 1.13.1.12. I don't expect this to be perfect, nor presented in the best possible way. This is mostly intended for me so that I don't loose this data. If this helps you in some way, and you have suggestions on how to make it better, please feel free to do so on my [[User_talk:Niaht_Nakamichi|Talk Page]]
    // Otherwise print a thank you note
    else if (!empty($thanks)) {
      print_thanks($form_title, $thanks);
    }
}


The emerging patterns are already becoming clear, and I can see that I will be able to reduce the changes down to named library changes instead of listing any files.
// Display the form if enabled
 
else if ($display_form) {
<div id="box">
    print_form($form_title, $subject_field, $message_field);
{| border="1" cellspacing="0"
}
|-
</php>
|'''From'''
|'''To'''
|'''Changes'''
|-
|1.13.2.13
|1.13.2.15
|None
|-
|1.13.2.15
|1.13.3.2
|None
|-
| valign="top" |1.13.3.2
| valign="top" |1.14.0.0
|
'''Files Removed'''
* indra/newview/app-settings/static_data.db2
* indra/newview/app-settings/static_index.db2
 
'''Files Changed'''
* indra/newview/app_settings/mozilla/ (many)
* LibOpenJPEG.lib
* js3250.dll
* libcurl.lib
* llkdu.dll (Release Only)
* llmozlib.lib
* nspr4.dll
* plc4.dll
* plds4.dll
* xul.dll
* curl.h
* curlver.h
* mprintf.h
* multi.h
* openjpeg.h
 
'''New Files'''
* libboost_regex-vc80-mt-s.lib
* llmozlib-vc80.lib
* libboost_python-vc80-m5.lib (Release only)
|-
|1.14.0.0
|1.14.0.1
|None
|-
| valign="top" |1.14.0.1
| valign="top" |1.15.0.2
|
'''Files Changed'''
* curl.h
* curlver.h
* mprintf.h
* multi.h
* tut.h
 
'''New Files'''
* indra/newview/fonts
|-
| valign="top" |1.15.0.2
| valign="top" |1.15.1.3
|
'''Files Changed'''
* libraries/include/boost (Many)
* curl.h
* curlver.h
* mprintf.h
* multi.h
|-
| valign="top" |1.15.1.3
| valign="top" |1.16.0.5
|
'''Files Changed'''
* llmozlib-vc80.lib
* libraries/include/boost (Many)
* curl.h
* curlver.h
* mprintf.h
* multi.h
|-
| valign="top" |1.16.0.5
| valign="top" |1.17.0.12
|
'''Files Changed'''
* indra/newview/app_settings/mozilla (Many)
* js3250.dll
* llmozlib-vc80.lib (Release Only)
* llmozlib.lib
* nspr4.dll
* plc4.dll
* plds4.dll
* xul.dll
 
'''Files Removed'''
* indra/newview/app_settings/mozilla/components (Many [.xpt files])
 
'''New Files'''
* indra/newview/app_settings/mozilla/components/all.xpt
|-
| valign="top" |1.17.0.12
| valign="top" |1.17.1.0
|
'''Files Changed'''
* indra/newview/app_settings/mozilla (Many)
* js3250.dll
* libcurl.lib
* llmozlib.lib
* nspr4.dll
* plc4.dll
* plds4.dll
* xul.dll
* libraries/include/boost (Many)
* curl.h
* curlver.h
* mprintf.h
* multi.h
 
'''New Files'''
* png12.lib
|-
|1.17.1.0
|1.17.2.0
|None
|-
|1.17.2.0
|1.17.3.0
|None
|-
| valign="top" |1.17.3.0
| valign="top" |1.18.0.6
|
'''Files Changed'''
* libraries/include/boost (Many)
* curl.h
* curlver.h
* mprintf.h
* multi.h
* tut.h
|-
|1.18.0.6
|1.18.1.2
|
|-
|1.18.1.2
|1.18.2.0
|
|-
|1.18.2.0
|1.18.2.1
|
|-
|1.18.2.1
|RC-1.18.3.2
|
|-
|RC-1.18.3.2
|RC-1.18.3.3
|
|-
|RC-1.18.3.3
|RC-1.18.3.4
|None
|-
|RC-1.18.3.4
|RC-1.18.3.5
|
|-
|RC-1.18.3.5
|RC-1.18.4.0
|
|-
|RC-1.18.4.0
|RC-1.18.4.1
|None
|-
|RC-1.18.4.1
|RC-1.18.4.2
|None
|-
|RC-1.18.4.2
|1.18.4.3
|None
|-
|1.18.4.3
|RC-1.18.5.0
|
|-
|RC-1.18.5.0
|RC-1.18.5.1
|
|-
|RC-1.18.5.1
|RC-1.18.5.2
|
|-
|RC-1.18.5.2
|1.18.5.3
|None
|-
|RC-1.18.5.3
|RC-1.18.6.0
|
|-
|RC-1.18.6.0
|RC-1.18.6.1
|
|-
|RC-1.18.6.1
|RC-1.18.6.2
|
|-
|RC-1.18.6.2
|RC-1.18.6.4
|None
|-
|RC-1.18.6.4
|Branch_1-19.0-Viewer-r79209
|
|-
|Branch_1-19.0-Viewer-r79209
|Branch-1-19.0-Viewer-r79825
|None
|-
|Branch-1-19.0-Viewer-r79825
|Branch-1-19.0-Viewer-r80554
|None
|-
|Branch-1-19.0-Viewer-r80554
|Branch-1-19.0-Viewer-r80803
|None
|-
|Branch-1-19.0-Viewer-r80803
|Branch-1-19.0-Viewer-r81066
|None
|-
|Branch-1-19.0-Viewer-r81066
|Branch-1-19.1-Viewer-r81993
|
|}
</div>

Latest revision as of 19:25, 28 July 2012

About Me

I do what it is that I do.

I am a mentor/teacher. This means I will answer specific questions about scripting, or guide you through specific subjects. This does not mean I will write your code for you. Please do not ask me to unless you intend to hire me (see below), or inspire me.

Sure, I can do work for hire, at L$27,000/hr. :P

Data type Tests

Here are some quick and dirty data type tests.. so far they work for me. They have not been optimized, most need to be replaced with *far* better methods.

isKey

Testing for valid keys is made very simple. Invalid key values won't be positively compared to the null key static NULL_KEY, where with other data types invalid values will be converted to the zero value static for that data type (or zero) and thusly will compare positively to their corresponding zero value.

To test if a given key is a valid (and non-null), the code 'if ((key)stringvar)' is sufficient.

As Strife Onizuka pointed out you can use the following code to determine if a key is valid and also take into consideration if the key is a NULL_KEY, making for a more proper isKey test. <lsl> integer isKey(key k) {

   if (k) return 2;
   return (k == NULL_KEY);

} </lsl> This works as expected for standard if(isKey("key")) tests since 'if' evaluates any integer greater than zero to TRUE. The rest of the tests below could easily be modified to behave the same way if desired, or the above isKey could be modified to simply return 1 for all valid cases.

isInteger

<lsl> integer isInteger(string s) {

   if (s != "") {
       integer i;
       integer l = llStringLength(s);
       do {
           if(! ~llListFindList(["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"], (list)llGetSubString(s, i, i))) return FALSE;
           ++i;
       } while (i < l);
     return TRUE;
   }
   return FALSE;

} </lsl>

isFloat

<lsl> integer isFloat(string s) {

   if (s != "") {
       integer i; integer d; string c;
       integer l = llStringLength(s);
       do {
           c = llGetSubString(s, i, i);
           if (! ~llListFindList([".", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"], (list)c)) return FALSE;
           if (c == ".") ++d;
           if (d > 1) return FALSE;
           ++i;
       } while (i < l);
       return TRUE;
   }
   return FALSE;

} </lsl>

isVector

Note: Uses 'isFloat' above . . . <lsl> integer isVector(string s) {

   list f;
   integer i = 0;
   if ((rotation)s) return FALSE; // don't accept rotations
   if ((vector)s) return TRUE;    // accept any positive valid
   // Everything past here is mostly for testing for a proper ZERO vector, so possibly excessive.
   if (llSubStringIndex(s, "<") == 0)
       if (llSubStringIndex(s, ">") == (llStringLength(s) - 1))
           if (llGetListLength(f = llParseString2List(s, ["<",">", " "], [","])) == 5)
               if (isFloat(llList2String(f, 0)))
                   if (llList2String(f, 1) == ",")
                       if (isFloat(llList2String(f, 0)))
                           if (llList2String(f, 3) == ",")
                               if (isFloat(llList2String(f, 4))) return TRUE;
   return FALSE;

} </lsl>

Looping

These are some examples of fancy looping. This is hardly a complete or even best set of examples.


This example might be used in the case of processing a list in reverse. <lsl> integer i = 10; while(~(i = ~ -i)) {

 // Do something

} </lsl>

The same thing as a do-while <lsl> integer i = 10 - 1; do {

 // Do something

} while (i = ~ -i); </lsl>

Object Rezzing

X-Pointed

<lsl>

       string obj = "My Object";
       vector offset = <0.75, 0.0, 0.0>;
       float velocity = 10.0;
       integer start_param = 0;
       rotation rot = llGetRot();
       llRezAtRoot(obj, llGetPos() + offset * rot, llRot2Fwd(rot) * velocity, rot, start_param);

</lsl>

Y-Pointed

<lsl>

       string obj = "My Object";
       vector offset = <0.0, 0.75, 0.0>;
       float velocity = 10.0;
       integer start_param = 0;
       rotation rot = llGetRot();
       llRezAtRoot(obj, llGetPos() + offset * rot, llRot2Left(rot) * velocity, rot, start_param);

</lsl>

Z-Pointed

<lsl>

       string obj = "My Object";
       vector offset = <0.0, 0.0, 0.75>;
       float velocity = 10.0;
       integer start_param = 0;
       rotation rot = llGetRot();
       llRezAtRoot(obj, llGetPos() + offset * rot, llRot2Up(rot) * velocity, rot, start_param);

</lsl>

Rotations

Global To Local

To convert the global rotation of a child to a local rotation <lsl>

       integer link = 2;
       rotation child_rot_local = (rotation)((string)llGetLinkPrimitiveParams(link, [PRIM_ROTATION])) / llGetRootRotation();

</lsl>

Local To Global

To convert a local rotation to a global rotation <lsl>

       rotation child_rot_global = child_rot_local * llGetRootRotation();

</lsl>

Random Number Generation

The following code handles both positive and negative numbers. Your min should be the number closest to zero, however you can span negative and positive. <lsl> integer rand_between(integer min, integer max) {

   max += (max >= 0) - (max < 0);
   return (integer)llFrand(max - min) + min;

} </lsl>

Random Listen Channels

Generate a positive random channel excluding the debug channel and a bottom series of commonly used channels. Though there really isn't a good reason to do so, you may include the debug channel, or channels down to zero, but not both or you will experience an "integer overflow" with unexpected results. <lsl> integer chan = rand_between(6000, 2147483646); </lsl>

Generate a negative random channel excluding a bottom series of commonly used channels. You may include channel zero if you drop channel max down to no more than -2147483647 (You probably don't want to do that). <lsl> integer chan = rand_between(-6000, -2147483648); </lsl>

Simple PHP Code

Someone asked for this once. It's old, lacking, but should work. <php> <?php /**

Simple PHP Form Mailer
Written by Niaht Nakamichi (2008-2010)
You are free to do whatever you want with this.
  • /

/**

  • Message Configuration
  • /

$to = 'nobody@example.com'; // Were to send the message too. $from = 'webmaster@example.com'; // Who the message is from. $reply_to = 'nobody@example.com'; // Who to reply to. $subject = 'Message sent from your website'; // The default Subject (if none is provided in the form). $thanks = 'Thanks for your message!'; // Message given after submitting the form. $thanks_url = // Set this to a valid URL if you want a redirect.

/**

  • Form settings
  • /

$display_form = true; // Set this to false if this page should not display a form $form_title = "Contact Me";

/**

  • Form field names (fill these in to match your html form if using an external form)
  • /

$subject_field = 'subject'; // Leave this blank to ONLY use default subject. $message_field = 'message';

/**

  • Form templates
  • If you know what you are doing, you can customize these.
  • /

// Thank you message template function print_thanks($title, $message) { ?>

 <html>
 <head>
   <title><?php echo $title; ?></title>
 </head>
 <body>
   <?php echo $message; ?>
 </body>
 </html>

<?php }

// Form template function print_form($title, $subject_field, $message_field) { ?>

 <html>
 <head>
   <title><?php echo $title; ?></title>
 </head>
 <html>
   <form id="mailer" method="post">
     <?php if (!empty($subject_field)): ?>
       <label for="<?php echo $subject_field ?>">Subject: </label>
       <input type="text" id="<?php echo $subject_field; ?>" name="<?php echo $subject_field; ?>">
<?php endif; ?> <label for="<?php echo $message_field; ?>">Message: </label> <textarea id="<?php echo $message_field; ?>" name="<?php echo $message_field; ?>"></textarea>
<input type="submit" id="submit" name="submit" value="Submit"> <input type="reset" id="reset"> </form>

<?php }

//************************************************************* // You probably don't need to change anything below here. //*************************************************************

// Process the post if ($_POST[$message_field]) {

   $headers = 'From: ' . $from . "\r\n" .
       'Reply-To: ' . $reply_to . "\r\n" .
       'X-Mailer: PHP/' . phpversion();
   
   if ($subject_field !=  && isset($_POST[$subject_field])) {
       $subject = strip_tags($_POST[$subject_field]);
   }
   $message = strip_tags($_POST[$message_field]);
   mail($to, $subject, $message, $headers);
   // Perform a redirect
   if (!empty($thanks_url)) {
       header('Location: ' . $thanks_url);
   }
   // Otherwise print a thank you note
   else if (!empty($thanks)) {
      print_thanks($form_title, $thanks);
   }

}

// Display the form if enabled else if ($display_form) {

   print_form($form_title, $subject_field, $message_field);

} </php>