Pol  Revision:cb584c9
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 
40  : my_vital_changed( nullptr ), others_vital_changed( nullptr )
41 {
42 }
43 
44 ClientAttributeUpdaters::ClientAttributeUpdaters() : my_attr_changed( nullptr ), pUOSkill( nullptr )
45 {
46 }
47 
49 {
50  clients.push_back( client );
51 }
53 {
54  for ( unsigned i = 0; i < clients.size(); ++i )
55  {
56  if ( clients[i] == client )
57  {
58  clients[i] = clients.back();
59  clients.pop_back();
60  break;
61  }
62  }
63 }
64 
65 // static
67 {
68  Client* client = who->client;
69  if ( client && client->ready )
70  {
71  const ClientVitalUpdaters& cvu = client->Interface.vital_updaters[vital->vitalid];
72  if ( cvu.my_vital_changed )
73  cvu.my_vital_changed( client, who, vital );
74  }
75 
76  // on all the client interfaces, for their connected clients, possibly tell them
77  Core::networkManager.uo_client_interface->bcast_vital_changed( who, vital );
78 }
80  const Mobile::Attribute* attr )
81 {
82  Client* client = who->client;
83  if ( client && client->ready )
84  {
85  const ClientAttributeUpdaters& cau = client->Interface.attribute_updaters[attr->attrid];
86  if ( cau.my_attr_changed )
87  cau.my_attr_changed( client, who, attr );
88  }
89 }
90 
92 void send_fake_hits( Client* client, Mobile::Character* me, const Core::Vital* vital )
93 {
95  msg->Write<u32>( me->serial_ext );
96  msg->WriteFlipped<u16>( 1000u );
97  msg->WriteFlipped<u16>( static_cast<u16>( me->vital( vital->vitalid ).current_thousands() ) );
98  msg.Send( client );
99 }
100 
101 void send_uo_hits( Client* client, Mobile::Character* me, const Core::Vital* vital )
102 {
104  msg->Write<u32>( me->serial_ext );
105  int v = me->vital( vital->vitalid ).maximum_ones();
106  if ( v > 0xFFFF )
107  v = 0xFFFF;
108  msg->WriteFlipped<u16>( static_cast<u16>( v ) );
109 
110  v = me->vital( vital->vitalid ).current_ones();
111  if ( v > 0xFFFF )
112  v = 0xFFFF;
113  msg->WriteFlipped<u16>( static_cast<u16>( v ) );
114  msg.Send( client );
115 }
116 
117 void send_uo_mana( Client* client, Mobile::Character* me, const Core::Vital* vital )
118 {
120  msg->Write<u32>( me->serial_ext );
121  int v = me->vital( vital->vitalid ).maximum_ones();
122  if ( v > 0xFFFF )
123  v = 0xFFFF;
124  msg->WriteFlipped<u16>( static_cast<u16>( v ) );
125 
126  v = me->vital( vital->vitalid ).current_ones();
127  if ( v > 0xFFFF )
128  v = 0xFFFF;
129  msg->WriteFlipped<u16>( static_cast<u16>( v ) );
130  msg.Send( client );
131 
132  if ( me->has_party() )
133  me->party()->on_mana_changed( me );
134 }
135 
136 void send_uo_stamina( Client* client, Mobile::Character* me, const Core::Vital* vital )
137 {
139  msg->Write<u32>( me->serial_ext );
140  int v = me->vital( vital->vitalid ).maximum_ones();
141  if ( v > 0xFFFF )
142  v = 0xFFFF;
143  msg->WriteFlipped<u16>( static_cast<u16>( v ) );
144 
145  v = me->vital( vital->vitalid ).current_ones();
146  if ( v > 0xFFFF )
147  v = 0xFFFF;
148  msg->WriteFlipped<u16>( static_cast<u16>( v ) );
149  msg.Send( client );
150 
151  if ( me->has_party() )
152  me->party()->on_stam_changed( me );
153 }
154 void send_uo_strength( Client* client, Mobile::Character* me, const Mobile::Attribute* /*attr*/ )
155 {
156  Core::send_full_statmsg( client, me );
157 }
158 void send_uo_dexterity( Client* client, Mobile::Character* me, const Mobile::Attribute* /*attr*/ )
159 {
160  Core::send_full_statmsg( client, me );
161 }
163  const Mobile::Attribute* /*attr*/ )
164 {
165  Core::send_full_statmsg( client, me );
166 }
167 void send_uo_skill( Client* client, Mobile::Character* me, const Mobile::Attribute* attr )
168 {
170 
172  msg->offset += 2;
173  if ( !Core::settingsManager.ssopt.core_sends_caps )
175  else
177  msg->WriteFlipped<u16>( cau.pUOSkill->skillid );
178  const Mobile::AttributeValue& av = me->attribute( attr->attrid );
179  msg->WriteFlipped<u16>( static_cast<u16>( av.effective_tenths() ) ); // value
180  msg->WriteFlipped<u16>(
181  static_cast<u16>( av.base() ) ); // value_unmod base is always in tenths...
182  msg->Write<u8>( av.lock() );
183  if ( Core::settingsManager.ssopt.core_sends_caps )
184  msg->WriteFlipped<u16>( av.cap() );
185  u16 len = msg->offset;
186  msg->offset = 1;
187  msg->WriteFlipped<u16>( len );
188  msg.Send( client, len );
189 }
191 {
192  vital_updaters.resize( Core::gamestate.vitals.size() );
193  attribute_updaters.resize( Core::gamestate.attributes.size() );
194 }
195 
197 {
199 
200  // tell a player's own client when his life changes
201  if ( Core::networkManager.uoclient_general.hits.any )
202  {
203  vital_updaters[Core::networkManager.uoclient_general.hits.id].my_vital_changed = send_uo_hits;
204  vital_updaters[Core::networkManager.uoclient_general.hits.id].others_vital_changed =
206  }
207  if ( Core::networkManager.uoclient_general.mana.any )
208  {
209  vital_updaters[Core::networkManager.uoclient_general.mana.id].my_vital_changed = send_uo_mana;
210  }
211  if ( Core::networkManager.uoclient_general.stamina.any )
212  {
213  vital_updaters[Core::networkManager.uoclient_general.stamina.id].my_vital_changed =
215  }
216 
217  if ( Core::networkManager.uoclient_general.strength.any )
218  {
219  attribute_updaters[Core::networkManager.uoclient_general.strength.id].my_attr_changed =
221  }
222  if ( Core::networkManager.uoclient_general.intelligence.any )
223  {
224  attribute_updaters[Core::networkManager.uoclient_general.intelligence.id].my_attr_changed =
226  }
227  if ( Core::networkManager.uoclient_general.dexterity.any )
228  {
229  attribute_updaters[Core::networkManager.uoclient_general.dexterity.id].my_attr_changed =
231  }
232 
233  for ( unsigned short i = 0; i < Core::networkManager.uoclient_general.maxskills + 1; ++i )
234  {
235  const Core::UOSkill& uoskill = Core::GetUOSkill( i );
236  if ( uoskill.inited && uoskill.pAttr )
237  {
238  attribute_updaters[uoskill.pAttr->attrid].my_attr_changed = send_uo_skill;
239  attribute_updaters[uoskill.pAttr->attrid].pUOSkill = &uoskill;
240  }
241  }
242 }
243 
245  const Core::Vital* vital ) const
246 {
247  const ClientVitalUpdaters& cvu = vital_updaters[vital->vitalid];
248  if ( cvu.others_vital_changed != nullptr )
249  {
250  for ( auto& client : clients )
251  {
252  if ( who->client != client && client->ready && inrange( who, client->chr ) )
253  {
254  cvu.others_vital_changed( client, who, vital );
255  }
256  }
257  }
258 }
259 } // namespace Network
260 } // namespace Pol
unsigned char u8
Definition: rawtypes.h:25
void send_uo_intelligence(Client *client, Mobile::Character *me, const Mobile::Attribute *)
Definition: cliface.cpp:162
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:92
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:154
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:158
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:117
void send_uo_hits(Client *client, Mobile::Character *me, const Core::Vital *vital)
Definition: cliface.cpp:101
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:196
ClientInterface & Interface
Definition: client.h:183
static void tell_attribute_changed(Mobile::Character *who, const Mobile::Attribute *attr)
Definition: cliface.cpp:79
void send_uo_stamina(Client *client, Mobile::Character *me, const Core::Vital *vital)
Definition: cliface.cpp:136
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:244
SettingsManager settingsManager
Definition: settings.cpp:14
void send_uo_skill(Client *client, Mobile::Character *me, const Mobile::Attribute *attr)
Definition: cliface.cpp:167
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:66
void deregister_client(Client *client)
Definition: cliface.cpp:52
void register_client(Client *client)
Definition: cliface.cpp:48
UoClientGeneral uoclient_general
Definition: network.h:67