-
Notifications
You must be signed in to change notification settings - Fork 0
/
amon.t.js
78 lines (71 loc) · 1.81 KB
/
amon.t.js
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
/**
* Created by Administrator on 14-7-9.
*/
var env=[];
function Amon(name){
var events=require('events');
this.event=new events.EventEmitter();
this.type='Amon';
this.name='amon';
if(name)this.name=name;
this.env=env;
this.env.push(this);
var this_=this;
this.event.on("say",function(msg){
if(typeof(msg)==='object'){
console.log(this_.name+' get msg:');
console.log('{');
for(var key in msg){
console.log('"'+key+'":'+msg[key]);
}
console.log('}');
}else{
console.log(''+msg);
}
if(typeof (msg)==='object'){
console.log("is handle msg begin..."+msg);
for(var i=this_.env.length-1;i>=0;i--){
console.log('my type:'+this_.env[i].type);
console.log('my name:'+this_.env[i].name);
}
console.log("is handle msg end..."+msg);
}else{
console.log("unknow msg:"+msg);
}
console.log("say恭喜,处理完毕!");
});
this.hi=function(){
console.log('hi');
}
this.say=function(msg){
this.event.emit('say',msg);
}
}
function hash(obj){
var str='';
if(typeof (obj)==='object'){
for(var key in obj){
str+=''+key+obj[key];
}
}else{
str=""+obj;
}
prime=key=str;
str=str+"";
var h = 0, off = 0;
var len = str.length;
for(var i = 0; i < len; i++){
h = 31 * h + str.charCodeAt(off++);
if(h>0x7fffffff || h<0x80000000){
h=h & 0xffffffff;
}
}
return h;
}
var am=new Amon('123456');
var a=require('crypto').randomBytes(16, function(ex, buf) {
var token = buf.toString('hex');
console.log(token);
});
console.log();
module.exports=Amon;