Game Development Reference
In-Depth Information
number or an account ID number or whatever. On Ultima Online, this ID was a
unique player ID number that was assigned to it by the account login system when
new accounts were created. You can use whatever you want, but it is a good thing to
associate an unchanging ID number with each socket, since socket handles can
change if the socket is dropped and reconnected.
Another thing that the socket manager tracks is statistics for socket traffic and the
maximum number of sockets the manager has managed at one time. This can be
useful if you decide to track that sort of thing in production or even after release.
As an example, Ultima Online tracked all manner of statistics about player activity,
network activity, and so on.
If you set the subnet members, the socket manager can tell if a socket is coming from
an internal IP address. For example, it can ensure that an IP address is on the local
network and deny access from an IP address coming from the Internet. This feature
proved to be pretty useful to mask off special functions, like the
God
commands in
Ultima Online, from anyone outside of the development team.
Like other members of the application layer, the socket manager is a singleton object.
It can manage both client and listen sockets, although the implementations in this
chapter favor a straight client or straight server paradigm.
BaseSocketManager *g_pSocketManager = NULL;
BaseSocketManager::BaseSocketManager()
{
m_Inbound = 0;
m_Outbound = 0;
m_MaxOpenSockets = 0;
m_SubnetMask = 0;
m_Subnet = 0xffffffff;
g_pSocketManager = this;
ZeroMemory(&m_WsaData, sizeof(WSADATA));
}
bool BaseSocketManager::Init()
{
if (WSAStartup(0x0202, &m_WsaData)==0)
return true;
else
{
GCC_ERROR(
WSAStartup failure!
);
return false;
}
Search WWH ::




Custom Search