Mesen/Core/GameConnection.h

44 lines
897 B
C
Raw Normal View History

2014-07-09 23:58:39 +00:00
#pragma once
#include "stdafx.h"
#include "../Utilities/SimpleLock.h"
class Socket;
class NetMessage;
class ClientConnectionData;
struct PlayerInfo
{
string Name;
uint8_t ControllerPort;
bool IsHost;
};
2014-07-09 23:58:39 +00:00
class GameConnection
{
protected:
shared_ptr<Socket> _socket;
shared_ptr<ClientConnectionData> _connectionData;
uint8_t _readBuffer[0x40000] = {};
uint8_t _messageBuffer[0x40000] = {};
2014-07-09 23:58:39 +00:00
int _readPosition = 0;
SimpleLock _socketLock;
private:
void ReadSocket();
bool ExtractMessage(void *buffer, uint32_t &messageLength);
2014-07-09 23:58:39 +00:00
NetMessage* ReadMessage();
virtual void ProcessMessage(NetMessage* message) = 0;
protected:
void Disconnect();
2014-07-09 23:58:39 +00:00
public:
static const uint8_t SpectatorPort = 0xFF;
GameConnection(shared_ptr<Socket> socket, shared_ptr<ClientConnectionData> connectionData);
2014-07-09 23:58:39 +00:00
bool ConnectionError();
void ProcessMessages();
void SendNetMessage(NetMessage &message);
2014-07-09 23:58:39 +00:00
};