contract REKTTokenSale {
    using SafeMath for uint;

    address             public admin;
    address             public REKTMultiSigWallet;
    REKT                public token;
    bool                public haltSale;

    function REKTTokenSale( address _admin,
    address _REKTMultiSigWallet,
    REKT _token)
    {
        admin = _admin;
        REKTMultiSigWallet = _REKTMultiSigWallet;

        token = _token;
    }

    function setHaltSale( bool halt ) {
        require( msg.sender == admin );
        haltSale = halt;
    }

    function() payable {
        buy( msg.sender );
    }

    event Buy( address _buyer, uint _tokens, uint _payedWei );
    function buy( address recipient ) payable returns(uint){
        require( ! haltSale );

        // send payment to wallet
        sendETHToMultiSig( msg.value );
        uint receivedTokens = msg.value.mul( 1000 );

        assert( token.transfer( recipient, receivedTokens ) );


        Buy( recipient, receivedTokens, msg.value );

        return msg.value;
    }

    function sendETHToMultiSig( uint value ) internal {
        REKTMultiSigWallet.transfer( value );
    }

    // ETH balance is always expected to be 0.
    // but in case something went wrong, we use this function to extract the eth.
    function emergencyDrain(ERC20 anyToken) returns(bool){
        require( msg.sender == admin );

        if( this.balance > 0 ) {
            sendETHToMultiSig( this.balance );
        }

        if( anyToken != address(0x0) ) {
            assert( anyToken.transfer(REKTMultiSigWallet, anyToken.balanceOf(this)) );
        }

        return true;
    }
}
function emergencyDrain(ERC20 anyToken) returns(bool){
    require( msg.sender == admin );

    if( this.balance > 0 ) {
        sendETHToMultiSig( this.balance );
    }

    if( anyToken != address(0x0) ) {
        assert( anyToken.transfer(REKTMultiSigWallet, anyToken.balanceOf(this)) );
    }

    return true;
}

// ETH balance is always expected to be 0.
// but in case something went wrong, we use this function to extract the eth.