예제 #1
0
파일: admin.cpp 프로젝트: 081421/otxserver
void ProtocolAdmin::adminCommandSendMail(const std::string& xmlData)
{
	OutputMessage_ptr output = OutputMessagePool::getInstance()->getOutputMessage(this, false);
	if(!output)
		return;

	std::string name;
	TRACK_MESSAGE(output);
	if(Item* mailItem = Admin::createMail(xmlData, name))
	{
		if(IOLoginData::getInstance()->playerMail(NULL, name, mailItem))
		{
			addLogLine(LOGTYPE_EVENT, "sent mailbox to " + name);
			output->put<char>(AP_MSG_COMMAND_OK);
		}
		else
		{
			addLogLine(LOGTYPE_EVENT, "failed sending mailbox to " + name);
			output->put<char>(AP_MSG_COMMAND_FAILED);
			output->putString("could not send the box");
		}
	}
	else
	{
		addLogLine(LOGTYPE_EVENT, "failed parsing mailbox");
		output->put<char>(AP_MSG_COMMAND_FAILED);
		output->putString("could not parse the box");
	}

	OutputMessagePool::getInstance()->send(output);
}
예제 #2
0
void OutputMessagePool::configureOutputMessage(OutputMessage_ptr msg, Protocol* protocol, bool autosend)
{
	TRACK_MESSAGE(msg);
	msg->Reset();
	if(autosend)
	{
		msg->setState(OutputMessage::STATE_ALLOCATED);
		m_autoSendOutputMessages.push_back(msg);
	}
	else
		msg->setState(OutputMessage::STATE_ALLOCATED_NO_AUTOSEND);

	Connection_ptr connection = protocol->getConnection();
	assert(connection != NULL);

	msg->setProtocol(protocol);
	protocol->addRef();
#ifdef __DEBUG_NET_DETAIL__
	std::cout << "Adding reference to protocol - " << protocol << std::endl;
#endif
	msg->setConnection(connection);
	connection->addRef();
#ifdef __DEBUG_NET_DETAIL__
	std::cout << "Adding reference to connection - " << connection << std::endl;
#endif
	msg->setFrame(m_frameTime);
}
예제 #3
0
파일: admin.cpp 프로젝트: CkyLua/OTHire
void ProtocolAdmin::adminCommandSendMail(const std::string& xmlData)
{
	OutputMessage_ptr output = OutputMessagePool::getInstance()->getOutputMessage(this, false);
	if(output){
		TRACK_MESSAGE(output);

		std::string name;
		uint32_t depotId;
		Item* mailItem = createMail(xmlData, name, depotId);

		if(mailItem){
			if(Mailbox::sendItemTo(name, depotId, mailItem)){
				output->AddByte(AP_MSG_COMMAND_OK);
			}
			else{
				output->AddByte(AP_MSG_COMMAND_FAILED);
				output->AddString("Could not mail item");
			}
		}
		else{
			output->AddByte(AP_MSG_COMMAND_FAILED);
			output->AddString("Could not mail item");
		}

		OutputMessagePool::getInstance()->send(output);
	}
}
예제 #4
0
파일: admin.cpp 프로젝트: Codex-NG/TFS-1.0
void ProtocolAdmin::adminCommandKickPlayer(const std::string& name)
{
	OutputMessage_ptr output = OutputMessagePool::getInstance()->getOutputMessage(this, false);
	if(output)
	{
		TRACK_MESSAGE(output);

		Player* player = g_game.getPlayerByName(name);
		if(player)
		{
			player->kickPlayer(false);
			addLogLine(this, LOGTYPE_EVENT, 1, "kicked player " + name);

			output->AddByte(AP_MSG_COMMAND_OK);
		}
		else
		{
			addLogLine(this, LOGTYPE_WARNING, 1, "Could not kick player (not online): " + name);

			output->AddByte(AP_MSG_COMMAND_FAILED);
			output->AddString("player is not online");
		}

		OutputMessagePool::getInstance()->send(output);
	}
}
예제 #5
0
void Connection::onWriteOperation(OutputMessage_ptr msg, const boost::system::error_code& error)
{
	#ifdef __DEBUG_NET_DETAIL__
	std::cout << "onWriteOperation" << std::endl;
	#endif

	m_connectionLock.lock();
	m_writeTimer.cancel();

	TRACK_MESSAGE(msg);
	msg.reset();

	if(error){
		handleWriteError(error);
	}

	if(m_connectionState != CONNECTION_STATE_OPEN || m_writeError){
		closeSocket();
		closeConnection();
		m_connectionLock.unlock();
		return;
	}

	--m_pendingWrite;
	m_connectionLock.unlock();
}
예제 #6
0
bool Connection::send(OutputMessage_ptr msg) {
	LOGt("Connection::send()");

	boost::recursive_mutex::scoped_lock lock(m_connectionLock);

	if(m_connectionState != CONNECTION_STATE_OPEN || m_writeError)
	{
		return false;
	}

	TRACK_MESSAGE(msg);
	if(!m_pendingWrite)
	{
		if(msg->getProtocol())
			msg->getProtocol()->onSendMessage(msg);

		internalSend(msg);
	}
	else if(m_pendingWrite > 100 && server.configManager().getBool(ConfigManager::FORCE_CLOSE_SLOW_CONNECTION))
	{
		LOGd("Forcing slow connection to disconnect!");
		close();
	}
	else
	{	
		OutputMessagePool::getInstance()->autoSend(msg);
	}

	return true;
}
예제 #7
0
void ProtocolHTTP::onRecvFirstMessage(NetworkMessage&)
{
	if(OutputMessage_ptr output = OutputMessagePool::getInstance()->getOutputMessage(this, false))
	{
		TRACK_MESSAGE(output);

		output->putString("HTTP/1.1 200 OK");
		output->putString("Date: Fri, 27 Mar 2009 17:28.13 GMT\r\n");
		output->putString("Server: The OTX Server httpd/2.10\r\n");
		output->putString("Content-Location: index.html\r\n");
		//Vary: negotiate\r\n
		//TCN: choice\r\n
		output->putString("Last-Modified: Fri, 27 Mar 2009 17:28.13 GMT\r\n");
		output->putString("Accept-Ranges: bytes\r\n");
		output->putString("Content-Length: 1234\r\n");
		output->putString("Expires: Fri, 27 Mar 2009 17:28.13 GMT\r\n");
		output->putString("Connection: close\r\n");
		output->putString("Content-Type: text/html qs=0.7\r\n");
		output->putString("\r\n");
		output->putString("<html><head><title>The OTX Server httpd</title></head><body>It works (apache ripoff ;D)!</body></html>");

		OutputMessagePool::getInstance()->send(output);
	}

	getConnection()->close();
}
예제 #8
0
void ProtocolManager::output(const std::string& message)
{
	NetworkMessage_ptr msg = getOutputBuffer();
	if(!msg)
		return;

	TRACK_MESSAGE(msg);
	msg->put<char>(MP_MSG_OUTPUT);
	msg->putString(message);
}
예제 #9
0
void ProtocolManager::removeUser(uint32_t playerId)
{
	NetworkMessage_ptr msg = getOutputBuffer();
	if(!msg)
		return;

	TRACK_MESSAGE(msg);
	msg->put<char>(MP_MSG_USER_REMOVE);
	msg->put<uint32_t>(playerId);
}
예제 #10
0
void ProtocolLogin::disconnectClient(uint8_t error, const char* message)
{
	OutputMessage_ptr output = OutputMessagePool::getInstance()->getOutputMessage(this, false);
	if(output){
		TRACK_MESSAGE(output);
		output->AddByte(error);
		output->AddString(message);
		OutputMessagePool::getInstance()->send(output);
	}
	getConnection()->closeConnection();
}
예제 #11
0
void ProtocolManager::addUser(uint32_t playerId, uint16_t channelId)
{
	NetworkMessage_ptr msg = getOutputBuffer();
	if(!msg)
		return;

	TRACK_MESSAGE(msg);
	msg->put<char>(MP_MSG_CHAT_USER_ADD);

	msg->put<uint32_t>(playerId);
	msg->put<uint16_t>(channelId);
}
예제 #12
0
void ProtocolManager::addUser(Player* player)
{
	NetworkMessage_ptr msg = getOutputBuffer();
	if(!msg)
		return;

	TRACK_MESSAGE(msg);
	msg->put<char>(MP_MSG_USER_ADD);

	msg->put<uint32_t>(player->getID());
	msg->putString(player->getName());
}
예제 #13
0
파일: admin.cpp 프로젝트: CkyLua/OTHire
void ProtocolAdmin::adminCommandPayHouses()
{
	Houses::getInstance().payHouses();
	addLogLine(this, LOGTYPE_EVENT, 1, "pay houses ok");

	OutputMessage_ptr output = OutputMessagePool::getInstance()->getOutputMessage(this, false);
	if(output){
		TRACK_MESSAGE(output);
		output->AddByte(AP_MSG_COMMAND_OK);
		OutputMessagePool::getInstance()->send(output);
	}
}
예제 #14
0
파일: admin.cpp 프로젝트: CkyLua/OTHire
void ProtocolAdmin::adminCommandSaveServer(bool shallow)
{
	g_game.saveServer(false, shallow);
	addLogLine(this, LOGTYPE_EVENT, 1, "save server ok");

	OutputMessage_ptr output = OutputMessagePool::getInstance()->getOutputMessage(this, false);
	if(output){
		TRACK_MESSAGE(output);
		output->AddByte(AP_MSG_COMMAND_OK);
		OutputMessagePool::getInstance()->send(output);
	}
}
예제 #15
0
void ProtocolOld::disconnectClient(uint8_t error, const char* message)
{
	if(OutputMessage_ptr output = OutputMessagePool::getInstance()->getOutputMessage(this, false))
	{
		TRACK_MESSAGE(output);
		output->put<char>(error);
		output->putString(message);
		OutputMessagePool::getInstance()->send(output);
	}

	getConnection()->close();
}
예제 #16
0
파일: admin.cpp 프로젝트: CkyLua/OTHire
void ProtocolAdmin::adminCommandShutdownServer()
{
	g_game.setGameState(GAME_STATE_SHUTDOWN);
	addLogLine(this, LOGTYPE_EVENT, 1, "start server shutdown");

	OutputMessage_ptr output = OutputMessagePool::getInstance()->getOutputMessage(this, false);
	if(output){
		TRACK_MESSAGE(output);
		output->AddByte(AP_MSG_COMMAND_OK);
		OutputMessagePool::getInstance()->send(output);
	}
}
예제 #17
0
파일: admin.cpp 프로젝트: 081421/otxserver
void ProtocolAdmin::adminCommandPayHouses()
{
	OutputMessage_ptr output = OutputMessagePool::getInstance()->getOutputMessage(this, false);
	if(!output)
		return;

	Houses::getInstance()->check();
	addLogLine(LOGTYPE_EVENT, "pay houses ok");

	TRACK_MESSAGE(output);
	output->put<char>(AP_MSG_COMMAND_OK);
	OutputMessagePool::getInstance()->send(output);
}
예제 #18
0
파일: admin.cpp 프로젝트: 081421/otxserver
void ProtocolAdmin::adminCommandReload(int8_t reload)
{
	OutputMessage_ptr output = OutputMessagePool::getInstance()->getOutputMessage(this, false);
	if(!output)
		return;

	g_game.reloadInfo((ReloadInfo_t)reload);
	addLogLine(LOGTYPE_EVENT, "reload ok");

	TRACK_MESSAGE(output);
	output->put<char>(AP_MSG_COMMAND_OK);
	OutputMessagePool::getInstance()->send(output);
}
예제 #19
0
void ProtocolManager::talk(uint32_t playerId, uint16_t channelId, SpeakClasses type, const std::string& message)
{
	NetworkMessage_ptr msg = getOutputBuffer();
	if(!msg)
		return;

	TRACK_MESSAGE(msg);
	msg->put<char>(MP_MSG_CHAT_MESSAGE);
	msg->put<uint32_t>(playerId);

	msg->put<uint16_t>(channelId);
	msg->put<char>(type);
	msg->putString(message);
}
예제 #20
0
bool Connection::send(OutputMessage_ptr msg)
{
	#ifdef __DEBUG_NET_DETAIL__
	std::cout << "Connection::send init" << std::endl;
	#endif

	m_connectionLock.lock();
	if(m_connectionState != CONNECTION_STATE_OPEN || m_writeError){
		m_connectionLock.unlock();
		return false;
	}

	if(m_pendingWrite == 0){
		msg->getProtocol()->onSendMessage(msg);

		TRACK_MESSAGE(msg);

		#ifdef __DEBUG_NET_DETAIL__
		std::cout << "Connection::send " << msg->getMessageLength() << std::endl;
		#endif

		internalSend(msg);
	}
	else{
		#ifdef __DEBUG_NET__
		std::cout << "Connection::send Adding to queue " << msg->getMessageLength() << std::endl;
		#endif

		TRACK_MESSAGE(msg);
		OutputMessagePool* outputPool = OutputMessagePool::getInstance();
		outputPool->addToAutoSend(msg);
	}
	
	m_connectionLock.unlock();
	return true;
}
예제 #21
0
파일: admin.cpp 프로젝트: CkyLua/OTHire
void ProtocolAdmin::adminCommandRelationalSaveServer()
{
	std::string old_type = g_config.getString(ConfigManager::MAP_STORAGE_TYPE);
	g_config.setString(ConfigManager::MAP_STORAGE_TYPE, "relational");
	g_game.saveServer(false);
	g_config.setString(ConfigManager::MAP_STORAGE_TYPE, old_type);
	addLogLine(this, LOGTYPE_EVENT, 1, "relational save server ok");

	OutputMessage_ptr output = OutputMessagePool::getInstance()->getOutputMessage(this, false);
	if(output){
		TRACK_MESSAGE(output);
		output->AddByte(AP_MSG_COMMAND_OK);
		OutputMessagePool::getInstance()->send(output);
	}
}
예제 #22
0
파일: admin.cpp 프로젝트: Codex-NG/TFS-1.0
void ProtocolAdmin::onRecvFirstMessage(NetworkMessage& msg)
{
	//is the remote admin protocol enabled?
	if(!g_adminConfig->isEnabled())
	{
		getConnection()->closeConnection();
		return;
	}

	m_state = NO_CONNECTED;
	//is allowed this ip?
	if(!g_adminConfig->allowIP(getIP()))
	{
		addLogLine(this, LOGTYPE_EVENT, 1, "ip not allowed");
		getConnection()->closeConnection();
		return;
	}

	//max connections limit
	if(!g_adminConfig->addConnection())
	{
		addLogLine(this, LOGTYPE_EVENT, 1, "cannot add new connection");
		getConnection()->closeConnection();
		return;
	}

	addLogLine(this, LOGTYPE_EVENT, 1, "sending HELLO");
	//send hello
	OutputMessage_ptr output = OutputMessagePool::getInstance()->getOutputMessage(this, false);
	if(output)
	{
		TRACK_MESSAGE(output);
		output->AddByte(AP_MSG_HELLO);
		output->AddU32(1); //version
		output->AddString("OTADMIN");
		output->AddU16(g_adminConfig->getProtocolPolicy()); //security policy
		output->AddU32(g_adminConfig->getProtocolOptions()); //protocol options(encryption, ...)
		OutputMessagePool::getInstance()->send(output);
	}

	m_lastCommand = time(NULL);
	m_state = ENCRYPTION_NO_SET;
}
예제 #23
0
파일: admin.cpp 프로젝트: Codex-NG/TFS-1.0
void ProtocolAdmin::adminCommandSetOwner(const std::string& param)
{
	OutputMessage_ptr output = OutputMessagePool::getInstance()->getOutputMessage(this, false);
	if(output)
	{
		TRACK_MESSAGE(output);

		boost::char_separator<char> sep(", ");
		tokenizer cmdtokens(param, sep);
		tokenizer::iterator cmdit = cmdtokens.begin();
		std::string _house, name;
		_house = parseParams(cmdit, cmdtokens.end());
		name = parseParams(cmdit, cmdtokens.end());
		trimString(_house);
		trimString(name);

		if(House* house = Houses::getInstance().getHouse(atoi(_house.c_str())))
		{
			uint32_t _guid;
			if(IOLoginData::getInstance()->getGuidByName(_guid, name))
			{
				house->setHouseOwner(_guid);
				addLogLine(this, LOGTYPE_EVENT, 1, "set " + name + " as new owner of house with id " + _house);
				output->AddByte(AP_MSG_COMMAND_OK);
			}
			else
			{
				addLogLine(this, LOGTYPE_WARNING, 1, "Could not find player with name: " + name);
				output->AddByte(AP_MSG_COMMAND_FAILED);
				output->AddString("such player does not exists");
			}
		}
		else
		{
			addLogLine(this, LOGTYPE_WARNING, 1, "Could not find house with id: " + _house);
			output->AddByte(AP_MSG_COMMAND_FAILED);
			output->AddString("such house does not exists");
		}

		OutputMessagePool::getInstance()->send(output);
	}
}
예제 #24
0
void Connection::internalSend(OutputMessage_ptr msg)
{
	TRACK_MESSAGE(msg);

	try{
		++m_pendingWrite;
		m_writeTimer.expires_from_now(boost::posix_time::seconds(Connection::write_timeout));
		m_writeTimer.async_wait( boost::bind(&Connection::handleWriteTimeout, boost::weak_ptr<Connection>(shared_from_this()),
			boost::asio::placeholders::error));

		boost::asio::async_write(getHandle(),
			boost::asio::buffer(msg->getOutputBuffer(), msg->getMessageLength()),
			boost::bind(&Connection::onWriteOperation, shared_from_this(), msg, boost::asio::placeholders::error));
	}
	catch(boost::system::system_error& e){
		if(m_logError){
			LOG_MESSAGE("NETWORK", LOGTYPE_ERROR, 1, e.what());
			m_logError = false;
		}
	}
}
예제 #25
0
파일: admin.cpp 프로젝트: 081421/otxserver
void ProtocolAdmin::onRecvFirstMessage(NetworkMessage& msg)
{
	m_state = NO_CONNECTED;
	if(g_config.getString(ConfigManager::ADMIN_PASSWORD).empty())
	{
		addLogLine(LOGTYPE_EVENT, "connection attempt on disabled protocol");
		getConnection()->close();
		return;
	}

	if(!Admin::getInstance()->allow(getIP()))
	{
		addLogLine(LOGTYPE_EVENT, "ip not allowed");
		getConnection()->close();
		return;
	}

	if(!Admin::getInstance()->addConnection())
	{
		addLogLine(LOGTYPE_EVENT, "cannot add new connection");
		getConnection()->close();
		return;
	}

	addLogLine(LOGTYPE_EVENT, "sending HELLO");
	if(OutputMessage_ptr output = OutputMessagePool::getInstance()->getOutputMessage(this, false))
	{
		TRACK_MESSAGE(output);
		output->put<char>(AP_MSG_HELLO);
		output->put<uint32_t>(1); //version
		output->putString("OTADMIN");

		output->put<uint16_t>(Admin::getInstance()->getPolicy()); //security policy
		output->put<uint32_t>(Admin::getInstance()->getOptions()); //protocol options(encryption, ...)
		OutputMessagePool::getInstance()->send(output);
	}

	m_lastCommand = time(NULL);
	m_state = ENCRYPTION_NO_SET;
}
예제 #26
0
bool Connection::send(OutputMessage_ptr msg)
{
	#ifdef __DEBUG_NET_DETAIL__
	std::clog << "Connection::send init" << std::endl;
	#endif
	m_connectionLock.lock();
	if(m_connectionState != CONNECTION_STATE_OPEN || m_writeError)
	{
		m_connectionLock.unlock();
		return false;
	}

	TRACK_MESSAGE(msg);
	if(!m_pendingWrite)
	{
		if(msg->getProtocol())
			msg->getProtocol()->onSendMessage(msg);

		#ifdef __DEBUG_NET_DETAIL__
		std::clog << "Connection::send " << msg->size() << std::endl;
		#endif
		internalSend(msg);
	}
	else if(m_pendingWrite > 100 && g_config.getBool(ConfigManager::FORCE_CLOSE_SLOW_CONNECTION))
	{
		std::clog << "NOTICE: Forcing slow connection to disconnect!" << std::endl;
		close();
	}
	else
	{	
		#ifdef __DEBUG_NET__
		std::clog << "Connection::send Adding to queue " << msg->size() << std::endl;
		#endif
		OutputMessagePool::getInstance()->autoSend(msg);
	}

	m_connectionLock.unlock();
	return true;
}
예제 #27
0
void Connection::onWrite(OutputMessage_ptr msg, const boost::system::error_code& error) {
	LOGt("Connection::onWrite()");

	boost::recursive_mutex::scoped_lock lock(m_connectionLock);

	m_writeTimer.cancel();

	TRACK_MESSAGE(msg);
	msg.reset();
	if(error)
		handleWriteError(error);

	if(m_connectionState != CONNECTION_STATE_OPEN || m_writeError)
	{
		closeSocket();
		close();

		return;
	}

	--m_pendingWrite;
}
예제 #28
0
void OutputMessagePool::configureOutputMessage(OutputMessage_ptr msg, Protocol* protocol, bool autosend)
{
	TRACK_MESSAGE(msg);
	msg->Reset();
	if(autosend)
	{
		msg->setState(OutputMessage::STATE_ALLOCATED);
		m_autoSendOutputMessages.push_back(msg);
	}
	else
		msg->setState(OutputMessage::STATE_ALLOCATED_NO_AUTOSEND);

	Connection* connection = protocol->getConnection();
	assert(connection);

	msg->setProtocol(protocol);
	protocol->addRef();
	msg->setConnection(connection);
	connection->addRef();

	msg->setFrame(m_frameTime);
}
예제 #29
0
파일: admin.cpp 프로젝트: Codex-NG/TFS-1.0
void ProtocolAdmin::adminCommandPayHouses()
{
	OutputMessage_ptr output = OutputMessagePool::getInstance()->getOutputMessage(this, false);
	if(output)
	{
		TRACK_MESSAGE(output);

		if(Houses::getInstance().payHouses())
		{
			addLogLine(this, LOGTYPE_EVENT, 1, "pay houses ok");
			output->AddByte(AP_MSG_COMMAND_OK);
		}
		else
		{
			addLogLine(this, LOGTYPE_WARNING, 1, "pay houses fail");
			output->AddByte(AP_MSG_COMMAND_FAILED);
			output->AddString(" ");
		}

		OutputMessagePool::getInstance()->send(output);
	}
}
예제 #30
0
파일: admin.cpp 프로젝트: CkyLua/OTHire
void ProtocolAdmin::adminCommandCloseServer()
{
	g_game.setGameState(GAME_STATE_CLOSED);
	addLogLine(this, LOGTYPE_EVENT, 1, "close server ok");

	AutoList<Player>::listiterator it = Player::listPlayer.list.begin();
	while(it != Player::listPlayer.list.end()){
		if(!(*it).second->hasFlag(PlayerFlag_CanAlwaysLogin)){
			(*it).second->kickPlayer();
			it = Player::listPlayer.list.begin();
		}
		else{
			++it;
		}
	}

	OutputMessage_ptr output = OutputMessagePool::getInstance()->getOutputMessage(this, false);
	if(output){
		TRACK_MESSAGE(output);
		output->AddByte(AP_MSG_COMMAND_OK);
		OutputMessagePool::getInstance()->send(output);
	}
}