Join us in Phaze Demesnes or follow us:

Home   Show All
Category: Contributor: Creator
Updater UpdateSubscriber  

UpdateSubscriber

UpdateSubscriber 1.lsl

Category: Updater
By : Emma Nowhere
Created: 2010-01-10 Edited: 2010-01-10
Worlds: Second Life + OpenSim

the Zip file

Download all files for UpdateSubscriber
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. UpdateSubscriber_1_1.lsl
1
2 //////////////////////////////////////////////////////////////////////////////////////
3 //
4 // UpdateSubscriber
5 // Version 1.01 Release
6 // Copyright (C) 2007, Emma Nowhere
7 // emma.nowhere@yahoo.com
8 //
9 // Place inside a prim that you want to receive object updates from an
10 // UpdateServer. You should have your UpdateServer already set up
11 // before adding this script to a prim.
12 //
13 // At startup the script will broadcast a request for all UpdateServers
14 // in the region and output the results to you.
15 //
16 // You need to register with a specific UpdateServer to enable updates
17 // to be received.
18 //
19 // To lock onto a specific UpdateServer, type:
20 //
21 // /128 UpdateSubscriberRegister <subscriberkey> <serverkey>
22 //
23 // where <subscriberkey> is the key of the prin containing the script
24 // and <serverkey> is the key shown next to the UpdateServer name that is
25 // displayed when this script displays the available UpdateServers in
26 // the region.
27 //
28 // License:
29 //
30 // This library is free software; you can redistribute it and/or
31 // modify it under the terms of the GNU Lesser General Public License
32 // as published by the Free Software Foundation; either
33 // version 2.1 of the License, or (at your option) any later version.
34 //
35 // This library is distributed in the hope that it will be useful,
36 // but WITHOUT ANY WARRANTY; without even the implied warranty of
37 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
38 // GNU Lesser General Public License for more details.
39 //
40 // You should have received a copy of the GNU Lesser General Public License
41 // along with this library; if not, write to the Free Software
42 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
43 //
44 //////////////////////////////////////////////////////////////////////////////////////
45
46 integer listenChannel = 128;
47 integer listenHandle = 0;
48 string scriptName;
49 key subscriberKey;
50 key serverKey;
51 integer registered = FALSE;
52
53 integer containsItem(string itemName) {
54
57 for (i = 0; i < total; i++) {
59 if ((name != scriptName) && (itemName == name)) return TRUE;
60 }
61 return FALSE;
62 }
63
64 default {
65
66 state_entry() {
67
68 scriptName = llGetScriptName();
69 subscriberKey = llGetKey();
70
71 llSay(0, "UpdateSubscriber installed in object " + llGetObjectName() + " (" + (string)subscriberKey + ")");
72 listenHandle = llListen(listenChannel, "", NULL_KEY, "");
73
74 llSay(0, "UpdateSubscriber listening on channel #" + (string)listenChannel);
75 llRegionSay(listenChannel, "UpdateServersQuery");
76 }
77
78 listen(integer channel, string name, key id, string message) {
79
80 list parsed = llParseString2List(message, [" "], []);
81 integer l = llGetListLength(parsed);
82 if (l == 0) return;
83
84 string command = llList2String(parsed, 0);
85
86 if (!registered) {
87
88 if ((l == 3) && (command == "UpdateSubscriberRegister")) {
89
90 if ((key)llList2String(parsed, 1) != subscriberKey) return;
91
92 serverKey = (key)llList2String(parsed, 2);
93
94 llListenRemove(listenHandle);
95
96 listenHandle = llListen(listenChannel, "", serverKey, "");
97
98 llSay(0, "Registered to Update Server " + llKey2Name(serverKey) + " (" + (string)serverKey + ")");
99
100 registered = TRUE;
101 }
102 else if ((l == 2) && (command == "UpdateServerAvailable")) {
103
104 key serverKey = (key)llList2String(parsed, 1);
105
106 string msg = "Update Server available:\n" + llKey2Name(serverKey) + " (" + (string)serverKey + ")\n\n" +
107 "Copy and paste the following line to register to this server:\n\n" +
108 "/128 UpdateSubscriberRegister " + (string)subscriberKey + " " + (string)serverKey + "\n\n";
109
110 llSay(0, msg);
111 }
112
113
114 return;
115 }
116
117
118 if ((l == 2) && (command == "UpdateAvailable")) {
119
120 string itemName = llUnescapeURL(llList2String(parsed, 1));
121
122 if (containsItem(itemName)) {
123
124 llSay(0, "Deleting old version of item " + itemName);
125 llRemoveInventory(itemName);
126
127 llSay(0, "Requesting new version of item " + itemName);
128 llRegionSay(listenChannel, "UpdateRequest " + llEscapeURL(itemName) + " " + (string)subscriberKey + " " + (string)serverKey);
129 }
130 }
131 else if ((l == 2) && (command == "UpdateSubscribersQuery")) {
132
133 key serverKey = (key)llList2String(parsed, 1);
134
135 llRegionSay(listenChannel, "UpdateSubscriberRegistered " + (string)serverKey + " " + (string)subscriberKey);
136 }
137
138 }
139
140 }
141 // END //