Skip to content

Commit

Permalink
Intermediary commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Kruhlmann committed May 20, 2024
1 parent c69fb5b commit f82b643
Show file tree
Hide file tree
Showing 5 changed files with 196 additions and 4 deletions.
12 changes: 12 additions & 0 deletions lib/api/game/login.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
open Lwt.Syntax
open Data.Platform.Credentials

let platform_login credentials game domain send =
let url = Uri.make ~scheme:"https" ~host:domain ~path:"/game/login/platformlogin" () in
let* json = send url in
match json with
| Some j ->
let model = Models.Response.Game.Platform_login.from_json j in
Lwt.return @@ Some model
| None -> Lwt.return None
;;
4 changes: 0 additions & 4 deletions lib/api/game/platformlogin.ml

This file was deleted.

18 changes: 18 additions & 0 deletions lib/form.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
open Lwt.Syntax
open Cohttp_lwt

let post (url : Uri.t) (form_data : (string * string) list) =
let headers = Header.init_with "Content-Type" "application/x-www-form-urlencoded" in
let body = Uri.encoded_of_query form_data in
let* resp, body = Client.post ~headers ~body:(Body.of_string body) url in
let status = Response.status resp in
if Code.code_of_status status = 200
then
let* body = Body.to_string body in
let json = Yojson.Basic.from_string body in
Lwt.return (Some json)
else (
let url_str = Uri.to_string url in
let* _ = Lwt_io.printl (Printf.sprintf "HTTP Error: %s for URL: %s" (Code.string_of_status status) url_str) in
Lwt.return None)
;;
165 changes: 165 additions & 0 deletions lib/models/response/platform_login.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
type data_entry =
{ id1 : string
; id2 : string
; url : string
; icon : string
; name : string
; unknown1 : string
; unknown2 : string
; unknown3 : string
; unknown4 : string
; unknown5 : string option
; unknown6 : string option
; id3 : string
; id4 : string
; unknown7 : string list
}

type config_entry =
{ key : string
; value : string
}

type nested_entry =
{ id1 : string
; id2 : string
; url : string
; icon : string
; name : string
; clan : string
; score1 : string
; score2 : string
; score3 : string
; score4 : string
; score5 : string option
; id3 : string
; id4 : string
; unknown_list : string list
}

type t =
{ id1 : string
; id2 : string
; timestamp1 : string
; timestamp2 : string
; data_entries : data_entry list
; unknown1 : string
; unknown2 : string
; unknown3 : string option
; config : config_entry list
; nested_entries : nested_entry list
}

let from_json json =
let open Yojson.Basic.Util in
{ id1 = json |> member "id1" |> to_string
; id2 = json |> member "id2" |> to_string
; timestamp1 = json |> member "timestamp1" |> to_string
; timestamp2 = json |> member "timestamp2" |> to_string
; data_entries =
json
|> member "data_entries"
|> to_list
|> List.map (fun entry ->
{ id1 = entry |> member "id1" |> to_string
; id2 = entry |> member "id2" |> to_string
; url = entry |> member "url" |> to_string
; icon = entry |> member "icon" |> to_string
; name = entry |> member "name" |> to_string
; unknown1 = entry |> member "unknown1" |> to_string
; unknown2 = entry |> member "unknown2" |> to_string
; unknown3 = entry |> member "unknown3" |> to_string
; unknown4 = entry |> member "unknown4" |> to_string
; unknown5 = entry |> member "unknown5" |> to_option to_string
; unknown6 = entry |> member "unknown6" |> to_option to_string
; id3 = entry |> member "id3" |> to_string
; id4 = entry |> member "id4" |> to_string
; unknown7 = entry |> member "unknown7" |> to_list |> List.map to_string
})
; unknown1 = json |> member "unknown1" |> to_string
; unknown2 = json |> member "unknown2" |> to_string
; unknown3 = json |> member "unknown3" |> to_option to_string
; config =
json
|> member "config"
|> to_list
|> List.map (fun entry ->
{ key = entry |> member "key" |> to_string; value = entry |> member "value" |> to_string })
; nested_entries =
json
|> member "nested_entries"
|> to_list
|> List.map (fun entry ->
{ id1 = entry |> member "id1" |> to_string
; id2 = entry |> member "id2" |> to_string
; url = entry |> member "url" |> to_string
; icon = entry |> member "icon" |> to_string
; name = entry |> member "name" |> to_string
; clan = entry |> member "clan" |> to_string
; score1 = entry |> member "score1" |> to_string
; score2 = entry |> member "score2" |> to_string
; score3 = entry |> member "score3" |> to_string
; score4 = entry |> member "score4" |> to_string
; score5 = entry |> member "score5" |> to_option to_string
; id3 = entry |> member "id3" |> to_string
; id4 = entry |> member "id4" |> to_string
; unknown_list = entry |> member "unknown_list" |> to_list |> List.map to_string
})
}
;;

let to_json a =
`Assoc
[ "id1", `String a.id1
; "id2", `String a.id2
; "timestamp1", `String a.timestamp1
; "timestamp2", `String a.timestamp2
; ( "data_entries"
, `List
(List.map
(fun entry ->
`Assoc
[ "id1", `String entry.id1
; "id2", `String entry.id2
; "url", `String entry.url
; "icon", `String entry.icon
; "name", `String entry.name
; "unknown1", `String entry.unknown1
; "unknown2", `String entry.unknown2
; "unknown3", `String entry.unknown3
; "unknown4", `String entry.unknown4
; ("unknown5", match entry.unknown5 with Some v -> `String v | None -> `Null)
; ("unknown6", match entry.unknown6 with Some v -> `String v | None -> `Null)
; "id3", `String entry.id3
; "id4", `String entry.id4
; "unknown7", `List (List.map (fun i -> `String i) entry.unknown7)
])
a.data_entries) )
; "unknown1", `String a.unknown1
; "unknown2", `String a.unknown2
; ("unknown3", match a.unknown3 with Some v -> `String v | None -> `Null)
; ( "config"
, `List (List.map (fun entry -> `Assoc [ "key", `String entry.key; "value", `String entry.value ]) a.config) )
; ( "nested_entries"
, `List
(List.map
(fun entry ->
`Assoc
[ "id1", `String entry.id1
; "id2", `String entry.id2
; "url", `String entry.url
; "icon", `String entry.icon
; "name", `String entry.name
; "clan", `String entry.clan
; "score1", `String entry.score1
; "score2", `String entry.score2
; "score3", `String entry.score3
; "score4", `String entry.score4
; ("score5", match entry.score5 with Some v -> `String v | None -> `Null)
; "id3", `String entry.id3
; "id4", `String entry.id4
; "unknown_list", `List (List.map (fun i -> `String i) entry.unknown_list)
])
a.nested_entries) )
]
;;
1 change: 1 addition & 0 deletions shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ pkgs.mkShell{
shellHook = ''
export C_INCLUDE_PATH=${pkgs.zlib.dev}/include:$C_INCLUDE_PATH
export LIBRARY_PATH=${pkgs.zlib}/lib:$LIBRARY_PATH
export OPAM_SWITCH_PREFIX=$HOME/.opam/5.2.0
'';
}

0 comments on commit f82b643

Please sign in to comment.