add some server commands

This commit is contained in:
2025-04-17 21:59:14 -05:00
parent 9147787fd2
commit 600d0f3c81
4 changed files with 22 additions and 1 deletions

View File

@@ -55,6 +55,7 @@ void ServerModule::startServer(int p) {
} }
void ServerModule::stopServer() { void ServerModule::stopServer() {
disconnectAllClients();
running = false; running = false;
} }

View File

@@ -39,6 +39,19 @@ class ServerModule : public Archimedes::Module {
} }
void disconnectClient(HSteamNetConnection c) {
if(clients.find(c) != clients.end()) {
interface->CloseConnection(c, 0, nullptr, false);
clients.erase(c);
}
}
void disconnectAllClients() {
while(!clients.empty()) {
disconnectClient(clients.begin()->first);
}
}
std::map<HSteamNetConnection, unsigned int> getClients() const { return clients; } std::map<HSteamNetConnection, unsigned int> getClients() const { return clients; }
void pollIncomingData(); void pollIncomingData();

View File

@@ -24,7 +24,7 @@ void ChatClient::run() {
static ClientModule* cm; { cm = (ClientModule*) moduleInstances[ClientModule()]; } static ClientModule* cm; { cm = (ClientModule*) moduleInstances[ClientModule()]; }
if(open) { if(open) {
static std::string s, addr; static std::string s, addr = "127.0.0.1:9932";
ImGui::Begin("ChatClient Module", &open); ImGui::Begin("ChatClient Module", &open);

View File

@@ -26,6 +26,13 @@ bool ChatServer::onEvent(const Archimedes::Event& event) {
static std::string s; s = std::string((const char*)e.msg->m_pData, e.msg->m_cbSize); static std::string s; s = std::string((const char*)e.msg->m_pData, e.msg->m_cbSize);
if(s == "/quit") {
sm->disconnectClient(e.msg->m_conn);
} else if(s == "/shutdown") {
sm->stopServer();
app->end();
}
std::cerr << "Server Recieved: " << s << std::endl; std::cerr << "Server Recieved: " << s << std::endl;
for(auto& it : sm->getClients()) { for(auto& it : sm->getClients()) {