Fixed player disconnects (again).
This commit is contained in:
@@ -92,9 +92,17 @@ SenderThread::Main()
|
|||||||
int selectResult = select(m_curSocket + 1, NULL, &writeSet, NULL, &timeout);
|
int selectResult = select(m_curSocket + 1, NULL, &writeSet, NULL, &timeout);
|
||||||
if (!IS_VALID_SELECT(selectResult))
|
if (!IS_VALID_SELECT(selectResult))
|
||||||
{
|
{
|
||||||
m_callback.SignalNetError(m_curSocket, ERR_SOCK_SELECT_FAILED, SOCKET_ERRNO());
|
// Never assume that this is a fatal error.
|
||||||
// Assume that this is a fatal error, terminate thread.
|
int errCode = SOCKET_ERRNO();
|
||||||
return;
|
if (errCode != SOCKET_ERR_WOULDBLOCK)
|
||||||
|
{
|
||||||
|
// Skip this packet - this is bad, and is therefore reported.
|
||||||
|
// Ignore invalid or not connected sockets.
|
||||||
|
if (errCode != SOCKET_ERR_NOTCONN && errCode != SOCKET_ERR_NOTSOCK)
|
||||||
|
m_callback.SignalNetError(m_curSocket, ERR_SOCK_SELECT_FAILED, errCode);
|
||||||
|
m_tmpOutBufSize = 0;
|
||||||
|
}
|
||||||
|
Msleep(SEND_TIMEOUT_MSEC);
|
||||||
}
|
}
|
||||||
if (selectResult > 0) // send is possible
|
if (selectResult > 0) // send is possible
|
||||||
{
|
{
|
||||||
@@ -103,9 +111,17 @@ SenderThread::Main()
|
|||||||
|
|
||||||
if (!IS_VALID_SEND(bytesSent))
|
if (!IS_VALID_SEND(bytesSent))
|
||||||
{
|
{
|
||||||
m_callback.SignalNetError(m_curSocket, ERR_SOCK_SEND_FAILED, SOCKET_ERRNO());
|
// Never assume that this is a fatal error.
|
||||||
// Assume that this is a fatal error, terminate thread.
|
int errCode = SOCKET_ERRNO();
|
||||||
return;
|
if (errCode != SOCKET_ERR_WOULDBLOCK)
|
||||||
|
{
|
||||||
|
// Skip this packet - this is bad, and is therefore reported.
|
||||||
|
// Ignore invalid or not connected sockets.
|
||||||
|
if (errCode != SOCKET_ERR_NOTCONN && errCode != SOCKET_ERR_NOTSOCK)
|
||||||
|
m_callback.SignalNetError(m_curSocket, ERR_SOCK_SEND_FAILED, errCode);
|
||||||
|
m_tmpOutBufSize = 0;
|
||||||
|
}
|
||||||
|
Msleep(SEND_TIMEOUT_MSEC);
|
||||||
}
|
}
|
||||||
else if ((unsigned)bytesSent < m_tmpOutBufSize)
|
else if ((unsigned)bytesSent < m_tmpOutBufSize)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -426,17 +426,19 @@ ServerRecvStateStartHand::Process(ServerRecvThread &server)
|
|||||||
// Send cards to all players.
|
// Send cards to all players.
|
||||||
for (int i = 0; i < curGame.getStartQuantityPlayers(); i++)
|
for (int i = 0; i < curGame.getStartQuantityPlayers(); i++)
|
||||||
{
|
{
|
||||||
assert(playerArray[i]->getNetSessionData().get()); // TODO throw exception
|
// also send to inactive players, but not to disconnected players.
|
||||||
|
if (playerArray[i]->getNetSessionData().get())
|
||||||
|
{
|
||||||
|
int cards[2];
|
||||||
|
playerArray[i]->getMyCards(cards);
|
||||||
|
boost::shared_ptr<NetPacket> notifyCards(new NetPacketHandStart);
|
||||||
|
NetPacketHandStart::Data handStartData;
|
||||||
|
handStartData.yourCards[0] = static_cast<unsigned>(cards[0]);
|
||||||
|
handStartData.yourCards[1] = static_cast<unsigned>(cards[1]);
|
||||||
|
static_cast<NetPacketHandStart *>(notifyCards.get())->SetData(handStartData);
|
||||||
|
|
||||||
int cards[2];
|
server.GetSender().Send(playerArray[i]->getNetSessionData()->GetSocket(), notifyCards);
|
||||||
playerArray[i]->getMyCards(cards);
|
}
|
||||||
boost::shared_ptr<NetPacket> notifyCards(new NetPacketHandStart);
|
|
||||||
NetPacketHandStart::Data handStartData;
|
|
||||||
handStartData.yourCards[0] = static_cast<unsigned>(cards[0]);
|
|
||||||
handStartData.yourCards[1] = static_cast<unsigned>(cards[1]);
|
|
||||||
static_cast<NetPacketHandStart *>(notifyCards.get())->SetData(handStartData);
|
|
||||||
|
|
||||||
server.GetSender().Send(playerArray[i]->getNetSessionData()->GetSocket(), notifyCards);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start hand.
|
// Start hand.
|
||||||
|
|||||||
@@ -476,13 +476,11 @@ ServerRecvThread::RemoveDisconnectedPlayers()
|
|||||||
for (int i = 0; i < m_game->getStartQuantityPlayers(); i++)
|
for (int i = 0; i < m_game->getStartQuantityPlayers(); i++)
|
||||||
{
|
{
|
||||||
PlayerInterface *tmpPlayer = m_game->getPlayerArray()[i];
|
PlayerInterface *tmpPlayer = m_game->getPlayerArray()[i];
|
||||||
if (tmpPlayer->getMyActiveStatus())
|
if (!IsPlayerConnected(tmpPlayer->getMyUniqueID()))
|
||||||
{
|
{
|
||||||
if (!IsPlayerConnected(tmpPlayer->getMyUniqueID()))
|
tmpPlayer->setMyCash(0);
|
||||||
{
|
tmpPlayer->setMyActiveStatus(false);
|
||||||
tmpPlayer->setMyCash(0);
|
tmpPlayer->setNetSessionData(boost::shared_ptr<SessionData>());
|
||||||
tmpPlayer->setMyActiveStatus(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,8 +30,8 @@
|
|||||||
#include <boost/shared_ptr.hpp>
|
#include <boost/shared_ptr.hpp>
|
||||||
|
|
||||||
#define SENDER_THREAD_TERMINATE_TIMEOUT 200
|
#define SENDER_THREAD_TERMINATE_TIMEOUT 200
|
||||||
#define SEND_TIMEOUT_MSEC 50
|
#define SEND_TIMEOUT_MSEC 10
|
||||||
#define SEND_QUEUE_SIZE 200
|
#define SEND_QUEUE_SIZE 500
|
||||||
|
|
||||||
class SenderThread : public Thread
|
class SenderThread : public Thread
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -32,6 +32,8 @@
|
|||||||
#define IOCTLSOCKET ioctlsocket
|
#define IOCTLSOCKET ioctlsocket
|
||||||
#define SOCKET_ERRNO() WSAGetLastError()
|
#define SOCKET_ERRNO() WSAGetLastError()
|
||||||
#define SOCKET_ERR_WOULDBLOCK WSAEWOULDBLOCK
|
#define SOCKET_ERR_WOULDBLOCK WSAEWOULDBLOCK
|
||||||
|
#define SOCKET_ERR_NOTCONN WSAENOTCONN
|
||||||
|
#define SOCKET_ERR_NOTSOCK WSAENOTSOCK
|
||||||
|
|
||||||
typedef unsigned __int16 u_int16_t;
|
typedef unsigned __int16 u_int16_t;
|
||||||
typedef unsigned __int32 u_int32_t;
|
typedef unsigned __int32 u_int32_t;
|
||||||
@@ -47,6 +49,8 @@ typedef unsigned char u_char;
|
|||||||
#define SOCKET_ERRNO() errno
|
#define SOCKET_ERRNO() errno
|
||||||
#define IOCTLSOCKET ioctl
|
#define IOCTLSOCKET ioctl
|
||||||
#define SOCKET_ERR_WOULDBLOCK EINPROGRESS
|
#define SOCKET_ERR_WOULDBLOCK EINPROGRESS
|
||||||
|
#define SOCKET_ERR_NOTCONN ENOTCONN
|
||||||
|
#define SOCKET_ERR_NOTSOCK ENOTSOCK
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user