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.

63 lines
1.3 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 <thread>
  9. #include <map>
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <string.h>
  13. #include <sys/types.h>
  14. #include <netdb.h>
  15. #include <netinet/in.h>
  16. #include <unistd.h>
  17. #include "common.hpp"
  18. namespace betacore
  19. {
  20. class Client
  21. {
  22. private:
  23. bool _online = false;
  24. bool _running = false;
  25. char key = 'Z';
  26. int _port;
  27. std::string _url;
  28. MODE _mode;
  29. int _client_socket;
  30. std::function<void(SHAPE &S)> _update;
  31. struct sockaddr_in _server_address;
  32. struct hostent *_server;
  33. std::map<std::string, std::string> lookup;
  34. std::string encode(const SHAPE &shape);
  35. std::string crypt(const std::string &shape);
  36. std::string raw(const SHAPE &shape);
  37. SHAPE parse(const std::string &message);
  38. SHAPE decode(const std::string &message);
  39. /**
  40. * Function for Thread for getting information from server
  41. */
  42. void listener();
  43. /**
  44. * Function for Thread for sending to server
  45. */
  46. void sender();
  47. void start();
  48. void stop();
  49. public:
  50. Client(MODE mode, int port, std::string url, std::function<void(SHAPE &S)> &update);
  51. void kill();
  52. bool running();
  53. void send(bool encrypt, SHAPE shape);
  54. };
  55. } // namespace betacore
  56. #endif