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

polserver / polserver / 21100551564

17 Jan 2026 08:40PM UTC coverage: 60.504% (+0.01%) from 60.492%
21100551564

Pull #857

github

turleypol
fixed scope
Pull Request #857: ClangTidy readability-else-after-return

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

48 existing lines in 26 files now uncovered.

44445 of 73458 relevant lines covered (60.5%)

515341.61 hits per line

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

6.84
/pol-core/pol/module/unimod.cpp
1
/** @file
2
 *
3
 * @par History
4
 * - 2006/10/07 Shinigami: GCC 3.4.x fix - added "template<>" to TmplExecutorModule
5
 * - 2009/09/03 MuadDib:   Relocation of account related cpp/h
6
 */
7

8
#include "unimod.h"
9
#include <iostream>
10
#include <string.h>
11

12
#include "../../bscript/berror.h"
13
#include "../../bscript/bobject.h"
14
#include "../../bscript/impstr.h"
15
#include "../../clib/clib_endian.h"
16
#include "../../clib/logfacility.h"
17
#include "../accounts/account.h"
18
#include "../item/item.h"
19
#include "../mobile/charactr.h"
20
#include "../network/cgdata.h"
21
#include "../network/client.h"
22
#include "../network/packethelper.h"
23
#include "../network/packets.h"
24
#include "../network/pktboth.h"
25
#include "../network/pktdef.h"
26
#include "../ufunc.h"
27
#include "../uoexec.h"
28
#include "uomod.h"
29

30
#include <module_defs/unicode.h>
31

32
namespace Pol
33
{
34
namespace Core
35
{
36
using namespace Network;
37

38
void send_unicode_prompt( Client* client, u32 serial )
×
39
{
40
  PktHelper::PacketOut<PktOut_C2> msg;
×
41
  msg->WriteFlipped<u16>( Core::PKTBI_C2::SERVER_MSGLEN );
×
42
  msg->Write<u32>( serial );  // serial
×
43
  msg->Write<u32>( serial );  // msg_id  Server-"decided" message ID. o_O
×
44
  msg->offset += 10;          // 10x u8 unk
×
45
  msg.Send( client );
×
46
}
×
47

48
void handle_unicode_prompt( Client* client, Core::PKTBI_C2* msg )
×
49
{
50
  // TODO do we really need two of them, this can also be done differently
51
  Module::UnicodeExecutorModule* uniemod = client->gd->prompt_uniemod;
×
52
  Module::UOExecutorModule* uoemod = client->gd->prompt_uoemod;
×
53
  if ( uoemod == nullptr && uniemod == nullptr )
×
54
    return;  // log it?
×
55

56
  int textlen = ( ( cfBEu16( msg->msglen ) - offsetof( Core::PKTBI_C2, wtext ) ) /
×
57
                  sizeof( msg->wtext[0] ) );  // note NO terminator!
58
  if ( textlen < 0 )
×
59
    textlen = 0;
×
60
  if ( textlen > SPEECH_MAX_LEN )
×
61
  {
62
    textlen = SPEECH_MAX_LEN;  // ENHANCE: May want to log this
×
63
    msg->wtext[textlen] = 0x0000;
×
64
  }
65

66
  // client version of the packet should always send this as a 1??
67
  /*if ( cfBEu16( msg->unk ) != 0x01 )
68
  {
69
    // ENHANCE: May want to log this, too?
70
    ok = false;
71
    valstack = new BObject( new BError( "Malformed return-packet from client" ) );
72
  }*/
73

74
  char lang[4];
75
  memcpy( lang, msg->lang, 4 );
×
76

77
  // String::fromUTF16 performs all the error checks
78
  // "Invalid unicode" will be returned if completly broken, but do we really need to take care?
79
  if ( uniemod != nullptr && uniemod->prompt_chr != nullptr )
×
80
  {
81
    std::unique_ptr<Bscript::BStruct> retval( new Bscript::BStruct() );
×
82
    retval->addMember( "lang", new Bscript::String( lang ) );
×
83
    retval->addMember( "text",
×
84
                       new Bscript::String( Bscript::String::fromUTF16( msg->wtext, textlen ) ) );
×
85
    uniemod->exec.ValueStack.back().set( new Bscript::BObject( retval.release() ) );
×
86
    uniemod->uoexec().revive();
×
87
  }
×
88
  else if ( uoemod != nullptr && uoemod->prompt_chr != nullptr )
×
89
  {
90
    // called from uo module, directly return string
91
    uoemod->exec.ValueStack.back().set( new Bscript::BObject(
×
92
        new Bscript::String( Bscript::String::fromUTF16( msg->wtext, textlen ) ) ) );
×
93

94
    uoemod->uoexec().revive();
×
95
  }
96
  if ( uniemod != nullptr )
×
97
    uniemod->prompt_chr = nullptr;
×
98
  if ( uoemod != nullptr )
×
99
    uoemod->prompt_chr = nullptr;
×
100
  client->gd->prompt_uniemod = nullptr;
×
101
  client->gd->prompt_uoemod = nullptr;
×
102
}
103
//////////////////////////////////////////////////////////////////////////
104
}  // namespace Core
105
namespace Module
106
{
107
using namespace Bscript;
108

109
UnicodeExecutorModule::UnicodeExecutorModule( Core::UOExecutor& exec )
371✔
110
    : TmplExecutorModule<UnicodeExecutorModule, Core::PolModule>( exec ), prompt_chr( nullptr )
371✔
111
{
112
}
371✔
113

114
UnicodeExecutorModule::~UnicodeExecutorModule()
742✔
115
{
116
  if ( prompt_chr != nullptr )
371✔
117
  {
118
    prompt_chr->client->gd->prompt_uniemod = nullptr;
×
119
    prompt_chr = nullptr;
×
120
  }
121
}
742✔
122

123
BObjectImp* UnicodeExecutorModule::mf_BroadcastUC()
×
124
{
125
  const String* text;
126
  const String* lang;
127
  unsigned short font;
128
  unsigned short color;
129
  unsigned short requiredCmdLevel;
130
  if ( getUnicodeStringParam( 0, text ) && getStringParam( 1, lang ) &&
×
131
       getParam( 2, font ) &&             // todo: getFontParam
×
132
       getParam( 3, color ) &&            // todo: getColorParam
×
133
       getParam( 4, requiredCmdLevel ) )  // todo: getRequiredCmdLevelParam
×
134
  {
135
    if ( text->length() > SPEECH_MAX_LEN )
×
136
      return new BError( "Text exceeds maximum size." );
×
137
    if ( lang->length() != 3 )
×
138
      return new BError( "langcode must be a 3-character code." );
×
139
    Core::broadcast_unicode( text->value(), Clib::strupperASCII( lang->value() ), font, color,
×
140
                             requiredCmdLevel );
141
    return new BLong( 1 );
×
142
  }
143

NEW
144
  return new BError( "A parameter was invalid" );
×
145
}
146

147
BObjectImp* UnicodeExecutorModule::mf_PrintTextAboveUC()
×
148
{
149
  Core::UObject* obj;
150
  const String* text;
151
  const String* lang;
152
  unsigned short font;
153
  unsigned short color;
154
  int journal_print;
155

156
  if ( getUObjectParam( 0, obj ) && getUnicodeStringParam( 1, text ) && getStringParam( 2, lang ) &&
×
157
       getParam( 3, font ) && getParam( 4, color ) && getParam( 5, journal_print ) )
×
158
  {
159
    if ( text->length() > SPEECH_MAX_LEN )
×
160
      return new BError( "Text exceeds maximum size." );
×
161
    if ( lang->length() != 3 )
×
162
      return new BError( "langcode must be a 3-character code." );
×
163

164
    return new BLong( say_above_unicode( obj, text->value(), Clib::strupperASCII( lang->value() ),
×
165
                                         font, color, journal_print ) );
×
166
  }
167

NEW
168
  return new BError( "A parameter was invalid" );
×
169
}
170

171
BObjectImp* UnicodeExecutorModule::mf_PrintTextAbovePrivateUC()
×
172
{
173
  Mobile::Character* chr;
174
  Core::UObject* obj;
175
  const String* text;
176
  const String* lang;
177
  unsigned short font;
178
  unsigned short color;
179

180
  if ( getUObjectParam( 0, obj ) && getUnicodeStringParam( 1, text ) && getStringParam( 2, lang ) &&
×
181
       getCharacterParam( 3, chr ) && getParam( 4, font ) && getParam( 5, color ) )
×
182
  {
183
    if ( text->length() > SPEECH_MAX_LEN )
×
184
      return new BError( "Text exceeds maximum size." );
×
185
    if ( lang->length() != 3 )
×
186
      return new BError( "langcode must be a 3-character code." );
×
187

188
    return new BLong( private_say_above_unicode(
×
189
        chr, obj, text->value(), Clib::strupperASCII( lang->value() ), font, color ) );
×
190
  }
191

NEW
192
  return new BError( "A parameter was invalid" );
×
193
}
194

195
BObjectImp* UnicodeExecutorModule::mf_RequestInputUC()
×
196
{
197
  Mobile::Character* chr;
198
  Items::Item* item;
199
  const String* prompt;
200
  const String* lang;
201
  if ( getCharacterParam( 0, chr ) && getItemParam( 1, item ) &&
×
202
       getUnicodeStringParam( 2, prompt ) && getStringParam( 3, lang ) )
×
203
  {
204
    if ( !chr->has_active_client() )
×
205
    {
206
      return new BError( "No client attached" );
×
207
    }
208

209
    if ( chr->has_active_prompt() )
×
210
    {
211
      return new BError( "Another script has an active prompt" );
×
212
    }
213

214
    if ( prompt->length() > SPEECH_MAX_LEN )
×
215
      return new BError( "Prompt exceeds maximum size." );
×
216
    if ( lang->length() != 3 )
×
217
      return new BError( "langcode must be a 3-character code." );
×
218

219
    if ( !uoexec().suspend() )
×
220
    {
221
      DEBUGLOGLN(
×
222
          "Script Error in '{}' PC={}: \n"
223
          "\tCall to function Unicode::RequestInputUC():\n"
224
          "\tThe execution of this script can't be blocked!",
225
          scriptname(), exec.PC );
×
226
      return new Bscript::BError( "Script can't be blocked" );
×
227
    }
228

229
    Core::send_sysmessage_unicode( chr->client, prompt->value(),
×
230
                                   Clib::strupperASCII( lang->value() ) );
×
231

232
    chr->client->gd->prompt_uniemod = this;
×
233
    prompt_chr = chr;
×
234

235
    Core::send_unicode_prompt( chr->client, ctBEu32( item->serial ) );
×
236

237
    return new BLong( 0 );
×
238
  }
239

NEW
240
  return new BError( "A parameter was invalid" );
×
241
}
242

243
BObjectImp* UnicodeExecutorModule::mf_SendSysMessageUC()
×
244
{
245
  Mobile::Character* chr;
246
  const String* text;
247
  const String* lang;
248
  unsigned short font;
249
  unsigned short color;
250

251
  if ( getCharacterParam( 0, chr ) && getUnicodeStringParam( 1, text ) &&
×
252
       getStringParam( 2, lang ) && getParam( 3, font ) && getParam( 4, color ) )
×
253
  {
254
    if ( chr->has_active_client() )
×
255
    {
256
      if ( text->length() > SPEECH_MAX_LEN )
×
257
        return new BError( "Text exceeds maximum size." );
×
258
      if ( lang->length() != 3 )
×
259
        return new BError( "langcode must be a 3-character code." );
×
260

261
      Core::send_sysmessage_unicode( chr->client, text->value(),
×
262
                                     Clib::strupperASCII( lang->value() ), font, color );
×
263
      return new BLong( 1 );
×
264
    }
265

NEW
266
    return new BError( "Mobile has no active client" );
×
267
  }
268

NEW
269
  return new BError( "Invalid parameter type" );
×
270
}
271

272
BObjectImp* UnicodeExecutorModule::mf_SendTextEntryGumpUC()
×
273
{
274
  // SendTextEntryGumpUC(who, uc_text1, cancel := TE_CANCEL_ENABLE,
275
  //            style := TE_STYLE_NORMAL, maximum := 40, uc_text2 := {} );
276

277
  return new BError( "Function not implimented" );
×
278
}
279

280
size_t UnicodeExecutorModule::sizeEstimate() const
14✔
281
{
282
  return sizeof( *this );
14✔
283
}
284
}  // namespace Module
285
}  // 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