Main Page | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages | Examples

ArServerClient Class Reference

This class represents the server's connection to the client, and contains the socket that the server uses to talk to the client and the information for sending packets to the client. More...

#include <ArServerClient.h>

List of all members.

Public Types

enum  ServerState { STATE_SENT_INTRO, STATE_REJECTED, STATE_CONNECTED, STATE_DISCONNECTED }
 The state of the connection. More...

Public Member Functions

 ArServerClient (ArSocket *tcpSocket, unsigned int udpPort, long authKey, long introKey, ArRetFunctor2< bool, ArNetPacket *, struct sockaddr_in * > *sendUdpCallback, std::map< unsigned int, ArServerData * > *dataMap, const char *passwordKey, const char *serverKey, const ArServerUserInfo *userInfo=NULL, int rejecting=0, const char *rejectingString="")
 Constructor.
void broadcastPacketTcp (ArNetPacket *packet)
 Broadcasts a packet over TCP if this client wants this data -- For internal use only!
void broadcastPacketUdp (ArNetPacket *packet)
 Broadcasts a packet over UDP if this client wants this data (unless client only wants tcp then sends over tcp) -- For internal ArNetworking use only!
void forceDisconnect (bool quiet)
 Forcibly disconnect a client (for client/server switching).
long getAuthKey (void)
 Gets the authKey used for setting up UDP from this client to the server.
long getFrequency (ArTypes::UByte2 command)
 Gets how often a command is asked for.
const char * getIPString (void) const
 Gets the IP string of the client.
ArSocketgetTcpSocket (void)
 Internal function to get the tcp socket.
sockaddr_in * getUdpAddress (void)
 Gets the sin (network address) for the UDP socket.
void handleRequests (void)
 Handles the requests for packets.
bool hasGroupAccess (const char *group)
 Sees if this client has access to a given group.
void logTracking (bool terse)
 Logs the tracking information (packet and byte counts).
void processAuthPacket (ArNetPacket *packet, struct sockaddr_in *sin)
 Processes the auth packets that came from udp.
void processPacket (ArNetPacket *packet, bool tcp=true)
 Process the packet whever it came from.
void resetTracking (void)
 Clears the tracking information (resets counters).
bool sendPacketTcp (ArNetPacket *packet)
 Send a packet over TCP.
bool sendPacketUdp (ArNetPacket *packet)
 Send a packet over UDP (unless client only wants TCP; then sends over TCP).
void setUdpAddress (struct sockaddr_in *sin)
 Sets the sin (network address) for the UDP socket.
void shutdown (void)
 Sends a shutdown command to the socket.
bool tcpCallback (void)
 The callback for taking care of the TCP connection.
virtual ~ArServerClient ()
 Destructor.

Protected Member Functions

unsigned int getCommand ()
void internalSwitchState (ServerState state)
void popCommand (void)
void pushCommand (unsigned int num)
void sendListPacket (void)
bool setupPacket (ArNetPacket *packet)
void trackPacketReceived (ArNetPacket *packet, ArTypes::UByte2, bool tcp)
void trackPacketSent (ArNetPacket *packet, bool tcp)

Protected Attributes

long myAuthKey
std::list< unsigned int > myCommandStack
std::map< unsigned int, ArServerData * > * myDataMap
std::set< std::string, ArStrCaseCmpOp > myGroups
long myIntroKey
std::string myPasswordKey
ArFunctor2C< ArServerClient,
ArNetPacket *, bool > 
myProcessPacketCB
int myRejecting
std::string myRejectingString
std::list< ArServerClientData * > myRequested
ArRetFunctor2< bool, ArNetPacket *,
struct sockaddr_in * > * 
mySendUdpCB
std::string myServerKey
sockaddr_in mySin
ServerState myState
ArTime myStateStart
bool myTcpOnly
ArNetPacketReceiverTcp myTcpReceiver
ArNetPacketSenderTcp myTcpSender
ArSocket myTcpSocket
std::map< ArTypes::UByte2,
Tracker * > 
myTrackingReceivedMap
std::map< ArTypes::UByte2,
Tracker * > 
myTrackingSentMap
ArTime myTrackingStarted
bool myUdpConfirmedFrom
bool myUdpConfirmedTo
const ArServerUserInfomyUserInfo

Classes

class  Tracker


Detailed Description

This class represents the server's connection to the client, and contains the socket that the server uses to talk to the client and the information for sending packets to the client.
Examples:

drawingsExampleWithRobot.cpp.

Definition at line 45 of file ArServerClient.h.


Member Enumeration Documentation

enum ArServerClient::ServerState
 

The state of the connection.

Enumeration values:
STATE_SENT_INTRO  opened socket, sent our intro to the server
STATE_REJECTED  Client was rejected by server.
STATE_CONNECTED  Client is connected to server.
STATE_DISCONNECTED  Client has disconnected from server.

Definition at line 49 of file ArServerClient.h.


Constructor & Destructor Documentation

ArServerClient::ArServerClient ArSocket tcpSocket,
unsigned int  udpPort,
long  authKey,
long  introKey,
ArRetFunctor2< bool, ArNetPacket *, struct sockaddr_in * > *  sendUdpCallback,
std::map< unsigned int, ArServerData * > *  dataMap,
const char *  passwordKey,
const char *  serverKey,
const ArServerUserInfo userInfo = NULL,
int  rejecting = 0,
const char *  rejectingString = ""
 

Constructor.

Parameters:
tcpSocket the socket that has been established between the client and the server
udpPort the udp port the server is using
authKey this authKey must be presented by the client to the server on the server's UDP port for the client to be recognized by the server
introKey this key must be presented by the server to the client so that the client will recognize the server
sendUdpCallback the callback used to send Udp packets (since the udp packets need to be sent from the server's udp port and the serverclient here doesn't have one)
dataMap the map between command numbers and the command data
passwordKey the key (just plain text thats used in an md5 along with the serverKey and the password over on the client side) that was generated for the passwords on this exact connection
serverKey the key (just plain text thats used in an md5 along with the passwordKey and the password over on the client side) that should be used for any connections to this server
userInfo the pointer to the item that holds our usernames and passwords

Definition at line 68 of file ArServerClient.cpp.

References ArNetPacket::empty(), internalSwitchState(), myAuthKey, myDataMap, myIntroKey, myPasswordKey, myProcessPacketCB, myRejecting, myRejectingString, mySendUdpCB, myServerKey, myTcpOnly, myTcpReceiver, myTcpSender, myTcpSocket, myUserInfo, pushCommand(), resetTracking(), sendPacketTcp(), ArSocket::setCloseCallback(), ArNetPacket::setCommand(), ArSocket::setNonBlock(), ArNetPacketReceiverTcp::setProcessPacketCB(), ArNetPacketSenderTcp::setSocket(), ArNetPacketReceiverTcp::setSocket(), STATE_SENT_INTRO, ArBasePacket::strToBuf(), ArSocket::transfer(), ArBasePacket::uByte2ToBuf(), and ArBasePacket::uByte4ToBuf().

ArServerClient::~ArServerClient  )  [virtual]
 

Destructor.

MPL fixing a memory leak

Definition at line 115 of file ArServerClient.cpp.

References ArServerData::callRequestChangedFunctor(), ArSocket::close(), ArUtil::deleteSetPairs(), myRequested, myTcpReceiver, myTcpSocket, myTrackingReceivedMap, myTrackingSentMap, ArNetPacketReceiverTcp::setProcessPacketCB(), and ArNetPacketReceiverTcp::setSocket().


Member Function Documentation

void ArServerClient::broadcastPacketTcp ArNetPacket packet  ) 
 

Broadcasts a packet over TCP if this client wants this data -- For internal use only!

For internal use only.

Definition at line 656 of file ArServerClient.cpp.

References ArServerData::getCommand(), ArServerClientData::getServerData(), myRequested, and sendPacketTcp().

void ArServerClient::broadcastPacketUdp ArNetPacket packet  ) 
 

Broadcasts a packet over UDP if this client wants this data (unless client only wants tcp then sends over tcp) -- For internal ArNetworking use only!

For internal use only.

Definition at line 678 of file ArServerClient.cpp.

References ArServerData::getCommand(), ArServerClientData::getServerData(), myRequested, and sendPacketUdp().

void ArServerClient::forceDisconnect bool  quiet  ) 
 

Forcibly disconnect a client (for client/server switching).

Definition at line 613 of file ArServerClient.cpp.

References ArSocket::getIPString(), internalSwitchState(), ArLog::log(), myTcpSocket, and STATE_DISCONNECTED.

long ArServerClient::getAuthKey void   ) 
 

Gets the authKey used for setting up UDP from this client to the server.

Definition at line 755 of file ArServerClient.cpp.

References myAuthKey.

unsigned int ArServerClient::getCommand  )  [protected]
 

Definition at line 760 of file ArServerClient.cpp.

References myCommandStack.

Referenced by setupPacket().

long ArServerClient::getFrequency ArTypes::UByte2  command  ) 
 

Gets how often a command is asked for.

Parameters:
command the command number, you can use findCommandFromName
Returns:
returns lowest amount of time requested for this packet, note that 0 and higher means thats how often it was asked for, -1 means nothing requested the data at an interval but wants it when its been pushed, and -2 means that nothing wants the data

Definition at line 1037 of file ArServerClient.cpp.

References ArServerData::getCommand(), ArServerClientData::getMSec(), ArServerClientData::getServerData(), and myRequested.

const char * ArServerClient::getIPString void   )  const
 

Gets the IP string of the client.

Definition at line 789 of file ArServerClient.cpp.

References ArSocket::getIPString(), and myTcpSocket.

Referenced by logTracking().

ArSocket* ArServerClient::getTcpSocket void   )  [inline]
 

Internal function to get the tcp socket.

Definition at line 127 of file ArServerClient.h.

References myTcpSocket.

struct sockaddr_in * ArServerClient::getUdpAddress void   ) 
 

Gets the sin (network address) for the UDP socket.

Definition at line 750 of file ArServerClient.cpp.

References mySin.

void ArServerClient::handleRequests void   ) 
 

Handles the requests for packets.

Definition at line 179 of file ArServerClient.cpp.

References ArServerData::getCommand(), ArServerData::getFunctor(), ArServerClientData::getLastSent(), ArServerClientData::getMSec(), ArServerClientData::getPacket(), ArServerClientData::getServerData(), ArFunctor2< P1, P2 >::invoke(), ArTime::mSecSince(), myRequested, popCommand(), pushCommand(), and ArServerClientData::setLastSentToNow().

bool ArServerClient::hasGroupAccess const char *  group  ) 
 

Sees if this client has access to a given group.

Definition at line 1019 of file ArServerClient.cpp.

References myGroups, and myUserInfo.

void ArServerClient::internalSwitchState ServerState  state  )  [protected]
 

Definition at line 147 of file ArServerClient.cpp.

References myState, myStateStart, and ArTime::setToNow().

Referenced by ArServerClient(), forceDisconnect(), and processPacket().

void ArServerClient::logTracking bool  terse  ) 
 

Logs the tracking information (packet and byte counts).

Definition at line 828 of file ArServerClient.cpp.

References ArSocket::getBytesRecvd(), ArSocket::getBytesSent(), getIPString(), ArSocket::getRecvs(), ArSocket::getSends(), ArLog::log(), ArServerClient::Tracker::myBytesTcp, ArServerClient::Tracker::myBytesUdp, myDataMap, ArServerClient::Tracker::myPacketsTcp, ArServerClient::Tracker::myPacketsUdp, myTcpSocket, myTrackingReceivedMap, myTrackingSentMap, myTrackingStarted, and ArTime::secSince().

void ArServerClient::popCommand void   )  [protected]
 

Definition at line 770 of file ArServerClient.cpp.

References ArLog::log(), and myCommandStack.

Referenced by handleRequests(), and processPacket().

void ArServerClient::processAuthPacket ArNetPacket packet,
struct sockaddr_in *  sin
 

Processes the auth packets that came from udp.

Definition at line 621 of file ArServerClient.cpp.

References ArBasePacket::byte4ToBuf(), ArNetPacket::empty(), ArLog::log(), myAuthKey, myIntroKey, mySin, myUdpConfirmedFrom, sendPacketTcp(), sendPacketUdp(), and ArNetPacket::setCommand().

void ArServerClient::processPacket ArNetPacket packet,
bool  tcp = true
 

Process the packet whever it came from.

Definition at line 314 of file ArServerClient.cpp.

References ArBasePacket::bufToByte4(), ArBasePacket::bufToData(), ArBasePacket::bufToStr(), ArBasePacket::bufToUByte2(), ArBasePacket::byte2ToBuf(), ArBasePacket::byte4ToBuf(), ArServerData::callRequestChangedFunctor(), ArNetPacket::empty(), ArServerData::getCommand(), ArServerData::getCommandGroup(), ArServerData::getFunctor(), ArSocket::getIPString(), ArServerData::getName(), ArServerClientData::getPacket(), ArServerData::getRequestOnceFunctor(), ArServerClientData::getServerData(), ArServerUserInfo::getUsersGroups(), ArSocket::hostToNetOrder(), ArSocket::inAddr(), internalSwitchState(), ArFunctor2< P1, P2 >::invoke(), ArLog::log(), ArServerUserInfo::matchUserPassword(), myDataMap, myGroups, myIntroKey, myPasswordKey, myRejecting, myRejectingString, myRequested, myServerKey, myState, myTcpOnly, myTcpSocket, myUdpConfirmedTo, myUserInfo, popCommand(), pushCommand(), sendListPacket(), sendPacketTcp(), sendPacketUdp(), ArNetPacket::setCommand(), ArServerClientData::setMSec(), ArServerClientData::setPacket(), setUdpAddress(), STATE_CONNECTED, STATE_DISCONNECTED, STATE_REJECTED, STATE_SENT_INTRO, ArBasePacket::strToBuf(), and trackPacketReceived().

void ArServerClient::pushCommand unsigned int  num  )  [protected]
 

Definition at line 765 of file ArServerClient.cpp.

References myCommandStack.

Referenced by ArServerClient(), handleRequests(), and processPacket().

void ArServerClient::resetTracking void   ) 
 

Clears the tracking information (resets counters).

Definition at line 1002 of file ArServerClient.cpp.

References myTcpSocket, myTrackingReceivedMap, myTrackingSentMap, myTrackingStarted, ArSocket::resetTracking(), and ArTime::setToNow().

Referenced by ArServerClient().

void ArServerClient::sendListPacket void   )  [protected]
 

Definition at line 207 of file ArServerClient.cpp.

References ArNetPacket::empty(), ArServerData::getArgumentDescription(), ArServerData::getCommand(), ArServerData::getCommandGroup(), ArServerData::getDataFlagsString(), ArServerData::getDescription(), ArBasePacket::getLength(), ArServerData::getName(), ArServerData::getReturnDescription(), myDataMap, myGroups, myUserInfo, sendPacketTcp(), ArNetPacket::setCommand(), ArBasePacket::setLength(), ArBasePacket::strToBuf(), and ArBasePacket::uByte2ToBuf().

Referenced by processPacket().

bool ArServerClient::sendPacketTcp ArNetPacket packet  ) 
 

Send a packet over TCP.

The command ID of the outgoing packet will be set to the current command ID (from the incoming packet).

Definition at line 700 of file ArServerClient.cpp.

References myTcpSender, ArNetPacketSenderTcp::sendPacket(), setupPacket(), and trackPacketSent().

Referenced by ArServerClient(), broadcastPacketTcp(), processAuthPacket(), processPacket(), sendListPacket(), sendPacketUdp(), and shutdown().

bool ArServerClient::sendPacketUdp ArNetPacket packet  ) 
 

Send a packet over UDP (unless client only wants TCP; then sends over TCP).

The command ID of the outgoing packet will be set to the current command ID (from the incoming packet).

Definition at line 712 of file ArServerClient.cpp.

References ArRetFunctor2< Ret, P1, P2 >::invokeR(), mySendUdpCB, mySin, myTcpOnly, sendPacketTcp(), setupPacket(), and trackPacketSent().

Referenced by broadcastPacketUdp(), processAuthPacket(), and processPacket().

void ArServerClient::setUdpAddress struct sockaddr_in *  sin  ) 
 

Sets the sin (network address) for the UDP socket.

Definition at line 745 of file ArServerClient.cpp.

References mySin.

Referenced by processPacket().

bool ArServerClient::setupPacket ArNetPacket packet  )  [protected]
 

Definition at line 728 of file ArServerClient.cpp.

References getCommand(), ArLog::log(), myState, and STATE_DISCONNECTED.

Referenced by sendPacketTcp(), and sendPacketUdp().

void ArServerClient::shutdown void   ) 
 

Sends a shutdown command to the socket.

Definition at line 780 of file ArServerClient.cpp.

References myTcpSender, ArNetPacketSenderTcp::sendData(), sendPacketTcp(), and ArNetPacket::setCommand().

bool ArServerClient::tcpCallback void   ) 
 

The callback for taking care of the TCP connection.

Definition at line 153 of file ArServerClient.cpp.

References ArSocket::getIPString(), ArLog::log(), myState, myTcpReceiver, myTcpSender, myTcpSocket, ArNetPacketReceiverTcp::readData(), ArNetPacketSenderTcp::sendData(), ArUtil::sleep(), STATE_DISCONNECTED, and STATE_REJECTED.

void ArServerClient::trackPacketReceived ArNetPacket packet,
ArTypes::UByte2  ,
bool  tcp
[protected]
 

Definition at line 811 of file ArServerClient.cpp.

References myTrackingReceivedMap.

Referenced by processPacket().

void ArServerClient::trackPacketSent ArNetPacket packet,
bool  tcp
[protected]
 

Definition at line 794 of file ArServerClient.cpp.

References myTrackingSentMap.

Referenced by sendPacketTcp(), and sendPacketUdp().


Member Data Documentation

long ArServerClient::myAuthKey [protected]
 

Definition at line 163 of file ArServerClient.h.

Referenced by ArServerClient(), getAuthKey(), and processAuthPacket().

std::list<unsigned int> ArServerClient::myCommandStack [protected]
 

Definition at line 134 of file ArServerClient.h.

Referenced by getCommand(), popCommand(), and pushCommand().

std::map<unsigned int, ArServerData *>* ArServerClient::myDataMap [protected]
 

Definition at line 151 of file ArServerClient.h.

Referenced by ArServerClient(), logTracking(), processPacket(), and sendListPacket().

std::set<std::string, ArStrCaseCmpOp> ArServerClient::myGroups [protected]
 

Definition at line 149 of file ArServerClient.h.

Referenced by hasGroupAccess(), processPacket(), and sendListPacket().

long ArServerClient::myIntroKey [protected]
 

Definition at line 164 of file ArServerClient.h.

Referenced by ArServerClient(), processAuthPacket(), and processPacket().

std::string ArServerClient::myPasswordKey [protected]
 

Definition at line 166 of file ArServerClient.h.

Referenced by ArServerClient(), and processPacket().

ArFunctor2C<ArServerClient, ArNetPacket *, bool> ArServerClient::myProcessPacketCB [protected]
 

Definition at line 160 of file ArServerClient.h.

Referenced by ArServerClient().

int ArServerClient::myRejecting [protected]
 

Definition at line 169 of file ArServerClient.h.

Referenced by ArServerClient(), and processPacket().

std::string ArServerClient::myRejectingString [protected]
 

Definition at line 170 of file ArServerClient.h.

Referenced by ArServerClient(), and processPacket().

std::list<ArServerClientData *> ArServerClient::myRequested [protected]
 

Definition at line 152 of file ArServerClient.h.

Referenced by broadcastPacketTcp(), broadcastPacketUdp(), getFrequency(), handleRequests(), processPacket(), and ~ArServerClient().

ArRetFunctor2<bool, ArNetPacket *, struct sockaddr_in *>* ArServerClient::mySendUdpCB [protected]
 

Definition at line 161 of file ArServerClient.h.

Referenced by ArServerClient(), and sendPacketUdp().

std::string ArServerClient::myServerKey [protected]
 

Definition at line 167 of file ArServerClient.h.

Referenced by ArServerClient(), and processPacket().

struct sockaddr_in ArServerClient::mySin [protected]
 

Definition at line 162 of file ArServerClient.h.

Referenced by getUdpAddress(), processAuthPacket(), sendPacketUdp(), and setUdpAddress().

ServerState ArServerClient::myState [protected]
 

Definition at line 154 of file ArServerClient.h.

Referenced by internalSwitchState(), processPacket(), setupPacket(), and tcpCallback().

ArTime ArServerClient::myStateStart [protected]
 

Definition at line 155 of file ArServerClient.h.

Referenced by internalSwitchState().

bool ArServerClient::myTcpOnly [protected]
 

Definition at line 165 of file ArServerClient.h.

Referenced by ArServerClient(), processPacket(), and sendPacketUdp().

ArNetPacketReceiverTcp ArServerClient::myTcpReceiver [protected]
 

Definition at line 159 of file ArServerClient.h.

Referenced by ArServerClient(), tcpCallback(), and ~ArServerClient().

ArNetPacketSenderTcp ArServerClient::myTcpSender [protected]
 

Definition at line 150 of file ArServerClient.h.

Referenced by ArServerClient(), sendPacketTcp(), shutdown(), and tcpCallback().

ArSocket ArServerClient::myTcpSocket [protected]
 

Definition at line 158 of file ArServerClient.h.

Referenced by ArServerClient(), forceDisconnect(), getIPString(), getTcpSocket(), logTracking(), processPacket(), resetTracking(), tcpCallback(), and ~ArServerClient().

std::map<ArTypes::UByte2, Tracker *> ArServerClient::myTrackingReceivedMap [protected]
 

Definition at line 189 of file ArServerClient.h.

Referenced by logTracking(), resetTracking(), trackPacketReceived(), and ~ArServerClient().

std::map<ArTypes::UByte2, Tracker *> ArServerClient::myTrackingSentMap [protected]
 

Definition at line 188 of file ArServerClient.h.

Referenced by logTracking(), resetTracking(), trackPacketSent(), and ~ArServerClient().

ArTime ArServerClient::myTrackingStarted [protected]
 

Definition at line 173 of file ArServerClient.h.

Referenced by logTracking(), and resetTracking().

bool ArServerClient::myUdpConfirmedFrom [protected]
 

Definition at line 156 of file ArServerClient.h.

Referenced by processAuthPacket().

bool ArServerClient::myUdpConfirmedTo [protected]
 

Definition at line 157 of file ArServerClient.h.

Referenced by processPacket().

const ArServerUserInfo* ArServerClient::myUserInfo [protected]
 

Definition at line 148 of file ArServerClient.h.

Referenced by ArServerClient(), hasGroupAccess(), processPacket(), and sendListPacket().


The documentation for this class was generated from the following files:
Generated on Tue Feb 20 10:51:51 2007 for ArNetworking by  doxygen 1.4.0