Morrrrre try catch
This commit is contained in:
parent
30416f1246
commit
c2235ddd97
@ -154,40 +154,40 @@ public:
|
||||
// Called every frame, so update things here
|
||||
bool OnUserUpdate(float fElapsedTime) override
|
||||
{
|
||||
if (ws&&ws->getReadyState() != WebSocket::CLOSED) {
|
||||
WebSocket::pointer wsp = &*ws; // <-- because a unique_ptr cannot be copied into a lambda
|
||||
ws->poll();
|
||||
ws->dispatch([&](const std::string & message) {
|
||||
std::println("{}",message);
|
||||
json data=json::parse(message);
|
||||
if(data.contains("score")&&!data["score"].is_null()){
|
||||
read_p1Score=ex1=data["score"]["p1_score"].get<int>();
|
||||
read_p2Score=ex2=data["score"]["p2_score"].get<int>();
|
||||
}
|
||||
try{
|
||||
for(int playerSlot=0;const auto&p:data["results"]["latest"]["players"]){
|
||||
if(p["present"].get<bool>()){
|
||||
if(playerSlot==0){
|
||||
read_p1Name=p["name"].get<std::string>();
|
||||
}else{
|
||||
read_p2Name=p["name"].get<std::string>();
|
||||
}
|
||||
}else{
|
||||
if(playerSlot==0){
|
||||
read_p1Name="";
|
||||
read_p1Score=0;
|
||||
}else{
|
||||
read_p2Name="";
|
||||
read_p2Score=0;
|
||||
}
|
||||
}
|
||||
playerSlot++;
|
||||
try{
|
||||
if (ws&&ws->getReadyState() != WebSocket::CLOSED) {
|
||||
WebSocket::pointer wsp = &*ws; // <-- because a unique_ptr cannot be copied into a lambda
|
||||
ws->poll();
|
||||
ws->dispatch([&](const std::string & message) {
|
||||
std::println("{}",message);
|
||||
json data=json::parse(message);
|
||||
if(data.contains("score")&&!data["score"].is_null()){
|
||||
read_p1Score=ex1=data["score"]["p1_score"].get<int>();
|
||||
read_p2Score=ex2=data["score"]["p2_score"].get<int>();
|
||||
}
|
||||
}catch(std::exception&e){}
|
||||
});
|
||||
}else{
|
||||
ws=std::unique_ptr<WebSocket>{WebSocket::from_url("ws://localhost:9000")};
|
||||
}
|
||||
for(int playerSlot=0;const auto&p:data["results"]["latest"]["players"]){
|
||||
if(p["present"].get<bool>()){
|
||||
if(playerSlot==0){
|
||||
read_p1Name=p["name"].get<std::string>();
|
||||
}else{
|
||||
read_p2Name=p["name"].get<std::string>();
|
||||
}
|
||||
}else{
|
||||
if(playerSlot==0){
|
||||
read_p1Name="";
|
||||
read_p1Score=0;
|
||||
}else{
|
||||
read_p2Name="";
|
||||
read_p2Score=0;
|
||||
}
|
||||
}
|
||||
playerSlot++;
|
||||
}
|
||||
});
|
||||
}else{
|
||||
ws=std::unique_ptr<WebSocket>{WebSocket::from_url("ws://localhost:9000")};
|
||||
}
|
||||
}catch(std::exception&e){}
|
||||
|
||||
score1.Update();
|
||||
score2.Update();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user