Skip to content
Snippets Groups Projects
Commit 75ac847a authored by deuce's avatar deuce
Browse files

Add a hotline client for the BBS.

Currently does not support chat, uploading, or posting messages.
parent 61c6474a
No related branches found
No related tags found
No related merge requests found
load("hotline_funcs.js");
function rage_quit(reason)
{
log(LOG_DEBUG, "Rage quit: "+reason);
client.socket.close();
exit();
}
function null_str(len)
{
var i;
var ret='';
for (i=0; i<len; i++) {
ret += '\x00';
}
return ret;
}
var protocol = client.socket.recvBin(4);
if (protocol != 0x48545846)
rage_quit("Incorrect protocol specifier");
var ref = client.socket.recvBin(4);
var size = client.socket.recvBin(4);
client.socket.recvBin(4);
var f = new File(system.temp_dir+'hotline.transfers');
var path;
if (f.open("r+b")) {
var lines=f.readAll(2048);
var i;
for (i in lines) {
var m = lines[i].match(/^([0-9]+) ([^\s]+) ([0-9]+) (.*)$/);
if (m == null)
rage_quit("Unable to parse line "+lines[i]);
if (parseInt(m[1], 10) == ref && m[2] == client.ip_address) {
lines.splice(i, 1);
path = m[4];
break;
}
}
f.truncate();
f.writeAll(lines);
f.close();
if (path == undefined)
rage_quit("Unable to find reference number");
}
else
rage_quit("Unable to open hotline.transfers");
f = new File(path);
// Flat file header
client.socket.write('FILP'+encode_short(1)+null_str(16)+encode_short(2));
// Information fork header
client.socket.write('INFO'+encode_long(0)+null_str(4)+encode_long(94));
// Informmation fork
client.socket.write('AMACTYPECREA'+encode_long(0)+encode_long(0x100)+null_str(32)+time_to_timestamp(f.date)+time_to_timestamp(f.date)+encode_short(0)+encode_short(3)+'hxd\x00\x11 ');
// Data fork header
client.socket.write('DATA'+encode_long(0)+null_str(4)+encode_long(f.length));
// Data fork
client.socket.sendfile(path);
for(i=0; i<30; i++) {
if(!client.socket.is_connected)
break;
mswait(1000);
}
This diff is collapsed.
function time_to_timestamp(time)
{
var ret ='';
var d = new Date(time*1000);
var y = new Date(time*1000);
y.setMonth(0);
y.setDate(1);
y.setHours(0);
y.setMinutes(0);
y.setSeconds(0);
y.setMilliseconds(0);
ret = encode_short(d.getYear()+1900);
ret += encode_short(0);
ret += encode_long((d.valueOf()-y.valueOf())/1000);
return ret;
}
function decode_integer(val)
{
var ret = 0;
while(val.length) {
ret <<= 8;
ret += ascii(val.substr(0,1));
val = val.substr(1);
}
return ret;
}
function encode_integer(val)
{
var ret ='';
val = parseInt(val, 10);
if (val < 0)
val = Math.pow(2, 32) + val;
while(val) {
ret = ascii(val & 0xff)+ret;
// We can't shift here or it will convert to 32-bit signed first.
val = Math.floor(val/256);
}
while (ret.length < 2)
ret = ascii(0)+ret;
if (ret.length == 3)
ret = ascii(0)+ret;
if (ret.length == 1 || ret.length == 0 || ret.length == 3 || ret.length > 4)
rage_quit("Invalid int length!");
return ret;
}
function encode_long(val)
{
var ret= encode_integer(val);
while (ret.length < 4)
ret = ascii(0)+ret;
return ret;
}
function encode_short(val)
{
var ret = encode_integer(val);
if (ret.length > 2)
rage_quit("Integer too long!");
return ret;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment