• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

polserver / polserver / 21066490217

16 Jan 2026 12:22PM UTC coverage: 60.507%. Remained the same
21066490217

push

github

web-flow
misc clang-tidy (#853)

* trigger tidy

* Automated clang-tidy change: modernize-use-equals-delete,modernize-make-shared,modernize-make-unique,modernize-use-constraints,readability-container-size-empty,modernize-redundant-void-arg,modernize-use-emplace

* removed non needed macros

* missed to disable tidy build

---------

Co-authored-by: Clang Tidy <clang-tidy@users.noreply.github.com>

174 of 248 new or added lines in 74 files covered. (70.16%)

2 existing lines in 2 files now uncovered.

44459 of 73477 relevant lines covered (60.51%)

515895.79 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

5.26
/pol-core/pol/console.cpp
1
/** @file
2
 *
3
 * @par History
4
 */
5

6

7
#include "console.h"
8

9
#include <ctype.h>
10
#include <stddef.h>
11

12
#include "../bscript/eprog.h"
13
#include "../bscript/impstr.h"
14
#include "../clib/cfgelem.h"
15
#include "../clib/cfgfile.h"
16
#include "../clib/fileutil.h"
17
#include "../clib/kbhit.h"
18
#include "../clib/logfacility.h"
19
#include "../clib/refptr.h"
20
#include "../clib/stlutil.h"
21
#include "../plib/systemstate.h"
22
#include "globals/state.h"
23
#include "globals/uvars.h"
24
#include "polsem.h"
25
#include "polsig.h"
26
#include "scrdef.h"
27
#include "scrsched.h"
28
#include "scrstore.h"
29
#include <fmt/format.h>
30

31
#ifdef _WIN32
32
#include <conio.h>
33
#endif
34

35
#include <exception>
36
#include <stdexcept>
37
#include <string>
38

39
namespace Pol
40
{
41
namespace Core
42
{
43
bool ConsoleCommand::console_locked = true;
44
char ConsoleCommand::unlock_char;
45

46
ConsoleCommand::ConsoleCommand( Clib::ConfigElem& elem, const std::string& cmd )
×
47
{
48
  ISTRINGSTREAM is( cmd );
×
49
  std::string charspec;
×
50
  if ( !( is >> charspec >> script ) )
×
51
  {
52
    elem.throw_error( "Ill-formed console command desc: " + cmd );
×
53
  }
54
  if ( charspec[0] == '^' && charspec.size() == 2 )
×
55
  {
56
    ch = static_cast<char>( toupper( charspec[1] ) ) - 'A' + 1;
×
57
  }
58
  else if ( charspec.size() == 1 )
×
59
  {
60
    ch = charspec[0];
×
61
  }
62
  else
63
  {
64
    elem.throw_error( "Ill-formed console command char: " + charspec );
×
65
  }
66
  getline( is, description );
×
NEW
67
  while ( !description.empty() && isspace( description[0] ) )
×
68
  {
69
    description.erase( 0, 1 );
×
70
  }
71

72
  if ( script == "[unlock]" || script == "[lock/unlock]" )
×
73
    ConsoleCommand::unlock_char = ch;
×
74
}
×
75

76
size_t ConsoleCommand::estimateSize() const
×
77
{
78
  return sizeof( char ) + script.capacity() + description.capacity();
×
79
}
80

81
std::string getcmdstr( char ch )
×
82
{
83
  if ( iscntrl( ch ) )
×
84
  {
85
    char s[3];
86
    s[0] = '^';
×
87
    s[1] = ch + 'A' - 1;
×
88
    s[2] = '\0';
×
89
    return s;
×
90
  }
91
  else
92
  {
93
    char s[2];
94
    s[0] = ch;
×
95
    s[1] = '\0';
×
96
    return s;
×
97
  }
98
}
99

100
ConsoleCommand* ConsoleCommand::find_console_command( char ch )
×
101
{
102
  for ( unsigned i = 0; i < gamestate.console_commands.size(); ++i )
×
103
  {
104
    ConsoleCommand& cmd = gamestate.console_commands[i];
×
105
    if ( cmd.ch == ch )
×
106
      return &cmd;
×
107
  }
108
  return nullptr;
×
109
}
110

111
void ConsoleCommand::load_console_commands()
37✔
112
{
113
  if ( !Clib::FileExists( "config/console.cfg" ) )
37✔
114
    return;
37✔
115

116
  Clib::ConfigFile cf( "config/console.cfg", "Commands" );
×
117
  Clib::ConfigElem elem;
×
118

119
  gamestate.console_commands.clear();
×
120

121
  while ( cf.read( elem ) )
×
122
  {
123
    std::string tmp;
×
124
    while ( elem.remove_prop( "CMD", &tmp ) )
×
125
    {
126
      ConsoleCommand cmd( elem, tmp );
×
127
      gamestate.console_commands.push_back( cmd );
×
128
    }
×
129
  }
×
130
}
×
131

132
void ConsoleCommand::exec_console_cmd( char ch )
×
133
{
134
#ifdef WIN32
135
  // cope with function keys.
136
  if ( ch == 0 || static_cast<unsigned char>( ch ) == 0xE0 )
137
  {
138
    getch();
139
    ch = '?';
140
  }
141
#endif
142
  if ( ch == '?' )
×
143
  {
144
    std::string tmp = "Commands: \n";
×
145
    for ( unsigned i = 0; i < gamestate.console_commands.size(); ++i )
×
146
    {
147
      ConsoleCommand& cmd = gamestate.console_commands[i];
×
148
      std::string sc = getcmdstr( cmd.ch );
×
149
      tmp += fmt::format( "{}{}: {}\n", sc.size() == 1 ? "  " : " ", sc, cmd.description );
×
150
    }
×
151
    tmp += "  ?: Help (This list)";
×
152
    INFO_PRINTLN( tmp );
×
153
    return;
×
154
  }
×
155

156

157
  ConsoleCommand* cmd = find_console_command( ch );
×
158
  if ( !cmd )
×
159
  {
160
    INFO_PRINTLN( "Unknown console command: '{}'", getcmdstr( ch ) );
×
161
    return;
×
162
  }
163
  if ( cmd->script == "[lock]" )
×
164
  {
165
    ConsoleCommand::console_locked = true;
×
166
    INFO_PRINTLN( "Console is now locked." );
×
167
    return;
×
168
  }
169
  if ( cmd->script == "[unlock]" )
×
170
  {
171
    ConsoleCommand::console_locked = true;
×
172
    INFO_PRINTLN( "Console is now unlocked." );
×
173
    return;
×
174
  }
175
  if ( cmd->script == "[lock/unlock]" )
×
176
  {
177
    ConsoleCommand::console_locked = !ConsoleCommand::console_locked;
×
178
    if ( ConsoleCommand::console_locked )
×
179
      INFO_PRINTLN( "Console is now locked." );
×
180
    else
181
      INFO_PRINTLN( "Console is now unlocked." );
×
182
    return;
×
183
  }
184
  if ( cmd->script == "[threadstatus]" )
×
185
  {
186
    stateManager.polsig.report_status_signalled = true;
×
187
    return;
×
188
  }
189
  if ( cmd->script == "[crash]" )
×
190
  {
191
    std::abort();
×
192
    return;
193
  }
194

195
  if ( ConsoleCommand::console_locked )
×
196
  {
197
    INFO_PRINTLN( "Console is locked.  Press '{}' to unlock.", ConsoleCommand::unlock_char );
×
198
    return;
×
199
  }
200

201
  std::string filename = "scripts/console/" + cmd->script;
×
202
  try
203
  {
204
    PolLock lck;
×
205
    ScriptDef sd;
×
206
    sd.quickconfig( filename + ".ecl" );
×
207
    ref_ptr<Bscript::EScriptProgram> prog =
208
        find_script2( sd, true, Plib::systemstate.config.cache_interactive_scripts );
×
209
    if ( prog.get() != nullptr )
×
210
      start_script( prog, new Bscript::String( getcmdstr( ch ) ) );
×
211
  }
×
212
  catch ( const char* msg )
×
213
  {
214
    ERROR_PRINTLN( "Command aborted due to: {}", msg );
×
215
  }
×
216
  catch ( std::string& str )
×
217
  {
218
    ERROR_PRINTLN( "Command aborted due to: {}", str );
×
NEW
219
  }  // egcs has some trouble realizing 'exception' should catch
×
220
  catch ( std::runtime_error& re )  // runtime_errors, so...
×
221
  {
222
    ERROR_PRINTLN( "Command aborted due to: {}", re.what() );
×
223
  }
×
224
  catch ( std::exception& ex )
×
225
  {
226
    ERROR_PRINTLN( "Command aborted due to: {}", ex.what() );
×
227
  }
×
228
  catch ( int xn )
×
229
  {
230
    ERROR_PRINTLN( "Command aborted due to: {}", xn );
×
231
  }
×
232
  return;
×
233
}
×
234
#ifdef _WIN32
235
void ConsoleCommand::check_console_commands()
236
{
237
  if ( kbhit() )
238
  {
239
    exec_console_cmd( static_cast<char>( getch() ) );
240
  }
241
}
242
#else
243
void ConsoleCommand::check_console_commands( Clib::KeyboardHook* kb )
9✔
244
{
245
  if ( kb->kbhit() )
9✔
246
  {
247
    exec_console_cmd( kb->getch() );
×
248
  }
249
}
9✔
250
#endif
251
}  // namespace Core
252
}  // namespace Pol
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc