Commit initial: GNUWorld servicii IRC cu README.md complet in limba romana - Analiza arhitecturala completa a proiectului - Documentatie ierarhie clase, bucla de evenimente, protocol P10 - Identificare probleme memorie si recomandari modernizare
This commit is contained in:
commit
fcb24f6de9
870 files changed
+311128
No files matched your search
@@ -0,0 +1 @@
|
||||
precious ^defs.h$
|
||||
@@ -0,0 +1,3 @@
|
||||
defs.h
|
||||
stamp-h*
|
||||
.arch-ids
|
||||
@@ -0,0 +1,627 @@
|
||||
/*
|
||||
* Channel.h
|
||||
* Author: Daniel Karrels (dan@karerls.com)
|
||||
* Copyright (C) 2002 Daniel Karrels <dan@karrels.com>
|
||||
*
|
||||
* 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; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; 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.
|
||||
*
|
||||
* $Id: Channel.h,v 1.37 2008/04/16 20:29:36 danielaustin Exp $
|
||||
*/
|
||||
|
||||
#ifndef __CHANNEL_H
|
||||
#define __CHANNEL_H "$Id: Channel.h,v 1.37 2008/04/16 20:29:36 danielaustin Exp $"
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <list>
|
||||
#include <utility>
|
||||
|
||||
#include <ctime>
|
||||
|
||||
#include "ChannelUser.h"
|
||||
#include "xparameters.h"
|
||||
#include "ELog.h"
|
||||
#include "gnuworld_config.h"
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
|
||||
/// Forward declaration of class iClient.
|
||||
class iClient ;
|
||||
|
||||
/**
|
||||
* This class represents a single network channel.
|
||||
* Channel users are also maintained in this structure.
|
||||
*/
|
||||
class Channel
|
||||
{
|
||||
|
||||
protected:
|
||||
|
||||
/**
|
||||
* The type used to hold this channel's users.
|
||||
*/
|
||||
typedef std::map< unsigned int, ChannelUser* > userListType ;
|
||||
|
||||
/**
|
||||
* The type to be used to store channel bans.
|
||||
*/
|
||||
typedef std::list< std::string > banListType ;
|
||||
|
||||
/// Make class xServer a friend of this class.
|
||||
friend class xServer ;
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* The type used to store this channel's current channel
|
||||
* modes.
|
||||
*/
|
||||
typedef unsigned short int modeType ;
|
||||
|
||||
/// Bit representing channel mode +t
|
||||
static const modeType MODE_T ;
|
||||
|
||||
/// Bit representing channel mode +n
|
||||
static const modeType MODE_N ;
|
||||
|
||||
/// Bit representing channel mode +s
|
||||
static const modeType MODE_S ;
|
||||
|
||||
/// Bit representing channel mode +p
|
||||
static const modeType MODE_P ;
|
||||
|
||||
/// Bit representing channel mode +k
|
||||
static const modeType MODE_K ;
|
||||
|
||||
/// Bit representing channel mode +l
|
||||
static const modeType MODE_L ;
|
||||
|
||||
/// Bit representing channel mode +m
|
||||
static const modeType MODE_M ;
|
||||
|
||||
/// Bit representing channel mode +i
|
||||
static const modeType MODE_I ;
|
||||
|
||||
/// Bit representing channel mode +r
|
||||
static const modeType MODE_R ;
|
||||
|
||||
/// Bit representing channel mode +R
|
||||
static const modeType MODE_REG ;
|
||||
|
||||
/// Bit representing channel mode +D
|
||||
static const modeType MODE_D ;
|
||||
|
||||
/// Bit representing channel mode +A
|
||||
static const modeType MODE_A ;
|
||||
|
||||
/// Bit representing channel mode +U
|
||||
static const modeType MODE_U ;
|
||||
|
||||
/// Type used to store number of clients in channel
|
||||
typedef userListType::size_type size_type ;
|
||||
|
||||
/**
|
||||
* The type used for mutable iteration through this
|
||||
* channel's user structure.
|
||||
*/
|
||||
typedef userListType::iterator userIterator ;
|
||||
|
||||
/**
|
||||
* The type used for immutable iteration through this
|
||||
* channel's user structure.
|
||||
*/
|
||||
typedef userListType::const_iterator const_userIterator ;
|
||||
|
||||
/**
|
||||
* The type used for immutable iteration through this
|
||||
* channel's ban structure.
|
||||
*/
|
||||
typedef banListType::const_iterator const_banIterator ;
|
||||
|
||||
/**
|
||||
* The type used for mutable iteration through this
|
||||
* channel's ban structure.
|
||||
*/
|
||||
typedef banListType::iterator banIterator ;
|
||||
|
||||
/**
|
||||
* Construct a channel of the given name, constructed at the
|
||||
* given creation time.
|
||||
*/
|
||||
Channel( const std::string& _name,
|
||||
const time_t& _creationTime ) ;
|
||||
|
||||
/**
|
||||
* Destroy this channel.
|
||||
*/
|
||||
virtual ~Channel() ;
|
||||
|
||||
/**
|
||||
* Test if a given channel mode is set.
|
||||
*/
|
||||
inline bool getMode( const modeType& whichMode ) const
|
||||
{ return (whichMode == (modes & whichMode)) ; }
|
||||
|
||||
/**
|
||||
* Set the given channel mode.
|
||||
*/
|
||||
inline void setMode( const modeType& whichMode )
|
||||
{ modes |= whichMode ; }
|
||||
|
||||
/**
|
||||
* Remove the given channel mode.
|
||||
*/
|
||||
inline void removeMode( const modeType& whichMode )
|
||||
{ modes &= ~whichMode ; }
|
||||
|
||||
/**
|
||||
* Return true if the given mode is set for the the ChannelUser
|
||||
* corresponding to the given iClient.
|
||||
*/
|
||||
bool getUserMode( const ChannelUser::modeType& whichMode,
|
||||
iClient* ) const ;
|
||||
|
||||
/**
|
||||
* Remove the given mode from the ChannelUser associated with
|
||||
* the given iClient.
|
||||
*/
|
||||
bool removeUserMode( const ChannelUser::modeType& whichMode,
|
||||
iClient* ) ;
|
||||
|
||||
/**
|
||||
* Set the given mode for the ChannelUser associated with the
|
||||
* given iClient.
|
||||
*/
|
||||
bool setUserMode( const ChannelUser::modeType& whichMode,
|
||||
iClient* ) ;
|
||||
|
||||
/**
|
||||
* Set a limit on the channel. This method will set the
|
||||
* channel mode and set the limit.
|
||||
*/
|
||||
inline void setLimit( const unsigned int& newLimit )
|
||||
{ limit = newLimit ; }
|
||||
|
||||
/**
|
||||
* Set a key on the channel. This method will set the
|
||||
* channel mode and the key as well.
|
||||
*/
|
||||
inline void setKey( const std::string& newKey )
|
||||
{ key = newKey ; }
|
||||
|
||||
/**
|
||||
* Set an Apass on the channel. This method will set the
|
||||
* channel mode and the Apass as well.
|
||||
*/
|
||||
inline void setApass( const std::string& newApass )
|
||||
{ Apass = newApass ; }
|
||||
|
||||
/**
|
||||
* Set an Upass on the channel. This method will set the
|
||||
* channel mode and the Upass as well.
|
||||
*/
|
||||
inline void setUpass( const std::string& newUpass )
|
||||
{ Upass = newUpass ; }
|
||||
|
||||
/**
|
||||
* Add a ban to this Channel's ban list.
|
||||
*/
|
||||
void setBan( const std::string& banMask ) ;
|
||||
|
||||
/**
|
||||
* Remove a ban from this channel's ban list. This does a lexical
|
||||
* comparison, not a wildcard match.
|
||||
* Returns true if ban found (and removed), false if not
|
||||
* found.
|
||||
*/
|
||||
bool removeBan( const std::string& banMask ) ;
|
||||
|
||||
/**
|
||||
* Remove all the bans in the channels ban list.
|
||||
*/
|
||||
inline void removeAllBans()
|
||||
{ banList.clear(); }
|
||||
|
||||
/**
|
||||
* Remove all channel modes on users and the channel itself.
|
||||
* Use with caution.
|
||||
*/
|
||||
void removeAllModes() ;
|
||||
|
||||
/**
|
||||
* Find a ban in the channel's ban list which lexically matches
|
||||
* the given banMask.
|
||||
*/
|
||||
bool findBan( const std::string& banMask ) const ;
|
||||
|
||||
/**
|
||||
* Find a ban in the channel's ban list which wildcard matches
|
||||
* the given banMask.
|
||||
*/
|
||||
bool matchBan( const std::string& banMask ) const ;
|
||||
|
||||
/**
|
||||
* Search for a ban that matches the mask in (banMask).
|
||||
* If a matching ban is found, it is stored in (matchingBan),
|
||||
* and true is returned.
|
||||
* Otherwise, (matchingBan) is unmodified, and false is
|
||||
* returned.
|
||||
*/
|
||||
inline bool getMatchingBan( const std::string& banMask,
|
||||
std::string& matchingBan ) const ;
|
||||
|
||||
/**
|
||||
* Retrieve the current channel modes.
|
||||
*/
|
||||
inline const modeType& getModes() const
|
||||
{ return modes ; }
|
||||
|
||||
/**
|
||||
* Retrieve a string of the current channel modes.
|
||||
*/
|
||||
const std::string getModeString() const ;
|
||||
|
||||
/**
|
||||
* Type used to store the size of the banlist.
|
||||
*/
|
||||
typedef banListType::size_type banListSizeType ;
|
||||
|
||||
/**
|
||||
* Retrieve the number of elements in the ban list.
|
||||
*/
|
||||
inline banListSizeType banList_size() const
|
||||
{ return banList.size() ; }
|
||||
|
||||
/**
|
||||
* Retrieve the name of this channel.
|
||||
*/
|
||||
inline const std::string& getName() const
|
||||
{ return name ; }
|
||||
|
||||
/**
|
||||
* Retrieve the creation time of this channel.
|
||||
*/
|
||||
inline const time_t& getCreationTime() const
|
||||
{ return creationTime ; }
|
||||
|
||||
/**
|
||||
* Set the creation time of this channel. This is protected
|
||||
* so that only class xServer may access it externally.
|
||||
*/
|
||||
inline virtual void setCreationTime( const time_t& newCT )
|
||||
{ creationTime = newCT ; }
|
||||
|
||||
/**
|
||||
* Retrieve this channel's key. Note that the
|
||||
* existence of a key does not mean that channel
|
||||
* mode +k is set.
|
||||
*/
|
||||
inline const std::string& getKey() const
|
||||
{ return key ; }
|
||||
|
||||
/**
|
||||
* Retrieve this channel's Apass. Note that the
|
||||
* existence of an Apass does not mean that channel
|
||||
* mode +A is set.
|
||||
*/
|
||||
inline const std::string& getApass() const
|
||||
{ return Apass ; }
|
||||
|
||||
/**
|
||||
* Retrieve this channel's Upass. Note that the
|
||||
* existence of an Upass does not mean that channel
|
||||
* mode +U is set.
|
||||
*/
|
||||
inline const std::string& getUpass() const
|
||||
{ return Upass ; }
|
||||
|
||||
/**
|
||||
* Retrieve this channel's limit. Note that the
|
||||
* existence of a limit here does not mean that
|
||||
* channel mode +l is set.
|
||||
*/
|
||||
inline const unsigned int& getLimit() const
|
||||
{ return limit ; }
|
||||
|
||||
/**
|
||||
* Return true if no clients remain in this channel,
|
||||
* false otherwise.
|
||||
*/
|
||||
inline bool empty() const
|
||||
{ return userList.empty() ; }
|
||||
|
||||
/**
|
||||
* Return the number of clients in this channel.
|
||||
*/
|
||||
inline size_type size() const
|
||||
{ return userList.size() ; }
|
||||
|
||||
/**
|
||||
* Retrieve a const_iterator to the beginning of the ban list.
|
||||
*/
|
||||
inline const_banIterator banList_begin() const
|
||||
{ return banList.begin() ; }
|
||||
|
||||
/**
|
||||
* Retrieve a const_iterator to the end of the channel ban list.
|
||||
*/
|
||||
inline const_banIterator banList_end() const
|
||||
{ return banList.end() ; }
|
||||
|
||||
/**
|
||||
* Retrieve an iterator to the beginning of the ban list.
|
||||
*/
|
||||
inline banIterator banList_begin()
|
||||
{ return banList.begin() ; }
|
||||
|
||||
/**
|
||||
* Retrieve an iterator to the end of the channel ban list.
|
||||
*/
|
||||
inline banIterator banList_end()
|
||||
{ return banList.end() ; }
|
||||
|
||||
/**
|
||||
* Retrieve an iterator to the beginning of
|
||||
* this channel's user structure.
|
||||
*/
|
||||
inline userIterator userList_begin()
|
||||
{ return userList.begin() ; }
|
||||
|
||||
/**
|
||||
* Retrieve an iterator to the end of
|
||||
* this channel's user structure.
|
||||
*/
|
||||
inline userIterator userList_end()
|
||||
{ return userList.end() ; }
|
||||
|
||||
/**
|
||||
* Retrieve a const iterator to the beginning of
|
||||
* this channel's user structure.
|
||||
*/
|
||||
inline const_userIterator userList_begin() const
|
||||
{ return userList.begin() ; }
|
||||
|
||||
/**
|
||||
* Retrieve a const iterator to the end of this
|
||||
* channel's user structure.
|
||||
*/
|
||||
inline const_userIterator userList_end() const
|
||||
{ return userList.end() ; }
|
||||
|
||||
/**
|
||||
* Add a ChannelUser to this channel's internal user
|
||||
* structure.
|
||||
*/
|
||||
bool addUser( ChannelUser* newUser ) ;
|
||||
|
||||
/**
|
||||
* Add an iClient to this chanenl's internal user
|
||||
* structure.
|
||||
*/
|
||||
bool addUser( iClient* theClient ) ;
|
||||
|
||||
/**
|
||||
* Remove a ChannelUser from this channel's internal
|
||||
* user structure. Note that the memory associated
|
||||
* with the ChannelUser is NOT deallocated, it is
|
||||
* returned to the caller.
|
||||
*/
|
||||
ChannelUser* removeUser( iClient* theClient ) ;
|
||||
|
||||
/**
|
||||
* Remove the given ChannelUser from this Channel.
|
||||
*/
|
||||
ChannelUser* removeUser( ChannelUser* theUser ) ;
|
||||
|
||||
/**
|
||||
* Remove a ChannelUser from this channel's internal
|
||||
* user structure. Note that the memory associated
|
||||
* with the ChannelUser is NOT deallocated, it is
|
||||
* returned to the caller.
|
||||
*/
|
||||
ChannelUser* removeUser( const unsigned int& intYYXXX ) ;
|
||||
|
||||
/**
|
||||
* Return the ChannelUser associated with the given iClient,
|
||||
* NULL if not found.
|
||||
*/
|
||||
ChannelUser* findUser( const iClient* theClient ) const ;
|
||||
|
||||
#ifdef TOPIC_TRACK
|
||||
|
||||
/**
|
||||
* Returns the channel topic (if TOPIC_TRACK is defined)
|
||||
*/
|
||||
const std::string& getTopic() const
|
||||
{ return topic; }
|
||||
|
||||
const std::string& getTopicWhoSet() const
|
||||
{ return topic_whoset; }
|
||||
|
||||
const long& getTopicTS() const
|
||||
{ return topic_ts; }
|
||||
|
||||
/**
|
||||
* Sets this channel's topic value to the value passed in.
|
||||
* This method exists only if TOPIC_TRACK is defined.
|
||||
*/
|
||||
void setTopic( const std::string& _Topic )
|
||||
{ topic = _Topic; }
|
||||
|
||||
void setTopicWhoSet( const std::string& _TopicWhoSet )
|
||||
{ topic_whoset = _TopicWhoSet; }
|
||||
|
||||
void setTopicTS( const long& _TopicTS )
|
||||
{ topic_ts = _TopicTS; }
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Convenience operator for outputting Channel information
|
||||
* to a C++ output stream.
|
||||
*/
|
||||
friend ELog& operator<<( ELog& out, const Channel& rhs )
|
||||
{
|
||||
out << "Name: " << rhs.name
|
||||
<< ", creation time: " << rhs.creationTime ;
|
||||
return out ;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a level 2 ban for the given user.
|
||||
*/
|
||||
static std::string createBan( const iClient* ) ;
|
||||
|
||||
/**
|
||||
* Return a uniform *!*@ip/host form ban for the given user.
|
||||
*/
|
||||
static std::string createUniformBan( const iClient* ) ;
|
||||
|
||||
protected:
|
||||
|
||||
/**
|
||||
* Handle one or more "simple" mode changes.
|
||||
*/
|
||||
virtual void onMode( const std::vector<
|
||||
std::pair< bool, modeType > >& ) ;
|
||||
|
||||
/**
|
||||
* This method is called when channel mode 'l' is set
|
||||
* or unset.
|
||||
*/
|
||||
virtual void onModeL( bool, const unsigned int& ) ;
|
||||
|
||||
/**
|
||||
* This method is called when channel mode 'k' is set
|
||||
* or unset.
|
||||
*/
|
||||
virtual void onModeK( bool, const std::string& ) ;
|
||||
|
||||
/**
|
||||
* This method is called when channel mode 'A' is set
|
||||
* or unset.
|
||||
*/
|
||||
virtual void onModeA( bool, const std::string& ) ;
|
||||
|
||||
/**
|
||||
* This method is called when channel mode 'U' is set
|
||||
* or unset.
|
||||
*/
|
||||
virtual void onModeU( bool, const std::string& ) ;
|
||||
|
||||
/**
|
||||
* This method is called when one or more channel
|
||||
* mode (t)'s is/are set or unset.
|
||||
*/
|
||||
virtual void onModeO( const std::vector<
|
||||
std::pair< bool, ChannelUser* > >& ) ;
|
||||
|
||||
/**
|
||||
* This method is called when one or more channel
|
||||
* mode (t)'s is/are set or unset.
|
||||
*/
|
||||
virtual void onModeH( const std::vector<
|
||||
std::pair< bool, ChannelUser* > >& ) ;
|
||||
|
||||
/**
|
||||
* This method is called when one or more channel
|
||||
* mode (v)'s is/are set or unset.
|
||||
*/
|
||||
virtual void onModeV( const std::vector<
|
||||
std::pair< bool, ChannelUser* > >& ) ;
|
||||
|
||||
/**
|
||||
* This method is called when one or more channel
|
||||
* mode (b)'s is/are set or unset.
|
||||
* This method will add to the vector passed to it any
|
||||
* bans that have been removed as a result of newly added
|
||||
* overlapping bans.
|
||||
*/
|
||||
virtual void onModeB( std::vector<
|
||||
std::pair< bool, std::string > >& ) ;
|
||||
|
||||
/**
|
||||
* The name of this channel.
|
||||
*/
|
||||
std::string name ;
|
||||
|
||||
/**
|
||||
* The time at which this channel was created.
|
||||
*/
|
||||
time_t creationTime ;
|
||||
|
||||
/**
|
||||
* This channel's current modes.
|
||||
*/
|
||||
modeType modes ;
|
||||
|
||||
/**
|
||||
* The limit associated with this channel.
|
||||
* Note that this variable may hold values
|
||||
* even when channel mode +l is NOT set.
|
||||
*/
|
||||
unsigned int limit ;
|
||||
|
||||
/**
|
||||
* The key associated with this channel.
|
||||
* Note that this variable may hold values
|
||||
* even when channel mode +k is NOT set.
|
||||
*/
|
||||
std::string key ;
|
||||
|
||||
/**
|
||||
* The Apass associated with this channel.
|
||||
* Note that this variable may hold values
|
||||
* even when channel mode +A is NOT set.
|
||||
*/
|
||||
std::string Apass ;
|
||||
|
||||
/**
|
||||
* The Upass associated with this channel.
|
||||
* Note that this variable may hold values
|
||||
* even when channel mode +U is NOT set.
|
||||
*/
|
||||
std::string Upass ;
|
||||
|
||||
/**
|
||||
* The structure used to hold the ChannelUser
|
||||
* instances.
|
||||
*/
|
||||
userListType userList ;
|
||||
|
||||
/**
|
||||
* The structure used to store the channel bans.
|
||||
*/
|
||||
banListType banList ;
|
||||
|
||||
#ifdef TOPIC_TRACK
|
||||
/**
|
||||
* This channel's topic, only if TOPIC_TRACK is defined.
|
||||
*/
|
||||
std::string topic;
|
||||
|
||||
std::string topic_whoset;
|
||||
|
||||
long topic_ts;
|
||||
#endif
|
||||
|
||||
} ;
|
||||
|
||||
} // namespace gnuworld
|
||||
|
||||
#endif // __CHANNEL_H
|
||||
@@ -0,0 +1,276 @@
|
||||
/**
|
||||
* ChannelUser.h
|
||||
* Copyright (C) 2002 Daniel Karrels <dan@karrels.com>
|
||||
*
|
||||
* 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; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; 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.
|
||||
*
|
||||
* $Id: ChannelUser.h,v 1.16 2009/07/26 18:30:37 mrbean_ Exp $
|
||||
*/
|
||||
|
||||
#ifndef __CHANNELUSER_H
|
||||
#define __CHANNELUSER_H "$Id: ChannelUser.h,v 1.16 2009/07/26 18:30:37 mrbean_ Exp $"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "ELog.h"
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
|
||||
/// Forward declaration of class iClient.
|
||||
class iClient ;
|
||||
|
||||
/**
|
||||
* This class represents an individual channel patron, one
|
||||
* instance for each user in each channel.
|
||||
*/
|
||||
class ChannelUser
|
||||
{
|
||||
|
||||
public:
|
||||
/**
|
||||
* The type to be used for this ChannelUser's channel
|
||||
* modes.
|
||||
*/
|
||||
typedef unsigned char modeType ;
|
||||
|
||||
/// Bit representing channel user mode +o
|
||||
static const modeType MODE_O ;
|
||||
|
||||
/// Bit representing channel user mode +h
|
||||
static const modeType MODE_H ;
|
||||
|
||||
/// Bit representing channel user mode +v
|
||||
static const modeType MODE_V ;
|
||||
|
||||
/**
|
||||
* Track if this user made an opmode
|
||||
*/
|
||||
bool madeOpMode;
|
||||
|
||||
/**
|
||||
* Construct a ChannelUser given an iClient
|
||||
* pointer.
|
||||
*/
|
||||
ChannelUser( iClient* ) ;
|
||||
|
||||
/**
|
||||
* Destroy this ChannelUser.
|
||||
* No heap space allocated.
|
||||
*/
|
||||
virtual ~ChannelUser() ;
|
||||
|
||||
/**
|
||||
* Retrieve a given channel user mode.
|
||||
*/
|
||||
inline bool getMode( const modeType& whichMode ) const
|
||||
{ return (whichMode == (modes & whichMode)) ; }
|
||||
|
||||
/**
|
||||
* Return true if this user has mode +o on this channel,
|
||||
* false otherwise.
|
||||
*/
|
||||
inline bool isModeO() const
|
||||
{ return getMode( MODE_O ) ; }
|
||||
|
||||
/**
|
||||
* Return true if this user has mode +h on this channel,
|
||||
* false otherwise.
|
||||
*/
|
||||
inline bool isModeH() const
|
||||
{ return getMode( MODE_H ) ; }
|
||||
|
||||
/**
|
||||
* Return true if this user has mode +v on this channel,
|
||||
* false otherwise.
|
||||
*/
|
||||
inline bool isModeV() const
|
||||
{ return getMode( MODE_V ) ; }
|
||||
|
||||
inline bool isMadeOpMode() const
|
||||
{ return madeOpMode ; }
|
||||
/**
|
||||
* Retrieve this ChannelUser's current modes in
|
||||
* its channel.
|
||||
*/
|
||||
inline const modeType& getModes() const
|
||||
{ return modes ; }
|
||||
|
||||
/**
|
||||
* Set a given channel user mode.
|
||||
*/
|
||||
inline void setMode( const modeType& whichMode )
|
||||
{ modes |= whichMode ; }
|
||||
|
||||
/**
|
||||
* Set the user's mode +o state in this channel.
|
||||
*/
|
||||
inline void setModeO()
|
||||
{ setMode( MODE_O ) ; }
|
||||
|
||||
/**
|
||||
* Set the user's mode +h state in this channel.
|
||||
*/
|
||||
inline void setModeH()
|
||||
{ setMode( MODE_H ) ; }
|
||||
|
||||
/**
|
||||
* Set the user's mode +v state in this channel.
|
||||
*/
|
||||
inline void setModeV()
|
||||
{ return setMode( MODE_V ) ; }
|
||||
|
||||
|
||||
/**
|
||||
* Remove a given channel user mode.
|
||||
*/
|
||||
inline void removeMode( const modeType& whichMode )
|
||||
{ modes &= ~whichMode ; }
|
||||
|
||||
/**
|
||||
* Remove the user's mode +o state in this channel.
|
||||
*/
|
||||
inline void removeModeO()
|
||||
{ removeMode( MODE_O ) ; }
|
||||
|
||||
/**
|
||||
* Remove the user's mode +h state in this channel.
|
||||
*/
|
||||
inline void removeModeH()
|
||||
{ removeMode( MODE_H ) ; }
|
||||
|
||||
/**
|
||||
* Remove the user's mode +v state in this channel.
|
||||
*/
|
||||
inline void removeModeV()
|
||||
{ removeMode( MODE_V ) ; }
|
||||
|
||||
/**
|
||||
* Set the user's mode +v state in this channel.
|
||||
*/
|
||||
void setMadeOpMode();
|
||||
|
||||
void removeMadeOpMode();
|
||||
|
||||
|
||||
/*
|
||||
* These are not defined in the header file to avoid
|
||||
* recursive includes.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Retrieve this user's nick name.
|
||||
* Note that this method will simply query this
|
||||
* instance's iClient object for the nick name.
|
||||
* Thus, if the user changes its nickname, this
|
||||
* will be reflected automatically.
|
||||
*/
|
||||
const std::string& getNickName() const ;
|
||||
|
||||
/**
|
||||
* Retrieve this user's user name.
|
||||
*/
|
||||
const std::string& getUserName() const ;
|
||||
|
||||
/**
|
||||
* Retrieve this channel user's host name.
|
||||
*/
|
||||
const std::string& getHostName() const ;
|
||||
|
||||
/**
|
||||
* Retrieve this channel user's network numeric.
|
||||
*/
|
||||
const std::string getCharYYXXX() const ;
|
||||
|
||||
/**
|
||||
* Retrieve this channel user's IP.
|
||||
*/
|
||||
const unsigned int& getIP() const ;
|
||||
|
||||
/**
|
||||
* Retrieve this channel user's integer representation
|
||||
* of its server numeric.
|
||||
*/
|
||||
unsigned int getIntYY() const ;
|
||||
|
||||
/**
|
||||
* Retrieve this channel user's integer representation
|
||||
* of its client numeric.
|
||||
*/
|
||||
unsigned int getIntXXX() const ;
|
||||
|
||||
/**
|
||||
* Retrieve this channel user's integer representation
|
||||
* of its network numeric.
|
||||
*/
|
||||
unsigned int getIntYYXXX() const ;
|
||||
|
||||
/**
|
||||
* Return true if this client is an oper.
|
||||
*/
|
||||
bool isOper() const ;
|
||||
|
||||
/**
|
||||
* Return a pointer to the iClient to which this ChannelUser
|
||||
* is associated.
|
||||
* Use of this method is strongly discouraged.
|
||||
*/
|
||||
inline iClient* getClient() const
|
||||
{ return theClient ; }
|
||||
|
||||
/**
|
||||
* Return a human readable string of modes this user has
|
||||
* in the channel.
|
||||
* Valid modes are:
|
||||
* - "op"
|
||||
* - "voice"
|
||||
* - "oper"
|
||||
*/
|
||||
std::string getModeString() const ;
|
||||
|
||||
/**
|
||||
* Convenience operator method for outputting this
|
||||
* ChannelUser's information to a C++ standard
|
||||
* output stream.
|
||||
*/
|
||||
friend ELog& operator<<( ELog& out, const ChannelUser& rhs )
|
||||
{
|
||||
out << rhs.getNickName() << '!'
|
||||
<< rhs.getUserName() << '@'
|
||||
<< rhs.getHostName() << ' '
|
||||
<< rhs.getCharYYXXX()
|
||||
<< " user modes: "
|
||||
<< rhs.getModeString() ;
|
||||
return out ;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
/**
|
||||
* The iClient to which this ChannelUser instance is associated.
|
||||
*/
|
||||
iClient* theClient ;
|
||||
|
||||
/**
|
||||
* This channel user's modes in the current channel.
|
||||
*/
|
||||
modeType modes ;
|
||||
|
||||
} ;
|
||||
|
||||
} // namespace gnuworld
|
||||
|
||||
#endif // __CHANNELUSER_H
|
||||
+192
@@ -0,0 +1,192 @@
|
||||
/**
|
||||
* Gline.h
|
||||
* Copyright (C) 2002 Daniel Karrels <dan@karrels.com>
|
||||
*
|
||||
* 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; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; 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.
|
||||
*
|
||||
* $Id: Gline.h,v 1.7 2003/12/29 23:59:36 dan_karrels Exp $
|
||||
*/
|
||||
|
||||
#ifndef __GLINE_H
|
||||
#define __GLINE_H "$Id: Gline.h,v 1.7 2003/12/29 23:59:36 dan_karrels Exp $"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <ctime>
|
||||
|
||||
#include "misc.h"
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
|
||||
/**
|
||||
* A simple data storage class which represents a network G-Line.
|
||||
*/
|
||||
class Gline
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Construct a Gline instance given the nick!user@host of the
|
||||
* user requesting it, the userHost being glined, th reason
|
||||
* for the gline, and the duration (in seconds) of the
|
||||
* gline.
|
||||
*/
|
||||
Gline( const std::string& _setBy,
|
||||
const std::string& _userHost,
|
||||
const std::string& _reason,
|
||||
const time_t& _duration ,
|
||||
const time_t& _lastmod = ::time( 0 ))
|
||||
: setBy( _setBy ),
|
||||
userHost( _userHost ),
|
||||
reason( _reason ),
|
||||
expiration( _duration + ::time( 0 ) ),
|
||||
lastmod( _lastmod )
|
||||
{}
|
||||
|
||||
/**
|
||||
* Copy constructor.
|
||||
* Construct a Gline given another Gline.
|
||||
*/
|
||||
Gline( const Gline& rhs )
|
||||
: setBy( rhs.setBy ),
|
||||
userHost( rhs.userHost ),
|
||||
reason( rhs.reason ),
|
||||
expiration( rhs.expiration ),
|
||||
lastmod (rhs.lastmod)
|
||||
{}
|
||||
|
||||
/**
|
||||
* Destroy this gline. No heap space allocated.
|
||||
*/
|
||||
virtual ~Gline()
|
||||
{}
|
||||
|
||||
/**
|
||||
* Return true if this Gline is equivalent (case insensitive)
|
||||
* to the given userHost mask.
|
||||
* This does NOT perform a wildcard match.
|
||||
*/
|
||||
inline bool operator==( const std::string& _userHost ) const
|
||||
{ return (0 == strcasecmp( userHost, _userHost )) ; }
|
||||
|
||||
/**
|
||||
* Retrieve the nick!user@host of the user who set this gline.
|
||||
*/
|
||||
inline const std::string& getSetBy() const
|
||||
{ return setBy ; }
|
||||
|
||||
/**
|
||||
* Retrieve the user@host which has been glined.
|
||||
*/
|
||||
inline const std::string& getUserHost() const
|
||||
{ return userHost ; }
|
||||
|
||||
/**
|
||||
* Retrieve the reason for this gline.
|
||||
*/
|
||||
inline const std::string& getReason() const
|
||||
{ return reason ; }
|
||||
|
||||
/**
|
||||
* Retrieve the time at which this gline will expire.
|
||||
*/
|
||||
inline const time_t& getExpiration() const
|
||||
{ return expiration ; }
|
||||
|
||||
/**
|
||||
* Retrieve the time at which the gline was last modified
|
||||
*/
|
||||
inline const time_t& getLastmod() const
|
||||
{ return lastmod ; }
|
||||
|
||||
/**
|
||||
* Retrieve the user/server who set this gline.
|
||||
*/
|
||||
inline void setSetBy( const std::string& _setBy )
|
||||
{ setBy = _setBy; }
|
||||
|
||||
/**
|
||||
* Set the hostmask affected by this gline.
|
||||
*/
|
||||
inline void setHost( const std::string& _host )
|
||||
{ userHost = _host; }
|
||||
|
||||
/**
|
||||
* Set the reason for this gline.
|
||||
*/
|
||||
inline void setReason( const std::string& _reason )
|
||||
{ reason = _reason; }
|
||||
|
||||
/**
|
||||
* Set the expiration time on this gline.
|
||||
*/
|
||||
inline void setExpiration( const time_t _expiration )
|
||||
{ expiration = _expiration; }
|
||||
|
||||
/**
|
||||
* Set the lastmod time
|
||||
*/
|
||||
inline void setLastmod( const time_t _lastmod )
|
||||
{ lastmod = _lastmod; }
|
||||
|
||||
/**
|
||||
* Convenience operator method which allows the output
|
||||
* of a Gline instance to a C++ standard output stream.
|
||||
*/
|
||||
friend ELog& operator<<( ELog& out, const Gline& rhs )
|
||||
{
|
||||
out << "Mask: " << rhs.userHost << ' '
|
||||
<< "Reason: " << rhs.reason << ' '
|
||||
<< "Set by: " << rhs.setBy << ' '
|
||||
<< "Expires: " << rhs.expiration << ' '
|
||||
<< "Last modified: " << rhs.lastmod ;
|
||||
return out ;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
/**
|
||||
* The nick!user@host of the user who set this gline.
|
||||
*/
|
||||
std::string setBy ;
|
||||
|
||||
/**
|
||||
* The banned user@host.
|
||||
*/
|
||||
std::string userHost ;
|
||||
|
||||
/**
|
||||
* The reason this gline was set.
|
||||
*/
|
||||
std::string reason ;
|
||||
|
||||
/**
|
||||
* The time at which this gline expires.
|
||||
*/
|
||||
time_t expiration ;
|
||||
|
||||
/**
|
||||
* The time at which this gline was last modified
|
||||
*/
|
||||
time_t lastmod ;
|
||||
|
||||
} ;
|
||||
|
||||
} // namespace gnuworld
|
||||
|
||||
#endif // __GLINE_H
|
||||
@@ -0,0 +1,84 @@
|
||||
/**
|
||||
* LoadClientTimerHandler.h
|
||||
* Copyright (C) 2002 Daniel Karrels <dan@karrels.com>
|
||||
*
|
||||
* 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; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; 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.
|
||||
*
|
||||
* $Id: LoadClientTimerHandler.h,v 1.6 2004/05/19 19:46:33 jeekay Exp $
|
||||
*/
|
||||
|
||||
#ifndef __LOADCLIENTTIMERHANDLER_H
|
||||
#define __LOADCLIENTTIMERHANDLER_H "$Id: LoadClientTimerHandler.h,v 1.6 2004/05/19 19:46:33 jeekay Exp $"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "ServerTimerHandlers.h"
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
|
||||
class xServer ;
|
||||
|
||||
/**
|
||||
* The purpose of this class is to load xClient's at a particular time,
|
||||
* it is used to perform xClient unload/loads while still allowing the
|
||||
* event system to give the xClient time to unload before reloading a
|
||||
* new instance.
|
||||
*/
|
||||
class LoadClientTimerHandler : public ServerTimerHandler
|
||||
{
|
||||
|
||||
protected:
|
||||
|
||||
/// The name of the module to be loaded
|
||||
std::string moduleName ;
|
||||
|
||||
/// The configuration file name to pass to the client constructor
|
||||
std::string configFileName ;
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Constructor receives:
|
||||
* - The xServer instance for the system
|
||||
* - The xClient's module name
|
||||
* - The configuration file name for the xClient.
|
||||
*/
|
||||
LoadClientTimerHandler( xServer* theServer,
|
||||
const std::string& _moduleName,
|
||||
const std::string& _configFileName )
|
||||
: ServerTimerHandler( theServer, 0),
|
||||
moduleName( _moduleName ),
|
||||
configFileName( _configFileName )
|
||||
{}
|
||||
|
||||
/**
|
||||
* Default destructor, nothing to do here atm.
|
||||
*/
|
||||
virtual ~LoadClientTimerHandler()
|
||||
{}
|
||||
|
||||
/**
|
||||
* The method that is called by the server when this handler's
|
||||
* time to perform has arrived.
|
||||
*/
|
||||
virtual void OnTimer( const timerID& , void* ) ;
|
||||
|
||||
} ;
|
||||
|
||||
} // namespace gnuworld
|
||||
|
||||
#endif // __LOADCLIENTTIMERHANDLER_H
|
||||
@@ -0,0 +1,993 @@
|
||||
/**
|
||||
* Network.h
|
||||
* Author: Daniel Karrels (dan@karrels.com)
|
||||
* Copyright (C) 2002 Daniel Karrels <dan@karrels.com>
|
||||
*
|
||||
* 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; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; 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.
|
||||
*
|
||||
* $Id: Network.h,v 1.48 2007/04/27 19:30:43 mrbean_ Exp $
|
||||
*/
|
||||
|
||||
#ifndef __NETWORK_H
|
||||
#define __NETWORK_H "$Id: Network.h,v 1.48 2007/04/27 19:30:43 mrbean_ Exp $"
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <set>
|
||||
#include <map>
|
||||
#include <list>
|
||||
|
||||
#include <ctime>
|
||||
|
||||
#include "iServer.h"
|
||||
#include "iClient.h"
|
||||
#include "Channel.h"
|
||||
#include "client.h"
|
||||
#include "misc.h" // struct noCaseCompare
|
||||
#include "gnuworld_config.h"
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
|
||||
class xServer ;
|
||||
|
||||
/**
|
||||
* This class is responsible for storing the network's iClient's,
|
||||
* iServer's, and local xClient's. This is done using several
|
||||
* tables, some of which are a bit non-trivial to understand at
|
||||
* first, but are actually very simple.
|
||||
* This is a big container class, mutated primarily by the
|
||||
* xServer instance.
|
||||
*
|
||||
* The following semantics about the addition and removal of
|
||||
* fake clients and servers is followed:
|
||||
*
|
||||
* addFake{client,server}
|
||||
* - Adds fake element of the {client,server}
|
||||
* - Adds normal element of the {client,server}
|
||||
*
|
||||
* add{Client,Server}
|
||||
* - Adds normal element of the {client,server}
|
||||
*
|
||||
* removeFake{client,server}
|
||||
* - Removes fake element of {client,server}
|
||||
*
|
||||
* remove{Client,Server}
|
||||
* - Removes normal element of {client,server}
|
||||
* - Removes fake element of {client,server}
|
||||
*
|
||||
* None of the remove* methods deallocate the {client,server}.
|
||||
* This also means that OnSplit() will properly clean up even
|
||||
* fake servers and clients.
|
||||
*/
|
||||
class xNetwork
|
||||
{
|
||||
/// Allow xServer to access this class's private
|
||||
/// members/methods.
|
||||
friend class xServer ;
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
* Type used to store all reserved intYY and intYYXXX's
|
||||
* for the local server and juped iClient/xClient/iServer's.
|
||||
* Keyed top level by the server's intYY, then each
|
||||
* set is keyed by intXXX for that particular server.
|
||||
*/
|
||||
typedef std::map< unsigned int, std::set< unsigned int > >
|
||||
reservedNumericMapType ;
|
||||
|
||||
/**
|
||||
* This is an iterator type definition for the
|
||||
* reservedNumericMapType.
|
||||
*/
|
||||
typedef reservedNumericMapType::iterator
|
||||
reservedNumeric_iterator ;
|
||||
|
||||
/**
|
||||
* This type maps fake iClient's to their owning
|
||||
* xClient's, keyed by the iClient's intYYXXX numeric.
|
||||
*/
|
||||
typedef std::map< unsigned int, std::pair< iClient*, xClient* > >
|
||||
fakeClientMapType ;
|
||||
|
||||
/**
|
||||
* This type stores fake (juped) servers.
|
||||
*/
|
||||
typedef std::map< unsigned int, std::pair< iServer*, xClient* > >
|
||||
fakeServerMapType ;
|
||||
|
||||
/**
|
||||
* This is the type of vector for storing
|
||||
* local (services) clients.
|
||||
*/
|
||||
typedef std::map< unsigned int, xClient* > xClientMapType ;
|
||||
|
||||
/**
|
||||
* This is the type used to store the network Channel
|
||||
* instances.
|
||||
*/
|
||||
typedef std::map< std::string, Channel*, noCaseCompare >
|
||||
channelMapType ;
|
||||
|
||||
/**
|
||||
* This is the type used to store the nick name/iClient* pairs.
|
||||
*/
|
||||
typedef std::map< std::string, iClient*, noCaseCompare >
|
||||
nickMapType ;
|
||||
|
||||
/**
|
||||
* The type used to store information about iClient's,
|
||||
* keyed by integer numeric.
|
||||
*/
|
||||
typedef std::map< unsigned int, iClient* > numericMapType ;
|
||||
|
||||
/**
|
||||
* The type used to store information about iServer's,
|
||||
* keyed by integer numeric.
|
||||
*/
|
||||
typedef std::map< unsigned int, iServer* > serverMapType ;
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* The default constructor handles all of the default
|
||||
* allocation and initialization.
|
||||
*/
|
||||
xNetwork() ;
|
||||
|
||||
/**
|
||||
* The default destructor will deallocate all objects
|
||||
* that are not explicitly removed from this structure.
|
||||
* Therefore, it is highly recommend that the application
|
||||
* programmer iterate through this structure and remove
|
||||
* all items before destroying this structure.
|
||||
*/
|
||||
virtual ~xNetwork() ;
|
||||
|
||||
/* Addition methods
|
||||
* These methods return true if addition is successful,
|
||||
* false otherwise.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Add a new iClient to the network. This will also handle
|
||||
* any additions into the nickname table, if required.
|
||||
* Returns false if the addition fails.
|
||||
*/
|
||||
virtual bool addClient( iClient* ) ;
|
||||
|
||||
/**
|
||||
* Add a fake client to this (or a juped) server. The
|
||||
* xClient is the "owner" of the iClient.
|
||||
* This method will fill in the iClient's intXXX/charXXX,
|
||||
* but the intYY/charYY must be valid.
|
||||
*/
|
||||
virtual bool addFakeClient( iClient* theClient,
|
||||
xClient* ownerClient ) ;
|
||||
|
||||
/**
|
||||
* Add a services client to the network table.
|
||||
* This is stored in the table of local clients.
|
||||
* Returns false if the addition fails.
|
||||
*/
|
||||
virtual bool addClient( xClient* ) ;
|
||||
|
||||
/**
|
||||
* Add a new server to the network table.
|
||||
* Returns false if the addition fails.
|
||||
*/
|
||||
virtual bool addServer( iServer* ) ;
|
||||
|
||||
/**
|
||||
* Add a new fake (juped) server to the structure
|
||||
* of fake servers.
|
||||
* Returns true on success, false on failure.
|
||||
*/
|
||||
virtual bool addFakeServer( iServer*, xClient* ) ;
|
||||
|
||||
/**
|
||||
* Add a new channel to the network table.
|
||||
* Returns false if the addition fails.
|
||||
*/
|
||||
virtual bool addChannel( Channel* ) ;
|
||||
|
||||
/*
|
||||
* All nickname based searches are case insensitive.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Find a remote client given the client's integer numeric.
|
||||
* Returns NULL if not found.
|
||||
*/
|
||||
virtual iClient* findClient( const unsigned int& YY,
|
||||
const unsigned int& XXX ) const ;
|
||||
|
||||
/**
|
||||
* Find a remote client given the client's integer numeric.
|
||||
* Returns NULL if not found.
|
||||
*/
|
||||
virtual iClient* findClient( const unsigned int& intYYXXX )
|
||||
const ;
|
||||
|
||||
/**
|
||||
* Find a fake client given the client's integer numeric.
|
||||
* Returns NULL if not found.
|
||||
*/
|
||||
virtual iClient* findFakeClient( const unsigned int& YY,
|
||||
const unsigned int& XXX ) const ;
|
||||
|
||||
/**
|
||||
* Find a remote client given the client's character numeric.
|
||||
* Returns NULL if not found.
|
||||
*/
|
||||
virtual iClient* findClient( const std::string& yyxxx )
|
||||
const ;
|
||||
|
||||
/**
|
||||
* Find a fake client by numeric.
|
||||
* Returns NULL if not found.
|
||||
*/
|
||||
virtual iClient* findFakeClient( const std::string& yyxxx )
|
||||
const ;
|
||||
|
||||
/**
|
||||
* Lookup a fake (juped) iClient.
|
||||
*/
|
||||
virtual iClient* findFakeClient( iClient* ) const ;
|
||||
|
||||
/**
|
||||
* Lookup the xClient owner of a particular iClient.
|
||||
*/
|
||||
virtual xClient* findFakeClientOwner( iClient* ) const ;
|
||||
|
||||
/**
|
||||
* Lookup all fake iClients belonging to an xClient.
|
||||
* If the xClient is NULL, return all fake clients.
|
||||
*/
|
||||
virtual std::list< iClient* > findFakeClients( xClient* ) const ;
|
||||
|
||||
/**
|
||||
* Retrieve a pointer to an iClient given its nick name.
|
||||
* Returns NULL if not found.
|
||||
*/
|
||||
virtual iClient* findNick( const std::string& nickName )
|
||||
const ;
|
||||
|
||||
/**
|
||||
* Find a local (services) client by its character numeric.
|
||||
* Returns NULL if not found.
|
||||
*/
|
||||
virtual xClient* findLocalClient( const std::string& yyxxx )
|
||||
const ;
|
||||
|
||||
/**
|
||||
* Find a local (services) client by its integer numeric.
|
||||
* Returns NULL if not found.
|
||||
*/
|
||||
virtual xClient* findLocalClient( const unsigned int& intYYXXX )
|
||||
const ;
|
||||
|
||||
/**
|
||||
* Find a local (services) client by its case-insensitive nickname.
|
||||
* Returns NULL if not found.
|
||||
*/
|
||||
virtual xClient* findLocalNick( const std::string& nickName )
|
||||
const ;
|
||||
|
||||
/**
|
||||
* Lookup a fake (juped) iClient by nickname.
|
||||
*/
|
||||
virtual iClient* findFakeNick( const std::string& nickName )
|
||||
const ;
|
||||
|
||||
/**
|
||||
* Find a remote server by its integer numeric.
|
||||
* Returns NULL if not found.
|
||||
*/
|
||||
virtual iServer* findServer( const unsigned int& YY ) const ;
|
||||
|
||||
/**
|
||||
* Find a fake server, return that server if it is fake (juped),
|
||||
* or NULL otherwise.
|
||||
*/
|
||||
virtual iServer* findFakeServer( const iServer* ) const ;
|
||||
|
||||
/**
|
||||
* Find a fake server described by the given intYY numeric.
|
||||
* Return 0 on failure.
|
||||
*/
|
||||
virtual iServer* findFakeServer( unsigned int intYY ) const ;
|
||||
|
||||
/**
|
||||
* Find a remote server by its character numeric.
|
||||
* Returns NULL if not found.
|
||||
*/
|
||||
virtual iServer* findServer( const std::string& YY ) const ;
|
||||
|
||||
/**
|
||||
* Find a remote server by its case-insensitive name.
|
||||
* Returns NULL if not found.
|
||||
*/
|
||||
virtual iServer* findServerName( const std::string& name )
|
||||
const ;
|
||||
|
||||
/**
|
||||
* Find a fake server by (case insensitive) name.
|
||||
*/
|
||||
virtual iServer* findFakeServerName( const std::string& )
|
||||
const ;
|
||||
|
||||
/**
|
||||
* Find a remote server by a wildmask name.
|
||||
* Returns NULL if not found.
|
||||
*/
|
||||
virtual iServer* findExpandedServerName(
|
||||
const std::string& name ) const ;
|
||||
/**
|
||||
* Returns all the servers which are currently in bursting state
|
||||
*/
|
||||
virtual std::list< iServer* > getAllBurstingServers();
|
||||
|
||||
/**
|
||||
* Find a global channel by case insensitive name.
|
||||
* Returns NULL if not found.
|
||||
*/
|
||||
virtual Channel* findChannel( const std::string& name )
|
||||
const ;
|
||||
|
||||
/* Removal methods. */
|
||||
|
||||
/**
|
||||
* Remove a remote client by integer numeric and return a
|
||||
* pointer to the iClient.
|
||||
* Return NULL if not found.
|
||||
*/
|
||||
virtual iClient* removeClient(
|
||||
const unsigned int& intYYXXX ) ;
|
||||
|
||||
/**
|
||||
* Remove a remote client by integer server and client numerics,
|
||||
* and return a pointer to the iClient.
|
||||
* Returns NULL if not found.
|
||||
*/
|
||||
virtual iClient* removeClient( const unsigned int& YY,
|
||||
const unsigned int& XXX ) ;
|
||||
|
||||
/**
|
||||
* Remove a remote client by character numeric, and return a
|
||||
* pointer to it.
|
||||
* Returns NULL if not found.
|
||||
*/
|
||||
virtual iClient* removeClient( const std::string& yyxxx ) ;
|
||||
|
||||
/**
|
||||
* Remove a remote client by its pointer.
|
||||
* This will NOT deallocate the iClient instance.
|
||||
*/
|
||||
virtual iClient* removeClient( iClient* ) ;
|
||||
|
||||
/**
|
||||
* Remove a local client from the network data tables.
|
||||
*/
|
||||
virtual xClient* removeLocalClient( xClient* ) ;
|
||||
|
||||
/**
|
||||
* Remove a fake client from the network data structures
|
||||
* and deallocate its reserved numeric.
|
||||
*/
|
||||
virtual iClient* removeFakeClient( iClient* ) ;
|
||||
|
||||
/**
|
||||
* Remove a fake server from the network data structures
|
||||
* and deallocate its reserved numeric.
|
||||
*/
|
||||
virtual iServer* removeFakeServer( iServer* ) ;
|
||||
|
||||
/**
|
||||
* Remove a fake iServer from the network data structures
|
||||
* by (case-insensitive) name, and remove its reserved
|
||||
* numeric.
|
||||
*/
|
||||
virtual iServer* removeFakeServerName( const std::string& ) ;
|
||||
|
||||
/**
|
||||
* Remove a nick name from the internal nick name table.
|
||||
* Note that this returns void. This is because nick names
|
||||
* are cross referenced in the nick name table. That is,
|
||||
* no heap space is allocated for elements in the nick name
|
||||
* table, they simply point to iClient instances.
|
||||
*/
|
||||
virtual void removeNick( const std::string& nickName ) ;
|
||||
|
||||
/**
|
||||
* Remove a remote server by its integer numeric, and
|
||||
* return a pointer to it.
|
||||
* When a server is removed, all its clients are also
|
||||
* removed. Each client is deleted, so make sure that
|
||||
* the clients added to the network table (this) are
|
||||
* allocated on the heap, and that there are no
|
||||
* other stale pointers to any clients.
|
||||
* If postEvent is true, then an EVT_QUIT will be generated
|
||||
* for each client removal.
|
||||
* Returns NULL if not found.
|
||||
*/
|
||||
virtual iServer* removeServer( const unsigned int& YY,
|
||||
bool postEvent = false ) ;
|
||||
|
||||
/**
|
||||
* Remove a remote server by its character numeric, and
|
||||
* return a pointer to it.
|
||||
* When a server is removed, all its clients are also
|
||||
* removed. Each client is deleted, so make sure that
|
||||
* the clients added to the network table (this) are
|
||||
* allocated on the heap, and that there are no
|
||||
* other stale pointers to any clients.
|
||||
* Returns NULL if not found.
|
||||
*/
|
||||
virtual iServer* removeServer( const std::string& YY ) ;
|
||||
|
||||
/**
|
||||
* Remove a remote server by its case-insensitive name, and
|
||||
* return a pointer to it.
|
||||
* When a server is removed, all its clients are also
|
||||
* removed. Each client is deleted, so make sure that
|
||||
* the clients added to the network table (this) are
|
||||
* allocated on the heap, and that there are no
|
||||
* other stale pointers to any clients.
|
||||
* Returns NULL if not found.
|
||||
*/
|
||||
virtual iServer* removeServerName( const std::string& name ) ;
|
||||
|
||||
/**
|
||||
* Remove a channel from the network table, keyed by its
|
||||
* case insensitive name.
|
||||
* Returns NULL if not found.
|
||||
*/
|
||||
virtual Channel* removeChannel( const std::string& name ) ;
|
||||
|
||||
/**
|
||||
* Remove a channel from the network table.
|
||||
* Returns the Channel which has been removed, or NULL if the
|
||||
* channel was not found.
|
||||
*/
|
||||
virtual Channel* removeChannel( const Channel* theChan ) ;
|
||||
|
||||
/* Utility methods */
|
||||
|
||||
/**
|
||||
* Change a remote client's nickname, given its character
|
||||
* numeric and new nickname.
|
||||
* This method does NOT work for local clients.
|
||||
*/
|
||||
virtual void rehashNick( const std::string& yyxxx,
|
||||
const std::string& newNick ) ;
|
||||
|
||||
/**
|
||||
* This method performs a recursive removal of all servers
|
||||
* which are uplinked by intYY.
|
||||
* The server referenced by intYY is deallocated in this
|
||||
* method.
|
||||
*/
|
||||
virtual void OnSplit( const unsigned int& intYY ) ;
|
||||
|
||||
/**
|
||||
* An iterator to a network (iClient), which allows mutation.
|
||||
* This iterator is a pair< const string (nickname), iClient* >.
|
||||
*/
|
||||
typedef nickMapType::iterator clientIterator ;
|
||||
|
||||
/**
|
||||
* Return a mutator to the beginning of the network client
|
||||
* data structure. The client referenced is mutable.
|
||||
*/
|
||||
inline clientIterator clients_begin()
|
||||
{ return nickMap.begin() ; }
|
||||
|
||||
/**
|
||||
* Return a mutator to the end of the network client
|
||||
* data structure. The client referenced is mutable.
|
||||
*/
|
||||
inline clientIterator clients_end()
|
||||
{ return nickMap.end() ; }
|
||||
|
||||
/**
|
||||
* An iterator to a network (iClient), which disallows mutation.
|
||||
* This iterator is a pair< const string (nickname), iClient* >.
|
||||
*/
|
||||
typedef nickMapType::const_iterator const_clientIterator ;
|
||||
|
||||
/**
|
||||
* Return a mutator to the beginning of the network client
|
||||
* data structure. The client referenced is immutable.
|
||||
*/
|
||||
inline const_clientIterator clients_begin() const
|
||||
{ return nickMap.begin() ; }
|
||||
|
||||
/**
|
||||
* Return a mutator to the end of the network client
|
||||
* data structure. The client referenced is immutable.
|
||||
*/
|
||||
inline const_clientIterator clients_end() const
|
||||
{ return nickMap.end() ; }
|
||||
|
||||
/**
|
||||
* Define a non-const iterator for walking through the
|
||||
* structure of remote servers.
|
||||
*/
|
||||
typedef serverMapType::iterator serverIterator ;
|
||||
|
||||
/**
|
||||
* Define a const iterator for walking through the structure
|
||||
* of remote servers.
|
||||
*/
|
||||
typedef serverMapType::const_iterator const_serverIterator ;
|
||||
|
||||
/**
|
||||
* Return a non-const iterator to the beginning of the
|
||||
* remote servers table.
|
||||
*/
|
||||
inline serverIterator servers_begin()
|
||||
{ return serverMap.begin() ; }
|
||||
|
||||
/**
|
||||
* Return a non-const iterator to the end of the
|
||||
* remote servers table.
|
||||
*/
|
||||
inline serverIterator servers_end()
|
||||
{ return serverMap.end() ; }
|
||||
|
||||
/**
|
||||
* Return a const iterator to the beginning of the
|
||||
* remote servers table.
|
||||
*/
|
||||
inline const_serverIterator servers_begin() const
|
||||
{ return serverMap.begin() ; }
|
||||
|
||||
/**
|
||||
* Return a const iterator to the end of the remote
|
||||
* servers table.
|
||||
*/
|
||||
inline const_serverIterator servers_end() const
|
||||
{ return serverMap.end() ; }
|
||||
|
||||
/**
|
||||
* Define a non-const iterator for walking through the
|
||||
* structure of local clients (xClients).
|
||||
*/
|
||||
typedef xClientMapType::iterator localClientIterator ;
|
||||
|
||||
/**
|
||||
* Define a const iterator for walking through the
|
||||
* structure of local clients (xClients).
|
||||
*/
|
||||
typedef xClientMapType::const_iterator const_localClientIterator ;
|
||||
|
||||
/**
|
||||
* Return a non-const iterator to the beginning of the
|
||||
* local clients table.
|
||||
*/
|
||||
inline localClientIterator localClient_begin()
|
||||
{ return localClients.begin() ; }
|
||||
|
||||
/**
|
||||
* Return a non-const iterator to the end of the local
|
||||
* clients table.
|
||||
*/
|
||||
inline localClientIterator localClient_end()
|
||||
{ return localClients.end() ; }
|
||||
|
||||
/**
|
||||
* Return a const iterator the beginning of the
|
||||
* local clients table.
|
||||
*/
|
||||
inline const_localClientIterator localClient_begin() const
|
||||
{ return localClients.begin() ; }
|
||||
|
||||
/**
|
||||
* Return a const iterator to the end of the local
|
||||
* clients table.
|
||||
*/
|
||||
inline const_localClientIterator localClient_end() const
|
||||
{ return localClients.end() ; }
|
||||
|
||||
/**
|
||||
* Define a const iterator for walking through the
|
||||
* channels structure
|
||||
*/
|
||||
typedef channelMapType::const_iterator const_channelIterator;
|
||||
|
||||
/**
|
||||
* Returns an iterator to the begining of the channels structure
|
||||
*/
|
||||
inline const_channelIterator channels_begin() const
|
||||
{ return channelMap.begin(); }
|
||||
|
||||
/**
|
||||
* Returns an iterator to the end of the channels structure
|
||||
*/
|
||||
inline const_channelIterator channels_end() const
|
||||
{ return channelMap.end(); }
|
||||
|
||||
/**
|
||||
* Define a mutating iterator for walking through the
|
||||
* channels structure
|
||||
*/
|
||||
typedef channelMapType::iterator channelIterator;
|
||||
|
||||
/**
|
||||
* Returns an iterator to the begining of the channels structure
|
||||
*/
|
||||
inline channelIterator channels_begin()
|
||||
{ return channelMap.begin(); }
|
||||
|
||||
/**
|
||||
* Returns an iterator to the end of the channels structure
|
||||
*/
|
||||
inline channelIterator channels_end()
|
||||
{ return channelMap.end(); }
|
||||
|
||||
/**
|
||||
* const_iterator to a fake client.
|
||||
*/
|
||||
typedef fakeClientMapType::const_iterator const_fakeClientIterator ;
|
||||
|
||||
/**
|
||||
* Return a const iterator the beginning of the fake
|
||||
* client structure.
|
||||
*/
|
||||
inline const_fakeClientIterator fakeClient_begin() const
|
||||
{ return fakeClientMap.begin() ; }
|
||||
|
||||
/**
|
||||
* Return a const iterator the end of the fake
|
||||
* client structure.
|
||||
*/
|
||||
inline const_fakeClientIterator fakeClient_end() const
|
||||
{ return fakeClientMap.end() ; }
|
||||
|
||||
/**
|
||||
* Mutable iterator to a fake client.
|
||||
*/
|
||||
typedef fakeClientMapType::iterator fakeClientIterator ;
|
||||
|
||||
/**
|
||||
* Return a mutable iterator the beginning of the fake
|
||||
* client structure.
|
||||
*/
|
||||
inline fakeClientIterator fakeClient_begin()
|
||||
{ return fakeClientMap.begin() ; }
|
||||
|
||||
/**
|
||||
* Return a mutable iterator the end of the fake
|
||||
* client structure.
|
||||
*/
|
||||
inline fakeClientIterator fakeClient_end()
|
||||
{ return fakeClientMap.end() ; }
|
||||
|
||||
/**
|
||||
* const_iterator to the fakeServerMap.
|
||||
*/
|
||||
typedef fakeServerMapType::const_iterator
|
||||
const_fakeServerIterator ;
|
||||
|
||||
/**
|
||||
* Return a const_iterator to the beginning of the fake
|
||||
* server structure.
|
||||
*/
|
||||
inline const_fakeServerIterator fakeServers_begin() const
|
||||
{ return fakeServerMap.begin() ; }
|
||||
|
||||
/**
|
||||
* Return a const_iterator to the end of the fake
|
||||
* server structure.
|
||||
*/
|
||||
inline const_fakeServerIterator fakeServers_end() const
|
||||
{ return fakeServerMap.end() ; }
|
||||
|
||||
/**
|
||||
* iterator to the fakeServerMap.
|
||||
*/
|
||||
typedef fakeServerMapType::iterator fakeServerIterator ;
|
||||
|
||||
/**
|
||||
* Return a mutable iterator to the beginning of the fake
|
||||
* server structure.
|
||||
*/
|
||||
inline fakeServerIterator fakeServers_begin()
|
||||
{ return fakeServerMap.begin() ; }
|
||||
|
||||
/**
|
||||
* Return a mutable iterator to the end of the fake
|
||||
* server structure.
|
||||
*/
|
||||
inline fakeServerIterator fakeServers_end()
|
||||
{ return fakeServerMap.end() ; }
|
||||
|
||||
/**
|
||||
* Return the number of channels currently stored in the
|
||||
* the channel table.
|
||||
*/
|
||||
inline size_t channelList_size() const
|
||||
{ return channelMap.size() ; }
|
||||
|
||||
/**
|
||||
* Return the number of servers currently stored in the
|
||||
* the server table.
|
||||
*/
|
||||
size_t serverList_size() const ;
|
||||
|
||||
/**
|
||||
* Return the number of network clients currently stored
|
||||
* in the client table.
|
||||
*/
|
||||
size_t clientList_size() const ;
|
||||
|
||||
/**
|
||||
* Retrieve the number of clients on the given server.
|
||||
*/
|
||||
size_t countClients( const iServer* theServer ) const ;
|
||||
|
||||
/**
|
||||
* This method is used to set the xServer used for
|
||||
* backwards communication. This is bad, and I would like
|
||||
* very much to get rid of it.
|
||||
*/
|
||||
virtual void setServer( xServer* _theServer ) ;
|
||||
|
||||
/**
|
||||
* Attempt to match the hostname, which may include wildcard
|
||||
* characters, with any clients on the network. Return a
|
||||
* list of pointers to const iClient's which match.
|
||||
*/
|
||||
virtual std::list< const iClient* > matchHost(
|
||||
const std::string& wildHost ) const ;
|
||||
|
||||
/**
|
||||
* Match the given user@host string, which may include
|
||||
* wildcards, to each client on the network. Return a
|
||||
* list of pointers to const iClient's which match.
|
||||
*/
|
||||
virtual std::list< const iClient* > matchUserHost(
|
||||
const std::string& ) const ;
|
||||
|
||||
/**
|
||||
* Match the given channel key, which may include wildcards,
|
||||
* to each channel on the network. Return a list of pointers
|
||||
* to const Channel's which match.
|
||||
*/
|
||||
virtual std::list<const Channel*> getChannelsWithKey(
|
||||
const std::string& key) const;
|
||||
|
||||
/**
|
||||
* Match the given channel modes, which may NOT include wildcards,
|
||||
* to each channel on the network. Return a list of pointers
|
||||
* to const Channel's which match.
|
||||
*/
|
||||
virtual std::list<const Channel*> getChannelsWithModes(
|
||||
const std::string& modes) const;
|
||||
|
||||
#ifdef TOPIC_TRACK
|
||||
/**
|
||||
* Match the given channel topic, which may include wildcards,
|
||||
* to each channel on the network. Return a list of pointers
|
||||
* to const Channel's which match.
|
||||
*/
|
||||
virtual std::list<const Channel*> getChannelsWithTopic(
|
||||
const std::string& topic) const;
|
||||
|
||||
/**
|
||||
* Match the given channel topic setter, which may include wildcards,
|
||||
* to each channel on the network. Return a list of pointers
|
||||
* to const Channel's which match.
|
||||
*/
|
||||
virtual std::list<const Channel*> getChannelsWithTopicBy(
|
||||
const std::string& topicby) const;
|
||||
#endif
|
||||
/**
|
||||
* Attempt to find hostnames which are equivalent to the given
|
||||
* hostname, found using a case insensitive search.
|
||||
* Return a list of pointers to const iClient's which are
|
||||
* found.
|
||||
*/
|
||||
virtual std::list< const iClient* > findHost(
|
||||
const std::string& hostName ) const ;
|
||||
|
||||
/**
|
||||
* Perform a similar match as to matchHost(), except return
|
||||
* only the number of matches found.
|
||||
*/
|
||||
virtual size_t countMatchingHost( const std::string& wildHost )
|
||||
const ;
|
||||
|
||||
/**
|
||||
* Perform a similar match as to matchUserHost(), except return
|
||||
* only the number of matches found.
|
||||
*/
|
||||
virtual size_t countMatchingUserHost( const std::string& wildUserHost )
|
||||
const ;
|
||||
/**
|
||||
* Perform a similar operation as to findHost(), except return
|
||||
* only the number of hosts found.
|
||||
*/
|
||||
virtual size_t countHost( const std::string& hostName ) const ;
|
||||
|
||||
/**
|
||||
* Attempt to match the real hostname, which may include wildcard
|
||||
* characters, with any clients on the network. Return a
|
||||
* list of pointers to const iClient's which match.
|
||||
*/
|
||||
virtual std::list< const iClient* > matchRealHost(
|
||||
const std::string& wildHost ) const ;
|
||||
|
||||
/**
|
||||
* Match the given user@host string, which may include
|
||||
* wildcards, to each client on the network. Return a
|
||||
* list of pointers to const iClient's which match.
|
||||
*/
|
||||
virtual std::list< const iClient* > matchRealUserHost(
|
||||
const std::string& ) const ;
|
||||
|
||||
/**
|
||||
* Attempt to find real hostnames which are equivalent to the given
|
||||
* hostname, found using a case insensitive search.
|
||||
* Return a list of pointers to const iClient's which are
|
||||
* found.
|
||||
*/
|
||||
virtual std::list< const iClient* > findRealHost(
|
||||
const std::string& hostName ) const ;
|
||||
|
||||
/**
|
||||
* Perform a similar match as to matchRealHost(), except return
|
||||
* only the number of matches found.
|
||||
*/
|
||||
virtual size_t countMatchingRealHost( const std::string& wildHost )
|
||||
const ;
|
||||
|
||||
/**
|
||||
* Perform a similar match as to matchRealUserHost(), except return
|
||||
* only the number of matches found.
|
||||
*/
|
||||
virtual size_t countMatchingRealUserHost( const std::string& wildUserHost )
|
||||
const ;
|
||||
/**
|
||||
* Perform a similar operation as to findRealHost(), except return
|
||||
* only the number of hosts found.
|
||||
*/
|
||||
virtual size_t countRealHost( const std::string& hostName ) const ;
|
||||
|
||||
/**
|
||||
* Match the given client real name string, which may include
|
||||
* wildcards, to each client on the network. Return a
|
||||
* list of pointers to const iClient's which match.
|
||||
*/
|
||||
virtual std::list< const iClient* > matchRealName(
|
||||
const std::string& ) const ;
|
||||
|
||||
/**
|
||||
* Find a new server (iServer) numeric.
|
||||
* The new numeric is assigned to intYY.
|
||||
* On success, true is returned, false otherwise.
|
||||
*/
|
||||
virtual bool allocateServerNumeric( unsigned int& intYY ) ;
|
||||
|
||||
protected:
|
||||
|
||||
/**
|
||||
* Disable copy constructing, this method is declared
|
||||
* but NOT defined.
|
||||
*/
|
||||
xNetwork( const xNetwork& ) ;
|
||||
|
||||
/**
|
||||
* Disable copy assignment, this method is declared but
|
||||
* NOT defined.
|
||||
*/
|
||||
xNetwork operator=( const xNetwork& ) ;
|
||||
|
||||
/**
|
||||
* Find a new client (iClient or xClient) numeric.
|
||||
* The new numeric is assigned to newIntYYXXX.
|
||||
* On success, true is returned, false otherwise.
|
||||
*/
|
||||
virtual bool allocateClientNumeric( unsigned int intYY,
|
||||
unsigned int& newIntXXX ) ;
|
||||
|
||||
/**
|
||||
* Free a reserved client (iClient or xClient) numeric.
|
||||
*/
|
||||
virtual bool freeClientNumeric( unsigned int intYYXXX ) ;
|
||||
|
||||
|
||||
/**
|
||||
* Free a reserved server (iServer) numeric.
|
||||
*/
|
||||
virtual bool freeServerNumeric( unsigned int intYYXXX ) ;
|
||||
|
||||
/**
|
||||
* This method is used internally when a client is added to
|
||||
* the structure.
|
||||
*/
|
||||
virtual void addNick( iClient* ) ;
|
||||
|
||||
/**
|
||||
* Perform a simple recursive search for all leaves of
|
||||
* the server whose numeric is the second arguments, and
|
||||
* place each of those servers' numerics into the vector.
|
||||
*/
|
||||
virtual void findLeaves( std::vector< unsigned int >& yyVector,
|
||||
const unsigned int intYY ) const ;
|
||||
|
||||
/**
|
||||
* The vector of local clients.
|
||||
*/
|
||||
xClientMapType localClients ;
|
||||
|
||||
/**
|
||||
* The structure used to store the network channel
|
||||
* information.
|
||||
*/
|
||||
channelMapType channelMap ;
|
||||
|
||||
/**
|
||||
* The structure used to store the nick name->iClient
|
||||
* cross references.
|
||||
*/
|
||||
nickMapType nickMap ;
|
||||
|
||||
/**
|
||||
* The container used to store the network iClient's,
|
||||
* keyed by iClient numeric.
|
||||
*/
|
||||
numericMapType numericMap ;
|
||||
|
||||
/**
|
||||
* The container used to store the network iServer's,
|
||||
* keyed by iServer numeric.
|
||||
*/
|
||||
serverMapType serverMap ;
|
||||
|
||||
/**
|
||||
* This variable is used backwards calls to the main server.
|
||||
*/
|
||||
xServer *theServer ;
|
||||
|
||||
/**
|
||||
* This structure maps fake iClient's to their owning
|
||||
* xClient's.
|
||||
*/
|
||||
fakeClientMapType fakeClientMap ;
|
||||
|
||||
/**
|
||||
* This structure stores fake (juped) servers.
|
||||
*/
|
||||
fakeServerMapType fakeServerMap ;
|
||||
|
||||
/**
|
||||
* Structure used to store all reserved intYY and intYYXXX's
|
||||
* for the local server and juped iClient/xClient/iServer's.
|
||||
*/
|
||||
reservedNumericMapType reservedNumericMap ;
|
||||
} ;
|
||||
|
||||
/**
|
||||
* Declare the single xNetwork instance as global, for now.
|
||||
*/
|
||||
extern xNetwork* Network ;
|
||||
|
||||
} // namespace gnuworld
|
||||
|
||||
#endif // __NETWORK_H
|
||||
@@ -0,0 +1,208 @@
|
||||
/**
|
||||
* NetworkTarget.h
|
||||
* Author: Daniel Karrels (dan@karrels.com)
|
||||
*
|
||||
* Copyright (C) 2002 Daniel Karrels <dan@karrels.com>
|
||||
*
|
||||
* 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; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; 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.
|
||||
*
|
||||
* $Id: NetworkTarget.h,v 1.2 2003/12/29 23:59:36 dan_karrels Exp $
|
||||
*/
|
||||
|
||||
#ifndef __NETWORKTARGET_H
|
||||
#define __NETWORKTARGET_H
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "Numeric.h"
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
|
||||
class xNetwork ;
|
||||
|
||||
/**
|
||||
* This class is basically a convenience class for addressing
|
||||
* targets according to the ircu network protocol. That is,
|
||||
* this class supports integer and string numerics.
|
||||
*/
|
||||
class NetworkTarget
|
||||
{
|
||||
/// Allow xNetwork to call the protected mutator methods
|
||||
friend class xNetwork ;
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
* The integer base 64 representation of this target's
|
||||
* server.
|
||||
*/
|
||||
unsigned int intYY ;
|
||||
|
||||
/**
|
||||
* The integer base 64 representation of this target's
|
||||
* client ID (relative to its server).
|
||||
*/
|
||||
unsigned int intXXX ;
|
||||
|
||||
/**
|
||||
* The char array base 64 representation of this target's
|
||||
* server.
|
||||
*/
|
||||
char charYY[ 3 ] ;
|
||||
|
||||
/**
|
||||
* The char array base 64 representation of this target's
|
||||
* client ID (relative to its server).
|
||||
*/
|
||||
char charXXX[ 4 ] ;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Instantiate a NetworkTarget with no arguments.
|
||||
* All variables will be set to 0.
|
||||
*/
|
||||
NetworkTarget()
|
||||
: intYY( 0 ),
|
||||
intXXX( 0 )
|
||||
{
|
||||
charYY[ 0 ] = charYY[ 1 ] = charYY[ 2 ] = 0 ;
|
||||
charXXX[ 0 ] = charXXX[ 1 ] = charXXX[ 2 ] = charXXX[ 3 ] = 0 ;
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiate a NetworkTarget given its base 64 integer
|
||||
* numerics.
|
||||
*/
|
||||
NetworkTarget( const unsigned int& intYY,
|
||||
const unsigned int& intXXX )
|
||||
{
|
||||
setIntYY( intYY ) ;
|
||||
setIntXXX( intXXX ) ;
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiate a NetworkTarget given its base 64 char array
|
||||
* numerics.
|
||||
*/
|
||||
NetworkTarget( const std::string& stringYYXXX )
|
||||
{
|
||||
setCharYY( stringYYXXX.substr( 0, 2 ) ) ;
|
||||
setCharXXX( stringYYXXX.substr( 2, 3 ) ) ;
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy this NetworkTarget object.
|
||||
*/
|
||||
virtual ~NetworkTarget()
|
||||
{}
|
||||
|
||||
/**
|
||||
* Return the integer base 64 representation of this
|
||||
* target's server.
|
||||
*/
|
||||
inline unsigned int getIntYY() const
|
||||
{ return intYY ; }
|
||||
|
||||
/**
|
||||
* Return the integer base 64 representation of this
|
||||
* target's client identifier (relative to its server).
|
||||
*/
|
||||
inline unsigned int getIntXXX() const
|
||||
{ return intXXX ; }
|
||||
|
||||
/**
|
||||
* Return the integer base 64 representation of this
|
||||
* target's full client/server numeric.
|
||||
*/
|
||||
inline unsigned int getIntYYXXX() const
|
||||
{ return combinebase64int( intYY, intXXX ) ; }
|
||||
|
||||
/**
|
||||
* Return the char array base 64 representation of this
|
||||
* target's server.
|
||||
*/
|
||||
inline const std::string getCharYY() const
|
||||
{ return std::string( charYY ) ; }
|
||||
|
||||
/**
|
||||
* Return the char array base 64 representation of this
|
||||
* target's client identifier (relative to its server).
|
||||
*/
|
||||
inline const std::string getCharXXX() const
|
||||
{ return std::string( charXXX ) ; }
|
||||
|
||||
/**
|
||||
* Return the char array base 64 representation of this
|
||||
* target's full client/server numeric.
|
||||
*/
|
||||
inline const std::string getCharYYXXX() const
|
||||
{ return (getCharYY() + getCharXXX()) ; }
|
||||
|
||||
protected:
|
||||
|
||||
/**
|
||||
* Set the integer base 64 representation of this
|
||||
* target's server.
|
||||
*/
|
||||
inline void setIntYY( unsigned int newIntYY )
|
||||
{
|
||||
intYY = newIntYY ;
|
||||
inttobase64( charYY, intYY, 2 ) ;
|
||||
charYY[ 2 ] = 0 ;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the integer base 64 representation of this
|
||||
* target's client identifier (relative to its server).
|
||||
*/
|
||||
inline void setIntXXX( unsigned int newIntXXX )
|
||||
{
|
||||
intXXX = newIntXXX ;
|
||||
inttobase64( charXXX, intXXX, 3 ) ;
|
||||
charXXX[ 3 ] = 0 ;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the char array base 64 representation of this
|
||||
* target's server.
|
||||
*/
|
||||
inline void setCharYY( const std::string& stringYY )
|
||||
{
|
||||
charYY[ 0 ] = stringYY[ 0 ] ;
|
||||
charYY[ 1 ] = stringYY[ 1 ] ;
|
||||
charYY[ 2 ] = 0 ;
|
||||
intYY = base64toint( stringYY.c_str(), 2 ) ;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the char array base 64 representation of this
|
||||
* target's client identifier (relative to its server).
|
||||
*/
|
||||
inline void setCharXXX( const std::string& stringXXX )
|
||||
{
|
||||
charXXX[ 0 ] = stringXXX[ 0 ] ;
|
||||
charXXX[ 1 ] = stringXXX[ 1 ] ;
|
||||
charXXX[ 2 ] = stringXXX[ 2 ] ;
|
||||
charXXX[ 3 ] = 0 ;
|
||||
intXXX = base64toint( stringXXX.c_str(), 3 ) ;
|
||||
}
|
||||
|
||||
} ;
|
||||
|
||||
} // namespace gnuworld
|
||||
|
||||
#endif // __NETWORKTARGET_H
|
||||
@@ -0,0 +1,190 @@
|
||||
/**
|
||||
* Numeric.h
|
||||
* This file contains basic routines for converting numerics between
|
||||
* integer and char* and std::string formats.
|
||||
* The majority of this code is from the Undernet ircu code base.
|
||||
*
|
||||
* 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; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; 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.
|
||||
*
|
||||
* $Id: Numeric.h,v 1.7 2009/07/26 18:30:37 mrbean_ Exp $
|
||||
*/
|
||||
|
||||
#ifndef __NUMERIC_H
|
||||
#define __NUMERIC_H "$Id: Numeric.h,v 1.7 2009/07/26 18:30:37 mrbean_ Exp $"
|
||||
|
||||
/*
|
||||
* Numeric nicks are new as of version ircu2.10.00beta1.
|
||||
*
|
||||
* The idea is as follows:
|
||||
* In most messages (for protocol 10+) the original nick will be
|
||||
* replaced by a 3 character string: YXX
|
||||
* Where 'Y' represents the server, and 'XX' the nick on that server.
|
||||
*
|
||||
* 'YXX' should not interfer with the input parser, and therefore is
|
||||
* not allowed to contain spaces or a ':'.
|
||||
* Also, 'Y' can't start with a '+' because of m_server().
|
||||
*
|
||||
* We keep the characters printable for debugging reasons too.
|
||||
*
|
||||
* The 'XX' value can be larger then the maximum number of clients
|
||||
* per server, we use a mask (struct Server::nn_mask) to get the real
|
||||
* client numeric. The overhead is used to have some redundancy so
|
||||
* just-disconnected-client aren't confused with just-connected ones.
|
||||
*/
|
||||
|
||||
/* These must be the same on ALL servers ! Do not change ! */
|
||||
#include <cassert>
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
|
||||
/// The length of the character numerics, 5 for n2k
|
||||
#define P10_NUMNICKLEN 5
|
||||
#define NUMNICKLOG 6
|
||||
#define NUMNICKMAXCHAR 'z' /* See convert2n[] */
|
||||
#define NUMNICKBASE 64 /* (2 << NUMNICKLOG) */
|
||||
#define NUMNICKMASK 63 /* (NUMNICKBASE-1) */
|
||||
#define NN_MAX_SERVER 4096 /* (NUMNICKBASE * NUMNICKBASE) */
|
||||
|
||||
/*
|
||||
* The internal counter for the 'XX' of local clients
|
||||
*/
|
||||
|
||||
/**
|
||||
* convert2y[] converts a numeric to the corresponding character.
|
||||
* The following characters are currently known to be forbidden:
|
||||
*
|
||||
* '\0' : Because we use '\0' as end of line.
|
||||
*
|
||||
* ' ' : Because parse_*() uses this as parameter seperator.
|
||||
* ':' : Because parse_server() uses this to detect if a prefix is a
|
||||
* numeric or a name.
|
||||
* '+' : Because m_nick() uses this to determine if parv[6] is a
|
||||
* umode or not.
|
||||
* '&', '#', '+', '$', '@' and '%' :
|
||||
* Because m_message() matches these characters to detect special cases.
|
||||
*/
|
||||
static const char convert2y[] = {
|
||||
'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P',
|
||||
'Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f',
|
||||
'g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v',
|
||||
'w','x','y','z','0','1','2','3','4','5','6','7','8','9','[',']'
|
||||
};
|
||||
|
||||
/**
|
||||
* convert2n[] ocnverts a character to the corresponding integer.
|
||||
*/
|
||||
static const unsigned int convert2n[] = {
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
52,53,54,55,56,57,58,59,60,61, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,
|
||||
15,16,17,18,19,20,21,22,23,24,25,62, 0,63, 0, 0,
|
||||
0,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,
|
||||
41,42,43,44,45,46,47,48,49,50,51, 0, 0, 0, 0, 0,
|
||||
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
||||
};
|
||||
|
||||
/**
|
||||
* This method converts a base64 character array to
|
||||
* an unsigned integer.
|
||||
*/
|
||||
inline unsigned int base64toint( const char* s )
|
||||
{
|
||||
unsigned int i = convert2n[ static_cast< unsigned char >( *s++ ) ] ;
|
||||
while( *s )
|
||||
{
|
||||
i <<= NUMNICKLOG;
|
||||
i += convert2n[ static_cast< unsigned char >( *s++ ) ] ;
|
||||
}
|
||||
return i ;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method converts only the first (count) characters
|
||||
* of the string (s) to unsigned integer format.
|
||||
*/
|
||||
inline unsigned int base64toint( const char* s, size_t count )
|
||||
{
|
||||
assert( s != 0 ) ;
|
||||
|
||||
unsigned int i = convert2n[ static_cast< unsigned char >( *s++ ) ] ;
|
||||
while (*s && --count > 0)
|
||||
{
|
||||
i <<= NUMNICKLOG;
|
||||
i += convert2n[ static_cast< unsigned char >( *s++ ) ] ;
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method converts an unsigned integer (v) to a base64
|
||||
* character array of length (count).
|
||||
* Be sure that buf is allocated and large enough to hold
|
||||
* (count) characters (excluding null terminator).
|
||||
* This method returns a pointer to the base 64 buffer.
|
||||
*/
|
||||
inline const char* inttobase64( char* buf, unsigned int v, size_t count )
|
||||
{
|
||||
assert( buf != 0 ) ;
|
||||
|
||||
buf[count] = '\0';
|
||||
while (count > 0)
|
||||
{
|
||||
buf[ --count ] = convert2y[(v & NUMNICKMASK)];
|
||||
v >>= NUMNICKLOG;
|
||||
}
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
inline void splitbase64int( unsigned int intYYXXX,
|
||||
unsigned int& intYY,
|
||||
unsigned int& intXXX )
|
||||
{
|
||||
// Decompose to charYYXXX
|
||||
char charYYXXX[ 6 ] ;
|
||||
inttobase64( charYYXXX, intYYXXX, 5 ) ;
|
||||
|
||||
// Now split the charYYXXX into two ints
|
||||
intYY = base64toint( charYYXXX, 2 ) ;
|
||||
intXXX = base64toint( &charYYXXX[ 2 ], 3 ) ;
|
||||
}
|
||||
|
||||
inline unsigned int combinebase64int( const unsigned int& intYY,
|
||||
const unsigned int& intXXX )
|
||||
{
|
||||
char charYYXXX[ 6 ] ;
|
||||
|
||||
inttobase64( charYYXXX, intYY, 2 ) ;
|
||||
inttobase64( &charYYXXX[ 2 ], intXXX, 3 ) ;
|
||||
|
||||
return base64toint( charYYXXX, 5 ) ;
|
||||
}
|
||||
|
||||
} // namespace gnuworld
|
||||
|
||||
#endif // __NUMERIC_H
|
||||
@@ -0,0 +1,81 @@
|
||||
/**
|
||||
* ServerCommandHandler.h
|
||||
*
|
||||
* 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; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; 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.
|
||||
*
|
||||
* "$Id: ServerCommandHandler.h,v 1.3 2003/06/28 01:21:18 dan_karrels Exp $"
|
||||
*/
|
||||
|
||||
#ifndef __SERVERCOMMANDHANDLER_H
|
||||
#define __SERVERCOMMANDHANDLER_H "$Id: ServerCommandHandler.h,v 1.3 2003/06/28 01:21:18 dan_karrels Exp $"
|
||||
|
||||
#include "xparameters.h"
|
||||
#include "ELog.h"
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
|
||||
class xServer ;
|
||||
|
||||
class ServerCommandHandler
|
||||
{
|
||||
protected:
|
||||
xServer *theServer ;
|
||||
|
||||
public:
|
||||
|
||||
ServerCommandHandler( xServer* _theServer )
|
||||
: theServer( _theServer )
|
||||
{}
|
||||
virtual ~ServerCommandHandler()
|
||||
{}
|
||||
|
||||
virtual bool Execute( const xParameters& ) = 0 ;
|
||||
} ;
|
||||
|
||||
#define CREATE_HANDLER(name) \
|
||||
class name : public ServerCommandHandler \
|
||||
{ \
|
||||
public: \
|
||||
name( xServer* theServer ) \
|
||||
: ServerCommandHandler( theServer ) \
|
||||
{} \
|
||||
virtual ~name() \
|
||||
{} \
|
||||
\
|
||||
virtual bool Execute( const xParameters& ) ; \
|
||||
} ; \
|
||||
\
|
||||
extern "C" \
|
||||
{ \
|
||||
name* _gnuwinit_##name( xServer* theServer ) \
|
||||
{ \
|
||||
return new name( theServer ) ; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define CREATE_LOADER(name) \
|
||||
extern "C" \
|
||||
{ \
|
||||
name* _gnuwinit_##name( xServer* theServer ) \
|
||||
{ \
|
||||
return new name( theServer ) ; \
|
||||
} \
|
||||
}
|
||||
|
||||
} // namespace gnuworld
|
||||
|
||||
#endif // __SERVERCOMMANDHANDLER_H
|
||||
@@ -0,0 +1,107 @@
|
||||
/**
|
||||
* ServerTimerHandlers.h
|
||||
* Copyright (C) 2002 Daniel Karrels <dan@karrels.com>
|
||||
*
|
||||
* 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; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; 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.
|
||||
*
|
||||
* $Id: ServerTimerHandlers.h,v 1.6 2004/05/19 19:46:33 jeekay Exp $
|
||||
*/
|
||||
|
||||
#ifndef __SERVERTIMERHANDLERS_H
|
||||
#define __SERVERTIMERHANDLERS_H "$Id: ServerTimerHandlers.h,v 1.6 2004/05/19 19:46:33 jeekay Exp $"
|
||||
|
||||
#include "TimerHandler.h"
|
||||
|
||||
#include <ctime>
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
|
||||
/// Forward declaration of the xServer class
|
||||
class xServer ;
|
||||
|
||||
/**
|
||||
* This is the abstract base class from which each timer to be used
|
||||
* by the GNUWorld server core must derive. Each server timer
|
||||
* must inherit from this class, and define the abstract method
|
||||
* OnTimer(). The OnTimer() method will be called by the timer
|
||||
* system when the timer expires.
|
||||
*/
|
||||
class ServerTimerHandler : public TimerHandler
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* The constructor receives a pointer to the server core,
|
||||
* and the interval at which to reschedule the timer,
|
||||
* if the timer handler chooses to do so.
|
||||
*/
|
||||
ServerTimerHandler( xServer* _theServer, time_t _updateInterval )
|
||||
: theServer( _theServer ),
|
||||
updateInterval( _updateInterval )
|
||||
{}
|
||||
|
||||
/**
|
||||
* This is the virtual destructor, which currently does
|
||||
* nothing, but must be present in a class hierarchy.
|
||||
*/
|
||||
virtual ~ServerTimerHandler()
|
||||
{}
|
||||
|
||||
/**
|
||||
* This method is called when the timer expires. The timerID
|
||||
* argument is registration ID of the timer. The void*
|
||||
* argument is a pointer to whatever data was given during
|
||||
* timer registration. Make sure that this data is placed
|
||||
* into persistent memory, otherwise a segmentation fault
|
||||
* may occur when running OnTimer().
|
||||
*/
|
||||
virtual void OnTimer( const timerID& , void* ) = 0 ;
|
||||
|
||||
protected:
|
||||
|
||||
/**
|
||||
* This is a pointer to the server core.
|
||||
*/
|
||||
xServer* theServer ;
|
||||
|
||||
/**
|
||||
* This is the timer rescheduling interval.
|
||||
*/
|
||||
time_t updateInterval ;
|
||||
} ;
|
||||
|
||||
/**
|
||||
* This macro is used to create a generic subclass of class
|
||||
* ServerTimerHandler, and to declare the OnTimer() method as
|
||||
* concrete.
|
||||
*/
|
||||
#define SUBCLASS_SERVERTIMERHANDLER(className)\
|
||||
class className##Timer : public ServerTimerHandler \
|
||||
{ \
|
||||
public: \
|
||||
className##Timer( xServer* theServer, time_t updateInterval ) \
|
||||
: ServerTimerHandler( theServer, updateInterval ) \
|
||||
{} \
|
||||
virtual ~className##Timer() {} \
|
||||
virtual void OnTimer( const timerID& , void* ) ; \
|
||||
} ;
|
||||
|
||||
SUBCLASS_SERVERTIMERHANDLER( GlineUpdate )
|
||||
SUBCLASS_SERVERTIMERHANDLER( PING )
|
||||
|
||||
} // namespace gnuworld
|
||||
|
||||
#endif // __SERVERTIMERHANDLER_H
|
||||
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
* Timer.h
|
||||
*
|
||||
* 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; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; 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.
|
||||
*/
|
||||
|
||||
#ifndef TIMER_H
|
||||
#define TIMER_H
|
||||
|
||||
#include <sys/time.h>
|
||||
#include <time.h>
|
||||
|
||||
namespace gnuworld {
|
||||
|
||||
class Timer {
|
||||
public:
|
||||
inline Timer(bool autostart = true)
|
||||
{ if(autostart) { Start(); } }
|
||||
|
||||
inline void Start()
|
||||
{ gettimeofday(&startTime, 0); }
|
||||
inline void Stop()
|
||||
{ gettimeofday(&stopTime, 0); }
|
||||
inline unsigned int getTimeMS()
|
||||
{ return (stopTime.tv_sec - startTime.tv_sec) * 1000 +
|
||||
(stopTime.tv_usec - startTime.tv_usec) / 1000; }
|
||||
inline unsigned long getTimeUS()
|
||||
{ return (stopTime.tv_sec - startTime.tv_sec) * 1000000 +
|
||||
(stopTime.tv_usec - startTime.tv_usec); }
|
||||
inline unsigned int stopTimeMS()
|
||||
{ Stop(); return getTimeMS(); }
|
||||
inline unsigned long stopTimeUS()
|
||||
{ Stop(); return getTimeUS(); }
|
||||
protected:
|
||||
struct timeval startTime, stopTime;
|
||||
}; // class Timer
|
||||
|
||||
} // namespace gnuworld
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,88 @@
|
||||
/**
|
||||
* TimerHandler.h
|
||||
* Copyright (C) 2002 Daniel Karrels <dan@karrels.com>
|
||||
*
|
||||
* 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; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; 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.
|
||||
*
|
||||
* $Id: TimerHandler.h,v 1.6 2004/05/19 19:46:33 jeekay Exp $
|
||||
*/
|
||||
|
||||
#ifndef __TIMERHANDLER_H
|
||||
#define __TIMERHANDLER_H "$Id: TimerHandler.h,v 1.6 2004/05/19 19:46:33 jeekay Exp $"
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
|
||||
/**
|
||||
* This is the abstract base class used in the GNUWorld timer system.
|
||||
* All timer handlers must subclass this class, and define the
|
||||
* abstract method OnTimer(). The OnTimer() method will be called
|
||||
* by the timer system when the timer has expired.
|
||||
*/
|
||||
class TimerHandler
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* The constructor does nothing.
|
||||
*/
|
||||
TimerHandler() {}
|
||||
|
||||
/**
|
||||
* The destructor does nothing.
|
||||
*/
|
||||
virtual ~TimerHandler() {}
|
||||
|
||||
/**
|
||||
* The type used to represent timer events.
|
||||
*/
|
||||
typedef unsigned int timerID ;
|
||||
|
||||
/**
|
||||
* Handle a timer event. The first argument is the
|
||||
* handle for the timer registration, and the second
|
||||
* is the argument that was passed when registering the
|
||||
* timer.
|
||||
*/
|
||||
virtual void OnTimer( const timerID& , void* ) = 0 ;
|
||||
|
||||
/**
|
||||
* This method is invoked when the server removes a
|
||||
* timed event without being requested by the TimerHandler.
|
||||
* This can happen when the TimerHandler is being destroyed,
|
||||
* but has not removed all of its timers yet.
|
||||
*/
|
||||
virtual void OnTimerDestroy( timerID, void * ) {}
|
||||
|
||||
} ;
|
||||
|
||||
/**
|
||||
* This macro is meant to assist in creating new subclasses of
|
||||
* the TimerHandler class.
|
||||
*/
|
||||
#define SUBCLASS_TIMERHANDLER(className) \
|
||||
class className##Timer : public TimerHandler \
|
||||
{ \
|
||||
public: \
|
||||
className##Timer() {} \
|
||||
virtual ~className##Timer() {} \
|
||||
virtual void OnTimer( timerID, void* ) ; \
|
||||
} ;
|
||||
|
||||
} // namespace gnuworld
|
||||
|
||||
#endif // __TIMERHANDLER_H
|
||||
@@ -0,0 +1,82 @@
|
||||
/**
|
||||
* UnloadClientTimerHandler.h
|
||||
* Copyright (C) 2002 Daniel Karrels <dan@karrels.com>
|
||||
*
|
||||
* 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; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; 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.
|
||||
*
|
||||
* $Id: UnloadClientTimerHandler.h,v 1.7 2004/05/19 19:46:33 jeekay Exp $
|
||||
*/
|
||||
|
||||
#ifndef __UNLOADCLIENTTIMERHANDLER_H
|
||||
#define __UNLOADCLIENTTIMERHANDLER_H "$Id: UnloadClientTimerHandler.h,v 1.7 2004/05/19 19:46:33 jeekay Exp $"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "ServerTimerHandlers.h"
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
|
||||
class xServer ;
|
||||
|
||||
/**
|
||||
* This class is responsible for unloading an xClient at a particular time.
|
||||
* This delayed unload allows the xClient to finish cleanup work as
|
||||
* requested by the server event system.
|
||||
*/
|
||||
class UnloadClientTimerHandler : public ServerTimerHandler
|
||||
{
|
||||
|
||||
protected:
|
||||
|
||||
/// The xClient module name
|
||||
std::string moduleName ;
|
||||
|
||||
/// The reason for the unload, will be delivered to the xClient
|
||||
std::string reason ;
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* The constructor receives the follow arguments:
|
||||
* - A pointer to the global xServer instance
|
||||
* - The xClient module name
|
||||
* - The reason for unloading the client.
|
||||
*/
|
||||
UnloadClientTimerHandler( xServer* theServer,
|
||||
const std::string& _moduleName,
|
||||
const std::string& _reason )
|
||||
: ServerTimerHandler( theServer, 0),
|
||||
moduleName( _moduleName ),
|
||||
reason( _reason )
|
||||
{}
|
||||
|
||||
/**
|
||||
* Destructor, not much to talk about here.
|
||||
*/
|
||||
virtual ~UnloadClientTimerHandler()
|
||||
{}
|
||||
|
||||
/**
|
||||
* The method that is called when it's time to unload the client.
|
||||
*/
|
||||
virtual void OnTimer( const timerID& , void* ) ;
|
||||
|
||||
} ;
|
||||
|
||||
} // namespace gnuworld
|
||||
|
||||
#endif // __UNLOADCLIENTTIMERHANDLER_H
|
||||
+105
@@ -0,0 +1,105 @@
|
||||
/**
|
||||
* cidr.h
|
||||
*
|
||||
* 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; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; 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.
|
||||
*
|
||||
* $Id: cidr.h,v 1.4 2009/07/26 18:30:37 mrbean_ Exp $
|
||||
*/
|
||||
|
||||
#ifndef __CIDR_H
|
||||
#define __CIDR_H "$Id: cidr.h,v 1.4 2009/07/26 18:30:37 mrbean_ Exp $"
|
||||
|
||||
#include <string>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netdb.h>
|
||||
#include <arpa/inet.h>
|
||||
#include "ip.h"
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
|
||||
/**
|
||||
* A utility class that is used to retrieve information about
|
||||
* CIDR addresses.
|
||||
*/
|
||||
class xCIDR
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Construct an xIP instance given an address in std::string
|
||||
* format.
|
||||
*/
|
||||
xCIDR( const std::string& IP) ;
|
||||
|
||||
/**
|
||||
* Checks whether or not the CIDR is valid.
|
||||
*/
|
||||
inline const bool& GetValid() const
|
||||
{ return valid; }
|
||||
|
||||
/**
|
||||
* Retrieve the mask of this CIDR (the part after the /).
|
||||
*/
|
||||
inline const int& GetMask() const
|
||||
{ return mask; }
|
||||
|
||||
/**
|
||||
* Retrieve the prefix of this CIDR (the part before the /).
|
||||
*/
|
||||
inline const xIP& GetPrefix() const
|
||||
{ return prefix; }
|
||||
|
||||
inline const std::string& AsString() const
|
||||
{ return str; }
|
||||
|
||||
bool matches(const std::string& IP) ;
|
||||
|
||||
protected:
|
||||
|
||||
/**
|
||||
* Wheter this CIDR is valid.
|
||||
*/
|
||||
bool valid ;
|
||||
|
||||
/**
|
||||
* The mask
|
||||
*/
|
||||
int mask ;
|
||||
|
||||
std::string str;
|
||||
|
||||
/**
|
||||
* The prefix
|
||||
*/
|
||||
xIP prefix ;
|
||||
|
||||
|
||||
|
||||
private:
|
||||
|
||||
bool ExtractMask(const std::string&);
|
||||
|
||||
bool ExtractPrefix(const std::string&,const unsigned int&,unsigned int&);
|
||||
|
||||
} ;
|
||||
|
||||
} // namespace gnuworld
|
||||
|
||||
#endif // __XCIDR_H
|
||||
+1031
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,149 @@
|
||||
/* include/defs.h.in. Generated from configure.ac by autoheader. */
|
||||
|
||||
/* Enable LOG4CPLUS */
|
||||
#undef ENABLE_LOG4CPLUS
|
||||
|
||||
/* Define to 1 if you have the <asm/ioctls.h> header file. */
|
||||
#undef HAVE_ASM_IOCTLS_H
|
||||
|
||||
/* define if the Boost::Thread library is available */
|
||||
#undef HAVE_BOOST_THREAD
|
||||
|
||||
/* Define to 1 if you have the <dlfcn.h> header file. */
|
||||
#undef HAVE_DLFCN_H
|
||||
|
||||
/* Define to 1 if you have the <getopt.h> header file. */
|
||||
#undef HAVE_GETOPT_H
|
||||
|
||||
/* Define to 1 if you have the <inttypes.h> header file. */
|
||||
#undef HAVE_INTTYPES_H
|
||||
|
||||
/* Define to 1 if you have the `nsl' library (-lnsl). */
|
||||
#undef HAVE_LIBNSL
|
||||
|
||||
/* Define to 1 if you have the `pq' library (-lpq). */
|
||||
#undef HAVE_LIBPQ
|
||||
|
||||
/* Define to 1 if you have the `socket' library (-lsocket). */
|
||||
#undef HAVE_LIBSOCKET
|
||||
|
||||
/* Define to 1 if you have the <memory.h> header file. */
|
||||
#undef HAVE_MEMORY_H
|
||||
|
||||
/* define if the compiler implements namespaces */
|
||||
#undef HAVE_NAMESPACES
|
||||
|
||||
/* Define to 1 if you have the <netinet/in.h> header file. */
|
||||
#undef HAVE_NETINET_IN_H
|
||||
|
||||
/* Using PostGreSQL */
|
||||
#undef HAVE_PGSQL
|
||||
|
||||
/* Define to 1 if you have the <pthread.h> header file. */
|
||||
#undef HAVE_PTHREAD_H
|
||||
|
||||
/* Socket length type */
|
||||
#undef HAVE_SOCKLEN_T
|
||||
|
||||
/* Define to 1 if you have the <stdint.h> header file. */
|
||||
#undef HAVE_STDINT_H
|
||||
|
||||
/* Define to 1 if you have the <stdlib.h> header file. */
|
||||
#undef HAVE_STDLIB_H
|
||||
|
||||
/* Define to 1 if you have the <strings.h> header file. */
|
||||
#undef HAVE_STRINGS_H
|
||||
|
||||
/* Define to 1 if you have the <string.h> header file. */
|
||||
#undef HAVE_STRING_H
|
||||
|
||||
/* Define to 1 if you have the <sys/file.h> header file. */
|
||||
#undef HAVE_SYS_FILE_H
|
||||
|
||||
/* Define to 1 if you have the <sys/filio.h> header file. */
|
||||
#undef HAVE_SYS_FILIO_H
|
||||
|
||||
/* Define to 1 if you have the <sys/ioctl.h> header file. */
|
||||
#undef HAVE_SYS_IOCTL_H
|
||||
|
||||
/* Define to 1 if you have the <sys/resource.h> header file. */
|
||||
#undef HAVE_SYS_RESOURCE_H
|
||||
|
||||
/* Define to 1 if you have the <sys/socket.h> header file. */
|
||||
#undef HAVE_SYS_SOCKET_H
|
||||
|
||||
/* Define to 1 if you have the <sys/stat.h> header file. */
|
||||
#undef HAVE_SYS_STAT_H
|
||||
|
||||
/* Define to 1 if you have the <sys/time.h> header file. */
|
||||
#undef HAVE_SYS_TIME_H
|
||||
|
||||
/* Define to 1 if you have the <sys/types.h> header file. */
|
||||
#undef HAVE_SYS_TYPES_H
|
||||
|
||||
/* Define to 1 if you have the <sys/un.h> header file. */
|
||||
#undef HAVE_SYS_UN_H
|
||||
|
||||
/* Define to 1 if you have the <unistd.h> header file. */
|
||||
#undef HAVE_UNISTD_H
|
||||
|
||||
/* Define to 1 if you have the <xti_inet.h> header file. */
|
||||
#undef HAVE_XTI_INET_H
|
||||
|
||||
/* Define to the sub-directory in which libtool stores uninstalled libraries.
|
||||
*/
|
||||
#undef LT_OBJDIR
|
||||
|
||||
/* Name of package */
|
||||
#undef PACKAGE
|
||||
|
||||
/* Define to the address where bug reports for this package should be sent. */
|
||||
#undef PACKAGE_BUGREPORT
|
||||
|
||||
/* Define to the full name of this package. */
|
||||
#undef PACKAGE_NAME
|
||||
|
||||
/* Define to the full name and version of this package. */
|
||||
#undef PACKAGE_STRING
|
||||
|
||||
/* Define to the one symbol short name of this package. */
|
||||
#undef PACKAGE_TARNAME
|
||||
|
||||
/* Define to the home page for this package. */
|
||||
#undef PACKAGE_URL
|
||||
|
||||
/* Define to the version of this package. */
|
||||
#undef PACKAGE_VERSION
|
||||
|
||||
/* Define as the return type of signal handlers (`int' or `void'). */
|
||||
#undef RETSIGTYPE
|
||||
|
||||
/* Define to 1 if you have the ANSI C header files. */
|
||||
#undef STDC_HEADERS
|
||||
|
||||
/* Define to 1 if you can safely include both <sys/time.h> and <time.h>. */
|
||||
#undef TIME_WITH_SYS_TIME
|
||||
|
||||
/* Version number of package */
|
||||
#undef VERSION
|
||||
|
||||
/* Define to `int' if <sys/types.h> doesn't define. */
|
||||
#undef gid_t
|
||||
|
||||
/* Define to `int' if <sys/types.h> does not define. */
|
||||
#undef mode_t
|
||||
|
||||
/* Define to `int' if <sys/types.h> does not define. */
|
||||
#undef pid_t
|
||||
|
||||
/* Define to `unsigned int' if <sys/types.h> does not define. */
|
||||
#undef size_t
|
||||
|
||||
/* Define to `int' if <sys/types.h> does not define. */
|
||||
#undef socklen_t
|
||||
|
||||
/* Define to `int' if <sys/types.h> doesn't define. */
|
||||
#undef uid_t
|
||||
|
||||
/* Have LIBOATH */
|
||||
#undef HAVE_LIBOATH
|
||||
@@ -0,0 +1,171 @@
|
||||
/**
|
||||
* Events.h
|
||||
* This file defines the basic network and channel events that
|
||||
* the GNUWorld server may distribute to its services clients.
|
||||
* Hopefully most of these are pretty self explanatory.
|
||||
* This file was originally created by Orlando Bassotto.
|
||||
*
|
||||
* Copyright (C) 2002 Daniel Karrels <dan@karrels.com>
|
||||
*
|
||||
* 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; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; 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.
|
||||
*
|
||||
* $Id: events.h,v 1.22 2010/09/05 17:26:35 denspike Exp $
|
||||
*/
|
||||
|
||||
#ifndef __EVENTS_H
|
||||
#define __EVENTS_H "$Id: events.h,v 1.22 2010/09/05 17:26:35 denspike Exp $"
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
|
||||
/**
|
||||
* This is used to enumerate the possible network (non-channel)
|
||||
* events that gnuworld will track and deliver to registered
|
||||
* clients.
|
||||
*/
|
||||
enum
|
||||
{
|
||||
EVT_OPER,
|
||||
EVT_NETBREAK,
|
||||
EVT_NETJOIN,
|
||||
EVT_BURST_CMPLT,
|
||||
EVT_BURST_ACK,
|
||||
EVT_EA_SENT,
|
||||
EVT_GLINE,
|
||||
EVT_REMGLINE,
|
||||
EVT_JUPE,
|
||||
EVT_UNJUPE,
|
||||
EVT_QUIT,
|
||||
EVT_KILL,
|
||||
EVT_NICK,
|
||||
EVT_CHNICK,
|
||||
EVT_ACCOUNT,
|
||||
EVT_RAW,
|
||||
EVT_XQUERY,
|
||||
EVT_XREPLY,
|
||||
|
||||
// EVT_NOOP must always be last
|
||||
EVT_NOOP
|
||||
} ;
|
||||
|
||||
/**
|
||||
* The type used to represent network (non-channel) events.
|
||||
*/
|
||||
typedef int eventType ;
|
||||
|
||||
/**
|
||||
* This enumerates the possible channel events that gnuworld will
|
||||
* track and deliver to registered clients.
|
||||
*/
|
||||
enum
|
||||
{
|
||||
EVT_JOIN = EVT_NOOP,
|
||||
EVT_PART,
|
||||
EVT_SERVERMODE, // when server performs modes.
|
||||
EVT_TOPIC, // passed even if TRACK_TOPIC is disabled
|
||||
EVT_KICK, // moved to xClient::OnNetworkKick()
|
||||
EVT_CREATE
|
||||
} ;
|
||||
|
||||
/**
|
||||
* The type used to store possible channel events.
|
||||
*/
|
||||
typedef int channelEventType ;
|
||||
|
||||
/**
|
||||
* Arguments for the various events:
|
||||
* EVT_KILL
|
||||
* 1) iClient* or iServer* - source, could be NULL
|
||||
* 2) iClient* - target
|
||||
* 3) string* - reason
|
||||
* EVT_QUIT
|
||||
* 1) iClient*
|
||||
* EVT_SQUIT
|
||||
* 1) iServer* - server being squit
|
||||
* 2) string* - source
|
||||
* 3) string* - reason
|
||||
* EVT_BURST_ACK
|
||||
* 1) iServer*
|
||||
* EVT_NICK
|
||||
* 1) iClient*
|
||||
* EVT_NETJOIN
|
||||
* 1) iServer* - newly joined server
|
||||
* 2) iServer* - newly joined server's uplink server
|
||||
* EVT_BURST_ACK
|
||||
* 1) iServer*
|
||||
* EVT_CHNICK
|
||||
* 1) iClient* (nick updated)
|
||||
* 2) string* (old nick)
|
||||
* EVT_GLINE
|
||||
* 1) Gline*
|
||||
* EVT_REMGLINE
|
||||
* 1) Gline*
|
||||
* EVT_ACCOUNT
|
||||
* 1) iClient*
|
||||
* EVT_XQUERY
|
||||
* 1) iServer* source (might add iClient* later)
|
||||
* 2) string* - routing
|
||||
* 3) string* - command
|
||||
* EVT_XREPLY
|
||||
* 1) iServer* source
|
||||
* 2) string* - routing
|
||||
* 3) string* - command
|
||||
*
|
||||
* Channel Events
|
||||
* --------------
|
||||
* EVT_CREATE
|
||||
* 1) iClient*
|
||||
* EVT_PART
|
||||
* 1) iClient*
|
||||
* EVT_KICK
|
||||
* 1) iClient*
|
||||
* EVT_JOIN
|
||||
* 1) iClient*
|
||||
* 2) ChannelUser*
|
||||
*/
|
||||
|
||||
const std::string eventNames[] = {
|
||||
"Oper Up", /* EVT_OPER */
|
||||
"Net Break", /* EVT_NETBREAK */
|
||||
"Net Join", /* EVT_NETJOIN */
|
||||
"Burst Complete", /* EVT_BURST_CMPLT */
|
||||
"Burst Acknowledge", /* EVT_BURST_ACK */
|
||||
"Burst Acknowledge Sent", /* EVT_EA_SENT */
|
||||
"Gline Add", /* EVT_GLINE */
|
||||
"Gline Remove", /* EVT_REMGLINE */
|
||||
"Server Jupe", /* EVT_JUPE */
|
||||
"Server UnJupe", /* EVT_UNJUPE */
|
||||
"Client Quit", /* EVT_QUIT */
|
||||
"Client Kill", /* EVT_KILL */
|
||||
"Client Connect", /* EVT_NICK */
|
||||
"Nick Change", /* EVT_CHNICK */
|
||||
"Account Login", /* EVT_ACCOUNT */
|
||||
"Raw", /* EVT_RAW */
|
||||
"XQuery", /* EVT_XQUERY */
|
||||
"XReply", /* EVT_XREPLY */
|
||||
"Channel Join", /* EVT_JOIN */
|
||||
"Channel Part", /* EVT_PART */
|
||||
"Channel Mode By Server", /* EVT_SERVERMODE */
|
||||
"Channel Topic Change", /* EVT_TOPIC */
|
||||
"Channel Kick", /* EVT_KICK */
|
||||
"Channel Create" /* EVT_CREATE */
|
||||
} ;
|
||||
|
||||
} // namespace gnuworld
|
||||
|
||||
#endif // __EVENTS_H
|
||||
@@ -0,0 +1,77 @@
|
||||
/**
|
||||
* gnuworld_config.h
|
||||
* Copyright (C) 2002 Daniel Karrels <dan@karrels.com>
|
||||
*
|
||||
* 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; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; 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.
|
||||
*
|
||||
* $Id: gnuworld_config.h,v 1.4 2006/09/26 17:35:57 kewlio Exp $
|
||||
*/
|
||||
|
||||
#ifndef __GNUWORLD_CONFIG_H
|
||||
#define __GNUWORLD_CONFIG_H "$Id: gnuworld_config.h,v 1.4 2006/09/26 17:35:57 kewlio Exp $"
|
||||
|
||||
/* GNUWorld main configuration file */
|
||||
/* All core settings are set/defined here.
|
||||
*/
|
||||
#include "defs.h"
|
||||
|
||||
/**
|
||||
* CONFFILE
|
||||
* This is the name of the default file from which GNUWorld
|
||||
* will read its server characteristics.
|
||||
*/
|
||||
#define CONFFILE "GNUWorld.conf"
|
||||
|
||||
/**
|
||||
* ASUKA
|
||||
* Define this variable if gnuworld will be running on Asuka.
|
||||
* Enabling this by default will not have adverse effects on gnuworld's
|
||||
* functionality, except to increase memory usage a bit.
|
||||
*/
|
||||
#define ASUKA
|
||||
|
||||
/**
|
||||
* SRVX
|
||||
* Define this variable if gnuworld will be running on srvx.
|
||||
* Enabling this by default will not have adverse effects on gnuworld's
|
||||
* functionality, except to increase memory usage a bit.
|
||||
*/
|
||||
#define SRVX
|
||||
|
||||
/**
|
||||
* MAX_CHAN_MODES
|
||||
* The maximum number of channel modes per command.
|
||||
*/
|
||||
#define MAX_CHAN_MODES 10
|
||||
|
||||
/**
|
||||
* TOPIC_TRACK
|
||||
* Set if you want gnuworld to track topics in the network channels
|
||||
*/
|
||||
#define TOPIC_TRACK
|
||||
|
||||
/**
|
||||
* DAEMON
|
||||
* Set this to make GNUWorld fork into the background when run.
|
||||
* default is OFF to maintain original operation
|
||||
*/
|
||||
#undef DAEMON
|
||||
|
||||
#ifndef RCSTAG
|
||||
#define RCSTAG(tag) static const char rcsId[] = tag
|
||||
#endif
|
||||
|
||||
#endif /* __GNUWORLD_CONFIG_H */
|
||||
@@ -0,0 +1,877 @@
|
||||
/**
|
||||
* iClient.h
|
||||
* Copyright (C) 2002 Daniel Karrels <dan@karrels.com>
|
||||
*
|
||||
* 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; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; 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.
|
||||
*
|
||||
* $Id: iClient.h,v 1.49 2009/07/26 18:30:37 mrbean_ Exp $
|
||||
*/
|
||||
|
||||
#ifndef __ICLIENT_H
|
||||
#define __ICLIENT_H "$Id: iClient.h,v 1.49 2009/07/26 18:30:37 mrbean_ Exp $"
|
||||
|
||||
#include <string>
|
||||
#include <list>
|
||||
#include <map>
|
||||
|
||||
#include <ctime>
|
||||
|
||||
#include "gnuworld_config.h"
|
||||
#include "Channel.h"
|
||||
#include "iServer.h"
|
||||
#include "NetworkTarget.h"
|
||||
#include "ELog.h"
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
|
||||
class xClient ;
|
||||
class Network ;
|
||||
|
||||
/**
|
||||
* iClient objects represent network users. This class provides
|
||||
* basic functionality and state expected for a network client.
|
||||
* Note that iClient is NOT used for services clients, see
|
||||
* class xClient for that.
|
||||
*/
|
||||
class iClient : public NetworkTarget
|
||||
{
|
||||
|
||||
protected:
|
||||
|
||||
/**
|
||||
* The type used to hold channel patronage information
|
||||
* for each particular user.
|
||||
*/
|
||||
typedef std::list< Channel* > channelListType ;
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Define a type to be used for storing the
|
||||
* iClient's modes.
|
||||
*/
|
||||
typedef unsigned int modeType ;
|
||||
|
||||
/// MODE_OPER is true if the iClient is an IRC operator.
|
||||
static const modeType MODE_OPER ;
|
||||
|
||||
/// MODE_WALLOPS is true if the iClient is receiving wallops.
|
||||
static const modeType MODE_WALLOPS ;
|
||||
|
||||
/// MODE_INVISIBLE is true if the iClient is user mode invisible.
|
||||
static const modeType MODE_INVISIBLE ;
|
||||
|
||||
/// MODE_DEAF is true if the iClient is not receiving messages.
|
||||
static const modeType MODE_DEAF ;
|
||||
|
||||
/// MODE_SERVICES is true if the iClient is a service agent.
|
||||
static const modeType MODE_SERVICES ;
|
||||
|
||||
/// MODE_REGISTERED is true if the iClient has an account set.
|
||||
static const modeType MODE_REGISTERED ;
|
||||
|
||||
/// MODE_HIDDEN_HOST is true if the iClient has HIDDEN_HOST (+x) set.
|
||||
static const modeType MODE_HIDDEN_HOST ;
|
||||
|
||||
/// MODE_FAKE_HOST is true if the iClient has FAKE_HOST (+f) set.
|
||||
static const modeType MODE_FAKE_HOST ;
|
||||
|
||||
/// MODE_CLOAK_HOST is true if the iClient has CLOAK_HOST (+C) set.
|
||||
static const modeType MODE_CLOAK_HOST ;
|
||||
|
||||
/// MODE_CLOAK_IP is true if the iClient has CLOAK_IP (+c) set.
|
||||
static const modeType MODE_CLOAK_IP ;
|
||||
|
||||
/// MODE_G is true if the iCilent has user mode g set.
|
||||
static const modeType MODE_G ;
|
||||
|
||||
/// MODE_SERVNOTICES is true if this user is receiving server
|
||||
/// notices. This may not be transmitted on all networks.
|
||||
static const modeType MODE_SERVNOTICES ;
|
||||
|
||||
/** MODE_FAKE is true if this user is a fake client. */
|
||||
static const modeType MODE_FAKE;
|
||||
|
||||
/// Iterator for channels this user is on.
|
||||
typedef channelListType::iterator channelIterator ;
|
||||
|
||||
/// Constant iterator for channels this user is on.
|
||||
typedef channelListType::const_iterator const_channelIterator ;
|
||||
|
||||
/// Type used to store the number of channels for this iClient
|
||||
typedef channelListType::size_type channels_sizeType ;
|
||||
|
||||
/**
|
||||
* Construct a new iClient given a large list of
|
||||
* parameters for the client's state.
|
||||
*/
|
||||
iClient( const unsigned int& _uplink,
|
||||
const std::string& _yyxxx,
|
||||
const std::string& _nickName,
|
||||
const std::string& _userName,
|
||||
const std::string& _hostBase64,
|
||||
const std::string& _insecureHost,
|
||||
const std::string& _realInsecureHost,
|
||||
const std::string& _mode,
|
||||
const std::string& _account,
|
||||
const time_t _account_ts,
|
||||
const std::string& _description,
|
||||
const time_t& _connectTime ) ;
|
||||
|
||||
/**
|
||||
* Construct a new iClient given a large list of
|
||||
* parameters for the client's state.
|
||||
* This signature assumes that either/both of asuka are being
|
||||
* used.
|
||||
*/
|
||||
iClient( const unsigned int& _uplink,
|
||||
const std::string& _yyxxx,
|
||||
const std::string& _nickName,
|
||||
const std::string& _userName,
|
||||
const std::string& _hostBase64,
|
||||
const std::string& _insecureHost,
|
||||
const std::string& _realInsecureHost,
|
||||
const std::string& _mode,
|
||||
const std::string& _account,
|
||||
const time_t _account_ts,
|
||||
const std::string& _setHost,
|
||||
const std::string& _fakeHost,
|
||||
const std::string& _description,
|
||||
const time_t& _connectTime ) ;
|
||||
|
||||
/**
|
||||
* Construct a new iClient given a large list of
|
||||
* parameters for the client's state.
|
||||
* Used in case of Nefarious2 cloakedHost/IP
|
||||
*/
|
||||
iClient( const unsigned int& _uplink,
|
||||
const std::string& _yyxxx,
|
||||
const std::string& _nickName,
|
||||
const std::string& _userName,
|
||||
const std::string& _hostBase64,
|
||||
const std::string& _insecureHost,
|
||||
const std::string& _realInsecureHost,
|
||||
const std::string& _mode,
|
||||
const std::string& _account,
|
||||
const time_t _account_ts,
|
||||
const std::string& _description,
|
||||
const time_t& _connectTime,
|
||||
const std::string& _cloakHost,
|
||||
const std::string& _cloakIP,
|
||||
const std::string& _setHost,
|
||||
const std::string& _fakeHost
|
||||
) ;
|
||||
|
||||
/**
|
||||
* Destruct the iClient.
|
||||
* This will call xClient::deleteCustomData() for each
|
||||
* xClient which is storing a data element in this iClient.
|
||||
*/
|
||||
virtual ~iClient() ;
|
||||
|
||||
/* Accessor methods */
|
||||
|
||||
/**
|
||||
* Retrieve the iClient's nick name.
|
||||
*/
|
||||
inline const std::string& getNickName() const
|
||||
{ return nickName ; }
|
||||
|
||||
/**
|
||||
* Retrieve the iClient's user name.
|
||||
*/
|
||||
inline const std::string& getUserName() const
|
||||
{ return userName ; }
|
||||
|
||||
/**
|
||||
* Retrieve the iClient's host name, NOT IP.
|
||||
*/
|
||||
inline const std::string& getInsecureHost() const
|
||||
{ return insecureHost ;}
|
||||
|
||||
/**
|
||||
* Retrieve the iClient's 'real' host name.
|
||||
*/
|
||||
inline const std::string& getRealInsecureHost() const
|
||||
{ return realInsecureHost ;}
|
||||
|
||||
/**
|
||||
* Retrieve the iClient's 'cloaked' host name.
|
||||
*/
|
||||
inline const std::string& getCloakHost() const
|
||||
{ return cloakHost ;}
|
||||
|
||||
/**
|
||||
* Retrieve the iClient's 'cloaked' ip.
|
||||
*/
|
||||
inline const std::string& getCloakIP() const
|
||||
{ return cloakIP ;}
|
||||
|
||||
/**
|
||||
* Retrieve a string of the form: nick!user@host for this user.
|
||||
*/
|
||||
inline const std::string getNickUserHost() const
|
||||
{ return (nickName + '!' + userName + '@' + insecureHost) ; }
|
||||
|
||||
/**
|
||||
* Retrieve a string of the form: nick!user@real-host for this user.
|
||||
*/
|
||||
inline const std::string getRealNickUserHost() const
|
||||
{ return (nickName + '!' + userName + '@' + realInsecureHost) ; }
|
||||
|
||||
/**
|
||||
* Retrieve client's 'real-name' field.
|
||||
*/
|
||||
inline const std::string& getDescription() const
|
||||
{ return description ; }
|
||||
|
||||
/**
|
||||
* Overwrite this clients "Real Host" with a "Hidden Host".
|
||||
*/
|
||||
inline void setHiddenHost()
|
||||
{
|
||||
if (!isModeF())
|
||||
insecureHost = account + hiddenHostSuffix ;
|
||||
else
|
||||
insecureHost = getFakeHost();
|
||||
}
|
||||
|
||||
inline void setSetHost()
|
||||
{
|
||||
#ifdef ASUKA
|
||||
insecureHost = setHost;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will set the hidden host suffix. This value
|
||||
* is only modified by the xServer on startup.
|
||||
*/
|
||||
inline static void setHiddenHostSuffix( const std::string& newVal )
|
||||
{ hiddenHostSuffix = newVal ; }
|
||||
|
||||
/**
|
||||
* Retrieve client's 'account' field.
|
||||
*/
|
||||
inline const std::string& getAccount() const
|
||||
{ return account ; }
|
||||
|
||||
/**
|
||||
* Retrieve client's account timestamp.
|
||||
*
|
||||
* @return the timestamp of the account if set, else 0.
|
||||
*/
|
||||
inline const time_t& getAccountTS() const
|
||||
{ return account_ts; }
|
||||
|
||||
/**
|
||||
* Return the suffix hostname to be appended to the
|
||||
* user's account name for use with host hiding.
|
||||
*/
|
||||
inline static const std::string& getHiddenHostSuffix()
|
||||
{ return hiddenHostSuffix ; }
|
||||
|
||||
/**
|
||||
* This method sets user mode +r and records the account
|
||||
* domain for this network client.
|
||||
*/
|
||||
inline void setAccount( const std::string& _account )
|
||||
{
|
||||
account = _account ;
|
||||
setModeR() ;
|
||||
|
||||
// We know that the user is mode R already
|
||||
if (isModeX()) setHiddenHost();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the account timestamp for this iClient.
|
||||
* Only valid if the iClient isModeR()
|
||||
*/
|
||||
inline void setAccountTS( const time_t _account_ts )
|
||||
{
|
||||
if( ! isModeR() ) { return ; }
|
||||
|
||||
account_ts = _account_ts;
|
||||
}
|
||||
|
||||
#ifdef ASUKA
|
||||
/**
|
||||
* Retrieve the iClient's sethost.
|
||||
*/
|
||||
inline const std::string& getSetHost() const
|
||||
{ return setHost ; }
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This method sets user mode +r and records the account
|
||||
* domain for this network client.
|
||||
*/
|
||||
inline void setFakeHost( const std::string& _fakeHost )
|
||||
{
|
||||
#ifdef SRVX
|
||||
fakeHost = _fakeHost ;
|
||||
setModeF();
|
||||
if (isModeX())
|
||||
insecureHost = fakeHost;
|
||||
#endif
|
||||
}
|
||||
/*
|
||||
* This is only prinicple, probably ircu can't undo a hidden/fake host
|
||||
*/
|
||||
inline void clearFakeHost()
|
||||
{
|
||||
#ifdef SRVX
|
||||
fakeHost = std::string();
|
||||
removeModeF();
|
||||
if (isModeX())
|
||||
insecureHost = account + hiddenHostSuffix ;
|
||||
else
|
||||
insecureHost = getRealInsecureHost();
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef SRVX
|
||||
/**
|
||||
* Retrieve the iClient's fakehost.
|
||||
*/
|
||||
inline const std::string& getFakeHost() const
|
||||
{ return fakeHost ; }
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Retrieve the iClient's server
|
||||
*/
|
||||
const iServer* getServer();
|
||||
|
||||
/**
|
||||
* Retrieve the iClient's connection time.
|
||||
*/
|
||||
inline const time_t& getConnectTime() const
|
||||
{ return connectTime ; }
|
||||
|
||||
/**
|
||||
* Retrieve the iClient's IP. A network byte ordered
|
||||
* one-word mask is returned.
|
||||
* TODO: Make sure that a word is 32 bits, adjusting where
|
||||
* necessary for > 32bit architectures.
|
||||
*/
|
||||
inline const unsigned int& getIP() const
|
||||
{ return IP ; }
|
||||
|
||||
/**
|
||||
* Obtain const iterator to beginning of this user's channel
|
||||
* membership structure.
|
||||
*/
|
||||
inline const_channelIterator channels_begin() const
|
||||
{ return channelList.begin() ; }
|
||||
|
||||
/**
|
||||
* Obtain const iterator to end of this user's channel
|
||||
* membership structure.
|
||||
*/
|
||||
inline const_channelIterator channels_end() const
|
||||
{ return channelList.end() ; }
|
||||
|
||||
/**
|
||||
* Obtain mutable iterator to beginning of this user's channel
|
||||
* membership structure.
|
||||
*/
|
||||
inline channelIterator channels_begin()
|
||||
{ return channelList.begin() ; }
|
||||
|
||||
/**
|
||||
* Obtain mutable iterator to end of this user's channel
|
||||
* membership structure.
|
||||
*/
|
||||
inline channelIterator channels_end()
|
||||
{ return channelList.end() ; }
|
||||
|
||||
/**
|
||||
* Return the number of channels which this user is on.
|
||||
*/
|
||||
inline channels_sizeType channels_size() const
|
||||
{ return channelList.size() ; }
|
||||
|
||||
/* Mutator methods */
|
||||
|
||||
/**
|
||||
* Add a channel to this user's channel patronage structure.
|
||||
*/
|
||||
bool addChannel( Channel* newChannel ) ;
|
||||
|
||||
/**
|
||||
* Remove a channel from this user's channel patronage structure.
|
||||
*/
|
||||
bool removeChannel( Channel* theChannel ) ;
|
||||
|
||||
/**
|
||||
* Return true if this iClient is in the given channel.
|
||||
*/
|
||||
bool findChannel( const Channel* theChannel ) const ;
|
||||
|
||||
/**
|
||||
* Clear this client's list of channels. No heap space needs
|
||||
* to be deallocated here.
|
||||
*/
|
||||
inline void clearChannels()
|
||||
{ channelList.clear() ; }
|
||||
|
||||
/**
|
||||
* Change this iClient's nick name.
|
||||
* During an iClient's lifetime on the network, the only
|
||||
* thing that may change is its nickname.
|
||||
*/
|
||||
inline void setNickName( const std::string& newNick )
|
||||
{ nickName = newNick ; }
|
||||
|
||||
// The following methods are used to access and mutate
|
||||
// the client's modes.
|
||||
|
||||
/**
|
||||
* Return true if this client has the given mode set, false
|
||||
* otherwise.
|
||||
*/
|
||||
inline bool getMode( const modeType& theMode ) const
|
||||
{ return (theMode == (mode & theMode)) ; }
|
||||
|
||||
/**
|
||||
* Return true if this client has the +i mode set, false otherwise.
|
||||
*/
|
||||
inline bool isModeI() const
|
||||
{ return getMode( MODE_INVISIBLE ) ; }
|
||||
|
||||
/**
|
||||
* Return true if this client has the +w mode set, false otherwise.
|
||||
*/
|
||||
inline bool isModeW() const
|
||||
{ return getMode( MODE_WALLOPS ) ; }
|
||||
|
||||
/**
|
||||
* Return true if this client has the +k mode set, false otherwise.
|
||||
*/
|
||||
inline bool isModeK() const
|
||||
{ return getMode( MODE_SERVICES ) ; }
|
||||
|
||||
/**
|
||||
* Return true if this client has the +o mode set, false otherwise.
|
||||
*/
|
||||
inline bool isModeO() const
|
||||
{ return getMode( MODE_OPER ) ; }
|
||||
|
||||
/**
|
||||
* Return true if this client has the +d mode set, false otherwise.
|
||||
*/
|
||||
inline bool isModeD() const
|
||||
{ return getMode( MODE_DEAF ) ; }
|
||||
|
||||
/**
|
||||
* Return true if this client has the +r mode set, false otherwise.
|
||||
*/
|
||||
inline bool isModeR() const
|
||||
{ return getMode( MODE_REGISTERED ) ; }
|
||||
|
||||
/**
|
||||
* Return true if this client has the +x mode set, false otherwise.
|
||||
*/
|
||||
inline bool isModeX() const
|
||||
{ return getMode( MODE_HIDDEN_HOST ) ; }
|
||||
|
||||
/**
|
||||
* Return true if this client has the +f mode set, false otherwise.
|
||||
*/
|
||||
inline bool isModeF() const
|
||||
{ return getMode( MODE_FAKE_HOST ) ; }
|
||||
|
||||
/**
|
||||
* +h sethost, is always a hidden host.
|
||||
*/
|
||||
inline bool isModeH() const
|
||||
{ return getMode( MODE_HIDDEN_HOST ) ; }
|
||||
|
||||
/**
|
||||
* +C cloak host, is a hidden host.
|
||||
*/
|
||||
inline bool isModeC() const
|
||||
{ return getMode( MODE_CLOAK_HOST ) ; }
|
||||
|
||||
/**
|
||||
* +c cloak ip, is a hidden host.
|
||||
*/
|
||||
inline bool isModec() const
|
||||
{ return getMode( MODE_CLOAK_IP ) ; }
|
||||
|
||||
|
||||
/**
|
||||
* Return true if this client has the +g mode set, false otherwise.
|
||||
*/
|
||||
inline bool isModeG() const
|
||||
{ return getMode( MODE_G ) ; }
|
||||
|
||||
/**
|
||||
* Return true if this iClient is a fake, false otherwise.
|
||||
*/
|
||||
inline bool isFake() const
|
||||
{ return getMode( MODE_FAKE ) ; }
|
||||
|
||||
/**
|
||||
* Return true if this iClient is an oper, false otherwise.
|
||||
*/
|
||||
inline bool isOper() const
|
||||
{ return getMode( MODE_OPER ) ; }
|
||||
|
||||
/**
|
||||
* Return this iClient's current user modes.
|
||||
*/
|
||||
inline const modeType& getModes() const
|
||||
{ return mode ; }
|
||||
|
||||
/**
|
||||
* Set a user mode for this iClient.
|
||||
*/
|
||||
inline void setMode( const modeType& newMode )
|
||||
{ mode |= newMode ; }
|
||||
|
||||
/**
|
||||
* Set mode +i for this user.
|
||||
*/
|
||||
inline void setModeI()
|
||||
{ setMode( MODE_INVISIBLE ) ; }
|
||||
|
||||
/**
|
||||
* Set mode +w for this user.
|
||||
*/
|
||||
inline void setModeW()
|
||||
{ setMode( MODE_WALLOPS ) ; }
|
||||
|
||||
/**
|
||||
* Set mode +k for this user.
|
||||
*/
|
||||
inline void setModeK()
|
||||
{ setMode( MODE_SERVICES ) ; }
|
||||
|
||||
/**
|
||||
* Set mode +d for this user.
|
||||
*/
|
||||
inline void setModeD()
|
||||
{ setMode( MODE_DEAF ) ; }
|
||||
|
||||
/**
|
||||
* Set mode +g for this user.
|
||||
*/
|
||||
inline void setModeG()
|
||||
{ setMode( MODE_G ) ; }
|
||||
|
||||
/**
|
||||
* Set mode +o for this user.
|
||||
*/
|
||||
inline void setModeO()
|
||||
{ setMode( MODE_OPER ) ; }
|
||||
|
||||
/**
|
||||
* Set mode +x for this user.
|
||||
*/
|
||||
inline void setModeX()
|
||||
{
|
||||
setMode( MODE_HIDDEN_HOST ) ;
|
||||
if (isModeR() && isModeX()) setHiddenHost();
|
||||
}
|
||||
|
||||
inline void setModeF()
|
||||
{
|
||||
setMode( MODE_FAKE_HOST ) ;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set mode +r for this user.
|
||||
*/
|
||||
inline void setModeR()
|
||||
{ setMode( MODE_REGISTERED ) ; }
|
||||
|
||||
/**
|
||||
* Designate this iClient as a fake.
|
||||
*/
|
||||
inline void setFake()
|
||||
{ setMode( MODE_FAKE ) ; }
|
||||
|
||||
/**
|
||||
* Set mode +h for this user.
|
||||
*/
|
||||
inline void setModeH()
|
||||
{
|
||||
setMode( MODE_HIDDEN_HOST ) ;
|
||||
if (isModeH())
|
||||
setSetHost();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set mode +C for this user.
|
||||
*/
|
||||
inline void setModeC()
|
||||
{
|
||||
setMode( MODE_CLOAK_HOST ) ;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set mode +c for this user.
|
||||
*/
|
||||
inline void setModec()
|
||||
{
|
||||
setMode( MODE_CLOAK_IP ) ;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a user mode for this iClient.
|
||||
*/
|
||||
inline void removeMode( const modeType& theMode )
|
||||
{ mode &= ~theMode ; }
|
||||
|
||||
/**
|
||||
* Remove user mode 'i'.
|
||||
*/
|
||||
inline void removeModeI()
|
||||
{ removeMode( MODE_INVISIBLE ) ; }
|
||||
|
||||
/**
|
||||
* Remove user mode 'w'.
|
||||
*/
|
||||
inline void removeModeW()
|
||||
{ removeMode( MODE_WALLOPS ) ; }
|
||||
|
||||
/**
|
||||
* Remove user mode 'k'.
|
||||
*/
|
||||
inline void removeModeK()
|
||||
{ removeMode( MODE_SERVICES ) ; }
|
||||
|
||||
/**
|
||||
* Remove user mode 'd'.
|
||||
*/
|
||||
inline void removeModeD()
|
||||
{ removeMode( MODE_DEAF ) ; }
|
||||
|
||||
/**
|
||||
* Remove user mode 'g'.
|
||||
*/
|
||||
inline void removeModeG()
|
||||
{ removeMode( MODE_G ) ; }
|
||||
|
||||
/**
|
||||
* Remove user mode 'o'.
|
||||
*/
|
||||
inline void removeModeO()
|
||||
{ removeMode( MODE_OPER ) ; }
|
||||
|
||||
/**
|
||||
* Remove user mode 'x'.
|
||||
*/
|
||||
inline void removeModeX()
|
||||
{ removeMode( MODE_HIDDEN_HOST ) ; }
|
||||
|
||||
/**
|
||||
* Remove user mode 'r'.
|
||||
*/
|
||||
inline void removeModeR()
|
||||
{ removeMode( MODE_REGISTERED ) ; }
|
||||
|
||||
/**
|
||||
* Remove user mode 'f'.
|
||||
*/
|
||||
inline void removeModeF()
|
||||
{ removeMode( MODE_FAKE_HOST ) ; }
|
||||
|
||||
/**
|
||||
* Remove user mode 'h'.
|
||||
*/
|
||||
inline void removeModeH()
|
||||
{ removeMode( MODE_HIDDEN_HOST ) ; }
|
||||
/**
|
||||
* Return a string representation of this iClient's user
|
||||
* modes.
|
||||
*/
|
||||
const std::string getStringModes() const ;
|
||||
|
||||
/**
|
||||
* Add an xClient's personal data representation to this
|
||||
* iClient. Only one element per xClient is permitted.
|
||||
* This method will return false if the internal allocation
|
||||
* fails, or if the xClient in question is already using
|
||||
* a data element in this iClient, or if the addition to the
|
||||
* internal data structure fails.
|
||||
* Add a NULL value to this iClient is permitted.
|
||||
*/
|
||||
bool setCustomData( xClient*, void* ) ;
|
||||
|
||||
/**
|
||||
* Retrieve the custom data element for the given xClient.
|
||||
* If none is found, NULL is returned.
|
||||
*/
|
||||
void* getCustomData( xClient* ) const ;
|
||||
|
||||
/**
|
||||
* Retrieve, remove, and return the custom data element
|
||||
* for the given xClient. If none is found, NULL is
|
||||
* returned.
|
||||
*/
|
||||
void* removeCustomData( xClient* ) ;
|
||||
|
||||
/**
|
||||
* operator<< is overloaded for debugging purposes,
|
||||
* this makes it extremely easy to output this client's
|
||||
* information to an output stream.
|
||||
*/
|
||||
friend ELog& operator<<( ELog& out,
|
||||
const iClient& theClient )
|
||||
{
|
||||
out << theClient.nickName << '!'
|
||||
<< theClient.userName << '@'
|
||||
<< theClient.insecureHost
|
||||
<< " Numeric: " << theClient.getCharYYXXX()
|
||||
<< ", int YY/XXX/YYXXX: "
|
||||
<< theClient.getIntYY() << '/'
|
||||
<< theClient.getIntXXX() << '/'
|
||||
<< theClient.getIntYYXXX() ;
|
||||
return out ;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
/**
|
||||
* Disable copy constructor. This method is declared but
|
||||
* NOT defined.
|
||||
*/
|
||||
iClient( const iClient& ) ;
|
||||
|
||||
/**
|
||||
* Disable default assignment. This method is declared but
|
||||
* NOT defined.
|
||||
*/
|
||||
iClient operator=( const iClient& ) ;
|
||||
|
||||
/**
|
||||
* Parse a string of modes and set this iClient's
|
||||
* modes appropriately.
|
||||
* This is called by the constructor only.
|
||||
*/
|
||||
void setModes( const std::string& ) ;
|
||||
|
||||
// The below variables are ordered to provide
|
||||
// efficient instantiation. Do not alter order.
|
||||
|
||||
/**
|
||||
* This client's nick name.
|
||||
*/
|
||||
std::string nickName ;
|
||||
|
||||
/** This client's user name.
|
||||
*/
|
||||
std::string userName ;
|
||||
|
||||
/**
|
||||
* This client's 32 bit IP, stored in
|
||||
* network (bigendian) byte order.
|
||||
*/
|
||||
unsigned int IP ;
|
||||
|
||||
/**
|
||||
* This client's hostname as it appears to network users.
|
||||
* (Possibly a hidden-hostname is the user is +x)
|
||||
*/
|
||||
std::string insecureHost ;
|
||||
|
||||
/**
|
||||
* This client's actual network hostname, unhidden and
|
||||
* exposed.
|
||||
*/
|
||||
std::string realInsecureHost ;
|
||||
|
||||
/**
|
||||
* Nefarious2 Cloaked Host
|
||||
*/
|
||||
std::string cloakHost;
|
||||
|
||||
/**
|
||||
* Nefarious2 Cloaked IP
|
||||
*/
|
||||
std::string cloakIP;
|
||||
|
||||
/**
|
||||
* This client's 'real-name' field data.
|
||||
*/
|
||||
std::string description ;
|
||||
|
||||
/**
|
||||
* The time at which this iClient connected to the network.
|
||||
*/
|
||||
time_t connectTime ;
|
||||
|
||||
/**
|
||||
* This client's current user modes.
|
||||
*/
|
||||
modeType mode ;
|
||||
|
||||
/** This client's "Account". */
|
||||
std::string account ;
|
||||
|
||||
/** The timestamp of this client's account. */
|
||||
time_t account_ts ;
|
||||
|
||||
#ifdef ASUKA
|
||||
/**
|
||||
* This client's sethost.
|
||||
*/
|
||||
std::string setHost ;
|
||||
#endif
|
||||
|
||||
#ifdef SRVX
|
||||
/**
|
||||
* This client's fakehost.
|
||||
*/
|
||||
std::string fakeHost ;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* The structure used to store which channels this user is in.
|
||||
*/
|
||||
channelListType channelList ;
|
||||
|
||||
/**
|
||||
* This is the type used to represent the custom data map.
|
||||
*/
|
||||
typedef std::map< xClient*, void* > customDataMapType ;
|
||||
|
||||
/**
|
||||
* This structure is used to store generic data for
|
||||
* individual xClient's. Only one element per xClient is
|
||||
* permitted to be stored in this structure. A pointer is
|
||||
* used here to reduce memory footprint for those iClient's
|
||||
* whose customDataMap's aren't used.
|
||||
*/
|
||||
customDataMapType *customDataMap ;
|
||||
|
||||
/**
|
||||
* The suffix for all hidden host names.
|
||||
* This variable is read from the .conf file, and
|
||||
* has the form of "mynetwork.org".
|
||||
*/
|
||||
static std::string hiddenHostSuffix ;
|
||||
|
||||
} ;
|
||||
|
||||
} // namespace gnuworld
|
||||
|
||||
#endif // __ICLIENT_H
|
||||
@@ -0,0 +1,316 @@
|
||||
/**
|
||||
* iServer.h
|
||||
* iServer objects represent servers across the network, except
|
||||
* for the GNUWorld server itself (see class xServer).
|
||||
* Copyright (C) 2002 Daniel Karrels <dan@karrels.com>
|
||||
*
|
||||
* 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; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; 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.
|
||||
*
|
||||
* $Id: iServer.h,v 1.15 2006/12/22 06:41:41 kewlio Exp $
|
||||
*/
|
||||
|
||||
#ifndef __ISERVER_H
|
||||
#define __ISERVER_H "$Id: iServer.h,v 1.15 2006/12/22 06:41:41 kewlio Exp $"
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include <ctime>
|
||||
|
||||
#include "ELog.h"
|
||||
#include "NetworkTarget.h"
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
|
||||
class xServer ;
|
||||
class xNetwork ;
|
||||
|
||||
/**
|
||||
* This class represents a network server.
|
||||
*/
|
||||
class iServer : public NetworkTarget
|
||||
{
|
||||
/**
|
||||
* Allow xServer to directly manipulate the
|
||||
* internal state of this iServer.
|
||||
*/
|
||||
friend class xServer ;
|
||||
|
||||
/**
|
||||
* xNetwork needs access to setIntYY().
|
||||
*/
|
||||
friend class xNetwork ;
|
||||
|
||||
public:
|
||||
|
||||
/// Type used to hold flags
|
||||
typedef unsigned int flagType ;
|
||||
|
||||
/**
|
||||
* Flags that iServers may have.
|
||||
*/
|
||||
/* Set if this iServer is juped, false otherwise */
|
||||
static const flagType FLAG_JUPE ;
|
||||
/* Set if this iServer is a hub (+h) */
|
||||
static const flagType FLAG_HUB ;
|
||||
/* Set if this iServer is a service (+s) */
|
||||
static const flagType FLAG_SERVICE ;
|
||||
/* Set if this iServer is IPv6-compatible (+6) */
|
||||
static const flagType FLAG_IPV6 ;
|
||||
|
||||
/**
|
||||
* Construct an iServer given its vital state variables
|
||||
* as parameters.
|
||||
*/
|
||||
iServer( const unsigned int& _uplink,
|
||||
const std::string& _yyxxx,
|
||||
const std::string& _name,
|
||||
const time_t& _connectTime,
|
||||
const std::string& description = std::string() ) ;
|
||||
|
||||
/**
|
||||
* Destruct this iServer instance.
|
||||
*/
|
||||
virtual ~iServer() ;
|
||||
|
||||
/* Accessor methods */
|
||||
|
||||
/**
|
||||
* Return the iServer's flags.
|
||||
*/
|
||||
inline const flagType& getFlags() const
|
||||
{ return flags ; }
|
||||
|
||||
/**
|
||||
* Return true if a particular flag is set, false otherwise.
|
||||
*/
|
||||
inline bool getFlag( const flagType& whichFlag ) const
|
||||
{ return ((flags & whichFlag) == whichFlag) ; }
|
||||
|
||||
/**
|
||||
* Set a particular flags.
|
||||
*/
|
||||
inline void setFlag( const flagType& whichFlag )
|
||||
{ flags |= whichFlag ; }
|
||||
|
||||
/**
|
||||
* Remove a particular flag.
|
||||
*/
|
||||
inline void removeFlag( const flagType& whichFlag )
|
||||
{ flags &= ~whichFlag ; }
|
||||
|
||||
/**
|
||||
* Return true if this server is a jupe.
|
||||
*/
|
||||
inline bool isJupe() const
|
||||
{ return getFlag( FLAG_JUPE ) ; }
|
||||
|
||||
/**
|
||||
* Set this iServer as a juped server.
|
||||
*/
|
||||
inline void setJupe()
|
||||
{ setFlag( FLAG_JUPE ) ; }
|
||||
|
||||
/**
|
||||
* Return true if this server is a hub.
|
||||
*/
|
||||
inline bool isHub() const
|
||||
{ return getFlag( FLAG_HUB ) ; }
|
||||
|
||||
/**
|
||||
* Set this iServer as a hub.
|
||||
*/
|
||||
inline void setHub()
|
||||
{ setFlag( FLAG_HUB ) ; }
|
||||
|
||||
/**
|
||||
* Return true if this server is a service
|
||||
*/
|
||||
inline bool isService() const
|
||||
{ return getFlag( FLAG_SERVICE ) ; }
|
||||
|
||||
/**
|
||||
* Set this iServer as a service.
|
||||
*/
|
||||
inline void setService()
|
||||
{ setFlag( FLAG_SERVICE ) ; }
|
||||
|
||||
/**
|
||||
* Return true if this server is IPv6-compatible
|
||||
*/
|
||||
inline bool isIPv6() const
|
||||
{ return getFlag( FLAG_IPV6 ) ; }
|
||||
|
||||
/**
|
||||
* Set this iServer as IPv6-compatible
|
||||
*/
|
||||
inline void setIPv6()
|
||||
{ setFlag( FLAG_IPV6 ) ; }
|
||||
|
||||
/**
|
||||
* Return the server numeric of this server's uplink.
|
||||
*/
|
||||
inline const unsigned int& getUplinkIntYY() const
|
||||
{ return uplinkIntYY ; }
|
||||
|
||||
/**
|
||||
* Return the name of this server.
|
||||
*/
|
||||
inline const std::string& getName() const
|
||||
{ return name ; }
|
||||
|
||||
/**
|
||||
* Return the time at which this server connected to the network.
|
||||
*/
|
||||
inline const time_t& getConnectTime() const
|
||||
{ return connectTime ; }
|
||||
|
||||
/**
|
||||
* Return the time at which this server started.
|
||||
*/
|
||||
inline const time_t& getStartTime() const
|
||||
{ return startTime ; }
|
||||
|
||||
/**
|
||||
* Return the description of this server.
|
||||
*/
|
||||
inline const std::string& getDescription() const
|
||||
{ return description ; }
|
||||
|
||||
/**
|
||||
* Return true if no BURST state exists, false otherwise.
|
||||
*/
|
||||
virtual bool isBursting() const
|
||||
{ return bursting ; }
|
||||
|
||||
/**
|
||||
* This method is used by xServer to signify that this
|
||||
* iServer is now in the bursting state.
|
||||
*/
|
||||
virtual void startBursting()
|
||||
{ bursting = true ; }
|
||||
|
||||
/**
|
||||
* This method is called by xServer to signify that this
|
||||
* iServer has completed bursting.
|
||||
*/
|
||||
virtual void stopBursting()
|
||||
{ bursting = false ; }
|
||||
|
||||
/**
|
||||
* Permit setting an arbitrary value to the bursting
|
||||
* variable.
|
||||
*/
|
||||
virtual void setBursting( bool newVal )
|
||||
{ bursting = newVal ; }
|
||||
|
||||
/**
|
||||
* This method is called by class xServer once the uplink
|
||||
* of the xServer is known. This method is only called
|
||||
* for the single instance of the iServer for the core
|
||||
* xServer.
|
||||
*/
|
||||
virtual void setUplinkIntYY( const unsigned int& newYY )
|
||||
{ uplinkIntYY = newYY ; }
|
||||
|
||||
/**
|
||||
* Nice debugging method for outputting the iServer's
|
||||
* information to an ELog stream.
|
||||
*/
|
||||
friend ELog& operator<<( ELog& out,
|
||||
const iServer& serv )
|
||||
{
|
||||
out << "Name: " << serv.getName() << ' '
|
||||
<< "intYY: " << serv.getIntYY() << ' '
|
||||
<< "uplinkIntYY: "
|
||||
<< serv.getUplinkIntYY() << ' '
|
||||
<< "charYY: " << serv.getCharYY() ;
|
||||
return out ;
|
||||
}
|
||||
|
||||
/**
|
||||
* Nice debugging method for outputting the iServer's
|
||||
* information to a standard c++ output stream.
|
||||
*/
|
||||
friend std::ostream& operator<<( std::ostream& out,
|
||||
const iServer& serv )
|
||||
{
|
||||
out << "Name: " << serv.getName() << ' '
|
||||
<< "intYY: " << serv.getIntYY() << ' '
|
||||
<< "uplinkIntYY: "
|
||||
<< serv.getUplinkIntYY() << ' '
|
||||
<< "charYY: " << serv.getCharYY() ;
|
||||
return out ;
|
||||
}
|
||||
|
||||
/* Mutator methods */
|
||||
|
||||
/**
|
||||
* Interpret a server's flags.
|
||||
*/
|
||||
void setFlags( const std::string& ) ;
|
||||
|
||||
protected:
|
||||
|
||||
/**
|
||||
* Allow friends to modify the iServer's description. This
|
||||
* is used in the case of adding this server as a juped
|
||||
* server.
|
||||
*/
|
||||
inline void setDescription( const std::string& newDescription )
|
||||
{ description = newDescription ; }
|
||||
|
||||
/**
|
||||
* Integer numeric of this server's uplink.
|
||||
*/
|
||||
unsigned int uplinkIntYY ;
|
||||
|
||||
/**
|
||||
* Name of this server.
|
||||
*/
|
||||
std::string name ;
|
||||
|
||||
/**
|
||||
* The time at which this server joined the network.
|
||||
*/
|
||||
time_t connectTime ;
|
||||
|
||||
/**
|
||||
* The time at which this server was started.
|
||||
*/
|
||||
time_t startTime ;
|
||||
|
||||
/**
|
||||
* The server's description field.
|
||||
*/
|
||||
std::string description ;
|
||||
|
||||
/**
|
||||
* This variable is true when this server is bursting.
|
||||
*/
|
||||
bool bursting ;
|
||||
|
||||
/**
|
||||
* This server's flags.
|
||||
*/
|
||||
flagType flags ;
|
||||
|
||||
} ;
|
||||
|
||||
} // namespace gnuworld
|
||||
|
||||
#endif // __ISERVER_H
|
||||
+115
@@ -0,0 +1,115 @@
|
||||
/**
|
||||
* ip.h
|
||||
* This stuff should probably be moved to a static class.
|
||||
* xIP provides mostly utilitarian functionality for IP
|
||||
* addresses.
|
||||
* This class originally created by Orlando Bassotto.
|
||||
*
|
||||
* 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; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; 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.
|
||||
*
|
||||
* $Id: ip.h,v 1.7 2004/01/07 03:08:29 dan_karrels Exp $
|
||||
*/
|
||||
|
||||
#ifndef __IP_H
|
||||
#define __IP_H "$Id: ip.h,v 1.7 2004/01/07 03:08:29 dan_karrels Exp $"
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
|
||||
/**
|
||||
* A utility class that is used to retrieve information about
|
||||
* IP addresses.
|
||||
*/
|
||||
class xIP
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Construct an xIP instance given an address in std::string
|
||||
* format.
|
||||
*/
|
||||
xIP( const std::string& IP, bool Base64 = false ) ;
|
||||
|
||||
/**
|
||||
* Construct an xIP instance given an IP in long int format.
|
||||
*/
|
||||
xIP( const unsigned int& IP ) ;
|
||||
|
||||
/**
|
||||
* Construct an xIP instance given the four octets of
|
||||
* an IP address.
|
||||
*/
|
||||
xIP( const unsigned int& a,
|
||||
const unsigned int& b,
|
||||
const unsigned int& c,
|
||||
const unsigned int& d ) ;
|
||||
|
||||
/**
|
||||
* Copy constructor.
|
||||
*/
|
||||
xIP( const xIP& IP ) ;
|
||||
|
||||
/**
|
||||
* Destruct this xIP instance. No heap space is allocated.
|
||||
*/
|
||||
~xIP() {}
|
||||
|
||||
/**
|
||||
* Retrieve the IP in dotted decimals format.
|
||||
* This method invoked ::gethostbyaddr(), so might be slower.
|
||||
*/
|
||||
std::string GetIP() const ;
|
||||
|
||||
/**
|
||||
* Retrieve the IP in xxx.xxx.xxx.xxx character array format.
|
||||
*/
|
||||
std::string GetNumericIP() const ;
|
||||
|
||||
/**
|
||||
* Retrieve the IP as an unsigned int.
|
||||
*/
|
||||
const unsigned int& GetLongIP() const ;
|
||||
|
||||
/**
|
||||
* Place into the four variables passed to this method the
|
||||
* four octets of the IP.
|
||||
*/
|
||||
void GetIP( unsigned int& a,
|
||||
unsigned int& b,
|
||||
unsigned int& c,
|
||||
unsigned int& d ) const ;
|
||||
|
||||
/**
|
||||
* Return a character array representation of the base 64
|
||||
* IP.
|
||||
*/
|
||||
std::string GetBase64IP() const ;
|
||||
|
||||
protected:
|
||||
|
||||
/**
|
||||
* The IP number itself.
|
||||
*/
|
||||
unsigned int IP ;
|
||||
|
||||
} ;
|
||||
|
||||
} // namespace gnuworld
|
||||
|
||||
#endif // __XIP_H
|
||||
@@ -0,0 +1,241 @@
|
||||
/**
|
||||
* moduleLoader.h
|
||||
* Author: Daniel Karrels (dan@karrels.com)
|
||||
* Copyright (C) 2002 Daniel Karrels <dan@karrels.com>
|
||||
*
|
||||
* 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; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; 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.
|
||||
*
|
||||
* $Id: moduleLoader.h,v 1.21 2004/05/18 16:50:57 dan_karrels Exp $
|
||||
*/
|
||||
|
||||
#ifndef __MODULELOADER_H
|
||||
#define __MODULELOADER_H "$Id: moduleLoader.h,v 1.21 2004/05/18 16:50:57 dan_karrels Exp $"
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include <cstdlib> // exit()
|
||||
#include "ltdl.h"
|
||||
|
||||
#include "ELog.h"
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
|
||||
/**
|
||||
* This is a templated module loader class. The templated type is the
|
||||
* type of object to retrieve from the module. This class is used with
|
||||
* libtool for maximum portability.
|
||||
*/
|
||||
template< typename modType, typename argType = std::string >
|
||||
class moduleLoader
|
||||
{
|
||||
|
||||
protected:
|
||||
|
||||
/**
|
||||
* This is the type of the bootstrap function.
|
||||
*/
|
||||
typedef modType (*GNUWModuleFunc)(argType arg) ;
|
||||
|
||||
/**
|
||||
* Pointer to the loaded module.
|
||||
*/
|
||||
lt_dlhandle moduleHandle ;
|
||||
|
||||
/**
|
||||
* Pointer to the initialisation function.
|
||||
*/
|
||||
GNUWModuleFunc modFunc ;
|
||||
|
||||
/**
|
||||
* Pointer to the object being retrieved from the
|
||||
* module.
|
||||
*/
|
||||
modType modPtr ;
|
||||
|
||||
/**
|
||||
* The name of the module which this instance represents.
|
||||
*/
|
||||
std::string moduleName ;
|
||||
|
||||
/**
|
||||
* This variable is true if there was an error in loading
|
||||
* or resolving a symbol, false otherwise.
|
||||
*/
|
||||
bool hasError ;
|
||||
|
||||
/**
|
||||
* Provide a protected mutator for this class to use to modify
|
||||
* the error value.
|
||||
*/
|
||||
inline void setError( bool newVal = true )
|
||||
{ hasError = newVal ; }
|
||||
|
||||
public:
|
||||
/**
|
||||
* Constructor, takes a module filename as the only
|
||||
* parameter.
|
||||
*/
|
||||
moduleLoader( const std::string& _moduleName )
|
||||
: moduleName( _moduleName ),
|
||||
hasError( false )
|
||||
{
|
||||
// Initialize the function pointer to 0
|
||||
modFunc = 0 ;
|
||||
|
||||
// Must call lt_dlinit() to initialize libltdl.
|
||||
// This method may be called more than once
|
||||
if( lt_dlinit() != 0 )
|
||||
{
|
||||
elog << "moduleLoader> Failed to initialize "
|
||||
<< "module loading system: "
|
||||
<< lt_dlerror()
|
||||
<< std::endl ;
|
||||
setError() ;
|
||||
return ;
|
||||
}
|
||||
|
||||
std::string fileName( moduleName ) ;
|
||||
if( fileName[ 0 ] != '/' )
|
||||
{
|
||||
// No absolute path specified
|
||||
// Attempt to find the module in the currect directory
|
||||
fileName = std::string( "./" ) + fileName ;
|
||||
}
|
||||
|
||||
// Libtool libraries end with .la, and at this point, this class
|
||||
// only supports libtool libraries
|
||||
if( std::string::npos == fileName.find( ".la" ) )
|
||||
{
|
||||
// TODO: This should be more thorough
|
||||
fileName += ".la" ;
|
||||
}
|
||||
|
||||
// elog << "moduleLoader> Attempting to load module "
|
||||
// << fileName
|
||||
// << std::endl;
|
||||
|
||||
// lt_dlopenext() will do all that lt_dlopen() does,
|
||||
// but also check for .la, .so, .sl, etc extensions
|
||||
moduleHandle = lt_dlopen( fileName.c_str() ) ;
|
||||
|
||||
if( 0 == moduleHandle )
|
||||
{
|
||||
elog << "moduleLoader> Error opening module ("
|
||||
<< moduleName
|
||||
<< "): "
|
||||
<< lt_dlerror()
|
||||
<< std::endl;
|
||||
setError() ;
|
||||
return ;
|
||||
}
|
||||
|
||||
// elog << "moduleLoader> Module "
|
||||
// << moduleName
|
||||
// << " successfully loaded"
|
||||
// << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* The destructor closes the module, but does not perform
|
||||
* any other deallocation.
|
||||
*/
|
||||
virtual ~moduleLoader()
|
||||
{
|
||||
if( lt_dlclose( moduleHandle ) != 0 )
|
||||
{
|
||||
elog << "~moduleLoader> Error closing module: "
|
||||
<< lt_dlerror()
|
||||
<< std::endl ;
|
||||
}
|
||||
moduleHandle = 0 ;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts an instance of modType
|
||||
* derived object from this module, and returns it.
|
||||
* This method will execute only once for each instance.
|
||||
* Each additional call after the initial call to laodObject()
|
||||
* will return the object previously created.
|
||||
* The symbolSuffix is used to distinguish between similarly
|
||||
* named symbols to be loaded from the same module.
|
||||
*/
|
||||
modType loadObject( argType arg,
|
||||
const std::string& symbolSuffix = std::string() )
|
||||
{
|
||||
if( getError() )
|
||||
{
|
||||
// Error already present
|
||||
return 0 ;
|
||||
}
|
||||
|
||||
const std::string symbolName =
|
||||
std::string( "_gnuwinit" ) + symbolSuffix ;
|
||||
modFunc = (GNUWModuleFunc) lt_dlsym( moduleHandle,
|
||||
symbolName.c_str() ) ;
|
||||
if( 0 == modFunc )
|
||||
{
|
||||
elog << "moduleLoader::loadObject> Error: "
|
||||
<< lt_dlerror()
|
||||
<< std::endl ;
|
||||
setError() ;
|
||||
return 0 ;
|
||||
}
|
||||
|
||||
modPtr = modFunc( arg );
|
||||
|
||||
// Types usable by this class must support comparison against 0
|
||||
if( 0 == modPtr )
|
||||
{
|
||||
elog << "moduleLoader> Unable to instantiate modType."
|
||||
<< std::endl;
|
||||
setError() ;
|
||||
}
|
||||
|
||||
return modPtr ;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a string containing the module's name, as passed
|
||||
* to the constructor
|
||||
*/
|
||||
inline const std::string& getModuleName() const
|
||||
{ return moduleName ; }
|
||||
|
||||
/**
|
||||
* Return the last error seen by the module system.
|
||||
*/
|
||||
inline const std::string& getLastError() const
|
||||
{ return ::lt_dlerror() ; }
|
||||
|
||||
/**
|
||||
* Return by value the object being loaded from the module.
|
||||
*/
|
||||
inline modType getObject() const
|
||||
{ return modPtr ; }
|
||||
|
||||
/**
|
||||
* Return true if an error occured, false otherwise.
|
||||
*/
|
||||
inline bool getError() const
|
||||
{ return hasError ; }
|
||||
|
||||
} ;
|
||||
|
||||
} /* gnuworld */
|
||||
|
||||
#endif /* __MODULELOADER_H */
|
||||
@@ -0,0 +1,116 @@
|
||||
/**
|
||||
* nickUserCidr.h
|
||||
*
|
||||
* 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; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; 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.
|
||||
*
|
||||
* $Id: nickUserCidr.h,v 1.3 2009/07/26 18:30:37 mrbean_ Exp $
|
||||
*/
|
||||
|
||||
#ifndef __NICK_USER_CIDR_H
|
||||
#define __NICK_USER_CIDR_H "$Id: nickUserCidr.h,v 1.3 2009/07/26 18:30:37 mrbean_ Exp $"
|
||||
|
||||
#include <string>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netdb.h>
|
||||
#include <arpa/inet.h>
|
||||
#include "cidr.h"
|
||||
|
||||
namespace gnuworld
|
||||
{
|
||||
|
||||
/**
|
||||
* A utility class that is used to retrieve information about
|
||||
* CIDR addresses.
|
||||
*/
|
||||
class xNickUserCIDR
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Construct an xNickUserCIDR instance given an address in std::string
|
||||
* format.
|
||||
*/
|
||||
xNickUserCIDR( const std::string& nickUserCIDR) ;
|
||||
|
||||
/**
|
||||
* Checks whether or not the CIDR is valid.
|
||||
*/
|
||||
inline const bool& GetValid() const
|
||||
{ return valid; }
|
||||
|
||||
/**
|
||||
* Retrieve the mask of this CIDR (the part after the /).
|
||||
*/
|
||||
inline int GetMask() const
|
||||
{ return cidr.GetMask(); }
|
||||
|
||||
/**
|
||||
* Retrieve the prefix of this CIDR (the part before the /).
|
||||
*/
|
||||
inline const xIP& GetPrefix() const
|
||||
{ return cidr.GetPrefix(); }
|
||||
|
||||
/**
|
||||
* Retrieve the nick
|
||||
*/
|
||||
inline const std::string& GetNick() const
|
||||
{ return nick; }
|
||||
|
||||
/**
|
||||
* Retrieve the user
|
||||
*/
|
||||
inline const std::string& GetUser() const
|
||||
{ return user; }
|
||||
|
||||
inline const std::string& AsString() const
|
||||
{ return str; }
|
||||
|
||||
|
||||
bool matches(const std::string& IP) ;
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
/**
|
||||
* CIDR part
|
||||
*/
|
||||
xCIDR cidr;
|
||||
|
||||
/**
|
||||
* The nick
|
||||
*/
|
||||
std::string nick ;
|
||||
|
||||
/**
|
||||
* user
|
||||
*/
|
||||
std::string user ;
|
||||
|
||||
std::string str ;
|
||||
|
||||
bool valid;
|
||||
private:
|
||||
|
||||
bool ExtractNickUser(const std::string&);
|
||||
|
||||
} ;
|
||||
|
||||
} // namespace gnuworld
|
||||
|
||||
#endif
|
||||
+1559
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user