2016-09-27 22:26:36 +00:00
|
|
|
#pragma once
|
|
|
|
|
2016-09-28 05:28:18 +00:00
|
|
|
#define ASIO_STANDALONE
|
|
|
|
|
2016-09-27 22:26:36 +00:00
|
|
|
#include <iostream>
|
|
|
|
#include <memory>
|
|
|
|
#include <utility>
|
2016-09-28 01:35:05 +00:00
|
|
|
#include <string>
|
2016-09-27 22:26:36 +00:00
|
|
|
#include <asio.hpp>
|
|
|
|
|
2016-09-28 01:35:05 +00:00
|
|
|
#include "game.hpp"
|
|
|
|
|
2016-09-27 22:26:36 +00:00
|
|
|
using asio::ip::tcp;
|
|
|
|
|
|
|
|
class Session
|
|
|
|
: public std::enable_shared_from_this<Session>
|
|
|
|
{
|
|
|
|
public:
|
2016-09-27 23:48:34 +00:00
|
|
|
Session(tcp::socket socket, game::State* state)
|
|
|
|
: m_socket(std::move(socket))
|
2016-09-27 22:26:36 +00:00
|
|
|
{
|
2016-09-27 23:48:34 +00:00
|
|
|
m_state = state;
|
2016-09-27 22:26:36 +00:00
|
|
|
}
|
|
|
|
|
2016-09-28 01:35:05 +00:00
|
|
|
void start();
|
2016-09-27 22:26:36 +00:00
|
|
|
|
|
|
|
private:
|
2016-09-28 01:35:05 +00:00
|
|
|
void do_read();
|
|
|
|
void do_write(char m_snd_data[], std::size_t length);
|
|
|
|
bool parse(std::string);
|
|
|
|
tcp::socket m_socket;
|
|
|
|
enum { max_length = 1024 };
|
|
|
|
char m_rcv_data[max_length];
|
2016-09-27 23:48:34 +00:00
|
|
|
game::State* m_state;
|
|
|
|
bool m_started = false;
|
2016-09-28 01:35:05 +00:00
|
|
|
int m_pid;
|
2016-09-27 22:26:36 +00:00
|
|
|
};
|