Advertisement
dvarnai

Untitled

Sep 28th, 2013
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 8.57 KB | None | 0 0
  1. Index: MTA10_Server/core/CServerImpl.cpp
  2. ===================================================================
  3. --- MTA10_Server/core/CServerImpl.cpp   (revision 5848)
  4. +++ MTA10_Server/core/CServerImpl.cpp   (working copy)
  5. @@ -24,6 +24,13 @@
  6.  #include <signal.h>
  7.  #ifdef WIN32
  8.      #include <Mmsystem.h>
  9. +#else
  10. +    #include <termios.h>
  11. +    #include <unistd.h>
  12. +
  13. +    // This is probably safer than changing MTAPlatform.h against compatibility issues
  14. +    #undef Printf
  15. +    #define Print printf
  16.  #endif
  17.  
  18.  // Define libraries
  19. @@ -33,6 +40,7 @@
  20.  using namespace std;
  21.  
  22.  bool g_bSilent = false;
  23. +bool g_bNoCurses = false;
  24.  bool g_bNoTopBar = false;
  25.  #ifndef WIN32
  26.  bool g_bDaemonized = false;
  27. @@ -107,7 +115,10 @@
  28.  #ifdef WIN32
  29.          vprintf ( szFormat, ap );
  30.  #else
  31. -        vwprintw ( stdscr, szFormat, ap );
  32. +        if(!g_bNoCurses)
  33. +            vwprintw ( stdscr, szFormat, ap );
  34. +        else
  35. +            vprintf ( szFormat, ap );
  36.  #endif
  37.      }
  38.  
  39. @@ -205,49 +216,54 @@
  40.          assert ( strcoll( "a", "B" ) > 0 );
  41.  
  42.          // Initialize the window and any necessary curses options
  43. -        initscr ( );
  44. -        keypad ( stdscr, TRUE );
  45. -        nonl ( );
  46. -        cbreak ( );
  47. -        noecho ( );
  48. -        nodelay ( stdscr, TRUE );
  49. -        idlok ( stdscr, FALSE );
  50. -        scrollok ( stdscr, TRUE );
  51. -        if ( !g_bNoTopBar )
  52. -            setscrreg ( 1, LINES - 1 );
  53. -        else
  54. -            setscrreg ( 0, LINES - 1 );
  55. -
  56. -        // Initialize the colors
  57. -        if ( has_colors ( ) )
  58. +        if( !g_bNoCurses )
  59.          {
  60. -            start_color ( );
  61. +            initscr ( );
  62. +            keypad ( stdscr, TRUE );
  63. +            nonl ( );
  64. +            cbreak ( );
  65. +            noecho ( );
  66. +            nodelay ( stdscr, TRUE );
  67. +            idlok ( stdscr, FALSE );
  68. +            scrollok ( stdscr, TRUE );
  69.  
  70. -            init_pair ( 1, COLOR_BLACK, COLOR_WHITE );
  71. -            init_pair ( 2, COLOR_BLACK, COLOR_GREEN );
  72. -            init_pair ( 3, COLOR_WHITE, COLOR_WHITE );
  73. -            init_pair ( 4, COLOR_RED, COLOR_WHITE );
  74. -            init_pair ( 5, COLOR_GREEN, COLOR_WHITE );
  75. -            init_pair ( 6, COLOR_BLUE, COLOR_WHITE );
  76. -        }
  77. -        // Create the input window
  78. -        m_wndInput = subwin ( stdscr, 1, COLS, LINES - 1, 0 );
  79. -        scrollok ( m_wndInput, TRUE );
  80. -        wbkgd ( m_wndInput, COLOR_PAIR ( 2 ) );
  81. +            if ( !g_bNoTopBar )
  82. +                setscrreg ( 1, LINES - 1 );
  83. +            else
  84. +                setscrreg ( 0, LINES - 1 );
  85.  
  86. -        // Create the menu window
  87. -        if ( !g_bNoTopBar )
  88. -        {
  89. -            m_wndMenu = subwin ( stdscr, 1, COLS, 0, 0 );
  90. -            wbkgd ( m_wndMenu, COLOR_PAIR ( 1 ) );
  91. +            // Initialize the colors
  92. +            if ( has_colors ( ) )
  93. +            {
  94. +                start_color ( );
  95. +
  96. +                init_pair ( 1, COLOR_BLACK, COLOR_WHITE );
  97. +                init_pair ( 2, COLOR_BLACK, COLOR_GREEN );
  98. +                init_pair ( 3, COLOR_WHITE, COLOR_WHITE );
  99. +                init_pair ( 4, COLOR_RED, COLOR_WHITE );
  100. +                init_pair ( 5, COLOR_GREEN, COLOR_WHITE );
  101. +                init_pair ( 6, COLOR_BLUE, COLOR_WHITE );
  102. +            }
  103. +            // Create the input window
  104. +            m_wndInput = subwin ( stdscr, 1, COLS, LINES - 1, 0 );
  105. +            scrollok ( m_wndInput, TRUE );
  106. +            wbkgd ( m_wndInput, COLOR_PAIR ( 2 ) );
  107. +
  108. +            // Create the menu window
  109. +            if ( !g_bNoTopBar )
  110. +            {
  111. +                m_wndMenu = subwin ( stdscr, 1, COLS, 0, 0 );
  112. +                wbkgd ( m_wndMenu, COLOR_PAIR ( 1 ) );
  113. +            }
  114. +
  115. +            // Position the cursor and refresh the physical screen
  116. +
  117. +            if ( !g_bNoTopBar)
  118. +                move ( 1, 0 );
  119. +            else
  120. +                move ( 0, 0 );
  121. +            refresh ( );
  122.          }
  123. -
  124. -        // Position the cursor and refresh the physical screen
  125. -        if ( !g_bNoTopBar )
  126. -            move ( 1, 0 );
  127. -        else
  128. -            move ( 0, 0 );
  129. -        refresh ( );
  130.  #endif
  131.      }
  132.  
  133. @@ -393,7 +409,7 @@
  134.      while ( !m_bRequestedQuit )
  135.      {
  136.  #ifndef WIN32
  137. -        if ( !g_bSilent )
  138. +        if ( !g_bSilent && !g_bNoCurses)
  139.          {
  140.              // Update all the windows, and the physical screen in one burst
  141.              if ( m_wndMenu )
  142. @@ -403,7 +419,7 @@
  143.              wbkgd ( m_wndInput, COLOR_PAIR ( 2 ) );
  144.          }
  145.  #endif
  146. -        if ( !g_bSilent && !g_bNoTopBar )
  147. +        if ( !g_bSilent && !g_bNoTopBar && !g_bNoCurses)
  148.          {
  149.              // Show the info tag, 80 is a fixed length
  150.              char szInfoTag[80] = { '\0' };
  151. @@ -472,7 +488,7 @@
  152.  /*************************/
  153.  void CServerImpl::ShowInfoTag ( char* szTag )
  154.  {
  155. -    if ( g_bSilent || g_bNoTopBar )
  156. +    if ( g_bSilent || g_bNoTopBar || g_bNoCurses)
  157.          return;
  158.  #ifdef WIN32
  159.      // Windows console code
  160. @@ -573,8 +589,28 @@
  161.          iStdIn = _getwch();
  162.      }
  163.  #else
  164. -    if ( get_wch(&iStdIn) == ERR )
  165. -        iStdIn = 0;
  166. +    if( !g_bNoCurses )
  167. +    {
  168. +        if ( get_wch(&iStdIn) == ERR )
  169. +            iStdIn = 0;
  170. +    }
  171. +    else
  172. +    {
  173. +        struct termios oldattr, newattr;
  174. +        int oldf;
  175. +        tcgetattr( STDIN_FILENO, &oldattr );
  176. +        newattr = oldattr;
  177. +        newattr.c_lflag &= ~( ICANON | ECHO );
  178. +        tcsetattr( STDIN_FILENO, TCSANOW, &newattr );
  179. +        oldf = fcntl(STDIN_FILENO, F_GETFL, 0);
  180. +        fcntl(STDIN_FILENO, F_SETFL, oldf | O_NONBLOCK);
  181. +        iStdIn = getwchar();
  182. +        tcsetattr( STDIN_FILENO, TCSANOW, &oldattr );
  183. +        fcntl(STDIN_FILENO, F_SETFL, oldf);
  184. +
  185. +        if ( iStdIn == -1 )
  186. +            iStdIn = 0;
  187. +    }
  188.  #endif
  189.  
  190.      if ( iStdIn == 0 )
  191. @@ -591,7 +627,7 @@
  192.              // set string termination (required for compare/string functions
  193.              m_szInputBuffer[m_uiInputCount] = 0;
  194.  
  195. -            if ( !g_bSilent )
  196. +            if ( !g_bSilent && !g_bNoCurses)
  197.              {
  198.                  // Clear the input window
  199.                  wclear ( m_wndInput );
  200. @@ -641,8 +677,8 @@
  201.  #ifdef WIN32
  202.              Printf ( "%c %c", 0x08, 0x08 );
  203.  #else
  204. -            if ( !g_bSilent )
  205. -                wprintw ( m_wndInput, "%c %c", 0x08, 0x08 );
  206. +            if ( !g_bSilent && !g_bNoCurses)
  207. +                    wprintw ( m_wndInput, "%c %c", 0x08, 0x08 );
  208.  #endif
  209.              m_uiInputCount--;
  210.              m_szInputBuffer[m_uiInputCount] = 0;
  211. @@ -677,7 +713,7 @@
  212.  
  213.              Printf ( "\r%s", UTF16ToMbUTF8(szBuffer).c_str() );
  214.  #else
  215. -            if ( !g_bSilent )
  216. +            if ( !g_bSilent && !g_bNoCurses )
  217.                  wmove ( m_wndInput, 0, --m_uiInputCount );
  218.  #endif
  219.              break;
  220. @@ -700,7 +736,7 @@
  221.  
  222.              Printf ( "\r%s", UTF16ToMbUTF8(szBuffer).c_str() );
  223.  #else
  224. -            if ( !g_bSilent )
  225. +            if ( !g_bSilent && !g_bNoCurses )
  226.                  wmove ( m_wndInput, 0, ++m_uiInputCount );
  227.  #endif
  228.              break;
  229. @@ -738,7 +774,7 @@
  230.              Printf ( "%s", UTF16ToMbUTF8(wUNICODE).c_str() );
  231.  #else
  232.              wchar_t wUNICODE[2] = { iStdIn, 0 };
  233. -            if ( !g_bSilent )
  234. +            if ( !g_bSilent && !g_bNoCurses)
  235.                  wprintw ( m_wndInput, "%s", UTF16ToMbUTF8(wUNICODE).c_str() );
  236.  #endif
  237.  
  238. @@ -806,6 +842,11 @@
  239.                  {
  240.                      g_bDaemonized = true;
  241.                  }
  242. +                else if ( strcmp ( szArguments [i], "-n" ) == 0 )
  243. +                {
  244. +                    g_bNoTopBar = true;
  245. +                    g_bNoCurses = true;
  246. +                }
  247.  #endif
  248.                  else if ( strcmp ( szArguments [i], "-t" ) == 0 )
  249.                  {
  250. @@ -851,7 +892,7 @@
  251.  void CServerImpl::DestroyWindow ( void )
  252.  {
  253.  #ifndef WIN32
  254. -    if ( !g_bSilent )
  255. +    if ( !g_bSilent  || !g_bNoCurses)
  256.      {
  257.          if ( m_wndMenu )
  258.              delwin ( m_wndMenu );
  259. Index: MTA10_Server/launcher/Main.cpp
  260. ===================================================================
  261. --- MTA10_Server/launcher/Main.cpp  (revision 5848)
  262. +++ MTA10_Server/launcher/Main.cpp  (working copy)
  263. @@ -70,6 +70,7 @@
  264.  #endif
  265.              printf ( "  -t                   Run server with a simple console\n" );
  266.              printf ( "  -f                   Run server with a standard console (Default)\n" );
  267. +            printf ( "  -n                   Disable the usage of ncurses\n" );
  268.              printf ( "  -D [PATH]            Use as base directory\n" );
  269.              printf ( "  --config [FILE]      Alternate mtaserver.conf file\n" );
  270.              printf ( "  --ip [ADDR]          Set IP address\n" );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement