Open jayspur11 opened 9 years ago
Good reference: http://www.linuxhowtos.org/C_C++/socket.htm
I'm thinking of spawning pthreads for passing info to the clients.
Update One thread per connection is NOT a good idea; computers can handle far more connections than threads. Things to look into:
I think the easiest thing to do is directly tell the server the initial values (map size, number of players, etc). So the server would start and ask for the necessary starting values on the command line, then start listening on as many sockets as it needs.
(Blatantly stolen idea from Minecraft) Config file for startup data?
Updated description!
Updated description to outline all classes I'll need to create for this.
In the case of someone dropping out, you could just kill off their population?
If things are going well enough, I'll muck through killing off populations. The way things are set up now, though, the population should die out naturally -- they can't have births server-side, so the population should steadily decline. Or crush the opposition. Either way...
I would like to begin by noting that this is probably the hardest part of writing this server. Networking? Threading? Considering things I've never seriously worked with before? Yikes! Thus, I'll try to keep things well-documented as I go along. If you have any ideas about a good way to handle something, please let me know.
Server Lobby
The server lobby is the setup area for the players to connect to the server and get ready. The main program will create an instance of this class and request that it wait for connections. This should start up a loop wherein the lobby accepts incoming connections, so long as the current list of players is not entirely ready. The Lobby will be responsible for setting up the Server Comm. Note: All connections will be set in non-blocking mode, to ensure we can exit out.
Thread Organization
Note: This will need to be made thread-safe. I'm thinking named semaphores, because they're simple. (reference here)
Server Comm
The server comm is the server's method of communicating with the clients. It tracks all connections and will be used to send & receive data via them.
Method Format
Methods shall be prepared to handle non-blocking sockets.
Server Engine
The server engine is the primary purpose of the server; once the lobby is finished and the game is ready to go, the main program will start an instance of the engine to run the game.
Note: We will need to, at some point, address what happens when clients drop out...for now, I'm going to act like it doesn't happen. LA-LA-LA-I-CAN'T-HEAR-YOU (I will ensure it does not crash the game with a null-memory access or something)