Skip to content
Snippets Groups Projects
Commit 42f86991 authored by mcmlxxix's avatar mcmlxxix
Browse files

attach user alias and system name to shared-object subscriptions

parent b25da445
No related branches found
No related tags found
No related merge requests found
......@@ -107,14 +107,16 @@ function JSONClient(serverAddr,serverPort) {
this.subscribe=function(scope,location) {
this.send(scope,"QUERY",{
oper:"SUBSCRIBE",
location:location,
nick:user?user.alias:undefined,
system:system?system.name:undefined,
location:location
});
}
this.unsubscribe=function(scope,location) {
this.send(scope,"QUERY",{
oper:"UNSUBSCRIBE",
location:location,
location:location
});
}
......
......@@ -73,11 +73,10 @@ function JSONdb (fileName) {
KEEP_READABLE:false,
READ_ONLY:false,
UPDATES:false,
};
/* error constants */
this.errors = {
/* error constants */
INVALID_REQUEST:0,
OBJECT_NOT_FOUND:1,
NOT_LOCKED:2,
......@@ -87,7 +86,7 @@ function JSONdb (fileName) {
DUPLICATE_SUB:6,
NON_ARRAY:7,
READ_ONLY:8
}
};
/*************************** database methods ****************************/
/* subscribe a client to an object */
......@@ -350,13 +349,14 @@ function JSONdb (fileName) {
/* return a list of subscriptions and associated IP address for clients */
this.who = function(client,record) {
var data = [];
for each(var s in record.info.subscribers) {
if(!data[s.remote_ip_address])
data[s.remote_ip_address] = [];
data[s.remote_ip_address].push(
record.location
);
}
for each(var s in record.shadow[record.child_name]._subscribers) {
data.push({
id:s.id,
nick:s.nick,
system:s.system
});
}
log(data.toSource());
send_packet(client,data,"RESPONSE");
return true;
}
......@@ -378,6 +378,16 @@ function JSONdb (fileName) {
/* temporary array for queue additions */
var q=[];
/* if there is a username supplied, attach it to the client object */
if(query.nick !== undefined) {
client.nick = query.nick;
}
/* if there is a username supplied, attach it to the client object */
if(query.system !== undefined) {
client.system = query.system;
}
/* if an operation is requested */
if(query.oper !== undefined) {
request = new Request(client,query.oper,parent_name,child_name,query.data);
......@@ -396,6 +406,7 @@ function JSONdb (fileName) {
client,"LOCK",parent_name,child_name,this.settings.LOCK_UNLOCK
));
}
/* add the temporary queue to the main queue */
this.queue=this.queue.concat(q);
}
......@@ -623,7 +634,7 @@ function JSONdb (fileName) {
this.info=info;
}
/* request object generated by Database.queue() method
/* request object generated by queue() method
contains the requested object parent, the specific child property requested,
data (in the case of a PUT operation ) */
function Request(client,operation,parent_name,child_name,data) {
......@@ -811,4 +822,3 @@ function JSONdb (fileName) {
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment