///- Delete buffer and decrease active admins count
delete[]buff;
sLog.outRemote("Connection was closed.\n");
if(stage==OK)
iUsers--;
}
/// Accept an incoming connection
voidRASocket::OnAccept()
{
std::stringss=GetRemoteAddress();
sLog.outRemote("Incoming connection from %s.\n",ss.c_str());
///- If there is already an active admin, drop the connection
if(iUsers)
dropclient
///- Else print Motd
Sendf("%s\r\n",sWorld.GetMotd());
}
/// Read data from the network
voidRASocket::OnRead()
{
///- Read data and check input length
TcpSocket::OnRead();
unsignedintsz=ibuf.GetLength();
if(iInputLength+sz>=RA_BUFF_SIZE)
{
sLog.outRemote("Input buffer overflow, possible DOS attack.\n");
SetCloseAndDelete();
return;
}
///- If there is already an active admin (other than you), drop the connection
if(stage!=OK&&iUsers)
dropclient
char*inp=newchar[sz+1];
ibuf.Read(inp,sz);
/// \todo Can somebody explain this 'Linux bugfix'?
if(stage==NONE)
if(sz>4)//linux remote telnet
if(memcmp(inp,"USER ",5))
{
delete[]inp;return;
printf("lin bugfix");
}//linux bugfix
///- Discard data after line break or line feed
boolgotenter=false;
unsignedinty=0;
for(;y<sz;y++)
if(inp[y]=='\r'||inp[y]=='\n')
{
gotenter=true;
break;
}
//No buffer overflow (checked above)
memcpy(&buff[iInputLength],inp,y);
iInputLength+=y;
delete[]inp;
if(gotenter)
{
buff[iInputLength]=0;
iInputLength=0;
switch(stage)
{
/// <ul> <li> If the input is 'USER <username>'
caseNONE:
if(!memcmp(buff,"USER ",5))//got "USER" cmd
{
szLogin=&buff[5];
///- Get the password from the account table
std::stringlogin=szLogin;
///- Convert Account name to Upper Format
AccountMgr::normalizeString(login);
///- Escape the Login to allow quotes in names
LoginDatabase.escape_string(login);
QueryResult_AutoPtrresult=LoginDatabase.PQuery("SELECT a.id, aa.gmlevel, aa.RealmID FROM account a LEFT JOIN account_access aa ON (a.id = aa.id) WHERE a.username = '%s'",login.c_str());
///- If the user is not found, deny access
if(!result)
{
Sendf("-No such user.\r\n");
sLog.outRemote("User %s does not exist.\n",szLogin.c_str());