• 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

17.09
/pol-core/poltool/PolToolMain.cpp
1
#include "PolToolMain.h"
2

3
#include <fstream>
4
#include <string>
5

6
#include "../clib/Program/ProgramMain.h"
7
#include "../clib/clib_endian.h"
8
#include "../clib/fileutil.h"
9
#include "../clib/logfacility.h"
10
#include "../clib/rawtypes.h"
11
#include "../plib/mapcell.h"
12
#include "../plib/mapfunc.h"
13
#include "../plib/mapserver.h"
14
#include "../plib/mapshape.h"
15
#include "../plib/maptile.h"
16
#include "../plib/maptileserver.h"
17
#include "../plib/realmdescriptor.h"
18
#include "baredistro.h"
19
#include "testenv.h"
20
#include "testfiles.h"
21

22

23
#include <zlib.h>
24

25

26
namespace Pol::Clib
27
{
28
using namespace std;
29

30
///////////////////////////////////////////////////////////////////////////////
31

32
PolToolMain::PolToolMain() : ProgramMain() {}
4✔
33
///////////////////////////////////////////////////////////////////////////////
34

35
void PolToolMain::showHelp()
×
36
{
37
  ERROR_PRINTLN(
×
38
      "Usage:\n"
39
      "    \n"
40
      "  POLTOOL mapdump [options]\n"
41
      "        Options:\n"
42
      "            x1 y1 [x2 y2 realm]       writes polmap info to polmap.html\n"
43
      "  POLTOOL uncompressgump FileName\n"
44
      "        unpacks and prints 0xDD gump from given packet log\n"
45
      "        file needs to contain a single 0xDD packetlog\n"
46
      "  POLTOOL testfiles [options]\n"
47
      "        Options:\n"
48
      "          outdir=.\n"
49
      "          hsa=0\n"
50
      "          maxtiles=0x3fff\n"
51
      "          width=6144\n"
52
      "          height=4096" );
53
}
×
54

55
int PolToolMain::mapdump()
×
56
{
57
  short wxl = 5485, wxh = 5500, wyl = 0, wyh = 30;
×
58
  const std::vector<std::string>& binArgs = programArgs();
×
59
  std::string realmname = "britannia";
×
60
  if ( binArgs.size() >= 7 )
×
61
  {
62
    realmname = binArgs[6];
×
63
  }
64
  Plib::RealmDescriptor descriptor = Plib::RealmDescriptor::Load(
×
65
      realmname.c_str() );  // TODO: use a string in the signature of Load()
×
66
  Plib::MapServer* mapserver = Plib::MapServer::Create( descriptor );
×
67
  std::unique_ptr<Plib::MapServer> _owner( mapserver );
×
68

69
  std::unique_ptr<Plib::MapTileServer> mts( new Plib::MapTileServer( descriptor ) );
×
70
  if ( binArgs.size() >= 4 )
×
71
  {
72
    wxl = wxh = static_cast<short>( atoi( binArgs[2].c_str() ) );
×
73
    wyl = wyh = static_cast<short>( atoi( binArgs[3].c_str() ) );
×
74
  }
75
  if ( binArgs.size() >= 6 )
×
76
  {
77
    wxh = static_cast<short>( atoi( binArgs[4].c_str() ) );
×
78
    wyh = static_cast<short>( atoi( binArgs[5].c_str() ) );
×
79
  }
80

81
  std::ofstream ofs( "polmap.html" );
×
82

83
  ofs << Plib::flagdescs() << std::endl;
×
84
  ofs << "<table border=1 cellpadding=5 cellspacing=0>" << std::endl;
×
85
  ofs << "<tr><td>&nbsp;</td>";
×
86
  for ( int x = wxl; x <= wxh; ++x )
×
87
  {
88
    ofs << "<td align=center>" << x << "</td>";
×
89
  }
90
  ofs << "</tr>" << std::endl;
×
91
  for ( unsigned short y = wyl; y <= wyh; ++y )
×
92
  {
93
    ofs << "<tr><td valign=center>" << y << "</td>" << std::endl;
×
94
    for ( unsigned short x = wxl; x <= wxh; ++x )
×
95
    {
96
      ofs << "<td align=left valign=top>";
×
97

98
      Plib::MAPCELL cell = mapserver->GetMapCell( x, y );
×
99
      Plib::MapShapeList mlist;
×
100
      mapserver->GetMapShapes( mlist, x, y, static_cast<u32>( Plib::FLAG::ALL ) );
×
101
      Plib::MAPTILE_CELL tile = mts->GetMapTile( x, y );
×
102

103
      ofs << "landtile=" << int( tile.landtile ) << "<br>";
×
104
      ofs << "tilez=" << int( tile.z ) << "<br>";
×
105
      ofs << "z=" << int( cell.z ) << "<br>";
×
106
      ofs << "flags=" << Plib::flagstr( cell.flags );
×
107

108
      for ( unsigned i = 1; i < mlist.size(); ++i )
×
109
      {
110
        ofs << "<br>" << "solid.z=" << int( mlist[i].z ) << "<br>"
×
111
            << "solid.height=" << int( mlist[i].height ) << "<br>"
×
112
            << "solid.flags=" << Plib::flagstr( mlist[i].flags );
×
113
      }
114

115
      ofs << "</td>" << std::endl;
×
116
    }
×
117
    ofs << "</tr>" << std::endl;
×
118
  }
119
  ofs << "</table>" << std::endl;
×
120
  return 0;
×
121
}
×
122

123
int PolToolMain::unpackCompressedGump()
×
124
{
125
  const std::vector<std::string>& binArgs = programArgs();
×
126
  if ( binArgs.size() < 3 )
×
127
  {
128
    showHelp();
×
129
    return 1;
×
130
  }
131
  if ( !Clib::FileExists( binArgs[2] ) )
×
132
    return 1;
×
133

134
  ifstream dmp( binArgs[2] );
×
135
  std::vector<unsigned char> bytes;
×
136
  dmp.setf( std::ios::hex );
×
137
  int per_line = 0;
×
138
  while ( dmp )
×
139
  {
140
    std::string tmp;
×
141
    while ( dmp )
×
142
    {
143
      char c;
144
      dmp.get( c );
×
145
      if ( c == ' ' )
×
146
      {
147
        break;
×
148
      }
NEW
149
      if ( per_line == 16 )  // both razor and pol have 16 bytes per line
×
150
      {
151
        if ( c == '\n' )
×
152
          per_line = 0;
×
153
      }
154
      else if ( isdigit( c ) )
×
155
        tmp += c;
×
156
      else if ( c >= 'A' && c <= 'Z' )
×
157
        tmp += c;
×
158
    }
159
    if ( tmp.size() == 2 )
×
160
    {
161
      int num = std::stoi( tmp, nullptr, 16 );
×
162
      bytes.push_back( static_cast<unsigned char>( num ) );
×
163
      ++per_line;
×
164
    }
165
  }
×
166

167
  size_t index = 0;
×
NEW
168
  auto toInt = [&]( size_t i ) -> unsigned int
×
169
  {
170
    return ( bytes[i] << 24 ) | ( bytes[i + 1] << 16 ) | ( bytes[i + 2] << 8 ) | ( bytes[i + 3] );
×
171
  };
×
172
  auto toShort = [&]( size_t i ) -> unsigned short { return ( bytes[i] << 8 ) | ( bytes[i + 1] ); };
×
173
  if ( bytes[index] != 0xdd )
×
174
    return 1;
×
175
  ++index;
×
176
  auto len = toShort( index );
×
177
  std::string msg = fmt::format( "len {}", len );
×
178
  index += 2;
×
179
  auto serial = toInt( index );
×
180
  index += 4;
×
181
  msg += fmt::format( " serial {}", serial );
×
182
  auto gumpid = static_cast<unsigned int>( toInt( index ) );
×
183
  index += 4;
×
184
  msg += fmt::format( " gumpID {}", gumpid );
×
185

186
  auto x = toInt( index );
×
187
  index += 4;
×
188
  msg += fmt::format( " x {}", x );
×
189
  auto y = toInt( index );
×
190
  index += 4;
×
191
  msg += fmt::format( " y {}", y );
×
192
  INFO_PRINTLN( msg );
×
193
  auto cbuflen = toInt( index ) - 4;
×
194
  index += 4;
×
195
  auto datalen = static_cast<unsigned long>( toInt( index ) );
×
196
  index += 4;
×
197
  std::unique_ptr<unsigned char[]> uncompressed( new unsigned char[datalen] );
×
198
  int res = uncompress( uncompressed.get(), &datalen, &bytes.data()[index], cbuflen );
×
199
  if ( res < 0 )
×
200
    return 1;
×
201
  index += cbuflen;
×
202
  std::string layout( uncompressed.get(), uncompressed.get() + datalen - 1 );
×
203
  msg = '\n';
×
204
  for ( const auto& c : layout )
×
205
  {
206
    msg += c;
×
207
    if ( c == '}' )
×
208
      msg += '\n';
×
209
  }
210
  INFO_PRINTLN( msg );
×
211

212
  auto linecount = toInt( index );
×
213
  index += 4;
×
214
  cbuflen = toInt( index ) - 4;
×
215
  index += 4;
×
216
  datalen = static_cast<unsigned long>( toInt( index ) );
×
217
  index += 4;
×
218
  std::unique_ptr<unsigned char[]> uncompressed2( new unsigned char[datalen] );
×
219
  res = uncompress( uncompressed2.get(), &datalen, &bytes.data()[index], cbuflen );
×
220
  if ( res < 0 )
×
221
    return 1;
×
222
  std::string layout2( uncompressed2.get(), uncompressed2.get() + datalen );
×
223
  msg = "\n\n";
×
224
  size_t j = 0;
×
225
  for ( size_t i = 0; i < linecount; ++i )
×
226
  {
227
    unsigned short wc = ( uncompressed2[j] << 8 ) | ( uncompressed2[j + 1] );
×
228
    if ( wc > 0 )
×
229
    {
230
      std::u16string u16s( reinterpret_cast<const char16_t*>( &uncompressed2[j + 2] ), wc );
×
231
      std::string u8_conv;
×
232
      for ( auto c : u16s )
×
233
      {
234
        c = ctBEu16( c );
×
235
        if ( c <= 256 )
×
236
          u8_conv += static_cast<char>( c );
×
237
        else
238
        {
239
          u8_conv += static_cast<char>( c & 0xff );
×
240
          u8_conv += static_cast<char>( ( c >> 8 ) & 0xff );
×
241
        }
242
      }
243
      msg += '"' + u8_conv + "\"\n";
×
244
    }
×
245
    else
246
      msg += "\"\"\n";
×
247
    j += 2 + wc * 2;
×
248
  }
249
  INFO_PRINTLN( msg );
×
250
  return 0;
×
251
}
×
252

253
int PolToolMain::main()
4✔
254
{
255
  const std::vector<std::string>& binArgs = programArgs();
4✔
256

257
  /**********************************************
258
   * show help
259
   **********************************************/
260
  if ( binArgs.size() == 1 )
4✔
261
  {
262
    showHelp();
×
263
    return 0;  // return "okay"
×
264
  }
265

266
  /**********************************************
267
   * execute the map dumping
268
   **********************************************/
269
  if ( binArgs[1] == "mapdump" )
4✔
270
  {
271
    return mapdump();
×
272
  }
273
  if ( binArgs[1] == "uncompressgump" )
4✔
274
  {
275
    return unpackCompressedGump();
×
276
  }
277
  if ( binArgs[1] == "testfiles" )
4✔
278
  {
279
    std::string outdir = programArgsFindEquals( "outdir=", "." );
3✔
280
    bool hsa = programArgsFindEquals( "hsa=", 0, false ) != 0 ? true : false;
3✔
281
    int maxtiles = programArgsFindEquals( "maxtiles=", 0x3fff, true );
3✔
282
    int width = programArgsFindEquals( "width=", 6144, false );
3✔
283
    int height = programArgsFindEquals( "height=", 4096, false );
3✔
284
    int mapid = programArgsFindEquals( "mapid=", 0, false );
3✔
285
    PolTool::FileGenerator g( outdir, hsa, maxtiles, mapid, width, height );
3✔
286
    g.generateTiledata();
3✔
287
    g.generateMap();
3✔
288
    g.generateStatics();
3✔
289
    g.generateMultis();
3✔
290
    return 0;
3✔
291
  }
3✔
292
  if ( binArgs[1] == "baredistro" )
1✔
293
  {
294
    std::string outdir = programArgsFindEquals( "outdir=", "." );
×
295
    bool hsa = programArgsFindEquals( "hsa=", 0, false ) != 0 ? true : false;
×
296
    int maxtiles = programArgsFindEquals( "maxtiles=", 0x3fff, true );
×
297
    int width = programArgsFindEquals( "width=", 6144, false );
×
298
    int height = programArgsFindEquals( "height=", 4096, false );
×
299
    PolTool::BareDistro distro( outdir, hsa, maxtiles, width, height );
×
300
    distro.generate();
×
301
    return 0;
×
302
  }
×
303
  if ( binArgs[1] == "testenv" )
1✔
304
  {
305
    std::string outdir = programArgsFindEquals( "outdir=", "." );
1✔
306
    bool hsa = programArgsFindEquals( "hsa=", 0, false ) != 0 ? true : false;
1✔
307
    int maxtiles = programArgsFindEquals( "maxtiles=", 0x3fff, true );
1✔
308
    int width = programArgsFindEquals( "width=", 6144, false );
1✔
309
    int height = programArgsFindEquals( "height=", 4096, false );
1✔
310
    PolTool::TestEnv testenv( outdir, hsa, maxtiles, width, height );
1✔
311
    testenv.generate();
1✔
312
    return 0;
1✔
313
  }
1✔
NEW
314
  ERROR_PRINTLN( "Unknown command {}", binArgs[1] );
×
NEW
315
  return 1;  // return "error"
×
316
}
317
}  // namespace Pol::Clib
318

319

320
///////////////////////////////////////////////////////////////////////////////
321
///////////////////////////////////////////////////////////////////////////////
322
///////////////////////////////////////////////////////////////////////////////
323

324
int main( int argc, char* argv[] )
4✔
325
{
326
  Pol::Clib::PolToolMain* PolToolMain = new Pol::Clib::PolToolMain();
4✔
327
  PolToolMain->start( argc, argv );
4✔
328
}
×
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