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

flatten queries to single-level object

parent c562b2b4
No related branches found
No related tags found
No related merge requests found
...@@ -264,20 +264,20 @@ chat = new (function() { ...@@ -264,20 +264,20 @@ chat = new (function() {
this.process = function(client,packet) { this.process = function(client,packet) {
switch(packet.func.toUpperCase()) { switch(packet.func.toUpperCase()) {
case "IDENT": case "IDENT":
this.ident(client,packet.data); this.ident(client,packet);
break; break;
case "BAN": case "BAN":
if(!admin.verify(client,packet,90)) if(!admin.verify(client,packet,90))
break; break;
this.ban(client,packet.data.ip); this.ban(client,packet.ip);
break; break;
case "UNBAN": case "UNBAN":
if(!admin.verify(client,packet,90)) if(!admin.verify(client,packet,90))
break; break;
this.unban(client,packet.data.ip); this.unban(client,packet.ip);
break; break;
case "QUERY": case "QUERY":
this.db.query(client,packet.data); this.db.query(client,packet);
break; break;
default: default:
error(client,errors.UNKNOWN_FUNCTION,packet.func); error(client,errors.UNKNOWN_FUNCTION,packet.func);
...@@ -332,7 +332,7 @@ admin = new (function() { ...@@ -332,7 +332,7 @@ admin = new (function() {
this.process = function(client,packet) { this.process = function(client,packet) {
switch(packet.func.toUpperCase()) { switch(packet.func.toUpperCase()) {
case "IDENT": case "IDENT":
this.ident(client,packet.data); this.ident(client,packet);
break; break;
case "RESTART": case "RESTART":
if(!this.verify(client,packet,90)) if(!this.verify(client,packet,90))
...@@ -342,12 +342,12 @@ admin = new (function() { ...@@ -342,12 +342,12 @@ admin = new (function() {
case "BAN": case "BAN":
if(!this.verify(client,packet,90)) if(!this.verify(client,packet,90))
break; break;
this.ban(client,packet.data.ip); this.ban(client,packet.ip);
break; break;
case "UNBAN": case "UNBAN":
if(!this.verify(client,packet,90)) if(!this.verify(client,packet,90))
break; break;
this.unban(client,packet.data.ip); this.unban(client,packet.ip);
break; break;
case "CLOSE": case "CLOSE":
if(!this.verify(client,packet,90)) if(!this.verify(client,packet,90))
...@@ -364,12 +364,23 @@ admin = new (function() { ...@@ -364,12 +364,23 @@ admin = new (function() {
break; break;
this.modules(client); this.modules(client);
break; break;
case "TIME":
this.time(client);
break;
default: default:
error(client,errors.UNKNOWN_FUNCTION,packet.func); error(client,errors.UNKNOWN_FUNCTION,packet.func);
break; break;
} }
} }
/* release a socket from the list of authenticated users */ /* release a socket from the list of authenticated users */
this.time = function(client) {
client.sendJSON({
scope:undefined,
func:"RESPONSE",
oper:"TIME",
data:time()
});
}
this.release = function(client) { this.release = function(client) {
if(this.authenticated[client.id]) { if(this.authenticated[client.id]) {
log(LOG_DEBUG,"releasing auth: " + client.id); log(LOG_DEBUG,"releasing auth: " + client.id);
...@@ -485,7 +496,7 @@ engine = new (function() { ...@@ -485,7 +496,7 @@ engine = new (function() {
error(client,errors.NOT_AUTHORIZED,packet.func); error(client,errors.NOT_AUTHORIZED,packet.func);
break; break;
} }
module.db.query(client,packet.data); module.db.query(client,packet);
break; break;
case "IDENT": case "IDENT":
break; break;
...@@ -538,12 +549,12 @@ engine = new (function() { ...@@ -538,12 +549,12 @@ engine = new (function() {
/* verify a client's access to queries */ /* verify a client's access to queries */
this.verify = function(client,packet,module) { this.verify = function(client,packet,module) {
switch(packet.data.oper) { switch(packet.oper) {
case "READ": case "READ":
case "SLICE": case "SLICE":
if(module.read > 0) { if(module.read > 0) {
if(!admin.verify(client,packet,module.read)) { if(!admin.verify(client,packet,module.read)) {
error(client,errors.NOT_AUTHORIZED,packet.data.oper); error(client,errors.NOT_AUTHORIZED,packet.oper);
return false; return false;
} }
} }
...@@ -556,7 +567,7 @@ engine = new (function() { ...@@ -556,7 +567,7 @@ engine = new (function() {
case "DELETE": case "DELETE":
if(module.write > 0) { if(module.write > 0) {
if(!admin.verify(client,packet,module.write)) { if(!admin.verify(client,packet,module.write)) {
error(client,errors.NOT_AUTHORIZED,packet.data.oper); error(client,errors.NOT_AUTHORIZED,packet.oper);
return false; return false;
} }
} }
...@@ -583,7 +594,7 @@ engine = new (function() { ...@@ -583,7 +594,7 @@ engine = new (function() {
this.db; this.db;
this.init = function() { this.init = function() {
this.db=new JSONdb(this.dir+this.name+".json"); this.db=new JSONdb(this.dir+this.name+".json", this.name);
/* load module background service file */ /* load module background service file */
if(file_exists(this.dir + "service.js")) { if(file_exists(this.dir + "service.js")) {
try { try {
...@@ -615,7 +626,9 @@ error = function(client,err,value) { ...@@ -615,7 +626,9 @@ error = function(client,err,value) {
client.descriptor,desc client.descriptor,desc
)); ));
client.sendJSON({ client.sendJSON({
scope:undefined,
func:"ERROR", func:"ERROR",
oper:"ERROR",
data:{ data:{
description:desc, description:desc,
client:client.descriptor, client:client.descriptor,
...@@ -628,6 +641,7 @@ error = function(client,err,value) { ...@@ -628,6 +641,7 @@ error = function(client,err,value) {
confirm = function(client,message) { confirm = function(client,message) {
log(LOG_INFO,message); log(LOG_INFO,message);
client.sendJSON({ client.sendJSON({
scope:undefined,
func:"OK", func:"OK",
data:message data:message
}); });
...@@ -636,6 +650,7 @@ confirm = function(client,message) { ...@@ -636,6 +650,7 @@ confirm = function(client,message) {
/* packet request response to client */ /* packet request response to client */
respond = function(client,data) { respond = function(client,data) {
client.sendJSON({ client.sendJSON({
scope:undefined,
func:"RESPONSE", func:"RESPONSE",
data:data data:data
}); });
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment