// 2006.12.11 shoutMesh_broadcastNode string VERSION = "0.82"; integer G_CHANNEL = 4102; // send to generic devices (must be repeat-tolerant) integer I_CHANNEL = 4103; // intermediate packet channel // alternate, not for most devices integer S_CHANNEL = 4101; // send to shout-protocol-enabled device string BREAKER = "***"; integer gSListener; integer gGListener; integer gMsgId = 9999; // an incrementing value to provide unique packet ids. integer gDebug = 0; d(list debugList) { if(!gDebug) return; else { string s = (string)(debugList); llOwnerSay("(dbg) "+s); } } init() { // use our own position to generate a somewhat-unique // initial message Id. vector here = llGetPos(); gMsgId = ((integer)llFrand(100)) << 24; gMsgId += ((integer)here.x) << 16; gMsgId += ((integer)here.y) << 16; gMsgId += ((integer)here.z); llListenRemove(gSListener); llListenRemove(gGListener); gSListener = llListen(S_CHANNEL,"","",""); gGListener = llListen(G_CHANNEL,"","",""); llSay(0,"v" + VERSION + " ready, " + (string)llGetFreeMemory() + " words free."); } integer newMessageId() { return gMsgId++; } shout(integer channel,string message) { d(["shout@",channel,": ",message]); llShout(channel,message); } // commands to the node itself are processed here doCommand(string command,key av) { list messageL = llParseString2List(command,[" "],[]); string cmd = llToLower(llList2String(messageL,0)); integer arg1 = llList2Integer(messageL,1); string arg1S = llList2String(messageL,1); integer arg1OnOff = 0; if(llToLower(arg1S) == "on" || ((integer)arg1S > 0) || arg1S == "" ) arg1OnOff = 1; if(cmd == "debug") { gDebug = arg1OnOff; d(["debug is ",gDebug]); doMessage(G_CHANNEL,"4104 debug " + arg1S,av); } else if(cmd == "where") { doMessage(G_CHANNEL,"4104 where " + (string)arg1S,arg1S); } } // the initial broadcast format for a message // is ... . On S_CHANNEL means // destination uses shout-protocol. On G_CHANNEL, // message id delivered raw. doMessage(integer channel,string message,key av) { d(["doMessage(",channel,",",message,")"]); integer firstSpaceIndex = llSubStringIndex(message," "); integer deviceChannel = (integer)llGetSubString(message,0,firstSpaceIndex - 1); string deviceMessage = llGetSubString(message,firstSpaceIndex + 1,-1); if(deviceChannel > 0) { integer messageId = newMessageId(); string msgKind = "."; if(channel == S_CHANNEL) msgKind = "S"; else if(channel == G_CHANNEL) msgKind = "G"; string intermediatePacket = llDumpList2String([msgKind,deviceChannel,messageId,deviceMessage],BREAKER); shout(I_CHANNEL,intermediatePacket); } else doCommand(message,av); // see if its an local command. } default { on_rez(integer n) { init(); } state_entry() { init(); } touch_start(integer total_number) { } listen(integer channel,string name,key id,string message) { doMessage(channel,message,id); } timer() { } } // end of file