Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

86 lines
2.1 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //===========================================================================//
  6. #ifndef NETWORKSERVER_H
  7. #define NETWORKSERVER_H
  8. #include "networksystem/inetworksystem.h"
  9. #include "netchannel.h"
  10. //-----------------------------------------------------------------------------
  11. // Forward declarations
  12. //-----------------------------------------------------------------------------
  13. class CPlayer;
  14. //-----------------------------------------------------------------------------
  15. // Server class
  16. //-----------------------------------------------------------------------------
  17. class CNetworkServer : public IConnectionlessPacketHandler, public INetworkMessageHandler, public ILookupChannel
  18. {
  19. public:
  20. CNetworkServer( );
  21. virtual ~CNetworkServer();
  22. bool Init( int nServerPort );
  23. void Shutdown();
  24. // IConnectionlessPacketHandler
  25. virtual bool ProcessConnectionlessPacket( CNetPacket *packet ); // process a connectionless packet
  26. // INetworkMessageHandler
  27. virtual void OnConnectionClosing( INetChannel *channel, char const *reason );
  28. virtual void OnConnectionStarted( INetChannel *channel );
  29. virtual void OnPacketStarted( int inseq, int outseq );
  30. virtual void OnPacketFinished();
  31. // ILookupChannel
  32. virtual CNetChannel *FindNetChannel( const netadr_t& from ) ;
  33. void ReadPackets();
  34. void SendUpdates();
  35. void AcceptConnection( const netadr_t& remote );
  36. CPlayer *FindPlayerByAddress( const netadr_t& adr );
  37. CPlayer *FindPlayerByNetChannel( INetChannel *chan );
  38. CUDPSocket *m_pSocket;
  39. CUtlVector< CPlayer * > m_Players;
  40. };
  41. //-----------------------------------------------------------------------------
  42. // Represents a connected player to the server
  43. //-----------------------------------------------------------------------------
  44. class CPlayer
  45. {
  46. public:
  47. CPlayer( CNetworkServer *server, netadr_t& remote );
  48. void SendUpdate();
  49. const netadr_t &GetRemoteAddress()
  50. {
  51. return m_NetChan.GetRemoteAddress();
  52. }
  53. char const *GetName()
  54. {
  55. return "Foozle";
  56. }
  57. void Shutdown();
  58. CNetChannel m_NetChan;
  59. bool m_bMarkedForDeletion;
  60. };
  61. #endif // NETWORKSERVER_H