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

polserver / polserver / 21108840797

18 Jan 2026 08:35AM UTC coverage: 60.508% (+0.02%) from 60.492%
21108840797

push

github

web-flow
ClangTidy readability-else-after-return (#857)

* trigger tidy

* Automated clang-tidy change: readability-else-after-return

* compile test

* rerun

* Automated clang-tidy change: readability-else-after-return

* trigger..

* Automated clang-tidy change: readability-else-after-return

* manually removed a few

* Automated clang-tidy change: readability-else-after-return

* removed duplicate code

* fix remaining warnings

* fixed scope

---------

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

837 of 1874 new or added lines in 151 files covered. (44.66%)

46 existing lines in 25 files now uncovered.

44448 of 73458 relevant lines covered (60.51%)

525066.38 hits per line

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

46.09
/pol-core/pol/module/polsystemmod.cpp
1
/** @file
2
 *
3
 * @par History
4
 * - 2005/11/26 Shinigami: changed "strcmp" into "stricmp" to suppress Script Errors
5
 * - 2006/10/07 Shinigami: GCC 3.4.x fix - added "template<>" to TmplExecutorModule
6
 * - 2007/04/08 MuadDib:   Changed Realms() to get BObject IMP, and check for string
7
 *                         explicitly.
8
 * - 2009/11/30 Turley:    added MD5Encrypt(string)
9
 * - 2010/03/28 Shinigami: Transmit Pointer as Pointer and not Int as Pointer within
10
 * decay_thread_shadow
11
 */
12

13

14
#include "polsystemmod.h"
15
#include <ctime>
16
#include <fstream>
17
#include <string>
18

19
#include "bscript/berror.h"
20
#include "bscript/bobject.h"
21
#include "bscript/dict.h"
22
#include "bscript/impstr.h"
23
#include "clib/clib.h"
24
#include "clib/clib_MD5.h"
25
#include "clib/fileutil.h"
26
#include "clib/rawtypes.h"
27
#include "clib/strutil.h"
28
#include "clib/threadhelp.h"
29
#include "plib/pkg.h"
30
#include "plib/systemstate.h"
31

32

33
#include "realms/realm.h"
34
#include "realms/realms.h"
35

36
#include "globals/settings.h"
37
#include "globals/uvars.h"
38
#include "item/item.h"
39
#include "item/itemdesc.h"
40

41
#include "cmdlevel.h"
42
#include "core.h"
43
#include "decay.h"
44
#include "listenpt.h"
45
#include "packetscrobj.h"
46
#include "proplist.h"
47
#include "tooltips.h"
48
#include "uobject.h"
49
#include "uoexec.h"
50

51
#include <module_defs/polsys.h>
52

53
namespace Pol
54
{
55
namespace Core
56
{
57
void reload_configuration();
58
}  // namespace Core
59
namespace Module
60
{
61
using namespace Bscript;
62

63
BApplicObjType packageobjimp_type;
64

65
PackageObjImp::PackageObjImp( const PackagePtrHolder& other )
38✔
66
    : PackageObjImpBase( &packageobjimp_type, other )
38✔
67
{
68
}
38✔
69
const char* PackageObjImp::typeOf() const
×
70
{
71
  return "Package";
×
72
}
73
u8 PackageObjImp::typeOfInt() const
×
74
{
75
  return OTPackage;
×
76
}
77
BObjectImp* PackageObjImp::copy() const
×
78
{
79
  return new PackageObjImp( obj_ );
×
80
}
81
BObjectImp* PackageObjImp::call_polmethod( const char* /*methodname*/, Core::UOExecutor& /*ex*/ )
×
82
{
83
  return new BError( "undefined method" );
×
84
}
85
BObjectRef PackageObjImp::get_member( const char* membername )
140✔
86
{
87
  if ( stricmp( membername, "name" ) == 0 )
140✔
88
  {
89
    return BObjectRef( new String( value()->name() ) );
68✔
90
  }
91
  if ( stricmp( membername, "version" ) == 0 )
72✔
92
  {
93
    return BObjectRef( new String( value()->version() ) );
×
94
  }
95
  if ( stricmp( membername, "supports_http" ) == 0 )
72✔
96
  {
97
    const Plib::Package* pkg = value().Ptr();
×
98
    return BObjectRef( new BLong( Clib::FileExists( pkg->dir() + "www" ) ) );
×
99
  }
100
  if ( stricmp( membername, "npcdesc" ) == 0 )
72✔
101
  {
102
    const Plib::Package* pkg = value().Ptr();
×
103
    std::string filepath = Plib::GetPackageCfgPath( pkg, "npcdesc.cfg" );
×
104
    return BObjectRef( new BLong( Clib::FileExists( filepath ) ) );
×
105
  }
×
106
  if ( stricmp( membername, "dir" ) == 0 )
72✔
107
  {
108
    const Plib::Package* pkg = value().Ptr();
38✔
109
    return BObjectRef( new String( pkg->dir() ) );
38✔
110
  }
111
  if ( stricmp( membername, "desc" ) == 0 )
34✔
112
  {
113
    return BObjectRef( new String( value()->desc() ) );
68✔
114
  }
NEW
115
  return BObjectRef( new BError( "Undefined member" ) );
×
116
}
117

118
PolSystemExecutorModule::PolSystemExecutorModule( Bscript::Executor& exec )
371✔
119
    : Bscript::TmplExecutorModule<PolSystemExecutorModule, Core::PolModule>( exec )
371✔
120
{
121
}
371✔
122

123
BObjectImp* PolSystemExecutorModule::mf_IncRevision( /* uobject */ )
×
124
{
125
  Core::UObject* uobj;
126
  if ( getUObjectParam( 0, uobj ) )
×
127
  {
128
    uobj->increv();
×
129
    send_object_cache_to_inrange( uobj );
×
130
    return new BLong( 1 );
×
131
  }
132

NEW
133
  return new BError( "Invalid parameter type" );
×
134
}
135

136
BObjectImp* PolSystemExecutorModule::mf_GetCmdLevelName()
×
137
{
138
  int cmdlevel_num;
139
  const String* cmdlevel_alias;
140

141
  if ( exec.numParams() != 1 )
×
142
    return new BError( "Expected 1 parameter." );
×
NEW
143
  if ( getParam( 0, cmdlevel_num ) )
×
144
  {
145
    if ( cmdlevel_num >= static_cast<int>( Core::gamestate.cmdlevels.size() ) )
×
146
      cmdlevel_num = static_cast<int>( Core::gamestate.cmdlevels.size() - 1 );
×
147

148
    return new String( Core::gamestate.cmdlevels[cmdlevel_num].name );
×
149
  }
NEW
150
  if ( getStringParam( 0, cmdlevel_alias ) )
×
151
  {
152
    Core::CmdLevel* cmdlevel = Core::FindCmdLevelByAlias( cmdlevel_alias->data() );
×
153
    if ( cmdlevel == nullptr )
×
154
      return new BError( "Could not find a command level with that alias." );
×
NEW
155
    return new String( cmdlevel->name );
×
156
  }
NEW
157
  return new BError( "Invalid parameter type." );
×
158
}
159

160
BObjectImp* PolSystemExecutorModule::mf_GetCmdLevelNumber()
×
161
{
162
  const String* cmdlvlname;
163
  if ( !getStringParam( 0, cmdlvlname ) )
×
164
    return new BError( "Invalid parameter type." );
×
165

166
  Core::CmdLevel* cmdlevel_search = Core::find_cmdlevel( cmdlvlname->data() );
×
167
  if ( cmdlevel_search == nullptr )
×
168
    return new BError( "Could not find a command level with that name." );
×
169

170
  return new BLong( cmdlevel_search->cmdlevel );
×
171
}
172

173
BObjectImp* PolSystemExecutorModule::mf_Packages()
2✔
174
{
175
  std::unique_ptr<ObjArray> arr( new ObjArray );
2✔
176
  for ( unsigned i = 0; i < Plib::systemstate.packages.size(); ++i )
40✔
177
  {
178
    PackageObjImp* imp = new PackageObjImp( PackagePtrHolder( Plib::systemstate.packages[i] ) );
38✔
179
    arr->addElement( imp );
38✔
180
  }
181
  return arr.release();
4✔
182
}
2✔
183

184
BObjectImp* PolSystemExecutorModule::mf_GetPackageByName()
×
185
{
186
  const String* pkgname;
187
  if ( !getStringParam( 0, pkgname ) )
×
188
    return new BError( "Invalid parameter type." );
×
189

190
  // pkgname->toLower();
191
  Plib::Package* pkg = Plib::find_package( pkgname->value() );
×
192
  if ( !pkg )
×
193
    return new BError( "No package found by that name." );
×
NEW
194
  return new PackageObjImp( PackagePtrHolder( pkg ) );
×
195
}
196

197
BObjectImp* PolSystemExecutorModule::mf_ListTextCommands()
1✔
198
{
199
  std::unique_ptr<BDictionary> pkg_list( new BDictionary );
1✔
200

201
  int max_cmdlevel;
202
  if ( exec.numParams() < 1 || !getParam( 0, max_cmdlevel ) )
1✔
203
    max_cmdlevel = -1;
×
204

205
  // Sets up text commands not in a package.
206
  {
207
    auto cmd_lvl_list = Core::ListAllCommandsInPackage( nullptr, max_cmdlevel );
1✔
208
    if ( !cmd_lvl_list->contents().empty() )
1✔
209
      pkg_list->addMember( new String( "" ), cmd_lvl_list.release() );
×
210
  }
1✔
211

212
  // Sets up packaged text commands.
213
  for ( Plib::Packages::iterator itr = Plib::systemstate.packages.begin();
1✔
214
        itr != Plib::systemstate.packages.end(); ++itr )
20✔
215
  {
216
    Plib::Package* pkg = ( *itr );
19✔
217
    auto cmd_lvl_list = Core::ListAllCommandsInPackage( pkg, max_cmdlevel );
19✔
218
    if ( !cmd_lvl_list->contents().empty() )
19✔
219
      pkg_list->addMember( new String( pkg->name().c_str() ), cmd_lvl_list.release() );
1✔
220
  }
19✔
221

222
  return pkg_list.release();
2✔
223
}
1✔
224

225
BObjectImp* PolSystemExecutorModule::mf_ReloadConfiguration()
36✔
226
{
227
  try
228
  {
229
    Core::reload_configuration();
36✔
230
  }
231
  catch ( const std::exception& ex )
2✔
232
  {
233
    return new BError( ex.what() );
2✔
234
  }
2✔
235
  catch ( ... )
×
236
  {
237
    return new BError( "Configuration file error" );
×
238
  }
×
239

240
  return new BLong( 1 );
34✔
241
}
242

243
BObjectImp* PolSystemExecutorModule::mf_ReadMillisecondClock()
772✔
244
{
245
  return new Double( static_cast<double>( Core::polclock_t_to_ms( Core::polclock() ) ) );
772✔
246
}
247

248
BObjectImp* PolSystemExecutorModule::mf_ListenPoints()
×
249
{
250
  return Core::ListenPoint::GetListenPoints();
×
251
}
252

253
BStruct* SetupRealmDetails( Realms::Realm* realm )
1✔
254
{
255
  std::unique_ptr<BStruct> details( new BStruct() );
1✔
256
  details->addMember( "width", new BLong( realm->width() ) );
1✔
257
  details->addMember( "height", new BLong( realm->height() ) );
1✔
258
  details->addMember( "season", new BLong( realm->season() ) );
1✔
259
  details->addMember( "mapid", new BLong( realm->getUOMapID() ) );
1✔
260
  details->addMember( "toplevel_item_count", new BLong( realm->toplevel_item_count() ) );
1✔
261
  details->addMember( "mobile_count", new BLong( realm->mobile_count() ) );
1✔
262
  details->addMember( "offline_mobs_count", new BLong( realm->offline_mobile_count() ) );
1✔
263
  details->addMember( "multi_count", new BLong( realm->multi_count() ) );
1✔
264

265
  return details.release();
2✔
266
}
1✔
267

268
BObjectImp* PolSystemExecutorModule::mf_Realms( /* realm_name:="" */ )
1✔
269
{
270
  const String* realm_name;
271
  //  getStringParam(0, realm_name);
272
  BObjectImp* imp = getParamImp( 0 );
1✔
273
  if ( imp->isa( BObjectImp::OTString ) )
1✔
274
  {
275
    realm_name = static_cast<const String*>( imp );
1✔
276
  }
277
  else
278
  {
279
    return new BError( std::string( "Parameter must be a String or empty, got " ) +
×
280
                       BObjectImp::typestr( imp->type() ) );
×
281
  }
282

283
  if ( realm_name->length() > 0 )
1✔
284
  {
285
    Realms::Realm* realm = Core::find_realm( realm_name->value() );
1✔
286
    if ( !realm )
1✔
287
      return new BError( "Realm not found." );
×
288
    return SetupRealmDetails( realm );
1✔
289
  }
290

NEW
291
  BDictionary* dict = new BDictionary;
×
NEW
292
  std::vector<Realms::Realm*>::iterator itr;
×
NEW
293
  for ( itr = Core::gamestate.Realms.begin(); itr != Core::gamestate.Realms.end(); ++itr )
×
294
  {
NEW
295
    dict->addMember( ( *itr )->name().c_str(), SetupRealmDetails( *itr ) );
×
296
  }
297

NEW
298
  return dict;
×
299
}
300

301
BObjectImp* PolSystemExecutorModule::mf_SetSysTrayPopupText()
×
302
{
303
#ifdef _WIN32
304
  const char* text = exec.paramAsString( 0 );
305

306
  Core::CoreSetSysTrayToolTip( text, Core::ToolTipPriorityScript );
307
#endif
308
  return new BLong( 1 );
×
309
}
310

311
BObjectImp* PolSystemExecutorModule::mf_GetItemDescriptor()
8✔
312
{
313
  unsigned int objtype;
314
  if ( getObjtypeParam( 0, objtype ) )
8✔
315
  {
316
    const Items::ItemDesc& id = Items::find_itemdesc( objtype );
8✔
317
    if ( id.objtype == 0 && id.graphic == 0 )
8✔
318
      return new BError( "Itemdesc.cfg entry for objtype " + Clib::hexint( objtype ) +
×
319
                         " not found." );
×
320

321
    std::unique_ptr<BStruct> descriptor( new BStruct() );
8✔
322

323
    id.PopulateStruct( descriptor.get() );
8✔
324

325
    return descriptor.release();
8✔
326
  }
8✔
327

NEW
328
  return new BError( "Invalid parameter type" );
×
329
}
330

331
BObjectImp* PolSystemExecutorModule::mf_FormatItemDescription()
×
332
{
333
  const String* desc;
334
  unsigned short amount;
335
  const String* suffix;
336

337
  if ( getStringParam( 0, desc ) && getParam( 1, amount ) && getStringParam( 2, suffix ) )
×
338
  {
339
    return new String( Core::format_description( 0, desc->value(), amount, suffix->value() ) );
×
340
  }
341

NEW
342
  return new BError( "Invalid parameter type" );
×
343
}
344

345
BObjectImp* PolSystemExecutorModule::mf_CreatePacket()
4✔
346
{
347
  int size;
348
  unsigned short type;
349
  if ( exec.getParam( 0, type ) && exec.getParam( 1, size ) )
4✔
350
  {
351
    if ( type > 0xFF )
4✔
352
      return new BError( "Packet type too high" );
×
353

354
    return new Core::BPacket( static_cast<u8>( type ), static_cast<signed short>( size ) );
4✔
355
  }
356

NEW
357
  return new BError( "Invalid parameter type" );
×
358
}
359

360
BObjectImp* PolSystemExecutorModule::mf_AddRealm( /*name,base*/ )
4✔
361
{
362
  const String* realm_name;
363
  const String* base;
364
  if ( !( getStringParam( 0, realm_name ) && getStringParam( 1, base ) ) )
4✔
365
  {
366
    return new BError( "Invalid parameter" );
×
367
  }
368
  Realms::Realm* baserealm = Core::find_realm( base->value() );
4✔
369
  if ( !baserealm )
4✔
370
    return new BError( "BaseRealm not found." );
×
371
  if ( baserealm->is_shadowrealm )
4✔
372
    return new BError( "BaseRealm is a ShadowRealm." );
×
373
  if ( Core::defined_realm( realm_name->value() ) )
4✔
374
    return new BError( "Realmname already defined." );
×
375
  Core::add_realm( realm_name->value(), baserealm );
4✔
376
  return new BLong( 1 );
4✔
377
}
378

379
BObjectImp* PolSystemExecutorModule::mf_DeleteRealm( /*name*/ )
5✔
380
{
381
  const String* realm_name;
382
  if ( !( getStringParam( 0, realm_name ) ) )
5✔
383
    return new BError( "Invalid parameter" );
×
384

385
  Realms::Realm* realm = Core::find_realm( realm_name->value() );
5✔
386

387
  if ( !realm )
5✔
388
    return new BError( "Realm not found." );
2✔
389
  if ( !realm->is_shadowrealm )
3✔
390
    return new BError( "Realm is not a ShadowRealm." );
×
391
  if ( realm->mobile_count() > 0 )
3✔
392
    return new BError( "Mobiles in Realm." );
×
393
  if ( realm->offline_mobile_count() > 0 )
3✔
394
    return new BError( "Offline characters in Realm" );
×
395
  if ( realm->toplevel_item_count() > 0 )
3✔
396
    return new BError( "Items in Realm." );
×
397
  if ( realm->multi_count() > 0 )
3✔
398
    return new BError( "Multis in Realm." );
×
399

400
  Core::remove_realm( realm_name->value() );
3✔
401
  return new BLong( 1 );
3✔
402
}
403

404
BObjectImp* PolSystemExecutorModule::mf_GetRealmDecay( /*name*/ )
×
405
{
406
  const String* realm_name;
407
  if ( !getStringParam( 0, realm_name ) )
×
408
  {
409
    return new BError( "Invalid parameter" );
×
410
  }
411
  Realms::Realm* realm = Core::find_realm( realm_name->value() );
×
412
  if ( !realm )
×
413
    return new BError( "Realm not found." );
×
414

415
  return new BBoolean( realm->has_decay );
×
416
}
417

418
BObjectImp* PolSystemExecutorModule::mf_SetRealmDecay( /*name,has_decay*/ )
×
419
{
420
  const String* realm_name;
421
  bool has_deacy;
422
  if ( !( getStringParam( 0, realm_name ) && getParam( 1, has_deacy ) ) )
×
423
  {
424
    return new BError( "Invalid parameter" );
×
425
  }
426
  Realms::Realm* realm = Core::find_realm( realm_name->value() );
×
427
  if ( !realm )
×
428
    return new BError( "Realm not found." );
×
429

430
  realm->has_decay = has_deacy;
×
431
  Core::gamestate.decay.after_realms_size_changed();
×
432

433
  return new BLong( 1 );
×
434
}
435

436
BObjectImp* PolSystemExecutorModule::mf_MD5Encrypt( /*string*/ )
3✔
437
{
438
  const String* string;
439
  if ( !( getStringParam( 0, string ) ) )
3✔
440
    return new BError( "Invalid parameter" );
×
441
  if ( string->length() < 1 )
3✔
442
    return new BError( "String is empty" );
×
443
  std::string temp;
3✔
444
  if ( !Clib::MD5_Encrypt( string->value(), temp ) )
3✔
445
    return new BError( "Failed to encrypt" );
×
446
  return new String( temp );
3✔
447
}
3✔
448

449
/**
450
 * Dumps the CProp profiling info into the log file
451
 *
452
 * @author Bodom
453
 */
454
BObjectImp* PolSystemExecutorModule::mf_LogCPropProfile()
×
455
{
456
  const std::string filepath = "log/cpprofile.log";
×
457
  std::ofstream ofs( filepath.c_str(), std::ios::out | std::ios::app );
×
458

459
  if ( !ofs.is_open() )
×
460
    return new BError( "Unable to open file: " + filepath );
×
461

462
  // Write the header
463
  auto t = std::time( nullptr );
×
464
  auto tm = Clib::localtime( t );
×
465
  ofs << std::string( 80, '=' ) << std::endl;
×
466
  ofs << "CProp profiling information dumped on " << std::asctime( &tm ) << std::endl;
×
467
  ofs << "the profiler is using an estimated amount of "
×
468
      << Core::CPropProfiler::instance().estimateSize() << " Bytes of memory." << std::endl;
×
469
  ofs << "the profiler is currently "
470
      << ( Plib::systemstate.config.profile_cprops ? "enabled" : "disabled" ) << "." << std::endl;
×
471
  ofs << std::endl;
×
472

473
  // Write the body
474
  Core::CPropProfiler::instance().dumpProfile( ofs );
×
475

476
  // Write the footer
477
  ofs << std::string( 80, '=' ) << std::endl;
×
478

479
  if ( ofs.fail() )
×
480
    return new BError( "Error during write." );
×
481

482
  ofs.close();
×
483
  return new BLong( 1 );
×
484
}
×
485
}  // namespace Module
486
}  // 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