1717use Slim \Exception \HttpBadRequestException ;
1818use Slim \Exception \HttpNotFoundException ;
1919
20- class ModerateCrashReportController {
20+ class ModerateCrashReportController
21+ {
2122
2223 public function listIndex (
2324 Request $ request ,
2425 Response $ response ,
2526 TwigEnvironment $ twig ,
2627 EntityManager $ em
27- ){
28+ ) {
2829 $ response ->getBody ()->write (
2930 $ twig ->render ('devcp/crash-report/crash-report.list.devcp.html.twig ' , [
30- 'crash_reports ' => $ em ->getRepository (CrashReport::class)->findBy ([],['id ' => 'DESC ' ])
31+ 'crash_reports ' => $ em ->getRepository (CrashReport::class)->findBy ([], ['id ' => 'DESC ' ])
3132 ])
3233 );
3334
@@ -41,19 +42,51 @@ public function view(
4142 EntityManager $ em ,
4243 FlashMessage $ flash ,
4344 $ id
44- ){
45+ ) {
46+ $ error = [];
47+
4548 // Find crash report
4649 $ crash_report = $ em ->getRepository (CrashReport::class)->find ($ id );
47- if (!$ crash_report ){
50+ if (!$ crash_report ) {
4851 $ flash ->warning ('Crash report not found. ' );
4952 $ response = $ response ->withHeader ('Location ' , '/dev/crash-report/list ' )->withStatus (302 );
5053 return $ response ;
5154 }
5255
56+
57+ // Check if there is a game log
58+ $ game_log = $ crash_report ->getGameLog ();
59+ if ($ game_log ) {
60+
61+ // Check for error pattern
62+ $ error_pattern = '/Exception ([0-9xa-fA-F]+) thrown\: ([0-9_A-Za-f]+)\nError\: (.+)/ ' ;
63+ if (\preg_match ($ error_pattern , $ game_log , $ error_matches )) {
64+
65+ $ error = [
66+ 'exception_code ' => $ error_matches [1 ],
67+ 'identifier ' => $ error_matches [2 ],
68+ 'error_message ' => $ error_matches [3 ],
69+ ];
70+
71+ // Check for trace
72+ $ trace_pattern = '/\[\#(\d+)\s?\]\s(.+)$/m ' ;
73+ if (\preg_match_all ($ trace_pattern , $ game_log , $ trace_matches , PREG_PATTERN_ORDER )) {
74+
75+ $ trace = [];
76+ for ($ i = 0 ; $ i < \count ($ trace_matches [0 ]); $ i ++) {
77+ $ trace [(int )$ trace_matches [1 ][$ i ]] = (string )$ trace_matches [2 ][$ i ];
78+ }
79+
80+ $ error ['trace ' ] = $ trace ;
81+ }
82+ }
83+ }
84+
5385 // Show output
5486 $ response ->getBody ()->write (
5587 $ twig ->render ('devcp/crash-report/crash-report.devcp.html.twig ' , [
56- 'crash_report ' => $ crash_report
88+ 'crash_report ' => $ crash_report ,
89+ 'error ' => $ error ,
5790 ])
5891 );
5992 return $ response ;
@@ -66,23 +99,23 @@ public function delete(
6699 EntityManager $ em ,
67100 FlashMessage $ flash ,
68101 $ id
69- ){
102+ ) {
70103 // Find crash report
71104 $ crash_report = $ em ->getRepository (CrashReport::class)->find ($ id );
72- if (!$ crash_report ){
105+ if (!$ crash_report ) {
73106 $ flash ->warning ('Crash report not found. ' );
74107 $ response = $ response ->withHeader ('Location ' , '/dev/crash-report/list ' )->withStatus (302 );
75108 return $ response ;
76109 }
77110
78111 // Delete savefile
79112 $ save_filename = $ crash_report ->getSaveFilename ();
80- if ($ save_filename ){
113+ if ($ save_filename ) {
81114 $ dir = Config ::get ('storage.path.crash-report-savefile ' );
82- if (\file_exists ($ dir )){
115+ if (\file_exists ($ dir )) {
83116 $ filepath = $ dir . '/ ' . $ save_filename ;
84- if (\file_exists ($ filepath )){
85- if (\unlink ($ filepath ) === false ){
117+ if (\file_exists ($ filepath )) {
118+ if (\unlink ($ filepath ) === false ) {
86119 throw new \Exception ("failed to delete savefile: {$ filepath }" );
87120 }
88121 }
0 commit comments