~ubuntu-branches/debian/squeeze/openttd/squeeze

« back to all changes in this revision

Viewing changes to src/network/core/tcp_game.h

  • Committer: Bazaar Package Importer
  • Author(s): Jordi Mallach, Matthijs Kooijman, Jordi Mallach
  • Date: 2009-04-15 18:22:10 UTC
  • mfrom: (1.1.6 upstream) (2.1.3 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090415182210-22ktb8kdbp2tf3bm
[ Matthijs Kooijman ]
* New upstream release.
* Remove Debian specific desktop file, upstream provides one now. 
* Add debian/watch file.

[ Jordi Mallach ]
* Bump Standards-Version to 3.8.1, with no changes required.
* Move to debhelper compat 7. Bump Build-Depends accordingly.
* Use dh_prep.
* Add "set -e" to config script.
* Remove a few extra doc files that get installed by upstream Makefile.
* Add more complete copyright information.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $Id: tcp_game.h 15903 2009-03-30 23:15:05Z rubidium $ */
 
2
 
 
3
/**
 
4
 * @file tcp_game.h Basic functions to receive and send TCP packets for game purposes.
 
5
 */
 
6
 
 
7
#ifndef NETWORK_CORE_TCP_GAME_H
 
8
#define NETWORK_CORE_TCP_GAME_H
 
9
 
 
10
#ifdef ENABLE_NETWORK
 
11
 
 
12
#include "os_abstraction.h"
 
13
#include "tcp.h"
 
14
#include "packet.h"
 
15
 
 
16
/**
 
17
 * Enum with all types of UDP packets.
 
18
 * The order of the first 4 packets MUST not be changed, as
 
19
 * it protects old clients from joining newer servers
 
20
 * (because SERVER_ERROR is the respond to a wrong revision)
 
21
 */
 
22
enum {
 
23
        PACKET_SERVER_FULL,
 
24
        PACKET_SERVER_BANNED,
 
25
        PACKET_CLIENT_JOIN,
 
26
        PACKET_SERVER_ERROR,
 
27
        PACKET_CLIENT_COMPANY_INFO,
 
28
        PACKET_SERVER_COMPANY_INFO,
 
29
        PACKET_SERVER_CLIENT_INFO,
 
30
        PACKET_SERVER_NEED_PASSWORD,
 
31
        PACKET_CLIENT_PASSWORD,
 
32
        PACKET_SERVER_WELCOME,
 
33
        PACKET_CLIENT_GETMAP,
 
34
        PACKET_SERVER_WAIT,
 
35
        PACKET_SERVER_MAP,
 
36
        PACKET_CLIENT_MAP_OK,
 
37
        PACKET_SERVER_JOIN,
 
38
        PACKET_SERVER_FRAME,
 
39
        PACKET_SERVER_SYNC,
 
40
        PACKET_CLIENT_ACK,
 
41
        PACKET_CLIENT_COMMAND,
 
42
        PACKET_SERVER_COMMAND,
 
43
        PACKET_CLIENT_CHAT,
 
44
        PACKET_SERVER_CHAT,
 
45
        PACKET_CLIENT_SET_PASSWORD,
 
46
        PACKET_CLIENT_SET_NAME,
 
47
        PACKET_CLIENT_QUIT,
 
48
        PACKET_CLIENT_ERROR,
 
49
        PACKET_SERVER_QUIT,
 
50
        PACKET_SERVER_ERROR_QUIT,
 
51
        PACKET_SERVER_SHUTDOWN,
 
52
        PACKET_SERVER_NEWGAME,
 
53
        PACKET_SERVER_RCON,
 
54
        PACKET_CLIENT_RCON,
 
55
        PACKET_SERVER_CHECK_NEWGRFS,
 
56
        PACKET_CLIENT_NEWGRFS_CHECKED,
 
57
        PACKET_SERVER_MOVE,
 
58
        PACKET_CLIENT_MOVE,
 
59
        PACKET_SERVER_COMPANY_UPDATE,
 
60
        PACKET_SERVER_CONFIG_UPDATE,
 
61
        PACKET_END                   ///< Must ALWAYS be on the end of this list!! (period)
 
62
};
 
63
 
 
64
/** Packet that wraps a command */
 
65
struct CommandPacket;
 
66
 
 
67
/** Status of a client */
 
68
enum ClientStatus {
 
69
        STATUS_INACTIVE,   ///< The client is not connected nor active
 
70
        STATUS_AUTHORIZING,///< The client is authorizing
 
71
        STATUS_AUTH,       ///< The client is authorized
 
72
        STATUS_MAP_WAIT,   ///< The client is waiting as someone else is downloading the map
 
73
        STATUS_MAP,        ///< The client is downloading the map
 
74
        STATUS_DONE_MAP,   ///< The client has downloaded the map
 
75
        STATUS_PRE_ACTIVE, ///< The client is catching up the delayed frames
 
76
        STATUS_ACTIVE,     ///< The client is active within in the game
 
77
};
 
78
 
 
79
 
 
80
class NetworkClientSocket;
 
81
DECLARE_OLD_POOL(NetworkClientSocket, NetworkClientSocket, NCI_BITS_PER_POOL_BLOCK, MAX_CLIENT_SLOTS >> NCI_BITS_PER_POOL_BLOCK);
 
82
 
 
83
/** Base socket handler for all TCP sockets */
 
84
class NetworkClientSocket : public PoolItem<NetworkClientSocket, ClientIndex, &_NetworkClientSocket_pool>, public NetworkTCPSocketHandler {
 
85
/* TODO: rewrite into a proper class */
 
86
private:
 
87
        NetworkClientInfo *info;  ///< Client info related to this socket
 
88
public:
 
89
        ClientID client_id;       ///< Client identifier
 
90
        uint32 last_frame;        ///< Last frame we have executed
 
91
        uint32 last_frame_server; ///< Last frame the server has executed
 
92
        byte lag_test;            ///< Byte used for lag-testing the client
 
93
 
 
94
        ClientStatus status;      ///< Status of this client
 
95
 
 
96
        CommandPacket *command_queue; ///< The command-queue awaiting delivery
 
97
 
 
98
        NetworkRecvStatus CloseConnection();
 
99
 
 
100
        NetworkClientSocket(ClientID client_id = INVALID_CLIENT_ID);
 
101
        ~NetworkClientSocket();
 
102
 
 
103
        inline bool IsValid() const { return this->IsConnected(); }
 
104
        inline void SetInfo(NetworkClientInfo *info) { assert(info != NULL && this->info == NULL); this->info = info; }
 
105
        inline NetworkClientInfo *GetInfo() const { return this->info; }
 
106
 
 
107
        const char *Recv_Command(Packet *p, CommandPacket *cp);
 
108
        void Send_Command(Packet *p, const CommandPacket *cp);
 
109
};
 
110
 
 
111
static inline bool IsValidNetworkClientSocketIndex(ClientIndex index)
 
112
{
 
113
        return (uint)index < GetNetworkClientSocketPoolSize() && GetNetworkClientSocket(index)->IsValid();
 
114
}
 
115
 
 
116
#define FOR_ALL_CLIENT_SOCKETS_FROM(d, start) for (d = GetNetworkClientSocket(start); d != NULL; d = (d->index + 1U < GetNetworkClientSocketPoolSize()) ? GetNetworkClientSocket(d->index + 1U) : NULL) if (d->IsValid())
 
117
#define FOR_ALL_CLIENT_SOCKETS(d) FOR_ALL_CLIENT_SOCKETS_FROM(d, 0)
 
118
 
 
119
#endif /* ENABLE_NETWORK */
 
120
 
 
121
#endif /* NETWORK_CORE_TCP_GAME_H */