Skip to content

Commit

Permalink
last commit before migrating back to pdf format
Browse files Browse the repository at this point in the history
  • Loading branch information
Pismice committed Jul 19, 2024
1 parent 6573463 commit 9e5ef99
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 63 deletions.
9 changes: 4 additions & 5 deletions TODO.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ Projet:
- [ ] + de cohesion avec les persist
- [ ] securite verifier que les actions peuvent seulement etre faites par la bonne personne
- [ ] test coverage
- [ ] avant de constuire un bulding verifier assez argent et or
- [ ] get village qui retourne aussi les buildings
- [*] Tester avec GPA pour les memory leaks (shutdown et sigint a mettre dans doc si ca marche)

Doc:
- [ ] Ecrire doc du projet
- [ ] Fil rouge pour partie concurence (comme dans le livre)
- [*] Epoll https://discord.com/channels/605571803288698900/1259840408545136700
- [ ] TOUT relire (verifier que tous les premiers scripts sont executables)

Fin:
- [ ] TOUT relire (verifier que tous les premiers scripts sont executables
- [ ] sources zotero
- [ ] faire un autre export ou autre branche ou je mets tout joli pour word ou latex avec les bonnes images, titres, liens etc
- [ ] corriger fautes orthographe
Expand Down Expand Up @@ -42,5 +42,4 @@ Futur:
- [!] zig test en vert

Questions:
- c'est quoi resume publiable ?
- est ce que je peux rajouter qqch d interessant pour la concurence par exmple pour epoll ?
- est ce que je peux rajouter qqch d interessant pour la concurence par exmple pour epoll, psq je trouve assez fade?
8 changes: 5 additions & 3 deletions content/docs/project-1/_index.org
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,12 @@ The database is needed in my project in order to persist the data and not have i
I only have 2 simple criterias for the database. The first is that I need it to be as easy as possible to integrate in my project, and the second is that I would prefer a SQL database since I am already familiar with SQL queries.

***** Solution: SQLite
Since it is only a file and does net require tons of installation or running on my machine I decided to go with SQLITE. In Zig there are ways to integrate SQLITE in our project.
Since it is only a file and does net require tons of installation or running an other process on my machine I decided to go with SQLITE.

The SQLite database could also be run on the same machine as the server if we only have one server, allowing low latency between the database and the WEB server. Thus making [[#architecture][requets 2 and 3]] faster.

The first is to simply use the [[https://www.sqlite.org/cintro.html][C SQLite library]], this is the solution I am going to go with in order to test the Zig-C interoperability in a big project.
In Zig there are 2 main ways to integrate SQLITE in our project.

However if I happen to encounter issues I could always fall back to an other community appreciated solution which is a [[https://github.com/vrischmann/zig-sqlite][Zig wrapper]] around the C library.
The first is to simply use the [[https://www.sqlite.org/cintro.html][C SQLite library]], as we have seen already it is very easy to use a C library within a Zig project making it a very decent option

However if I found a [[https://github.com/vrischmann/zig-sqlite][Zig wrapper]] around that same library that includes a few [[https://github.com/vrischmann/zig-sqlite?tab=readme-ov-file#features][other features]] like checking the paramaters of the query at compile time. It also has the advantage of giving the feeling that I am using a Zig library, thus not having to wrap my head around the such concepts as [[https://ziglang.org/documentation/master/#C-Pointers][C pointers]] or other C specific features.
99 changes: 51 additions & 48 deletions content/docs/project-1/api-design.org
Original file line number Diff line number Diff line change
Expand Up @@ -5,61 +5,64 @@

The client is going to interact with the game by sendin HTTP requests to the server. Those requests are going to be returned with a JSON response. All the possible actions a player can do are going to be done through the API. He can get informations about the state of the game like the ranking of the best players or do actions like building units and attacking another player.

Here is a list of all the possible HTTP requests a player can do.
Here is a list of all the possible HTTP requests a player can do, not including the authentification specific routes.

TODO I STILL DONT KNOW HOW TO PASS DATA WITH POST REQUESTS (query, body, ...)
For all of these endpoints the user must have a valid =session_id= cookie, except GET /game/ranking which is a public ranking.

GET /village/{}
Send to the player the state of his village
- name
- gold (peut etre faire une requete que pour gold pour eviter de trop charger le serveur ?)
- x_position
- y_position
- wall_levels
- level =Which is the level of the town center, since there is only one per Village both the Village and the Town Center have the same level=
- space_capacity =Available space for new Buildings in the Village=
- buildings =GET /building/=
*** GET /
Take no parameter and return a welcome message containing the number of players registered.

POST /build/{building_name}/{village_id}
#+begin_src json
[
"Welcome to my game which currently has 2 players !"
]
#+end_src

POST /upgrade_building/{id}
Upgrade a building corresponding to the id, only the owner of the building can upgrade it.
The server check if the user has enough gold and if it is possible to upgrade the building.
Return if the upgrade of the building has been started or not
*** GET /game/ranking
Take no parameter and return all the players ranked by the amount of gold they have.

POST /buy_units/{nb_archers}/{nb_cavalery}/{nb_infantry}
Buy units for the player, the server check if the player has enough gold and if it the case instantly produces them and assign them to the garnison army.
#+begin_src json
[
[
{
"username": "user1",
"gold": 4110
},
{
"username": "user2",
"gold": 222
}
]
]
#+end_src

GET /ranking/{}
Send to the player the ranking of the best players by gold possession
*** GET /game/village
Take no paramater and return the village informations of the connected player
#+begin_src json
[
{
"id": 31,
"name": "testoo",
"x_position": 50,
"y_position": 96,
"gold": 4110,
"level": 1,
"space_capacity": 5,
"player_id": 43,
"army_id": 21
}
]
#+end_src

GET /attackable_villages/{}
Send to the player all the villages he can attack including thoses informations about the villages:- name
- player_name
- gold
- x_position
- y_position
- wall_levels
- level =Which is the level of the town center, since there is only one per Village both the Village and the Town Center have the same level=
*** POST /game/create_building
#+begin_src json
{
"success": true
}
#+end_src

POST /attack/{village_id}/{army_id}
Start the process of an attack.
*** POST /game/upgrade_building

GET /armies/{}
Send to the player the state of all his armies, corresponding to GET /army/ but for all the armies of the player
*** POST /game/buy_units

OPTIONAL: GET /building/{id}
Send to the player the state of a building corresponding to the id, only the owner of the building can get access to this ressource
- id
- level
- space_taken
- productivity # Only if it is a production building like a Gold Mine
- upgrade_cost

OPTIONAL: GET /army/{id}
Send to the player the state of his army corresponding to the id, only the owner of the army can get access to this ressource
- id
- nb_archers
- nb_cavalery
- nb_infantry
- is_moving # True if the army is outside the village and False if it is in the village
*** POST /game/attack
5 changes: 5 additions & 0 deletions content/docs/project-1/entities.org
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#+title: Entities
#+weight: 7
#+hugo_cascade_type: docs
#+math: true

5 changes: 5 additions & 0 deletions content/docs/project-1/interfaces.org
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#+title: Interfaces
#+weight: 5
#+hugo_cascade_type: docs
#+math: true

5 changes: 5 additions & 0 deletions content/docs/project-1/shutdown.org
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#+title: Graceful shutdown
#+weight: 5
#+hugo_cascade_type: docs
#+math: true

7 changes: 0 additions & 7 deletions content/docs/project-2/_index.org

This file was deleted.

0 comments on commit 9e5ef99

Please sign in to comment.