summaryrefslogtreecommitdiff
path: root/networksystem/networkserver.h
blob: bd88b5b5319ed1161b63b4e92e9b7776845051c9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: 
//
//===========================================================================//

#ifndef NETWORKSERVER_H
#define NETWORKSERVER_H

#include "networksystem/inetworksystem.h"
#include "netchannel.h"


//-----------------------------------------------------------------------------
// Forward declarations
//-----------------------------------------------------------------------------
class CPlayer;


//-----------------------------------------------------------------------------
// Server class
//-----------------------------------------------------------------------------
class CNetworkServer : public IConnectionlessPacketHandler, public INetworkMessageHandler, public ILookupChannel
{
public:
	CNetworkServer( );
	virtual ~CNetworkServer();

	bool Init( int nServerPort );
	void Shutdown();

	// IConnectionlessPacketHandler
	virtual bool	ProcessConnectionlessPacket( CNetPacket *packet );	// process a connectionless packet
	
	// INetworkMessageHandler
	virtual void	OnConnectionClosing( INetChannel *channel, char const *reason );
	virtual void	OnConnectionStarted( INetChannel *channel );

	virtual void	OnPacketStarted( int inseq, int outseq );
	virtual void	OnPacketFinished();

	// ILookupChannel
    virtual CNetChannel *FindNetChannel( const netadr_t& from ) ;

	void ReadPackets();
	void SendUpdates();
	void AcceptConnection( const netadr_t& remote );

	CPlayer *FindPlayerByAddress( const netadr_t& adr );
	CPlayer *FindPlayerByNetChannel( INetChannel *chan );

	CUDPSocket *m_pSocket;

	CUtlVector< CPlayer * >	m_Players;
};


//-----------------------------------------------------------------------------
// Represents a connected player to the server
//-----------------------------------------------------------------------------
class CPlayer
{
public:
	CPlayer( CNetworkServer *server, netadr_t& remote );

	void			SendUpdate();

	const netadr_t		&GetRemoteAddress()
	{
		return m_NetChan.GetRemoteAddress();
	}

	char const *GetName()
	{
		return "Foozle";
	}

	void			Shutdown();

	CNetChannel		m_NetChan;
	bool			m_bMarkedForDeletion;
};


#endif // NETWORKSERVER_H