Merge with feature-crashreport+develop

--HG--
branch : develop
hg/feature/cef3
kaetemi 10 years ago
commit 163abf31b8

@ -83,4 +83,3 @@ IF(WITH_NEL_TOOLS OR WITH_NEL_MAXPLUGIN)
ENDIF(WITH_NEL_TOOLS)
ADD_SUBDIRECTORY(tools)
ENDIF(WITH_NEL_TOOLS OR WITH_NEL_MAXPLUGIN)

@ -350,8 +350,10 @@ void setCrashAlreadyReported(bool state);
*/
// removed because we always check assert (even in release mode) #if defined (NL_OS_WINDOWS) && defined (NL_DEBUG)
#if defined (NL_OS_WINDOWS)
#define NLMISC_BREAKPOINT __debugbreak();
#if defined(NL_OS_WINDOWS)
#define NLMISC_BREAKPOINT __debugbreak()
#elif defined(NL_OS_UNIX) && defined(NL_COMP_GCC)
#define NLMISC_BREAKPOINT __builtin_trap()
#else
#define NLMISC_BREAKPOINT abort()
#endif

@ -21,25 +21,38 @@
namespace NLMISC {
/** Display a custom message box.
#if FINAL_VERSION
#define NL_REPORT_SYNCHRONOUS false
#define NL_REPORT_DEFAULT NLMISC::ReportAbort
#else
#define NL_REPORT_SYNCHRONOUS true
#define NL_REPORT_DEFAULT NLMISC::ReportBreak
#endif
enum TReportResult
{
// See also crash_report_widget.h EReturnValue
ReportAlwaysIgnore = 21,
ReportIgnore = 22,
ReportAbort = 23,
ReportBreak = 24
};
/** Display a crash report
*
* \param title set the title of the report. If empty, it'll display "NeL report".
* \param header message displayed before the edit text box. If empty, it displays the default message.
* \param body message displayed in the edit text box. This string will be sent by email.
* \param debugButton 0 for disabling it, 1 for enable with default behaviors (generate a breakpoint), 2 for enable with no behavior
* \param title set the title of the report. If empty, it'll display "NeL report"
* \param subject extended title of the report
* \param body message displayed in the edit text box. This string will be sent to the crash report tool
* \param attachment binary file to attach. This is a filename
* \param synchronous use system() and wait for the crash tool exit code, passes -dev flag; otherwise return defaultResult immediately
* \param sendReport hide 'dont send' button, or auto enable 'send report' checkbox
*
*
*
* \return the button clicked or error
* \return the button clicked or defaultResult
*/
TReportResult report(const std::string &title, const std::string &subject, const std::string &body, const std::string &attachment, bool synchronous, bool sendReport, TReportResult defaultResult);
enum TReportResult { ReportDebug, ReportIgnore, ReportQuit, ReportError };
TReportResult report (const std::string &title, const std::string &header, const std::string &subject, const std::string &body, bool enableCheckIgnore, uint debugButton, bool ignoreButton, sint quitButton, bool sendReportButton, bool &ignoreNextTime, const std::string &attachedFile = "");
/** call this in the main of your appli to enable email: setReportEmailFunction (sendEmail);
*/
void setReportEmailFunction (void *emailFunction);
/// Set the Url of the web service used to post crash reports to. String is copied
void setReportPostUrl(const char *postUrl);
} // NLMISC

@ -18,11 +18,16 @@
#include <stdlib.h>
// contains all debug features
#include "nel/misc/debug.h"
#include <nel/misc/debug.h>
#include <nel/misc/report.h>
using namespace NLMISC;
void repeatederror()
{
// hit always ignore to surpress this error for the duration of the program
nlassert(false && "hit always ignore");
}
int main (int /* argc */, char ** /* argv */)
int main(int /* argc */, char ** /* argv */)
{
// all debug functions have different behaviors in debug and in release mode.
// in general, in debug mode, all debug functions are active, they display
@ -36,20 +41,24 @@ int main (int /* argc */, char ** /* argv */)
// in release mode, this function does nothing by default. you have to add a displayer
// manually, or put true in the parameter to say to the function that you want it to
// add the default displayers
createDebug ();
NLMISC::createDebug();
// enable the crash report tool
NLMISC::INelContext::getInstance().setWindowedApplication(true);
NLMISC::setReportPostUrl("http://ryzomcore.org/crash_report/");
// display debug information, that will be skipped in release mode.
nldebug ("nldebug() %d", 1);
nldebug("nldebug() %d", 1);
// display the string
nlinfo ("nlinfo() %d", 2);
nlinfo("nlinfo() %d", 2);
// when something not normal, but that the program can manage, occurs, call nlwarning()
nlwarning ("nlwarning() %d", 3);
nlwarning("nlwarning() %d", 3);
// nlassert() is like assert but do more powerful things. in release mode, the test is
// not executed and nothing will happen. (Press F5 in Visual C++ to continue the execution)
nlassert (true == false);
nlassert(true == false);
// in a switch case or when you want that the program never executes a part of code, use stop.
// in release, nlstop does nothing. in debug mode,
@ -61,16 +70,20 @@ int main (int /* argc */, char ** /* argv */)
// occurs. (In Visual C++ press F5 to continue)
try
{
nlerror ("nlerror() %d", 4);
nlerror("nlerror() %d", 4);
}
catch(const EFatalError &)
catch (const NLMISC::EFatalError &)
{
// just continue...
nlinfo ("nlerror() generated an EFatalError exception, just ignore it");
nlinfo("nlerror() generated an EFatalError exception, just ignore it");
}
// keep repeating the same error
for (int i = 0; i < 32; ++i)
repeatederror();
printf("\nPress <return> to exit\n");
getchar ();
getchar();
return EXIT_SUCCESS;
}

@ -78,7 +78,8 @@ using namespace std;
#define LOG_IN_FILE NEL_LOG_IN_FILE
// If true, debug system will trap crash even if the application is in debugger
static const bool TrapCrashInDebugger = false;
//static const bool TrapCrashInDebugger = false;
static const bool TrapCrashInDebugger = true;
#ifdef DEBUG_NEW
#define new DEBUG_NEW
@ -547,8 +548,8 @@ public:
{
// yoyo: allow only to send the crash report once. Because users usually click ignore,
// which create noise into list of bugs (once a player crash, it will surely continues to do it).
bool i = false;
report (progname+shortExc, "", subject, _Reason, true, 1, true, 1, !isCrashAlreadyReported(), i, NL_CRASH_DUMP_FILE);
report(progname + shortExc, subject, _Reason, NL_CRASH_DUMP_FILE, true, !isCrashAlreadyReported(), ReportAbort);
// TODO: Does this need to be synchronous? Why does this not handle the report result?
// no more sent mail for crash
setCrashAlreadyReported(true);
@ -1191,10 +1192,10 @@ void createDebug (const char *logPath, bool logInFile, bool eraseLastLog)
#ifdef NL_OS_WINDOWS
if (TrapCrashInDebugger || !IsDebuggerPresent ())
#endif
{
DefaultMsgBoxDisplayer = new CMsgBoxDisplayer ("DEFAULT_MBD");
}
#endif
#if LOG_IN_FILE
if (logInFile)

@ -520,7 +520,7 @@ void CFileDisplayer::doDisplay ( const CLog::TDisplayInfo& args, const char *mes
// in release "<Msg>"
void CMsgBoxDisplayer::doDisplay ( const CLog::TDisplayInfo& args, const char *message)
{
#ifdef NL_OS_WINDOWS
//#ifdef NL_OS_WINDOWS
bool needSpace = false;
// stringstream ss;
@ -679,39 +679,35 @@ void CMsgBoxDisplayer::doDisplay ( const CLog::TDisplayInfo& args, const char *m
// yoyo: allow only to send the crash report once. Because users usually click ignore,
// which create noise into list of bugs (once a player crash, it will surely continues to do it).
std::string filename = getLogDirectory() + NL_CRASH_DUMP_FILE;
TReportResult reportResult = report(args.ProcessName + " NeL " + toString(logTypeToString(args.LogType, true)),
subject, body, filename, NL_REPORT_SYNCHRONOUS, !isCrashAlreadyReported(), NL_REPORT_DEFAULT);
if (ReportDebug == report (args.ProcessName + " NeL " + toString(logTypeToString(args.LogType, true)), "", subject, body, true, 2, true, 1, !isCrashAlreadyReported(), IgnoreNextTime, filename.c_str()))
switch (reportResult)
{
case ReportAlwaysIgnore:
IgnoreNextTime = true;
break;
case ReportBreak:
INelContext::getInstance().setDebugNeedAssert(true);
break;
case ReportAbort:
# ifdef NL_OS_WINDOWS
# ifndef NL_COMP_MINGW
// disable the Windows popup telling that the application aborted and disable the dr watson report.
_set_abort_behavior(0, _WRITE_ABORT_MSG | _CALL_REPORTFAULT);
# endif
# endif
abort();
break;
}
// no more sent mail for crash
setCrashAlreadyReported(true);
}
}
/* // Check the envvar NEL_IGNORE_ASSERT
if (getenv ("NEL_IGNORE_ASSERT") == NULL)
{
// Ask the user to continue, debug or ignore
int result = MessageBox (NULL, ss2.str().c_str (), logTypeToString(args.LogType, true), MB_ABORTRETRYIGNORE | MB_ICONSTOP);
if (result == IDABORT)
{
// Exit the program now
exit (EXIT_FAILURE);
}
else if (result == IDRETRY)
{
// Give the debugger a try
DebugNeedAssert = true;
}
else if (result == IDIGNORE)
{
// Continue, do nothing
}
}
*/ }
#endif
//#endif
}

@ -16,342 +16,206 @@
#include "stdmisc.h"
#include <stdlib.h>
#include <sstream>
#include "nel/misc/common.h"
#include "nel/misc/ucstring.h"
#include "nel/misc/report.h"
#include "nel/misc/path.h"
#ifdef NL_OS_WINDOWS
# include <windowsx.h>
# include <winuser.h>
#endif // NL_OS_WINDOWS
#define NL_NO_DEBUG_FILES 1
using namespace std;
#include "nel/misc/file.h"
#ifdef DEBUG_NEW
#define new DEBUG_NEW
#endif
#define NL_REPORT_POST_URL_ENVVAR "NL_REPORT_POST_URL"
#ifdef NL_OS_WINDOWS
#define NL_CRASH_REPORT_TOOL "crash_report.exe"
#else
#define NL_CRASH_REPORT_TOOL "crash_report"
#endif
#define NL_DEBUG_REPORT 0
// Set to 1 if you want command line report tool
#define NL_REPORT_CONSOLE 0
// Set to 1 if you want command line report tool even when the debugger is present
#define NL_REPORT_CONSOLE_DEBUGGER 1
namespace NLMISC
{
void setReportPostUrl(const char *postUrl)
{
#if NL_DEBUG_REPORT
if (INelContext::isContextInitialised())
nldebug("Set report post url to '%s'", postUrl);
#endif
#ifdef NL_OS_WINDOWS
static HWND sendReport=NULL;
SetEnvironmentVariableA(NL_REPORT_POST_URL_ENVVAR, postUrl);
#else
setenv(NL_REPORT_POST_URL_ENVVAR, postUrl, 1);
#endif
}
//old doesn't work on visual c++ 7.1 due to default parameter typedef bool (*TEmailFunction) (const std::string &smtpServer, const std::string &from, const std::string &to, const std::string &subject, const std::string &body, const std::string &attachedFile = "", bool onlyCheck = false);
typedef bool (*TEmailFunction) (const std::string &smtpServer, const std::string &from, const std::string &to, const std::string &subject, const std::string &body, const std::string &attachedFile, bool onlyCheck);
#define DELETE_OBJECT(a) if((a)!=NULL) { DeleteObject (a); a = NULL; }
static TEmailFunction EmailFunction = NULL;
void setReportEmailFunction (void *emailFunction)
inline const char *getReportPostURL()
{
EmailFunction = (TEmailFunction)emailFunction;
#ifdef NL_OS_WINDOWS
if (sendReport)
EnableWindow(sendReport, FALSE);
static char buf[512];
buf[0] = '\0';
int res = GetEnvironmentVariableA(NL_REPORT_POST_URL_ENVVAR, buf, sizeof(buf));
if (res <= 0 || res > 511) return NULL;
if (buf[0] == '\0') return NULL;
return buf;
#else
char *res = getenv(NL_REPORT_POST_URL_ENVVAR);
if (res == NULL || res[0] == '\0') return NULL;
return res;
#endif
}
#ifndef NL_OS_WINDOWS
TReportResult report(const std::string &title, const std::string &subject, const std::string &body, const std::string &attachment, bool synchronous, bool sendReport, TReportResult defaultResult)
{
std::string reportPath;
if (!body.empty())
{
std::stringstream reportFile;
reportFile << getLogDirectory();
reportFile << "nel_report_";
reportFile << (int)time(NULL);
reportFile << ".log";
reportPath = CFile::findNewFile(reportFile.str());
std::ofstream f;
f.open(reportPath.c_str());
if (!f.good())
{
#if NL_DEBUG_REPORT
if (INelContext::isContextInitialised())
nldebug("Failed to write report log to '%s'", reportPath.c_str());
#endif
reportPath.clear();
}
else
{
f << body;
f.close();
}
}
// GNU/Linux, do nothing
if (INelContext::isContextInitialised()
&& INelContext::getInstance().isWindowedApplication()
&& CFile::isExists(NL_CRASH_REPORT_TOOL))
{
std::stringstream params;
params << NL_CRASH_REPORT_TOOL;
void report ()
{
}
if (!reportPath.empty())
params << " -log \"" << reportPath << "\"";
#else
if (!subject.empty())
params << " -attachment \"" << attachment << "\"";
// Windows specific version
if (!title.empty())
params << " -title \"" << title << "\"";
static string Body;
static string Subject;
static string AttachedFile;
if (!subject.empty())
params << " -subject \"" << subject << "\"";
static HWND checkIgnore=NULL;
static HWND debug=NULL;
static HWND ignore=NULL;
static HWND quit=NULL;
static HWND dialog=NULL;
const char *reportPostUrl = getReportPostURL();
if (reportPostUrl)
params << " -host \"" << reportPostUrl << "\"";
static bool NeedExit;
static TReportResult Result;
static bool IgnoreNextTime;
static bool CanSendMailReport= false;
if (synchronous)
params << " -dev";
static bool DebugDefaultBehavior, QuitDefaultBehavior;
if (sendReport)
params << " -sendreport";
static void sendEmail()
{
if (CanSendMailReport && SendMessage(sendReport, BM_GETCHECK, 0, 0) != BST_CHECKED)
{
bool res = EmailFunction ("", "", "", Subject, Body, AttachedFile, false);
if (res)
std::string paramsStr = params.str();
if (synchronous)
{
// EnableWindow(sendReport, FALSE);
// MessageBox (dialog, "The email was successfully sent", "email", MB_OK);
#ifndef NL_NO_DEBUG_FILES
CFile::createEmptyFile(getLogDirectory() + "report_sent");
TReportResult result = (TReportResult)::system(paramsStr.c_str());
if (result != ReportAlwaysIgnore
&& result != ReportIgnore
&& result != ReportAbort
&& result != ReportBreak)
{
#if NL_DEBUG_REPORT
if (INelContext::isContextInitialised())
nldebug("Return default result, invalid return code %i", (int)result);
#endif
return defaultResult;
}
return result;
}
else
{
#ifndef NL_NO_DEBUG_FILES
CFile::createEmptyFile(getLogDirectory() + "report_failed");
#endif
// MessageBox (dialog, "Failed to send the email", "email", MB_OK | MB_ICONERROR);
NLMISC::launchProgram(NL_CRASH_REPORT_TOOL, paramsStr); // FIXME: Don't use this function, it uses logging, etc, so may loop infinitely!
return defaultResult;
}
}
else
{
#ifndef NL_NO_DEBUG_FILES
CFile::createEmptyFile(getLogDirectory() + "report_refused");
#if NL_DEBUG_REPORT
if (INelContext::isContextInitialised() && !CFile::isExists(NL_CRASH_REPORT_TOOL))
nldebug("Crash report tool '%s' does not exist", NL_CRASH_REPORT_TOOL);
#endif
}
}
static LRESULT CALLBACK WndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
//MSGFILTER *pmf;
if (message == WM_COMMAND && HIWORD(wParam) == BN_CLICKED)
{
if ((HWND) lParam == checkIgnore)
#if defined(NL_OS_WINDOWS) && !FINAL_VERSION && !NL_REPORT_CONSOLE_DEBUGGER
if (IsDebuggerPresent())
{
IgnoreNextTime = !IgnoreNextTime;
}
else if ((HWND) lParam == debug)
{
sendEmail();
NeedExit = true;
Result = ReportDebug;
if (DebugDefaultBehavior)
{
NLMISC_BREAKPOINT;
}
return defaultResult;
}
else if ((HWND) lParam == ignore)
{
sendEmail();
NeedExit = true;
Result = ReportIgnore;
}
else if ((HWND) lParam == quit)
{
sendEmail();
NeedExit = true;
Result = ReportQuit;
if (QuitDefaultBehavior)
{
// ace: we cannot call exit() because it's call the static object dtor and can crash the application
// if the dtor call order is not good.
//exit(EXIT_SUCCESS);
#ifdef NL_OS_WINDOWS
#ifndef NL_COMP_MINGW
// disable the Windows popup telling that the application aborted and disable the dr watson report.
_set_abort_behavior(0, _WRITE_ABORT_MSG | _CALL_REPORTFAULT);
#endif
else
#endif
// quit without calling atexit or static object dtors.
abort();
}
}
/*else if ((HWND) lParam == sendReport)
if (synchronous)
{
if (EmailFunction != NULL)
#if NL_REPORT_CONSOLE
// An interactive console based report
printf("\n");
if (!title.empty())
printf("%s\n", title.c_str());
else
printf("NeL report\n");
printf("\n");
if (!subject.empty())
printf("\tsubject: '%s'\n", subject.c_str());
if (!body.empty())
printf("\tbody: '%s'\n", reportPath.c_str());
if (!attachment.empty())
printf("\tattachment: '%s'\n", attachment.c_str());
for (;;)
{
bool res = EmailFunction ("", "", "", Subject, Body, AttachedFile, false);
if (res)
{
EnableWindow(sendReport, FALSE);
MessageBox (dialog, "The email was successfully sent", "email", MB_OK);
CFile::createEmptyFile(getLogDirectory() + "report_sent");
}
else
printf("\n");
printf("Always Ignore (S), Ignore (I), Abort (A), Break (B)?\n"); // S for Surpress
printf("> ");
int c = getchar();
getchar();
switch (c)
{
MessageBox (dialog, "Failed to send the email", "email", MB_OK | MB_ICONERROR);
case 'S':
case 's':
return ReportAlwaysIgnore;
case 'I':
case 'i':
return ReportIgnore;
case 'A':
case 'a':
return ReportAbort;
case 'B':
case 'b':
return ReportBreak;
}
}
}*/
}
else if (message == WM_CHAR)
{
if (wParam == 27)
{
// ESC -> ignore
sendEmail();
NeedExit = true;
Result = ReportIgnore;
}
}
return DefWindowProc (hWnd, message, wParam, lParam);
}
TReportResult report (const std::string &title, const std::string &header, const std::string &subject, const std::string &body, bool enableCheckIgnore, uint debugButton, bool ignoreButton, sint quitButton, bool sendReportButton, bool &ignoreNextTime, const string &attachedFile)
{
// register the window
static bool AlreadyRegister = false;
if(!AlreadyRegister)
{
WNDCLASSW wc;
memset (&wc,0,sizeof(wc));
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = (WNDPROC)WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = GetModuleHandle(NULL);
wc.hIcon = NULL;
wc.hCursor = LoadCursor(NULL,IDC_ARROW);
wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
wc.lpszClassName = L"NLReportWindow";
wc.lpszMenuName = NULL;
if (!RegisterClassW(&wc)) return ReportError;
AlreadyRegister = true;
}
ucstring formatedTitle = title.empty() ? ucstring("NeL report") : ucstring(title);
// create the window
dialog = CreateWindowW (L"NLReportWindow", (LPCWSTR)formatedTitle.c_str(), WS_DLGFRAME | WS_CAPTION /*| WS_THICKFRAME*/, CW_USEDEFAULT, CW_USEDEFAULT, 456, 400, NULL, NULL, GetModuleHandle(NULL), NULL);
// create the font
HFONT font = CreateFont (-12, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, "Arial");
Subject = subject;
AttachedFile = attachedFile;
// create the edit control
HWND edit = CreateWindowW (L"EDIT", NULL, WS_BORDER | WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL | ES_READONLY | ES_LEFT | ES_MULTILINE, 7, 70, 429, 212, dialog, (HMENU) NULL, (HINSTANCE) GetWindowLongPtr(dialog, GWLP_HINSTANCE), NULL);
SendMessage (edit, WM_SETFONT, (WPARAM) font, TRUE);
// set the edit text limit to lot of :)
SendMessage (edit, EM_LIMITTEXT, ~0U, 0);
Body = addSlashR (body);
// set the message in the edit text
SendMessage (edit, WM_SETTEXT, (WPARAM)0, (LPARAM)Body.c_str());
if (enableCheckIgnore)
{
// create the combo box control
checkIgnore = CreateWindowW (L"BUTTON", L"Don't display this report again", WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX | BS_CHECKBOX, 7, 290, 429, 18, dialog, (HMENU) NULL, (HINSTANCE) GetWindowLongPtr(dialog, GWLP_HINSTANCE), NULL);
SendMessage (checkIgnore, WM_SETFONT, (WPARAM) font, TRUE);
if(ignoreNextTime)
{
SendMessage (checkIgnore, BM_SETCHECK, BST_CHECKED, 0);
#else
return defaultResult;
#endif
}
}
// create the debug button control
debug = CreateWindowW (L"BUTTON", L"Debug", WS_CHILD | WS_VISIBLE, 7, 315, 75, 25, dialog, (HMENU) NULL, (HINSTANCE) GetWindowLongPtr(dialog, GWLP_HINSTANCE), NULL);
SendMessage (debug, WM_SETFONT, (WPARAM) font, TRUE);
if (debugButton == 0)
EnableWindow(debug, FALSE);
// create the ignore button control
ignore = CreateWindowW (L"BUTTON", L"Ignore", WS_CHILD | WS_VISIBLE, 75+7+7, 315, 75, 25, dialog, (HMENU) NULL, (HINSTANCE) GetWindowLongPtr(dialog, GWLP_HINSTANCE), NULL);
SendMessage (ignore, WM_SETFONT, (WPARAM) font, TRUE);
if (ignoreButton == 0)
EnableWindow(ignore, FALSE);
// create the quit button control
quit = CreateWindowW (L"BUTTON", L"Quit", WS_CHILD | WS_VISIBLE, 75+75+7+7+7, 315, 75, 25, dialog, (HMENU) NULL, (HINSTANCE) GetWindowLongPtr(dialog, GWLP_HINSTANCE), NULL);
SendMessage (quit, WM_SETFONT, (WPARAM) font, TRUE);
if (quitButton == 0)
EnableWindow(quit, FALSE);
// create the debug button control
sendReport = CreateWindowW (L"BUTTON", L"Don't send the report", WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX, 7, 315+32, 429, 18, dialog, (HMENU) NULL, (HINSTANCE) GetWindowLongPtr(dialog, GWLP_HINSTANCE), NULL);
SendMessage (sendReport, WM_SETFONT, (WPARAM) font, TRUE);
string formatedHeader;
if (header.empty())
{
formatedHeader = "This application stopped to display this report.";
}
else
{
formatedHeader = header;
}
// ace don't do that because it s slow to try to send a mail
//CanSendMailReport = sendReportButton && EmailFunction != NULL && EmailFunction("", "", "", "", "", true);
CanSendMailReport = sendReportButton && EmailFunction != NULL;
if (CanSendMailReport)
formatedHeader += " Send report will only email the contents of the box below. Please, send it to help us (it could take few minutes to send the email, be patient).";
else
EnableWindow(sendReport, FALSE);
ucstring uc = ucstring::makeFromUtf8(formatedHeader);
// create the label control
HWND label = CreateWindowW (L"STATIC", (LPCWSTR)uc.c_str(), WS_CHILD | WS_VISIBLE /*| SS_WHITERECT*/, 7, 7, 429, 51, dialog, (HMENU) NULL, (HINSTANCE) GetWindowLongPtr(dialog, GWLP_HINSTANCE), NULL);
SendMessage (label, WM_SETFONT, (WPARAM) font, TRUE);
DebugDefaultBehavior = debugButton==1;
QuitDefaultBehavior = quitButton==1;
IgnoreNextTime = ignoreNextTime;
// show until the cursor really show :)
while (ShowCursor(TRUE) < 0)
;
SetWindowPos (dialog, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
SetFocus(dialog);
SetForegroundWindow(dialog);
NeedExit = false;
while(!NeedExit)
{
MSG msg;
while (PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE))
else
{
TranslateMessage(&msg);
DispatchMessageW(&msg);
return defaultResult;
}
nlSleep (1);
}
// set the user result
ignoreNextTime = IgnoreNextTime;
ShowWindow(dialog, SW_HIDE);
DELETE_OBJECT(sendReport)
DELETE_OBJECT(quit)
DELETE_OBJECT(ignore)
DELETE_OBJECT(debug)
DELETE_OBJECT(checkIgnore)
DELETE_OBJECT(edit)
DELETE_OBJECT(label)
DELETE_OBJECT(dialog)
return Result;
}
#endif
} // NLMISC

@ -600,7 +600,7 @@ sint IService::main (const char *serviceShortName, const char *serviceLongName,
ListeningPort = servicePort;
setReportEmailFunction ((void*)sendEmail);
// setReportEmailFunction ((void*)sendEmail);
// setDefaultEmailParams ("gw.nevrax.com", "", "cado@nevrax.com");

@ -3,6 +3,7 @@ SUBDIRS(bnp_make disp_sheet_id extract_filename lock make_sheet_id xml_packer)
IF(WITH_QT)
ADD_SUBDIRECTORY(words_dic_qt)
ADD_SUBDIRECTORY(message_box_qt)
ADD_SUBDIRECTORY(crash_report)
ENDIF(WITH_QT)
IF(WIN32)

@ -0,0 +1,39 @@
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SRC_DIR} ${QT_INCLUDES})
FILE(GLOB CRASHREPORT_SRC *.cpp)
FILE(GLOB CRASHREPORT_HDR *h)
SET(CRASHREPORT_MOC_HDR
crash_report_socket.h
crash_report_widget.h
)
SET(CRASHREPORT_UI
crash_report_widget.ui
)
SET(QT_USE_QTGUI TRUE)
SET(QT_USE_QTNETWORK TRUE)
SET(QT_USE_QTMAIN TRUE)
SET(QT_USE_QTOPENGL FALSE)
SET(QT_USE_QTXML FALSE)
INCLUDE(${QT_USE_FILE})
ADD_DEFINITIONS(${QT_DEFINITIONS})
QT4_WRAP_CPP(CRASHREPORT_MOC_SRC ${CRASHREPORT_MOC_HDR})
QT4_WRAP_UI(CRASHREPORT_UI_HDR ${CRASHREPORT_UI})
SOURCE_GROUP(QtResources FILES ${CRASHREPORT_UI})
SOURCE_GROUP(QtGeneratedUiHdr FILES ${CRASHREPORT_UI_HDR})
SOURCE_GROUP(QtGeneratedMocQrcSrc FILES ${CRASHREPORT_MOC_SRC})
SOURCE_GROUP("source files" FILES ${CRASHREPORT_SRC})
SOURCE_GROUP("header files" FILES ${CRASHREPORT_HDR})
ADD_EXECUTABLE(crash_report WIN32 MACOSX_BUNDLE ${CRASHREPORT_SRC} ${CRASHREPORT_MOC_HDR} ${CRASHREPORT_MOC_SRC} ${CRASHREPORT_UI_HDR})
TARGET_LINK_LIBRARIES(crash_report ${QT_LIBRARIES} ${QT_QTMAIN_LIBRARY})
NL_DEFAULT_PROPS(crash_report "NeL, Tools, Misc: Crash Report")
NL_ADD_RUNTIME_FLAGS(crash_report)
INSTALL(TARGETS crash_report RUNTIME DESTINATION ${NL_BIN_PREFIX})

@ -0,0 +1,111 @@
// Nel MMORPG framework - Error Reporter
//
// Copyright (C) 2015 Laszlo Kis-Adam
// Copyright (C) 2010 Ryzom Core <http://ryzomcore.org/>
//
// 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 "crash_report_widget.h"
#include <QApplication>
#include <QMessageBox>
#include <stack>
#include <vector>
#include <string>
class CCmdLineParser
{
public:
static void parse( int argc, char **argv, std::vector< std::pair< std::string, std::string > > &v )
{
std::stack< std::string > stack;
std::string key;
std::string value;
for( int i = argc - 1 ; i >= 0; i-- )
{
stack.push( std::string( argv[ i ] ) );
}
while( !stack.empty() )
{
key = stack.top();
stack.pop();
// If not a real parameter ( they start with '-' ), discard.
if( key[ 0 ] != '-' )
continue;
// Remove the '-'
key = key.substr( 1 );
// No more parameters
if( stack.empty() )
{
v.push_back( std::make_pair( key, "" ) );
break;
}
value = stack.top();
// If next parameter is a key, process it in the next iteration
if( value[ 0 ] == '-' )
{
v.push_back( std::make_pair( key, "" ) );
continue;
}
// Otherwise store the pair
else
{
v.push_back( std::make_pair( key, value ) );
stack.pop();
}
}
}
};
int main( int argc, char **argv )
{
#ifndef WIN32
// Workaround to default -style=gtk+ on recent Cinnamon versions
char *currentDesktop = getenv("XDG_CURRENT_DESKTOP");
if (currentDesktop)
{
printf("XDG_CURRENT_DESKTOP: %s\n", currentDesktop);
if (!strcmp(currentDesktop, "X-Cinnamon"))
{
setenv("XDG_CURRENT_DESKTOP", "gnome", 1);
}
}
#endif
QApplication app( argc, argv );
std::vector< std::pair< std::string, std::string > > params;
CCmdLineParser::parse( argc, argv, params );
CCrashReportWidget w;
w.setup( params );
w.show();
int ret = app.exec();
if( ret != EXIT_SUCCESS )
return ret;
else
return w.getReturnValue();
}

@ -0,0 +1,33 @@
// Ryzom Core MMORPG framework - Error Reporter
//
// Copyright (C) 2015 Laszlo Kis-Adam
// Copyright (C) 2010 Ryzom Core <http://ryzomcore.org/>
//
// 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/>.
#ifndef RCERROR_DATA
#define RCERROR_DATA
#include <QString>
struct SCrashReportData
{
QString description;
QString report;
QString email;
};
#endif

@ -0,0 +1,78 @@
// Nel MMORPG framework - Error Reporter
//
// Copyright (C) 2015 Laszlo Kis-Adam
// Copyright (C) 2010 Ryzom Core <http://ryzomcore.org/>
//
// 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 "crash_report_socket.h"
#include <QNetworkAccessManager>
#include <QUrl>
#include <QNetworkRequest>
#include <QNetworkReply>
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
# include <QUrlQuery>
#endif
class CCrashReportSocketPvt
{
public:
QNetworkAccessManager mgr;
};
CCrashReportSocket::CCrashReportSocket( QObject *parent ) :
QObject( parent )
{
m_pvt = new CCrashReportSocketPvt();
connect( &m_pvt->mgr, SIGNAL( finished( QNetworkReply* ) ), this, SLOT( onFinished( QNetworkReply* ) ) );
}
CCrashReportSocket::~CCrashReportSocket()
{
delete m_pvt;
}
void CCrashReportSocket::sendReport( const SCrashReportData &data )
{
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
QUrlQuery params;
#else
QUrl params;
#endif
params.addQueryItem( "report", data.report );
params.addQueryItem( "descr", data.description );
params.addQueryItem("email", data.email);
QUrl url( m_url );
QNetworkRequest request( url );
request.setRawHeader( "Connection", "close" );
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
QByteArray postData = params.query(QUrl::FullyEncoded).toUtf8();
#else
QByteArray postData = params.encodedQuery();
#endif
m_pvt->mgr.post(request, postData);
}
void CCrashReportSocket::onFinished( QNetworkReply *reply )
{
if( reply->error() != QNetworkReply::NoError )
Q_EMIT reportFailed();
else
Q_EMIT reportSent();
}

@ -0,0 +1,55 @@
// Nel MMORPG framework - Error Reporter
//
// Copyright (C) 2015 Laszlo Kis-Adam
// Copyright (C) 2010 Ryzom Core <http://ryzomcore.org/>
//
// 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/>.
#ifndef RCERROR_SOCKET
#define RCERROR_SOCKET
#include <QObject>
#include "crash_report_data.h"
class CCrashReportSocketPvt;
class QNetworkReply;
class CCrashReportSocket : public QObject
{
Q_OBJECT
public:
CCrashReportSocket( QObject *parent );
~CCrashReportSocket();
void setURL( const char *URL ){ m_url = URL; }
QString url() const{ return m_url; }
void sendReport( const SCrashReportData &data );
Q_SIGNALS:
void reportSent();
void reportFailed();
private Q_SLOTS:
void onFinished( QNetworkReply *reply );
private:
CCrashReportSocketPvt *m_pvt;
QString m_url;
};
#endif

@ -0,0 +1,301 @@
// Nel MMORPG framework - Error Reporter
//
// Copyright (C) 2015 Laszlo Kis-Adam
// Copyright (C) 2010 Ryzom Core <http://ryzomcore.org/>
//
// 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 "crash_report_widget.h"
#include "crash_report_socket.h"
#include "crash_report_data.h"
#include <QTimer>
#include <QTextStream>
#include <QFile>
#include <QMessageBox>
#include <QFile>
#include <QPushButton>
#include <QHBoxLayout>
#include <QCheckBox>
CCrashReportWidget::CCrashReportWidget( QWidget *parent ) :
QWidget( parent )
{
m_developerMode = false;
m_forceSend = false;
m_devSendReport = false;
m_returnValue = ERET_NULL;
m_ui.setupUi( this );
m_socket = new CCrashReportSocket( this );
QTimer::singleShot( 1, this, SLOT( onLoad() ) );
connect( m_ui.emailCB, SIGNAL( stateChanged( int ) ), this, SLOT( onCBClicked() ) );
connect( m_socket, SIGNAL( reportSent() ), this, SLOT( onReportSent() ) );
connect( m_socket, SIGNAL( reportFailed() ), this, SLOT( onReportFailed() ) );
}
CCrashReportWidget::~CCrashReportWidget()
{
m_socket = NULL;
}
void CCrashReportWidget::setup( const std::vector< std::pair< std::string, std::string > > &params )
{
for( int i = 0; i < params.size(); i++ )
{
const std::pair< std::string, std::string > &p = params[ i ];
const std::string &k = p.first;
const std::string &v = p.second;
if( k == "log" )
{
m_fileName = v.c_str();
if( !QFile::exists( m_fileName ) )
m_fileName.clear();
}
else
if( k == "host" )
{
m_socket->setURL( v.c_str() );
}
else
if( k == "title" )
{
setWindowTitle( v.c_str() );
}
else
if( k == "dev" )
{
m_developerMode = true;
}
else
if( k == "sendreport" )
{
m_forceSend = true;
}
}
if( m_fileName.isEmpty() )
{
m_ui.reportLabel->hide();
m_ui.reportEdit->hide();
}
if( m_socket->url().isEmpty() || m_fileName.isEmpty() )
{
m_ui.descriptionEdit->hide();
m_ui.emailCB->hide();
m_ui.emailEdit->hide();
m_ui.descrLabel->hide();
}
QHBoxLayout *hbl = new QHBoxLayout( this );
if( m_developerMode )
{
if( !m_socket->url().isEmpty() && !m_fileName.isEmpty() )
{
m_ui.emailCB->setEnabled( false );
QCheckBox *cb = new QCheckBox( tr( "Send report" ), this );
m_ui.gridLayout->addWidget( cb, 4, 0, 1, 1 );
m_ui.gridLayout->addWidget( m_ui.emailCB, 5, 0, 1, 1 );
m_ui.gridLayout->addWidget( m_ui.emailEdit, 6, 0, 1, 1 );
connect(cb, SIGNAL(stateChanged(int)), this, SLOT(onSendCBClicked()));
if (m_forceSend)
cb->setChecked(true);
}
hbl->addStretch();
QPushButton *alwaysIgnoreButton = new QPushButton( tr( "Always Ignore" ), this );
QPushButton *ignoreButton = new QPushButton( tr( "Ignore" ), this );
QPushButton *abortButton = new QPushButton( tr( "Abort" ), this );
QPushButton *breakButton = new QPushButton(tr("Break"), this);
breakButton->setAutoDefault(true);
hbl->addWidget( alwaysIgnoreButton );
hbl->addWidget( ignoreButton );
hbl->addWidget( abortButton );
hbl->addWidget( breakButton );
m_ui.gridLayout->addLayout( hbl, 7, 0, 1, 3 );
connect( alwaysIgnoreButton, SIGNAL( clicked( bool ) ), this, SLOT( onAlwaysIgnoreClicked() ) );
connect( ignoreButton, SIGNAL( clicked( bool ) ), this, SLOT( onIgnoreClicked() ) );
connect( abortButton, SIGNAL( clicked( bool ) ), this, SLOT( onAbortClicked() ) );
connect( breakButton, SIGNAL( clicked( bool ) ), this, SLOT( onBreakClicked() ) );
}
else
{
hbl->addStretch();
// If -host is specified, offer the send function
if( !m_socket->url().isEmpty() && !m_fileName.isEmpty() )
{
if (!m_forceSend)
{
QPushButton *cancelButton = new QPushButton(tr("Don't send report"), this);
connect(cancelButton, SIGNAL(clicked(bool)), this, SLOT(onCancelClicked()));
hbl->addWidget(cancelButton);
}
QPushButton *sendButton = new QPushButton( tr( "Send report" ), this );
sendButton->setAutoDefault(true);
connect( sendButton, SIGNAL( clicked( bool ) ), this, SLOT( onSendClicked() ) );
hbl->addWidget( sendButton );
}
// Otherwise only offer exit
else
{
QPushButton *exitButton = new QPushButton( tr( "Exit" ), this );
connect( exitButton, SIGNAL( clicked( bool ) ), this, SLOT( onCancelClicked() ) );
hbl->addWidget(exitButton);
exitButton->setAutoDefault(true);
}
m_ui.gridLayout->addLayout( hbl, 6, 0, 1, 3 );
}
}
void CCrashReportWidget::onLoad()
{
if( m_fileName.isEmpty() )
return;
QFile f( m_fileName );
bool b = f.open( QFile::ReadOnly | QFile::Text );
if( !b )
{
m_fileName.clear();
return;
}
QTextStream ss( &f );
m_ui.reportEdit->setPlainText( ss.readAll() );
f.close();
}
void CCrashReportWidget::onSendClicked()
{
if( m_developerMode && !m_devSendReport )
{
close();
return;
}
if( m_socket->url().isEmpty() || m_fileName.isEmpty() )
{
close();
return;
}
QApplication::setOverrideCursor( Qt::WaitCursor );
SCrashReportData data;
data.description = m_ui.descriptionEdit->toPlainText();
data.report = m_ui.reportEdit->toPlainText();
if( m_ui.emailCB->isChecked() )
data.email = m_ui.emailEdit->text();
m_socket->sendReport( data );
}
void CCrashReportWidget::onCancelClicked()
{
removeAndQuit();
}
void CCrashReportWidget::onCBClicked()
{
m_ui.emailEdit->setEnabled( m_ui.emailCB->isChecked() );
}
void CCrashReportWidget::onSendCBClicked()
{
bool b = m_ui.emailCB->isEnabled();
if( b )
{
m_ui.emailCB->setChecked( false );
}
m_ui.emailCB->setEnabled( !b );
m_devSendReport = !m_devSendReport;
}
void CCrashReportWidget::onAlwaysIgnoreClicked()
{
m_returnValue = ERET_ALWAYS_IGNORE;
onSendClicked();
}
void CCrashReportWidget::onIgnoreClicked()
{
m_returnValue = ERET_IGNORE;
onSendClicked();
}
void CCrashReportWidget::onAbortClicked()
{
m_returnValue = ERET_ABORT;
onSendClicked();
}
void CCrashReportWidget::onBreakClicked()
{
m_returnValue = ERET_BREAK;
onSendClicked();
}
void CCrashReportWidget::onReportSent()
{
QApplication::setOverrideCursor( Qt::ArrowCursor );
QMessageBox::information( this,
tr( "Report sent" ),
tr( "The report has been sent." ) );
removeAndQuit();
}
void CCrashReportWidget::onReportFailed()
{
QApplication::setOverrideCursor( Qt::ArrowCursor );
QMessageBox::information( this,
tr( "Report failed" ),
tr( "Failed to send the report..." ) );
removeAndQuit();
}
void CCrashReportWidget::removeAndQuit()
{
if( !m_fileName.isEmpty() )
QFile::remove( m_fileName );
close();
}

@ -0,0 +1,82 @@
// Nel MMORPG framework - Error Reporter
//
// Copyright (C) 2015 Laszlo Kis-Adam
// Copyright (C) 2010 Ryzom Core <http://ryzomcore.org/>
//
// 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/>.
#ifndef RCERROR_WIDGET
#define RCERROR_WIDGET
#include "ui_crash_report_widget.h"
#include <vector>
#include <string>
class CCrashReportSocket;
class CCrashReportWidget : public QWidget
{
Q_OBJECT
public:
enum EReturnValue
{
ERET_NULL = 0,
ERET_ALWAYS_IGNORE = 21,
ERET_IGNORE = 22,
ERET_ABORT = 23,
ERET_BREAK = 24
};
CCrashReportWidget( QWidget *parent = NULL );
~CCrashReportWidget();
void setFileName( const char *fn ){ m_fileName = fn; }
void setup( const std::vector< std::pair< std::string, std::string > > &params );
EReturnValue getReturnValue() const{ return m_returnValue; }
private Q_SLOTS:
void onLoad();
void onSendClicked();
void onCancelClicked();
void onCBClicked();
void onSendCBClicked();
void onAlwaysIgnoreClicked();
void onIgnoreClicked();
void onAbortClicked();
void onBreakClicked();
void onReportSent();
void onReportFailed();
private:
void removeAndQuit();
Ui::CrashReportWidget m_ui;
QString m_fileName;
CCrashReportSocket *m_socket;
bool m_developerMode;
bool m_forceSend;
bool m_devSendReport;
EReturnValue m_returnValue;
};
#endif

@ -0,0 +1,68 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CrashReportWidget</class>
<widget class="QWidget" name="CrashReportWidget">
<property name="windowModality">
<enum>Qt::ApplicationModal</enum>
</property>
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>406</width>
<height>430</height>
</rect>
</property>
<property name="windowTitle">
<string>NeL report</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0" colspan="2">
<widget class="QLabel" name="descrLabel">
<property name="text">
<string>What were you doing when the crash occured?</string>
</property>
</widget>
</item>
<item row="2" column="0" colspan="2">
<widget class="QLabel" name="reportLabel">
<property name="text">
<string>Contents of the report ( automatically generated )</string>
</property>
</widget>
</item>
<item row="1" column="0" colspan="3">
<widget class="QPlainTextEdit" name="descriptionEdit"/>
</item>
<item row="4" column="0" colspan="3">
<widget class="QCheckBox" name="emailCB">
<property name="text">
<string>Email me if you have further questions, or updates on this issue</string>
</property>
</widget>
</item>
<item row="5" column="0" colspan="3">
<widget class="QLineEdit" name="emailEdit">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Enter your email address here</string>
</property>
</widget>
</item>
<item row="3" column="0" colspan="3">
<widget class="QPlainTextEdit" name="reportEdit">
<property name="enabled">
<bool>true</bool>
</property>
<property name="textInteractionFlags">
<set>Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

@ -103,7 +103,6 @@ extern uint32 Version; // Client Version.
extern UDriver *Driver;
extern UTextContext *TextContext;
extern bool game_exit;
extern CMsgBoxDisplayer MsgBoxError;
extern CSoundManager *SoundMngr;

@ -142,7 +142,6 @@ using namespace std;
// Ligo primitive class
CLigoConfig LigoConfig;
CMsgBoxDisplayer MsgBoxError;
CClientChatManager ChatMngr;
bool LastScreenSaverEnabled = false;

@ -0,0 +1,30 @@
<?php
// Ryzom Core MMORPG framework - Error Reporter
//
// Copyright (C) 2015 Laszlo Kis-Adam
// Copyright (C) 2010 Ryzom Core <http://ryzomcore.org/>
//
// 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/>.
class BugReportConfig
{
static public $dbhost = "localhost";
static public $dbport = "3306";
static public $dbdb = "bugs";
static public $dbuser = "bugs";
static public $dbpw = "bugs";
}
?>

@ -0,0 +1,45 @@
<?php
// Ryzom Core MMORPG framework - Error Reporter
//
// Copyright (C) 2015 Laszlo Kis-Adam
// Copyright (C) 2010 Ryzom Core <http://ryzomcore.org/>
//
// 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/>.
/// Simple file logger class
class Logger
{
private $lf = NULL;
function __construct()
{
$this->lf = fopen( 'log.txt', 'a' );
if( $this->lf === FALSE )
exit( 1 );
}
function __destruct()
{
fclose( $this->lf );
}
public function log( $msg )
{
$date = date( "[M d, Y H:i:s] " );
fwrite( $this->lf, $date . $msg . "\n" );
}
}
?>

@ -0,0 +1,112 @@
<?php
// Ryzom Core MMORPG framework - Error Reporter
//
// Copyright (C) 2015 Laszlo Kis-Adam
// Copyright (C) 2010 Ryzom Core <http://ryzomcore.org/>
//
// 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/>.
require_once( 'config.inc.php' );
require_once( 'log.inc.php' );
/// Example web application that takes bug reports from the bug reporter Qt app
class BugReportGatherApp
{
private $db = NULL;
private $logger = NULL;
function __construct()
{
$this->logger = new Logger();
}
private function logPOSTVars()
{
$report = "";
$descr = "";
$email = "";
if( isset( $_POST[ 'report' ] ) )
$report = $_POST[ 'report' ];
if( isset( $_POST[ 'descr' ] ) )
$descr = $_POST[ 'descr' ];
if( isset( $_POST[ 'email' ] ) )
$email = $_POST[ 'email' ];
$this->logger->log( 'report: ' . "\n" . $report );
$this->logger->log( 'description: ' . "\n" . $descr );
$this->logger->log( 'email: ' . "\n" . $email );
}
private function buildQuery()
{
$report = "";
$descr = "";
$email = "";
if( isset( $_POST[ 'report' ] ) )
$report = $_POST[ 'report' ];
if( isset( $_POST[ 'descr' ] ) )
$descr = $_POST[ 'descr' ];
if( isset( $_POST[ 'email' ] ) )
$email = $_POST[ 'email' ];
$report = $this->db->real_escape_string( $report );
$descr = $this->db->real_escape_string( $descr );
$email = $this->db->real_escape_string( $email );
$q = "INSERT INTO `bugs` (`report`,`description`,`email`) VALUES (";
$q .= "'$report',";
$q .= "'$descr',";
$q .= "'$email')";
return $q;
}
public function exec()
{
//$this->logPOSTVars();
$this->db = new mysqli( BugReportConfig::$dbhost, BugReportConfig::$dbuser, BugReportConfig::$dbpw, BugReportConfig::$dbdb, BugReportConfig::$dbport );
if( mysqli_connect_error() )
{
$this->logger->log( "Connection error :(" );
$this->logger->log( mysqli_connect_error() );
return;
}
$q = $this->buildQuery();
$result = $this->db->query( $q );
if( $result !== TRUE )
{
$this->logger->log( "Query failed :(" );
$this->logger->log( 'Query: ' . $q );
$this->logPOSTVars();
}
$this->db->close();
}
}
$app = new BugReportGatherApp();
$app->exec();
?>
Loading…
Cancel
Save