Jump to content
External pictures are being replaced... ×
×
×
  • Create New...

Small Fix About Connect


Recommended Posts

  • Moon

Hi, everyone. Most people know when you are trying to connect the server with a lot of people, the server can not respond to you or something might go wrong. This example is same for warp too. Webzen did something about this too and I'd like to share it with you.

What are exactly are we doing?

If the client can not connect to the server, the client will wait one second to connect the server again.

Open NetStream.cpp. Find Connect function and replace with this

bool CNetworkStream::Connect(const CNetworkAddress& c_rkNetAddr, int limitSec)
{
	Clear();

	m_addr = c_rkNetAddr;

	m_sock = socket(AF_INET, SOCK_STREAM, 0);

	if (m_sock == INVALID_SOCKET)
	{
		Clear();
		OnConnectFailure();
		return false;
	}

	DWORD arg = 1;
	ioctlsocket(m_sock, FIONBIO, &arg);	// Non-blocking mode

	if (connect(m_sock, reinterpret_cast<PSOCKADDR>(&m_addr), m_addr.GetSize()) == SOCKET_ERROR)
	{
		int error = WSAGetLastError();

      	// If something went wrong, the client will wait one second to connect the server again.
      	// Of course, it will clear and setting up everything again.
		if (error != WSAEWOULDBLOCK)
		{
			Sleep(1000);
			Clear();
			m_sock = socket(AF_INET, SOCK_STREAM, 0);
			if (m_sock == INVALID_SOCKET)
			{
				Clear();
				OnConnectFailure();
				return false;

			}

			ioctlsocket(m_sock, FIONBIO, &arg);
			if (connect(m_sock, reinterpret_cast<PSOCKADDR>(&m_addr), m_addr.GetSize()) == SOCKET_ERROR)
			{
				Tracen("error != WSAEWOULDBLOCK");
				Clear();
				OnConnectFailure();
				return false;
			}
		}
	}

	m_connectLimitTime = time(NULL) + limitSec;
	return true;	
}

Best Regards

Ken

  • Love 16

Do not be sorry, be better.

Link to comment
Share on other sites

  • 6 months later...
  • Premium
On 1/7/2017 at 6:07 PM, Ken said:

when you are trying to connect the server with a lot of people

 

 

52 minutes ago, Cyber36 said:

How can I test this bug on my server? (To test the fix?)

MfG

Cyber

 

 

"Nothing's free in this life.

Ignorant people have an obligation to make up for their ignorance by paying those who help them.

Either you got the brains or cash, if you lack both you're useless."

Syreldar

Link to comment
Share on other sites

  • 2 years later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.


Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.