You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

Communication.h 2.0 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #ifndef COMMUNICATION_H
  2. #define COMMUNICATION_H
  3. #include "Message2Server.pb.h"
  4. #include "Message2Clients.pb.h"
  5. #include "MessageType.pb.h"
  6. #include "Services.grpc.pb.h"
  7. #include "Services.pb.h"
  8. #include <grpcpp/grpcpp.h>
  9. #include "structures.h"
  10. #include <thread>
  11. #include <mutex>
  12. #include <condition_variable>
  13. #include <queue>
  14. #include <atomic>
  15. #undef GetMessage
  16. #undef SendMessage
  17. #undef PeekMessage
  18. class Logic;
  19. class Communication
  20. {
  21. public:
  22. Communication(std::string sIP, std::string sPort);
  23. ~Communication()
  24. {
  25. }
  26. bool Move(int64_t time, double angle, int64_t playerID);
  27. bool PickProp(THUAI6::PropType prop, int64_t playerID);
  28. bool UseProp(THUAI6::PropType prop, int64_t playerID);
  29. bool ThrowProp(THUAI6::PropType prop, int64_t playerID);
  30. bool UseSkill(int32_t skillID, int64_t playerID);
  31. bool SendMessage(int64_t toID, std::string message, bool binary, int64_t playerID);
  32. bool OpenDoor(int64_t playerID);
  33. bool CloseDoor(int64_t playerID);
  34. bool SkipWindow(int64_t playerID);
  35. bool StartOpenGate(int64_t playerID);
  36. bool StartOpenChest(int64_t playerID);
  37. bool EndAllAction(int64_t playerID);
  38. bool Graduate(int64_t playerID);
  39. bool StartLearning(int64_t playerID);
  40. bool StartEncourageMate(int64_t playerID, int64_t mateID);
  41. bool StartRouseMate(int64_t playerID, int64_t mateID);
  42. bool Attack(double angle, int64_t playerID);
  43. bool TryConnection(int64_t playerID);
  44. protobuf::MessageToClient GetMessage2Client();
  45. void AddPlayer(int64_t playerID, THUAI6::PlayerType playerType, THUAI6::StudentType studentType, THUAI6::TrickerType trickerType);
  46. private:
  47. std::unique_ptr<protobuf::AvailableService::Stub> THUAI6Stub;
  48. bool haveNewMessage = false;
  49. protobuf::MessageToClient message2Client;
  50. std::mutex mtxMessage;
  51. std::mutex mtxLimit;
  52. int counter;
  53. static constexpr const int limit = 50;
  54. std::condition_variable cvMessage;
  55. };
  56. #endif