mmo-project/fortran/server/README.md

44 lines
1.7 KiB
Markdown
Raw Normal View History

# server
2023-10-13 22:55:14 -04:00
The server implementation is as simple as I could make it.
I found a library called mod_dill from the [tcp-client-server demo code](https://github.com/modern-fortran/tcp-client-server) from a book on modern fortran. This gave me a simple TCP interface to send and recieve "messages".
Originally I had tried saving formatted fortran data into a string and trying to send that, but when you convert the fortran string to a c-string it oftend became garbled and unusable when sent through the tcp connection so I stopped using that method.
2023-10-13 22:55:14 -04:00
I found in [fpm](https://fpm.fortran-lang.org/index.html) [official registry](https://registry-frontend.vercel.app/) a json library which would make it *much* easier to deal with data transfer.
The simplest way to implement the communcation between the server and clients would be a series of tcp requests and responses.
- request
- int :: request_type
2023-09-17 13:20:12 -04:00
- ping # 0
- login # 1
- logout # 2
- move # 3
- str(24) :: username
- double :: x_pos
- double :: y_pos
- response
- array :: records
- str(24) :: username
- str(24) :: color
- double :: x_pos
- double :: y_pos
2023-10-13 22:55:14 -04:00
For each request, the same response is returned with is a list of the logged in users.
The commands that can be sent to the server are logging in, logging out, moving, and the default "ping" which is essentially a noop from the servers pov.
The server uses the same sqlite library as the [www implementation](../www/README.md).
The server loop is:
1. listen for connection
2. read message from client
3. convert c string to fortran string
4. convert the fortran string to a json object
5. run the command from the json object
6. create a json array of the logged in users and send to client.