view libmlk-client/malikania/client/state/login_state.cpp @ 208:263122adef77

client: add texture and painter closes #966 @2h closes #967 @2h
author David Demelier <markand@malikania.fr>
date Wed, 05 Dec 2018 22:24:44 +0100
parents 12873699ad8b
children
line wrap: on
line source

/*
 * login_state.cpp -- login state
 *
 * Copyright (c) 2013-2018 David Demelier <markand@malikania.fr>
 *
 * Permission to use, copy, modify, and/or distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#include <malikania/unicode.hpp>

#include <malikania/client/color.hpp>
#include <malikania/client/client.hpp>
#include <malikania/client/theme.hpp>
#include <malikania/client/window.hpp>

#include "login_state.hpp"
#include "lobby_state.hpp"

namespace mlk {

namespace client {

void login_state::do_connect()
{
	state_ = state_t::connecting;
	status_ = "Connecting...";
	client_.connect("localhost", 3320);
}

void login_state::do_auth()
{
	status_ = "Authenticating";
	state_ = state_t::authenticating;
	client_.send({
		{ "command",    "auth"                          },
		{ "login",      unicode::to_utf8(login_)        },
		{ "password",   unicode::to_utf8(password_)     }
	});
}

login_state::login_state(client& clt)
	: client_(clt)
{
	client_.window().start_edit();
}

#if 0

void login_state::handle_text(const text_event& ev)
{
	if (index_ == 0)
		login_ += ev.text;
	else
		password_ += ev.text;
}

#endif

void login_state::update(client&)
{
}

#if 0

void login_state::handle_connect(const std::error_code& code)
{
	if (code)
		status_ = code.message();
	else
		do_auth();
}

void login_state::handle_message(const std::error_code& code, const nlohmann::json& msg)
{
	if (code)
		status_ = code.message();
	else
		status_ = msg["error"].get<std::string>();
}

void login_state::handle_key_down(const key_event& ev)
{
}

#endif

void login_state::draw(client& clt)
{
}

} // !client

} // !mlk