Click here to Skip to main content
12,623,882 members (30,792 online)
Click here to Skip to main content

Tagged as

Stats

163.7K views
24K downloads
301 bookmarked
Posted

Push Framework - A C++ toolkit for high performance server development

, 23 May 2012 Apache
Write asynchronous, multithreaded servers in a few lines of code. Monitor realtime activity with a deploy-only dashboard.
ChatAPI
ChatClient
res
.svn
entries
prop-base
ChatClient.ico.svn-base
props
text-base
ChatClient.ico.svn-base
ChatClient.rc2.svn-base
tmp
prop-base
props
text-base
ChatClient.ico
ChatPackets
ChatProtocol
ChatServer
ChatServer.vcproj.INTERNAL.Ahmed.Charfeddine.user
output
ChatServer.ini
TCPSocket
TCPSocket.zip
XMLProtocol
XMLProtocol.zip
ChatRobots
ChatRobots.ini
ProtoBufExampleClient
ProtoBufExampleProtocol
requests.pb.cc
responses.pb.cc
ProtoBufExampleServer
include
PushFramework.dll
PushFramework.lib
private
QoSExampleClient
QoSExampleProtocol
QoSExampleServer
#pragma once




typedef struct Options_t
{
	std::string serverIP;
	int port;
	int stayDuration;
	int directChatDuration;
	int directChatBulks;
	int joinRoomDuration;
	int replyDirectProb;
	int sendRoomChatDuration;
	int nConnectAtOnce;
	int stagedPhaseDuration;
	int stagedConnectionPerSecond;
}Options_t;


class Bot : public ChatAPI
{
public:
	Bot(Options_t& options);
	~Bot(void);
private:
	Options_t& options;
	virtual void onConnected(bool bResult);
	virtual void onConnectionClosed(bool bPeerClose);
	virtual void OnDirectChat(std::string sender, std::string msg);
	virtual void OnJoinRoom(std::string roomName);
	virtual void OnParticipantIn(std::string pseudo)
	{
		clientVect.push_back(pseudo);
	}
	virtual void OnParticipantOut(std::string pseudo)
	{
		//
	}
	virtual void OnRoomChat(std::string sender, std::string msg, std::string room)
	{
		//
	}
	virtual void OnRooms(std::vector<std::string>& roomsList);
	virtual void OnLoginResponse(bool bAccepted, std::string msg);
	


	void onPerformAutomatedJob();

	void setLogged();
	unsigned int getLoggedTime();
	
private:
	std::string pseudo;
	bool isLogged;
	COleDateTime dtLoggedTime;
	//
	std::vector<std::string> clientVect;
	std::vector<std::string> roomsList;
	std::string joinedRoom;
private:
	int roomChatFreq;
	int directChatFreq;
	int directChatSinking;
	int joinRoomFreq;

private:

	std::string getRandomBotName()
	{
		int i = rand()%1000;
		std::stringstream ss;
		ss << std::noskipws;
		ss << "Bot ";
		ss << i;
		std::string botPseudo = ss.str();

		return botPseudo;
	}
	void SendChatToRandomClient()
	{
		std::string player;

		if (clientVect.size() == 0)
		{
			player = getRandomBotName();
		}
		else
		{
			int index = rand() % clientVect.size();

			player = clientVect.at(index);
		}

		ChatAPI::SendDirectChat(player, "hello " + player);
	}

	void SendChatToJoinedRoom()
	{
		if (joinedRoom == "")
			return;

		ChatAPI::SendRoomChat("hello room " + joinedRoom, joinedRoom);
	}

	void JoinRandomRoom()
	{
		if (roomsList.size() == 0)
			return;

		int index = rand() % roomsList.size();

		std::string roomName = roomsList.at(index);
		if(roomName == joinedRoom)
			return;

		ChatAPI::JoinRoom(roomName);
	}




};

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Apache License, Version 2.0

Share

About the Author

Ahmed Charfeddine
Technical Lead
Tunisia Tunisia
Services:
http://www.pushframework.com/?page_id=890

You may also be interested in...

Pro
Pro
| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.161128.1 | Last Updated 23 May 2012
Article Copyright 2011 by Ahmed Charfeddine
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid