<commit_before>#include "pch.h"

#include "Game.h"
#include "Event.h"

#include "Events\LoginErrorEvent.h"
#include "Events\LoginSuccessEvent.h"
#include "Events\ScreenChangedEvent.h"
#include "Events\PointerPressedEvent.h"

#include "Systems\NetworkSystem.h"

#include "Util\StringUtils.h"

#include "PinnedDownNet.h"

using namespace concurrency;

using namespace PinnedDownCore;
using namespace PinnedDownClient::Events;
using namespace PinnedDownClient::Systems;

using namespace Windows::Networking;
using namespace Windows::Networking::Sockets;


using namespace Windows::Storage::Streams;


#define PINNED_DOWN_SERVER_HOST "localhost"
#define PINNED_DOWN_SERVER_PORT "27015"
#define REQUIRES_AUTH

NetworkSystem::NetworkSystem()
{
}

void NetworkSystem::InitSystem(PinnedDownCore::Game* game)
{
	GameSystem::InitSystem(game);

	this->game->eventManager->AddListener(this, ScreenChangedEvent::ScreenChangedEventType);
	this->game->eventManager->AddListener(this, PointerPressedEvent::PointerPressedEventType);
}

void NetworkSystem::OnEvent(Event & newEvent)
{
	if (newEvent.GetEventType() == ScreenChangedEvent::ScreenChangedEventType)
	{
		auto screenChangedEvent = static_cast<ScreenChangedEvent&>(newEvent);
		this->OnScreenChanged(screenChangedEvent);
	}
	else if (newEvent.GetEventType() == PointerPressedEvent::PointerPressedEventType)
	{
		auto pointerPressedEvent = static_cast<PointerPressedEvent&>(newEvent);
		this->OnPointerPressed(pointerPressedEvent);
	}
}

void NetworkSystem::OnPointerPressed(PointerPressedEvent& pointerPressedEvent)
{
	this->SendPacket();
}

void NetworkSystem::OnScreenChanged(ScreenChangedEvent& screenChangedEvent)
{
	if (screenChangedEvent.newScreen == ScreenName::Login)
	{
		this->InitSocket();
	}
}

void NetworkSystem::InitSocket()
{
	this->clientSocket = ref new StreamSocket();
	this->serverHost = ref new HostName(PINNED_DOWN_SERVER_HOST);

	auto storeTask = create_task(this->clientSocket->ConnectAsync(serverHost, PINNED_DOWN_SERVER_PORT));

	storeTask.then([this](void)
	{
#ifdef REQUIRES_AUTH
		auto client = PinnedDownClient::Services::PinnedDownMobileService::GetClient();
		return client.login(azure::mobile::facebook);
	}).then([this](azure::mobile::user authUser)
	{
		if (authUser.is_authenticated())
		{
#endif
			this->connected = true;
			this->user = authUser;

			// Create the DataWriter object backed by the socket stream.  When dataWriter is deleted, it will also close the underlying stream.
			this->dataWriter = ref new DataWriter(this->clientSocket->OutputStream);
			dataWriter->UnicodeEncoding = UnicodeEncoding::Utf8;
			dataWriter->ByteOrder = ByteOrder::LittleEndian;<commit_msg>CHANGED: Azure - Disabled server-side authentication.<commit_after>#include "pch.h"

#include "Game.h"
#include "Event.h"

#include "Events\LoginErrorEvent.h"
#include "Events\LoginSuccessEvent.h"
#include "Events\ScreenChangedEvent.h"
#include "Events\PointerPressedEvent.h"

#include "Systems\NetworkSystem.h"

#include "Util\StringUtils.h"

#include "PinnedDownNet.h"

using namespace concurrency;

using namespace PinnedDownCore;
using namespace PinnedDownClient::Events;
using namespace PinnedDownClient::Systems;

using namespace Windows::Networking;
using namespace Windows::Networking::Sockets;


using namespace Windows::Storage::Streams;


#define PINNED_DOWN_SERVER_HOST "localhost"
#define PINNED_DOWN_SERVER_PORT "27015"
//#define REQUIRES_AUTH

NetworkSystem::NetworkSystem()
{
}

void NetworkSystem::InitSystem(PinnedDownCore::Game* game)
{
	GameSystem::InitSystem(game);

	this->game->eventManager->AddListener(this, ScreenChangedEvent::ScreenChangedEventType);
	this->game->eventManager->AddListener(this, PointerPressedEvent::PointerPressedEventType);
}

void NetworkSystem::OnEvent(Event & newEvent)
{
	if (newEvent.GetEventType() == ScreenChangedEvent::ScreenChangedEventType)
	{
		auto screenChangedEvent = static_cast<ScreenChangedEvent&>(newEvent);
		this->OnScreenChanged(screenChangedEvent);
	}
	else if (newEvent.GetEventType() == PointerPressedEvent::PointerPressedEventType)
	{
		auto pointerPressedEvent = static_cast<PointerPressedEvent&>(newEvent);
		this->OnPointerPressed(pointerPressedEvent);
	}
}

void NetworkSystem::OnPointerPressed(PointerPressedEvent& pointerPressedEvent)
{
	this->SendPacket();
}

void NetworkSystem::OnScreenChanged(ScreenChangedEvent& screenChangedEvent)
{
	if (screenChangedEvent.newScreen == ScreenName::Login)
	{
		this->InitSocket();
	}
}

void NetworkSystem::InitSocket()
{
	this->clientSocket = ref new StreamSocket();
	this->serverHost = ref new HostName(PINNED_DOWN_SERVER_HOST);

	auto storeTask = create_task(this->clientSocket->ConnectAsync(serverHost, PINNED_DOWN_SERVER_PORT));

	storeTask.then([this](void)
	{
#ifdef REQUIRES_AUTH
		auto client = PinnedDownClient::Services::PinnedDownMobileService::GetClient();
		return client.login(azure::mobile::facebook);
	}).then([this](azure::mobile::user authUser)
	{
		if (authUser.is_authenticated())
		{

			this->connected = true;
			this->user = authUser;
#endif
			// Create the DataWriter object backed by the socket stream.  When dataWriter is deleted, it will also close the underlying stream.
			this->dataWriter = ref new DataWriter(this->clientSocket->OutputStream);
			dataWriter->UnicodeEncoding = UnicodeEncoding::Utf8;
			dataWriter->ByteOrder = ByteOrder::LittleEndian;
{'fraction_non_alphanumeric': 0.11902985074626865, 'fraction_numerical': 0.002238805970149254, 'mean_word_length': 7.55023923444976, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '417984', 'n_tokens_mistral': 1703, 'n_tokens_neox': 1631, 'n_words': 295}