(svn r20923) -Codechange: prepare creating sub-classes of NetworkClientSocket for server and client side
This commit is contained in:
@@ -18,7 +18,6 @@
|
||||
#include "../network.h"
|
||||
#include "../network_internal.h"
|
||||
#include "../../core/pool_func.hpp"
|
||||
#include "../../order_backup.h"
|
||||
|
||||
#include "table/strings.h"
|
||||
|
||||
@@ -29,18 +28,16 @@ assert_compile(NetworkClientSocketPool::MAX_SIZE == MAX_CLIENT_SLOTS);
|
||||
NetworkClientSocketPool _networkclientsocket_pool("NetworkClientSocket");
|
||||
INSTANTIATE_POOL_METHODS(NetworkClientSocket)
|
||||
|
||||
NetworkClientSocket::NetworkClientSocket(ClientID client_id)
|
||||
/**
|
||||
* Create a new socket for the game connection.
|
||||
* @param s The socket to connect with.
|
||||
*/
|
||||
NetworkGameSocketHandler::NetworkGameSocketHandler(SOCKET s)
|
||||
{
|
||||
this->client_id = client_id;
|
||||
this->status = STATUS_INACTIVE;
|
||||
}
|
||||
|
||||
NetworkClientSocket::~NetworkClientSocket()
|
||||
{
|
||||
if (_redirect_console_to_client == this->client_id) _redirect_console_to_client = INVALID_CLIENT_ID;
|
||||
if (_network_server) OrderBackup::ResetUser(this->client_id);
|
||||
this->client_id = INVALID_CLIENT_ID;
|
||||
this->status = STATUS_INACTIVE;
|
||||
this->sock = s;
|
||||
this->last_frame = _frame_counter;
|
||||
this->last_frame_server = _frame_counter;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -51,7 +48,7 @@ NetworkClientSocket::~NetworkClientSocket()
|
||||
* @return the new status
|
||||
* TODO: needs to be splitted when using client and server socket packets
|
||||
*/
|
||||
NetworkRecvStatus NetworkClientSocket::CloseConnection(bool error)
|
||||
NetworkRecvStatus NetworkGameSocketHandler::CloseConnection(bool error)
|
||||
{
|
||||
/* Clients drop back to the main menu */
|
||||
if (!_network_server && _networking) {
|
||||
|
@@ -108,15 +108,18 @@ enum ClientStatus {
|
||||
STATUS_END ///< Must ALWAYS be on the end of this list!! (period)
|
||||
};
|
||||
|
||||
class NetworkClientSocket;
|
||||
class NetworkGameSocketHandler;
|
||||
typedef NetworkGameSocketHandler NetworkClientSocket;
|
||||
typedef Pool<NetworkClientSocket, ClientIndex, 8, MAX_CLIENT_SLOTS> NetworkClientSocketPool;
|
||||
extern NetworkClientSocketPool _networkclientsocket_pool;
|
||||
|
||||
/** Base socket handler for all TCP sockets */
|
||||
class NetworkClientSocket : public NetworkClientSocketPool::PoolItem<&_networkclientsocket_pool>, public NetworkTCPSocketHandler {
|
||||
class NetworkGameSocketHandler : public NetworkClientSocketPool::PoolItem<&_networkclientsocket_pool>, public NetworkTCPSocketHandler {
|
||||
/* TODO: rewrite into a proper class */
|
||||
private:
|
||||
NetworkClientInfo *info; ///< Client info related to this socket
|
||||
protected:
|
||||
NetworkGameSocketHandler(SOCKET s);
|
||||
public:
|
||||
ClientID client_id; ///< Client identifier
|
||||
uint32 last_frame; ///< Last frame we have executed
|
||||
@@ -129,9 +132,7 @@ public:
|
||||
CommandQueue outgoing_queue; ///< The command-queue awaiting delivery
|
||||
|
||||
NetworkRecvStatus CloseConnection(bool error = true);
|
||||
|
||||
NetworkClientSocket(ClientID client_id = INVALID_CLIENT_ID);
|
||||
~NetworkClientSocket();
|
||||
virtual ~NetworkGameSocketHandler() {}
|
||||
|
||||
inline void SetInfo(NetworkClientInfo *info) { assert(info != NULL && this->info == NULL); this->info = info; }
|
||||
inline NetworkClientInfo *GetInfo() const { return this->info; }
|
||||
|
Reference in New Issue
Block a user