PolCPP avatar PolCPP committed 5c6c513

Proxy working for "210" commands

Comments (0)

Files changed (2)

data/database.db

-15je8n2f	{"secret":"5ebe2294ecd0e0f08eab7690d2a6ee69"}
-1v8rb71g	{"secret":"5ebe2294ecd0e0f08eab7690d2a6ee69"}
-2eobnlah	{"secret":"5ebe2294ecd0e0f08eab7690d2a6ee69"}
-15je8n2f	
-1v8rb71g	
-2eobnlah	
-2hroj4o2	{"secret":"5ebe2294ecd0e0f08eab7690d2a6ee69"}
-3thrnv9e	{"secret":"5ebe2294ecd0e0f08eab7690d2a6ee69"}
 crypto = require "crypto"
 
 #The global var is used to jump from a socket to the server.
-
 gServer = false
 
 class Server
-  clients = []
-  socket = false
-  security = false
+  clients:  {}
+  socket: false
+  security: false
   constructor: (@net, @port, @host, @connection, @client) ->
     gServer = this
     this.security = new Security connection
-    this.client.events.on 'message', (message) ->
-      console.log "Nyan"
+    this.client.events.on 'message', (message) -> gServer._parseTethPacket(message)
       
-
   ###
   Initializes the server
   Example usage:
     server = this.net.createServer this._startSocket
     server.listen this.port, this.host
 
-  _startSocket: (socket) ->
+  _startSocket: (socket) -> 
     socket.authenticated = false
     socket.uid = false
     socket.write "407"
             socket.authenticated = true
             socket.uid =  crypto.createHash("md5").update((new Date().getTime()+Math.floor(Math.random()*1000)).toString()).digest("hex")
             socket.write "102"
+            gServer.clients[socket.uid] = socket
           else
             gServer._disconnectClient socket, "101"
       else
     return false
  
   _disconnectClient: (socket,code) ->
+    delete gServer.clients[socket.uid] if socket.uid
     socket.write(code)
     socket.end()
 
     switch command
       when "210" then gServer._sendToTethealla(socket,details)
 
+  _parseTethPacket: (data) ->
+    if data.length > 35
+      command = data.substring 0, 3
+      uid = data.substring 3, 35
+      message = data.substring 35, data.length
+      if gServer.clients[uid] != "undefined"
+        gServer.clients[uid].write message
+
   _sendToTethealla: (socket,action) ->    
     if gServer.client
-      console.log action
+      gServer.client.stream.write "200"+socket.uid+action
 
 
 module.exports.Server = Server
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.