OpenTTD
tcp_game.cpp
Go to the documentation of this file.
1 /* $Id: tcp_game.cpp 26482 2014-04-23 20:13:33Z rubidium $ */
2 
3 /*
4  * This file is part of OpenTTD.
5  * OpenTTD 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, version 2.
6  * OpenTTD 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.
7  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
8  */
9 
14 #ifdef ENABLE_NETWORK
15 
16 #include "../../stdafx.h"
17 
18 #include "../network.h"
19 #include "../network_internal.h"
20 #include "../../debug.h"
21 #include "../../error.h"
22 
23 #include "table/strings.h"
24 
25 #include "../../safeguards.h"
26 
32  last_frame(_frame_counter), last_frame_server(_frame_counter), last_packet(_realtime_tick)
33 {
34  this->sock = s;
35 }
36 
45 {
46  /* Clients drop back to the main menu */
47  if (!_network_server && _networking) {
49  _networking = false;
50  ShowErrorMessage(STR_NETWORK_ERROR_LOSTCONNECTION, INVALID_STRING_ID, WL_CRITICAL);
51 
53  }
54 
56 }
57 
58 
65 {
67 
69 
70  switch (this->HasClientQuit() ? PACKET_END : type) {
71  case PACKET_SERVER_FULL: return this->Receive_SERVER_FULL(p);
72  case PACKET_SERVER_BANNED: return this->Receive_SERVER_BANNED(p);
73  case PACKET_CLIENT_JOIN: return this->Receive_CLIENT_JOIN(p);
74  case PACKET_SERVER_ERROR: return this->Receive_SERVER_ERROR(p);
82  case PACKET_SERVER_WELCOME: return this->Receive_SERVER_WELCOME(p);
83  case PACKET_CLIENT_GETMAP: return this->Receive_CLIENT_GETMAP(p);
84  case PACKET_SERVER_WAIT: return this->Receive_SERVER_WAIT(p);
86  case PACKET_SERVER_MAP_SIZE: return this->Receive_SERVER_MAP_SIZE(p);
87  case PACKET_SERVER_MAP_DATA: return this->Receive_SERVER_MAP_DATA(p);
88  case PACKET_SERVER_MAP_DONE: return this->Receive_SERVER_MAP_DONE(p);
89  case PACKET_CLIENT_MAP_OK: return this->Receive_CLIENT_MAP_OK(p);
90  case PACKET_SERVER_JOIN: return this->Receive_SERVER_JOIN(p);
91  case PACKET_SERVER_FRAME: return this->Receive_SERVER_FRAME(p);
92  case PACKET_SERVER_SYNC: return this->Receive_SERVER_SYNC(p);
93  case PACKET_CLIENT_ACK: return this->Receive_CLIENT_ACK(p);
94  case PACKET_CLIENT_COMMAND: return this->Receive_CLIENT_COMMAND(p);
95  case PACKET_SERVER_COMMAND: return this->Receive_SERVER_COMMAND(p);
96  case PACKET_CLIENT_CHAT: return this->Receive_CLIENT_CHAT(p);
97  case PACKET_SERVER_CHAT: return this->Receive_SERVER_CHAT(p);
99  case PACKET_CLIENT_SET_NAME: return this->Receive_CLIENT_SET_NAME(p);
100  case PACKET_CLIENT_QUIT: return this->Receive_CLIENT_QUIT(p);
101  case PACKET_CLIENT_ERROR: return this->Receive_CLIENT_ERROR(p);
102  case PACKET_SERVER_QUIT: return this->Receive_SERVER_QUIT(p);
104  case PACKET_SERVER_SHUTDOWN: return this->Receive_SERVER_SHUTDOWN(p);
105  case PACKET_SERVER_NEWGAME: return this->Receive_SERVER_NEWGAME(p);
106  case PACKET_SERVER_RCON: return this->Receive_SERVER_RCON(p);
107  case PACKET_CLIENT_RCON: return this->Receive_CLIENT_RCON(p);
110  case PACKET_SERVER_MOVE: return this->Receive_SERVER_MOVE(p);
111  case PACKET_CLIENT_MOVE: return this->Receive_CLIENT_MOVE(p);
114 
115  default:
116  this->CloseConnection();
117 
118  if (this->HasClientQuit()) {
119  DEBUG(net, 0, "[tcp/game] received invalid packet type %d from client %d", type, this->client_id);
120  } else {
121  DEBUG(net, 0, "[tcp/game] received illegal packet from client %d", this->client_id);
122  }
124  }
125 }
126 
135 {
136  Packet *p;
137  while ((p = this->ReceivePacket()) != NULL) {
139  delete p;
140  if (res != NETWORK_RECV_STATUS_OKAY) return res;
141  }
142 
144 }
145 
152 {
153  DEBUG(net, 0, "[tcp/game] received illegal packet type %d from client %d", type, this->client_id);
155 }
156 
200 
201 #endif /* ENABLE_NETWORK */