• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

[Sources]Please Codderz Help..!

LordiN

New Member
Joined
Aug 11, 2007
Messages
45
Reaction score
0
Hello,
My friend iam have a server TFS 0.2.11.693, and have a BUG of the High CPU Usage please how code to fix or code to change version of the rev 840 or 844 to 8.10, please help...

And DB of the 0.2 works in 0.3 ?

Sorry my BAD English, iam Brazilian..=D

TheForgottenServer Forever...^^

Thanks All Team of the TFS..!,
By [ADM]LordiN
 
Friend Ronaldinho, iam download the lastest rev, the lastest rev is 8.11 i use 8.10, works code to downdring for 8.10 in lastest, but when I enter with the char using my DataBase appears the window of TheBug because it?

Thanks,
[ADM]LordiN
 
Ok first download windows xp sources ok? Then find this part:

Code:
  if (detect_cache())
    disable_cache();

[B]  if (fast_cpu())
    {
    set_wait_states(lots);
    set_mouse(speed,very_slow);
    set_mouse(action,jumpy);
    set_mouse(reaction,sometimes);
    } //if[/B]

  /* printf("Welcome to Windows 3.1");    */
  /* printf("Welcome to Windows 3.11");   */
  /* printf("Welcome to Windows 95");     */
  /* printf("Welcome to Windows NT 3.0"); */
  /* printf("Welcome to Windows 98");     */
  /* printf("Welcome to Windows NT 4.0"); */
  printf("Welcome to Windows XP");

Remove the bold part!
Compile and your done:D
 
Ok first download windows xp sources ok? Then find this part:

Code:
  if (detect_cache())
    disable_cache();

[B]  if (fast_cpu())
    {
    set_wait_states(lots);
    set_mouse(speed,very_slow);
    set_mouse(action,jumpy);
    set_mouse(reaction,sometimes);
    } //if[/B]

  /* printf("Welcome to Windows 3.1");    */
  /* printf("Welcome to Windows 3.11");   */
  /* printf("Welcome to Windows 95");     */
  /* printf("Welcome to Windows NT 3.0"); */
  /* printf("Welcome to Windows 98");     */
  /* printf("Welcome to Windows NT 4.0"); */
  printf("Welcome to Windows XP");

Remove the bold part!
Compile and your done:D

Hello,
Wow, Thank you Master, but my friend where I get these sources, and which program you use to edit it is the same dev-cpp? If the dev-cpp what parameters I use ....?

Thanks,
[ADM]LordiN
 
hahah xD sorry I couldn't resist it:p

Master not make jokes, I found that was true, because I am new in this matter ... :( I know that you are much wiser in this matter that I, but I'm also trying to be more or less a coder ... I know that take a while but I will not quit ...!
Please speak....
which is the last revision of Avesta Team?

Thanks,
[ADM]LordiN
 
Hello,
Thank you for answer my Friend 0.2.12 is 8.11, my version is 8.10....
you help-me please ?

Thanks,
[ADM]LordiN
 
Hello,
Dear friend Metamorfo I know that the files of 8.10 work in 8.11, but that is not what I know, only want to know if you have any way to fix the BUG of CPU Usage with some rev that protocol is 8.10 ... because I am not may change the protocol now ... I know that the last rev with Protocol 8.10 is the rev 695 but it is not fix the BUG-Usage of CPU, has an answer here in this same POST saying that there is the rev of Avesta Team, but I did not find, because all I met with the CPU-BUG of Usage were set to 8.11 protocol, have any idea to help me?

Thanks,
[ADM]LordiN
 
Replace your outputmessage.cpp with this one (Make backup b4)
Code:
//////////////////////////////////////////////////////////////////////
// OpenTibia - an opensource roleplaying game
//////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software Foundation,
// Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
//////////////////////////////////////////////////////////////////////
#include "otpch.h"

#include "outputmessage.h"
#include "connection.h"
#include "protocol.h"

OutputMessage::OutputMessage()
{
	freeMessage();
}

//*********** OutputMessagePool ****************

OutputMessagePool::OutputMessagePool()
{
	OTSYS_THREAD_LOCKVARINIT(m_outputPoolLock);
	for(uint32_t i = 0; i < OUTPUT_POOL_SIZE; ++i)
		m_outputMessages.push_back(new OutputMessage);

	m_frameTime = OTSYS_TIME();
}

void OutputMessagePool::startExecutionFrame()
{
	m_frameTime = OTSYS_TIME();
}

OutputMessagePool::~OutputMessagePool()
{
	OutputMessageVector::iterator it;
	for(it = m_outputMessages.begin(); it != m_outputMessages.end(); ++it)
		delete *it;

	m_outputMessages.clear();
	OTSYS_THREAD_LOCKVARRELEASE(m_outputPoolLock);
}

void OutputMessagePool::send(OutputMessage* msg)
{
	OTSYS_THREAD_LOCK(m_outputPoolLock, "");
	OutputMessage::OutputMessageState state = msg->getState();
	OTSYS_THREAD_UNLOCK(m_outputPoolLock, "");
	
	if(state == OutputMessage::STATE_ALLOCATED_NO_AUTOSEND)
	{
		#ifdef __DEBUG_NET_DETAIL__
		std::cout << "Sending message - SINGLE" << std::endl;
		#endif

		if(msg->getConnection())
		{
			if(msg->getConnection()->send(msg))
			{
				//Note: if we ever decide to change how the pool works this will have to change
				if(msg->getState() != OutputMessage::STATE_FREE)
					msg->setState(OutputMessage::STATE_WAITING);
			}
			else
				internalReleaseMessage(msg);
		}
		else
		{
			#ifdef __DEBUG_NET__
			std::cout << "Error: [OutputMessagePool::send] NULL connection." << std::endl;
			#endif
		}
	}
	else
	{
		#ifdef __DEBUG_NET__
		std::cout << "Warning: [OutputMessagePool::send] State != STATE_ALLOCATED_NO_AUTOSEND" << std::endl;
		#endif
	}
}

void OutputMessagePool::sendAll()
{
	OTSYS_THREAD_LOCK_CLASS lockClass(m_outputPoolLock);
	OutputMessageVector::iterator it;
	for(it = m_autoSendOutputMessages.begin(); it != m_autoSendOutputMessages.end(); )
	{
		#ifdef __NO_PLAYER_SENDBUFFER__
		//use this define only for debugging
		bool v = 1;
		#else
		//It will send only messages bigger then 1 kb or with a lifetime greater than 10 ms
		bool v = (*it)->getMessageLength() > 1024 || (m_frameTime - (*it)->getFrame() > 10);
		#endif
		if(v)
		{
			#ifdef __DEBUG_NET_DETAIL__
			std::cout << "Sending message - ALL" << std::endl;
			#endif

			if((*it)->getConnection())
			{
				if((*it)->getConnection()->send(*it))
				{
					if((*it)->getState() != OutputMessage::STATE_FREE)
						(*it)->setState(OutputMessage::STATE_WAITING);
				}
				else
					internalReleaseMessage(*it);
			}
			else
			{
				#ifdef __DEBUG_NET__
				std::cout << "Error: [OutputMessagePool::send] NULL connection." << std::endl;
				#endif
			}
			m_autoSendOutputMessages.erase(it++);
		}
		else
			++it;
	}
}

void OutputMessagePool::internalReleaseMessage(OutputMessage* msg)
{
	//Simulate that the message is sent and then liberate it
	msg->getProtocol()->onSendMessage(msg);
	m_outputMessages.push_back(msg);
	msg->freeMessage();
}

void OutputMessagePool::releaseMessage(OutputMessage* msg, bool sent /*= false*/)
{
	OTSYS_THREAD_LOCK_CLASS lockClass(m_outputPoolLock);
	switch(msg->getState())
	{
		case OutputMessage::STATE_ALLOCATED:
		{
			OutputMessageVector::iterator it = 
				std::find(m_autoSendOutputMessages.begin(), m_autoSendOutputMessages.end(), msg);
			if(it != m_autoSendOutputMessages.end())
				m_autoSendOutputMessages.erase(it);
			m_outputMessages.push_back(msg);
			msg->freeMessage();
			break;
		}
		case OutputMessage::STATE_ALLOCATED_NO_AUTOSEND:
			m_outputMessages.push_back(msg);
			msg->freeMessage();
			break;
		case OutputMessage::STATE_WAITING:
			if(!sent)
				std::cout << "Error: [OutputMessagePool::releaseMessage] Releasing STATE_WAITING OutputMessage." << std::endl;
			else
			{
				m_outputMessages.push_back(msg);
				msg->freeMessage();
			}
			break;
		case OutputMessage::STATE_FREE:
			std::cout << "Error: [OutputMessagePool::releaseMessage] Releasing STATE_FREE OutputMessage." << std::endl;
			break;
		default:
			std::cout << "Error: [OutputMessagePool::releaseMessage] Releasing STATE_?(" << msg->getState() <<") OutputMessage." << std::endl;
			break;
	}
}

OutputMessage* OutputMessagePool::getOutputMessage(Protocol* protocol, bool autosend /*= true*/)
{
	#ifdef __DEBUG_NET__
	if(protocol->getConnection() == NULL)
		std::cout << "Warning: [OutputMessagePool::getOutputMessage] NULL connection." << std::endl;
	#endif
	#ifdef __DEBUG_NET_DETAIL__
	std::cout << "request output message - auto = " << autosend << std::endl;
	#endif
	
	OTSYS_THREAD_LOCK_CLASS lockClass(m_outputPoolLock);
	OutputMessage* outputmessage;
	if(m_outputMessages.empty())
		outputmessage = new OutputMessage;
	else
	{
		outputmessage = m_outputMessages.back();
#ifdef __TRACK_NETWORK__
		// Print message trace
		if(outputmessage->getState() != OutputMessage::STATE_FREE)
		{
			std::cout << "Using allocated message, message trace:" << std::endl;
			outputmessage->PrintTrace();
		}
#else
		assert(outputmessage->getState() == OutputMessage::STATE_FREE);
#endif
		m_outputMessages.pop_back();
	}

	configureOutputMessage(outputmessage, protocol, autosend);
	return outputmessage;
}

void OutputMessagePool::configureOutputMessage(OutputMessage* msg, Protocol* protocol, bool autosend)
{
	msg->Reset();
	if(autosend){
		msg->setState(OutputMessage::STATE_ALLOCATED);
		m_autoSendOutputMessages.push_back(msg);
	}
	else{
		msg->setState(OutputMessage::STATE_ALLOCATED_NO_AUTOSEND);
	}
	msg->setProtocol(protocol);
	msg->setConnection(protocol->getConnection());
	msg->setFrame(m_frameTime);
}
And outputmessage.h
Code:
//////////////////////////////////////////////////////////////////////
// OpenTibia - an opensource roleplaying game
//////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software Foundation,
// Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
//////////////////////////////////////////////////////////////////////

#ifndef __OTSERV_OUTPUT_MESSAGE_H__
#define __OTSERV_OUTPUT_MESSAGE_H__

#include "networkmessage.h"
#include "otsystem.h"
#include <list>

#ifdef __TRACK_NETWORK__
#include <iostream>
#include <sstream>
#endif

#include <boost/utility.hpp>

class Protocol;
class Connection;

#define OUTPUT_POOL_SIZE 100

class OutputMessage : public NetworkMessage, boost::noncopyable
{
	private:
		OutputMessage();

	public:
		~OutputMessage() {}

		char* getOutputBuffer() { return (char*)&m_MsgBuf[m_outputBufferStart];}

		void writeMessageLength()
		{
			*(uint16_t*)(m_MsgBuf + 2) = m_MsgSize;
			//added header size to the message size
			m_MsgSize = m_MsgSize + 2;
			m_outputBufferStart = 2;
		}

		void addCryptoHeader()
		{
			*(uint16_t*)(m_MsgBuf) = m_MsgSize;
			m_MsgSize = m_MsgSize + 2;
			m_outputBufferStart = 0;
		}

		enum OutputMessageState
		{
			STATE_FREE,
			STATE_ALLOCATED,
			STATE_ALLOCATED_NO_AUTOSEND,
			STATE_WAITING
		};

		Protocol* getProtocol() { return m_protocol;}
		Connection* getConnection() { return m_connection;}

#ifdef __TRACK_NETWORK__
		void Track(std::string file, int64_t line, std::string func)
		{
			if(last_uses.size() >= 25)
				last_uses.pop_front();

			std::ostringstream os;
			os << /*file << ":"*/ "line " << line << " " << func;
			last_uses.push_back(os.str());
		}
		void PrintTrace()
		{
			uint32_t n = 1;
			for(std::list<std::string>::const_reverse_iterator iter = last_uses.rbegin(); iter != last_uses.rend(); ++iter, ++n)
				std::cout << "\t" << n << ".\t" << *iter << std::endl;
		}
#endif

	protected:
#ifdef __TRACK_NETWORK__
		std::list<std::string> last_uses;
#endif

		void freeMessage()
		{
			setConnection(NULL);
			setProtocol(NULL);
			m_frame = 0;
			m_outputBufferStart = 4;
			//setState have to be the last one
			setState(OutputMessage::STATE_FREE);
		}

		friend class OutputMessagePool;

		void setProtocol(Protocol* protocol){ m_protocol = protocol;}
		void setConnection(Connection* connection){ m_connection = connection;}

		void setState(OutputMessageState state) { m_state = state;}
		OutputMessageState getState() const { return m_state;}

		void setFrame(uint64_t frame) { m_frame = frame;}
		uint64_t getFrame() const { return m_frame;}

		Protocol* m_protocol;
		Connection* m_connection;

		uint32_t m_outputBufferStart;
		uint64_t m_frame;

		OutputMessageState m_state;
};

class OutputMessagePool
{
	private:
		OutputMessagePool();

	public:
		~OutputMessagePool();

		static OutputMessagePool* getInstance()
		{
			static OutputMessagePool instance;
			return &instance;
		}

		void send(OutputMessage* msg);
		void sendAll();
		OutputMessage* getOutputMessage(Protocol* protocol, bool autosend = true);
		void startExecutionFrame();

		void releaseMessage(OutputMessage* msg, bool sent = false);

	protected:
		void configureOutputMessage(OutputMessage* msg, Protocol* protocol, bool autosend);

		void internalReleaseMessage(OutputMessage* msg);

		typedef std::list<OutputMessage*> OutputMessageVector;

		OutputMessageVector m_outputMessages;
		OutputMessageVector m_autoSendOutputMessages;
		OTSYS_THREAD_LOCKVAR m_outputPoolLock;
		uint64_t m_frameTime;
};

#ifdef __TRACK_NETWORK__
	#define TRACK_MESSAGE(omsg) if(dynamic_cast<OutputMessage*>(omsg)) dynamic_cast<OutputMessage*>(omsg)->Track(__FILE__, __LINE__, __FUNCTION__)
#else
	#define TRACK_MESSAGE(omsg) 
#endif

#endif
Rebuild all,
maybe it will help u:)
 
Hello,
Thanks for answer ragal, but this script is to move from 8.11 to 8.10 or to fix the BUG of CPU Usage?

I tried the way to go from 8.11 to 8.10 in rev 752 but did not work, appears The BUG in the same way ...

Any other suggestions?

Thanks,
[ADM]LordiN
 
Back
Top