diff --git a/.github/FUNDING.yaml b/.github/FUNDING.yaml new file mode 100644 index 0000000..87df536 --- /dev/null +++ b/.github/FUNDING.yaml @@ -0,0 +1,3 @@ +# These are supported funding model platforms + +github: [TCL606] diff --git a/.github/workflows/clang-format.yml b/.github/workflows/clang-format.yml deleted file mode 100644 index a21aed8..0000000 --- a/.github/workflows/clang-format.yml +++ /dev/null @@ -1,13 +0,0 @@ -name: clang-format -on: [push, pull_request] -jobs: - clang-format-checking: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: DoozyX/clang-format-lint-action@v0.14 - with: - source: '.' - extensions: 'cs,c,h,C,H,cpp,hpp,cc,hh,c++,h++,cxx,hxx,i,ixx,ipp,i++' - clangFormatVersion: 14 - inplace: False diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml new file mode 100644 index 0000000..5357743 --- /dev/null +++ b/.github/workflows/format.yml @@ -0,0 +1,34 @@ +name: format +on: [push, pull_request] +jobs: + clang-format-checking: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: DoozyX/clang-format-lint-action@v0.14 + with: + source: '.' + extensions: 'c,h,C,H,cpp,hpp,cc,hh,c++,h++,cxx,hxx,i,ixx,ipp,i++' + clangFormatVersion: 14 + inplace: False + + dotnet-format-checking: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Setup .NET Core + uses: actions/setup-dotnet@v3 + with: + dotnet-version: 6.0.x + + - name: Check Logic + run: dotnet format "./logic/logic.sln" --severity error --no-restore + + - name: Check Installer + run: dotnet format "./installer/installer.sln" --severity error --no-restore + + - name: Check Launcher + run: dotnet format "./launcher/launcher.sln" --severity error --no-restore + + - name: Check Playback + run: dotnet format "./playback/playback.sln" --severity error --no-restore diff --git a/CAPI/API/include/structures.h b/CAPI/API/include/structures.h index bdeab2e..436e1e7 100644 --- a/CAPI/API/include/structures.h +++ b/CAPI/API/include/structures.h @@ -87,7 +87,7 @@ namespace THUAI6 ButcherBuffType4 = 4, }; - //人类状态枚举 + // 人类状态枚举 enum class HumanState : unsigned char { NullHumanState = 0, @@ -118,8 +118,7 @@ namespace THUAI6 struct Human : public Player { - bool onChair; // 是否被挂 - bool onGround; // 是否倒地 + HumanState state; // 人类状态 int32_t life; // 剩余生命(本次倒地之前还能承受的伤害) int32_t hangedTime; // 被挂的次数 diff --git a/CAPI/API/include/utils.hpp b/CAPI/API/include/utils.hpp index 1f5a5f9..d73d333 100644 --- a/CAPI/API/include/utils.hpp +++ b/CAPI/API/include/utils.hpp @@ -76,6 +76,15 @@ namespace Proto2THUAI6 {protobuf::ButcherBuffType::BBUFFTYPE4, THUAI6::ButcherBuffType::ButcherBuffType4}, }; + inline std::map humanStateDict{ + {protobuf::HumanState::NULL_STATUS, THUAI6::HumanState::NullHumanState}, + {protobuf::HumanState::IDLE, THUAI6::HumanState::Idle}, + {protobuf::HumanState::FIXING, THUAI6::HumanState::Fixing}, + {protobuf::HumanState::DYING, THUAI6::HumanState::Dying}, + {protobuf::HumanState::ON_CHAIR, THUAI6::HumanState::OnChair}, + {protobuf::HumanState::DEAD, THUAI6::HumanState::Dead}, + }; + // 用于将Protobuf中的类转换为THUAI6的类 inline std::shared_ptr Protobuf2THUAI6Butcher(const protobuf::MessageOfButcher& butcherMsg) { @@ -115,8 +124,7 @@ namespace Proto2THUAI6 human->playerType = THUAI6::PlayerType::HumanPlayer; human->prop = propTypeDict[humanMsg.prop()]; human->place = placeTypeDict[humanMsg.place()]; - human->onChair = humanMsg.on_chair(); - human->onGround = humanMsg.on_ground(); + human->state = humanStateDict[humanMsg.state()]; human->life = humanMsg.life(); human->hangedTime = humanMsg.hanged_time(); human->humanType = humanTypeDict[humanMsg.human_type()]; diff --git a/CAPI/proto/Services.grpc.pb.cc b/CAPI/proto/Services.grpc.pb.cc index b5edb79..3fdfba7 100644 --- a/CAPI/proto/Services.grpc.pb.cc +++ b/CAPI/proto/Services.grpc.pb.cc @@ -34,7 +34,7 @@ namespace protobuf "/protobuf.AvailableService/GetMessage", "/protobuf.AvailableService/StartFixMachine", "/protobuf.AvailableService/EndFixMachine", - "/protobuf.AvailableService/SaveHuman", + "/protobuf.AvailableService/StartSaveHuman", "/protobuf.AvailableService/EndSaveHuman", "/protobuf.AvailableService/Attack", "/protobuf.AvailableService/CarryHuman", @@ -63,7 +63,7 @@ namespace protobuf rpcmethod_GetMessage_(AvailableService_method_names[8], options.suffix_for_stats(), ::grpc::internal::RpcMethod::NORMAL_RPC, channel), rpcmethod_StartFixMachine_(AvailableService_method_names[9], options.suffix_for_stats(), ::grpc::internal::RpcMethod::NORMAL_RPC, channel), rpcmethod_EndFixMachine_(AvailableService_method_names[10], options.suffix_for_stats(), ::grpc::internal::RpcMethod::NORMAL_RPC, channel), - rpcmethod_SaveHuman_(AvailableService_method_names[11], options.suffix_for_stats(), ::grpc::internal::RpcMethod::NORMAL_RPC, channel), + rpcmethod_StartSaveHuman_(AvailableService_method_names[11], options.suffix_for_stats(), ::grpc::internal::RpcMethod::NORMAL_RPC, channel), rpcmethod_EndSaveHuman_(AvailableService_method_names[12], options.suffix_for_stats(), ::grpc::internal::RpcMethod::NORMAL_RPC, channel), rpcmethod_Attack_(AvailableService_method_names[13], options.suffix_for_stats(), ::grpc::internal::RpcMethod::NORMAL_RPC, channel), rpcmethod_CarryHuman_(AvailableService_method_names[14], options.suffix_for_stats(), ::grpc::internal::RpcMethod::NORMAL_RPC, channel), @@ -373,30 +373,30 @@ namespace protobuf return result; } - ::grpc::Status AvailableService::Stub::SaveHuman(::grpc::ClientContext* context, const ::protobuf::IDMsg& request, ::protobuf::BoolRes* response) + ::grpc::Status AvailableService::Stub::StartSaveHuman(::grpc::ClientContext* context, const ::protobuf::IDMsg& request, ::protobuf::BoolRes* response) { - return ::grpc::internal::BlockingUnaryCall<::protobuf::IDMsg, ::protobuf::BoolRes, ::grpc::protobuf::MessageLite, ::grpc::protobuf::MessageLite>(channel_.get(), rpcmethod_SaveHuman_, context, request, response); + return ::grpc::internal::BlockingUnaryCall<::protobuf::IDMsg, ::protobuf::BoolRes, ::grpc::protobuf::MessageLite, ::grpc::protobuf::MessageLite>(channel_.get(), rpcmethod_StartSaveHuman_, context, request, response); } - void AvailableService::Stub::async::SaveHuman(::grpc::ClientContext* context, const ::protobuf::IDMsg* request, ::protobuf::BoolRes* response, std::function f) + void AvailableService::Stub::async::StartSaveHuman(::grpc::ClientContext* context, const ::protobuf::IDMsg* request, ::protobuf::BoolRes* response, std::function f) { - ::grpc::internal::CallbackUnaryCall<::protobuf::IDMsg, ::protobuf::BoolRes, ::grpc::protobuf::MessageLite, ::grpc::protobuf::MessageLite>(stub_->channel_.get(), stub_->rpcmethod_SaveHuman_, context, request, response, std::move(f)); + ::grpc::internal::CallbackUnaryCall<::protobuf::IDMsg, ::protobuf::BoolRes, ::grpc::protobuf::MessageLite, ::grpc::protobuf::MessageLite>(stub_->channel_.get(), stub_->rpcmethod_StartSaveHuman_, context, request, response, std::move(f)); } - void AvailableService::Stub::async::SaveHuman(::grpc::ClientContext* context, const ::protobuf::IDMsg* request, ::protobuf::BoolRes* response, ::grpc::ClientUnaryReactor* reactor) + void AvailableService::Stub::async::StartSaveHuman(::grpc::ClientContext* context, const ::protobuf::IDMsg* request, ::protobuf::BoolRes* response, ::grpc::ClientUnaryReactor* reactor) { - ::grpc::internal::ClientCallbackUnaryFactory::Create<::grpc::protobuf::MessageLite, ::grpc::protobuf::MessageLite>(stub_->channel_.get(), stub_->rpcmethod_SaveHuman_, context, request, response, reactor); + ::grpc::internal::ClientCallbackUnaryFactory::Create<::grpc::protobuf::MessageLite, ::grpc::protobuf::MessageLite>(stub_->channel_.get(), stub_->rpcmethod_StartSaveHuman_, context, request, response, reactor); } - ::grpc::ClientAsyncResponseReader<::protobuf::BoolRes>* AvailableService::Stub::PrepareAsyncSaveHumanRaw(::grpc::ClientContext* context, const ::protobuf::IDMsg& request, ::grpc::CompletionQueue* cq) + ::grpc::ClientAsyncResponseReader<::protobuf::BoolRes>* AvailableService::Stub::PrepareAsyncStartSaveHumanRaw(::grpc::ClientContext* context, const ::protobuf::IDMsg& request, ::grpc::CompletionQueue* cq) { - return ::grpc::internal::ClientAsyncResponseReaderHelper::Create<::protobuf::BoolRes, ::protobuf::IDMsg, ::grpc::protobuf::MessageLite, ::grpc::protobuf::MessageLite>(channel_.get(), cq, rpcmethod_SaveHuman_, context, request); + return ::grpc::internal::ClientAsyncResponseReaderHelper::Create<::protobuf::BoolRes, ::protobuf::IDMsg, ::grpc::protobuf::MessageLite, ::grpc::protobuf::MessageLite>(channel_.get(), cq, rpcmethod_StartSaveHuman_, context, request); } - ::grpc::ClientAsyncResponseReader<::protobuf::BoolRes>* AvailableService::Stub::AsyncSaveHumanRaw(::grpc::ClientContext* context, const ::protobuf::IDMsg& request, ::grpc::CompletionQueue* cq) + ::grpc::ClientAsyncResponseReader<::protobuf::BoolRes>* AvailableService::Stub::AsyncStartSaveHumanRaw(::grpc::ClientContext* context, const ::protobuf::IDMsg& request, ::grpc::CompletionQueue* cq) { auto* result = - this->PrepareAsyncSaveHumanRaw(context, request, cq); + this->PrepareAsyncStartSaveHumanRaw(context, request, cq); result->StartCall(); return result; } @@ -734,7 +734,7 @@ namespace protobuf const ::protobuf::IDMsg* req, ::protobuf::BoolRes* resp) { - return service->SaveHuman(ctx, req, resp); + return service->StartSaveHuman(ctx, req, resp); }, this ) @@ -917,7 +917,7 @@ namespace protobuf return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); } - ::grpc::Status AvailableService::Service::SaveHuman(::grpc::ServerContext* context, const ::protobuf::IDMsg* request, ::protobuf::BoolRes* response) + ::grpc::Status AvailableService::Service::StartSaveHuman(::grpc::ServerContext* context, const ::protobuf::IDMsg* request, ::protobuf::BoolRes* response) { (void)context; (void)request; diff --git a/CAPI/proto/Services.grpc.pb.h b/CAPI/proto/Services.grpc.pb.h index bb709c6..209e0e4 100644 --- a/CAPI/proto/Services.grpc.pb.h +++ b/CAPI/proto/Services.grpc.pb.h @@ -148,14 +148,14 @@ namespace protobuf return std::unique_ptr<::grpc::ClientAsyncResponseReaderInterface<::protobuf::BoolRes>>(PrepareAsyncEndFixMachineRaw(context, request, cq)); } // 主动停止修复 - virtual ::grpc::Status SaveHuman(::grpc::ClientContext* context, const ::protobuf::IDMsg& request, ::protobuf::BoolRes* response) = 0; - std::unique_ptr<::grpc::ClientAsyncResponseReaderInterface<::protobuf::BoolRes>> AsyncSaveHuman(::grpc::ClientContext* context, const ::protobuf::IDMsg& request, ::grpc::CompletionQueue* cq) + virtual ::grpc::Status StartSaveHuman(::grpc::ClientContext* context, const ::protobuf::IDMsg& request, ::protobuf::BoolRes* response) = 0; + std::unique_ptr<::grpc::ClientAsyncResponseReaderInterface<::protobuf::BoolRes>> AsyncStartSaveHuman(::grpc::ClientContext* context, const ::protobuf::IDMsg& request, ::grpc::CompletionQueue* cq) { - return std::unique_ptr<::grpc::ClientAsyncResponseReaderInterface<::protobuf::BoolRes>>(AsyncSaveHumanRaw(context, request, cq)); + return std::unique_ptr<::grpc::ClientAsyncResponseReaderInterface<::protobuf::BoolRes>>(AsyncStartSaveHumanRaw(context, request, cq)); } - std::unique_ptr<::grpc::ClientAsyncResponseReaderInterface<::protobuf::BoolRes>> PrepareAsyncSaveHuman(::grpc::ClientContext* context, const ::protobuf::IDMsg& request, ::grpc::CompletionQueue* cq) + std::unique_ptr<::grpc::ClientAsyncResponseReaderInterface<::protobuf::BoolRes>> PrepareAsyncStartSaveHuman(::grpc::ClientContext* context, const ::protobuf::IDMsg& request, ::grpc::CompletionQueue* cq) { - return std::unique_ptr<::grpc::ClientAsyncResponseReaderInterface<::protobuf::BoolRes>>(PrepareAsyncSaveHumanRaw(context, request, cq)); + return std::unique_ptr<::grpc::ClientAsyncResponseReaderInterface<::protobuf::BoolRes>>(PrepareAsyncStartSaveHumanRaw(context, request, cq)); } // 开始救人 virtual ::grpc::Status EndSaveHuman(::grpc::ClientContext* context, const ::protobuf::IDMsg& request, ::protobuf::BoolRes* response) = 0; @@ -245,8 +245,8 @@ namespace protobuf virtual void EndFixMachine(::grpc::ClientContext* context, const ::protobuf::IDMsg* request, ::protobuf::BoolRes* response, std::function) = 0; virtual void EndFixMachine(::grpc::ClientContext* context, const ::protobuf::IDMsg* request, ::protobuf::BoolRes* response, ::grpc::ClientUnaryReactor* reactor) = 0; // 主动停止修复 - virtual void SaveHuman(::grpc::ClientContext* context, const ::protobuf::IDMsg* request, ::protobuf::BoolRes* response, std::function) = 0; - virtual void SaveHuman(::grpc::ClientContext* context, const ::protobuf::IDMsg* request, ::protobuf::BoolRes* response, ::grpc::ClientUnaryReactor* reactor) = 0; + virtual void StartSaveHuman(::grpc::ClientContext* context, const ::protobuf::IDMsg* request, ::protobuf::BoolRes* response, std::function) = 0; + virtual void StartSaveHuman(::grpc::ClientContext* context, const ::protobuf::IDMsg* request, ::protobuf::BoolRes* response, ::grpc::ClientUnaryReactor* reactor) = 0; // 开始救人 virtual void EndSaveHuman(::grpc::ClientContext* context, const ::protobuf::IDMsg* request, ::protobuf::BoolRes* response, std::function) = 0; virtual void EndSaveHuman(::grpc::ClientContext* context, const ::protobuf::IDMsg* request, ::protobuf::BoolRes* response, ::grpc::ClientUnaryReactor* reactor) = 0; @@ -296,8 +296,8 @@ namespace protobuf virtual ::grpc::ClientAsyncResponseReaderInterface<::protobuf::BoolRes>* PrepareAsyncStartFixMachineRaw(::grpc::ClientContext* context, const ::protobuf::IDMsg& request, ::grpc::CompletionQueue* cq) = 0; virtual ::grpc::ClientAsyncResponseReaderInterface<::protobuf::BoolRes>* AsyncEndFixMachineRaw(::grpc::ClientContext* context, const ::protobuf::IDMsg& request, ::grpc::CompletionQueue* cq) = 0; virtual ::grpc::ClientAsyncResponseReaderInterface<::protobuf::BoolRes>* PrepareAsyncEndFixMachineRaw(::grpc::ClientContext* context, const ::protobuf::IDMsg& request, ::grpc::CompletionQueue* cq) = 0; - virtual ::grpc::ClientAsyncResponseReaderInterface<::protobuf::BoolRes>* AsyncSaveHumanRaw(::grpc::ClientContext* context, const ::protobuf::IDMsg& request, ::grpc::CompletionQueue* cq) = 0; - virtual ::grpc::ClientAsyncResponseReaderInterface<::protobuf::BoolRes>* PrepareAsyncSaveHumanRaw(::grpc::ClientContext* context, const ::protobuf::IDMsg& request, ::grpc::CompletionQueue* cq) = 0; + virtual ::grpc::ClientAsyncResponseReaderInterface<::protobuf::BoolRes>* AsyncStartSaveHumanRaw(::grpc::ClientContext* context, const ::protobuf::IDMsg& request, ::grpc::CompletionQueue* cq) = 0; + virtual ::grpc::ClientAsyncResponseReaderInterface<::protobuf::BoolRes>* PrepareAsyncStartSaveHumanRaw(::grpc::ClientContext* context, const ::protobuf::IDMsg& request, ::grpc::CompletionQueue* cq) = 0; virtual ::grpc::ClientAsyncResponseReaderInterface<::protobuf::BoolRes>* AsyncEndSaveHumanRaw(::grpc::ClientContext* context, const ::protobuf::IDMsg& request, ::grpc::CompletionQueue* cq) = 0; virtual ::grpc::ClientAsyncResponseReaderInterface<::protobuf::BoolRes>* PrepareAsyncEndSaveHumanRaw(::grpc::ClientContext* context, const ::protobuf::IDMsg& request, ::grpc::CompletionQueue* cq) = 0; virtual ::grpc::ClientAsyncResponseReaderInterface<::protobuf::BoolRes>* AsyncAttackRaw(::grpc::ClientContext* context, const ::protobuf::AttackMsg& request, ::grpc::CompletionQueue* cq) = 0; @@ -417,14 +417,14 @@ namespace protobuf { return std::unique_ptr<::grpc::ClientAsyncResponseReader<::protobuf::BoolRes>>(PrepareAsyncEndFixMachineRaw(context, request, cq)); } - ::grpc::Status SaveHuman(::grpc::ClientContext* context, const ::protobuf::IDMsg& request, ::protobuf::BoolRes* response) override; - std::unique_ptr<::grpc::ClientAsyncResponseReader<::protobuf::BoolRes>> AsyncSaveHuman(::grpc::ClientContext* context, const ::protobuf::IDMsg& request, ::grpc::CompletionQueue* cq) + ::grpc::Status StartSaveHuman(::grpc::ClientContext* context, const ::protobuf::IDMsg& request, ::protobuf::BoolRes* response) override; + std::unique_ptr<::grpc::ClientAsyncResponseReader<::protobuf::BoolRes>> AsyncStartSaveHuman(::grpc::ClientContext* context, const ::protobuf::IDMsg& request, ::grpc::CompletionQueue* cq) { - return std::unique_ptr<::grpc::ClientAsyncResponseReader<::protobuf::BoolRes>>(AsyncSaveHumanRaw(context, request, cq)); + return std::unique_ptr<::grpc::ClientAsyncResponseReader<::protobuf::BoolRes>>(AsyncStartSaveHumanRaw(context, request, cq)); } - std::unique_ptr<::grpc::ClientAsyncResponseReader<::protobuf::BoolRes>> PrepareAsyncSaveHuman(::grpc::ClientContext* context, const ::protobuf::IDMsg& request, ::grpc::CompletionQueue* cq) + std::unique_ptr<::grpc::ClientAsyncResponseReader<::protobuf::BoolRes>> PrepareAsyncStartSaveHuman(::grpc::ClientContext* context, const ::protobuf::IDMsg& request, ::grpc::CompletionQueue* cq) { - return std::unique_ptr<::grpc::ClientAsyncResponseReader<::protobuf::BoolRes>>(PrepareAsyncSaveHumanRaw(context, request, cq)); + return std::unique_ptr<::grpc::ClientAsyncResponseReader<::protobuf::BoolRes>>(PrepareAsyncStartSaveHumanRaw(context, request, cq)); } ::grpc::Status EndSaveHuman(::grpc::ClientContext* context, const ::protobuf::IDMsg& request, ::protobuf::BoolRes* response) override; std::unique_ptr<::grpc::ClientAsyncResponseReader<::protobuf::BoolRes>> AsyncEndSaveHuman(::grpc::ClientContext* context, const ::protobuf::IDMsg& request, ::grpc::CompletionQueue* cq) @@ -505,8 +505,8 @@ namespace protobuf void StartFixMachine(::grpc::ClientContext* context, const ::protobuf::IDMsg* request, ::protobuf::BoolRes* response, ::grpc::ClientUnaryReactor* reactor) override; void EndFixMachine(::grpc::ClientContext* context, const ::protobuf::IDMsg* request, ::protobuf::BoolRes* response, std::function) override; void EndFixMachine(::grpc::ClientContext* context, const ::protobuf::IDMsg* request, ::protobuf::BoolRes* response, ::grpc::ClientUnaryReactor* reactor) override; - void SaveHuman(::grpc::ClientContext* context, const ::protobuf::IDMsg* request, ::protobuf::BoolRes* response, std::function) override; - void SaveHuman(::grpc::ClientContext* context, const ::protobuf::IDMsg* request, ::protobuf::BoolRes* response, ::grpc::ClientUnaryReactor* reactor) override; + void StartSaveHuman(::grpc::ClientContext* context, const ::protobuf::IDMsg* request, ::protobuf::BoolRes* response, std::function) override; + void StartSaveHuman(::grpc::ClientContext* context, const ::protobuf::IDMsg* request, ::protobuf::BoolRes* response, ::grpc::ClientUnaryReactor* reactor) override; void EndSaveHuman(::grpc::ClientContext* context, const ::protobuf::IDMsg* request, ::protobuf::BoolRes* response, std::function) override; void EndSaveHuman(::grpc::ClientContext* context, const ::protobuf::IDMsg* request, ::protobuf::BoolRes* response, ::grpc::ClientUnaryReactor* reactor) override; void Attack(::grpc::ClientContext* context, const ::protobuf::AttackMsg* request, ::protobuf::BoolRes* response, std::function) override; @@ -566,8 +566,8 @@ namespace protobuf ::grpc::ClientAsyncResponseReader<::protobuf::BoolRes>* PrepareAsyncStartFixMachineRaw(::grpc::ClientContext* context, const ::protobuf::IDMsg& request, ::grpc::CompletionQueue* cq) override; ::grpc::ClientAsyncResponseReader<::protobuf::BoolRes>* AsyncEndFixMachineRaw(::grpc::ClientContext* context, const ::protobuf::IDMsg& request, ::grpc::CompletionQueue* cq) override; ::grpc::ClientAsyncResponseReader<::protobuf::BoolRes>* PrepareAsyncEndFixMachineRaw(::grpc::ClientContext* context, const ::protobuf::IDMsg& request, ::grpc::CompletionQueue* cq) override; - ::grpc::ClientAsyncResponseReader<::protobuf::BoolRes>* AsyncSaveHumanRaw(::grpc::ClientContext* context, const ::protobuf::IDMsg& request, ::grpc::CompletionQueue* cq) override; - ::grpc::ClientAsyncResponseReader<::protobuf::BoolRes>* PrepareAsyncSaveHumanRaw(::grpc::ClientContext* context, const ::protobuf::IDMsg& request, ::grpc::CompletionQueue* cq) override; + ::grpc::ClientAsyncResponseReader<::protobuf::BoolRes>* AsyncStartSaveHumanRaw(::grpc::ClientContext* context, const ::protobuf::IDMsg& request, ::grpc::CompletionQueue* cq) override; + ::grpc::ClientAsyncResponseReader<::protobuf::BoolRes>* PrepareAsyncStartSaveHumanRaw(::grpc::ClientContext* context, const ::protobuf::IDMsg& request, ::grpc::CompletionQueue* cq) override; ::grpc::ClientAsyncResponseReader<::protobuf::BoolRes>* AsyncEndSaveHumanRaw(::grpc::ClientContext* context, const ::protobuf::IDMsg& request, ::grpc::CompletionQueue* cq) override; ::grpc::ClientAsyncResponseReader<::protobuf::BoolRes>* PrepareAsyncEndSaveHumanRaw(::grpc::ClientContext* context, const ::protobuf::IDMsg& request, ::grpc::CompletionQueue* cq) override; ::grpc::ClientAsyncResponseReader<::protobuf::BoolRes>* AsyncAttackRaw(::grpc::ClientContext* context, const ::protobuf::AttackMsg& request, ::grpc::CompletionQueue* cq) override; @@ -591,7 +591,7 @@ namespace protobuf const ::grpc::internal::RpcMethod rpcmethod_GetMessage_; const ::grpc::internal::RpcMethod rpcmethod_StartFixMachine_; const ::grpc::internal::RpcMethod rpcmethod_EndFixMachine_; - const ::grpc::internal::RpcMethod rpcmethod_SaveHuman_; + const ::grpc::internal::RpcMethod rpcmethod_StartSaveHuman_; const ::grpc::internal::RpcMethod rpcmethod_EndSaveHuman_; const ::grpc::internal::RpcMethod rpcmethod_Attack_; const ::grpc::internal::RpcMethod rpcmethod_CarryHuman_; @@ -622,7 +622,7 @@ namespace protobuf // 开始修理机器 virtual ::grpc::Status EndFixMachine(::grpc::ServerContext* context, const ::protobuf::IDMsg* request, ::protobuf::BoolRes* response); // 主动停止修复 - virtual ::grpc::Status SaveHuman(::grpc::ServerContext* context, const ::protobuf::IDMsg* request, ::protobuf::BoolRes* response); + virtual ::grpc::Status StartSaveHuman(::grpc::ServerContext* context, const ::protobuf::IDMsg* request, ::protobuf::BoolRes* response); // 开始救人 virtual ::grpc::Status EndSaveHuman(::grpc::ServerContext* context, const ::protobuf::IDMsg* request, ::protobuf::BoolRes* response); // 主动停止救人 @@ -941,7 +941,7 @@ namespace protobuf } }; template - class WithAsyncMethod_SaveHuman : public BaseClass + class WithAsyncMethod_StartSaveHuman : public BaseClass { private: void BaseClassMustBeDerivedFromService(const Service* /*service*/) @@ -949,21 +949,21 @@ namespace protobuf } public: - WithAsyncMethod_SaveHuman() + WithAsyncMethod_StartSaveHuman() { ::grpc::Service::MarkMethodAsync(11); } - ~WithAsyncMethod_SaveHuman() override + ~WithAsyncMethod_StartSaveHuman() override { BaseClassMustBeDerivedFromService(this); } // disable synchronous version of this method - ::grpc::Status SaveHuman(::grpc::ServerContext* /*context*/, const ::protobuf::IDMsg* /*request*/, ::protobuf::BoolRes* /*response*/) override + ::grpc::Status StartSaveHuman(::grpc::ServerContext* /*context*/, const ::protobuf::IDMsg* /*request*/, ::protobuf::BoolRes* /*response*/) override { abort(); return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); } - void RequestSaveHuman(::grpc::ServerContext* context, ::protobuf::IDMsg* request, ::grpc::ServerAsyncResponseWriter<::protobuf::BoolRes>* response, ::grpc::CompletionQueue* new_call_cq, ::grpc::ServerCompletionQueue* notification_cq, void* tag) + void RequestStartSaveHuman(::grpc::ServerContext* context, ::protobuf::IDMsg* request, ::grpc::ServerAsyncResponseWriter<::protobuf::BoolRes>* response, ::grpc::CompletionQueue* new_call_cq, ::grpc::ServerCompletionQueue* notification_cq, void* tag) { ::grpc::Service::RequestAsyncUnary(11, context, request, response, new_call_cq, notification_cq, tag); } @@ -1136,7 +1136,7 @@ namespace protobuf ::grpc::Service::RequestAsyncUnary(17, context, request, response, new_call_cq, notification_cq, tag); } }; - typedef WithAsyncMethod_TryConnection>>>>>>>>>>>>>>>>> AsyncService; + typedef WithAsyncMethod_TryConnection>>>>>>>>>>>>>>>>> AsyncService; template class WithCallbackMethod_TryConnection : public BaseClass { @@ -1559,7 +1559,7 @@ namespace protobuf } }; template - class WithCallbackMethod_SaveHuman : public BaseClass + class WithCallbackMethod_StartSaveHuman : public BaseClass { private: void BaseClassMustBeDerivedFromService(const Service* /*service*/) @@ -1567,12 +1567,12 @@ namespace protobuf } public: - WithCallbackMethod_SaveHuman() + WithCallbackMethod_StartSaveHuman() { ::grpc::Service::MarkMethodCallback(11, new ::grpc::internal::CallbackUnaryHandler<::protobuf::IDMsg, ::protobuf::BoolRes>([this](::grpc::CallbackServerContext* context, const ::protobuf::IDMsg* request, ::protobuf::BoolRes* response) - { return this->SaveHuman(context, request, response); })); + { return this->StartSaveHuman(context, request, response); })); } - void SetMessageAllocatorFor_SaveHuman( + void SetMessageAllocatorFor_StartSaveHuman( ::grpc::MessageAllocator<::protobuf::IDMsg, ::protobuf::BoolRes>* allocator ) { @@ -1580,17 +1580,17 @@ namespace protobuf static_cast<::grpc::internal::CallbackUnaryHandler<::protobuf::IDMsg, ::protobuf::BoolRes>*>(handler) ->SetMessageAllocator(allocator); } - ~WithCallbackMethod_SaveHuman() override + ~WithCallbackMethod_StartSaveHuman() override { BaseClassMustBeDerivedFromService(this); } // disable synchronous version of this method - ::grpc::Status SaveHuman(::grpc::ServerContext* /*context*/, const ::protobuf::IDMsg* /*request*/, ::protobuf::BoolRes* /*response*/) override + ::grpc::Status StartSaveHuman(::grpc::ServerContext* /*context*/, const ::protobuf::IDMsg* /*request*/, ::protobuf::BoolRes* /*response*/) override { abort(); return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); } - virtual ::grpc::ServerUnaryReactor* SaveHuman( + virtual ::grpc::ServerUnaryReactor* StartSaveHuman( ::grpc::CallbackServerContext* /*context*/, const ::protobuf::IDMsg* /*request*/, ::protobuf::BoolRes* /*response*/ ) { @@ -1831,7 +1831,7 @@ namespace protobuf return nullptr; } }; - typedef WithCallbackMethod_TryConnection>>>>>>>>>>>>>>>>> CallbackService; + typedef WithCallbackMethod_TryConnection>>>>>>>>>>>>>>>>> CallbackService; typedef CallbackService ExperimentalCallbackService; template class WithGenericMethod_TryConnection : public BaseClass @@ -2098,7 +2098,7 @@ namespace protobuf } }; template - class WithGenericMethod_SaveHuman : public BaseClass + class WithGenericMethod_StartSaveHuman : public BaseClass { private: void BaseClassMustBeDerivedFromService(const Service* /*service*/) @@ -2106,16 +2106,16 @@ namespace protobuf } public: - WithGenericMethod_SaveHuman() + WithGenericMethod_StartSaveHuman() { ::grpc::Service::MarkMethodGeneric(11); } - ~WithGenericMethod_SaveHuman() override + ~WithGenericMethod_StartSaveHuman() override { BaseClassMustBeDerivedFromService(this); } // disable synchronous version of this method - ::grpc::Status SaveHuman(::grpc::ServerContext* /*context*/, const ::protobuf::IDMsg* /*request*/, ::protobuf::BoolRes* /*response*/) override + ::grpc::Status StartSaveHuman(::grpc::ServerContext* /*context*/, const ::protobuf::IDMsg* /*request*/, ::protobuf::BoolRes* /*response*/) override { abort(); return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); @@ -2574,7 +2574,7 @@ namespace protobuf } }; template - class WithRawMethod_SaveHuman : public BaseClass + class WithRawMethod_StartSaveHuman : public BaseClass { private: void BaseClassMustBeDerivedFromService(const Service* /*service*/) @@ -2582,21 +2582,21 @@ namespace protobuf } public: - WithRawMethod_SaveHuman() + WithRawMethod_StartSaveHuman() { ::grpc::Service::MarkMethodRaw(11); } - ~WithRawMethod_SaveHuman() override + ~WithRawMethod_StartSaveHuman() override { BaseClassMustBeDerivedFromService(this); } // disable synchronous version of this method - ::grpc::Status SaveHuman(::grpc::ServerContext* /*context*/, const ::protobuf::IDMsg* /*request*/, ::protobuf::BoolRes* /*response*/) override + ::grpc::Status StartSaveHuman(::grpc::ServerContext* /*context*/, const ::protobuf::IDMsg* /*request*/, ::protobuf::BoolRes* /*response*/) override { abort(); return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); } - void RequestSaveHuman(::grpc::ServerContext* context, ::grpc::ByteBuffer* request, ::grpc::ServerAsyncResponseWriter<::grpc::ByteBuffer>* response, ::grpc::CompletionQueue* new_call_cq, ::grpc::ServerCompletionQueue* notification_cq, void* tag) + void RequestStartSaveHuman(::grpc::ServerContext* context, ::grpc::ByteBuffer* request, ::grpc::ServerAsyncResponseWriter<::grpc::ByteBuffer>* response, ::grpc::CompletionQueue* new_call_cq, ::grpc::ServerCompletionQueue* notification_cq, void* tag) { ::grpc::Service::RequestAsyncUnary(11, context, request, response, new_call_cq, notification_cq, tag); } @@ -3111,7 +3111,7 @@ namespace protobuf } }; template - class WithRawCallbackMethod_SaveHuman : public BaseClass + class WithRawCallbackMethod_StartSaveHuman : public BaseClass { private: void BaseClassMustBeDerivedFromService(const Service* /*service*/) @@ -3119,22 +3119,22 @@ namespace protobuf } public: - WithRawCallbackMethod_SaveHuman() + WithRawCallbackMethod_StartSaveHuman() { ::grpc::Service::MarkMethodRawCallback(11, new ::grpc::internal::CallbackUnaryHandler<::grpc::ByteBuffer, ::grpc::ByteBuffer>([this](::grpc::CallbackServerContext* context, const ::grpc::ByteBuffer* request, ::grpc::ByteBuffer* response) - { return this->SaveHuman(context, request, response); })); + { return this->StartSaveHuman(context, request, response); })); } - ~WithRawCallbackMethod_SaveHuman() override + ~WithRawCallbackMethod_StartSaveHuman() override { BaseClassMustBeDerivedFromService(this); } // disable synchronous version of this method - ::grpc::Status SaveHuman(::grpc::ServerContext* /*context*/, const ::protobuf::IDMsg* /*request*/, ::protobuf::BoolRes* /*response*/) override + ::grpc::Status StartSaveHuman(::grpc::ServerContext* /*context*/, const ::protobuf::IDMsg* /*request*/, ::protobuf::BoolRes* /*response*/) override { abort(); return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); } - virtual ::grpc::ServerUnaryReactor* SaveHuman( + virtual ::grpc::ServerUnaryReactor* StartSaveHuman( ::grpc::CallbackServerContext* /*context*/, const ::grpc::ByteBuffer* /*request*/, ::grpc::ByteBuffer* /*response*/ ) { @@ -3598,7 +3598,7 @@ namespace protobuf virtual ::grpc::Status StreamedEndFixMachine(::grpc::ServerContext* context, ::grpc::ServerUnaryStreamer<::protobuf::IDMsg, ::protobuf::BoolRes>* server_unary_streamer) = 0; }; template - class WithStreamedUnaryMethod_SaveHuman : public BaseClass + class WithStreamedUnaryMethod_StartSaveHuman : public BaseClass { private: void BaseClassMustBeDerivedFromService(const Service* /*service*/) @@ -3606,23 +3606,23 @@ namespace protobuf } public: - WithStreamedUnaryMethod_SaveHuman() + WithStreamedUnaryMethod_StartSaveHuman() { ::grpc::Service::MarkMethodStreamed(11, new ::grpc::internal::StreamedUnaryHandler<::protobuf::IDMsg, ::protobuf::BoolRes>([this](::grpc::ServerContext* context, ::grpc::ServerUnaryStreamer<::protobuf::IDMsg, ::protobuf::BoolRes>* streamer) - { return this->StreamedSaveHuman(context, streamer); })); + { return this->StreamedStartSaveHuman(context, streamer); })); } - ~WithStreamedUnaryMethod_SaveHuman() override + ~WithStreamedUnaryMethod_StartSaveHuman() override { BaseClassMustBeDerivedFromService(this); } // disable regular version of this method - ::grpc::Status SaveHuman(::grpc::ServerContext* /*context*/, const ::protobuf::IDMsg* /*request*/, ::protobuf::BoolRes* /*response*/) override + ::grpc::Status StartSaveHuman(::grpc::ServerContext* /*context*/, const ::protobuf::IDMsg* /*request*/, ::protobuf::BoolRes* /*response*/) override { abort(); return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); } // replace default version of method with streamed unary - virtual ::grpc::Status StreamedSaveHuman(::grpc::ServerContext* context, ::grpc::ServerUnaryStreamer<::protobuf::IDMsg, ::protobuf::BoolRes>* server_unary_streamer) = 0; + virtual ::grpc::Status StreamedStartSaveHuman(::grpc::ServerContext* context, ::grpc::ServerUnaryStreamer<::protobuf::IDMsg, ::protobuf::BoolRes>* server_unary_streamer) = 0; }; template class WithStreamedUnaryMethod_EndSaveHuman : public BaseClass @@ -3786,7 +3786,7 @@ namespace protobuf // replace default version of method with streamed unary virtual ::grpc::Status StreamedEscape(::grpc::ServerContext* context, ::grpc::ServerUnaryStreamer<::protobuf::IDMsg, ::protobuf::BoolRes>* server_unary_streamer) = 0; }; - typedef WithStreamedUnaryMethod_TryConnection>>>>>>>>>>>>>>>> StreamedUnaryService; + typedef WithStreamedUnaryMethod_TryConnection>>>>>>>>>>>>>>>> StreamedUnaryService; template class WithSplitStreamingMethod_AddPlayer : public BaseClass { @@ -3815,7 +3815,7 @@ namespace protobuf virtual ::grpc::Status StreamedAddPlayer(::grpc::ServerContext* context, ::grpc::ServerSplitStreamer<::protobuf::PlayerMsg, ::protobuf::MessageToClient>* server_split_streamer) = 0; }; typedef WithSplitStreamingMethod_AddPlayer SplitStreamedService; - typedef WithStreamedUnaryMethod_TryConnection>>>>>>>>>>>>>>>>> StreamedService; + typedef WithStreamedUnaryMethod_TryConnection>>>>>>>>>>>>>>>>> StreamedService; }; } // namespace protobuf diff --git a/CAPI/proto/Services.pb.cc b/CAPI/proto/Services.pb.cc index e5cc936..cbe66f5 100644 --- a/CAPI/proto/Services.pb.cc +++ b/CAPI/proto/Services.pb.cc @@ -31,7 +31,7 @@ static constexpr ::_pb::Message* const* file_default_instances = nullptr; const char descriptor_table_protodef_Services_2eproto[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = "\n\016Services.proto\022\010protobuf\032\025Message2Clie" - "nts.proto\032\024Message2Server.proto2\246\007\n\020Avai" + "nts.proto\032\024Message2Server.proto2\253\007\n\020Avai" "lableService\0223\n\rTryConnection\022\017.protobuf" ".IDMsg\032\021.protobuf.BoolRes\022=\n\tAddPlayer\022\023" ".protobuf.PlayerMsg\032\031.protobuf.MessageTo" @@ -46,16 +46,16 @@ const char descriptor_table_protodef_Services_2eproto[] PROTOBUF_SECTION_VARIABL "protobuf.IDMsg\032\020.protobuf.MsgRes\0225\n\017Star" "tFixMachine\022\017.protobuf.IDMsg\032\021.protobuf." "BoolRes\0223\n\rEndFixMachine\022\017.protobuf.IDMs" - "g\032\021.protobuf.BoolRes\022/\n\tSaveHuman\022\017.prot" - "obuf.IDMsg\032\021.protobuf.BoolRes\0222\n\014EndSave" - "Human\022\017.protobuf.IDMsg\032\021.protobuf.BoolRe" - "s\0220\n\006Attack\022\023.protobuf.AttackMsg\032\021.proto" - "buf.BoolRes\0220\n\nCarryHuman\022\017.protobuf.IDM" - "sg\032\021.protobuf.BoolRes\0222\n\014ReleaseHuman\022\017." - "protobuf.IDMsg\032\021.protobuf.BoolRes\022/\n\tHan" - "gHuman\022\017.protobuf.IDMsg\032\021.protobuf.BoolR" - "es\022,\n\006Escape\022\017.protobuf.IDMsg\032\021.protobuf" - ".BoolResb\006proto3"; + "g\032\021.protobuf.BoolRes\0224\n\016StartSaveHuman\022\017" + ".protobuf.IDMsg\032\021.protobuf.BoolRes\0222\n\014En" + "dSaveHuman\022\017.protobuf.IDMsg\032\021.protobuf.B" + "oolRes\0220\n\006Attack\022\023.protobuf.AttackMsg\032\021." + "protobuf.BoolRes\0220\n\nCarryHuman\022\017.protobu" + "f.IDMsg\032\021.protobuf.BoolRes\0222\n\014ReleaseHum" + "an\022\017.protobuf.IDMsg\032\021.protobuf.BoolRes\022/" + "\n\tHangHuman\022\017.protobuf.IDMsg\032\021.protobuf." + "BoolRes\022,\n\006Escape\022\017.protobuf.IDMsg\032\021.pro" + "tobuf.BoolResb\006proto3"; static const ::_pbi::DescriptorTable* const descriptor_table_Services_2eproto_deps[2] = { &::descriptor_table_Message2Clients_2eproto, &::descriptor_table_Message2Server_2eproto, @@ -64,7 +64,7 @@ static ::_pbi::once_flag descriptor_table_Services_2eproto_once; const ::_pbi::DescriptorTable descriptor_table_Services_2eproto = { false, false, - 1016, + 1021, descriptor_table_protodef_Services_2eproto, "Services.proto", &descriptor_table_Services_2eproto_once, diff --git a/dependency/proto/Protos.csproj b/dependency/proto/Protos.csproj new file mode 100644 index 0000000..5377978 --- /dev/null +++ b/dependency/proto/Protos.csproj @@ -0,0 +1,34 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + + diff --git a/dependency/proto/Services.proto b/dependency/proto/Services.proto index d903045..018fdad 100755 --- a/dependency/proto/Services.proto +++ b/dependency/proto/Services.proto @@ -21,7 +21,7 @@ service AvailableService rpc GetMessage(IDMsg) returns (MsgRes); rpc StartFixMachine(IDMsg) returns (BoolRes); // 开始修理机器 rpc EndFixMachine(IDMsg) returns (BoolRes); // 主动停止修复 - rpc SaveHuman(IDMsg) returns (BoolRes); // 开始救人 + rpc StartSaveHuman(IDMsg) returns (BoolRes); // 开始救人 rpc EndSaveHuman(IDMsg) returns (BoolRes); // 主动停止救人 rpc Attack (AttackMsg) returns (BoolRes); rpc CarryHuman (IDMsg) returns (BoolRes); diff --git a/dependency/shell/format.sh b/dependency/shell/format.sh index dba6115..4f00151 100644 --- a/dependency/shell/format.sh +++ b/dependency/shell/format.sh @@ -1,7 +1,10 @@ -for i in {1..10} +SHELL_FOLDER=$(dirname $(readlink -f "$0")) +cd $SHELL_FOLDER +cd ../.. + +for i in {1..3} do -find . -iname "*.cs" \ - -or -iname "*.c" \ +find . -iname "*.c" \ -or -iname "*.h" \ -or -iname "*.C" \ -or -iname "*.H" \ @@ -19,3 +22,10 @@ find . -iname "*.cs" \ -or -iname "*.i++" \ | xargs clang-format -i done + +cd logic && dotnet format && cd .. +cd installer && dotnet format && cd .. +cd launcher && dotnet format && cd .. +cd playback && dotnet format && cd .. + +echo "Done!" \ No newline at end of file diff --git a/installer/Installer/AssemblyInfo.cs b/installer/Installer/AssemblyInfo.cs index 87c30a8..746c6a3 100644 --- a/installer/Installer/AssemblyInfo.cs +++ b/installer/Installer/AssemblyInfo.cs @@ -1,6 +1,6 @@ using System.Windows; -[assembly:ThemeInfo( +[assembly: ThemeInfo( ResourceDictionaryLocation.None, // where theme specific resource dictionaries are located //(used if a resource is not found in the page, // or application resource dictionaries) diff --git a/installer/Installer/Model.cs b/installer/Installer/Model.cs index 03ffad1..a511c1a 100644 --- a/installer/Installer/Model.cs +++ b/installer/Installer/Model.cs @@ -26,15 +26,21 @@ namespace starter.viewmodel.settings /// /// Route of files /// - public string Route { - get; set; } + public string Route + { + get; set; + } /// /// if the route was set or is under editing /// - public bool HaveRoute { - get; set; } - public bool EditingRoute { - get; set; } + public bool HaveRoute + { + get; set; + } + public bool EditingRoute + { + get; set; + } /// /// downloader function /// @@ -144,7 +150,8 @@ namespace Downloader GetObjectRequest request = new GetObjectRequest(bucket, key, localDir, localFileName); Dictionary test = request.GetRequestHeaders(); - request.SetCosProgressCallback(delegate(long completed, long total) { + request.SetCosProgressCallback(delegate (long completed, long total) + { Console.WriteLine(String.Format("progress = {0:##.##}%", completed * 100.0 / total)); }); // 执行请求 @@ -680,4 +687,158 @@ namespace Downloader } } } -} \ No newline at end of file +} + +namespace WebConnect +{ + class Web + { + public static string logintoken = ""; + async public Task LoginToEEsast(HttpClient client, string useremail, string password) + { + string token = ""; + using (var response = await client.PostAsync("https://api.eesast.com/users/login", JsonContent.Create(new + { + email = useremail, + password = password, + }))) + { + switch (response.StatusCode) + { + case System.Net.HttpStatusCode.OK: + Console.WriteLine("Success login"); + token = (System.Text.Json.JsonSerializer.Deserialize(await response.Content.ReadAsStreamAsync(), typeof(LoginResponse), new JsonSerializerOptions() + { + PropertyNamingPolicy = JsonNamingPolicy.CamelCase, + }) as LoginResponse)?.Token ?? throw new Exception("no token!"); + logintoken = token; + SaveToken(); + break; + + default: + int code = ((int)response.StatusCode); + Console.WriteLine(code); + if (code == 401) + { + Console.WriteLine("邮箱或密码错误!"); + } + return; + } + } + } + + async public Task UserDetails(HttpClient client) //用来测试访问网站 + { + if (!ReadToken()) //读取token失败 + { + return; + } + try + { + client.DefaultRequestHeaders.Authorization = new("Bearer", logintoken); + Console.WriteLine(logintoken); + using (var response = await client.GetAsync("https://api.eesast.com/application/info")) //JsonContent.Create(new + //{ + + //}))) + { + switch (response.StatusCode) + { + case System.Net.HttpStatusCode.OK: + Console.WriteLine("Require OK"); + Console.WriteLine(await response.Content.ReadAsStringAsync()); + break; + default: + int code = ((int)response.StatusCode); + if (code == 401) + { + Console.WriteLine("您未登录或登录过期,请先登录"); + } + return; + } + } + } + catch + { + Console.WriteLine("请求错误!请检查网络连接!"); + } + } + + public void SaveToken()//保存token + { + string savepath = Path.Combine(Data.dataPath, "Token.dat"); + try + { + FileStream fs = new FileStream(savepath, FileMode.OpenOrCreate, FileAccess.ReadWrite); + StreamWriter sw = new StreamWriter(fs); + fs.SetLength(0); + sw.Write(logintoken); //将token写入文件 + sw.Close(); + fs.Close(); + } + catch (DirectoryNotFoundException) + { + Console.WriteLine("保存token时未找到下载器地址!请检查下载器是否被移动!"); + } + catch (PathTooLongException) + { + Console.WriteLine("下载器的路径名太长!请尝试移动下载器!"); + } + catch (ArgumentNullException) + { + Console.WriteLine("下载器路径初始化失败!"); + } + catch (IOException) + { + Console.WriteLine("写入token.dat发生冲突!请检查token.dat是否被其它程序占用!"); + } + } + public bool ReadToken()//读取token + { + try + { + string savepath = Path.Combine(Data.dataPath, "Token.dat"); + FileStream fs = new FileStream(savepath, FileMode.Open, FileAccess.Read); + StreamReader sr = new StreamReader(fs); + logintoken = sr.ReadLine(); + sr.Close(); + fs.Close(); + return true; + } + catch (DirectoryNotFoundException) + { + Console.WriteLine("读取token时未找到下载器地址!请检查下载器是否被移动!"); + return false; + } + catch (FileNotFoundException) + { + //没有登陆 + Console.WriteLine("请先登陆!"); + return false; + } + catch (PathTooLongException) + { + Console.WriteLine("下载器的路径名太长!请尝试移动下载器!"); + return false; + } + catch (ArgumentNullException) + { + Console.WriteLine("下载器路径初始化失败!"); + return false; + } + catch (IOException) + { + Console.WriteLine("写入token.dat发生冲突!请检查token.dat是否被其它程序占用!"); + return false; + } + } + } + [Serializable] + record LoginResponse + { + // Map `Token` to `token` when serializing + + public string Token { get; set; } = ""; + } + +} diff --git a/installer/Installer/ViewModel.cs b/installer/Installer/ViewModel.cs index 291dbac..12c9842 100644 --- a/installer/Installer/ViewModel.cs +++ b/installer/Installer/ViewModel.cs @@ -22,10 +22,12 @@ namespace starter.viewmodel.settings public string Route { - get { + get + { return obj.Route; } - set { + set + { obj.Route = value; this.RaisePropertyChanged("Route"); } @@ -33,10 +35,12 @@ namespace starter.viewmodel.settings public bool CanEditRoute // if the user can still edit install route { - get { + get + { return !obj.HaveRoute; } - set { + set + { obj.HaveRoute = !value; obj.EditingRoute = value; this.RaisePropertyChanged("CanEditRoute"); @@ -46,7 +50,8 @@ namespace starter.viewmodel.settings private BaseCommand clickBrowseCommand; public BaseCommand ClickBrowseCommand { - get { + get + { if (clickBrowseCommand == null) { clickBrowseCommand = new BaseCommand(new Action(o => @@ -54,28 +59,29 @@ namespace starter.viewmodel.settings using (FolderBrowserDialog dialog = new FolderBrowserDialog()) { _ = dialog.ShowDialog(); - if (dialog.SelectedPath != String.Empty) - Route = dialog.SelectedPath; + if (dialog.SelectedPath != String.Empty) + Route = dialog.SelectedPath; + } + })); } - })); - } - return clickBrowseCommand; - } -} -private BaseCommand clickConfirmCommand; -public BaseCommand ClickConfirmCommand -{ - get { - if (clickConfirmCommand == null) + return clickBrowseCommand; + } + } + private BaseCommand clickConfirmCommand; + public BaseCommand ClickConfirmCommand { + get + { + if (clickConfirmCommand == null) + { clickConfirmCommand = new BaseCommand(new Action(o => { CanEditRoute = false; - obj.install(); - })); - } + obj.install(); + })); + } return clickConfirmCommand; } - } - } - } \ No newline at end of file + } + } +} \ No newline at end of file diff --git a/launcher/Launcher/AssemblyInfo.cs b/launcher/Launcher/AssemblyInfo.cs index 87c30a8..746c6a3 100644 --- a/launcher/Launcher/AssemblyInfo.cs +++ b/launcher/Launcher/AssemblyInfo.cs @@ -1,6 +1,6 @@ using System.Windows; -[assembly:ThemeInfo( +[assembly: ThemeInfo( ResourceDictionaryLocation.None, // where theme specific resource dictionaries are located //(used if a resource is not found in the page, // or application resource dictionaries) diff --git a/logic/ClientTest/ClientTest.csproj b/logic/ClientTest/ClientTest.csproj new file mode 100644 index 0000000..075a2ce --- /dev/null +++ b/logic/ClientTest/ClientTest.csproj @@ -0,0 +1,20 @@ + + + + Exe + net6.0 + enable + enable + + + + + + + + + + + + + diff --git a/logic/ClientTest/Program.cs b/logic/ClientTest/Program.cs new file mode 100644 index 0000000..ef30dc9 --- /dev/null +++ b/logic/ClientTest/Program.cs @@ -0,0 +1,36 @@ +using Grpc.Core; +using Protobuf; + +namespace ClientTest +{ + public class Program + { + public static async Task Main(string[] args) + { + Channel channel = new Channel("0.0.0.0:8888", ChannelCredentials.Insecure); + var client = new AvailableService.AvailableServiceClient(channel); + PlayerMsg playerInfo = new(); + playerInfo.PlayerId = Convert.ToInt32(args[0]); + playerInfo.PlayerType = (PlayerType)Convert.ToInt32(args[1]); + var call = client.AddPlayer(playerInfo); + while (await call.ResponseStream.MoveNext()) + { + var currentGameInfo = call.ResponseStream.Current; + if (playerInfo.PlayerType == PlayerType.HumanPlayer) + { + for (int i = 0; i < currentGameInfo.HumanMessage.Count; i++) + { + Console.WriteLine($"Human is at ({currentGameInfo.HumanMessage[i].X}, {currentGameInfo.HumanMessage[i].Y})"); + } + } + if (playerInfo.PlayerType == PlayerType.ButcherPlayer) + { + for (int i = 0; i < currentGameInfo.ButcherMessage.Count; i++) + { + Console.WriteLine($"Butcher is at ({currentGameInfo.ButcherMessage[i].X}, {currentGameInfo.ButcherMessage[i].Y})"); + } + } + } + } + } +} \ No newline at end of file diff --git a/logic/Server/Game.cs b/logic/Server/Game.cs new file mode 100644 index 0000000..22d8ac7 --- /dev/null +++ b/logic/Server/Game.cs @@ -0,0 +1,105 @@ +using Grpc.Core; +using Protobuf; +using System.Threading; +using Timothy.FrameRateTask; +using System; +using System.Net.Http.Headers; + +namespace Server +{ + public class Game + { + private const int gameTime = 3000; + public int GameTime => gameTime; + + private MessageToClient gameInfo = new(); + private object gameInfoLock = new(); + private int isGaming = 0; + public bool IsGaming + { + get => Interlocked.CompareExchange(ref isGaming, 0, 0) != 0; + set => Interlocked.Exchange(ref isGaming, value ? 1 : 0); + } + + public MessageToClient GetCopiedGameInfo() + { + lock (gameInfoLock) + { + return gameInfo.Clone(); + } + } + public void AddPlayer(PlayerMsg player) + { + lock (gameInfoLock) + { + if (player.PlayerType == PlayerType.NullPlayerType) + return; + if (player.PlayerType == PlayerType.HumanPlayer) + { + gameInfo.HumanMessage.Add(new MessageOfHuman() + { + PlayerId = player.PlayerId + }); + return; + } + if (player.PlayerType == PlayerType.ButcherPlayer) + { + gameInfo.ButcherMessage.Add(new MessageOfButcher() + { + PlayerID = player.PlayerId + }); + return; + } + } + } + + public SemaphoreSlim StartGame() + { + IsGaming = true; + var waitHandle = new SemaphoreSlim(0); + + new Thread + ( + () => + { + new FrameRateTaskExecutor + ( + () => IsGaming, + () => + { + lock (gameInfo) + { + for (int i = 0; i < gameInfo.HumanMessage.Count; i++) + { + if (gameInfo.HumanMessage[i] != null) + { + gameInfo.HumanMessage[i].X++; + gameInfo.HumanMessage[i].Y--; + } + } + for (int i = 0; i < gameInfo.ButcherMessage.Count; i++) + { + if (gameInfo.ButcherMessage[i] != null) + { + gameInfo.ButcherMessage[i].X--; + gameInfo.ButcherMessage[i].Y++; + } + } + } + }, + 100, + () => + { + IsGaming = false; + waitHandle.Release(); + return 0; + }, + gameTime + ).Start(); + } + ) + { IsBackground = true }.Start(); + return waitHandle; + } + } +} diff --git a/logic/Server/GameServer.cs b/logic/Server/GameServer.cs new file mode 100644 index 0000000..fa80c96 --- /dev/null +++ b/logic/Server/GameServer.cs @@ -0,0 +1,120 @@ +using Grpc.Core; +using Protobuf; +using System.Threading; +using Timothy.FrameRateTask; +using System; +using System.Net.Http.Headers; + +namespace Server +{ + public class GameServer : AvailableService.AvailableServiceBase + { + private Dictionary semaDict = new(); + private object gameLock = new(); + private const int playerNum = 1; + private MessageToClient currentGameInfo = new(); + private Game game = new(); + public int GameTime => game.GameTime; + private SemaphoreSlim endGameSem = new(0); + + public override Task TryConnection(IDMsg request, ServerCallContext context) + { + var onConnection = new BoolRes(); + lock (gameLock) + { + // if (0 <= request.PlayerId && request.PlayerId < playerNum) + { + onConnection.ActSuccess = true; + return Task.FromResult(onConnection); + } + } + onConnection.ActSuccess = false; + return Task.FromResult(onConnection); + } + + public override async Task AddPlayer(PlayerMsg request, IServerStreamWriter responseStream, ServerCallContext context) + { + lock (gameLock) + { + if (game.IsGaming) + return; + game.AddPlayer(request); + var temp = (new SemaphoreSlim(0, 1), new SemaphoreSlim(0, 1)); + + bool start = false; + Console.WriteLine($"Id: {request.PlayerId} joins."); + lock (semaDict) + { + semaDict.Add(request.PlayerId, temp); + start = semaDict.Count == playerNum; + } + + if (start) + { + Console.WriteLine("Game starts!"); + StartGame(); + } + } + + do + { + semaDict[request.PlayerId].Item1.Wait(); + if (currentGameInfo != null) + { + await responseStream.WriteAsync(currentGameInfo); + Console.WriteLine("Send!"); + } + semaDict[request.PlayerId].Item2.Release(); + } while (game.IsGaming); + } + public void StartGame() + { + var waitHandle = game.StartGame(); + new Thread(() => + { + new FrameRateTaskExecutor + ( + () => game.IsGaming, + ReportGame, + 1000, + () => + { + ReportGame(); // 最后发一次消息,唤醒发消息的线程,防止发消息的线程由于有概率处在 Wait 状态而卡住 + return 0; + } + ).Start(); + }) + { IsBackground = true }.Start(); + new Thread(() => + { + waitHandle.Wait(); + this.endGameSem.Release(); + }) + { IsBackground = true }.Start(); + + } + public void WaitForEnd() + { + this.endGameSem.Wait(); + } + + public void ReportGame() + { + currentGameInfo = game.GetCopiedGameInfo(); + + foreach (var kvp in semaDict) + { + kvp.Value.Item1.Release(); + } + + foreach (var kvp in semaDict) + { + kvp.Value.Item2.Wait(); + } + } + + public GameServer() + { + } + } +} \ No newline at end of file diff --git a/logic/Server/Program.cs b/logic/Server/Program.cs index 3751555..155a97b 100644 --- a/logic/Server/Program.cs +++ b/logic/Server/Program.cs @@ -1,2 +1,35 @@ -// See https://aka.ms/new-console-template for more information -Console.WriteLine("Hello, World!"); +using Grpc.Core; +using Protobuf; +using System.Threading; +using Timothy.FrameRateTask; +using System; +using System.Net.Http.Headers; + +namespace Server +{ + public class Program + { + public static void Main() + { + try + { + GameServer gameServer = new(); + Grpc.Core.Server server = new Grpc.Core.Server(new[] { new ChannelOption(ChannelOptions.SoReuseport, 0) }) + { + Services = { AvailableService.BindService(gameServer) }, + Ports = { new ServerPort("0.0.0.0", 8888, ServerCredentials.Insecure) } + }; + server.Start(); + + Console.WriteLine("Server begins to listen!"); + gameServer.WaitForEnd(); + Console.WriteLine("Server end!"); + server.ShutdownAsync().Wait(); + } + catch (Exception ex) + { + Console.WriteLine(ex.ToString()); + } + } + } +} \ No newline at end of file diff --git a/logic/Server/Server.csproj b/logic/Server/Server.csproj index 74abf5c..62045cf 100644 --- a/logic/Server/Server.csproj +++ b/logic/Server/Server.csproj @@ -7,4 +7,19 @@ enable + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + diff --git a/logic/cmd/test.cmd b/logic/cmd/test.cmd new file mode 100644 index 0000000..0ea590e --- /dev/null +++ b/logic/cmd/test.cmd @@ -0,0 +1,7 @@ +@echo off + +start cmd /k .\Server\bin\Debug\net6.0\Server.exe + +start cmd /k .\ClientTest\bin\Debug\net6.0\ClientTest.exe 0 1 + +start cmd /k .\ClientTest\bin\Debug\net6.0\ClientTest.exe 1 2 diff --git a/logic/logic.sln b/logic/logic.sln index 51f61b6..d95a3b7 100644 --- a/logic/logic.sln +++ b/logic/logic.sln @@ -5,6 +5,10 @@ VisualStudioVersion = 17.0.32014.148 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Server", "Server\Server.csproj", "{D033B809-2FB7-4340-B8B4-DDA30D6CA6FF}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ClientTest", "ClientTest\ClientTest.csproj", "{F3C98717-DD4F-45B8-B0F0-C217E7E2B5D4}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Protos", "..\dependency\proto\Protos.csproj", "{9ADA1EF8-DF2F-4C2E-9DE2-BC94DF89B44D}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -15,6 +19,14 @@ Global {D033B809-2FB7-4340-B8B4-DDA30D6CA6FF}.Debug|Any CPU.Build.0 = Debug|Any CPU {D033B809-2FB7-4340-B8B4-DDA30D6CA6FF}.Release|Any CPU.ActiveCfg = Release|Any CPU {D033B809-2FB7-4340-B8B4-DDA30D6CA6FF}.Release|Any CPU.Build.0 = Release|Any CPU + {F3C98717-DD4F-45B8-B0F0-C217E7E2B5D4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F3C98717-DD4F-45B8-B0F0-C217E7E2B5D4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F3C98717-DD4F-45B8-B0F0-C217E7E2B5D4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F3C98717-DD4F-45B8-B0F0-C217E7E2B5D4}.Release|Any CPU.Build.0 = Release|Any CPU + {9ADA1EF8-DF2F-4C2E-9DE2-BC94DF89B44D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9ADA1EF8-DF2F-4C2E-9DE2-BC94DF89B44D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9ADA1EF8-DF2F-4C2E-9DE2-BC94DF89B44D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9ADA1EF8-DF2F-4C2E-9DE2-BC94DF89B44D}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE