<commit_before>//- Standard Library -
#include <map>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>

//- Beach Judge -
#include <BeachJudge/Base.h>
#include <BeachJudge/Session.h>

using namespace std;

#define BEACHJUDGE_SESSION_EXPIREMS 30 * 60 * 1000 //- TODO: Externalize to Config -

namespace beachjudge
{
	bool SessionExpireComp(Session *sessA, Session *sessB)
	{
		return sessA->GetExpireTimeMS() > sessB->GetExpireTimeMS();
	}

	map<unsigned long, Session *> g_sessionMap;
	map<unsigned short, Session *> g_sessionIDMap;
	vector<Session *> g_sessionVec;

	Session *Session::Create(unsigned long address, unsigned short port, Team *team)
	{
		Session *session = Lookup(address);
		if(!session)
		{
			session = new Session();
			session->m_address = address;
			string addrStr;
			g_sessionMap[address] = session;
			for(unsigned char a = 0; a < 4; a++)
			{
				char buff[4];
				memset(buff, 0, 4);
				sprintf(buff, "%d", (unsigned short)(address & 0xFF));
				addrStr.append(buff);
				address >>= 8;
				if(a < 3)
					addrStr.push_back('.');
			}
			session->m_addressString = addrStr;

			do
			{
				session->m_id = (unsigned short)rand();
			}
			while(g_sessionIDMap.count(session->m_id));
			g_sessionIDMap[session->m_id] = session;
			g_sessionVec.push_back(session);
		}

		session->m_variables["isJudge"] = team->IsJudge() ? 1 : 0;
		session->m_port = port;
		session->m_team = team;
		session->ResetTimeout();
		return session;
	}
	Session *Session::Lookup(unsigned long address)
	{
		if(g_sessionMap.count(address))
			return g_sessionMap[address];
		return 0;
	}
	void Session::Cleanup(bool deleteAll)
	{
		unsigned long currTimeMS = getRunTimeMS();
		while(g_sessionVec.size())
		{
			Session *session = g_sessionVec.back();
			if(deleteAll || session->GetExpireTimeMS() <= currTimeMS)
				delete session;
			else
				break;
		}
	}

	void Session::ListCurrent()<commit_msg>Added isTeam var for Page generation<commit_after>//- Standard Library -
#include <map>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>

//- Beach Judge -
#include <BeachJudge/Base.h>
#include <BeachJudge/Session.h>

using namespace std;

#define BEACHJUDGE_SESSION_EXPIREMS 30 * 60 * 1000 //- TODO: Externalize to Config -

namespace beachjudge
{
	bool SessionExpireComp(Session *sessA, Session *sessB)
	{
		return sessA->GetExpireTimeMS() > sessB->GetExpireTimeMS();
	}

	map<unsigned long, Session *> g_sessionMap;
	map<unsigned short, Session *> g_sessionIDMap;
	vector<Session *> g_sessionVec;

	Session *Session::Create(unsigned long address, unsigned short port, Team *team)
	{
		Session *session = Lookup(address);
		if(!session)
		{
			session = new Session();
			session->m_address = address;
			string addrStr;
			g_sessionMap[address] = session;
			for(unsigned char a = 0; a < 4; a++)
			{
				char buff[4];
				memset(buff, 0, 4);
				sprintf(buff, "%d", (unsigned short)(address & 0xFF));
				addrStr.append(buff);
				address >>= 8;
				if(a < 3)
					addrStr.push_back('.');
			}
			session->m_addressString = addrStr;

			do
			{
				session->m_id = (unsigned short)rand();
			}
			while(g_sessionIDMap.count(session->m_id));
			g_sessionIDMap[session->m_id] = session;
			g_sessionVec.push_back(session);
		}

		session->m_variables["isJudge"] = team->IsJudge() ? 1 : 0;
		session->m_variables["isTeam"] = team->IsJudge() ? 0 : 1;
		session->m_port = port;
		session->m_team = team;
		session->ResetTimeout();
		return session;
	}
	Session *Session::Lookup(unsigned long address)
	{
		if(g_sessionMap.count(address))
			return g_sessionMap[address];
		return 0;
	}
	void Session::Cleanup(bool deleteAll)
	{
		unsigned long currTimeMS = getRunTimeMS();
		while(g_sessionVec.size())
		{
			Session *session = g_sessionVec.back();
			if(deleteAll || session->GetExpireTimeMS() <= currTimeMS)
				delete session;
			else
				break;
		}
	}

	void Session::ListCurrent()
{'fraction_non_alphanumeric': 0.14274943453128927, 'fraction_numerical': 0.010052777079668259, 'mean_word_length': 4.0571791613723, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 59, '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': '4284758', 'n_tokens_mistral': 1615, 'n_tokens_neox': 1390, 'n_words': 304}