Pol  Revision:cb584c9
clfunc.cpp
Go to the documentation of this file.
1 
10 #include "clfunc.h"
11 
12 #include <cstddef>
13 #include <string.h>
14 
15 #include "mobile/charactr.h"
16 #include "network/packethelper.h"
17 #include "pktdef.h"
18 #include "ufunc.h"
19 
20 namespace Pol
21 {
22 namespace Core
23 {
24 using namespace Network;
25 
26 void send_sysmessage_cl( Client* client, /*Character *chr_from, ObjArray* oText,*/
27  unsigned int cliloc_num, const u16* arguments, unsigned short font,
28  unsigned short color )
29 {
31  msg->offset += 2;
32  unsigned textlen = 0;
33 
34  if ( arguments != nullptr )
35  {
36  while ( arguments[textlen] != L'\0' )
37  ++textlen;
38  }
39 
40  if ( textlen > ( SPEECH_MAX_LEN ) )
41  textlen = SPEECH_MAX_LEN;
42 
43  msg->Write<u32>( 0xFFFFFFFFu ); // serial
44  msg->Write<u16>( 0xFFFFu ); // body
45  msg->Write<u8>( 6u ); // type 6 lower left, 7 on player
46  msg->WriteFlipped<u16>( color );
47  msg->WriteFlipped<u16>( font );
48  msg->WriteFlipped<u32>( cliloc_num );
49  msg->Write( "System", 30, false );
50  if ( arguments != nullptr )
51  msg->Write( arguments, static_cast<u16>( textlen ), true ); // ctLEu16
52  else
53  msg->offset += 2;
54  u16 len = msg->offset;
55  msg->offset = 1;
56  msg->WriteFlipped<u16>( len );
57  msg.Send( client, len );
58 }
59 
60 void say_above_cl( UObject* obj, unsigned int cliloc_num, const u16* arguments, unsigned short font,
61  unsigned short color )
62 {
64  msg->offset += 2;
65  unsigned textlen = 0;
66 
67  if ( arguments != nullptr )
68  {
69  while ( arguments[textlen] != L'\0' )
70  ++textlen;
71  }
72 
73  if ( textlen > ( SPEECH_MAX_LEN ) )
74  textlen = SPEECH_MAX_LEN;
75 
76  msg->Write<u32>( obj->serial_ext );
77  msg->WriteFlipped<u16>( obj->graphic ); // body
78  msg->Write<u8>( 7u ); // type 6 lower left, 7 on player
79  msg->WriteFlipped<u16>( color );
80  msg->WriteFlipped<u16>( font );
81  msg->WriteFlipped<u32>( cliloc_num );
82  msg->Write( obj->description().c_str(), 30, false );
83  if ( arguments != nullptr )
84  msg->Write( arguments, static_cast<u16>( textlen ), true ); // ctLEu16
85  else
86  msg->offset += 2;
87  u16 len = msg->offset;
88  msg->offset = 1;
89  msg->WriteFlipped<u16>( len );
90  // MuadDib - FIXME: only send to those that I'm visible to.
91  transmit_to_inrange( obj, &msg->buffer, len );
92 }
93 
94 void private_say_above_cl( Mobile::Character* chr, const UObject* obj, unsigned int cliloc_num,
95  const u16* arguments, unsigned short font, unsigned short color )
96 {
98  msg->offset += 2;
99  unsigned textlen = 0;
100 
101  if ( arguments != nullptr )
102  {
103  while ( arguments[textlen] != L'\0' )
104  ++textlen;
105  }
106 
107  if ( textlen > ( SPEECH_MAX_LEN ) )
108  textlen = SPEECH_MAX_LEN;
109 
110  msg->Write<u32>( obj->serial_ext );
111  msg->WriteFlipped<u16>( obj->graphic ); // body
112  msg->Write<u8>( 7u ); // type 6 lower left, 7 on player
113  msg->WriteFlipped<u16>( color );
114  msg->WriteFlipped<u16>( font );
115  msg->WriteFlipped<u32>( cliloc_num );
116  msg->Write( obj->description().c_str(), 30, false );
117  if ( arguments != nullptr )
118  msg->Write( arguments, static_cast<u16>( textlen ), true ); // ctLEu16
119  else
120  msg->offset += 2;
121  u16 len = msg->offset;
122  msg->offset = 1;
123  msg->WriteFlipped<u16>( len );
124  msg.Send( chr->client, len );
125 }
126 
127 
128 void send_sysmessage_cl_affix( Client* client, unsigned int cliloc_num, const char* affix,
129  bool prepend, const u16* arguments, unsigned short font,
130  unsigned short color )
131 {
133  msg->offset += 2;
134  unsigned textlen = 0, affix_len = 0;
135 
136  if ( arguments != nullptr )
137  {
138  while ( arguments[textlen] != L'\0' )
139  ++textlen;
140  }
141  affix_len = static_cast<unsigned>( strlen( affix ) + 1 );
142  if ( affix_len > SPEECH_MAX_LEN + 1 )
143  affix_len = SPEECH_MAX_LEN + 1;
144 
145  if ( textlen > ( SPEECH_MAX_LEN ) )
146  textlen = SPEECH_MAX_LEN;
147 
148  msg->Write<u32>( 0xFFFFFFFFu ); // serial
149  msg->Write<u16>( 0xFFFFu ); // body
150  msg->Write<u8>( 6u ); // type 6 lower left, 7 on player
151  msg->WriteFlipped<u16>( color );
152  msg->WriteFlipped<u16>( font );
153  msg->WriteFlipped<u32>( cliloc_num );
154  msg->Write<u8>( ( prepend ) ? 1u : 0u );
155  msg->Write( "System", 30, false );
156  msg->Write( affix, static_cast<u16>( affix_len ) );
157  if ( arguments != nullptr )
158  msg->WriteFlipped( arguments, static_cast<u16>( textlen ), true );
159  else
160  msg->offset += 2;
161  u16 len = msg->offset;
162  msg->offset = 1;
163  msg->WriteFlipped<u16>( len );
164  msg.Send( client, len );
165 }
166 
167 void say_above_cl_affix( UObject* obj, unsigned int cliloc_num, const char* affix, bool prepend,
168  const u16* arguments, unsigned short font, unsigned short color )
169 {
171  msg->offset += 2;
172  unsigned textlen = 0, affix_len = 0;
173 
174  if ( arguments != nullptr )
175  {
176  while ( arguments[textlen] != L'\0' )
177  ++textlen;
178  }
179  affix_len = static_cast<unsigned>( strlen( affix ) + 1 );
180  if ( affix_len > SPEECH_MAX_LEN + 1 )
181  affix_len = SPEECH_MAX_LEN + 1;
182 
183  if ( textlen > ( SPEECH_MAX_LEN ) )
184  textlen = SPEECH_MAX_LEN;
185 
186  msg->Write<u32>( obj->serial_ext ); // serial
187  msg->WriteFlipped<u16>( obj->graphic ); // body
188  msg->Write<u8>( 7u ); // type 6 lower left, 7 on player
189  msg->WriteFlipped<u16>( color );
190  msg->WriteFlipped<u16>( font );
191  msg->WriteFlipped<u32>( cliloc_num );
192  msg->Write<u8>( ( prepend ) ? 1u : 0u );
193  msg->Write( obj->description().c_str(), 30, false );
194  msg->Write( affix, static_cast<u16>( affix_len ) );
195  if ( arguments != nullptr )
196  msg->WriteFlipped( arguments, static_cast<u16>( textlen ), true ); // ctLEu16
197  else
198  msg->offset += 2;
199  u16 len = msg->offset;
200  msg->offset = 1;
201  msg->WriteFlipped<u16>( len );
202 
203  // MuadDib - FIXME: only send to those that I'm visible to.
204  transmit_to_inrange( obj, &msg->buffer, len );
205 }
206 
208  unsigned int cliloc_num, const char* affix, bool prepend,
209  const u16* arguments, unsigned short font, unsigned short color )
210 {
212  msg->offset += 2;
213  unsigned textlen = 0, affix_len = 0;
214 
215  if ( arguments != nullptr )
216  {
217  while ( arguments[textlen] != L'\0' )
218  ++textlen;
219  }
220  affix_len = static_cast<unsigned>( strlen( affix ) + 1 );
221  if ( affix_len > SPEECH_MAX_LEN + 1 )
222  affix_len = SPEECH_MAX_LEN + 1;
223 
224  if ( textlen > ( SPEECH_MAX_LEN ) )
225  textlen = SPEECH_MAX_LEN;
226 
227  msg->Write<u32>( obj->serial_ext ); // serial
228  msg->WriteFlipped<u16>( obj->graphic ); // body
229  msg->Write<u8>( 7u ); // type 6 lower left, 7 on player
230  msg->WriteFlipped<u16>( color );
231  msg->WriteFlipped<u16>( font );
232  msg->WriteFlipped<u32>( cliloc_num );
233  msg->Write<u8>( ( prepend ) ? 1u : 0u );
234  msg->Write( obj->description().c_str(), 30, false );
235  msg->Write( affix, static_cast<u16>( affix_len ) );
236  if ( arguments != nullptr )
237  msg->WriteFlipped( arguments, static_cast<u16>( textlen ), true );
238  else
239  msg->offset += 2;
240  u16 len = msg->offset;
241  msg->offset = 1;
242  msg->WriteFlipped<u16>( len );
243 
244  msg.Send( chr->client, len );
245 }
246 
247 void build_sysmessage_cl( PktOut_C1* msg, unsigned int cliloc_num, const u16* arguments,
248  unsigned short font, unsigned short color )
249 {
250  msg->offset += 2;
251  unsigned textlen = 0;
252 
253  if ( arguments != nullptr )
254  {
255  while ( arguments[textlen] != L'\0' )
256  ++textlen;
257  }
258 
259  if ( textlen > ( SPEECH_MAX_LEN ) )
260  textlen = SPEECH_MAX_LEN;
261 
262  msg->Write<u32>( 0xFFFFFFFFu ); // serial
263  msg->Write<u16>( 0xFFFFu ); // body
264  msg->Write<u8>( 6u ); // type 6 lower left, 7 on player
265  msg->WriteFlipped<u16>( color );
266  msg->WriteFlipped<u16>( font );
267  msg->WriteFlipped<u32>( cliloc_num );
268  msg->Write( "System", 30, false );
269  if ( arguments != nullptr )
270  msg->Write( arguments, static_cast<u16>( textlen ), true ); // ctLEu16
271  else
272  msg->offset += 2;
273  u16 len = msg->offset;
274  msg->offset = 1;
275  msg->WriteFlipped<u16>( len );
276  msg->offset = len;
277 }
278 
279 void build_sysmessage_cl_affix( PktOut_CC* msg, unsigned int cliloc_num, const char* affix,
280  bool prepend, const u16* arguments, unsigned short font,
281  unsigned short color )
282 {
283  msg->offset += 2;
284  unsigned textlen = 0, affix_len = 0;
285 
286  if ( arguments != nullptr )
287  {
288  while ( arguments[textlen] != L'\0' )
289  ++textlen;
290  }
291  affix_len = static_cast<unsigned>( strlen( affix ) + 1 );
292  if ( affix_len > SPEECH_MAX_LEN + 1 )
293  affix_len = SPEECH_MAX_LEN + 1;
294 
295  if ( textlen > ( SPEECH_MAX_LEN ) )
296  textlen = SPEECH_MAX_LEN;
297 
298  msg->Write<u32>( 0xFFFFFFFu ); // serial
299  msg->Write<u16>( 0xFFFFu ); // body
300  msg->Write<u8>( 6u ); // type 6 lower left, 7 on player
301  msg->WriteFlipped<u16>( color );
302  msg->WriteFlipped<u16>( font );
303  msg->WriteFlipped<u32>( cliloc_num );
304  msg->Write<u8>( ( prepend ) ? 1u : 0u );
305  msg->Write( "System", 30, false );
306  msg->Write( affix, static_cast<u16>( affix_len ) );
307  if ( arguments != nullptr )
308  msg->WriteFlipped( arguments, static_cast<u16>( textlen ), true );
309  else
310  msg->offset += 2;
311  u16 len = msg->offset;
312  msg->offset = 1;
313  msg->WriteFlipped<u16>( len );
314  msg->offset = len;
315 }
316 }
317 }
unsigned char u8
Definition: rawtypes.h:25
void private_say_above_cl_affix(Mobile::Character *chr, const UObject *obj, unsigned int cliloc_num, const char *affix, bool prepend, const u16 *arguments, unsigned short font, unsigned short color)
Definition: clfunc.cpp:207
void build_sysmessage_cl_affix(PktOut_CC *msg, unsigned int cliloc_num, const char *affix, bool prepend, const u16 *arguments, unsigned short font, unsigned short color)
Definition: clfunc.cpp:279
void send_sysmessage_cl(Client *client, unsigned int cliloc_num, const u16 *arguments, unsigned short font, unsigned short color)
Definition: clfunc.cpp:26
std::enable_if< std::is_same< T, N >::value, void >::type Write(N x)
Definition: packets.h:186
Network::Client * client
Definition: charactr.h:871
void transmit_to_inrange(const UObject *center, const void *msg, unsigned msglen)
Definition: ufunc.cpp:1511
#define SPEECH_MAX_LEN
Definition: pktdef.h:27
unsigned short u16
Definition: rawtypes.h:26
unsigned int u32
Definition: rawtypes.h:27
void build_sysmessage_cl(PktOut_C1 *msg, unsigned int cliloc_num, const u16 *arguments, unsigned short font, unsigned short color)
Definition: clfunc.cpp:247
std::enable_if< std::is_same< T, N >::value, void >::type WriteFlipped(N x)
Definition: packets.h:217
void Send(Client *client, int len=-1) const
Definition: packethelper.h:69
void say_above_cl_affix(UObject *obj, unsigned int cliloc_num, const char *affix, bool prepend, const u16 *arguments, unsigned short font, unsigned short color)
Definition: clfunc.cpp:167
void send_sysmessage_cl_affix(Client *client, unsigned int cliloc_num, const char *affix, bool prepend, const u16 *arguments, unsigned short font, unsigned short color)
Definition: clfunc.cpp:128
virtual std::string description() const
Definition: uobject.cpp:201
void say_above_cl(UObject *obj, unsigned int cliloc_num, const u16 *arguments, unsigned short font, unsigned short color)
Definition: clfunc.cpp:60
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