1. David Stone
  2. Technical Machine

Source

Technical Machine / source / clients / pokemon_lab / client.hpp

// Connect to Pokemon Lab
// Copyright (C) 2012 David Stone
//
// This file is part of Technical Machine.
//
// Technical Machine is free software: you can redistribute it and / or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

#ifndef POKEMON_LAB__CONNECT_HPP_
#define POKEMON_LAB__CONNECT_HPP_

#include <cstdint>
#include <string>
#include <vector>
#include <utility>

#include <boost/asio/deadline_timer.hpp>

#include "inmessage.hpp"
#include "../network/client.hpp"

namespace technicalmachine {
enum class Result;
namespace pl {

class Battle;
class Channel;
class Metagame;

class Client : public network::Client {
public:
	explicit Client (unsigned set_depth);
	void run ();
	void handle_message (InMessage::Message code, InMessage & msg);
	void send_channel_message(std::string const & channel, std::string const & message);
	void send_channel_message (uint32_t channel_id, std::string const & message);
private:
	void reset_timer(long timer_length);
	void request_authentication ();
	void send_keep_alive_message ();
	void handle_welcome_message (uint32_t version, std::string const & server, std::string const & message) const;
	void handle_password_challenge (InMessage & msg);
	enum SecretStyle {
		NONE = 0,
		MD5 = 1,		// This secret style is never actually used.
		VBULLETIN = 2
	};
	std::string get_challenge_response (std::string const & challenge, SecretStyle secret_style, std::string const & salt);
	std::string get_shared_secret (SecretStyle secret_style, std::string const & salt);
	void handle_registry_response (uint8_t code, std::string const & details);
	void join_channel (std::string const & channel);
	void part_channel (std::string const & channel);
	void handle_channel_info (uint32_t channel_id, uint8_t info, std::string const & channel_name, std::string const & topic, uint32_t channel_flags, std::vector <std::pair <std::string, uint32_t> > const & users);
	void handle_channel_join_part (uint32_t channel_id, std::string const & user, bool joining);
	void handle_channel_status (uint32_t channel_id, std::string const & invoker, std::string const & user, uint32_t flags);
	void handle_channel_list (std::vector <Channel> const & channel_list);
	void send_battle_challenge (std::string const & opponent);
	void handle_finalize_challenge (std::string const & user, bool accepted, bool challenger);
	void handle_metagame_list (std::vector <Metagame> const & metagames);
	void handle_invalid_team(std::vector<int16_t> const & violations) const;
	void handle_error_message (uint8_t code, std::string const & details) const;
	void send_private_message (std::string const & user, std::string const & message);
	Result get_result (uint32_t battle_id, uint16_t winner);

	std::unique_ptr<boost::asio::deadline_timer> timer;
	std::map <std::string, uint32_t> channel_to_id;
};

} // namespace pl
} // namespace technicalmachine
#endif // POKEMON_LAB__CONNECT_HPP_