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

« back to all changes in this revision

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

  • 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.cpp 15903 2009-03-30 23:15:05Z rubidium $ */
 
2
 
 
3
/**
 
4
 * @file tcp_game.cpp Basic functions to receive and send TCP packets for game purposes.
 
5
 */
 
6
 
 
7
#ifdef ENABLE_NETWORK
 
8
 
 
9
#include "../../stdafx.h"
 
10
#include "../../openttd.h"
 
11
#include "../../variables.h"
 
12
 
 
13
#include "../network_internal.h"
 
14
#include "packet.h"
 
15
#include "tcp_game.h"
 
16
 
 
17
#include "table/strings.h"
 
18
#include "../../oldpool_func.h"
 
19
 
 
20
/** Make very sure the preconditions given in network_type.h are actually followed */
 
21
assert_compile(MAX_CLIENT_SLOTS == (MAX_CLIENT_SLOTS >> NCI_BITS_PER_POOL_BLOCK) << NCI_BITS_PER_POOL_BLOCK);
 
22
assert_compile(MAX_CLIENT_SLOTS > MAX_CLIENTS);
 
23
 
 
24
typedef ClientIndex NetworkClientSocketID;
 
25
DEFINE_OLD_POOL_GENERIC(NetworkClientSocket, NetworkClientSocket);
 
26
 
 
27
NetworkClientSocket::NetworkClientSocket(ClientID client_id)
 
28
{
 
29
        this->client_id         = client_id;
 
30
        this->status            = STATUS_INACTIVE;
 
31
}
 
32
 
 
33
NetworkClientSocket::~NetworkClientSocket()
 
34
{
 
35
        while (this->command_queue != NULL) {
 
36
                CommandPacket *p = this->command_queue->next;
 
37
                free(this->command_queue);
 
38
                this->command_queue = p;
 
39
        }
 
40
 
 
41
        this->client_id = INVALID_CLIENT_ID;
 
42
        this->status = STATUS_INACTIVE;
 
43
}
 
44
 
 
45
/**
 
46
 * Functions to help NetworkRecv_Packet/NetworkSend_Packet a bit
 
47
 *  A socket can make errors. When that happens this handles what to do.
 
48
 * For clients: close connection and drop back to main-menu
 
49
 * For servers: close connection and that is it
 
50
 * @return the new status
 
51
 * TODO: needs to be splitted when using client and server socket packets
 
52
 */
 
53
NetworkRecvStatus NetworkClientSocket::CloseConnection()
 
54
{
 
55
        /* Clients drop back to the main menu */
 
56
        if (!_network_server && _networking) {
 
57
                _switch_mode = SM_MENU;
 
58
                _networking = false;
 
59
                extern StringID _switch_mode_errorstr;
 
60
                _switch_mode_errorstr = STR_NETWORK_ERR_LOSTCONNECTION;
 
61
 
 
62
                return NETWORK_RECV_STATUS_CONN_LOST;
 
63
        }
 
64
 
 
65
        NetworkCloseClient(this);
 
66
        return NETWORK_RECV_STATUS_OKAY;
 
67
}
 
68
 
 
69
#endif /* ENABLE_NETWORK */