test
This commit is contained in:
@@ -14,6 +14,11 @@ namespace CMEvent {
|
|||||||
|
|
||||||
DataRecievedEvent(ISteamNetworkingMessage* m) : msg(m) {}
|
DataRecievedEvent(ISteamNetworkingMessage* m) : msg(m) {}
|
||||||
|
|
||||||
|
~DataRecievedEvent() {
|
||||||
|
if(msg)
|
||||||
|
msg->Release();
|
||||||
|
}
|
||||||
|
|
||||||
operator std::string() const { return "CMEvent::DataRecievedEvent"; }
|
operator std::string() const { return "CMEvent::DataRecievedEvent"; }
|
||||||
|
|
||||||
ISteamNetworkingMessage* msg;
|
ISteamNetworkingMessage* msg;
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ void ClientModule::startClient(SteamNetworkingIPAddr& serverAddr) {
|
|||||||
// Start connecting
|
// Start connecting
|
||||||
char szAddr[ SteamNetworkingIPAddr::k_cchMaxString ];
|
char szAddr[ SteamNetworkingIPAddr::k_cchMaxString ];
|
||||||
serverAddr.ToString( szAddr, sizeof(szAddr), true );
|
serverAddr.ToString( szAddr, sizeof(szAddr), true );
|
||||||
//Printf( "Connecting to chat server at %s", szAddr );
|
std::cerr << "Connecting to chat server at " << szAddr << std::endl;
|
||||||
SteamNetworkingConfigValue_t opt;
|
SteamNetworkingConfigValue_t opt;
|
||||||
opt.SetPtr( k_ESteamNetworkingConfig_Callback_ConnectionStatusChanged, (void*)SteamNetConnectionStatusChangedCallback );
|
opt.SetPtr( k_ESteamNetworkingConfig_Callback_ConnectionStatusChanged, (void*)SteamNetConnectionStatusChangedCallback );
|
||||||
connection = interface->ConnectByIPAddress( serverAddr, 1, &opt );
|
connection = interface->ConnectByIPAddress( serverAddr, 1, &opt );
|
||||||
@@ -125,17 +125,19 @@ bool ClientModule::onEvent(const Archimedes::Event& event) {
|
|||||||
|
|
||||||
void ClientModule::pollIncomingData() {
|
void ClientModule::pollIncomingData() {
|
||||||
|
|
||||||
while ( running )
|
int numMsgs;
|
||||||
{
|
do {
|
||||||
ISteamNetworkingMessage *pIncomingMsg = nullptr;
|
ISteamNetworkingMessage *pIncomingMsg = nullptr;
|
||||||
int numMsgs = interface->ReceiveMessagesOnConnection( connection, &pIncomingMsg, 1 );
|
numMsgs = interface->ReceiveMessagesOnConnection( connection, &pIncomingMsg, 1 );
|
||||||
if ( numMsgs == 0 )
|
if ( numMsgs == 0 )
|
||||||
break;
|
return;
|
||||||
if ( numMsgs < 0 )
|
if ( numMsgs < 0 )
|
||||||
std::cerr << "Error checking for messages" << std::endl;
|
std::cerr << "Error checking for messages" << std::endl;
|
||||||
assert( numMsgs == 1 && pIncomingMsg );
|
assert( numMsgs == 1 && pIncomingMsg );
|
||||||
assert( pIncomingMsg->m_conn == connection );
|
assert( pIncomingMsg->m_conn == connection );
|
||||||
|
|
||||||
app->emitEvent(new CMEvent::DataRecievedEvent(pIncomingMsg));
|
app->emitEvent(new CMEvent::DataRecievedEvent(pIncomingMsg));
|
||||||
}
|
//numMsgs--;
|
||||||
|
return;
|
||||||
|
} while (numMsgs > 0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,6 +30,8 @@ class ClientModule : public Archimedes::Module {
|
|||||||
|
|
||||||
bool isRunning() const { return running; }
|
bool isRunning() const { return running; }
|
||||||
|
|
||||||
|
bool isConnected() const { return connection != k_HSteamNetConnection_Invalid; }
|
||||||
|
|
||||||
void pollIncomingData();
|
void pollIncomingData();
|
||||||
|
|
||||||
void shouldHandleEvents(unsigned int events) { eventsToHandle = events; }
|
void shouldHandleEvents(unsigned int events) { eventsToHandle = events; }
|
||||||
|
|||||||
@@ -166,6 +166,7 @@ bool ServerModule::onEvent(const Archimedes::Event& event) {
|
|||||||
//Printf( "Can't accept connection. (It was already closed?)" );
|
//Printf( "Can't accept connection. (It was already closed?)" );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
std::cerr << "Connection Accepted!\n";
|
||||||
|
|
||||||
// Assign the poll group
|
// Assign the poll group
|
||||||
if ( !interface->SetConnectionPollGroup( e.info->m_hConn, pollGroup ) )
|
if ( !interface->SetConnectionPollGroup( e.info->m_hConn, pollGroup ) )
|
||||||
@@ -208,7 +209,7 @@ void ServerModule::pollIncomingData() {
|
|||||||
ISteamNetworkingMessage *pIncomingMsg = nullptr;
|
ISteamNetworkingMessage *pIncomingMsg = nullptr;
|
||||||
int numMsgs = interface->ReceiveMessagesOnPollGroup( pollGroup, &pIncomingMsg, 1 );
|
int numMsgs = interface->ReceiveMessagesOnPollGroup( pollGroup, &pIncomingMsg, 1 );
|
||||||
if ( numMsgs == 0 )
|
if ( numMsgs == 0 )
|
||||||
break;
|
return;
|
||||||
if ( numMsgs < 0 )
|
if ( numMsgs < 0 )
|
||||||
std::cerr << "Error checking for messages" << std::endl;
|
std::cerr << "Error checking for messages" << std::endl;
|
||||||
assert( numMsgs == 1 && pIncomingMsg );
|
assert( numMsgs == 1 && pIncomingMsg );
|
||||||
@@ -216,5 +217,6 @@ void ServerModule::pollIncomingData() {
|
|||||||
assert( itClient != clients.end() );
|
assert( itClient != clients.end() );
|
||||||
|
|
||||||
app->emitEvent(new SMEvent::DataRecievedEvent(pIncomingMsg));
|
app->emitEvent(new SMEvent::DataRecievedEvent(pIncomingMsg));
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ void ChatClient::run() {
|
|||||||
|
|
||||||
ImGui::InputText("Server Address: ", &addr);
|
ImGui::InputText("Server Address: ", &addr);
|
||||||
|
|
||||||
if(cm->isRunning()) {
|
if(cm->isRunning() && cm->isConnected()) {
|
||||||
|
|
||||||
if(ImGui::Button("Disconnect") && cm->isRunning()) {
|
if(ImGui::Button("Disconnect") && cm->isRunning()) {
|
||||||
cm->stopClient();
|
cm->stopClient();
|
||||||
|
|||||||
Reference in New Issue
Block a user