# network_client.h

Go to the documentation of this file.

    00001 /* $Id$ */
    00002
    00003 /*
    00004  * This file is part of OpenTTD.
    00005  * 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.
    00006  * 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.
    00007  * 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/>.
    00008  */
    00009
    00012 #ifndef NETWORK_CLIENT_H
    00013 #define NETWORK_CLIENT_H
    00014
    00015 #ifdef ENABLE_NETWORK
    00016
    00017 #include "network_internal.h"
    00018
    00020 class ClientNetworkGameSocketHandler : public ZeroedMemoryAllocator, public NetworkGameSocketHandler {
    00021 private:
    00022   struct PacketReader *savegame;
    00023   byte token;
    00024
    00026   enum ServerStatus {
    00027     STATUS_INACTIVE,
    00028     STATUS_COMPANY_INFO,
    00029     STATUS_JOIN,
    00030     STATUS_NEWGRFS_CHECK,
    00031     STATUS_AUTH_GAME,
    00032     STATUS_AUTH_COMPANY,
    00033     STATUS_AUTHORIZED,
    00034     STATUS_MAP_WAIT,
    00035     STATUS_MAP,
    00036     STATUS_ACTIVE,
    00037     STATUS_END,
    00038   };
    00039
    00040   ServerStatus status;
    00041
    00042 protected:
    00043   friend void NetworkExecuteLocalCommandQueue();
    00044   friend void NetworkClose(bool close_admins);
    00045   static ClientNetworkGameSocketHandler *my_client;
    00046
    00047   virtual NetworkRecvStatus Receive_SERVER_FULL(Packet *p);
    00048   virtual NetworkRecvStatus Receive_SERVER_BANNED(Packet *p);
    00049   virtual NetworkRecvStatus Receive_SERVER_ERROR(Packet *p);
    00050   virtual NetworkRecvStatus Receive_SERVER_COMPANY_INFO(Packet *p);
    00051   virtual NetworkRecvStatus Receive_SERVER_CLIENT_INFO(Packet *p);
    00052   virtual NetworkRecvStatus Receive_SERVER_NEED_GAME_PASSWORD(Packet *p);
    00053   virtual NetworkRecvStatus Receive_SERVER_NEED_COMPANY_PASSWORD(Packet *p);
    00054   virtual NetworkRecvStatus Receive_SERVER_WELCOME(Packet *p);
    00055   virtual NetworkRecvStatus Receive_SERVER_WAIT(Packet *p);
    00056   virtual NetworkRecvStatus Receive_SERVER_MAP_BEGIN(Packet *p);
    00057   virtual NetworkRecvStatus Receive_SERVER_MAP_SIZE(Packet *p);
    00058   virtual NetworkRecvStatus Receive_SERVER_MAP_DATA(Packet *p);
    00059   virtual NetworkRecvStatus Receive_SERVER_MAP_DONE(Packet *p);
    00060   virtual NetworkRecvStatus Receive_SERVER_JOIN(Packet *p);
    00061   virtual NetworkRecvStatus Receive_SERVER_FRAME(Packet *p);
    00062   virtual NetworkRecvStatus Receive_SERVER_SYNC(Packet *p);
    00063   virtual NetworkRecvStatus Receive_SERVER_COMMAND(Packet *p);
    00064   virtual NetworkRecvStatus Receive_SERVER_CHAT(Packet *p);
    00065   virtual NetworkRecvStatus Receive_SERVER_QUIT(Packet *p);
    00066   virtual NetworkRecvStatus Receive_SERVER_ERROR_QUIT(Packet *p);
    00067   virtual NetworkRecvStatus Receive_SERVER_SHUTDOWN(Packet *p);
    00068   virtual NetworkRecvStatus Receive_SERVER_NEWGAME(Packet *p);
    00069   virtual NetworkRecvStatus Receive_SERVER_RCON(Packet *p);
    00070   virtual NetworkRecvStatus Receive_SERVER_CHECK_NEWGRFS(Packet *p);
    00071   virtual NetworkRecvStatus Receive_SERVER_MOVE(Packet *p);
    00072   virtual NetworkRecvStatus Receive_SERVER_COMPANY_UPDATE(Packet *p);
    00073   virtual NetworkRecvStatus Receive_SERVER_CONFIG_UPDATE(Packet *p);
    00074
    00075   static NetworkRecvStatus SendNewGRFsOk();
    00076   static NetworkRecvStatus SendGetMap();
    00077   static NetworkRecvStatus SendMapOk();
    00078   void CheckConnection();
    00079 public:
    00080   ClientNetworkGameSocketHandler(SOCKET s);
    00081   ~ClientNetworkGameSocketHandler();
    00082
    00083   NetworkRecvStatus CloseConnection(NetworkRecvStatus status);
    00084   void ClientError(NetworkRecvStatus res);
    00085
    00086   static NetworkRecvStatus SendCompanyInformationQuery();
    00087
    00088   static NetworkRecvStatus SendJoin();
    00089   static NetworkRecvStatus SendCommand(const CommandPacket *cp);
    00090   static NetworkRecvStatus SendError(NetworkErrorCode errorno);
    00091   static NetworkRecvStatus SendQuit();
    00092   static NetworkRecvStatus SendAck();
    00093
    00094   static NetworkRecvStatus SendGamePassword(const char *password);
    00095   static NetworkRecvStatus SendCompanyPassword(const char *password);
    00096
    00097   static NetworkRecvStatus SendChat(NetworkAction action, DestType type, int dest, const char *msg, int64 data);
    00098   static NetworkRecvStatus SendSetPassword(const char *password);
    00099   static NetworkRecvStatus SendSetName(const char *name);
    00100   static NetworkRecvStatus SendRCon(const char *password, const char *command);
    00101   static NetworkRecvStatus SendMove(CompanyID company, const char *password);
    00102
    00103   static bool IsConnected();
    00104
    00105   static void Send();
    00106   static bool Receive();
    00107   static bool GameLoop();
    00108 };
    00109
    00111 typedef ClientNetworkGameSocketHandler MyClient;
    00112
    00113 void NetworkClient_Connected();
    00114 void NetworkClientSetCompanyPassword(const char *password);
    00115
    00116 extern CompanyID _network_join_as;
    00117
    00118 extern const char *_network_join_server_password;
    00119 extern const char *_network_join_company_password;
    00120
    00121 #endif /* ENABLE_NETWORK */
    00122
    00123 #endif /* NETWORK_CLIENT_H */