PolCPP avatar PolCPP committed e4e9532

A Quick and dirty cli client.
Updated the proxy to request 205 packets and print them (initial chat support)
Tiny fixes here and there

Comments (0)

Files changed (6)

cli_client.coffee

+###
+ 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.
+
+ Vesperia Command line client:
+ It has 2 modes. Direct connection and proxied. 
+ Default mode is proxied, you can change it via parameters
+###
+
+crypto = require "crypto"
+net = require 'net'
+
+# Configuration
+
+# The host and port from the tethealla server or proxy server
+host = "127.0.0.1"
+port = "9825"
+
+#Api hash is required for proxied connection auth, remember to set one that's on the proxy db 
+api_hash = "2925b6b28d87e54fe773586b7b6025f6"
+
+# UID is and unique id since we'll be emulating the proxy. It uses the same method as the server
+# to generate a unique md5 string
+uid =  crypto.createHash("md5").update((new Date().getTime()+Math.floor(Math.random()*1000)).toString()).digest("hex")
+
+# End of configuration.
+ConnectionModes = 
+  direct: 1
+  proxied: 2
+
+mode = ConnectionModes.direct
+command = ""
+pass = ""
+
+
+connection = net.createConnection port, host
+
+connection.on 'connect',  ->
+  console.log "Opened connection to #{host}:#{port}"
+  connection.write "110test"
+
+connection.on 'data', (data) ->
+  if data.toString() == "102" 
+    connection.write "210happyhour" 
+    console.log "Received: #{data}"
+
   stream: false
   events: false
 
-  constructor: (@net, @port, @host) ->
+  constructor: (@net, @port, @host, @ask_chat) ->
 
   ###
   Initializes the client
     this.events.on 'message', (message) -> 
       console.log "Recieved message: '#{message}'"
 
-  onConnect: (socket) -> 
-    this.client.attempts = 0
+  onConnect: -> 
+    this.client.attempts = 1
     this.client.connected = true
+    this.write "205"
     console.log "Connected"
 
   onData: (data)  ->
       setTimeout ( ->
         client.reconnect()
       ), settings.attemptWait
+    else
+      this.client.attempts = 1; 
 
   onEnd: ->
     client = this.client
 console.log "# Check LICENSE.MIT for more details"
 console.log "############################################################"
 
+ask_chat = false
+
+if process.argv.length == 2 && process.argv[0] != "coffee"
+  ask_chat = true
+
+if process.argv.length == 3 && process.argv[0] == "coffee" 
+  ask_chat = true
+
 connection = mysql.createConnection settings.dbConnection
 
-client = new tethClient.client net, settings.tetheallaPort, settings.tetheallaHost
+client = new tethClient.client net, settings.tetheallaPort, settings.tetheallaHost, ask_chat
 client.initialize()
 
 server = new vespServer.Server net, settings.vesperiaPort, settings.vesperiaHost, connection, client

mock/mockTethealla.coffee

-###
- 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()
-    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

mock/tethealla.coffee

+###
+ 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
   _startSocket: (socket) -> 
     socket.authenticated = false
     socket.uid = false
-    socket.write "407"
+    socket.write "100"
     socket.on 'data', (data) -> gServer._onData this,data.toString().replace("\n","")
 
   _onData: (socket, data) ->
       message = data.substring 35, data.length
       if gServer.clients[uid] != "undefined"
         gServer.clients[uid].write message
+    else
+      console.log data.toString()
 
   _sendToTethealla: (socket,action) ->    
     if gServer.client
-      gServer.client.stream.write "200"+socket.uid+action
-
+      if gServer.client.connected
+        gServer.client.stream.write "200"+socket.uid+action
+      else
+        gServer.client.reconnect()        
+        socket.write "202"
 
 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.