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.

84 lines
1.5 KiB

5 years ago
5 years ago
5 years ago
5 years ago
  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, MODE &M)> _update;
  31. struct sockaddr_in _server_address;
  32. struct hostent *_server;
  33. std::map<std::string, std::string> lookup;
  34. std::vector<std::string> explode(std::string &message);
  35. std::string encode(const SHAPE &shape);
  36. std::string crypt(const std::string &shape);
  37. std::string raw(const SHAPE &shape);
  38. SHAPE parse(const std::string &message);
  39. SHAPE decode(const std::string &message);
  40. /**
  41. * Function for Thread for getting information from server
  42. */
  43. void listener();
  44. /**
  45. * Function for Thread for sending to server
  46. */
  47. void sender();
  48. void start();
  49. void stop();
  50. public:
  51. /*
  52. * Create an instance of client
  53. */
  54. Client(
  55. MODE mode,
  56. int port,
  57. std::string url,
  58. std::function<void(SHAPE &S, MODE &M)> &update);
  59. ~Client();
  60. /*
  61. * Kill the server
  62. */
  63. void kill();
  64. /*
  65. * Running
  66. */
  67. bool running();
  68. /*
  69. * Send the shape encrypted or raw
  70. */
  71. void send(bool encrypt, SHAPE shape);
  72. };
  73. } // namespace betacore
  74. #endif