Browse Source

Remove external grab into the object

This change removes server object interacting with an internal variable
from the user object creation and reduces the amount of code from 3 to 1
line. This also simplifies future testing.
test/user
Sheogorath 5 years ago
parent
commit
b7bc3f3d4c
No known key found for this signature in database GPG Key ID: 1F05CC3635CDDFFD
  1. 5
      src/server.js
  2. 4
      src/user.js

5
src/server.js

@ -23,10 +23,7 @@ server.create = function create(config = {}) {
let userlist = {} let userlist = {}
let channellist = {} let channellist = {}
let server = net.createServer((socket) => { let server = net.createServer((socket) => {
const user = new User(socket)
if (!config.password) {
user.authenticated = true
}
const user = new User(socket, !config.password)
socket.on('data', function (data) { socket.on('data', function (data) {
data.toString("ascii").split("\r\n").forEach(function (commandline) { data.toString("ascii").split("\r\n").forEach(function (commandline) {
if (commandline == "") { if (commandline == "") {

4
src/user.js

@ -1,6 +1,6 @@
function User(socket) {
function User(socket, authenticatedDefault) {
this.registered = false this.registered = false
this.authenticated = false
this.authenticated = authenticatedDefault
this.nickname = "" this.nickname = ""
this.connection = socket this.connection = socket
this.realname = "" this.realname = ""

Loading…
Cancel
Save