 		destId: @destId
 		message: @message
 		read: @read
+		id: @id
+
+	toString: -> JSON.stringify @toJSON()
 
 getMessageById = (id) ->
 	return msg for msg in messageRegistry when msg.id is id

			socket.emit 'failure', 'bad password'
			return
		user.onConnect socket
		socket.emit 'success', {}
		for handler in eventHandlers
			socket.on handler.expectedType, (data) ->
				if not connectionIsLoggedIn socket
					socket.emit 'failure', 'You are not logged in'
					socket.disconnect()
					return
				source = getUserBySocketID socket.id
				if not source.isQualifiedFor handler.expectedPerm
					source.send 'failure', "You are not qualified to '#{handler.expectedType}', \
						required power level is #{handler.expectedPerm}, you have #{source.powerLevel}"
					return
				if not data[arg]? for arg in handler.expectedArgs
					source.send 'failure', "Missing arguments; expected #{handler.expectedArgs.join ', '}"
					return
				result = handler.onMessage data, source
				if not (result instanceof Array) or result.length isnt 2
					KcCoreLogger.error "Unexpected result from #{handler.expectedType} eventHandler: #{result}, expected 2-element array"
					source.send 'failure', 'Server internal error, please report to the owners'
					return
				source.send result[0], result[1]
	socket.on 'disconnect', ->
		source = getUserBySocketID socket.id
		source.onDisconnect() if source?

		expectedPerm: UserPowerLevels.admin
		expectedArgs: ['id', 'auth', 'powerLevel']
		onMessage: (msg, source) ->
			(return fail "#{msg.id} exists") if containsUser msg.id
			userRegistry.push new User msg.id, msg.powerLevel, Modules.sha msg.auth
			onUserModification()
			return succeed "#{msg.id} created"
	}
]
