Gobligine/metaserver/netdriver.h

152 lines
4 KiB
C
Raw Normal View History

2005-04-03 10:07:40 -06:00
// _________ __ __
// / _____// |_____________ _/ |______ ____ __ __ ______
// \_____ \\ __\_ __ \__ \\ __\__ \ / ___\| | \/ ___/
// / \| | | | \// __ \| | / __ \_/ /_/ > | /\___ |
// /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ >
// \/ \/ \//_____/ \/
// ______________________ ______________________
// T H E W A R B E G I N S
// Stratagus - A free fantasy real time strategy game engine
//
2005-09-17 19:51:04 -06:00
/**@name netdriver.h - Net driver header. */
2005-04-03 10:07:40 -06:00
//
2005-04-05 19:16:49 -06:00
// (c) Copyright 2005 by Edward Haase and Jimmy Salmon
2005-04-03 10:07:40 -06:00
//
// 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; only version 2 of the License.
//
// 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.
2005-04-03 10:15:33 -06:00
//
2005-04-03 10:07:40 -06:00
#ifndef __NETDRIVER_H__
#define __NETDRIVER_H__
//@{
/*----------------------------------------------------------------------------
-- Includes
----------------------------------------------------------------------------*/
#include <time.h>
2005-04-05 19:16:49 -06:00
#include "net_lowlevel.h"
2005-04-03 10:07:40 -06:00
/*----------------------------------------------------------------------------
-- Defines
----------------------------------------------------------------------------*/
#define DEFAULT_PORT 7775 // Server port
#define DEFAULT_MAX_CONN 500 // Max Connections
#define DEFAULT_SESSION_TIMEOUT 900 // 15 miniutes
#define DEFAULT_POLLING_DELAY 250 // MS (1000 = 1s)
2005-04-17 12:39:41 -06:00
#define MAX_USERNAME_LENGTH 32
#define MAX_PASSWORD_LENGTH 32
#define MAX_GAMENAME_LENGTH 32
#define MAX_VERSION_LENGTH 8
2005-04-03 10:07:40 -06:00
/*----------------------------------------------------------------------------
-- Declarations
----------------------------------------------------------------------------*/
2005-09-25 10:32:15 -06:00
class GameData;
2005-04-17 12:39:41 -06:00
2005-04-03 10:07:40 -06:00
/**
** Global server variables.
*/
2005-09-25 10:32:15 -06:00
class ServerStruct {
public:
ServerStruct() : Port(0), MaxConnections(0), IdleTimeout(0),
PollingDelay(0) {}
2005-04-03 10:07:40 -06:00
int Port;
int MaxConnections;
int IdleTimeout;
int PollingDelay;
2005-09-25 10:32:15 -06:00
};
2005-04-03 10:07:40 -06:00
extern ServerStruct Server;
/**
** Session data
**
** One per connection.
*/
2005-09-25 10:32:15 -06:00
class Session {
public:
Session() : Next(NULL), Prev(NULL), Idle(0), Sock(0), Game(NULL)
{
Buffer[0] = '\0';
AddrData.Host = 0;
AddrData.IPStr[0] = '\0';
AddrData.Port = 0;
UserData.Name[0] = '\0';
UserData.GameName[0] = '\0';
UserData.Version[0] = '\0';
UserData.LoggedIn = 0;
}
Session *Next;
Session *Prev;
2005-04-03 10:07:40 -06:00
2005-04-17 12:39:41 -06:00
char Buffer[1024];
2005-04-03 10:07:40 -06:00
time_t Idle;
2005-09-25 10:32:15 -06:00
Socket Sock;
2005-04-03 10:07:40 -06:00
struct {
2005-04-05 19:16:49 -06:00
unsigned long Host;
2005-04-03 10:07:40 -06:00
char IPStr[16];
int Port;
} AddrData; /// Remote address data.
struct {
2005-04-17 12:39:41 -06:00
char Name[MAX_USERNAME_LENGTH + 1];
char GameName[MAX_GAMENAME_LENGTH + 1];
char Version[MAX_VERSION_LENGTH + 1];
int LoggedIn;
2005-04-03 10:07:40 -06:00
} UserData; /// Specific user data.
2005-09-25 10:32:15 -06:00
GameData *Game;
};
2005-04-03 10:07:40 -06:00
/**
** Global session tracking.
*/
2005-09-25 10:32:15 -06:00
class SessionPool {
public:
SessionPool() : First(NULL), Last(NULL), Count(0), Sockets(NULL) {}
Session *First;
Session *Last;
2005-04-03 10:07:40 -06:00
int Count;
2005-09-25 10:32:15 -06:00
SocketSet *Sockets;
};
2005-04-03 10:07:40 -06:00
/// external reference to session tracking.
2005-09-25 10:32:15 -06:00
extern SessionPool *Pool;
2005-04-03 10:07:40 -06:00
/*----------------------------------------------------------------------------
-- Functions
----------------------------------------------------------------------------*/
extern void Send(Session *session, const char *msg);
2005-04-17 12:39:41 -06:00
extern int ServerInit(int port);
extern void ServerQuit(void);
2005-04-03 10:07:40 -06:00
extern int UpdateSessions(void);
//@}
#endif // __NETDRIVER_H__