Pol  Revision:3cfda13
clmod.cpp
Go to the documentation of this file.
1 
8 #include "clmod.h"
9 
10 #include "../../bscript/berror.h"
11 #include "../../clib/passert.h"
12 #include "../../clib/rawtypes.h"
13 #include "../clfunc.h"
14 #include "../mobile/charactr.h"
15 #include "../pktdef.h"
16 #include "../unicode.h"
17 #include "../uoexhelp.h"
18 
19 namespace Pol
20 {
21 namespace Bscript
22 {
23 using namespace Module;
24 template <>
27 
28  {"SendSysMessageCL", &ClilocExecutorModule::mf_SendSysMessageCL},
29  {"PrintTextAboveCL", &ClilocExecutorModule::mf_PrintTextAboveCL},
30  {"PrintTextAbovePrivateCL", &ClilocExecutorModule::mf_PrintTextAbovePrivateCL}};
31 }
32 namespace Module
33 {
34 using namespace Bscript;
35 
37  : Bscript::TmplExecutorModule<ClilocExecutorModule>( "cliloc", exec )
38 {
39 }
40 
42 {
43  Mobile::Character* chr;
44  ObjArray* oText;
45  unsigned int cliloc_num;
46  unsigned short color;
47  unsigned short font;
48 
49  if ( getCharacterParam( exec, 0, chr ) && getParam( 1, cliloc_num ) &&
50  getObjArrayParam( 2, oText ) && getParam( 3, font ) && getParam( 4, color ) )
51  {
52  passert_paranoid( chr != nullptr && oText != nullptr );
53 
54  if ( !chr->has_active_client() )
55  return new BError( "Mobile has no active client" );
56 
57  if ( oText->ref_arr.size() > SPEECH_MAX_LEN )
58  return new BError( "Unicode array exceeds maximum size." );
59 
60  u16 cltext[( SPEECH_MAX_LEN + 1 )];
61  size_t textlen = oText->ref_arr.size();
62  if ( !Core::convertArrayToUC( oText, cltext, textlen, false ) )
63  return new BError( "Invalid value in Unicode array." );
64 
65  Core::send_sysmessage_cl( chr->client, cliloc_num, cltext, font, color );
66  return new BLong( 1 );
67  }
68  else
69  {
70  return new BError( "Invalid parameter type" );
71  }
72 }
73 
75 {
76  Core::UObject* obj;
77  ObjArray* oText;
78  unsigned int cliloc_num;
79  unsigned short color;
80  unsigned short font;
81 
82  if ( getUObjectParam( exec, 0, obj ) && getParam( 1, cliloc_num ) &&
83  getObjArrayParam( 2, oText ) && getParam( 3, font ) && getParam( 4, color ) )
84  {
85  passert_paranoid( oText != nullptr && obj != nullptr );
86 
87  if ( oText->ref_arr.size() > SPEECH_MAX_LEN )
88  return new BError( "Unicode array exceeds maximum size." );
89 
90 
91  u16 cltext[( SPEECH_MAX_LEN + 1 )];
92  size_t textlen = oText->ref_arr.size();
93  if ( !Core::convertArrayToUC( oText, cltext, textlen, false ) )
94  return new BError( "Invalid value in Unicode array." );
95 
96  say_above_cl( obj, cliloc_num, cltext, font, color );
97  return new BLong( 1 );
98  }
99  else
100  {
101  return new BError( "Invalid parameter type" );
102  }
103 }
104 
106 {
107  Mobile::Character* chr;
108  Core::UObject* obj;
109  ObjArray* oText;
110  unsigned int cliloc_num;
111  unsigned short color;
112  unsigned short font;
113 
114  if ( getCharacterParam( exec, 0, chr ) && getUObjectParam( exec, 1, obj ) &&
115  getParam( 2, cliloc_num ) && getObjArrayParam( 3, oText ) && getParam( 4, font ) &&
116  getParam( 5, color ) )
117  {
118  passert_paranoid( chr != nullptr && oText != nullptr && obj != nullptr );
119 
120  if ( !chr->has_active_client() )
121  return new BError( "Mobile has no active client" );
122 
123  if ( chr->realm != obj->realm )
124  return new BError( "Cannot print messages across realms!" );
125 
126  if ( oText->ref_arr.size() > SPEECH_MAX_LEN )
127  return new BError( "Unicode array exceeds maximum size." );
128 
129 
130  u16 cltext[( SPEECH_MAX_LEN + 1 )];
131  size_t textlen = oText->ref_arr.size();
132  if ( !Core::convertArrayToUC( oText, cltext, textlen, false ) )
133  return new BError( "Invalid value in Unicode array." );
134 
135  private_say_above_cl( chr, obj, cliloc_num, cltext, font, color );
136  return new BLong( 1 );
137  }
138  else
139  {
140  return new BError( "Invalid parameter type" );
141  }
142 }
143 }
144 }
void send_sysmessage_cl(Client *client, unsigned int cliloc_num, const u16 *arguments, unsigned short font, unsigned short color)
Definition: clfunc.cpp:26
ClilocExecutorModule(Bscript::Executor &exec)
Definition: clmod.cpp:36
Network::Client * client
Definition: charactr.h:871
#define SPEECH_MAX_LEN
Definition: pktdef.h:27
bool getParam(unsigned param, int &value)
Definition: execmodl.cpp:62
bool has_active_client() const
Definition: charactr.cpp:448
unsigned short u16
Definition: rawtypes.h:26
Bscript::BObjectImp * mf_PrintTextAboveCL()
Definition: clmod.cpp:74
bool getCharacterParam(Bscript::Executor &exec, unsigned param, Mobile::Character *&chrptr)
Definition: uoexhelp.cpp:140
bool convertArrayToUC(Bscript::ObjArray *&in_text, u16 *out_wtext, size_t textlen, bool ConvToBE, bool nullterm)
Definition: unicode.cpp:21
Bscript::BObjectImp * mf_PrintTextAbovePrivateCL()
Definition: clmod.cpp:105
bool getUObjectParam(Executor &exec, unsigned param, UObject *&objptr)
Definition: uoexhelp.cpp:369
Realms::Realm * realm
Definition: baseobject.h:56
bool getObjArrayParam(unsigned param, ObjArray *&pobjarr)
Definition: execmodl.cpp:57
Bscript::BObjectImp * mf_SendSysMessageCL()
Definition: clmod.cpp:41
void say_above_cl(UObject *obj, unsigned int cliloc_num, const u16 *arguments, unsigned short font, unsigned short color)
Definition: clfunc.cpp:60
#define passert_paranoid(exp)
Definition: passert.h:95
void private_say_above_cl(Mobile::Character *chr, const UObject *obj, unsigned int cliloc_num, const u16 *arguments, unsigned short font, unsigned short color)
Definition: clfunc.cpp:94
Definition: berror.cpp:12