Pol  Revision:cb584c9
ssopt.cpp
Go to the documentation of this file.
1 
25 #include "ssopt.h"
26 
27 #include <cstring>
28 #include <ctype.h>
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <string>
32 
33 #include "../clib/cfgelem.h"
34 #include "../clib/cfgfile.h"
35 #include "../clib/fileutil.h"
36 #include "../clib/logfacility.h"
37 #include "globals/settings.h"
38 #include "pktdef.h"
39 
40 namespace Pol
41 {
42 namespace Core
43 {
45 {
47  Clib::ConfigElem elem;
48 
49  if ( Clib::FileExists( "config/servspecopt.local.cfg" ) )
50  {
51  cf.open( "config/servspecopt.local.cfg" );
52  cf.readraw( elem );
53  }
54  else if ( Clib::FileExists( "config/servspecopt.cfg" ) )
55  {
56  cf.open( "config/servspecopt.cfg" );
57  cf.readraw( elem );
58  }
59 
61  elem.remove_bool( "AllowSecureTradingInWarMode", false );
62  settingsManager.ssopt.dblclick_wait = elem.remove_ulong( "DoubleClickWait", 0 );
63  settingsManager.ssopt.decay_items = elem.remove_bool( "DecayItems", true );
64  settingsManager.ssopt.default_decay_time = elem.remove_ulong( "DefaultDecayTime", 10 );
66  elem.remove_ushort( "DefaultDoubleclickRange", 2 );
68  elem.remove_int( "DefaultAccessibleRange", settingsManager.ssopt.default_doubleclick_range);
69  settingsManager.ssopt.default_light_level = elem.remove_ushort( "DefaultLightLevel", 10 );
71  elem.remove_bool( "EventVisibilityCoreChecks", false );
72  settingsManager.ssopt.max_pathfind_range = elem.remove_ulong( "MaxPathFindRange", 50 );
73  settingsManager.ssopt.movement_uses_stamina = elem.remove_bool( "MovementUsesStamina", false );
74  settingsManager.ssopt.use_tile_flag_prefix = elem.remove_bool( "UseTileFlagPrefix", true );
76  elem.remove_ushort( "DefaultContainerMaxItems", 125 );
78  elem.remove_ushort( "DefaultContainerMaxWeight", 250 );
79  settingsManager.ssopt.hidden_turns_count = elem.remove_bool( "HiddenTurnsCount", true );
80  settingsManager.ssopt.invul_tag = elem.remove_ushort( "InvulTag", 1 );
81  settingsManager.ssopt.uo_feature_enable = elem.remove_ushort( "UOFeatureEnable", 0 );
82  settingsManager.ssopt.starting_gold = elem.remove_ushort( "StartingGold", 100 );
83  settingsManager.ssopt.item_color_mask = elem.remove_ushort( "ItemColorMask", 0xFFF );
84  settingsManager.ssopt.use_win_lfh = elem.remove_bool( "UseWinLFH", false );
85  settingsManager.ssopt.privacy_paperdoll = elem.remove_bool( "PrivacyPaperdoll", false );
87  elem.remove_bool( "ForceNewObjCachePackets", false );
88  settingsManager.ssopt.allow_moving_trade = elem.remove_bool( "AllowMovingTrade", false );
89  settingsManager.ssopt.core_handled_locks = elem.remove_bool( "CoreHandledLocks", false );
91  elem.remove_ushort( "DefaultAttributeCap", 1000 ); // 100.0
92  settingsManager.ssopt.default_max_slots = static_cast<unsigned char>( elem.remove_ushort(
93  "MaxContainerSlots", 125 ) ); // this is fine as is, yeah we cast it but 0-255 what we want.
94  settingsManager.ssopt.use_slot_index = elem.remove_bool( "UseContainerSlots", false );
95  settingsManager.ssopt.use_edit_server = elem.remove_bool( "EditServer", false );
96  settingsManager.ssopt.carrying_capacity_mod = elem.remove_double( "CarryingCapacityMod", 1.0 );
97  settingsManager.ssopt.core_sends_caps = elem.remove_bool( "CoreSendsCaps", false );
98  settingsManager.ssopt.send_stat_locks = elem.remove_bool( "SendStatLocks", false );
99  settingsManager.ssopt.speech_range = elem.remove_ushort( "SpeechRange", 12 );
100  settingsManager.ssopt.whisper_range = elem.remove_ushort( "WhisperRange", 2 );
101  settingsManager.ssopt.yell_range = elem.remove_ushort( "YellRange", 25 );
102  settingsManager.ssopt.core_sends_season = elem.remove_bool( "CoreSendsSeason", true );
103  settingsManager.ssopt.core_handled_tags = elem.remove_ushort( "CoreHandledTags", 0xFFFF );
105  static_cast<unsigned char>( elem.remove_ushort( "SupportFaces", 0 ) );
107  elem.remove_bool( "NewbieStartingEquipment", true );
108  settingsManager.ssopt.speedhack_prevention = elem.remove_bool( "SpeedhackPrevention", false );
110  elem.remove_bool( "ScriptedMerchantHandlers", false );
112  elem.remove_bool( "HonorUnequipScriptOnDeath", false );
113 
115  elem.remove_ushort( "SpeedHack_MountRunDelay", PKTIN_02_MOUNT_RUN );
117  elem.remove_ushort( "SpeedHack_MountWalkDelay", PKTIN_02_MOUNT_WALK );
119  elem.remove_ushort( "SpeedHack_FootRunDelay", PKTIN_02_FOOT_RUN );
121  elem.remove_ushort( "SpeedHack_FootWalkDelay", PKTIN_02_FOOT_WALK );
122  settingsManager.ssopt.seperate_speechtoken = elem.remove_bool( "SeperateSpeechTokens", false );
123  settingsManager.ssopt.core_sends_guildmsgs = elem.remove_bool( "CoreGuildMessages", true );
125  elem.remove_bool( "MobilesBlockNpcMovement", true );
126 
127  unsigned char default_character_height =
128  static_cast<unsigned char>( elem.remove_ushort( "DefaultCharacterHeight", 15 ) );
129  if ( default_character_height < 1 )
130  default_character_height = 1;
131  else if ( default_character_height > 32 )
132  default_character_height = 32;
134 
135  ssopt_parse_totalstats( elem );
136 
137  // Turley 2009/11/06 u8 range...
138  // if ( ssopt.default_max_slots > 255 )
139  // {
140  // cerr << "Invalid MaxContainerSlots value '"
141  // << ssopt.default_max_slots << "', using '255'" << endl;
142  // Log( "Invalid MaxContainerSlots value '%d', using '255'\n",
143  // ssopt.default_max_slots );
144  // ssopt.default_max_slots = 255;
145  // }
146 }
147 
149 {
150  static char tmp[100], tmpcopy[256];
151 
152  std::string total_stats = elem.remove_string( "TotalStatsAtCreation", "65,80" );
153  strncpy( tmpcopy, total_stats.c_str(), sizeof( tmpcopy ) - 1 ); // strncpy only sets last byte
154  // null if there is less bytes at
155  // src than the size of tmpcopy
156  // (Nando)
157  tmpcopy[sizeof( tmpcopy ) - 1] = '\0';
158 
159  char *token, *valmax, *valend;
160  unsigned int statmin, statmax;
161 
162  // Stat values must be comma-delimited.
163  // Ranges can be specified using the syntax: <min>-<max>
164  // <max> must be higher than <min>
165 
166  bool valok = true;
168  token = strtok( tmpcopy, "," );
169  while ( token != nullptr && valok )
170  {
171  valok = false;
172  statmin = strtoul( token, &valmax, 0 );
173  if ( valmax == token )
174  break; // invalid value
175  if ( *valmax != '\0' )
176  {
177  // second value given?
178  if ( *( valmax++ ) != '-' || !isdigit( *valmax ) )
179  break; // invalid second value
180  statmax = strtoul( valmax, &valend, 0 );
181  if ( *valend != '\0' || valend == valmax || statmax < statmin )
182  break; // invalid second value
183  if ( statmax == statmin )
184  sprintf( tmp, "%lu", static_cast<unsigned long>( statmin ) );
185  else
186  sprintf( tmp, "%lu-%lu", static_cast<unsigned long>( statmin ),
187  static_cast<unsigned long>( statmax ) );
188  }
189  else
190  sprintf( tmp, "%lu", static_cast<unsigned long>( statmin ) );
192  valok = true;
193  token = strtok( nullptr, "," );
194  }
195 
196  if ( !valok || settingsManager.ssopt.total_stats_at_creation.empty() )
197  {
201  POLLOG_ERROR << "Invalid TotalStatsAtCreation value '" << total_stats << "', using '65,80'\n";
202  }
203  /*
204  // DEBUG OUTPUT
205  std::vector<std::string>::const_iterator itr = ssopt.total_stats_at_creation.begin();
206  for( ; itr != ssopt.total_stats_at_creation.end() ; itr++ )
207  cout << "* Stats-at-creation entry: " << *itr << endl;
208  */
209 }
210 }
211 }
unsigned short default_doubleclick_range
Definition: ssopt.h:46
std::vector< std::string > total_stats_at_creation
Definition: ssopt.h:92
std::string remove_string(const char *propname)
Definition: cfgfile.cpp:381
bool allow_secure_trading_in_warmode
Definition: ssopt.h:42
double carrying_capacity_mod
Definition: ssopt.h:67
unsigned short default_light_level
Definition: ssopt.h:48
unsigned short speedhack_footrundelay
Definition: ssopt.h:89
bool newbie_starting_equipment
Definition: ssopt.h:81
unsigned short default_container_max_items
Definition: ssopt.h:53
unsigned short whisper_range
Definition: ssopt.h:75
unsigned short yell_range
Definition: ssopt.h:76
unsigned int remove_ulong(const char *propname)
Definition: cfgfile.cpp:461
unsigned short speedhack_footwalkdelay
Definition: ssopt.h:90
bool honor_unequip_script_on_death
Definition: ssopt.h:85
int remove_int(const char *propname)
Definition: cfgfile.cpp:340
bool mobiles_block_npc_movement
Definition: ssopt.h:95
unsigned short default_attribute_cap
Definition: ssopt.h:70
#define POLLOG_ERROR
Definition: logfacility.h:207
unsigned short core_handled_tags
Definition: ssopt.h:79
void readraw(ConfigElem &elem)
Definition: cfgfile.cpp:1028
bool core_sends_season
Definition: ssopt.h:78
double remove_double(const char *propname, double dflt)
Definition: cfgfile.cpp:448
int default_accessible_range
Definition: ssopt.h:47
unsigned short starting_gold
Definition: ssopt.h:58
bool core_sends_guildmsgs
Definition: ssopt.h:94
unsigned char default_max_slots
Definition: ssopt.h:60
bool speedhack_prevention
Definition: ssopt.h:82
bool event_visibility_core_checks
Definition: ssopt.h:49
bool scripted_merchant_handlers
Definition: ssopt.h:84
unsigned int max_pathfind_range
Definition: ssopt.h:50
unsigned short uo_feature_enable
Definition: ssopt.h:57
#define PKTIN_02_FOOT_RUN
Definition: pktdef.h:80
unsigned int dblclick_wait
Definition: ssopt.h:43
bool seperate_speechtoken
Definition: ssopt.h:93
bool force_new_objcache_packets
Definition: ssopt.h:63
unsigned short speech_range
Definition: ssopt.h:74
unsigned char default_character_height
Definition: ssopt.h:97
unsigned short invul_tag
Definition: ssopt.h:56
void open(const char *i_filename)
Definition: cfgfile.cpp:600
SettingsManager settingsManager
Definition: settings.cpp:14
unsigned short default_container_max_weight
Definition: ssopt.h:54
unsigned int default_decay_time
Definition: ssopt.h:45
unsigned char support_faces
Definition: ssopt.h:80
bool hidden_turns_count
Definition: ssopt.h:55
static void ssopt_parse_totalstats(Clib::ConfigElem &elem)
Definition: ssopt.cpp:148
bool core_handled_locks
Definition: ssopt.h:65
#define PKTIN_02_FOOT_WALK
Definition: pktdef.h:81
unsigned short remove_ushort(const char *propname)
Definition: cfgfile.cpp:318
static void read_servspecopt()
Definition: ssopt.cpp:44
bool allow_moving_trade
Definition: ssopt.h:64
bool FileExists(const char *filename)
Definition: fileutil.cpp:118
unsigned short speedhack_mountrundelay
Definition: ssopt.h:87
unsigned short item_color_mask
Definition: ssopt.h:59
bool use_tile_flag_prefix
Definition: ssopt.h:52
#define PKTIN_02_MOUNT_RUN
Definition: pktdef.h:78
bool privacy_paperdoll
Definition: ssopt.h:62
Definition: berror.cpp:12
bool remove_bool(const char *propname)
Definition: cfgfile.cpp:426
unsigned short speedhack_mountwalkdelay
Definition: ssopt.h:88
#define PKTIN_02_MOUNT_WALK
Definition: pktdef.h:79
bool movement_uses_stamina
Definition: ssopt.h:51