Pol  Revision:cb584c9
irequest.cpp
Go to the documentation of this file.
1 
9 #include <stddef.h>
10 
11 #include "../bscript/eprog.h"
12 #include "../clib/clib_endian.h"
13 #include "../clib/logfacility.h"
14 #include "../clib/rawtypes.h"
15 #include "../clib/refptr.h"
16 #include "../plib/systemstate.h"
17 #include "globals/network.h"
18 #include "globals/settings.h"
19 #include "mobile/attribute.h"
20 #include "mobile/charactr.h"
21 #include "network/client.h"
22 #include "network/packethelper.h"
23 #include "network/packets.h"
24 #include "party.h"
25 #include "pktboth.h"
26 #include "pktdef.h"
27 #include "pktin.h"
28 #include "scrdef.h"
29 #include "scrstore.h"
30 #include "statmsg.h"
31 #include "ufunc.h"
32 #include "uoclient.h"
33 #include "uoskills.h"
34 
35 namespace Pol
36 {
37 namespace Core
38 {
39 void statrequest( Network::Client* client, u32 serial )
40 {
41  if ( serial == client->chr->serial )
42  {
43  send_full_statmsg( client, client->chr );
44  }
45  else
46  {
47  Mobile::Character* chr = find_character( serial );
48  if ( chr != nullptr )
49  {
50  if ( client->chr->is_visible_to_me( chr ) )
51  {
52  if ( inrange( client->chr, chr ) )
53  send_short_statmsg( client, chr );
54  }
55  }
56  }
57 }
58 
59 void send_skillmsg( Network::Client* client, const Mobile::Character* chr )
60 {
62  msg->offset += 2;
64  msg->Write<u8>( PKTBI_3A_VALUES::FULL_LIST_CAP );
65  else
66  msg->Write<u8>( PKTBI_3A_VALUES::FULL_LIST );
67 
68  for ( unsigned short i = 0; i <= networkManager.uoclient_general.maxskills; ++i )
69  {
70  const UOSkill& uoskill = GetUOSkill( i );
71  msg->WriteFlipped<u16>( static_cast<u16>( i + 1 ) ); // for some reason, we send this 1-based
72  if ( uoskill.pAttr )
73  {
74  const Mobile::AttributeValue& av = chr->attribute( uoskill.pAttr->attrid );
75  int value;
76  value = av.effective_tenths();
77  if ( value > 0xFFFF )
78  value = 0xFFFF;
79  msg->WriteFlipped<u16>( static_cast<u16>( value ) );
80 
81  value = av.base();
82  if ( value > 0xFFFF )
83  value = 0xFFFF;
84  msg->WriteFlipped<u16>( static_cast<u16>( value ) );
85  msg->Write<u8>( av.lock() );
87  msg->WriteFlipped<u16>( av.cap() );
88  }
89  else
90  {
91  msg->offset += 4; // u16 value/value_unmod
92  msg->Write<u8>( PKTBI_3A_VALUES::LOCK_DOWN );
94  msg->WriteFlipped<u16>( settingsManager.ssopt.default_attribute_cap );
95  }
96  }
98  msg->offset += 2; // u16 nullterm
99  u16 len = msg->offset;
100  msg->offset = 1;
101  msg->WriteFlipped<u16>( len );
102  msg.Send( client, len );
103 }
104 
106 {
108  {
109  unsigned int skillid = cfBEu16( msg->skillid );
110  if ( skillid > networkManager.uoclient_general.maxskills )
111  return;
112 
113  const UOSkill& uoskill = GetUOSkill( skillid );
114  if ( !uoskill.pAttr ) // tried to set lockstate for a skill that isn't defined
115  return;
116 
117  if ( msg->lock_mode < 3 )
118  client->chr->attribute( uoskill.pAttr->attrid ).lock( msg->lock_mode );
119  else
120  INFO_PRINT << "Client " << client->chr->name() << " tried to set an illegal lock state.\n";
121  }
122 }
123 
124 void skillrequest( Network::Client* client, u32 serial )
125 {
126  if ( serial == client->chr->serial )
127  {
128  ScriptDef sd;
129  sd.quickconfig( "scripts/misc/skillwin.ecl" );
130  if ( sd.exists() )
131  {
133  prog = find_script2( sd,
134  false, // complain if not found
135  Plib::systemstate.config.cache_interactive_scripts );
136  if ( prog.get() != nullptr && client->chr->start_script( prog.get(), false ) )
137  {
138  return;
139  }
140  }
141  send_skillmsg( client, client->chr );
142  }
143 }
144 
145 void srequest( Network::Client* client, PKTIN_34* msg )
146 {
147  u32 serial = cfBEu32( msg->serial2 );
148 
149  if ( msg->stattype == STATTYPE_STATWINDOW )
150  {
151  if ( client->chr->serial == serial )
152  statrequest( client, serial );
153  else
154  {
155  Mobile::Character* bob = find_character( serial );
156  if ( bob == nullptr )
157  return;
158  if ( !client->chr->is_concealed_from_me( bob ) && client->chr->is_visible_to_me( bob ) )
159  {
160  if ( pol_distance( client->chr->x, client->chr->y, bob->x, bob->y ) < 20 )
161  statrequest( client, serial );
162  }
163  if ( client->chr->has_party() )
164  client->chr->party()->send_stat_to( client->chr, bob );
165  }
166  }
167  else if ( msg->stattype == STATTYPE_SKILLWINDOW )
168  skillrequest( client, serial );
169 }
170 }
171 }
unsigned char u8
Definition: rawtypes.h:25
ref_ptr< Bscript::EScriptProgram > find_script2(const ScriptDef &script, bool complain_if_not_found, bool cache_script)
Definition: scrstore.cpp:83
void quickconfig(const Plib::Package *pkg, const std::string &name_ecl)
Definition: scrdef.cpp:112
unsigned char lock() const
Definition: charactr.h:174
const Mobile::Attribute * pAttr
Definition: uoskills.h:38
SystemState systemstate
Definition: systemstate.cpp:12
void send_short_statmsg(Network::Client *client, Mobile::Character *chr)
Definition: statmsg.cpp:235
unsigned short cap() const
Definition: charactr.h:176
#define cfBEu32(x)
Definition: clib_endian.h:43
T * get() const
Definition: refptr.h:176
bool is_visible_to_me(const Character *chr) const
Definition: charactr.cpp:2658
bool inrange(const UObject *c1, unsigned short x, unsigned short y)
Definition: ufunc.cpp:454
unsigned short default_attribute_cap
Definition: ssopt.h:70
Mobile::Character * chr
Definition: client.h:182
unsigned short u16
Definition: rawtypes.h:26
unsigned int u32
Definition: rawtypes.h:27
unsigned short maxskills
Definition: uoclient.h:55
bool exists() const
Definition: scrdef.cpp:126
const UOSkill & GetUOSkill(unsigned skillid)
Definition: uoskills.cpp:21
void srequest(Network::Client *client, PKTIN_34 *msg)
Definition: irequest.cpp:145
NetworkManager networkManager
Definition: network.cpp:28
void Send(Client *client, int len=-1) const
Definition: packethelper.h:69
const AttributeValue & attribute(unsigned attrid) const
Definition: charactr.h:1051
#define STATTYPE_SKILLWINDOW
Definition: pktdef.h:85
#define STATTYPE_STATWINDOW
Definition: pktdef.h:84
int effective_tenths() const
Definition: charactr.h:155
#define cfBEu16(x)
Definition: clib_endian.h:44
void send_full_statmsg(Network::Client *client, Mobile::Character *chr)
Definition: statmsg.cpp:32
Mobile::Character * find_character(u32 serial)
Definition: fnsearch.cpp:60
SettingsManager settingsManager
Definition: settings.cpp:14
bool is_concealed_from_me(const Character *chr) const
Definition: charactr.cpp:2653
void statrequest(Network::Client *client, u32 serial)
Definition: irequest.cpp:39
void skillrequest(Network::Client *client, u32 serial)
Definition: irequest.cpp:124
void handle_skill_lock(Network::Client *client, PKTBI_3A_LOCKS *msg)
Definition: irequest.cpp:105
unsigned short pol_distance(unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2)
Definition: ufunc.cpp:481
bool core_handled_locks
Definition: ssopt.h:65
bool start_script(Bscript::EScriptProgram *prog, bool start_attached, Bscript::BObjectImp *param2=nullptr, Bscript::BObjectImp *param3=nullptr, Bscript::BObjectImp *param4=nullptr)
Definition: chrituse.cpp:30
#define INFO_PRINT
Definition: logfacility.h:223
virtual std::string name() const
Definition: uobject.cpp:196
Definition: berror.cpp:12
void send_skillmsg(Network::Client *client, const Mobile::Character *chr)
Definition: irequest.cpp:59
UoClientGeneral uoclient_general
Definition: network.h:67