hg revision stored in engine and checked in network (MSVC only)

stable-5.1
Sven Eberhardt 2010-03-22 13:41:14 +01:00
parent 99d4c3875f
commit 9b7009de94
8 changed files with 71 additions and 3 deletions

View File

@ -742,6 +742,13 @@ target_link_libraries(c4group
set_property(TARGET clonk APPEND PROPERTY COMPILE_DEFINITIONS GLEW_STATIC)
set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_DEBUG _DEBUG)
############################################################################
# hgrevision as part of MSVC resources
############################################################################
if(MSVC_VERSION)
add_custom_command(TARGET clonk PRE_BUILD COMMAND hg id > hgrevision)
endif()
############################################################################
# build to planet
############################################################################

View File

@ -28,6 +28,7 @@
#ifdef _WIN32
#include <StdRegistry.h>
#include <C4UpdateDlg.h>
#include <resource.h>
#endif
#include "C4Game.h"
@ -118,6 +119,30 @@ bool C4Application::DoInit()
// Open log
OpenLog();
Revision.Ref("unknown");
#ifdef _WIN32
// load hg revision
HRSRC hrsrc = FindResource(NULL, MAKEINTRESOURCE(IDR_HGREVISION), RT_RCDATA);
if (hrsrc)
{
DWORD hr_sz = SizeofResource(NULL, hrsrc);
HGLOBAL hr = LoadResource(NULL, hrsrc);
if (hr && hr_sz)
{
const char *hr_ptr = static_cast<const char *>(LockResource(hr));
if (hr_ptr)
{
// copy max until first space (omit stuff like "tip")
const char *rev_end = static_cast<const char *>(memchr(hr_ptr, 0x0a, hr_sz));
if (rev_end) hr_sz = rev_end - hr_ptr;
Revision.Copy(hr_ptr, hr_sz);
UnlockResource(hr); // Not necessary and has no effect.
}
}
DeleteObject(hrsrc);
}
#endif
// init system group
if (!SystemGroup.Open(C4CFN_System))
{
@ -184,7 +209,7 @@ bool C4Application::DoInit()
// Engine header message
Log(C4ENGINEINFOLONG);
LogF("Version: %s %s", C4VERSION, C4_OS);
LogF("Version: %s %s (%s)", C4VERSION, C4_OS, Revision.getData());
// Initialize D3D/OpenGL
DDraw = DDrawInit(this, isFullScreen, false, Config.Graphics.ResX, Config.Graphics.ResY, Config.Graphics.BitDepth, Config.Graphics.Engine, Config.Graphics.Monitor);

View File

@ -42,6 +42,8 @@ class C4Application: public CStdApp
private:
// if set, this mission will be launched next
StdCopyStrBuf NextMission;
// version information strings
StdCopyStrBuf Revision;
public:
C4Application();
~C4Application();
@ -100,6 +102,8 @@ class C4Application: public CStdApp
void QuitGame(); // quit game only, but restart application if in fullscreen startup menu mode
void Activate(); // activate app to gain full focus in OS
void SetNextMission(const char *szMissionFilename);
const char *GetRevision() const { return Revision.getData(); }
};
extern C4Application Application;

View File

@ -56,7 +56,7 @@ void C4ClientCore::SetLocal(int32_t inID, bool fnActivated, bool fnObserver)
// misc
Name.CopyValidated(Config.Network.LocalName);
CUID.CopyValidated(Config.GetRegistrationData("Cuid"));
Revision.CopyValidated(Application.GetRevision());
ValidatedStdCopyStrBuf<C4InVal::VAL_NameNoEmpty> NickBuf;
NickBuf.Copy(Config.Network.Nick);
if (!NickBuf.getLength()) NickBuf.CopyValidated(Config.GetRegistrationData("Nick"));
@ -70,6 +70,7 @@ void C4ClientCore::SetUnknown(int32_t inID)
iID = inID;
// fill everything else with default values
Name.Ref("unknown"); CUID.Ref("unknown"); Nick.Ref("unknown");
Revision.Ref("unknown");
fActivated = fObserver = false;
}
@ -98,6 +99,7 @@ void C4ClientCore::CompileFunc(StdCompiler *pComp)
pComp->Value(mkNamingAdapt(Name, "Name", ""));
pComp->Value(mkNamingAdapt(CUID, "CUID", ""));
pComp->Value(mkNamingAdapt(Nick, "Nick", ""));
pComp->Value(mkNamingAdapt(Revision, "Revision", ""));
}
// *** C4Client

View File

@ -43,8 +43,9 @@ protected:
// identification
int32_t iID;
ValidatedStdCopyStrBuf<C4InVal::VAL_NameNoEmpty> Name, Nick;
ValidatedStdCopyStrBuf<C4InVal::VAL_NameNoEmpty> Name, Nick;
ValidatedStdCopyStrBuf<C4InVal::VAL_NameAllowEmpty> CUID;
ValidatedStdCopyStrBuf<C4InVal::VAL_NameAllowEmpty> Revision; // engine hg revision number
// version info
int iVersion[4];
@ -68,6 +69,7 @@ public:
const char *getName() const { return Name.getData(); }
const char *getCUID() const { return CUID.getData(); }
const char *getNick() const { return Nick.getData(); }
const char *getRevision() const { return Revision.getData(); }
bool isRegistered()const { return CUID.getLength()>0; }
// initialization

View File

@ -217,6 +217,21 @@ C4Network2::InitResult C4Network2::InitClient(const C4Network2Reference &Ref, bo
if(isEnabled()) Clear();
// Get host core
const C4ClientCore &HostCore = Ref.Parameters.Clients.getHost()->getCore();
// host core revision check
if (!SEqualNoCase(HostCore.getRevision(), Application.GetRevision()))
{
StdStrBuf msg;
msg.Format("[!]WARNING! Host engine revision (%s) differs from local revision (%s). Engines might run out of sync.");
if (::pGUI)
{
if (!pGUI->ShowMessageModal(msg.getData(), "[!]Network warning", C4GUI::MessageDialog::btnOKAbort, C4GUI::Ico_Notify, NULL /* do not allow to skip this message! */))
return IR_Fatal;
}
else
{
Log(msg.getData());
}
}
// repeat if wrong password
fWrongPassword = Ref.isPasswordNeeded();
StdStrBuf Password;
@ -1192,6 +1207,11 @@ bool C4Network2::Join(C4ClientCore &CCore, C4Network2IOConnection *pConn, const
// get client, set status
C4Network2Client *pClient = Clients.GetClient(CCore);
if(pClient) pClient->SetStatus(NCS_Joining);
// warn if client revision doesn't match our host revision
if (!SEqualNoCase(CCore.getRevision(), Application.GetRevision()))
{
LogF("[!]WARNING! Client %s engine revision (%s) differs from local revision (%s). Client might run out of sync.", CCore.getName(), CCore.getRevision(), Application.GetRevision());
}
// ok, client joined.
return true;
// Note that the connection isn't fully accepted at this point and won't be

View File

@ -336,6 +336,13 @@ END
#endif // German (Germany) resources
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
//
// Text
//
IDR_HGREVISION RCDATA "../../hgrevision"
#ifndef APSTUDIO_INVOKED

View File

@ -93,6 +93,7 @@
#define IDR_CONSOLEMENU 6000
#define IDR_CONTEXTMENUS 6001
#define IDM_FILE_RECORD 40041
#define IDR_HGREVISION 7000
// Next default values for new objects
//