Pol  Revision:f37d500
cliface.cpp
Go to the documentation of this file.
1 
8 #include "cliface.h"
9 
10 #include <memory>
11 #include <stddef.h>
12 
13 #include "../../clib/rawtypes.h"
14 #include "../globals/network.h"
15 #include "../globals/settings.h"
16 #include "../globals/state.h"
17 #include "../globals/uvars.h"
18 #include "../mobile/attribute.h"
19 #include "../mobile/charactr.h"
20 #include "../network/packethelper.h"
21 #include "../party.h"
22 #include "../statmsg.h"
23 #include "../ufunc.h"
24 #include "../uoclient.h"
25 #include "../uoskills.h"
26 #include "../vital.h"
27 #include "client.h"
28 #include "packets.h"
29 
30 namespace Pol
31 {
32 namespace Network
33 {
35 {
37 }
38 
39 ClientVitalUpdaters::ClientVitalUpdaters() : my_vital_changed( NULL ), others_vital_changed( NULL )
40 {
41 }
42 
43 ClientAttributeUpdaters::ClientAttributeUpdaters() : my_attr_changed( NULL ), pUOSkill( nullptr ) {}
44 
46 {
47  clients.push_back( client );
48 }
50 {
51  for ( unsigned i = 0; i < clients.size(); ++i )
52  {
53  if ( clients[i] == client )
54  {
55  clients[i] = clients.back();
56  clients.pop_back();
57  break;
58  }
59  }
60 }
61 
62 // static
64 {
65  Client* client = who->client;
66  if ( client && client->ready )
67  {
68  const ClientVitalUpdaters& cvu = client->Interface.vital_updaters[vital->vitalid];
69  if ( cvu.my_vital_changed )
70  cvu.my_vital_changed( client, who, vital );
71  }
72 
73  // on all the client interfaces, for their connected clients, possibly tell them
74  Core::networkManager.uo_client_interface->bcast_vital_changed( who, vital );
75 }
77  const Mobile::Attribute* attr )
78 {
79  Client* client = who->client;
80  if ( client && client->ready )
81  {
82  const ClientAttributeUpdaters& cau = client->Interface.attribute_updaters[attr->attrid];
83  if ( cau.my_attr_changed )
84  cau.my_attr_changed( client, who, attr );
85  }
86 }
87 
89 void send_fake_hits( Client* client, Mobile::Character* me, const Core::Vital* vital )
90 {
92  msg->Write<u32>( me->serial_ext );
93  msg->WriteFlipped<u16>( 1000u );
94  msg->WriteFlipped<u16>( static_cast<u16>( me->vital( vital->vitalid ).current_thousands() ) );
95  msg.Send( client );
96 }
97 
98 void send_uo_hits( Client* client, Mobile::Character* me, const Core::Vital* vital )
99 {
101  msg->Write<u32>( me->serial_ext );
102  int v = me->vital( vital->vitalid ).maximum_ones();
103  if ( v > 0xFFFF )
104  v = 0xFFFF;
105  msg->WriteFlipped<u16>( static_cast<u16>( v ) );
106 
107  v = me->vital( vital->vitalid ).current_ones();
108  if ( v > 0xFFFF )
109  v = 0xFFFF;
110  msg->WriteFlipped<u16>( static_cast<u16>( v ) );
111  msg.Send( client );
112 }
113 
114 void send_uo_mana( Client* client, Mobile::Character* me, const Core::Vital* vital )
115 {
117  msg->Write<u32>( me->serial_ext );
118  int v = me->vital( vital->vitalid ).maximum_ones();
119  if ( v > 0xFFFF )
120  v = 0xFFFF;
121  msg->WriteFlipped<u16>( static_cast<u16>( v ) );
122 
123  v = me->vital( vital->vitalid ).current_ones();
124  if ( v > 0xFFFF )
125  v = 0xFFFF;
126  msg->WriteFlipped<u16>( static_cast<u16>( v ) );
127  msg.Send( client );
128 
129  if ( me->has_party() )
130  me->party()->on_mana_changed( me );
131 }
132 
133 void send_uo_stamina( Client* client, Mobile::Character* me, const Core::Vital* vital )
134 {
136  msg->Write<u32>( me->serial_ext );
137  int v = me->vital( vital->vitalid ).maximum_ones();
138  if ( v > 0xFFFF )
139  v = 0xFFFF;
140  msg->WriteFlipped<u16>( static_cast<u16>( v ) );
141 
142  v = me->vital( vital->vitalid ).current_ones();
143  if ( v > 0xFFFF )
144  v = 0xFFFF;
145  msg->WriteFlipped<u16>( static_cast<u16>( v ) );
146  msg.Send( client );
147 
148  if ( me->has_party() )
149  me->party()->on_stam_changed( me );
150 }
151 void send_uo_strength( Client* client, Mobile::Character* me, const Mobile::Attribute* /*attr*/ )
152 {
153  Core::send_full_statmsg( client, me );
154 }
155 void send_uo_dexterity( Client* client, Mobile::Character* me, const Mobile::Attribute* /*attr*/ )
156 {
157  Core::send_full_statmsg( client, me );
158 }
160  const Mobile::Attribute* /*attr*/ )
161 {
162  Core::send_full_statmsg( client, me );
163 }
164 void send_uo_skill( Client* client, Mobile::Character* me, const Mobile::Attribute* attr )
165 {
167 
169  msg->offset += 2;
170  if ( !Core::settingsManager.ssopt.core_sends_caps )
172  else
174  msg->WriteFlipped<u16>( cau.pUOSkill->skillid );
175  const Mobile::AttributeValue& av = me->attribute( attr->attrid );
176  msg->WriteFlipped<u16>( static_cast<u16>( av.effective_tenths() ) ); // value
177  msg->WriteFlipped<u16>(
178  static_cast<u16>( av.base() ) ); // value_unmod base is always in tenths...
179  msg->Write<u8>( av.lock() );
180  if ( Core::settingsManager.ssopt.core_sends_caps )
181  msg->WriteFlipped<u16>( av.cap() );
182  u16 len = msg->offset;
183  msg->offset = 1;
184  msg->WriteFlipped<u16>( len );
185  msg.Send( client, len );
186 }
188 {
189  vital_updaters.resize( Core::gamestate.vitals.size() );
190  attribute_updaters.resize( Core::gamestate.attributes.size() );
191 }
192 
194 {
196 
197  // tell a player's own client when his life changes
198  if ( Core::networkManager.uoclient_general.hits.any )
199  {
200  vital_updaters[Core::networkManager.uoclient_general.hits.id].my_vital_changed = send_uo_hits;
201  vital_updaters[Core::networkManager.uoclient_general.hits.id].others_vital_changed =
203  }
204  if ( Core::networkManager.uoclient_general.mana.any )
205  {
206  vital_updaters[Core::networkManager.uoclient_general.mana.id].my_vital_changed = send_uo_mana;
207  }
208  if ( Core::networkManager.uoclient_general.stamina.any )
209  {
210  vital_updaters[Core::networkManager.uoclient_general.stamina.id].my_vital_changed =
212  }
213 
214  if ( Core::networkManager.uoclient_general.strength.any )
215  {
216  attribute_updaters[Core::networkManager.uoclient_general.strength.id].my_attr_changed =
218  }
219  if ( Core::networkManager.uoclient_general.intelligence.any )
220  {
221  attribute_updaters[Core::networkManager.uoclient_general.intelligence.id].my_attr_changed =
223  }
224  if ( Core::networkManager.uoclient_general.dexterity.any )
225  {
226  attribute_updaters[Core::networkManager.uoclient_general.dexterity.id].my_attr_changed =
228  }
229 
230  for ( unsigned short i = 0; i < Core::networkManager.uoclient_general.maxskills + 1; ++i )
231  {
232  const Core::UOSkill& uoskill = Core::GetUOSkill( i );
233  if ( uoskill.inited && uoskill.pAttr )
234  {
235  attribute_updaters[uoskill.pAttr->attrid].my_attr_changed = send_uo_skill;
236  attribute_updaters[uoskill.pAttr->attrid].pUOSkill = &uoskill;
237  }
238  }
239 }
240 
242  const Core::Vital* vital ) const
243 {
244  const ClientVitalUpdaters& cvu = vital_updaters[vital->vitalid];
245  if ( cvu.others_vital_changed != NULL )
246  {
247  for ( auto& client : clients )
248  {
249  if ( who->client != client && client->ready && inrange( who, client->chr ) )
250  {
251  cvu.others_vital_changed( client, who, vital );
252  }
253  }
254  }
255 }
256 }
257 }
unsigned char u8
Definition: rawtypes.h:25
void send_uo_intelligence(Client *client, Mobile::Character *me, const Mobile::Attribute *)
Definition: cliface.cpp:159
unsigned skillid
Definition: uoskills.h:36
const Mobile::Attribute * pAttr
Definition: uoskills.h:38
Network::Client * client
Definition: charactr.h:871
void initialize_client_interfaces()
Definition: cliface.cpp:34
int current_thousands() const
Definition: charactr.h:194
void send_fake_hits(Client *client, Mobile::Character *me, const Core::Vital *vital)
Just like send_uo_hits, but sends hits on a 1000-basis instead.
Definition: cliface.cpp:89
void(* others_vital_changed)(Client *client, Mobile::Character *him, const Core::Vital *vital)
Definition: cliface.h:35
bool inrange(const UObject *c1, unsigned short x, unsigned short y)
Definition: ufunc.cpp:454
void send_uo_strength(Client *client, Mobile::Character *me, const Mobile::Attribute *)
Definition: cliface.cpp:151
int current_ones() const
Definition: charactr.h:193
std::unique_ptr< Network::UOClientInterface > uo_client_interface
Definition: network.h:63
unsigned short u16
Definition: rawtypes.h:26
unsigned int u32
Definition: rawtypes.h:27
unsigned short maxskills
Definition: uoclient.h:55
void send_uo_dexterity(Client *client, Mobile::Character *me, const Mobile::Attribute *)
Definition: cliface.cpp:155
void(* my_attr_changed)(Client *client, Mobile::Character *me, const Mobile::Attribute *attr)
Definition: cliface.h:44
void send_uo_mana(Client *client, Mobile::Character *me, const Core::Vital *vital)
Definition: cliface.cpp:114
void send_uo_hits(Client *client, Mobile::Character *me, const Core::Vital *vital)
Definition: cliface.cpp:98
const UOSkill & GetUOSkill(unsigned skillid)
Definition: uoskills.cpp:21
std::vector< ClientVitalUpdaters > vital_updaters
Definition: cliface.h:64
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
virtual void Initialize() POL_OVERRIDE
Definition: cliface.cpp:193
ClientInterface & Interface
Definition: client.h:183
static void tell_attribute_changed(Mobile::Character *who, const Mobile::Attribute *attr)
Definition: cliface.cpp:76
void send_uo_stamina(Client *client, Mobile::Character *me, const Core::Vital *vital)
Definition: cliface.cpp:133
int maximum_ones() const
Definition: charactr.h:200
GameState gamestate
Definition: uvars.cpp:74
void send_full_statmsg(Network::Client *client, Mobile::Character *chr)
Definition: statmsg.cpp:32
virtual void bcast_vital_changed(Mobile::Character *who, const Core::Vital *vital) const POL_OVERRIDE
Definition: cliface.cpp:241
SettingsManager settingsManager
Definition: settings.cpp:14
void send_uo_skill(Client *client, Mobile::Character *me, const Mobile::Attribute *attr)
Definition: cliface.cpp:164
std::vector< ClientAttributeUpdaters > attribute_updaters
Definition: cliface.h:65
void(* my_vital_changed)(Client *client, Mobile::Character *me, const Core::Vital *vital)
Definition: cliface.h:34
const VitalValue & vital(unsigned vitalid) const
Definition: charactr.h:1061
const Core::UOSkill * pUOSkill
Definition: cliface.h:46
unsigned vitalid
Definition: vital.h:38
Definition: berror.cpp:12
static void tell_vital_changed(Mobile::Character *who, const Core::Vital *vital)
Definition: cliface.cpp:63
void deregister_client(Client *client)
Definition: cliface.cpp:49
void register_client(Client *client)
Definition: cliface.cpp:45
UoClientGeneral uoclient_general
Definition: network.h:67