NMDC Bot
i've put together a quick DC bot in around 116 lines (include white spaced new lines but not including includes)
//
// Copyright (c) OverHertz Ltd.
// Permission is granted to modify and use this code with your projects.
// Compile Compatibility. Ziron 1.1.28.1+
//
program WIN32CUI 'DC-Bot';
#include 'ch.zir';
#include 'wsock32.zir';
#include 'dclib/dcutils.zir';
//consts (settings)
const BOTNAME = 'ZIRON';
const DC_TAG = '<ApexDC++ V:1.5.1,M:A,H:0/1/7,S:1>';
const HUBIP = '127.0.0.1';
const HUBPORT = 411;
////////////////////////////////////////////////////////
//useful macros
inline function strCompare(s1, s2) {
strCmp($s1, $s2);
$return eax;
}
//globals
WSADATA wsa_Data;
WSOCKET sock;
SOCKADDR_IN sin;
char buf1[2048], buf2[1024];
//code
sin.sin_addr = inet_addr(HUBIP);
sin.sin_family = AF_INET;
sin.sin_port = htons(HUBPORT);
WSAStartup(WSOCKVER2_2, @wsa_Data);
sock = socket(AF_INET, SOCK_STREAM, 0);
connect(sock, @sin, sizeof SOCKADDR_IN);
repeat {
buf1 = 0;
eax = 2048;
edi = @buf1;
@fill:
//begin receiving
eax = recv(sock, edi, eax, 0);
if (eax == -1) {
print('Connection closed\r\n');
break;
} elseif (eax == 0) {
print('Connection closed\r\n');
break;
}
char[edi+eax] = 0;
edi = @buf1;
eax = strLen(@buf1);
dl = [edi+eax-1];
if (dl <> "|") {
edi += eax;
edx = 2048;
edx -= eax;
eax = edx;
goto @fill;
}
if (char*[edi] == "$Loc" and word[edi+4] == "k ") {
edi += 6;
eax = strOffset(edi, '|');
[eax] = 0;
eax = DC_LockToKey(@buf1, @buf2);
push eax
send(sock, '$Supports UserCommand UserIP2 TTHSearch ZPipe0 GetZBlock |', sizeof '$Supports UserCommand UserIP2 TTHSearch ZPipe0 GetZBlock |', 0);
pop eax
send(sock, @buf2, eax, 0);
send(sock, '$ValidateNick '+BOTNAME+'|', sizeof '$ValidateNick '+BOTNAME+'|', 0);
} elseif (char*[edi] == "$Sup" and char*[edi+4] == "port" and word[edi+8] == "s ") {
send(sock, '$Version 1,0091|$GetNickList|$MyINFO $ALL '+BOTNAME+' '+DC_TAG+'$ $100?$$0$|', sizeof '$Version 1,0091|$GetNickList|$MyINFO $ALL '+BOTNAME+' '+DC_TAG+'$ $100?$$0$|', 0);
} elseif (char[edi] == "<") {
print(edi:string, '\r\n');
//chat message
edi = strOffset(@buf1, '>');
edi += 2;
if (char*[edi] == "zir ") {
if (char*[edi+4] == "say ") {
eax = strSub(@buf2, edi, 8, 1024);
push eax
send(sock, '<'+BOTNAME+'> ', sizeof '<'+BOTNAME+'> ', 0);
pop eax
send(sock, @buf2, eax, 0);
} elseif (char*[edi+4] == "quit") {
send(sock, '<'+BOTNAME+'> Goodbyte!|', sizeof '<'+BOTNAME+'> Goodbyte!|', 0);
break;
}
}
}
};
closesocket(sock);
WSACleanup();
wait_key(nil);
ExitProcess(0);
The code was written very quickly, is not optimized, but is good as a starter code, or even for learning a little...Settings are at the top, including ip of the server and port, the bot will connect and has 2 valid commands.
"zir say text here" - will send "text here" chat line.
and
"zir quit" - will quit from the server and prepare to close.
let me know what you think, and if you make any improvements or make any bots using this code, please post and let us know :)