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.

62 lines
1.2 KiB

  1. #ifndef __BETACORE_CLIENT_HPP__
  2. #define __BETACORE_CLIENT_HPP__
  3. #include <string>
  4. #include <iostream>
  5. #include <functional>
  6. #include <sstream>
  7. #include <vector>
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <string.h>
  11. #include <sys/types.h>
  12. #include <netdb.h>
  13. #include <netinet/in.h>
  14. #include <unistd.h>
  15. #include "common.hpp"
  16. namespace betacore{
  17. class Client{
  18. private:
  19. bool _online = false;
  20. bool _running= false;
  21. char key = 'Z';
  22. int _port;
  23. std::string _address;
  24. MODE _mode;
  25. int _client_socket;
  26. std::function<void(SHAPE &S)> _update;
  27. struct sockaddr_in _server_address;
  28. struct hostent * _server;
  29. std::string encode(const SHAPE &shape);
  30. std::string crypt(const std::string &shape);
  31. std::string raw(const SHAPE &shape);
  32. SHAPE parse(const std::string &message);
  33. SHAPE decode(const std::string &message);
  34. /**
  35. * Function for Thread for getting information from server
  36. */
  37. void listener();
  38. /**
  39. * Function for Thread for sending to server
  40. */
  41. void sender();
  42. void start();
  43. void stop();
  44. public:
  45. Client(MODE mode, int port, std::string address, std::function<void(SHAPE &S)> &update);
  46. void kill();
  47. bool running();
  48. void send(bool encrypt, SHAPE shape);
  49. };
  50. }
  51. #endif