# tcp.h

Go to the documentation of this file.

    00001 /* $Id: tcp.h 11818 2008-01-12 14:10:35Z rubidium $ */
    00002
    00007 #ifndef NETWORK_CORE_TCP_H
    00008 #define NETWORK_CORE_TCP_H
    00009
    00010 #ifdef ENABLE_NETWORK
    00011
    00012 #include "os_abstraction.h"
    00013 #include "core.h"
    00014 #include "packet.h"
    00015 #include "../../tile_type.h"
    00016
    00023 enum {
    00024   PACKET_SERVER_FULL,
    00025   PACKET_SERVER_BANNED,
    00026   PACKET_CLIENT_JOIN,
    00027   PACKET_SERVER_ERROR,
    00028   PACKET_CLIENT_COMPANY_INFO,
    00029   PACKET_SERVER_COMPANY_INFO,
    00030   PACKET_SERVER_CLIENT_INFO,
    00031   PACKET_SERVER_NEED_PASSWORD,
    00032   PACKET_CLIENT_PASSWORD,
    00033   PACKET_SERVER_WELCOME,
    00034   PACKET_CLIENT_GETMAP,
    00035   PACKET_SERVER_WAIT,
    00036   PACKET_SERVER_MAP,
    00037   PACKET_CLIENT_MAP_OK,
    00038   PACKET_SERVER_JOIN,
    00039   PACKET_SERVER_FRAME,
    00040   PACKET_SERVER_SYNC,
    00041   PACKET_CLIENT_ACK,
    00042   PACKET_CLIENT_COMMAND,
    00043   PACKET_SERVER_COMMAND,
    00044   PACKET_CLIENT_CHAT,
    00045   PACKET_SERVER_CHAT,
    00046   PACKET_CLIENT_SET_PASSWORD,
    00047   PACKET_CLIENT_SET_NAME,
    00048   PACKET_CLIENT_QUIT,
    00049   PACKET_CLIENT_ERROR,
    00050   PACKET_SERVER_QUIT,
    00051   PACKET_SERVER_ERROR_QUIT,
    00052   PACKET_SERVER_SHUTDOWN,
    00053   PACKET_SERVER_NEWGAME,
    00054   PACKET_SERVER_RCON,
    00055   PACKET_CLIENT_RCON,
    00056   PACKET_SERVER_CHECK_NEWGRFS,
    00057   PACKET_CLIENT_NEWGRFS_CHECKED,
    00058   PACKET_END
    00059 };
    00060
    00062 struct CommandPacket {
    00063   CommandPacket *next;
    00064   PlayerByte player;
    00065   uint32 cmd;
    00066   uint32 p1;
    00067   uint32 p2;
    00068   TileIndex tile;
    00069   char text[80];
    00070   uint32 frame;
    00071   byte callback;
    00072   bool my_cmd;
    00073 };
    00074
    00076 enum ClientStatus {
    00077   STATUS_INACTIVE,
    00078   STATUS_AUTHORIZING,
    00079   STATUS_AUTH,
    00080   STATUS_MAP_WAIT,
    00081   STATUS_MAP,
    00082   STATUS_DONE_MAP,
    00083   STATUS_PRE_ACTIVE,
    00084   STATUS_ACTIVE,
    00085 };
    00086
    00088 class NetworkTCPSocketHandler : public NetworkSocketHandler {
    00089 /* TODO: rewrite into a proper class */
    00090 private:
    00091   Packet *packet_queue;
    00092   Packet *packet_recv;
    00093 public:
    00094   uint16 index;
    00095   uint32 last_frame;
    00096   uint32 last_frame_server;
    00097   byte lag_test;
    00098
    00099   ClientStatus status;
    00100   bool writable;
    00101
    00102   CommandPacket *command_queue;
    00103
    00104   NetworkRecvStatus CloseConnection();
    00105   void Initialize();
    00106   void Destroy();
    00107
    00108   void Send_Packet(Packet *packet);
    00109   bool Send_Packets();
    00110   bool IsPacketQueueEmpty();
    00111
    00112   Packet *Recv_Packet(NetworkRecvStatus *status);
    00113 };
    00114
    00115 #endif /* ENABLE_NETWORK */
    00116
    00117 #endif /* NETWORK_CORE_TCP_H */