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.

49 lines
1.1 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.register = function(username, realname) {
  15. if (!this.authenticated) {
  16. this.connection.destroy()
  17. }
  18. this.username = username
  19. this.realname = realname
  20. this.registered = true
  21. }
  22. this.getAddress = function() {
  23. return this.connection.address().address
  24. }
  25. this.setNickname = function (nickname) {
  26. this.nickname = nickname
  27. }
  28. this.setRealName = function (realname) {
  29. this.realname = realname
  30. }
  31. this.closeConnection = function () {
  32. this.connection.destroy()
  33. }
  34. this.sendMsg = function (from, message) {
  35. this.sendRaw(`:${from.nickname} PRIVMSG ${this.nickname} :${message}`, "ascii")
  36. }
  37. this.sendRaw = function(message) {
  38. this.connection.write(`${message}\r\n`, "ascii")
  39. }
  40. }
  41. module.exports = User