OpenTTD
tcp_admin.cpp
Go to the documentation of this file.
1 /* $Id: tcp_admin.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_internal.h"
19 #include "tcp_admin.h"
20 #include "../../debug.h"
21 
22 #include "../../safeguards.h"
23 
24 /* Make sure that these enums match. */
25 assert_compile((int)CRR_MANUAL == (int)ADMIN_CRR_MANUAL);
26 assert_compile((int)CRR_AUTOCLEAN == (int)ADMIN_CRR_AUTOCLEAN);
27 assert_compile((int)CRR_BANKRUPT == (int)ADMIN_CRR_BANKRUPT);
28 assert_compile((int)CRR_END == (int)ADMIN_CRR_END);
29 
35 {
36  this->sock = s;
37  this->admin_name[0] = '\0';
38  this->admin_version[0] = '\0';
39 }
40 
41 NetworkAdminSocketHandler::~NetworkAdminSocketHandler()
42 {
43 }
44 
46 {
47  delete this;
49 }
50 
57 {
59 
60  switch (this->HasClientQuit() ? INVALID_ADMIN_PACKET : type) {
61  case ADMIN_PACKET_ADMIN_JOIN: return this->Receive_ADMIN_JOIN(p);
62  case ADMIN_PACKET_ADMIN_QUIT: return this->Receive_ADMIN_QUIT(p);
64  case ADMIN_PACKET_ADMIN_POLL: return this->Receive_ADMIN_POLL(p);
65  case ADMIN_PACKET_ADMIN_CHAT: return this->Receive_ADMIN_CHAT(p);
66  case ADMIN_PACKET_ADMIN_RCON: return this->Receive_ADMIN_RCON(p);
68  case ADMIN_PACKET_ADMIN_PING: return this->Receive_ADMIN_PING(p);
69 
70  case ADMIN_PACKET_SERVER_FULL: return this->Receive_SERVER_FULL(p);
72  case ADMIN_PACKET_SERVER_ERROR: return this->Receive_SERVER_ERROR(p);
77 
78  case ADMIN_PACKET_SERVER_DATE: return this->Receive_SERVER_DATE(p);
90  case ADMIN_PACKET_SERVER_CHAT: return this->Receive_SERVER_CHAT(p);
91  case ADMIN_PACKET_SERVER_RCON: return this->Receive_SERVER_RCON(p);
96  case ADMIN_PACKET_SERVER_PONG: return this->Receive_SERVER_PONG(p);
97 
98  default:
99  if (this->HasClientQuit()) {
100  DEBUG(net, 0, "[tcp/admin] received invalid packet type %d from '%s' (%s)", type, this->admin_name, this->admin_version);
101  } else {
102  DEBUG(net, 0, "[tcp/admin] received illegal packet from '%s' (%s)", this->admin_name, this->admin_version);
103  }
104 
105  this->CloseConnection();
107  }
108 }
109 
118 {
119  Packet *p;
120  while ((p = this->ReceivePacket()) != NULL) {
121  NetworkRecvStatus res = this->HandlePacket(p);
122  if (res != NETWORK_RECV_STATUS_OKAY) return res;
123  }
124 
126 }
127 
134 {
135  DEBUG(net, 0, "[tcp/admin] received illegal packet type %d from admin %s (%s)", type, this->admin_name, this->admin_version);
137 }
138 
147 
155 
175 
176 #endif /* ENABLE_NETWORK */