Skip to content

Commit

Permalink
Merge pull request #23 from addtheice/master
Browse files Browse the repository at this point in the history
Fixed missing include that blocked compile on linux.
  • Loading branch information
KimLS committed Mar 6, 2013
2 parents 7af51ff + 0c6eee6 commit f746941
Show file tree
Hide file tree
Showing 11 changed files with 1,223 additions and 1,222 deletions.
16 changes: 8 additions & 8 deletions common/EmuTCPServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 5 additions & 4 deletions common/ipc_mutex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -23,6 +23,7 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#endif
#include "types.h"
#include "eqemu_exception.h"
Expand Down Expand Up @@ -53,8 +54,8 @@ namespace EQEmu {
#else
std::string final_name = name;
final_name += ".lock";
imp_->fd_ = open(final_name.c_str(),

imp_->fd_ = open(final_name.c_str(),
O_RDWR | O_CREAT | O_CLOEXEC,
S_IRUSR | S_IWUSR);

Expand Down
6 changes: 3 additions & 3 deletions common/misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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," -");
Expand Down
92 changes: 46 additions & 46 deletions common/ptimer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
Expand All @@ -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
Expand All @@ -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
Expand All @@ -190,23 +190,23 @@ bool PersistentTimer::Store(Database *db) {
return(false);
}
safe_delete_array(query);

return(true);
}

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
Expand All @@ -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();
Expand All @@ -235,7 +235,7 @@ bool PersistentTimer::Expired(Database *db, bool iReset) {
}
return(true);
}

return(false);
}

Expand Down Expand Up @@ -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();
Expand All @@ -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
Expand All @@ -331,29 +331,29 @@ 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)) ) {
type = atoi(row[0]);
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);
}

Expand All @@ -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
Expand All @@ -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);
Expand Down Expand Up @@ -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()) {
Expand All @@ -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
Expand All @@ -497,7 +497,7 @@ bool PTimerList::ClearOffline(Database *db, uint32 char_id, pTimerType type) {
return(false);
}
safe_delete_array(query);

return(true);


Expand Down
Loading

0 comments on commit f746941

Please sign in to comment.