Skip to content

Commit

Permalink
Merge pull request #328 from eesast/dev
Browse files Browse the repository at this point in the history
v1.0.1
  • Loading branch information
DragonAura authored May 8, 2024
2 parents 99d4aa4 + 282617b commit 9f62f28
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 17 deletions.
20 changes: 12 additions & 8 deletions CAPI/cpp/API/src/Communication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,14 +227,18 @@ bool Communication::Recycle(int32_t playerID, int32_t teamID)

bool Communication::TryConnection(int32_t playerID, int32_t teamID)
{
protobuf::BoolRes reply;
ClientContext context;
constexpr int maxRetryNum = 10;
auto request = THUAI72Proto::THUAI72ProtobufIDMsg(playerID, teamID);
auto status = THUAI7Stub->TryConnection(&context, request, &reply);
if (status.ok())
return true;
else
return false;
for (int retryNum = 0; retryNum < maxRetryNum; retryNum++)
{
protobuf::BoolRes reply;
ClientContext context;
std::this_thread::sleep_for(std::chrono::milliseconds(2000));
auto status = THUAI7Stub->TryConnection(&context, request, &reply);
if (status.ok())
return true;
}
return false;
}

void Communication::AddPlayer(int32_t playerID, int32_t teamID, THUAI7::ShipType ShipType)
Expand Down Expand Up @@ -274,4 +278,4 @@ protobuf::MessageToClient Communication::GetMessage2Client()
{ return haveNewMessage; });
haveNewMessage = false;
return message2Client;
}
}
20 changes: 12 additions & 8 deletions CAPI/python/PyAPI/Communication.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,14 +235,18 @@ def BuildShip(
return buildResult.act_success

def TryConnection(self, playerID: int, teamID: int) -> bool:
try:
tryResult: Message2Clients.BoolRes = self.__THUAI7Stub.TryConnection(
THUAI72Proto.THUAI72ProtobufIDMsg(playerID, teamID)
)
except grpc.RpcError:
return False
else:
return tryResult.act_success
maxRetryNum: int = 10
for _ in range(maxRetryNum):
try:
time.sleep(1)
tryResult: Message2Clients.BoolRes = self.__THUAI7Stub.TryConnection(
THUAI72Proto.THUAI72ProtobufIDMsg(playerID, teamID)
)
except grpc.RpcError:
continue
else:
return tryResult.act_success
return False

def GetMessage2Client(self) -> Message2Clients.MessageToClient:
with self.__cvMessage:
Expand Down
3 changes: 2 additions & 1 deletion logic/Server/GameServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ protected void SendGameResult(int[] scores, bool crashed) // 天梯的 Server

protected double[] PullScore(double[] scores)
{

string? url2 = Environment.GetEnvironmentVariable("SCORE_URL");
if (url2 != null)
{
Expand All @@ -144,6 +143,8 @@ protected double[] PullScore(double[] scores)
else
{
double[] final = LadderCalculate(org, scores);
final[0] -= org[0];
final[1] -= org[1];
return final;
}
}
Expand Down

0 comments on commit 9f62f28

Please sign in to comment.