• 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

57.62
/pol-core/pol/target.cpp
1
/** @file
2
 *
3
 * @par History
4
 * - 2009/07/23 MuadDib:   updates for new Enum::Packet Out ID
5
 * - 2009/09/03 MuadDib:   Relocation of account related cpp/h
6
 *                         Relocation of multi related cpp/h
7
 */
8

9

10
#include "target.h"
11

12
#include <stddef.h>
13

14
#include "../clib/clib_endian.h"
15
#include "../clib/logfacility.h"
16
#include "../clib/rawtypes.h"
17
#include "../plib/systemstate.h"
18
#include "fnsearch.h"
19
#include "globals/uvars.h"
20
#include "item/itemdesc.h"
21
#include "mobile/charactr.h"
22
#include "multi/multi.h"
23
#include "network/cgdata.h"
24
#include "network/client.h"
25
#include "network/packethelper.h"
26
#include "network/packets.h"
27
#include "network/pktboth.h"
28
#include "polclass.h"
29
#include "realms/realm.h"
30
#include "regions/guardrgn.h"
31
#include "systems/suspiciousacts.h"
32
#include "ufunc.h"
33
#include "uobject.h"
34

35

36
namespace Pol::Core
37
{
38
void handle_target_cursor( Network::Client* client, PKTBI_6C* msg )
4✔
39
{
40
  Mobile::Character* targetter = client->chr;
4✔
41

42
  if ( !client->gd->tcursor2 )
4✔
43
  {
44
    SuspiciousActs::OutOfSequenceCursor( client );
×
45
    return;
×
46
  }
47
  client->gd->tcursor2->handle_target_cursor( targetter, msg );
4✔
48
}
49

50
/*
51
Target Cursor messages come in different forms:
52
1) Item selected:
53
'create': 0
54
target_cursor_serial: serial of cursor
55
unk6: 0
56
selected_serial: serial of selected item
57
x: x-pos of selected item
58
y: y-pos of selected item
59
unk15: 0
60
z: z-pos of selected item
61
objtype: objtype of selected item
62
2) Character selected:
63
same as for (1)
64
3) Cursor Cancelled:
65
create is 0
66
target_cursor_serial: serial of cursor
67
unk6: 0
68
selected_serial: 0
69
x: 0xffff
70
y: 0xffff
71
unk15: 0
72
z: 0
73
objtype: 0
74
4) Static targetted:
75
create is 1
76
target_cursor_serial: serial of cursor
77
unk6: 0
78
selected_serial: 0
79
x: x-pos
80
y: y-pos
81
unk15: 0
82
z: z-pos
83
objtype: objtype of item
84
5) Backpack on a paperdoll selected
85
create is 0
86
target_cursor_serial: serial of cursor
87
cursor_type: 0
88
selected_serial: serial of backpack
89
x: 0xffff
90
y: 0xffff
91
unk15: 0
92
z: 0
93
objtype: objtype of backpack
94
*/
95

96
/*
97
struct {
98
void (*func)(Client *client, PKTBI_6C *msg);
99
} target_handlers[ MAX_CURSORS ];
100
*/
101

102
TargetCursor::TargetCursor( bool inform_on_cancel ) : inform_on_cancel_( inform_on_cancel )
36✔
103
{
104
  cursorid_ = gamestate.target_cursors._cursorid_count++;
36✔
105
}
36✔
106

107
// FIXME we need something like is done for item menus, where we check
108
// to make sure that he client has any business using this menu - in this
109
// case, we need to make sure the client is supposed to have an active cursor.
110

111
bool TargetCursor::send_object_cursor( Network::Client* client, PKTBI_6C::CURSOR_TYPE crstype )
3✔
112
{
113
  if ( !client->chr->target_cursor_busy() )
3✔
114
  {
115
    Network::PktHelper::PacketOut<Network::PktOut_6C> msg;
3✔
116
    msg->Write<u8>( PKTBI_6C::UNK1_00 );
3✔
117
    msg->WriteFlipped<u32>( cursorid_ );
3✔
118
    msg->Write<u8>( crstype );
3✔
119
    // rest 0
120
    msg.Send( client, sizeof msg->buffer );
3✔
121
    client->gd->tcursor2 = this;
3✔
122
    return true;
3✔
123
  }
3✔
124

NEW
125
  return false;
×
126
}
127

128
void TargetCursor::cancel( Mobile::Character* chr )
×
129
{
130
  if ( chr->client )
×
131
    chr->client->gd->tcursor2 = nullptr;
×
132
  if ( inform_on_cancel_ )
×
133
    on_target_cursor( chr, nullptr );
×
134
}
×
135

136
void TargetCursor::handle_target_cursor( Mobile::Character* chr, PKTBI_6C* msg )
4✔
137
{
138
  u32 target_cursor_serial = cfBEu32( msg->target_cursor_serial );
4✔
139
  if ( target_cursor_serial != cursorid_ )
4✔
140
  {
141
    if ( target_cursor_serial != 0 )
×
142
      SuspiciousActs::OutOfSequenceCursor( chr->client );
×
143
    cancel( chr );
×
144
    return;
×
145
  }
146
  if ( msg->selected_serial != 0 )  // targetted something
4✔
147
  {
148
    if ( chr->dead() )  // but is dead
3✔
149
    {
150
      if ( chr->client != nullptr )
×
151
        send_sysmessage( chr->client, "I am dead and cannot do that." );
×
152
      cancel( chr );
×
153
      return;
×
154
    }
155

156
    if ( ( chr->frozen() || chr->paralyzed() ) && !chr->can_freemove() )
3✔
157
    {
158
      if ( chr->client != nullptr )
×
159
      {
160
        if ( chr->frozen() )
×
161
          private_say_above( chr, chr, "I am frozen and cannot do that." );
×
162
        else if ( chr->paralyzed() )
×
163
          private_say_above( chr, chr, "I am paralyzed and cannot do that." );
×
164
      }
165
      cancel( chr );
×
166
      return;
×
167
    }
168

169
    u32 selected_serial = cfBEu32( msg->selected_serial );
3✔
170
    UObject* obj = system_find_object( selected_serial );
3✔
171
    if ( obj != nullptr && obj->script_isa( POLCLASS_MOBILE ) && !obj->script_isa( POLCLASS_NPC ) )
3✔
172
    {
173
      Mobile::Character* targeted = find_character( selected_serial );
1✔
174
      // check for when char is not logged on
175
      if ( targeted != nullptr )
1✔
176
      {
177
        if ( !chr->is_visible_to_me( targeted ) )
1✔
178
        {
179
          cancel( chr );
×
180
          return;
×
181
        }
182

183
        if ( msg->cursor_type == 1 )
1✔
184
        {
185
          if ( ( JusticeRegion::RunNoCombatCheck( chr->client ) == true ) ||
2✔
186
               ( JusticeRegion::RunNoCombatCheck( targeted->client ) == true ) )
1✔
187
          {
188
            send_sysmessage( chr->client, "Combat is not allowed in this area." );
×
189
            cancel( chr );
×
190
            return;
×
191
          }
192
        }
193
      }
194
    }
195
  }
196

197
  if ( msg->x != 0xffff || msg->selected_serial != 0 )
4✔
198
  {
199
    if ( chr->client )
4✔
200
      chr->client->gd->tcursor2 = nullptr;
4✔
201
    on_target_cursor( chr, msg );
4✔
202
  }
203
  else
204
    cancel( chr );
×
205
}
206

207
FullMsgTargetCursor::FullMsgTargetCursor( void ( *func )( Mobile::Character*, PKTBI_6C* ) )
9✔
208
    : TargetCursor( false /* don't inform on cancel */ ), func( func )
9✔
209
{
210
}
9✔
211

212
void FullMsgTargetCursor::on_target_cursor( Mobile::Character* chr, PKTBI_6C* msg )
×
213
{
214
  ( *func )( chr, msg );
×
215
}
×
216

217

218
/******************************************************/
219
LosCheckedTargetCursor::LosCheckedTargetCursor( void ( *func )( Mobile::Character*, UObject* ),
6✔
220
                                                bool inform_on_cancel, bool allow_nonlocal )
6✔
221
    : TargetCursor( inform_on_cancel ), allow_nonlocal_( allow_nonlocal ), func( func )
6✔
222
{
223
}
6✔
224

225
void LosCheckedTargetCursor::on_target_cursor( Mobile::Character* chr, PKTBI_6C* msgin )
1✔
226
{
227
  if ( msgin == nullptr )
1✔
228
  {
229
    ( *func )( chr, nullptr );
×
230
    return;
1✔
231
  }
232

233
  u32 selected_serial = cfBEu32( msgin->selected_serial );
1✔
234

235
  UObject* uobj = find_toplevel_object( selected_serial );
1✔
236
  // FIXME inefficient, but neither works well by itself.
237
  bool additlegal = false;
1✔
238
  Mobile::Character* character_owner = nullptr;
1✔
239
  if ( uobj == nullptr )
1✔
240
    uobj = find_legal_item( chr, selected_serial, &additlegal );
1✔
241

242
  if ( uobj == nullptr )
1✔
243
    uobj = system_find_multi( selected_serial );
1✔
244

245
  if ( allow_nonlocal_ && uobj == nullptr )
1✔
246
  {
247
    uobj = find_snoopable_item( selected_serial, &character_owner );
1✔
248
    additlegal = false;
1✔
249
  }
250

251
  if ( uobj == nullptr )
1✔
252
  {
253
    if ( chr->client != nullptr )
×
254
      send_sysmessage( chr->client, "What you selected does not seem to exist." );
×
255
    if ( inform_on_cancel_ )
×
256
      ( *func )( chr, nullptr );
×
257
    return;
×
258
  }
259

260
  UObject* toplevel_owner = character_owner == nullptr ? uobj->toplevel_owner() : character_owner;
1✔
261

262
  if ( !additlegal && !chr->realm()->has_los( *chr, *toplevel_owner ) )
1✔
263
  {
264
    if ( chr->client != nullptr )
1✔
265
      send_sysmessage( chr->client, "That is not within your line of sight." );
1✔
266
    if ( inform_on_cancel_ )
1✔
267
      ( *func )( chr, nullptr );
1✔
268
    return;
1✔
269
  }
270

271
  ( *func )( chr, uobj );
×
272
}
273
/******************************************************/
274

275

276
/******************************************************/
277
NoLosCheckedTargetCursor::NoLosCheckedTargetCursor( void ( *func )( Mobile::Character*, UObject* ),
6✔
278
                                                    bool inform_on_cancel, bool allow_nonlocal )
6✔
279
    : TargetCursor( inform_on_cancel ), allow_nonlocal_( allow_nonlocal ), func( func )
6✔
280
{
281
}
6✔
282

283
void NoLosCheckedTargetCursor::on_target_cursor( Mobile::Character* chr, PKTBI_6C* msgin )
2✔
284
{
285
  if ( msgin == nullptr )
2✔
286
  {
287
    ( *func )( chr, nullptr );
×
288
    return;
×
289
  }
290

291
  u32 selected_serial = cfBEu32( msgin->selected_serial );
2✔
292

293
  UObject* uobj = find_toplevel_object( selected_serial );
2✔
294
  // FIXME inefficient, but neither works well by itself.
295
  bool additlegal = false;
2✔
296
  if ( uobj == nullptr )
2✔
297
    uobj = find_legal_item( chr, selected_serial, &additlegal );
1✔
298

299
  if ( uobj == nullptr )
2✔
300
    uobj = system_find_multi( selected_serial );
1✔
301

302
  if ( allow_nonlocal_ && uobj == nullptr )
2✔
303
    uobj = find_snoopable_item( selected_serial );
1✔
304

305
  if ( uobj == nullptr )
2✔
306
  {
307
    if ( chr->client != nullptr )
×
308
      send_sysmessage( chr->client, "What you selected does not seem to exist." );
×
309
    if ( inform_on_cancel_ )
×
310
      ( *func )( chr, nullptr );
×
311
    return;
×
312
  }
313

314
  ( *func )( chr, uobj );
2✔
315
}
316
/******************************************************/
317

318

319
LosCheckedCoordCursor::LosCheckedCoordCursor( void ( *func )( Mobile::Character*, PKTBI_6C* ),
3✔
320
                                              bool inform_on_cancel )
3✔
321
    : TargetCursor( inform_on_cancel ), func_( func )
3✔
322
{
323
}
3✔
324

325
bool LosCheckedCoordCursor::send_coord_cursor( Network::Client* client )
1✔
326
{
327
  if ( !client->chr->target_cursor_busy() )
1✔
328
  {
329
    Network::PktHelper::PacketOut<Network::PktOut_6C> msg;
1✔
330
    msg->Write<u8>( PKTBI_6C::UNK1_01 );
1✔
331
    msg->WriteFlipped<u32>( cursorid_ );
1✔
332
    msg->Write<u8>( PKTBI_6C::CURSOR_TYPE_NEUTRAL );
1✔
333
    // rest 0
334
    msg.Send( client, sizeof msg->buffer );
1✔
335
    client->gd->tcursor2 = this;
1✔
336
    return true;
1✔
337
  }
1✔
338

NEW
339
  return false;
×
340
}
341

342
void LosCheckedCoordCursor::on_target_cursor( Mobile::Character* chr, PKTBI_6C* msg )
1✔
343
{
344
  ( *func_ )( chr, msg );
1✔
345
}
1✔
346

347

348
MultiPlacementCursor::MultiPlacementCursor( void ( *func )( Mobile::Character*, PKTBI_6C* ) )
3✔
349
    : TargetCursor( true ), func_( func )
3✔
350
{
351
}
3✔
352

353
void MultiPlacementCursor::send_placemulti( Network::Client* client, unsigned int objtype,
×
354
                                            int flags, s16 xoffset, s16 yoffset, u32 hue )
355
{
356
  Network::PktHelper::PacketOut<Network::PktOut_99> msg;
×
357
  msg->Write<u8>( 0x1u );
×
358
  msg->WriteFlipped<u32>( cursorid_ );
×
359
  msg->offset += 12;  // 12x u8 unk
×
360
  u16 multiid = Items::find_multidesc( objtype ).multiid;
×
361
  multiid +=
×
362
      static_cast<u16>( ( flags & Multi::CRMULTI_FACING_MASK ) >> Multi::CRMULTI_FACING_SHIFT );
×
363
  msg->WriteFlipped<u16>( multiid );
×
364
  msg->WriteFlipped<s16>( xoffset );
×
365
  msg->WriteFlipped<s16>( yoffset );
×
366
  msg->offset += 2;  // u16 maybe_zoffset
×
367
  if ( client->ClientType & Network::CLIENTTYPE_7090 )
×
368
    msg->WriteFlipped<u32>( hue );
×
369
  msg.Send( client );
×
370
  client->gd->tcursor2 = this;
×
371
}
×
372

373
void MultiPlacementCursor::on_target_cursor( Mobile::Character* chr, PKTBI_6C* msg )
×
374
{
375
  ( *func_ )( chr, msg );
×
376
}
×
377

378

379
NoLosCharacterCursor::NoLosCharacterCursor( void ( *func )( Mobile::Character*,
9✔
380
                                                            Mobile::Character* ) )
9✔
381
    : TargetCursor( false /* don't inform on cancel */ ), func( func )
9✔
382
{
383
}
9✔
384

385
void NoLosCharacterCursor::on_target_cursor( Mobile::Character* targetter, PKTBI_6C* msgin )
×
386
{
387
  if ( msgin == nullptr )
×
388
    return;
×
389
  u32 selected_serial = cfBEu32( msgin->selected_serial );
×
390
  Mobile::Character* chr = find_character( selected_serial );
×
391
  if ( chr != nullptr )
×
392
    ( *func )( targetter, chr );
×
393
}
394

395
NoLosUObjectCursor::NoLosUObjectCursor( void ( *func )( Mobile::Character*, UObject* ),
×
396
                                        bool inform_on_cancel )
×
397
    : TargetCursor( inform_on_cancel ), func( func )
×
398
{
399
}
×
400

401
void NoLosUObjectCursor::on_target_cursor( Mobile::Character* targetter, PKTBI_6C* msgin )
×
402
{
403
  if ( msgin == nullptr )
×
404
  {
405
    ( *func )( targetter, nullptr );
×
406
    return;
×
407
  }
408
  u32 selected_serial = cfBEu32( msgin->selected_serial );
×
409

410
  UObject* obj = system_find_object( selected_serial );
×
411
  if ( obj )
×
412
  {
413
    ( *func )( targetter, obj );
×
414
  }
415
  else if ( inform_on_cancel_ )
×
416
  {
417
    ( *func )( targetter, nullptr );
×
418
  }
419
}
420

421
Cursors::Cursors()
3✔
422
    : _cursorid_count( 1 ),  // NOTE: the id is 1-based (seems that the stealth client has problem
3✔
423
                             // with serial==0)
424
      los_checked_script_cursor( Module::handle_script_cursor, true ),
3✔
425
      nolos_checked_script_cursor( Module::handle_script_cursor, true ),
3✔
426
      los_checked_allow_nonlocal_script_cursor( Module::handle_script_cursor, true, true ),
3✔
427
      nolos_checked_allow_nonlocal_script_cursor( Module::handle_script_cursor, true, true ),
3✔
428

429
      add_member_cursor( handle_add_member_cursor ),
3✔
430
      remove_member_cursor( handle_remove_member_cursor ),
3✔
431
      ident_cursor( handle_ident_cursor ),
3✔
432
      script_cursor2( Module::handle_coord_cursor, true ),
3✔
433
      multi_placement_cursor( Module::handle_coord_cursor ),
3✔
434
      repdata_cursor( show_repdata ),
3✔
435
      startlog_cursor( start_packetlog ),
3✔
436
      stoplog_cursor( stop_packetlog )
3✔
437
{
438
}
3✔
439
}  // namespace Pol::Core
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