work on ServerModule

This commit is contained in:
2025-04-16 23:59:12 -05:00
parent 00ef227128
commit 2c903c276d
3 changed files with 84 additions and 16 deletions

View File

@@ -10,17 +10,18 @@ namespace SMEvent {
public:
DataRecievedEvent() : clientID(0), buffer(nullptr), size(0) {}
DataRecievedEvent() : msg(nullptr) {}
~DataRecievedEvent() {
if(msg)
msg->Release();
}
DataRecievedEvent(unsigned int c, void* buf, unsigned int s) : clientID(c), buffer(buf), size(s) {}
DataRecievedEvent(ISteamNetworkingMessage* m) : msg(m) {}
operator std::string() const { return "DataRecievedEvent"; }
unsigned int clientID;
void* buffer;
unsigned int size;
ISteamNetworkingMessage* msg;
};
@@ -28,18 +29,18 @@ namespace SMEvent {
public:
DataSentEvent() : clientID(0), buffer(nullptr), size(0) {}
DataSentEvent() : msg(nullptr) {}
DataSentEvent(unsigned int c, void* buf, unsigned int s) : clientID(c), buffer(buf), size(s) {}
~DataSentEvent() {
if(msg)
msg->Release();
}
DataSentEvent(ISteamNetworkingMessage* m) : msg(m) {}
operator std::string() const { return "DataSentEvent"; }
unsigned int clientID;
void* buffer;
unsigned int size;
ISteamNetworkingMessage* msg;
};
class ConnectionStatusChangedEvent : public Archimedes::Event {

View File

@@ -45,7 +45,7 @@ void ServerModule::onLoad() {
void ServerModule::run() {
if(running) {
PollIncomingMessages();
pollIncomingData();
PollConnectionStateChanges();
PollLocalUserInput();
} else if(port >= 0) {
@@ -189,3 +189,20 @@ bool ServerModule::onEvent(const Archimedes::Event& event) {
return false;
}
void ServerModule::pollIncomingData() {
while ( running )
{
ISteamNetworkingMessage *pIncomingMsg = nullptr;
int numMsgs = interface->ReceiveMessagesOnPollGroup( pollGroup, &pIncomingMsg, 1 );
if ( numMsgs == 0 )
break;
if ( numMsgs < 0 )
std::cerr << "Error checking for messages" << std::endl;
assert( numMsgs == 1 && pIncomingMsg );
auto itClient = clients.find( pIncomingMsg->m_conn );
assert( itClient != clients.end() );
app->emitEvent(new SMEvent::DataRecievedEvent(pIncomingMsg));
}
}