Skip to content

Commit

Permalink
(svn r20963) -Add: stubs for a remote administration connection
Browse files Browse the repository at this point in the history
  • Loading branch information
rubidium42 committed Oct 17, 2010
1 parent 12a7e2f commit 33ed4dd
Show file tree
Hide file tree
Showing 13 changed files with 584 additions and 0 deletions.
4 changes: 4 additions & 0 deletions projects/openttd_vs100.vcxproj
Expand Up @@ -331,6 +331,7 @@
<ClCompile Include="..\src\mixer.cpp" />
<ClCompile Include="..\src\music.cpp" />
<ClCompile Include="..\src\network\network.cpp" />
<ClCompile Include="..\src\network\network_admin.cpp" />
<ClCompile Include="..\src\network\network_client.cpp" />
<ClCompile Include="..\src\network\network_command.cpp" />
<ClCompile Include="..\src\network\network_content.cpp" />
Expand Down Expand Up @@ -457,6 +458,7 @@
<ClInclude Include="..\src\map_type.h" />
<ClInclude Include="..\src\mixer.h" />
<ClInclude Include="..\src\network\network.h" />
<ClInclude Include="..\src\network\network_admin.h" />
<ClInclude Include="..\src\network\network_base.h" />
<ClInclude Include="..\src\network\network_client.h" />
<ClInclude Include="..\src\network\network_content.h" />
Expand Down Expand Up @@ -1039,6 +1041,8 @@
<ClInclude Include="..\src\network\core\tcp_content.h" />
<ClCompile Include="..\src\network\core\tcp_game.cpp" />
<ClInclude Include="..\src\network\core\tcp_game.h" />
<ClCompile Include="..\src\network\core\tcp_admin.cpp" />
<ClInclude Include="..\src\network\core\tcp_admin.h" />
<ClCompile Include="..\src\network\core\tcp_http.cpp" />
<ClInclude Include="..\src\network\core\tcp_http.h" />
<ClInclude Include="..\src\network\core\tcp_listen.h" />
Expand Down
12 changes: 12 additions & 0 deletions projects/openttd_vs100.vcxproj.filters
Expand Up @@ -213,6 +213,9 @@
<ClCompile Include="..\src\network\network.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\src\network\network_admin.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\src\network\network_client.cpp">
<Filter>Source Files</Filter>
</ClCompile>
Expand Down Expand Up @@ -591,6 +594,9 @@
<ClInclude Include="..\src\network\network.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\src\network\network_admin.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\src\network\network_base.h">
<Filter>Header Files</Filter>
</ClInclude>
Expand Down Expand Up @@ -2337,6 +2343,12 @@
<ClInclude Include="..\src\network\core\tcp_game.h">
<Filter>Network Core</Filter>
</ClInclude>
<ClCompile Include="..\src\network\core\tcp_admin.cpp">
<Filter>Network Core</Filter>
</ClCompile>
<ClInclude Include="..\src\network\core\tcp_admin.h">
<Filter>Network Core</Filter>
</ClInclude>
<ClCompile Include="..\src\network\core\tcp_http.cpp">
<Filter>Network Core</Filter>
</ClCompile>
Expand Down
16 changes: 16 additions & 0 deletions projects/openttd_vs80.vcproj
Expand Up @@ -594,6 +594,10 @@
RelativePath=".\..\src\network\network.cpp"
>
</File>
<File
RelativePath=".\..\src\network\network_admin.cpp"
>
</File>
<File
RelativePath=".\..\src\network\network_client.cpp"
>
Expand Down Expand Up @@ -1102,6 +1106,10 @@
RelativePath=".\..\src\network\network.h"
>
</File>
<File
RelativePath=".\..\src\network\network_admin.h"
>
</File>
<File
RelativePath=".\..\src\network\network_base.h"
>
Expand Down Expand Up @@ -3510,6 +3518,14 @@
RelativePath=".\..\src\network\core\tcp_game.h"
>
</File>
<File
RelativePath=".\..\src\network\core\tcp_admin.cpp"
>
</File>
<File
RelativePath=".\..\src\network\core\tcp_admin.h"
>
</File>
<File
RelativePath=".\..\src\network\core\tcp_http.cpp"
>
Expand Down
16 changes: 16 additions & 0 deletions projects/openttd_vs90.vcproj
Expand Up @@ -591,6 +591,10 @@
RelativePath=".\..\src\network\network.cpp"
>
</File>
<File
RelativePath=".\..\src\network\network_admin.cpp"
>
</File>
<File
RelativePath=".\..\src\network\network_client.cpp"
>
Expand Down Expand Up @@ -1099,6 +1103,10 @@
RelativePath=".\..\src\network\network.h"
>
</File>
<File
RelativePath=".\..\src\network\network_admin.h"
>
</File>
<File
RelativePath=".\..\src\network\network_base.h"
>
Expand Down Expand Up @@ -3507,6 +3515,14 @@
RelativePath=".\..\src\network\core\tcp_game.h"
>
</File>
<File
RelativePath=".\..\src\network\core\tcp_admin.cpp"
>
</File>
<File
RelativePath=".\..\src\network\core\tcp_admin.h"
>
</File>
<File
RelativePath=".\..\src\network\core\tcp_http.cpp"
>
Expand Down
4 changes: 4 additions & 0 deletions source.list
Expand Up @@ -39,6 +39,7 @@ misc.cpp
mixer.cpp
music.cpp
network/network.cpp
network/network_admin.cpp
network/network_client.cpp
network/network_command.cpp
network/network_content.cpp
Expand Down Expand Up @@ -190,6 +191,7 @@ map_func.h
map_type.h
mixer.h
network/network.h
network/network_admin.h
network/network_base.h
network/network_client.h
network/network_content.h
Expand Down Expand Up @@ -834,6 +836,8 @@ network/core/tcp_content.cpp
network/core/tcp_content.h
network/core/tcp_game.cpp
network/core/tcp_game.h
network/core/tcp_admin.cpp
network/core/tcp_admin.h
network/core/tcp_http.cpp
network/core/tcp_http.h
network/core/tcp_listen.h
Expand Down
2 changes: 2 additions & 0 deletions src/network/core/config.h
Expand Up @@ -29,10 +29,12 @@ static const uint16 NETWORK_MASTER_SERVER_PORT = 3978; ///< The default port
static const uint16 NETWORK_CONTENT_SERVER_PORT = 3978; ///< The default port of the content server (TCP)
static const uint16 NETWORK_CONTENT_MIRROR_PORT = 80; ///< The default port of the content mirror (TCP)
static const uint16 NETWORK_DEFAULT_PORT = 3979; ///< The default port of the game server (TCP & UDP)
static const uint16 NETWORK_ADMIN_PORT = 3977; ///< The default port for admin network
static const uint16 NETWORK_DEFAULT_DEBUGLOG_PORT = 3982; ///< The default port debug-log is sent too (TCP)

static const uint16 SEND_MTU = 1460; ///< Number of bytes we can pack in a single packet

static const byte NETWORK_GAME_ADMIN_VERSION = 1; ///< What version of the admin network do we use?
static const byte NETWORK_GAME_INFO_VERSION = 4; ///< What version of game-info do we use?
static const byte NETWORK_COMPANY_INFO_VERSION = 6; ///< What version of company info is this?
static const byte NETWORK_MASTER_SERVER_VERSION = 2; ///< What version of master-server-protocol do we use?
Expand Down
119 changes: 119 additions & 0 deletions src/network/core/tcp_admin.cpp
@@ -0,0 +1,119 @@
/* $Id$ */

/*
* This file is part of OpenTTD.
* 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.
* 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.
* 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/>.
*/

/**
* @file tcp_admin.cpp Basic functions to receive and send TCP packets to and from the admin network.
*/

#ifdef ENABLE_NETWORK

#include "../../stdafx.h"

#include "../network_internal.h"
#include "tcp_admin.h"
#include "../../debug.h"

NetworkAdminSocketHandler::NetworkAdminSocketHandler(SOCKET s)
{
this->sock = s;
}

NetworkAdminSocketHandler::~NetworkAdminSocketHandler()
{
}

NetworkRecvStatus NetworkAdminSocketHandler::CloseConnection(bool error)
{
delete this;
return NETWORK_RECV_STATUS_CONN_LOST;
}

/**
* Defines a simple (switch) case for each network packet.
* @param type the packet type to create the case for.
*/
#define ADMIN_COMMAND(type) case type: return this->NetworkPacketReceive_ ## type ## _command(p); break;

/**
* Handle the given packet, i.e. pass it to the right parser receive command.
* @param p the packet to handle.
* @return #NetworkRecvStatus of handling.
*/
NetworkRecvStatus NetworkAdminSocketHandler::HandlePacket(Packet *p)
{
PacketAdminType type = (PacketAdminType)p->Recv_uint8();

switch (this->HasClientQuit() ? INVALID_ADMIN_PACKET : type) {
ADMIN_COMMAND(ADMIN_PACKET_ADMIN_JOIN)
ADMIN_COMMAND(ADMIN_PACKET_ADMIN_QUIT)

ADMIN_COMMAND(ADMIN_PACKET_SERVER_FULL)
ADMIN_COMMAND(ADMIN_PACKET_SERVER_BANNED)
ADMIN_COMMAND(ADMIN_PACKET_SERVER_ERROR)
ADMIN_COMMAND(ADMIN_PACKET_SERVER_PROTOCOL)
ADMIN_COMMAND(ADMIN_PACKET_SERVER_WELCOME)
ADMIN_COMMAND(ADMIN_PACKET_SERVER_NEWGAME)
ADMIN_COMMAND(ADMIN_PACKET_SERVER_SHUTDOWN)

default:
if (this->HasClientQuit()) {
DEBUG(net, 0, "[tcp/admin] received invalid packet type %d from '%s' (%s)", type, this->admin_name, this->admin_version);
} else {
DEBUG(net, 0, "[tcp/admin] received illegal packet from '%s' (%s)", this->admin_name, this->admin_version);
}

this->CloseConnection();
return NETWORK_RECV_STATUS_MALFORMED_PACKET;
}
}

/**
* Do the actual receiving of packets.
* As long as HandlePacket returns OKAY packets are handled. Upon
* failure, or no more packets to process the last result of
* HandlePacket is returned.
* @return #NetworkRecvStatus of the last handled packet.
*/
NetworkRecvStatus NetworkAdminSocketHandler::Recv_Packets()
{
Packet *p;
while ((p = this->Recv_Packet()) != NULL) {
NetworkRecvStatus res = HandlePacket(p);
if (res != NETWORK_RECV_STATUS_OKAY) return res;
}

return NETWORK_RECV_STATUS_OKAY;
}

/**
* Create stub implementations for all receive commands that only
* show a warning that the given command is not available for the
* socket where the packet came from.
* @param type the packet type to create the stub for.
*/
#define DEFINE_UNAVAILABLE_ADMIN_RECEIVE_COMMAND(type) \
NetworkRecvStatus NetworkAdminSocketHandler::NetworkPacketReceive_## type ##_command(Packet *p) \
{ \
DEBUG(net, 0, "[tcp/admin] received illegal packet type %d from admin %s (%s)", \
type, this->admin_name, this->admin_version); \
return NETWORK_RECV_STATUS_MALFORMED_PACKET; \
}

DEFINE_UNAVAILABLE_ADMIN_RECEIVE_COMMAND(ADMIN_PACKET_ADMIN_JOIN)
DEFINE_UNAVAILABLE_ADMIN_RECEIVE_COMMAND(ADMIN_PACKET_ADMIN_QUIT)

DEFINE_UNAVAILABLE_ADMIN_RECEIVE_COMMAND(ADMIN_PACKET_SERVER_FULL)
DEFINE_UNAVAILABLE_ADMIN_RECEIVE_COMMAND(ADMIN_PACKET_SERVER_BANNED)
DEFINE_UNAVAILABLE_ADMIN_RECEIVE_COMMAND(ADMIN_PACKET_SERVER_ERROR)
DEFINE_UNAVAILABLE_ADMIN_RECEIVE_COMMAND(ADMIN_PACKET_SERVER_PROTOCOL)
DEFINE_UNAVAILABLE_ADMIN_RECEIVE_COMMAND(ADMIN_PACKET_SERVER_WELCOME)
DEFINE_UNAVAILABLE_ADMIN_RECEIVE_COMMAND(ADMIN_PACKET_SERVER_NEWGAME)
DEFINE_UNAVAILABLE_ADMIN_RECEIVE_COMMAND(ADMIN_PACKET_SERVER_SHUTDOWN)

#endif /* ENABLE_NETWORK */

0 comments on commit 33ed4dd

Please sign in to comment.