work on ClientModule, add ChatServer
This commit is contained in:
@@ -3,6 +3,8 @@
|
||||
#include <steam/steamnetworkingsockets.h>
|
||||
#include <steam/isteamnetworkingutils.h>
|
||||
|
||||
#include "ClientEvents.h"
|
||||
|
||||
class ClientModule : public Archimedes::Module {
|
||||
|
||||
public:
|
||||
@@ -10,9 +12,49 @@ class ClientModule : public Archimedes::Module {
|
||||
~ClientModule();
|
||||
void onLoad();
|
||||
void run();
|
||||
bool onEvent(const Archimedes::Event&);
|
||||
|
||||
void startClient(SteamNetworkingIPAddr&);
|
||||
void stopClient();
|
||||
|
||||
void sendReliable(const void* data, uint32 byteCount) {
|
||||
interface->SendMessageToConnection(connection, data, byteCount, k_nSteamNetworkingSend_Reliable, nullptr);
|
||||
|
||||
}
|
||||
|
||||
void pollIncomingData();
|
||||
|
||||
void shouldHandleEvents(unsigned int events) { eventsToHandle = events; }
|
||||
|
||||
enum CMEventEnum {
|
||||
None = 0,
|
||||
ConnectionStatusChanged = 1 << 0,
|
||||
DataRecieved = 1 << 1,
|
||||
DataSent = 1 << 2
|
||||
};
|
||||
private:
|
||||
|
||||
unsigned int eventsToHandle = CMEventEnum::ConnectionStatusChanged | CMEventEnum::DataSent | CMEventEnum::DataRecieved;
|
||||
|
||||
bool running = false;
|
||||
|
||||
ISteamNetworkingSockets* interface;
|
||||
HSteamNetConnection connection;
|
||||
|
||||
inline static ClientModule* callbackInstance = nullptr;
|
||||
|
||||
static void SteamNetConnectionStatusChangedCallback( SteamNetConnectionStatusChangedCallback_t *pInfo ) {
|
||||
callbackInstance->OnSteamNetConnectionStatusChanged( pInfo );
|
||||
}
|
||||
|
||||
void OnSteamNetConnectionStatusChanged( SteamNetConnectionStatusChangedCallback_t *pInfo ) {
|
||||
app->emitEvent(new CMEvent::ConnectionStatusChangedEvent(pInfo));
|
||||
}
|
||||
|
||||
void PollConnectionStateChanges() {
|
||||
callbackInstance = this;
|
||||
interface->RunCallbacks();
|
||||
}
|
||||
};
|
||||
|
||||
#ifdef CLIENTMODULE_DYNAMIC
|
||||
|
||||
Reference in New Issue
Block a user