_________ __                 __
        /   _____//  |_____________ _/  |______     ____  __ __  ______
        \_____  \\   __\_  __ \__  \\   __\__  \   / ___\|  |  \/  ___/
        /        \|  |  |  | \// __ \|  |  / __ \_/ /_/  >  |  /\___ \
       /_______  /|__|  |__|  (____  /__| (____  /\___  /|____//____  >
               \/                  \/          \//_____/            \/
    ______________________                           ______________________
                          T H E   W A R   B E G I N S
                   Stratagus - A free fantasy real time strategy game engine

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
netdriver.h
Go to the documentation of this file.
1 // _________ __ __
2 // / _____// |_____________ _/ |______ ____ __ __ ______
3 // \_____ \\ __\_ __ \__ \\ __\__ \ / ___\| | \/ ___/
4 // / \| | | | \// __ \| | / __ \_/ /_/ > | /\___ |
5 // /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ >
6 // \/ \/ \//_____/ \/
7 // ______________________ ______________________
8 // T H E W A R B E G I N S
9 // Stratagus - A free fantasy real time strategy game engine
10 //
12 //
13 // (c) Copyright 2005 by Edward Haase and Jimmy Salmon
14 //
15 // This program is free software; you can redistribute it and/or modify
16 // it under the terms of the GNU General Public License as published by
17 // the Free Software Foundation; only version 2 of the License.
18 //
19 // This program is distributed in the hope that it will be useful,
20 // but WITHOUT ANY WARRANTY; without even the implied warranty of
21 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 // GNU General Public License for more details.
23 //
24 // You should have received a copy of the GNU General Public License
25 // along with this program; if not, write to the Free Software
26 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
27 // 02111-1307, USA.
28 //
29 
30 #ifndef __NETDRIVER_H__
31 #define __NETDRIVER_H__
32 
34 
35 /*----------------------------------------------------------------------------
36 -- Includes
37 ----------------------------------------------------------------------------*/
38 
39 #include <time.h>
40 #include "net_lowlevel.h"
41 
42 /*----------------------------------------------------------------------------
43 -- Defines
44 ----------------------------------------------------------------------------*/
45 
46 #define DEFAULT_PORT 7775 // Server port
47 #define DEFAULT_MAX_CONN 500 // Max Connections
48 #define DEFAULT_SESSION_TIMEOUT 900 // 15 miniutes
49 #define DEFAULT_POLLING_DELAY 250 // MS (1000 = 1s)
50 
51 #define MAX_USERNAME_LENGTH 32
52 #define MAX_PASSWORD_LENGTH 32
53 
54 #define MAX_GAMENAME_LENGTH 32
55 #define MAX_VERSION_LENGTH 8
56 
57 /*----------------------------------------------------------------------------
58 -- Declarations
59 ----------------------------------------------------------------------------*/
60 
61 class GameData;
62 
66 class ServerStruct {
67 public:
69  PollingDelay(0) {}
70 
71  int Port;
75 };
76 
77 extern ServerStruct Server;
78 
84 class Session {
85 public:
86  Session() : Next(NULL), Prev(NULL), Idle(0), Sock(0), Game(NULL)
87  {
88  Buffer[0] = '\0';
89  AddrData.Host = 0;
90  AddrData.IPStr[0] = '\0';
91  AddrData.Port = 0;
92  UserData.Name[0] = '\0';
93  UserData.GameName[0] = '\0';
94  UserData.Version[0] = '\0';
95  UserData.LoggedIn = 0;
96  }
97 
100 
101  char Buffer[1024];
102  time_t Idle;
103 
105 
106  struct {
107  unsigned long Host;
108  char IPStr[16];
109  int Port;
110  } AddrData;
111 
112  struct {
116  int LoggedIn;
117  } UserData;
118 
120 };
121 
125 class SessionPool {
126 public:
127  SessionPool() : First(NULL), Last(NULL), Count(0), Sockets(NULL) {}
128 
131  int Count;
132 
134 };
135 
137 extern SessionPool *Pool;
138 
139 /*----------------------------------------------------------------------------
140 -- Functions
141 ----------------------------------------------------------------------------*/
142 
143 extern void Send(Session *session, const char *msg);
144 
145 extern int ServerInit(int port);
146 extern void ServerQuit(void);
147 extern int UpdateSessions(void);
148 
150 
151 #endif // __NETDRIVER_H__
int PollingDelay
Definition: netdriver.h:74
Socket Sock
Definition: netdriver.h:104
Session * First
Definition: netdriver.h:129
Session * Prev
Definition: netdriver.h:99
#define MAX_GAMENAME_LENGTH
Definition: netdriver.h:54
char GameName[MAX_GAMENAME_LENGTH+1]
Definition: netdriver.h:114
Definition: netdriver.h:66
ServerStruct()
Definition: netdriver.h:68
#define MAX_VERSION_LENGTH
Definition: netdriver.h:55
time_t Idle
Definition: netdriver.h:102
int Port
Definition: netdriver.h:109
int ServerInit(int port)
Definition: netdriver.cpp:121
SessionPool()
Definition: netdriver.h:127
void Send(Session *session, const char *msg)
Definition: netdriver.cpp:109
void ServerQuit(void)
Definition: netdriver.cpp:171
Session()
Definition: netdriver.h:86
GameData * Game
Specific user data.
Definition: netdriver.h:119
SessionPool * Pool
external reference to session tracking.
Definition: netdriver.cpp:96
char Name[MAX_USERNAME_LENGTH+1]
Definition: netdriver.h:113
unsigned long Host
Definition: netdriver.h:107
char Buffer[1024]
Definition: netdriver.h:101
int UpdateSessions(void)
Definition: netdriver.cpp:311
SocketSet * Sockets
Definition: netdriver.h:133
Session * Next
Definition: netdriver.h:98
Definition: netdriver.h:125
int Port
Definition: netdriver.h:71
int Count
Definition: netdriver.h:131
char Version[MAX_VERSION_LENGTH+1]
Definition: netdriver.h:115
Definition: netdriver.h:84
int LoggedIn
Definition: netdriver.h:116
char IPStr[16]
Definition: netdriver.h:108
#define MAX_USERNAME_LENGTH
Definition: netdriver.h:51
int MaxConnections
Definition: netdriver.h:72
ServerStruct Server
Definition: netdriver.cpp:97
Definition: games.h:49
int IdleTimeout
Definition: netdriver.h:73
SOCKET Socket
Definition: net_lowlevel.h:75
Definition: net_lowlevel.h:84
Session * Last
Definition: netdriver.h:130
struct Session::@53 UserData
Remote address data.
struct Session::@52 AddrData
(C) Copyright 1998-2012 by The Stratagus Project under the GNU General Public License.
All trademarks and copyrights on this page are owned by their respective owners.