2012-05-29 13:31:11 +00:00
|
|
|
// Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
|
|
|
|
// Copyright (C) 2010 Winch Gate Property Limited
|
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as
|
|
|
|
// published by the Free Software Foundation, either version 3 of the
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "stdpch.h"
|
|
|
|
|
|
|
|
//////////////
|
|
|
|
// INCLUDES //
|
|
|
|
//////////////
|
|
|
|
// Misc.
|
|
|
|
#include "nel/misc/types_nl.h"
|
|
|
|
|
|
|
|
#ifdef NL_OS_WINDOWS
|
|
|
|
#include <shellapi.h>
|
|
|
|
#else
|
|
|
|
#include <csignal>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef NL_OS_MAC
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <sys/resource.h>
|
|
|
|
#include "nel/misc/dynloadlib.h"
|
|
|
|
#include "app_bundle_utils.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "nel/misc/debug.h"
|
|
|
|
#include "nel/misc/command.h"
|
|
|
|
#include "nel/net/tcp_sock.h"
|
2016-01-23 17:57:32 +00:00
|
|
|
#include "nel/misc/cmd_args.h"
|
2012-05-29 13:31:11 +00:00
|
|
|
|
|
|
|
//#define TEST_CRASH_COUNTER
|
|
|
|
#ifdef TEST_CRASH_COUNTER
|
|
|
|
#undef FINAL_VERSION
|
|
|
|
#define FINAL_VERSION 1
|
|
|
|
#endif // TEST_CRASH_COUNTER
|
|
|
|
|
|
|
|
// Client
|
|
|
|
#include "resource.h"
|
|
|
|
#include "init.h"
|
|
|
|
#include "login.h"
|
|
|
|
#include "login_patch.h"
|
|
|
|
#include "connection.h"
|
|
|
|
#include "init_main_loop.h"
|
|
|
|
#include "main_loop.h"
|
|
|
|
#include "release.h"
|
|
|
|
#include "client_cfg.h"
|
|
|
|
#include "far_tp.h"
|
2016-02-15 11:07:49 +00:00
|
|
|
#include "user_agent.h"
|
2012-05-29 13:31:11 +00:00
|
|
|
|
|
|
|
///////////
|
|
|
|
// USING //
|
|
|
|
///////////
|
|
|
|
using namespace std;
|
|
|
|
using namespace NLMISC;
|
|
|
|
using namespace NLNET;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Macros
|
|
|
|
//
|
|
|
|
|
|
|
|
//
|
|
|
|
// RYZOM_TRY and RYZOM_CATCH aim is to catch differently in dev and final version
|
|
|
|
// In final version, we catch everything and nlerror the problem to display a NeL message box
|
|
|
|
// In dev version, we just catch EFatalError() and we leave the OS to catch the exception to enable us to cancel/debug it
|
|
|
|
//
|
|
|
|
|
|
|
|
// We don't catch(...) because these exception are already trapped with the se_translation that generate the NeL message box
|
|
|
|
|
|
|
|
#define RYZOM_TRY(_block) try { nlinfo(_block" of Ryzom...");
|
|
|
|
#define RYZOM_CATCH(_block) nlinfo(_block" of Ryzom success"); } catch(const EFatalError &) { return EXIT_FAILURE; }
|
|
|
|
|
|
|
|
/////////////
|
|
|
|
// GLOBALS //
|
|
|
|
/////////////
|
|
|
|
static uint32 Version = 1; // Client Version.
|
|
|
|
|
|
|
|
string Cookie;
|
|
|
|
string FSAddr;
|
|
|
|
|
|
|
|
|
|
|
|
///////////////
|
|
|
|
// FUNCTIONS //
|
|
|
|
///////////////
|
|
|
|
|
|
|
|
static CTcpSock CrashCounterSock;
|
|
|
|
|
|
|
|
void quitCrashReport ()
|
|
|
|
{
|
2012-12-01 11:00:46 +00:00
|
|
|
//if (NLMISC::CFile::fileExists(getLogDirectory() + "ryzom_started"))
|
|
|
|
//CFile::deleteFile (getLogDirectory() + "ryzom_started");
|
2012-05-29 13:31:11 +00:00
|
|
|
// must disconnect now, else could crash at dtor time because nldebug -> access a new INelContext()
|
|
|
|
contReset(CrashCounterSock);
|
|
|
|
}
|
|
|
|
|
2016-01-23 19:32:37 +00:00
|
|
|
// make it global if other classes/functions want to access to it
|
|
|
|
NLMISC::CCmdArgs Args;
|
|
|
|
|
2012-05-29 13:31:11 +00:00
|
|
|
//---------------------------------------------------
|
|
|
|
// MAIN :
|
|
|
|
// Entry for the Application.
|
|
|
|
//---------------------------------------------------
|
|
|
|
#ifdef NL_OS_WINDOWS
|
|
|
|
|
2015-11-09 08:55:38 +00:00
|
|
|
// enable optimus for NVIDIA cards
|
|
|
|
extern "C"
|
|
|
|
{
|
|
|
|
_declspec(dllexport) DWORD NvOptimusEnablement = 0x00000001;
|
|
|
|
}
|
|
|
|
|
2012-05-29 13:31:11 +00:00
|
|
|
void pump ()
|
|
|
|
{
|
|
|
|
// Display the window
|
|
|
|
MSG msg;
|
|
|
|
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
|
|
|
|
{
|
|
|
|
TranslateMessage(&msg);
|
|
|
|
DispatchMessage(&msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
INT_PTR CALLBACK MyDialogProc(
|
|
|
|
HWND hwndDlg, // handle to dialog box
|
|
|
|
UINT uMsg, // message
|
|
|
|
WPARAM wParam, // first message parameter
|
|
|
|
LPARAM lParam // second message parameter
|
|
|
|
)
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
HWND SlashScreen = NULL;
|
|
|
|
HINSTANCE HInstance;
|
|
|
|
|
|
|
|
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE /* hPrevInstance */, LPSTR cmdline, int /* nCmdShow */)
|
|
|
|
#else
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
// init the Nel context
|
|
|
|
CApplicationContext *appContext = new CApplicationContext;
|
|
|
|
|
2015-11-09 11:46:02 +00:00
|
|
|
// disable nldebug messages in logs in Release
|
|
|
|
#ifdef NL_RELEASE
|
|
|
|
DisableNLDebug = true;
|
|
|
|
#endif
|
|
|
|
|
2015-12-28 17:12:45 +00:00
|
|
|
// don't create log.log anymore because client.log is used
|
|
|
|
createDebug(NULL, false);
|
2012-05-29 13:31:11 +00:00
|
|
|
|
2015-02-24 16:17:45 +00:00
|
|
|
INelContext::getInstance().setWindowedApplication(true);
|
|
|
|
|
2012-05-29 13:31:11 +00:00
|
|
|
#ifndef NL_DEBUG
|
|
|
|
INelContext::getInstance().getDebugLog()->removeDisplayer("DEFAULT_SD");
|
|
|
|
INelContext::getInstance().getInfoLog()->removeDisplayer("DEFAULT_SD");
|
|
|
|
INelContext::getInstance().getWarningLog()->removeDisplayer("DEFAULT_SD");
|
|
|
|
#endif // NL_DEBUG
|
|
|
|
|
2016-01-23 17:57:32 +00:00
|
|
|
Args.setVersion(getDisplayVersion());
|
|
|
|
Args.setDescription("Ryzom client");
|
|
|
|
Args.addArg("c", "config", "id", "Use this configuration to determine what directory to use by default");
|
|
|
|
Args.addAdditionalArg("login", "Login to use", true, false);
|
|
|
|
Args.addAdditionalArg("password", "Password to use", true, false);
|
|
|
|
Args.addAdditionalArg("shard_id", "Shard ID to use", true, false);
|
|
|
|
|
2016-02-15 11:07:49 +00:00
|
|
|
#ifdef TEST_CRASH_COUNTER
|
|
|
|
Args.addArg("", "crash", "", "Crash client before init");
|
|
|
|
Args.addArg("", "break", "", "Create a break point");
|
|
|
|
Args.addArg("", "release", "", "Crash client after init");
|
|
|
|
#endif // TEST_CRASH_COUNTER
|
|
|
|
|
2016-01-23 17:57:32 +00:00
|
|
|
#ifdef NL_OS_WINDOWS
|
|
|
|
if (!Args.parse(cmdline)) return 1;
|
|
|
|
#else
|
|
|
|
if (!Args.parse(argc, argv)) return 1;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// extract the 2 or 3 first param (argv[1], argv[2] and argv[3]) it must be <login> <password> [shardId]
|
|
|
|
|
|
|
|
// no shard id in ring mode
|
|
|
|
std::string sLoginShardId;
|
|
|
|
|
|
|
|
if (Args.haveAdditionalArg("login") && Args.haveAdditionalArg("password"))
|
|
|
|
{
|
|
|
|
LoginLogin = Args.getAdditionalArg("login").front();
|
|
|
|
LoginPassword = Args.getAdditionalArg("password").front();
|
|
|
|
|
|
|
|
if (Args.haveAdditionalArg("shard_id"))
|
|
|
|
sLoginShardId = Args.getAdditionalArg("shard_id").front();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sLoginShardId.empty() || !fromString(sLoginShardId, LoginShardId))
|
|
|
|
LoginShardId = std::numeric_limits<uint32>::max();
|
|
|
|
|
2012-05-29 13:31:11 +00:00
|
|
|
// if client_default.cfg is not in current directory, use application default directory
|
2016-02-13 22:36:22 +00:00
|
|
|
if (Args.haveArg("c") || !CFile::isExists("client_default.cfg"))
|
2012-05-29 13:31:11 +00:00
|
|
|
{
|
|
|
|
std::string currentPath = CPath::getApplicationDirectory("Ryzom");
|
|
|
|
|
2016-01-23 17:58:58 +00:00
|
|
|
// append config ID to directory
|
|
|
|
if (Args.haveArg("c"))
|
|
|
|
currentPath = NLMISC::CPath::standardizePath(currentPath) + Args.getArg("c").front();
|
|
|
|
|
2012-05-29 13:31:11 +00:00
|
|
|
if (!CFile::isExists(currentPath)) CFile::createDirectory(currentPath);
|
|
|
|
|
|
|
|
CPath::setCurrentPath(currentPath);
|
|
|
|
}
|
|
|
|
|
2016-02-15 11:07:49 +00:00
|
|
|
#ifdef TEST_CRASH_COUNTER
|
|
|
|
if (Args.haveLongArg("crash"))
|
|
|
|
{
|
|
|
|
volatile int toto = *(int*)0;
|
|
|
|
}
|
|
|
|
#endif // TEST_CRASH_COUNTER
|
|
|
|
|
2012-05-29 13:31:11 +00:00
|
|
|
#ifdef NL_OS_MAC
|
|
|
|
struct rlimit rlp, rlp2, rlp3;
|
|
|
|
|
|
|
|
getrlimit(RLIMIT_NOFILE, &rlp);
|
|
|
|
|
|
|
|
rlp2.rlim_cur = 1024;
|
|
|
|
rlp2.rlim_max = rlp.rlim_max;
|
|
|
|
setrlimit(RLIMIT_NOFILE, &rlp2);
|
|
|
|
|
|
|
|
getrlimit(RLIMIT_NOFILE, &rlp3);
|
|
|
|
nlinfo("rlimit before %d %d\n", rlp.rlim_cur, rlp.rlim_max);
|
|
|
|
nlinfo("rlimit after %d %d\n", rlp3.rlim_cur, rlp3.rlim_max);
|
|
|
|
|
|
|
|
// add the bundle's plugins path as library search path (for nel drivers)
|
|
|
|
CLibrary::addLibPath(getAppBundlePath() + "/Contents/PlugIns/nel/");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(NL_OS_WINDOWS)
|
|
|
|
|
|
|
|
#ifdef TEST_CRASH_COUNTER
|
2016-02-15 11:07:49 +00:00
|
|
|
if (Args.haveLongArg("break"))
|
2015-11-08 12:25:36 +00:00
|
|
|
{
|
|
|
|
__debugbreak();
|
|
|
|
}
|
2012-05-29 13:31:11 +00:00
|
|
|
#endif // TEST_CRASH_COUNTER
|
|
|
|
|
|
|
|
HInstance = hInstance;
|
|
|
|
|
|
|
|
// Get the bitmap size
|
|
|
|
HRSRC hrsrc = FindResource(HInstance, MAKEINTRESOURCE(IDB_SLASH_SCREEN), RT_BITMAP);
|
|
|
|
nlassert (hrsrc);
|
|
|
|
HGLOBAL hBitmap = LoadResource (HInstance, hrsrc);
|
|
|
|
nlassert (hBitmap);
|
|
|
|
BITMAP *bitmap = (BITMAP*)LockResource(hBitmap);
|
|
|
|
nlassert (bitmap);
|
|
|
|
int width = bitmap->bmWidth;
|
|
|
|
int height = bitmap->bmHeight;
|
|
|
|
|
|
|
|
// Look the command line to see if we have a cookie and a addr
|
|
|
|
SlashScreen = CreateDialog (hInstance, MAKEINTRESOURCE(IDD_SLASH_SCREEN), NULL, MyDialogProc);
|
|
|
|
RECT rect;
|
|
|
|
RECT rectDesktop;
|
|
|
|
GetWindowRect (SlashScreen, &rect);
|
|
|
|
GetWindowRect (GetDesktopWindow (), &rectDesktop);
|
|
|
|
SetWindowPos (SlashScreen, HWND_TOP, (rectDesktop.right-rectDesktop.left-width)/2, (rectDesktop.bottom-rectDesktop.top-height)/2, width, height, 0);
|
|
|
|
ShowWindow (SlashScreen, SW_SHOW);
|
|
|
|
|
|
|
|
pump ();
|
|
|
|
|
|
|
|
// Delete the .bat file because it s not useful anymore
|
|
|
|
if (NLMISC::CFile::fileExists("updt_nl.bat"))
|
|
|
|
NLMISC::CFile::deleteFile("updt_nl.bat");
|
|
|
|
if (NLMISC::CFile::fileExists("bug_report.exe"))
|
|
|
|
NLMISC::CFile::deleteFile("bug_report.exe");
|
|
|
|
if (NLMISC::CFile::fileExists("bug_report_r.exe"))
|
|
|
|
NLMISC::CFile::deleteFile("bug_report_r.exe");
|
|
|
|
if (NLMISC::CFile::fileExists("bug_report_rd.exe"))
|
|
|
|
NLMISC::CFile::deleteFile("bug_report_rd.exe");
|
|
|
|
if (NLMISC::CFile::fileExists("bug_report_df.exe"))
|
|
|
|
NLMISC::CFile::deleteFile("bug_report_df.exe");
|
|
|
|
if (NLMISC::CFile::fileExists("bug_report_d.exe"))
|
|
|
|
NLMISC::CFile::deleteFile("bug_report_d.exe");
|
|
|
|
|
|
|
|
// Delete all the .ttf file in the /data directory
|
|
|
|
{
|
|
|
|
vector<string> files;
|
|
|
|
NLMISC::CPath::getPathContent ("data", false, false, true, files, NULL, true);
|
|
|
|
uint i;
|
|
|
|
for (i=0; i<files.size(); i++)
|
|
|
|
{
|
2015-11-13 15:22:49 +00:00
|
|
|
if (toLower(CFile::getExtension (files[i])) == "ttf")
|
2012-05-29 13:31:11 +00:00
|
|
|
CFile::deleteFile (files[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
// TODO for Linux : splashscreen
|
|
|
|
|
2014-03-23 19:26:29 +00:00
|
|
|
// Delete the .sh file because it s not useful anymore
|
|
|
|
if (NLMISC::CFile::fileExists("updt_nl.sh"))
|
|
|
|
NLMISC::CFile::deleteFile("updt_nl.sh");
|
2012-05-29 13:31:11 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// initialize patch manager and set the ryzom full path, before it's used
|
|
|
|
CPatchManager *pPM = CPatchManager::getInstance();
|
2016-01-23 17:57:32 +00:00
|
|
|
pPM->setRyzomFilename(Args.getProgramPath() + Args.getProgramName());
|
2012-05-29 13:31:11 +00:00
|
|
|
|
|
|
|
/////////////////////////////////
|
|
|
|
// Initialize the application. //
|
|
|
|
#ifndef TEST_CRASH_COUNTER
|
|
|
|
RYZOM_TRY("Pre-Login Init")
|
|
|
|
prelogInit();
|
|
|
|
RYZOM_CATCH("Pre-Login Init")
|
|
|
|
|
|
|
|
// Log the client and choose from shard
|
|
|
|
RYZOM_TRY("Login")
|
|
|
|
if (!ClientCfg.Local && (ClientCfg.TestBrowser || ClientCfg.FSHost.empty()))
|
|
|
|
{
|
|
|
|
if (login() == false)
|
|
|
|
{
|
|
|
|
quitCrashReport ();
|
|
|
|
|
|
|
|
#if !FINAL_VERSION
|
|
|
|
// display the file access logger stats and clear out memory allocated for the file access logger
|
|
|
|
//ICommand::execute("iFileAccessLogDisplay",*NLMISC::InfoLog);
|
|
|
|
//ICommand::execute("iFileAccessLogStop",*NLMISC::InfoLog);
|
|
|
|
//ICommand::execute("iFileAccessLogClear",*NLMISC::InfoLog);
|
|
|
|
#endif
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
RYZOM_CATCH("Login")
|
|
|
|
|
|
|
|
// Finish inits
|
|
|
|
RYZOM_TRY("Post-Login Init")
|
|
|
|
postlogInit();
|
|
|
|
RYZOM_CATCH("Post-Login Init")
|
|
|
|
#endif // TEST_CRASH_COUNTER
|
|
|
|
|
|
|
|
//////////////////////////////////////////
|
|
|
|
// The real main loop
|
|
|
|
//////////////////////////////////////////
|
|
|
|
#ifdef TEST_CRASH_COUNTER
|
|
|
|
bool ok = false;
|
|
|
|
#else // TEST_CRASH_COUNTER
|
|
|
|
bool ok = true;
|
|
|
|
#endif // TEST_CRASH_COUNTER
|
|
|
|
while(ok)
|
|
|
|
{
|
|
|
|
// hulud : memory snapshot to track reconnection memory leak
|
|
|
|
/* static int pass = 0;
|
|
|
|
string filename = "z_mem_connection_" + toString (pass++) + ".csv";
|
|
|
|
nlverify (NLMEMORY::StatisticsReport (filename.c_str(), true)); */
|
|
|
|
|
|
|
|
//////////////////////////////////////////
|
|
|
|
// Manage the connection to the server. //
|
|
|
|
RYZOM_TRY("Connection")
|
|
|
|
// If the connection return false we just want to quit the game
|
|
|
|
if(!connection(Cookie, FSAddr))
|
|
|
|
{
|
|
|
|
releaseOutGame();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
RYZOM_CATCH("Connection")
|
|
|
|
|
|
|
|
///////////////////////////////
|
|
|
|
// Initialize the main loop. //
|
|
|
|
RYZOM_TRY("Main loop initialisation")
|
|
|
|
initMainLoop();
|
|
|
|
RYZOM_CATCH("Main loop initialisation")
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////
|
|
|
|
// Main loop (biggest part of the application). //
|
|
|
|
RYZOM_TRY("Main loop")
|
|
|
|
ok = !mainLoop();
|
|
|
|
RYZOM_CATCH("Main loop")
|
|
|
|
|
|
|
|
/////////////////////////////
|
|
|
|
// Release all the memory. //
|
|
|
|
if (!FarTP.isReselectingChar())
|
|
|
|
{
|
|
|
|
RYZOM_TRY("Main loop releasing")
|
|
|
|
releaseMainLoop(!ok);
|
|
|
|
RYZOM_CATCH("Main loop releasing")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Offline client quit now
|
|
|
|
if(ClientCfg.Local)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if !FINAL_VERSION
|
|
|
|
// display the file access logger stats and clear out memory allocated for the file access logger
|
|
|
|
//ICommand::execute("iFileAccessLogDisplay",*NLMISC::InfoLog);
|
|
|
|
//ICommand::execute("iFileAccessLogStop",*NLMISC::InfoLog);
|
|
|
|
//ICommand::execute("iFileAccessLogClear",*NLMISC::InfoLog);
|
|
|
|
#endif
|
|
|
|
|
2012-12-01 11:00:46 +00:00
|
|
|
//CFile::createEmptyFile(getLogDirectory() + "during_release");
|
2012-05-29 13:31:11 +00:00
|
|
|
|
|
|
|
#ifdef TEST_CRASH_COUNTER
|
2016-02-15 11:07:49 +00:00
|
|
|
if (Args.haveLongArg("release"))
|
|
|
|
{
|
2012-05-29 13:31:11 +00:00
|
|
|
volatile int toto = *(int*)0;
|
2016-02-15 11:07:49 +00:00
|
|
|
}
|
2012-05-29 13:31:11 +00:00
|
|
|
#endif // TEST_CRASH_COUNTER
|
|
|
|
|
|
|
|
// Final release
|
|
|
|
RYZOM_TRY("Releasing")
|
|
|
|
release();
|
|
|
|
RYZOM_CATCH("Releasing")
|
|
|
|
|
|
|
|
#if FINAL_VERSION || defined (TEST_CRASH_COUNTER)
|
|
|
|
quitCrashReport ();
|
|
|
|
#endif // FINAL_VERSION
|
|
|
|
|
|
|
|
// delete the Nel context
|
|
|
|
delete appContext;
|
|
|
|
|
|
|
|
#ifdef NL_OS_WINDOWS
|
|
|
|
/// always do a sanity check for early (in the sense of production days) memory coruption detection
|
|
|
|
// _CrtCheckMemory();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// EXIT of the Application.
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
|
|
|
|
} // main/WinMain
|