Skip to content

Commit

Permalink
Merge pull request etternagame#42 from Nickito12/master
Browse files Browse the repository at this point in the history
Online protocol stuff
  • Loading branch information
MinaciousGrace authored Jan 26, 2017
2 parents a83ab16 + 0df2126 commit c4ba026
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 8 deletions.
17 changes: 15 additions & 2 deletions src/NetworkSyncManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ NetworkSyncManager *NSMAN;

#include "ver.h"


#if defined(WITHOUT_NETWORKING)
NetworkSyncManager::NetworkSyncManager( LoadingWindow *ld ) { useSMserver=false; isSMOnline = false; }
NetworkSyncManager::~NetworkSyncManager () { }
Expand Down Expand Up @@ -391,7 +390,7 @@ void NetworkSyncManager::StartRequest( short position )
for (int i=0; i<2-players; ++i)
m_packet.WriteNT(""); //Write a NULL if no player

//Send song hash/chartkey
//Send chartkey
if (m_ServerVersion >= 129) {
tSteps = GAMESTATE->m_pCurSteps[PLAYER_1];
if (tSteps != NULL && GAMESTATE->IsPlayerEnabled(PLAYER_1)) {
Expand All @@ -409,6 +408,7 @@ void NetworkSyncManager::StartRequest( short position )

int rate = (int)(GAMESTATE->m_SongOptions.GetCurrent().m_fMusicRate * 100);
m_packet.Write1(rate);
m_packet.WriteNT(GAMESTATE->m_pCurSong->GetFileHash());
}

//This needs to be reset before ScreenEvaluation could possibly be called
Expand Down Expand Up @@ -628,6 +628,11 @@ void NetworkSyncManager::ProcessInput()
m_sMainTitle = m_packet.ReadNT();
m_sArtist = m_packet.ReadNT();
m_sSubTitle = m_packet.ReadNT();
//Read songhash
if (m_ServerVersion >= 129) {
m_sFileHash = m_packet.ReadNT();
}
SCREENMAN->SendMessageToTopScreen( SM_ChangeSong );
SCREENMAN->SendMessageToTopScreen( SM_ChangeSong );
}
break;
Expand Down Expand Up @@ -733,6 +738,10 @@ void NetworkSyncManager::ReportPlayerOptions()
NetPlayerClient->SendPack((char*)&m_packet.Data, m_packet.Position);
}

int NetworkSyncManager::GetServerVersion()
{
return m_ServerVersion;
}
void NetworkSyncManager::SelectUserSong()
{
m_packet.ClearPacket();
Expand All @@ -741,6 +750,10 @@ void NetworkSyncManager::SelectUserSong()
m_packet.WriteNT( m_sMainTitle );
m_packet.WriteNT( m_sArtist );
m_packet.WriteNT( m_sSubTitle );
//Send songhash
if (m_ServerVersion >= 129) {
m_packet.WriteNT(GAMESTATE->m_pCurSong->GetFileHash());
}
NetPlayerClient->SendPack( (char*)&m_packet.Data, m_packet.Position );
}

Expand Down
3 changes: 3 additions & 0 deletions src/NetworkSyncManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,13 @@ class NetworkSyncManager
RString m_sMainTitle;
RString m_sArtist;
RString m_sSubTitle;
RString m_sFileHash;
int m_sHash;
int m_iSelectMode;
void SelectUserSong();

int GetServerVersion();

RString m_sChatText;

// FIXME: This should NOT be public. PERIOD. It probably shouldn't be a member at all.
Expand Down
36 changes: 30 additions & 6 deletions src/ScreenNetSelectMusic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,14 +245,38 @@ void ScreenNetSelectMusic::HandleScreenMessage( const ScreenMessage SM )

vector <Song *> AllSongs = SONGMAN->GetAllSongs();
unsigned i;
for( i=0; i < AllSongs.size(); i++ )

bool found = false;
if (NSMAN->GetServerVersion() >= 129)
{
m_cSong = AllSongs[i];
if( ( !m_cSong->GetTranslitArtist().CompareNoCase( NSMAN->m_sArtist ) ) &&
( !m_cSong->GetTranslitMainTitle().CompareNoCase( NSMAN->m_sMainTitle ) ) &&
( !m_cSong->GetTranslitSubTitle().CompareNoCase( NSMAN->m_sSubTitle ) ) )
break;
//Dont earch by filehash if none was sent
if(!NSMAN->m_sFileHash.empty())
for (i = 0; i < AllSongs.size(); i++)
{
m_cSong = AllSongs[i];
if (NSMAN->m_sArtist == m_cSong->GetTranslitArtist() &&
NSMAN->m_sMainTitle == m_cSong->GetTranslitMainTitle() &&
NSMAN->m_sSubTitle == m_cSong->GetTranslitSubTitle() &&
NSMAN->m_sFileHash == m_cSong->GetFileHash())
{
found = true;
break;
}
}

}
//If we couldnt find it using file hash search for it without using it, if using SMSERVER < 129 it will go here
if(!found)
for (i = 0; i < AllSongs.size(); i++)
{
m_cSong = AllSongs[i];
if (NSMAN->m_sArtist == m_cSong->GetTranslitArtist() &&
NSMAN->m_sMainTitle == m_cSong->GetTranslitMainTitle() &&
NSMAN->m_sSubTitle == m_cSong->GetTranslitSubTitle())
{
break;
}
}

bool haveSong = i != AllSongs.size();

Expand Down
27 changes: 27 additions & 0 deletions src/Song.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
#include <set>
#include <float.h>

//-Nick12 Used for song file hashing
#include <CryptManager.h>

/**
* @brief The internal version of the cache for StepMania.
Expand Down Expand Up @@ -1417,6 +1419,31 @@ void Song::AddAutoGenNotes()
}
}

RString Song::GetFileHash()
{
if (m_sFileHash.empty()) {
RString sPath = SetExtension(GetSongFilePath(), "sm");
if (!IsAFile(sPath))
sPath = SetExtension(GetSongFilePath(), "dwi");
if (!IsAFile(sPath))
sPath = SetExtension(GetSongFilePath(), "sma");
if (!IsAFile(sPath))
sPath = SetExtension(GetSongFilePath(), "bms");
if (!IsAFile(sPath))
sPath = SetExtension(GetSongFilePath(), "ksf");
if (!IsAFile(sPath))
sPath = SetExtension(GetSongFilePath(), "json");
if (!IsAFile(sPath))
sPath = SetExtension(GetSongFilePath(), "jso");
if (!IsAFile(sPath))
sPath = SetExtension(GetSongFilePath(), "ssc");
if (IsAFile(sPath))
m_sFileHash = BinaryToHex(CRYPTMAN->GetSHA1ForFile(sPath));
else
m_sFileHash = "";
}
return m_sFileHash;
}
void Song::AutoGen( StepsType ntTo, StepsType ntFrom )
{
// int iNumTracksOfTo = GAMEMAN->StepsTypeToNumTracks(ntTo);
Expand Down
3 changes: 3 additions & 0 deletions src/Song.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ class Song
bool ReloadFromSongDir() { return ReloadFromSongDir(GetSongDir()); }
void LoadEditsFromSongDir(const RString &dir);

RString m_sFileHash;
RString GetFileHash();

bool HasAutosaveFile();
bool LoadAutosaveFile();

Expand Down

0 comments on commit c4ba026

Please sign in to comment.