<commit_before>#include "cloginserver.h"
#include "cloginisc.h"
#include "cloginclient.h"
#include "ePacketType.h"

CLoginClient::CLoginClient() : CRoseClient(), access_rights_(0) {
  log_.SetIdentity("CLoginClient");
}

CLoginClient::CLoginClient(tcp::socket _sock)
    : CRoseClient(std::move(_sock)), access_rights_(0) {
  log_.SetIdentity("CLoginClient");
}

void CLoginClient::SendLoginReply(uint8_t Result) {
  CRosePacket* pak =
      new CRosePacket(ePacketType::PAKLC_LOGIN_REPLY, sizeof(pakLoginReply));
  pak->pLoginReply.Result = Result;
  pak->pLoginReply.Right = access_rights_;
  pak->pLoginReply.Type = 0;

  if (Result == 0) {
    // loop the server list here
    std::lock_guard<std::mutex> lock(CLoginServer::GetISCListMutex());
    for (auto& server : CLoginServer::GetISCList()) {
      if (server->GetType() == 1) {
        CLoginISC* svr = (CLoginISC*)server;

        // This if check is needed since the client actually looks for this.
        if (svr->IsTestServer())
          pak->Add<uint8_t>('@');
        else
          pak->Add<uint8_t>(' ');

        pak->AddString(svr->GetName().c_str(), true);
        pak->Add<uint32_t>(svr->GetId());
      }
    }
  }

  this->Send(pak);
}

bool CLoginClient::UserLogin(CRosePacket* P) {
  P->GetBytes(0, 32, password_);
  password_[32] = 0;  // Null term the string
  P->GetString(32, 16, (char*)username_);
  // IResult	*res = nullptr;
  // std::string	query = "CALL UserLogin('%s', '%s');";

  // TODO: Create string safe function to sanitize sql query input
  // TODO: Database class needs to become a singleton
  // res = pDB->QStore(query);

  // if(res != nullptr)
  {// Query the DB
   //	if(res)
   // 	{
   // 		// Already logged in
   // 		SendLoginReply( 4 );
   // 	}
   //
   // 	{
   // 		// Servers are under inspection
   // 		SendLoginReply( 1 );
   // 	}

   {// Okay to login!!
    SendLoginReply(0);
}

// 	{
// 		// Banned
// 		SendLoginReply( 5 );
// 	}
//
// 	{
// 		// Incorrect Password
// 		SendLoginReply( 3 );
// 	}
//
// 	{
// 		// Server Full
// 		SendLoginReply( 8 );
//	}
}
// else
{
  // The user doesn't exist or server is down.
  //	SendLoginReply( 1 );
}
return true;
}

bool CLoginClient::ChannelList(CRosePacket* P) {
  // m_Log.icprintf( "Channel List\n" );

  uint32_t ServerID = P->pChannelListReq.lServerID;

  CRosePacket* pak = new CRosePacket(ePacketType::PAKLC_CHANNEL_LIST_REPLY,
                                     sizeof(pakChannel_List));
  pak->pChannelList.lServerID = ServerID;
  pak->pChannelList.bServerCount = 0;

  pakChannelInfo channel;
  std::lock_guard<std::mutex> lock(CLoginServer::GetISCListMutex());
  for (auto& obj : CLoginServer::GetISCList()) {
    CLoginISC* server = (CLoginISC*)obj;
    if (server->GetType() == iscPacket::ServerReg_ServerType_CHAR &&
        server->GetId() == ServerID) {
      for (auto& obj : server->GetChannelList()) {
        tChannelInfo info = obj;
        {
          pak->pChannelList.bServerCount += 1;
          pakChannelInfo channel;
          channel.ChannelID = info.ChannelID;
          channel.pad = 0;
          channel.Status = 0;<commit_msg>Removed redefined variable<commit_after>#include "cloginserver.h"
#include "cloginisc.h"
#include "cloginclient.h"
#include "ePacketType.h"

CLoginClient::CLoginClient() : CRoseClient(), access_rights_(0) {
  log_.SetIdentity("CLoginClient");
}

CLoginClient::CLoginClient(tcp::socket _sock)
    : CRoseClient(std::move(_sock)), access_rights_(0) {
  log_.SetIdentity("CLoginClient");
}

void CLoginClient::SendLoginReply(uint8_t Result) {
  CRosePacket* pak =
      new CRosePacket(ePacketType::PAKLC_LOGIN_REPLY, sizeof(pakLoginReply));
  pak->pLoginReply.Result = Result;
  pak->pLoginReply.Right = access_rights_;
  pak->pLoginReply.Type = 0;

  if (Result == 0) {
    // loop the server list here
    std::lock_guard<std::mutex> lock(CLoginServer::GetISCListMutex());
    for (auto& server : CLoginServer::GetISCList()) {
      if (server->GetType() == 1) {
        CLoginISC* svr = (CLoginISC*)server;

        // This if check is needed since the client actually looks for this.
        if (svr->IsTestServer())
          pak->Add<uint8_t>('@');
        else
          pak->Add<uint8_t>(' ');

        pak->AddString(svr->GetName().c_str(), true);
        pak->Add<uint32_t>(svr->GetId());
      }
    }
  }

  this->Send(pak);
}

bool CLoginClient::UserLogin(CRosePacket* P) {
  P->GetBytes(0, 32, password_);
  password_[32] = 0;  // Null term the string
  P->GetString(32, 16, (char*)username_);
  // IResult	*res = nullptr;
  // std::string	query = "CALL UserLogin('%s', '%s');";

  // TODO: Create string safe function to sanitize sql query input
  // TODO: Database class needs to become a singleton
  // res = pDB->QStore(query);

  // if(res != nullptr)
  {// Query the DB
   //	if(res)
   // 	{
   // 		// Already logged in
   // 		SendLoginReply( 4 );
   // 	}
   //
   // 	{
   // 		// Servers are under inspection
   // 		SendLoginReply( 1 );
   // 	}

   {// Okay to login!!
    SendLoginReply(0);
}

// 	{
// 		// Banned
// 		SendLoginReply( 5 );
// 	}
//
// 	{
// 		// Incorrect Password
// 		SendLoginReply( 3 );
// 	}
//
// 	{
// 		// Server Full
// 		SendLoginReply( 8 );
//	}
}
// else
{
  // The user doesn't exist or server is down.
  //	SendLoginReply( 1 );
}
return true;
}

bool CLoginClient::ChannelList(CRosePacket* P) {
  // m_Log.icprintf( "Channel List\n" );

  uint32_t ServerID = P->pChannelListReq.lServerID;

  CRosePacket* pak = new CRosePacket(ePacketType::PAKLC_CHANNEL_LIST_REPLY,
                                     sizeof(pakChannel_List));
  pak->pChannelList.lServerID = ServerID;
  pak->pChannelList.bServerCount = 0;

  pakChannelInfo channel;
  std::lock_guard<std::mutex> lock(CLoginServer::GetISCListMutex());
  for (auto& obj : CLoginServer::GetISCList()) {
    CLoginISC* server = (CLoginISC*)obj;
    if (server->GetType() == iscPacket::ServerReg_ServerType_CHAR &&
        server->GetId() == ServerID) {
      for (auto& obj : server->GetChannelList()) {
        tChannelInfo info = obj;
        {
          pak->pChannelList.bServerCount += 1;
          channel.ChannelID = info.ChannelID;
          channel.pad = 0;
          channel.Status = 0;
{'fraction_non_alphanumeric': 0.15968544374899696, 'fraction_numerical': 0.01059220028887819, 'mean_word_length': 2.779260157671316, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 57, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '753277', 'n_tokens_mistral': 2315, 'n_tokens_neox': 2233, 'n_words': 421}