# core.h

Go to the documentation of this file.

    00001 /* $Id: core.h 15079 2009-01-14 12:50:13Z rubidium $ */
    00002
    00007 #ifndef NETWORK_CORE_H
    00008 #define NETWORK_CORE_H
    00009
    00010 #ifdef ENABLE_NETWORK
    00011
    00012 #include "os_abstraction.h"
    00013 #include "../../newgrf_config.h"
    00014
    00015 bool NetworkCoreInitialize();
    00016 void NetworkCoreShutdown();
    00017
    00019 enum NetworkRecvStatus {
    00020   NETWORK_RECV_STATUS_OKAY,
    00021   NETWORK_RECV_STATUS_DESYNC,
    00022   NETWORK_RECV_STATUS_NEWGRF_MISMATCH,
    00023   NETWORK_RECV_STATUS_SAVEGAME,
    00024   NETWORK_RECV_STATUS_CONN_LOST,
    00025   NETWORK_RECV_STATUS_MALFORMED_PACKET,
    00026   NETWORK_RECV_STATUS_SERVER_ERROR,
    00027   NETWORK_RECV_STATUS_SERVER_FULL,
    00028   NETWORK_RECV_STATUS_SERVER_BANNED,
    00029   NETWORK_RECV_STATUS_CLOSE_QUERY,
    00030 };
    00031
    00033 struct Packet;
    00034
    00038 class NetworkSocketHandler {
    00039 public:
    00040   /* TODO: make socket & has_quit protected once the TCP stuff
    00041    *is in a real class too */
    00042   bool has_quit;
    00043   SOCKET sock;
    00044 public:
    00046   NetworkSocketHandler(SOCKET s = INVALID_SOCKET) { this->sock = s; this->has_quit = false; }
    00047
    00049   virtual ~NetworkSocketHandler() { this->Close(); }
    00050
    00052   virtual void Close() {}
    00053
    00059   virtual NetworkRecvStatus CloseConnection() { this->has_quit = true; return NETWORK_RECV_STATUS_OKAY; }
    00060
    00065   bool IsConnected() const { return this->sock != INVALID_SOCKET; }
    00066
    00073   bool HasClientQuit() const { return this->has_quit; }
    00074
    00075   void Send_GRFIdentifier(Packet *p, const GRFIdentifier *grf);
    00076   void Recv_GRFIdentifier(Packet *p, GRFIdentifier *grf);
    00077   void Send_CompanyInformation(Packet *p, const struct Company *c, const struct NetworkCompanyStats *stats);
    00078 };
    00079
    00080 #endif /* ENABLE_NETWORK */
    00081
    00082 #endif /* NETWORK_CORE_H */