Pol  Revision:cb584c9
uoclient.cpp
Go to the documentation of this file.
1 
8 #include "uoclient.h"
9 
10 #include <string>
11 
12 #include "../clib/cfgelem.h"
13 #include "../plib/pkg.h"
14 #include "globals/network.h"
15 #include "mobile/attribute.h"
16 #include "skillid.h"
17 #include "syshookscript.h"
18 #include "vital.h"
19 
20 
21 namespace Pol
22 {
23 namespace Core
24 {
25 UoClientProtocol::UoClientProtocol() : EnableFlowControlPackets( false ) {}
27 {
28  return sizeof( UoClientProtocol );
29 }
30 
31 
33  : port( elem.remove_ushort( "PORT" ) ),
34  aosresist( elem.remove_bool( "AOSRESISTANCES", false ) ),
35  sticky( elem.remove_bool( "KeepClients", false ) )
36 
37 {
38  CalculateCryptKeys( elem.remove_string( "ENCRYPTION", "none" ), encryption );
39 }
40 
42 {
43  return sizeof( UoClientListener );
44 }
45 
46 void checka( Clib::ConfigElem& elem, UoClientGeneral::Mapping& mapping, const char* tag )
47 {
48  if ( !mapping.any )
49  {
50  std::string name;
51  if ( elem.remove_prop( tag, &name ) )
52  {
53  mapping.name = name;
54  mapping.any = true;
56  if ( pAttr )
57  mapping.id = pAttr->attrid;
58  else
59  elem.throw_error( "Attribute " + name + " not found" );
60  }
61  }
62 }
63 void checkv( Clib::ConfigElem& elem, UoClientGeneral::Mapping& mapping, const char* tag )
64 {
65  if ( !mapping.any )
66  {
67  std::string name;
68  if ( elem.remove_prop( tag, &name ) )
69  {
70  mapping.name = name;
71  mapping.any = true;
72  Vital* pVital = FindVital( name );
73  if ( pVital )
74  mapping.id = pVital->vitalid;
75  else
76  elem.throw_error( "Vital " + name + " not found" );
77  }
78  }
79 }
80 
81 // Strength
82 // Dexterity
84 {
85  checka( elem, networkManager.uoclient_general.strength, "Strength" );
86  checka( elem, networkManager.uoclient_general.intelligence, "Intelligence" );
87  checka( elem, networkManager.uoclient_general.dexterity, "Dexterity" );
88  checkv( elem, networkManager.uoclient_general.hits, "Hits" );
89  checkv( elem, networkManager.uoclient_general.stamina, "Stamina" );
90  checkv( elem, networkManager.uoclient_general.mana, "Mana" );
91  // dave changed 3/15/03, support configurable max skillid
93  std::string temp;
94  if ( elem.remove_prop( "MethodScript", &temp ) )
95  {
96  if ( !temp.empty() )
97  {
98  ExportScript* shs = new ExportScript( pkg, temp );
99  if ( shs->Initialize() )
101  else
102  delete shs;
103  }
104  }
105 }
106 
108 {
110  elem.remove_bool( "EnableFlowControlPackets" );
111 }
112 
114 {
116 }
117 
119 {
120  if ( elem.type_is( "general" ) )
121  load_general_entry( pkg, elem );
122  else if ( elem.type_is( "protocol" ) )
123  load_protocol_entry( pkg, elem );
124  else if ( elem.type_is( "listener" ) )
125  load_listener_entry( pkg, elem );
126 }
127 
129 {
130  load_packaged_cfgs( "uoclient.cfg", "general protocol listener", load_uoclient_entry );
131 }
132 
134 {
135  return sizeof( bool ) + name.capacity() + sizeof( unsigned );
136 }
138 {
139  size_t size = strength.estimateSize() + intelligence.estimateSize() + dexterity.estimateSize() +
140  hits.estimateSize() + stamina.estimateSize() + mana.estimateSize() +
141  sizeof( unsigned short ) /*maxskills*/
142  + sizeof( ExportScript* );
143  if ( method_script != nullptr )
144  size += method_script->estimateSize();
145  return size;
146 }
147 
149 {
150  if ( method_script != nullptr )
151  {
152  delete method_script;
153  method_script = nullptr;
154  }
155 }
156 }
157 }
ExportScript * method_script
Definition: uoclient.h:56
Vital * FindVital(const std::string &str)
Definition: vital.cpp:83
std::string remove_string(const char *propname)
Definition: cfgfile.cpp:381
void load_packaged_cfgs(const char *cfgname, const char *taglist, void(*loadentry)(const Package *, Clib::ConfigElem &))
Definition: pkg.cpp:454
void checka(Clib::ConfigElem &elem, UoClientGeneral::Mapping &mapping, const char *tag)
Definition: uoclient.cpp:46
size_t estimateSize() const
Definition: uoclient.cpp:41
Crypt::TCryptInfo encryption
Definition: uoclient.h:73
POL_NORETURN void throw_error(const std::string &errmsg) const
Definition: cfgfile.cpp:285
unsigned short maxskills
Definition: uoclient.h:55
NetworkManager networkManager
Definition: network.cpp:28
void load_uoclient_entry(const Plib::Package *pkg, Clib::ConfigElem &elem)
Definition: uoclient.cpp:118
void checkv(Clib::ConfigElem &elem, UoClientGeneral::Mapping &mapping, const char *tag)
Definition: uoclient.cpp:63
size_t estimateSize() const
Definition: uoclient.cpp:26
UoClientProtocol uoclient_protocol
Definition: network.h:68
bool remove_prop(const char *propname, std::string *value)
Definition: cfgfile.cpp:128
void CalculateCryptKeys(const std::string &name, TCryptInfo &infoCrypt)
Definition: cryptkey.cpp:31
bool type_is(const char *name) const
Definition: cfgfile.cpp:95
void load_protocol_entry(const Plib::Package *, Clib::ConfigElem &elem)
Definition: uoclient.cpp:107
void load_general_entry(const Plib::Package *pkg, Clib::ConfigElem &elem)
Definition: uoclient.cpp:83
unsigned short remove_ushort(const char *propname)
Definition: cfgfile.cpp:318
std::string name
Definition: osmod.cpp:943
void load_listener_entry(const Plib::Package *, Clib::ConfigElem &elem)
Definition: uoclient.cpp:113
unsigned vitalid
Definition: vital.h:38
size_t estimateSize() const
Definition: uoclient.cpp:137
void load_uoclient_cfg()
Definition: uoclient.cpp:128
UoClientListener(Clib::ConfigElem &elem)
Definition: uoclient.cpp:32
std::vector< UoClientListener > uoclient_listeners
Definition: network.h:69
Definition: berror.cpp:12
bool remove_bool(const char *propname)
Definition: cfgfile.cpp:426
static Attribute * FindAttribute(const std::string &str)
Definition: attribute.cpp:22
UoClientGeneral uoclient_general
Definition: network.h:67