user.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. var user = function(){
  2. this.name = null;
  3. this.TS = null;
  4. this.ident = null;
  5. this.host = null;
  6. this.account = null;
  7. this.umodes = {};
  8. this.vhost = null;
  9. this.cloakedHost = null;
  10. this.ip = null;
  11. this.realname = null;
  12. this.uid = null;
  13. this.distance = null;
  14. this.uplink = null;
  15. this.secure = false;
  16. this.certfp = null;
  17. this.vident = null;
  18. this.metadata = {};
  19. this.channels = [];
  20. this.events = {};
  21. this.introduce = function(nick, distance, TS, ident, host, uid, account, umodes, vhost, cloakedHost, ip, realname, uplink){ // nick, distance, TS, ident, host, uid, account, umodes, vhost, cloakedHost, ip, realname, uplink
  22. this.name = nick;
  23. this.distance = distance;
  24. this.TS = TS;
  25. this.ident = ident;
  26. this.host = host;
  27. this.uid = uid;
  28. this.account = account;
  29. this.umodes = umodes;
  30. this.vhost = vhost;
  31. this.cloakedHost = cloakedHost;
  32. this.ip = ip;
  33. this.realname = realname;
  34. this.uplink = uplink;
  35. }
  36. this.setEvents = function(events){
  37. this.events = events;
  38. }
  39. this.setSecure = function(secure){
  40. this.secure = secure;
  41. }
  42. this.setFingerprint = function(certfp){
  43. this.certfp = certfp;
  44. }
  45. this.changeVHost = function(host){
  46. this.vhost = host;
  47. this.events.doEvent('userVHost', this);
  48. }
  49. this.changeVIdent = function(ident){
  50. this.vident = ident;
  51. this.events.doEvent('userVIdent', this);
  52. }
  53. this.setRealname = function(realname){
  54. this.realname = realname;
  55. this.events.doEvent('userRealname', this);
  56. }
  57. this.changeNick = function(nick){
  58. this.name = nick;
  59. this.events.doEvent('userNick', this);
  60. }
  61. this.changeUmodes = function(umodes){
  62. for(umode in umodes){
  63. this.umodes[umode] = umodes[umode];
  64. }
  65. this.events.doEvent('userUmode', this);
  66. }
  67. this.setMetadata = function(name, visibility, value){
  68. if(value){
  69. this.metadata[name] = { 'visibility': visibility, 'value': value };
  70. } else {
  71. if(name in this.metadata){
  72. delete this.metadata[name];
  73. }
  74. }
  75. this.events.doEvent('userMetadata', this, name);
  76. }
  77. this.joinChannel = function(channel){
  78. if(this.channels.indexOf(channel) < 0) this.channels.push(channel);
  79. }
  80. this.leaveChannel = function(channel){
  81. for(var i=0; i<this.channels.length; i++){
  82. if(this.channels[i] == channel){
  83. this.channels.splice(i, 1);
  84. break;
  85. }
  86. }
  87. }
  88. }
  89. module.exports = user;