2014-07-09 23:58:39 +00:00
|
|
|
#pragma once
|
|
|
|
#include "stdafx.h"
|
|
|
|
#include "../Utilities/SimpleLock.h"
|
|
|
|
|
2015-07-02 03:17:14 +00:00
|
|
|
class Socket;
|
|
|
|
class NetMessage;
|
|
|
|
class ClientConnectionData;
|
|
|
|
|
2014-07-09 23:58:39 +00:00
|
|
|
class GameConnection
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
shared_ptr<Socket> _socket;
|
2015-07-02 03:17:14 +00:00
|
|
|
shared_ptr<ClientConnectionData> _connectionData;
|
2014-07-09 23:58:39 +00:00
|
|
|
char _readBuffer[0x40000];
|
|
|
|
char _messageBuffer[0x40000];
|
|
|
|
int _readPosition = 0;
|
|
|
|
SimpleLock _socketLock;
|
|
|
|
|
|
|
|
private:
|
|
|
|
void ReadSocket();
|
|
|
|
|
|
|
|
bool ExtractMessage(char *buffer, uint32_t &messageLength);
|
|
|
|
NetMessage* ReadMessage();
|
|
|
|
|
|
|
|
virtual void ProcessMessage(NetMessage* message) = 0;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void SendNetMessage(NetMessage &message);
|
|
|
|
|
|
|
|
public:
|
2015-07-02 03:17:14 +00:00
|
|
|
GameConnection(shared_ptr<Socket> socket, shared_ptr<ClientConnectionData> connectionData);
|
2014-07-09 23:58:39 +00:00
|
|
|
|
|
|
|
bool ConnectionError();
|
|
|
|
|
|
|
|
void ProcessMessages();
|
|
|
|
|
|
|
|
};
|