Ver Fonte

add remove player from lobby

jblanked há 9 meses atrás
pai
commit
df2ee8fdc9
2 ficheiros alterados com 38 adições e 0 exclusões
  1. 37 0
      game/storage.c
  2. 1 0
      game/storage.h

+ 37 - 0
game/storage.c

@@ -499,6 +499,43 @@ bool websocket_player_context(PlayerContext *player_context, FlipperHTTP *fhttp)
     return true;
     return true;
 }
 }
 
 
+bool remove_player_from_lobby(FlipperHTTP *fhttp)
+{
+    if (!fhttp)
+    {
+        FURI_LOG_E(TAG, "FlipperHTTP is NULL");
+        return false;
+    }
+    char username[32];
+    if (!load_char("Flip-Social-Username", username, sizeof(username)))
+    {
+        FURI_LOG_E(TAG, "Failed to load data/Flip-Social-Username");
+        return false;
+    }
+    char lobby_name[32];
+    if (!load_char("pvp_lobby_name", lobby_name, sizeof(lobby_name)))
+    {
+        FURI_LOG_E(TAG, "Failed to load data/pvp_lobby_name");
+        return false;
+    }
+    char url[128];
+    char payload[128];
+    snprintf(payload, sizeof(payload), "{\"username\":\"%s\", \"game_id\":\"%s\"}", username, lobby_name);
+    snprintf(url, sizeof(url), "https://www.jblanked.com/flipper/api/world/pvp/lobby/remove/");
+    fhttp->state = IDLE;
+    if (!flipper_http_request(fhttp, POST, url, "{\"Content-Type\":\"application/json\"}", payload))
+    {
+        FURI_LOG_E(TAG, "Failed to remove player from lobby");
+        return false;
+    }
+    fhttp->state = RECEIVING;
+    while (fhttp->state != IDLE)
+    {
+        furi_delay_ms(100);
+    }
+    return true;
+}
+
 // Helper function to load an integer
 // Helper function to load an integer
 static bool load_number(const char *path_name, int *value)
 static bool load_number(const char *path_name, int *value)
 {
 {

+ 1 - 0
game/storage.h

@@ -7,6 +7,7 @@
 bool save_player_context(PlayerContext *player_context);
 bool save_player_context(PlayerContext *player_context);
 bool save_player_context_api(PlayerContext *player_context, FlipperHTTP *fhttp);
 bool save_player_context_api(PlayerContext *player_context, FlipperHTTP *fhttp);
 bool websocket_player_context(PlayerContext *player_context, FlipperHTTP *fhttp);
 bool websocket_player_context(PlayerContext *player_context, FlipperHTTP *fhttp);
+bool remove_player_from_lobby(FlipperHTTP *fhttp);
 bool load_player_context(PlayerContext *player_context);
 bool load_player_context(PlayerContext *player_context);
 bool set_player_context();
 bool set_player_context();