//______________________________________________________________________________
 void TCommunicator::SendSerialize(int dest, int tag, Char_t *data, Int_t size)
 {
    //util function to send serialized data from TObject, send firts the size of array
    //and after the array with serialized data
    SendScalar(dest, tag, size);
    SendArray(dest, tag, data, size);
 }
Example #2
0
void AuthSocket::SendProofError(uint8 Error, uint8 * M2)
{
    uint8 buffer[28];
    memset(buffer, 0, 28);

    buffer[0] = 1;
    buffer[1] = Error;
    if(M2 == 0)
    {
        *(uint32*)&buffer[2] = 3;
        SendArray(buffer, 6, FALSE);
        return;
    }
    
    memcpy(&buffer[2], M2, 20);
    SendArray(buffer, 28, FALSE);
}
Example #3
0
void AuthSocket::SendChallengeError(uint8 Error)
{
    uint8 buffer[3];
    buffer[0] = buffer[1] = 0;
    buffer[2] = Error;

    SendArray(buffer, 3, FALSE);
}
Example #4
0
void SendMsg( const MPIMessage & sendmsg )
{
	SendArray(sendmsg.GetComm(),
	          sendmsg.GetProcessId(),
	          sendmsg.GetTag(),
	          sendmsg.GetBuffer(),
	          sendmsg.GetCount(),
	          sendmsg.GetDataType());
}
Example #5
0
bool YModem::Packet::Send(SPort &port, Id pkt_num) const {
  bool res = SendScalar(port, (uint8_t)_type);
  if (_data == 0 || _type != kSTX)
    return res;
  Crc crc(Crc::kZeros);
  const Crc::Value kCrcVal    = crc.Compute(_data, _data_sz);
  const Id         kInvPktNum = 255 - pkt_num;
  res = res && SendScalar(port, (uint8_t)pkt_num);
  res = res && SendScalar(port, (uint8_t)kInvPktNum);
  res = res && SendArray (port, _data, _data_sz);
  res = res && SendScalar(port, kCrcVal);
  return res;
}
Example #6
0
void IRCSocket::SendLine(const char* Text, ...)
{
    va_list l;
    va_start(l, Text);

    char * line = new char[strlen(Text) + 300];
    vsprintf(line, Text, l);
    
    // Append a newline character
    strcat(line, "\n");

    // remove spaces @ start
    char * nl = line;
    while(nl[0] == ' ')
        ++nl;

    // Send over the wire.
    SendArray((const u8*)nl, (u16)strlen(nl), FALSE);

    // cleanup.
    //Log.Out("OUT: \"%s\"", line);
    delete [] line;
    va_end(l);
}
Example #7
0
void AuthSocket::HandleChallenge()
{
	// No header
	if(!HasBytes(4))
		return;	

	// Check the rest of the packet is complete.
	uint16 full_size = *(uint16*)&ReceiveBuffer[2];
    sLog.outDetail("[AuthChallenge] got header, body is 0x%02X bytes", full_size);

	if(!HasBytes(full_size))
		return;

	// Copy the data into our cached challenge structure
	if(full_size > sizeof(sAuthLogonChallenge_C))
	{
		Disconnect();
		return;
	}

    sLog.outDebug("[AuthChallenge] got full packet.");

	memcpy(&m_challenge, ReceiveBuffer, full_size + 4);
    EraseReceiveBytes(full_size+4);

    // Check client build.
    if(m_challenge.build > LogonServer::getSingleton().max_build ||
        m_challenge.build < LogonServer::getSingleton().min_build)
    {
        SendChallengeError(CE_WRONG_BUILD_NUMBER);
        return;
    }

	// Check for a possible IP ban on this client.
#ifdef WIN32
    BAN_STATUS ipb = IPBanner::getSingleton().CalculateBanStatus(ConnectedPeer.sin_addr.S_un.S_addr);
#else
    BAN_STATUS ipb = IPBanner::getSingleton().CalculateBanStatus(RetreiveClientIP());
#endif

	switch(ipb)
	{
		case BAN_STATUS_PERMANANT_BAN:
			SendChallengeError(CE_ACCOUNT_CLOSED);
			return;

        case BAN_STATUS_TIME_LEFT_ON_BAN:
			SendChallengeError(CE_ACCOUNT_FREEZED);
			return;
    }

	// Null-terminate the account string
	m_challenge.I[m_challenge.I_len] = 0;

	// Look up the account information
	string AccountName = (char*)&m_challenge.I;
    sLog.outDebug("[AuthChallenge] Account Name: \"%s\"", AccountName.c_str());

    m_account = AccountMgr::getSingleton().GetAccount(AccountName);
	if(m_account == 0)
	{
        sLog.outDebug("[AuthChallenge] Invalid account.");

		// Non-existant account
		SendChallengeError(CE_NO_ACCOUNT);
		return;
	}

    sLog.outDebug("[AuthChallenge] Account banned state = %u", m_account->Banned);

    // Don't update when IP banned, but update anyway if it's an account ban
    AccountMgr::getSingleton().UpdateAccountLastIP(m_account->AccountId, RetreiveClientIP());

	// Check that the account isn't banned.
	if(m_account->Banned == 1)
	{
		SendChallengeError(CE_ACCOUNT_CLOSED);
		return;
	}
	else if(m_account->Banned > 0)
	{
		SendChallengeError(CE_ACCOUNT_FREEZED);
		return;
	}

	// We've passed all initial tests if we're here, lets build the response packet.
	Sha1Hash I;
	I.UpdateData((m_account->Username + ":" + m_account->Password));
	I.Finalize();

    sLog.outDebug("[AuthChallenge] UserPass hash: %X", I.GetDigest());

	Sha1Hash sha;
	uint32 tc = s.GetNumBytes();
	sha.UpdateData( s.AsByteArray(), 32 );
	sha.UpdateData( I.GetDigest(), 20 );
	sha.Finalize();

	BigNumber x;
	x.SetBinary( sha.GetDigest(), sha.GetLength() );
	v = g.ModExp(x, N);
	b.SetRand(152);

	BigNumber gmod = g.ModExp(b, N);
	B = ((v * 3) + gmod) % N;
	ASSERT(gmod.GetNumBytes() <= 32);

	BigNumber unk;
	unk.SetRand(128);

	uint8 response[200];
	uint32 c = 0;
	response[c] = 0;								        c += 1;
	response[c] = 0;								        c += 1;
	response[c] = CE_SUCCESS;						        c += 1;
	memcpy(&response[c], B.AsByteArray(), 32);		        c += 32;
	response[c] = 1;								        c += 1;
	response[c] = g.AsByteArray()[0];				        c += 1;
	response[c] = 32;								        c += 1;
	memcpy(&response[c], N.AsByteArray(), 32);		        c += 32;
	memcpy(&response[c], s.AsByteArray(), s.GetNumBytes()); c += s.GetNumBytes();
    memcpy(&response[c], unk.AsByteArray(), 16);            c += 16;
    response[c] = 0;                                        c += 1;

    SendArray(response, c, FALSE);
}