// This file is part of Timmi. // // Timmi is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. #ifndef TIMMISERVER_HH #define TIMMISERVER_HH #include #include #include #include enum ServerState {SERVER_PREGAME, SERVER_INGAME}; struct LogPlayer { int id; std::string name; std::string address; }; class TimmiServer: public TCPServer { public: TimmiServer(); void mainloop(); // Open logfile for appending games void open_log(std::string filename); // Add client to players void handle_connection(TCPSocket &socket); // Parse commmand void handle_line(TCPSocket &socket, std::string line); // Remove player void handle_disconnect(TCPSocket &socket); protected: std::ofstream logfile_; // Log file std::vector initial_players_; // Actual players in game GameState gs_; // Timmi game state ServerState ss_; // Server situation bool status_changed_; // Status changed since last transmission // Log game if logfile is open void log_game(); // Retransmit status to all connected players void send_status(); // Send a move to all connected clients void send_move(const Move &move); // Process command line void process_command(int playerid, std::string line); private: // Split-off mainloop - check for game over and act accordingly void handle_gameend(); // Split-off mainloop - check if table should go over void handle_goover(); // Split-off mainloop - check for winners void handle_winners(); // Store initial players for logging void store_initial_players(); }; #endif