Source

Vesperia / mock / tethealla.coffee

Full commit
###
 Vesperia: A Tethealla management port proxy and api server

 Copyright 2012 Pol Cámara
 Released under the MIT license
 Check LICENSE.MIT for more details.
###

# This is a little mock server that/will imitate tethealla mana port
net = require 'net'

domain = 'localhost'
port = 8825

server = net.createServer (socket) ->
  console.log "#{socket.remoteAddress} connected"

  socket.on 'data', (data) ->
    data = data.toString()
    console.log "Recieved: " + data
    if data.length > 35
      command = data.substring 0, 3
      uid = data.substring 3, 35
      action = data.substring 35, data.length
      if command == "200"
        socket.write "220" + uid + "Command ran successfully" 

console.log "Listening to #{domain}:#{port}"
server.listen port, domain