/*
....[@@@..[@@@..............[@.................. MUD++ is a written from
....[@..[@..[@..[@..[@..[@@@@@....[@......[@.... scratch multi-user swords and
....[@..[@..[@..[@..[@..[@..[@..[@@@@@..[@@@@@.. sorcery game written in C++.
....[@......[@..[@..[@..[@..[@....[@......[@.... This server is an ongoing
....[@......[@..[@@@@@..[@@@@@.................. development project. All
................................................ contributions are welcome.
....Copyright(C).1995.Melvin.Smith.............. Enjoy.
------------------------------------------------------------------------------
Melvin Smith (aka Fusion) msmith@hom.net
MUD++ development mailing list mudpp@van.ml.org
------------------------------------------------------------------------------
cluster.h
*/
#ifndef _CLUSTER_H
#include "string.h"
#include "socket.h"
#include "llist.h"
class Host
{
protected:
String name;
String passwd;
String host;
int port1;
int port2;
int tries;
int maxtries; // how many times should we try connection
timeval last; // last connect attempt
timeval timeout; // time in between tries
Socket * socket; // set if connected otherwise null
public:
Host()
: port1(0), port2(0), tries(0), maxtries(0), socket(0)
{
}
Host( char *n, char *pw, char *h, int p1, int p2, int t, int secs )
: port1(p1), port2(p2), tries(t), socket(0)
{
name = n;
passwd = pw;
host = h;
timeout.tv_sec = secs;
timeout.tv_usec = 0;
}
const String & getName() { return name; }
const String & getPasswd() { return passwd; }
const String & getHost() { return host; }
int getPlayerPort() { return port1; }
int getCommPort() { return port2; }
void setName( const String & x ) { name = x; }
void setPasswd( const String & x ) { passwd = x; }
void setHost( const String & x ) { host = x; }
void setPlayerPort( int x ) { port1 = x; }
void setCommPort( int x ) { port2 = x; }
int connect();
Socket * connected() { return socket; }
int write( const char * str );
int read( char * str, int bytes );
};
inline int Host::read( char * str, int max_read )
{
if( socket )
return socket->read( str, max_read );
return -1;
}
inline int Host::write( const char * str )
{
if( socket )
return socket->write( str );
return -1;
}
extern LList< Host > cluster;
extern Host local;
Host * getHostCluster( const String & );
int loadHostsFile();
#endif