1
0
forked from 0ad/0ad
0ad/source/ps/Network/Session.h
olsner 7bcc12373b - Created JSMap
- Changed player colour JS interface: setColour(...) instead of a colour
property
- Introduced a network log and replaced most network LOG() calls with
NET_LOG()
- Moved to a slot-based system for Pre-Game and extended a lot of the JS
APIs to networking stuff
- A bit of cleanup in the low-level network code (Unix parts)
- Clients now keep track of all other connected clients on the server
(And exposes this info to JS)
- Split out GameAttributes to its own file
- Removed unused class AttributeMap
- Changed CJSObject to use T* pointers in JS_SetPrivate (needed to make
ToScript work with multiple inheritance)

This was SVN commit r1929.
2005-02-21 17:13:31 +00:00

71 lines
1.5 KiB
C++
Executable File

#ifndef _Network_NetSession_H
#define _Network_NetSession_H
#include <Network/Network.h>
#include <Network/SessionManager.h>
/*
CNetSession
DESCRIPTION:
The representation of a network session (on both the client and server
side)
*/
class CNetSession: public CMessageSocket
{
protected:
/*
The MessageHandler callback follows the contract of HandleMessage, see
the documentation for that function for more information.
*/
typedef bool (MessageHandler)(CNetMessage *, CNetSession *);
MessageHandler *m_pMessageHandler;
CStrW m_Name;
public:
inline CNetSession(MessageHandler *pMsgHandler=NULL):
m_pMessageHandler(pMsgHandler)
{
g_SessionManager.Register(this);
}
inline CNetSession(CSocketInternal *pInt, MessageHandler *pMsgHandler=NULL):
CMessageSocket(pInt),
m_pMessageHandler(pMsgHandler)
{
g_SessionManager.Register(this);
}
virtual ~CNetSession();
/*
Handle an incoming message.
THREADS:
When used with the session manager, this method will only be
called from the main thread.
ARGUMENTS:
pMsg The incoming message
pSocket The socket the message came from
RETURNS:
TRUE if the message was handled by this class or another protocol
that this class knows of. FALSE if the message was not handled.
*/
inline bool HandleMessage(CNetMessage *pMsg)
{
if (m_pMessageHandler)
return (m_pMessageHandler)(pMsg, this);
else
return false;
}
inline CStrW GetName()
{
return m_Name;
}
};
#endif //_Network_NetSession_H