You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.2 KiB

  1. function User(socket) {
  2. this.registered = false
  3. this.authenticated = false
  4. this.nickname = ""
  5. this.connection = socket
  6. this.realname = ""
  7. this.username = ""
  8. this.setNickname = function(nickname) {
  9. this.nickname = nickname
  10. }
  11. this.getNickname = function(nickname) {
  12. return this.nickname
  13. }
  14. this.setPassword = function (password) {
  15. this.password = password
  16. }
  17. this.register = function(username, realname) {
  18. if (!this.authenticated) {
  19. this.connection.destroy()
  20. }
  21. this.username = username
  22. this.realname = realname
  23. this.registered = true
  24. }
  25. this.getAddress = function() {
  26. return this.connection.address().address
  27. }
  28. this.setNickname = function (nickname) {
  29. this.nickname = nickname
  30. }
  31. this.setRealName = function (realname) {
  32. this.realname = realname
  33. }
  34. this.closeConnection = function () {
  35. this.connection.destroy()
  36. }
  37. this.sendMsg = function (from, message) {
  38. this.sendRaw(`:${from.nickname} PRIVMSG ${this.nickname} :${message}`, "ascii")
  39. }
  40. this.sendRaw = function(message) {
  41. this.connection.write(`${message}\r\n`, "ascii")
  42. }
  43. }
  44. module.exports = User