OpenTTD
network_server.h
Go to the documentation of this file.
1 /* $Id: network_server.h 26576 2014-05-11 12:52:21Z 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 
12 #ifndef NETWORK_SERVER_H
13 #define NETWORK_SERVER_H
14 
15 #ifdef ENABLE_NETWORK
16 
17 #include "network_internal.h"
18 #include "core/tcp_listen.h"
19 #include "../thread/thread.h"
20 
27 
29 class ServerNetworkGameSocketHandler : public NetworkClientSocketPool::PoolItem<&_networkclientsocket_pool>, public NetworkGameSocketHandler, public TCPListenHandler<ServerNetworkGameSocketHandler, PACKET_SERVER_FULL, PACKET_SERVER_BANNED> {
30 protected:
47 
54 
55 public:
57  enum ClientStatus {
69  };
70 
71  byte lag_test;
72  byte last_token;
77 
80 
83 
84  virtual Packet *ReceivePacket();
86  void GetClientName(char *client_name, const char *last) const;
87 
93  NetworkRecvStatus SendRConResult(uint16 colour, const char *command);
95 
98  NetworkRecvStatus SendChat(NetworkAction action, ClientID client_id, bool self_send, const char *msg, int64 data);
105 
106  static void Send();
107  static void AcceptConnection(SOCKET s, const NetworkAddress &address);
108  static bool AllowConnection();
109 
114  static const char *GetName()
115  {
116  return "server";
117  }
118 
119  const char *GetClientIP();
120 
122 };
123 
124 void NetworkServer_Tick(bool send_frame);
125 void NetworkServerSetCompanyPassword(CompanyID company_id, const char *password, bool already_hashed = true);
126 void NetworkServerUpdateCompanyPassworded(CompanyID company_id, bool passworded);
127 
133 #define FOR_ALL_CLIENT_SOCKETS_FROM(var, start) FOR_ALL_ITEMS_FROM(NetworkClientSocket, clientsocket_index, var, start)
134 
139 #define FOR_ALL_CLIENT_SOCKETS(var) FOR_ALL_CLIENT_SOCKETS_FROM(var, 0)
140 
141 #else /* ENABLE_NETWORK */
142 /* Network function stubs when networking is disabled */
143 
144 static inline void NetworkServerMonthlyLoop() {}
145 static inline void NetworkServerYearlyLoop() {}
146 
147 #endif /* ENABLE_NETWORK */
148 
149 #endif /* NETWORK_SERVER_H */