-
Notifications
You must be signed in to change notification settings - Fork 0
/
music-controller.lsl
162 lines (146 loc) · 5.14 KB
/
music-controller.lsl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
integer group_only = TRUE; //Change to false for OwnerOnly control
string note_name = "stations";
integer note_line;
string station_name = "none";
list station_names;
list station_urls;
integer page_num;
integer page_count;
integer ready;
integer menu_channel;
integer input_handle;
key waiting_from;
show(key avatar, integer page)
{
waiting_from = avatar;
integer start = (9 * page) - !!page;
list menu = ["<<", "URL", ">>"] + llList2List(station_names, start, start + 8);
llDialog(avatar, "Welcome " + llGetDisplayName(llDetectedKey(0)) + ", \nCurrent station: " + station_name, menu, menu_channel);
llSetTimerEvent(44);
}
default
{
touch_start(integer n)
{
if (!ready) return;
key avatar = llDetectedKey(0);
if (avatar == llGetOwner() || // owner
!group_only || // anybody
(group_only && llSameGroup(avatar))) // any group member
{
show(avatar, page_num = 0);
}
else llInstantMessage(avatar, "You're not allowed to use this.");
}
listen(integer chat, string _, key avatar, string input)
{
// Next page with roll-over
if (input == ">>")
{
if (++page_num >= page_count) page_num = 0;
show(avatar, page_num);
}
// Last page with roll-over
else if (input == "<<")
{
if (--page_num < 0) page_num = page_count - 1;
show(avatar, page_num);
}
// Initiate user-input
else if (input == "URL")
{
waiting_from = avatar;
llListenRemove(input_handle); // Remove previous, if any
input_handle = llListen(menu_channel + 1, "", avatar, "");
llTextBox(avatar, "Enter a stream URL", menu_channel + 1);
llSetTimerEvent(30);
}
// Parse user-input
else if (chat == menu_channel + 1)
{
if (llSubStringIndex(input, ".") == -1)
{
llInstantMessage(avatar, "I don't think that's a real URL.");
return;
}
if (llSubStringIndex(input, "://") == -1) input = "http://" + input;
station_name = "custom choice";
llSetParcelMusicURL(input);
llInstantMessage(avatar, "Now listening to \"" + station_name + "\"");
llListenRemove(input_handle);
waiting_from = NULL_KEY;
llSetTimerEvent(0);
}
else
{
integer index = llListFindList(station_names, (list)input);
if (index == -1)
{
llInstantMessage(avatar, "I am not sure how you got here, but I will find you and I will have tea with you :3");
return;
}
station_name = llList2String(station_names, index);
llSetParcelMusicURL(llList2String(station_urls, index));
llInstantMessage(avatar, "Now listening to \"" + station_name + "\"");
llSetTimerEvent(0);
}
}
timer()
{
llInstantMessage(waiting_from, "The menu has timed out.");
llListenRemove(input_handle);
waiting_from = NULL_KEY;
llSetTimerEvent(0);
}
// Changed/state_entry/dataserver are only used to initialize the script.
// The main functionality is in touch_start/listen/timer.
changed(integer change)
{
if (change & CHANGED_OWNER ||
change & CHANGED_INVENTORY)
llResetScript();
}
state_entry()
{
if (llGetInventoryType(note_name) == INVENTORY_NOTECARD)
{
llOwnerSay("Loading stations...");
llGetNotecardLine(note_name, note_line);
}
else llOwnerSay("No \"" + note_name + "\" notecard was found.");
}
// Parse a notecard in this format:
// Menu button name;Station stream url
dataserver(key id, string data)
{
if (data == EOF)
{
page_count = 1 + llGetListLength(station_urls) / 9;
menu_channel = (integer)("0x" + llGetSubString(llGetKey(), 0, 7));
llListen(menu_channel, "", "", "");
ready = TRUE;
llOwnerSay((string)llGetListLength(station_urls) + " stations have successfuly been registered.");
}
else
{
string first = llGetSubString(data, 0, 0);
if (first != "#" && first != "")
{
integer separator = llSubStringIndex(data, ";");
if (separator == -1)
{
llOwnerSay("Missing \";\" on line " + (string)(note_line + 1));
llGetNotecardLine(note_name, ++note_line);
return;
}
string button = llGetSubString(data, 0, separator - 1);
button = llGetSubString(button, 0, 11);
string url = llGetSubString(data, separator + 1, -1);
if (llSubStringIndex(url, "://") == -1) url = "http://" + url;
station_names += button;
station_urls += url;
}
llGetNotecardLine(note_name, ++note_line);
}
}
}