// 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 TIMMICLIENT_HH #define TIMMICLIENT_HH #include #include #include #include #include enum PlayerState {ACTIVE, DISCONNECTED, OBSERVER}; struct Player { int id; std::string name; int handsize; PlayerState state; bool let_go_over; bool operator==(const Player &other) const; }; enum EventType {NOEVENT, MOVE_PICKUP, MOVE_HIT, MOVE_BEAT, MOVE_MOVE, OVER_TIMEOUT, OVER_CANTADD, OVER_LETGOOVER, STATUS_JOIN, STATUS_DISCONNECTED, STATUS_WON, STATUS_OBSERVER, STATUS_ACTIVE}; struct Event { EventType eventtype; int player; Card owncard; Card othercard; }; // Parse player information Player parse_player(std::string line); // Parse event information, eventtype = NOEVENT if not an event Event parse_event(std::string line); class TimmiClient: public TCPClient { public: TimmiClient(std::string name); void handle_line(std::string line); // Find player Player find_player(int playerid) const; Player &find_player_mutable(int playerid); // Next turn int next_turn_id() const; int next_turn_cardcount() const; // Describe player, nick(id) virtual std::string describe_player(int playerid) const; // Log an event // Subclasses should call this, for this updates internal status // between server status messages. virtual void handle_event(const Event &event); // Handle chat message virtual void handle_chat(int player, std::string message); // Handle error from server virtual void handle_error(std::string errorcode); // Handle winner list virtual void handle_winners(std::vector winners); protected: std::string name_; int myid_; std::vector table_; std::vector players_; std::vector hand_; int turn_; int decksize_; Card trump_; bool ingame_; bool status_valid_; // Invalidate after moves etc. int c_cards_in_hand_; int c_over_delay_; int c_deck_count_; int c_allow_jokers_; private: // Receive full status message void get_status(); }; #endif