Ejemplo n.º 1
0
void StepManiaLanServer::ScreenNetMusicSelectStatus(PacketFunctions& Packet, unsigned int clientNum)
{
	CString message = "";
	int EntExitCode = Packet.Read1();

	message += Client[clientNum]->Player[0].name;
	if (Client[clientNum]->twoPlayers)
		message += "&";
	message += Client[clientNum]->Player[1].name;

	if (EntExitCode % 2 == 1)
		Client[clientNum]->inNetMusicSelect = true;
	else
		Client[clientNum]->inNetMusicSelect = false;

	switch (EntExitCode)
	{
	case 0:
		message += " left the song selection.";
		break;
	case 1:
		message += " entered the song selection.";
		break;
	case 2:
		message += " went into options.";
		break;
	case 3:
		message += " came back from options.";
		break;
	}
	ServerChat(message);
}
Ejemplo n.º 2
0
bool COpenSubtitlesSearch::LogIn()
{
  if (!m_authenticated)
  {
    m_authenticated = CPasswordManager::GetInstance().SetUserPass(ModuleName(), m_strUser, m_strPass);
  }
  
  std::string strUA = StringUtils::Format("%s_v%i.%i" , CCompileInfo::GetAppName(),
                                          CCompileInfo::GetMajor(),CCompileInfo::GetMinor());
  StringUtils::ToLower(strUA);
  ulxr::MethodCall      methodcall(ULXR_PCHAR("LogIn"));
  methodcall.addParam(ulxr::RpcString(ULXR_PCHAR(m_strUser)));         // username
  methodcall.addParam(ulxr::RpcString(ULXR_PCHAR(m_strPass)));         // password
  methodcall.addParam(ulxr::RpcString(ULXR_PCHAR("eng")));             // language
  methodcall.addParam(ulxr::RpcString(ULXR_PCHAR(strUA)));             // useragent string
  ulxr::MethodResponse response = ServerChat(methodcall);
  ulxr::Struct cap = response.getResult();
  if (response.isOK() && cap.hasMember(ULXR_PCHAR("status")))
  {
    ulxr::RpcString status = cap.getMember(ULXR_PCHAR("status"));
    CLog::Log(LOGDEBUG, "%s - response - %s", __PRETTY_FUNCTION__, status.getString().c_str());
    if (status.getString() == "200 OK")
    {
      ulxr::RpcString token = cap.getMember(ULXR_PCHAR("token"));
      m_strToken = token.getString();
      return true;
    }
  }
  return false;
}
Ejemplo n.º 3
0
void StepManiaLanServer::AnalizeChat(PacketFunctions &Packet, const unsigned int clientNum)
{
	CString message = Packet.ReadNT();
	if (message.at(0) == '/')
	{
		CString command = message.substr(1, message.find(" ")-1);
		if ((command.compare("list") == 0)||(command.compare("have") == 0))
		{
			if (command.compare("list") == 0)
			{
				Reply.ClearPacket();
				Reply.Write1(NSCCM + NSServerOffset);
				Reply.WriteNT(ListPlayers());
				SendNetPacket(clientNum, Reply);
			}
			else
			{
				message = "";
				message += Client[clientNum]->Player[0].name;
				if (Client[clientNum]->twoPlayers)
					message += "&";
				message += Client[clientNum]->Player[1].name;
				message += " forces has song.";
				Client[clientNum]->forceHas = true;
				ServerChat(message);
			}
		}
		else
		{
			if (clientNum == 0)
			{
				if (command.compare("force_start") == 0)
					ForceStart();
				if (command.compare("kick") == 0)
				{
					CString name = message.substr(message.find(" ")+1);
					Kick(name);
				}
				if (command.compare("ban") == 0)
				{
					CString name = message.substr(message.find(" ")+1);
					Ban(name);
				}
			}
			else
			{
				Reply.ClearPacket();
				Reply.Write1(NSCCM + NSServerOffset);
				Reply.WriteNT("You do not have permission to use server commands.");
				SendNetPacket(clientNum, Reply);
			}
		}
	}
	else
		RelayChat(message, clientNum);
}
Ejemplo n.º 4
0
void StepManiaLanServer::Kick(CString &name)
{
	bool kicked = false;
	for (unsigned int x = 0; x < Client.size(); ++x)
		for (int y = 0; (y < 2)&&(kicked == false); ++y)
			if (name == Client[x]->Player[y].name)
			{
				ServerChat("Kicked " + name + ".");
				Disconnect(x);
				kicked = true;
			}
}
Ejemplo n.º 5
0
void StepManiaLanServer::Ban(CString &name)
{
	bool kicked = false;
	for (unsigned int x = 0; x < Client.size(); ++x)
		for (int y = 0; (y < 2)&&(kicked == false); ++y)
			if (name == Client[x]->Player[y].name)
			{
				ServerChat("Banned " + name + ".");
				bannedIPs.push_back(Client[x]->clientSocket.address);
				Disconnect(x);
				kicked = true;
			}
}
Ejemplo n.º 6
0
bool COpenSubtitlesSearch::Download(const CFileItem *subItem,std::vector<std::string> &items)
{
  ulxr::MethodCall      methodcall(ULXR_PCHAR("DownloadSubtitles"));
  ulxr::Array subtitleIDlist;
  ulxr::RpcString ID = subItem->GetProperty("IDSubtitleFile").asString();
  subtitleIDlist.addItem(ID);
  ulxr::RpcString token = m_strToken;
  methodcall.addParam(token);
  methodcall.addParam(subtitleIDlist);
  
  ulxr::MethodResponse response = ServerChat(methodcall);
  ulxr::Struct cap = response.getResult();
  
  if (response.isOK() && cap.hasMember(ULXR_PCHAR("status")))
  {
    ulxr::RpcString status = cap.getMember(ULXR_PCHAR("status"));
    CLog::Log(LOGDEBUG, "%s - response - %s", __PRETTY_FUNCTION__, status.getString().c_str());
    if (status.getString() == "200 OK")
    {
      if (cap.hasMember(ULXR_PCHAR("data")))
      {
        ulxr::Array subs = cap.getMember(ULXR_PCHAR("data"));
        for (unsigned i = 0; i < subs.size(); ++i)
        {
          ulxr::Struct entry = subs.getItem(i);
          ulxr::RpcString data = entry.getMember(ULXR_PCHAR("data"));
          std::string zipdata = data.getString();
          std::string zipdata64Decoded = Base64::Decode(zipdata);
          std::string zipdata64DecodedInflated;
          CSubtitleUtilities::gzipInflate(zipdata64Decoded,zipdata64DecodedInflated);
          XFILE::CFile file;
          std::string destination = StringUtils::Format("special://temp/%s.%s",
                                                        StringUtils::CreateUUID().c_str(),
                                                        subItem->GetProperty("SubFormat").asString().c_str()
                                                        );
          file.OpenForWrite(destination);
          file.Write(zipdata64DecodedInflated.c_str(), zipdata64DecodedInflated.size());
          items.push_back(destination);
        }
        CLog::Log(LOGDEBUG, "%s - OpenSubitles subfile downloaded", __PRETTY_FUNCTION__);
        return true;
      }
    }
  }
  return false;
}
Ejemplo n.º 7
0
void StepManiaLanServer::ScreenNetMusicSelectStatus(PacketFunctions& Packet, unsigned int clientNum)
{
	CString message = "";
	int EntExitCode = Packet.Read1();

	message += Client[clientNum]->Player[0].name;
	if (Client[clientNum]->twoPlayers)
		message += "&";
	message += Client[clientNum]->Player[1].name;

	if (EntExitCode % 2 == 1)
		Client[clientNum]->inNetMusicSelect = true;
	else
		Client[clientNum]->inNetMusicSelect = false;

	GameClient::LastNetScreen LastScreenInfo = GameClient::NS_NOWHERE;

	switch (EntExitCode)
	{
	case 0:
		message += " left the song selection.";
		break;
	case 1:
		message += " entered the song selection.";
		LastScreenInfo = GameClient::NS_SELECTSCREEN;
		break;
	case 2:
		message += " exited options.";
		break;
	case 3:
		message += " went into options.";
		LastScreenInfo = GameClient::NS_OPTIONS;
		break;
	case 4:
		//no need to mention exiting of options
		break;
	case 5:
		message += " finished the game.";
		LastScreenInfo = GameClient::NS_EVALUATION;
		break;
	}
	ServerChat(message);
	Client[clientNum]->NetScreenInfo = LastScreenInfo;
	SendUserList ();
}
Ejemplo n.º 8
0
void CUdpSocket::Parsing(char *pBuf, int len)
{
	BYTE command;
	int index = 0;

	command = GetByte( pBuf, index );

	switch( command ) {
	case STS_CHAT:
		ServerChat( pBuf+index );
		break;
	case UDP_BATTLE_EVENT_PACKET:
		RecvBattleEvent( pBuf+index );
		break;
	case UDP_KNIGHTS_PROCESS:
		ReceiveKnightsProcess( pBuf+index );
		break;
	case UDP_BATTLEZONE_CURRENT_USERS:
		RecvBattleZoneCurrentUsers( pBuf+index );
		break;
	}
}
Ejemplo n.º 9
0
void StepManiaLanServer::SelectSong(PacketFunctions& Packet, unsigned int clientNum)
{
	int use = Packet.Read1();
	CString message;

	if (use == 2)
	{
		if (clientNum == 0)
		{ 
			SecondSameSelect = false;

			CurrentSongInfo.title = Packet.ReadNT();
			CurrentSongInfo.artist = Packet.ReadNT();
			CurrentSongInfo.subtitle = Packet.ReadNT();

			Reply.ClearPacket();
			Reply.Write1(NSCRSG + NSServerOffset);
			Reply.Write1(1);
			Reply.WriteNT(CurrentSongInfo.title);
			Reply.WriteNT(CurrentSongInfo.artist);
			Reply.WriteNT(CurrentSongInfo.subtitle);		

			//Only send data to clients currently in ScreenNetMusicSelect
			for (unsigned int x = 0; x < Client.size(); ++x)
				if (Client[x]->inNetMusicSelect)
					SendNetPacket(x, Reply);

			//The following code forces the host to select the same song twice in order to play it.
			if ((strcmp(CurrentSongInfo.title, LastSongInfo.title) == 0) &&
				(strcmp(CurrentSongInfo.artist, LastSongInfo.artist) == 0) &&
				(strcmp(CurrentSongInfo.subtitle, LastSongInfo.subtitle) == 0))
					SecondSameSelect = true;

			if (!SecondSameSelect)
			{
				LastSongInfo.title = CurrentSongInfo.title;
				LastSongInfo.artist = CurrentSongInfo.artist;
				LastSongInfo.subtitle = CurrentSongInfo.subtitle;
				message = "Play \"";
				message += CurrentSongInfo.title + " " + CurrentSongInfo.subtitle;
				message += "\"?";
				ServerChat(message);
			}

		}
		else
		{
			message = servername;
			message += ": You do not have permission to pick a song.";
			Reply.ClearPacket();
			Reply.Write1(NSCCM + NSServerOffset);
			Reply.WriteNT(message);
			SendNetPacket(clientNum, Reply);
		}
	}

	if (use == 1)
	{
		//If user dosn't have song
		Client[clientNum]->hasSong = false;
		message = Client[clientNum]->Player[0].name;

		if (Client[clientNum]->twoPlayers)
		{
			message += "&";
			message += Client[clientNum]->Player[1].name;
		}

		message += " lacks song \"";
		message += CurrentSongInfo.title;
		message += "\"";
		ServerChat(message);
	}

	//If client has song
	if (use == 0)
		Client[clientNum]->hasSong = true;

	//Only play if everyone has the same song and the host has select the same song twice.
	if ( CheckHasSongState() && SecondSameSelect && (clientNum == 0) )
	{
		ClientsSongSelectStart();

		//Reset last song in case host picks same song again (otherwise dual select is bypassed)
		ResetLastSongInfo();
	}
}
Ejemplo n.º 10
0
bool COpenSubtitlesSearch::SubtitleSearch(const std::string &path,const std::string strLanguages,
                                          const std::string preferredLanguage,
                                          CFileItemList &subtitlesList)
{
  if (LogIn())
  {
    std::string strSize;
    std::string strHash;
    CSubtitleUtilities::SubtitleFileSizeAndHash(path, strSize, strHash);
    CLog::Log(LOGDEBUG, "%s - HASH - %s and Size - %s", __FUNCTION__, strHash.c_str(), strSize.c_str());

    ulxr::Array searchList;
    
    std::string lg;
    std::vector<std::string> languages3;
    std::vector<std::string> languages = StringUtils::Split(strLanguages, ',');
    // convert from English to eng
    for(std::vector<std::string>::iterator it = languages.begin(); it != languages.end(); ++it)
    {
      g_LangCodeExpander.ConvertToISO6392T((*it).c_str(),lg);
      languages3.push_back(lg);
    }
    
    //  hash search
    ulxr::Struct searchHashParam;
    std::string strLang = StringUtils::Join(languages3, ",");
    searchHashParam.addMember(ULXR_PCHAR("sublanguageid"), ulxr::RpcString(strLang));
    searchHashParam.addMember(ULXR_PCHAR("moviehash"),     ulxr::RpcString(strHash));
    searchHashParam.addMember(ULXR_PCHAR("moviebytesize"), ulxr::RpcString(strSize));
    searchList.addItem(searchHashParam);
    
    CVideoInfoTag* tag = g_application.CurrentFileItem().GetVideoInfoTag();
    
    std::string searchString;
    
    if (tag->m_iEpisode > -1)
    {
      searchString = StringUtils::Format("%s S%.2dE%.2d",tag->m_strShowTitle.c_str()
                                                        ,tag->m_iSeason
                                                        ,tag->m_iEpisode
                                         );
    }
    else
    {
      if (tag->m_iYear > 0)
      {
        int year = tag->m_iYear;
        std::string title = tag->m_strTitle;
        searchString = StringUtils::Format("%s (%i)",title.c_str(), year);
      }
      else
      {
        std::string strName = g_application.CurrentFileItem().GetMovieName(false);
        
        std::string strTitleAndYear;
        std::string strTitle;
        std::string strYear;
        CUtil::CleanString(strName, strTitle, strTitleAndYear, strYear, false);
        searchString = StringUtils::Format("%s (%s)",strTitle.c_str(), strYear.c_str());
      }
    }

    StringUtils::Replace(searchString, " ", "+");
    ulxr::Struct searchStringParam;
    
    //  title search
    searchStringParam.addMember(ULXR_PCHAR("sublanguageid"), ulxr::RpcString(StringUtils::Join(languages3, ",")));
    searchStringParam.addMember(ULXR_PCHAR("query"),         ulxr::RpcString(searchString));
    searchList.addItem(searchStringParam);
    
    ulxr::MethodCall      methodcall(ULXR_PCHAR("SearchSubtitles"));
    ulxr::RpcString token = m_strToken;
    methodcall.addParam(token);
    methodcall.addParam(searchList);
    ulxr::MethodResponse response = ServerChat(methodcall);
  
    ulxr::Struct cap = response.getResult();
    if (response.isOK() && cap.hasMember(ULXR_PCHAR("status")))
    {
      ulxr::RpcString status = cap.getMember(ULXR_PCHAR("status"));
      CLog::Log(LOGDEBUG, "%s - response - %s", __PRETTY_FUNCTION__, status.getString().c_str());
      if (status.getString() == "200 OK")
      {
        if (cap.hasMember(ULXR_PCHAR("data")))
        {
          ulxr::Array subs = cap.getMember(ULXR_PCHAR("data"));      
          for (unsigned i = 0; i < subs.size(); ++i)
          {
            ulxr::Struct entry = subs.getItem(i);
            CFileItemPtr item(new CFileItem());
            if (entry.hasMember(ULXR_PCHAR("LanguageName")))
            {
              ulxr::RpcString value = entry.getMember(ULXR_PCHAR("LanguageName"));
              item->SetLabel(value.getString());
            }
            if (entry.hasMember(ULXR_PCHAR("SubFileName")))
            {
              ulxr::RpcString value = entry.getMember(ULXR_PCHAR("SubFileName"));
              item->SetLabel2(value.getString());
            }
            if (entry.hasMember(ULXR_PCHAR("SubRating")))
            {
              ulxr::RpcString value = entry.getMember(ULXR_PCHAR("SubRating"));
              item->SetIconImage(StringUtils::Format("%i", atoi(value.getString().c_str())/2));
            }
            if (entry.hasMember(ULXR_PCHAR("ISO639")))
            {
              ulxr::RpcString value = entry.getMember(ULXR_PCHAR("ISO639"));
              item->SetArt("thumb",value.getString());
            }
            if (entry.hasMember(ULXR_PCHAR("MatchedBy")))
            {
              ulxr::RpcString value = entry.getMember(ULXR_PCHAR("MatchedBy"));
              item->SetProperty("sync", value.getString() == "moviehash" ? "true":"false");
            }
            if (entry.hasMember(ULXR_PCHAR("SubHearingImpaired")))
            {
              ulxr::RpcString value = entry.getMember(ULXR_PCHAR("SubHearingImpaired"));
              item->SetProperty("hearing_imp", value.getString() == "1" ? "true":"false");
            }
            if (entry.hasMember(ULXR_PCHAR("ZipDownloadLink")))
            {
              ulxr::RpcString value = entry.getMember(ULXR_PCHAR("ZipDownloadLink"));
              item->SetProperty("ZipDownloadLink", value.getString());
            }
            if (entry.hasMember(ULXR_PCHAR("IDSubtitleFile")))
            {
              ulxr::RpcString value = entry.getMember(ULXR_PCHAR("IDSubtitleFile"));
              item->SetProperty("IDSubtitleFile", value.getString());
            }
            if (entry.hasMember(ULXR_PCHAR("SubFormat")))
            {
              ulxr::RpcString value = entry.getMember(ULXR_PCHAR("SubFormat"));
              item->SetProperty("SubFormat", value.getString());
            }
            subtitlesList.Add(item);
          }
        }
        CLog::Log(LOGDEBUG, "%s - hold", __PRETTY_FUNCTION__);
        return true;
      }
    }
  }
  return false;
}