2023-01-14 09:47:51 -05:00
# prim-dns server script
The prim-dns server script is a modular SecondLife script that will request a temporary URL and register that URL with a [prim-dns web service ](https://github.com/annapuddles/prim-dns ) instance to automatically create a permanent alias, which client scripts can use to find the current temporary URL of the server at any given time. This allows you to quickly add robust HTTP server functionality to any prim, and the modular design means the core script can be updated without needing to edit your own code, and different functions of a server can be split across multiple scripts for easier management.
2024-12-05 22:24:36 -05:00
You can grab the core prim-dns script along with several examples here: https://marketplace.secondlife.com/p/prim-dns/24388106
2023-01-14 09:47:51 -05:00
# prim-dns server diagram
The diagram below illustrates the communication between the prim-dns server script, the request handler scripts, the prim-dns web service, and a client.

# Link messages API
Communication between the prim-dns script and the request handler scripts is accomplished via link messages, where the string portion of the message is a JSON-RPC object.
## prim-dns:request (request-id, method, body)
2023-01-09 14:37:40 -05:00
The prim-dns script received an HTTP request.
2023-01-14 09:47:51 -05:00
### Parameters
2023-01-10 12:06:40 -05:00
2023-01-09 14:37:40 -05:00
- `request-id` The key of the request.
- `method` The HTTP method of the request.
- `body` The body of the request.
2023-01-14 09:47:51 -05:00
### Example
2023-01-10 12:06:40 -05:00
```lsl
link_message(integer sender, integer num, string str, key id)
{
if (llJsonGetValue(str, ["method"]) == "prim-dns:request")
2023-01-13 19:49:01 -05:00
{
key request_id = (key) llJsonGetValue(str, ["params", "request-id"]);
string params = llList2Json(JSON_OBJECT, [
"request-id", request_id,
"status", 200,
"body", "Hello, world!"
]);
string message = llList2Json(JSON_OBJECT, [
"method", "prim-dns:response",
"params", params
]);
llMessageLinked(sender, 0, message, NULL_KEY);
2023-01-10 12:06:40 -05:00
}
}
```
2023-01-14 09:47:51 -05:00
## prim-dns:set-content-type (request-id, content-type)
2023-01-09 14:37:40 -05:00
Set the content type of the response.
2023-01-14 09:47:51 -05:00
### Parameters
2023-01-10 12:06:40 -05:00
2023-01-09 14:37:40 -05:00
- `request-id` The key of the request to set the response content type for.
- `content-type` One of the supported content type constants.
2023-01-14 09:47:51 -05:00
### Example
2023-01-09 14:37:40 -05:00
```lsl
string params = llList2Json(JSON_OBJECT, [
"request-id", request_id,
"content-type", CONTENT_TYPE_HTML
]);
string message = llList2Json(JSON_OBJECT, [
"method", "prim-dns:set-content-type",
"params", params
]);
llMessageLinked(LINK_THIS, 0, message, NULL_KEY);
```
2023-01-14 09:47:51 -05:00
## prim-dns:response (request-id, status, body)
2023-01-09 14:37:40 -05:00
Send the response.
2023-01-14 09:47:51 -05:00
### Parameters
2023-01-10 12:06:40 -05:00
2023-01-09 14:37:40 -05:00
- `request-id` The key of the request to respond to.
- `status` The HTTP status code of the response.
- `body` The body of the response.
2023-01-14 09:47:51 -05:00
### Example
2023-01-09 14:37:40 -05:00
```lsl
string params = llList2Json(JSON_OBJECT, [
"request-id", request_id,
"status", 200,
"body", "Hello, world!"
]);
string message = llList2son(JSON_OBJECT, [
"method", "prim-dns:response",
"params", params
]);
llMessageLinked(LINK_THIS, 0, message, NULL_KEY);
```
2023-01-14 09:47:51 -05:00
## prim-dns:reboot ()
2023-01-09 14:37:40 -05:00
Reboot the prim-dns server.
2023-01-14 09:47:51 -05:00
### Example
2023-01-09 14:37:40 -05:00
```lsl
string message = llList2Json(JSON_OBJECT, [
"method", "prim-dns:reboot"
]);
llMessageLinked(LINK_THIS, 0, message, NULL_KEY);
```
2023-01-14 09:47:51 -05:00
## prim-dns:shutdown ()
2023-01-09 14:37:40 -05:00
Shut down the prim-dns server.
2023-01-14 09:47:51 -05:00
### Example
2023-01-09 14:37:40 -05:00
```lsl
string message = llList2Json(JSON_OBJECT, [
"method", "prim-dns:shutdown"
]);
llMessageLinked(LINK_THIS, 0, message, NULL_KEY);
```
2023-01-14 09:47:51 -05:00
## prim-dns:startup ()
2023-01-09 14:37:40 -05:00
Sent when the prim-dns server finishes reading the configuration and is waiting to continue starting up. If auto_start = 1, then the server will immediately continue, otherwise it will wait for the prim-dns:start messsage.
2023-01-14 09:47:51 -05:00
### Example
2023-01-10 12:06:40 -05:00
```lsl
link_message(integer sender, integer num, string str, key id)
{
if (llJsonGetValue(str, ["method"]) == "prim-dns:startup")
{
llOwnerSay("The prim-dns server is now waiting to start.");
}
}
```
2023-01-14 09:47:51 -05:00
## prim-dns:start ()
2023-01-09 14:37:40 -05:00
Tell the prim-dns server to complete its startup.
2023-01-14 09:47:51 -05:00
### Example
2023-01-10 12:06:40 -05:00
2023-01-09 14:37:40 -05:00
```lsl
string message = llList2Json(JSON_OBJECT, [
"method", "prim-dns:start"
]);
llMessageLinked(LINK_THIS, 0, message, NULL_KEY);
```
2023-01-10 12:06:40 -05:00
2023-01-14 09:47:51 -05:00
## prim-dns:url-request-granted (url)
2023-01-10 12:06:40 -05:00
Sent when the prim-dns server is granted a temporary URL by the region.
2023-01-14 09:47:51 -05:00
### Parameters
2023-01-10 12:06:40 -05:00
- `url` The temporary URL assigned to the script.
2023-01-14 09:47:51 -05:00
### Example
2023-01-10 12:06:40 -05:00
```lsl
link_message(integer sender, integer num, string str, key id)
{
if (llJsonGetValue(str, ["method"]) == "prim-dns:url-request-granted")
2023-01-10 12:11:11 -05:00
{
llOwnerSay("The prim-dns server was granted a URL: " + llJsonGetValue(str, ["params", "url"]));
}
}
```
2023-01-14 09:47:51 -05:00
## prim-dns:alias-registered (alias)
2023-01-10 12:11:11 -05:00
Sent when the prim-dns server successfully registers or updates its alias.
2023-01-14 09:47:51 -05:00
### Parameters
2023-01-10 12:11:11 -05:00
- `alias` The endpoint URL of the registered alias.
2023-01-14 09:47:51 -05:00
### Example
2023-01-10 12:11:11 -05:00
```lsl
link_message(integer sender, integer num, string str, key id)
{
if (llJsonGetValue(str, ["method"]) == "prim-dns:alias-registered")
2023-01-10 12:06:40 -05:00
{
2023-01-10 12:11:11 -05:00
llOwnerSay("The alias was successfully registered: " + llJsonGetValue(str, ["params", "alias"]));
2023-01-10 12:06:40 -05:00
}
}
```
2023-01-17 08:47:21 -05:00
## prim-dns:shutting-down ()
Sent when the prim-dns server is shutting down.
### Example
```lsl
link_message(integer sender, integer num, string str, key id)
{
if (llJsonGetValue(str, ["method"]) == "prim-dns:shutting-down")
{
llOwnerSay("The prim-dns server is shutting down.");
}
}
```