PolyServer.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * PolyServer.h
  3. * Poly
  4. *
  5. * Created by Ivan Safrin on 3/6/09.
  6. * Copyright 2009 __MyCompanyName__. All rights reserved.
  7. *
  8. */
  9. // @package Network
  10. #pragma once
  11. #include "PolyGlobals.h"
  12. #include "PolyPeer.h"
  13. #include "PolyEvent.h"
  14. #include "PolyServerWorld.h"
  15. #include <vector>
  16. using std::vector;
  17. namespace Polycode {
  18. class _PolyExport ServerClientEvent : public Event {
  19. public:
  20. ServerClientEvent() {}
  21. ~ServerClientEvent() {}
  22. char *data;
  23. unsigned int dataSize;
  24. unsigned short dataType;
  25. static const int EVENT_CLIENT_DATA = 0;
  26. };
  27. class _PolyExport ServerClient : public EventDispatcher {
  28. public:
  29. ServerClient();
  30. ~ServerClient();
  31. void handlePacket(Packet *packet);
  32. unsigned int clientID;
  33. PeerConnection *connection;
  34. };
  35. class _PolyExport ServerEvent : public Event {
  36. public:
  37. ServerEvent(){client = NULL; }
  38. ~ServerEvent(){}
  39. ServerClient *client;
  40. static const int EVENT_CLIENT_CONNECTED = 0;
  41. static const int EVENT_CLIENT_DATA = 1;
  42. };
  43. class _PolyExport Server : public Peer {
  44. public:
  45. Server(unsigned int port, unsigned int rate, ServerWorld *world);
  46. ~Server();
  47. void handleEvent(Event *event);
  48. void handlePeerConnection(PeerConnection *connection);
  49. ServerClient *getConnectedClient(PeerConnection *connection);
  50. void sendReliableDataToClient(ServerClient *client, char *data, unsigned int size, unsigned short type);
  51. void handlePacket(Packet *packet, PeerConnection *connection);
  52. protected:
  53. Timer *rateTimer;
  54. ServerWorld *world;
  55. vector<ServerClient*> clients;
  56. };
  57. }