Fixed some warnings, like sprintf %i warnings (converted to %lu), fals vs NULL, etc

This commit is contained in:
Arthur Ice
2013-03-03 16:17:06 -08:00
parent d8628170b5
commit 950f00fae6
6 changed files with 306 additions and 306 deletions
+8 -8
View File
@@ -11,24 +11,24 @@ class EmuTCPServer : public TCPServer<EmuTCPConnection> {
public:
EmuTCPServer(uint16 iPort = 0, bool iOldFormat = false);
virtual ~EmuTCPServer();
//packet broadcast routines.
void SendPacket(ServerPacket* pack);
void SendPacket(EmuTCPNetPacket_Struct** tnps);
//special crap for relay management
EmuTCPConnection *FindConnection(uint32 iID);
//exposed for some crap we pull. Do not call from outside this object.
TCPServer<EmuTCPConnection>::AddConnection;
using TCPServer<EmuTCPConnection>::AddConnection;
protected:
virtual void Process();
virtual void CreateNewConnection(uint32 ID, SOCKET in_socket, uint32 irIP, uint16 irPort);
bool pOldFormat;
//broadcast packet queue..
void CheckInQueue();
Mutex MInQueue;
+3 -3
View File
@@ -118,7 +118,7 @@ static char *temp=NULL;
return false;
}
ptr++;
for(i=(name_pos-1);i<(max_field-1);i++) {
end=ptr-1;
while((end=strchr(end+1,'|'))!=NULL) {
@@ -463,7 +463,7 @@ bool in_quote=false;
}
if (in_quote)
continue;
if (seps.find(c)!=string::npos) {
if (seps.find(c)!=string::npos) {
break;
}
}
@@ -554,7 +554,7 @@ void build_hex_line(const char *buffer, unsigned long length, unsigned long offs
char *ptr=out_buffer;
int i;
char printable[17];
ptr+=sprintf(ptr,"%0*i:",padding,offset);
ptr+=sprintf(ptr,"%0*lu:",padding,offset);
for(i=0;i<16; i++) {
if (i==8) {
strcpy(ptr," -");
+46 -46
View File
@@ -48,7 +48,7 @@ to store them in the DB: Load and Store.
All durations are in seconds.
Each persistent timer is attached to a character, and given
Each persistent timer is attached to a character, and given
a specific type. A given character can only have one timer
of each type. While the type is just an arbitrary number,
please record what you are using it for in the enum for
@@ -59,7 +59,7 @@ client has a facility called p_timers which should handle
most of what you need. The idea is that instead of making
your own PersistentTimer, you use the methods on p_timers:
Start, Check, Clear, GetRemainingTime to access them. You
starting a timer which does not exist will create it. If
starting a timer which does not exist will create it. If
you need to do more than that with your timer, you should
still use p_timers, just use the Get() method to get direct
access to the PersistentTimer. All timers in the p_timers
@@ -101,7 +101,7 @@ PersistentTimer *PersistentTimer::LoadTimer(Database *db, uint32 char_id, pTimer
PersistentTimer::PersistentTimer(uint32 char_id, pTimerType type, uint32 in_timer_time) {
_char_id = char_id;
_type = type;
timer_time = in_timer_time;
start_time = get_current_time();
if (timer_time == 0) {
@@ -117,7 +117,7 @@ PersistentTimer::PersistentTimer(uint32 char_id, pTimerType type, uint32 in_time
PersistentTimer::PersistentTimer(uint32 char_id, pTimerType type, uint32 in_start_time, uint32 in_timer_time, bool in_enable) {
_char_id = char_id;
_type = type;
timer_time = in_timer_time;
start_time = in_start_time;
enabled = in_enable;
@@ -133,14 +133,14 @@ bool PersistentTimer::Load(Database *db) {
char *query = 0;
uint32 qlen = 0;
uint32 qcount = 0;
qlen = MakeAnyLenString(&query, "SELECT start,duration,enable "
" FROM timers WHERE char_id=%lu AND type=%u", (unsigned long)_char_id, _type);
#ifdef DEBUG_PTIMERS
printf("Loading timer: char %lu of type %u\n", (unsigned long)_char_id, _type);
#endif
if (!db->RunQuery(query, qlen, errbuf, &result)) {
safe_delete_array(query);
#if EQDEBUG > 5
@@ -149,39 +149,39 @@ bool PersistentTimer::Load(Database *db) {
return(false);
}
safe_delete_array(query);
bool res = false;
qcount = mysql_num_rows(result);
if(qcount == 1 && (row = mysql_fetch_row(result)) ) {
start_time = strtoul(row[0], NULL, 10);
timer_time = strtoul(row[1], NULL, 10);
enabled = (row[2][0] == '1');
res = true;
}
mysql_free_result(result);
return(res);
}
bool PersistentTimer::Store(Database *db) {
if(Expired(db, false)) //dont need to store expired timers.
return(true);
char errbuf[MYSQL_ERRMSG_SIZE];
char *query = 0;
uint32 qlen = 0;
qlen = MakeAnyLenString(&query, "REPLACE INTO timers "
" (char_id,type,start,duration,enable) "
" VALUES(%lu,%u,%lu,%lu,%d)",
(unsigned long)_char_id, _type, (unsigned long)start_time, (unsigned long)timer_time, enabled?1:0);
#ifdef DEBUG_PTIMERS
printf("Storing timer: char %lu of type %u: '%s'\n", (unsigned long)_char_id, _type, query);
#endif
if (!db->RunQuery(query, qlen, errbuf)) {
safe_delete_array(query);
#if EQDEBUG > 5
@@ -190,7 +190,7 @@ bool PersistentTimer::Store(Database *db) {
return(false);
}
safe_delete_array(query);
return(true);
}
@@ -198,15 +198,15 @@ bool PersistentTimer::Clear(Database *db) {
char errbuf[MYSQL_ERRMSG_SIZE];
char *query = 0;
uint32 qlen = 0;
qlen = MakeAnyLenString(&query, "DELETE FROM timers "
" WHERE char_id=%lu AND type=%u ",
(unsigned long)_char_id, _type);
#ifdef DEBUG_PTIMERS
printf("Clearing timer: char %lu of type %u: '%s'\n", (unsigned long)_char_id, _type, query);
#endif
if (!db->RunQuery(query, qlen, errbuf)) {
safe_delete_array(query);
#if EQDEBUG > 5
@@ -215,15 +215,15 @@ bool PersistentTimer::Clear(Database *db) {
return(false);
}
safe_delete_array(query);
return(true);
}
/* This function checks if the timer triggered */
bool PersistentTimer::Expired(Database *db, bool iReset) {
if (this == NULL) {
LogFile->write(EQEMuLog::Error, "Null timer during ->Check()!?\n");
if (this == NULL) {
LogFile->write(EQEMuLog::Error, "Null timer during ->Check()!?\n");
return(true);
}
uint32 current_time = get_current_time();
@@ -235,7 +235,7 @@ bool PersistentTimer::Expired(Database *db, bool iReset) {
}
return(true);
}
return(false);
}
@@ -287,7 +287,7 @@ uint32 PersistentTimer::get_current_time() {
PTimerList::PTimerList(uint32 char_id) {
_char_id = char_id;
}
PTimerList::~PTimerList() {
map<pTimerType, PersistentTimer *>::iterator s;
s = _list.begin();
@@ -308,21 +308,21 @@ bool PTimerList::Load(Database *db) {
s++;
}
_list.clear();
char errbuf[MYSQL_ERRMSG_SIZE];
MYSQL_RES *result;
MYSQL_ROW row;
char *query = 0;
uint32 qlen = 0;
uint32 qcount = 0;
qlen = MakeAnyLenString(&query, "SELECT type,start,duration,enable "
" FROM timers WHERE char_id=%lu", (unsigned long)_char_id);
#ifdef DEBUG_PTIMERS
printf("Loading all timers for char %lu\n", (unsigned long)_char_id);
#endif
if (!db->RunQuery(query, qlen, errbuf, &result)) {
safe_delete_array(query);
#if EQDEBUG > 5
@@ -331,11 +331,11 @@ bool PTimerList::Load(Database *db) {
return(false);
}
safe_delete_array(query);
pTimerType type;
uint32 start_time, timer_time;
bool enabled;
PersistentTimer *cur;
qcount = mysql_num_rows(result);
while((row = mysql_fetch_row(result)) ) {
@@ -343,17 +343,17 @@ bool PTimerList::Load(Database *db) {
start_time = strtoul(row[1], NULL, 10);
timer_time = strtoul(row[2], NULL, 10);
enabled = (row[3][0] == '1');
//if it expired allready, dont bother.
cur = new PersistentTimer(_char_id, type, start_time, timer_time, enabled);
if(!cur->Expired(false))
if(!cur->Expired(NULL, false))
_list[type] = cur;
else
delete cur;
}
mysql_free_result(result);
return(true);
}
@@ -380,18 +380,18 @@ bool PTimerList::Store(Database *db) {
bool PTimerList::Clear(Database *db) {
_list.clear();
char errbuf[MYSQL_ERRMSG_SIZE];
char *query = 0;
uint32 qlen = 0;
qlen = MakeAnyLenString(&query, "DELETE FROM timers "
" WHERE char_id=%lu ", (unsigned long)_char_id);
#ifdef DEBUG_PTIMERS
printf("Storing all timers for char %lu: '%s'\n", (unsigned long)_char_id, query);
#endif
if (!db->RunQuery(query, qlen, errbuf)) {
safe_delete_array(query);
#if EQDEBUG > 5
@@ -400,10 +400,10 @@ bool PTimerList::Clear(Database *db) {
return(false);
}
safe_delete_array(query);
return(true);
}
void PTimerList::Start(pTimerType type, uint32 duration) {
if(_list.count(type) == 1 && _list[type] != NULL) {
_list[type]->Start(duration);
@@ -463,9 +463,9 @@ PersistentTimer *PTimerList::Get(pTimerType type) {
}
void PTimerList::ToVector(vector< pair<pTimerType, PersistentTimer *> > &out) {
pair<pTimerType, PersistentTimer *> p;
map<pTimerType, PersistentTimer *>::iterator s;
s = _list.begin();
while(s != _list.end()) {
@@ -482,13 +482,13 @@ bool PTimerList::ClearOffline(Database *db, uint32 char_id, pTimerType type) {
char errbuf[MYSQL_ERRMSG_SIZE];
char *query = 0;
uint32 qlen = 0;
qlen = MakeAnyLenString(&query, "DELETE FROM timers WHERE char_id=%lu AND type=%u ",(unsigned long)char_id, type);
#ifdef DEBUG_PTIMERS
printf("Clearing timer (offline): char %lu of type %u: '%s'\n", (unsigned long)char_id, type, query);
#endif
if (!db->RunQuery(query, qlen, errbuf)) {
safe_delete_array(query);
#if EQDEBUG > 5
@@ -497,7 +497,7 @@ bool PTimerList::ClearOffline(Database *db, uint32 char_id, pTimerType type) {
return(false);
}
safe_delete_array(query);
return(true);
+29 -29
View File
@@ -4,13 +4,13 @@
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY except by those people which sell it, which
are required to give you total support for your newly bought product;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
@@ -25,7 +25,7 @@
/*
FatherNitwit: Added new rules subsystem to allow game rules to be changed
FatherNitwit: Added new rules subsystem to allow game rules to be changed
at runtime. more about this will come as time goes on.
FatherNitwit: Added #rules command to manage rules data from in game.
FatherNitwit: Renamed old #rules to #serverrules
@@ -162,12 +162,12 @@ bool RuleManager::GetRule(const char *rule_name, std::string &ret_val) {
bool RuleManager::SetRule(const char *rule_name, const char *rule_value, Database *db, bool db_save) {
if(rule_name == NULL || rule_value == NULL)
return(false);
RuleType type;
uint16 index;
if(!_FindRule(rule_name, type, index))
return(false);
switch(type) {
case IntRule:
m_RuleIntValues [index] = atoi(rule_value);
@@ -181,11 +181,11 @@ bool RuleManager::SetRule(const char *rule_name, const char *rule_value, Databas
uint32 val = 0;
if(!strcasecmp(rule_value, "on") || !strcasecmp(rule_value, "true") || !strcasecmp(rule_value, "yes") || !strcasecmp(rule_value, "enabled") || !strcmp(rule_value, "1"))
val = 1;
m_RuleBoolValues[index] = val;
m_RuleBoolValues[index] = val;
_log(RULES__CHANGE, "Set rule %s to value %s", rule_name, m_RuleBoolValues[index] == 1 ?"true":"false");
break;
}
if(db_save)
_SaveRule(db, type, index);
@@ -206,7 +206,7 @@ void RuleManager::ResetRules() {
bool RuleManager::_FindRule(const char *rule_name, RuleType &type_into, uint16 &index_into) {
if(rule_name == NULL)
return(false);
int r;
int rcount = CountRules();
for(r = 0; r < rcount; r++) {
@@ -253,7 +253,7 @@ void RuleManager::SaveRules(Database *db, const char *ruleset) {
} else {
_log(RULES__CHANGE, "Saving running rules into running rule set %s", m_activeName.c_str(), m_activeRuleset);
}
int r;
for(r = 0; r < _IntRuleCount; r++) {
_SaveRule(db, IntRule, r);
@@ -284,15 +284,15 @@ bool RuleManager::LoadRules(Database *db, const char *ruleset) {
m_activeRuleset = rsid;
m_activeName = ruleset;
if (db->RunQuery(query, MakeAnyLenString(&query,
if (db->RunQuery(query, MakeAnyLenString(&query,
"SELECT rule_name, rule_value"
" FROM rule_values"
" WHERE ruleset_id=%d", rsid), errbuf, &result))
{
safe_delete_array(query);
while((row = mysql_fetch_row(result))) {
if(!SetRule(row[0], row[1], false))
if(!SetRule(row[0], row[1],NULL, false))
_log(RULES__ERROR, "Unable to interpret rule record for %s", row[0]);
}
mysql_free_result(result);
@@ -319,10 +319,10 @@ void RuleManager::_SaveRule(Database *db, RuleType type, uint16 index) {
sprintf(vstr, "%s", m_RuleBoolValues[index]?"true":"false");
break;
}
char errbuf[MYSQL_ERRMSG_SIZE];
char* query = 0;
if (!db->RunQuery(query, MakeAnyLenString(&query,
if (!db->RunQuery(query, MakeAnyLenString(&query,
"REPLACE INTO rule_values (ruleset_id, rule_name, rule_value) "
" VALUES(%d, '%s', '%s')",
m_activeRuleset, _GetRuleName(type, index), vstr),errbuf))
@@ -338,14 +338,14 @@ int RuleManager::GetRulesetID(Database *db, const char *rulesetname) {
char *query = 0;
MYSQL_RES *result;
MYSQL_ROW row;
uint32 len = strlen(rulesetname);
char* rst = new char[2*len+1];
db->DoEscapeString(rst, rulesetname, len);
int res = -1;
if (db->RunQuery(query, MakeAnyLenString(&query,
if (db->RunQuery(query, MakeAnyLenString(&query,
"SELECT ruleset_id"
" FROM rule_sets"
" WHERE name='%s'", rst), errbuf, &result))
@@ -369,7 +369,7 @@ int RuleManager::_FindOrCreateRuleset(Database *db, const char *ruleset) {
res = GetRulesetID(db, ruleset);
if(res >= 0)
return(res); //found and existing one...
uint32 len = strlen(ruleset);
char* rst = new char[2*len+1];
db->DoEscapeString(rst, ruleset, len);
@@ -377,7 +377,7 @@ int RuleManager::_FindOrCreateRuleset(Database *db, const char *ruleset) {
uint32 new_id;
char errbuf[MYSQL_ERRMSG_SIZE];
char* query = 0;
if (!db->RunQuery(query, MakeAnyLenString(&query,
if (!db->RunQuery(query, MakeAnyLenString(&query,
"INSERT INTO rule_sets (ruleset_id, name) "
" VALUES(0, '%s')",
rst),errbuf,NULL,NULL,&new_id))
@@ -399,8 +399,8 @@ std::string RuleManager::GetRulesetName(Database *db, int id) {
MYSQL_ROW row;
std::string res;
if (db->RunQuery(query, MakeAnyLenString(&query,
if (db->RunQuery(query, MakeAnyLenString(&query,
"SELECT name"
" FROM rule_sets"
" WHERE ruleset_id=%d", id), errbuf, &result))
@@ -425,8 +425,8 @@ bool RuleManager::ListRulesets(Database *db, std::map<int, std::string> &into) {
//start out with the default set which is always present.
into[0] = "default";
if (db->RunQuery(query, MakeAnyLenString(&query,
if (db->RunQuery(query, MakeAnyLenString(&query,
"SELECT ruleset_id,name"
" FROM rule_sets"), errbuf, &result))
{
@@ -444,18 +444,18 @@ bool RuleManager::ListRulesets(Database *db, std::map<int, std::string> &into) {
}
int32 RuleManager::GetIntRule(RuleManager::IntType t) const
{
return(m_RuleIntValues[t]);
{
return(m_RuleIntValues[t]);
}
float RuleManager::GetRealRule(RuleManager::RealType t) const
{
return(m_RuleRealValues[t]);
{
return(m_RuleRealValues[t]);
}
bool RuleManager::GetBoolRule(RuleManager::BoolType t) const
{
return (m_RuleBoolValues[t] == 1);
{
return (m_RuleBoolValues[t] == 1);
}