Created
August 4, 2011 16:56
-
-
Save adammw/1125621 to your computer and use it in GitHub Desktop.
Omegle Command Prompt Chat Client written in Node.JS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Omegle Command Prompt Chat Client | |
* ================================= | |
* Version 1.0 by adammw111 | |
* Requires Node.JS | |
*/ | |
var net = require('net'); | |
var OMEGLE_HOST = 'cardassia.omegle.com'; | |
var OMEGLE_PORT = 1365; | |
/** | |
* Create an Omegle packet | |
* @param tag (string) | |
* @param data (string) | |
* @return Buffer | |
*/ | |
function createPacket(tag, data) { | |
var taglen = Buffer.byteLength(tag); | |
var datalen = Buffer.byteLength(data); | |
var buf = new Buffer(taglen+datalen+3); | |
buf.writeUInt8(taglen, 0, 'big'); | |
buf.write(tag, 1, taglen); | |
buf.writeUInt16(datalen, taglen+1, 'big'); | |
buf.write(data, taglen+3, datalen); | |
return buf; | |
} | |
/** | |
* Parse an Omegle packet | |
* @param Buffer | |
* @return Object | |
*/ | |
function parsePacket(buf) { | |
var taglen = buf.readUInt8(0, 'big'); | |
var tag = buf.toString('utf8', 1, taglen+1); | |
var datalen = buf.readUInt16(taglen+1, 'big'); | |
var data = buf.toString('utf8', taglen+3, taglen+datalen+3); | |
return {tag: tag, data: data}; | |
} | |
// Buffer what we type in, only send on ENTER. | |
var messageBuffer = ""; | |
process.stdin.resume(); | |
process.stdin.setEncoding('utf8'); | |
// Connect to server | |
var socket = net.createConnection(OMEGLE_PORT, OMEGLE_HOST, function() { | |
console.log('Connected to Omegle chat server.'); | |
// Start by sending a omegleStart packet | |
socket.write(createPacket('omegleStart', 'web-flash')); | |
// Buffer what we type in, only send on ENTER. | |
process.stdin.on('data', function(chunk) { | |
messageBuffer += chunk; | |
if (chunk == "\r" || chunk == "\n") { | |
socket.write(createPacket('s', messageBuffer)); | |
messageBuffer = ""; | |
process.stdout.write("\n\rYou: "); | |
} else { | |
process.stdout.write(chunk); | |
} | |
}); | |
// Parse and respond to packets | |
socket.on('data', function(data) { | |
var pkt = parsePacket(data); | |
switch (pkt.tag) { | |
case 'w': | |
console.log('Waiting for stranger...'); | |
break; | |
case 'c': | |
console.log('Connected to stranger...'); | |
process.stdout.write("You: "); | |
break; | |
case 't': | |
process.stdout.write("\r\t\t\t\t\t\t(typing)\rYou: "+messageBuffer); | |
break; | |
case 'm': | |
process.stdout.write("\rStranger: "+pkt.data+"\nYou: "+messageBuffer); | |
break; | |
case 'd': | |
process.stdout.write("\r\nStranger disconnected\n"); | |
process.exit(0); | |
break; | |
case 'recaptchaRequired': | |
console.log('You need to prove your a real person. Use omegle in your web browser and fill out the capacha to continue chatting.'); | |
process.exit(2); | |
break; | |
default: | |
//console.log(pkt); | |
} | |
}); | |
// If the server disconnects us, quit. | |
socket.on('end', function() { | |
console.log('Server disconnected'); | |
process.exit(1); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment