add some server commands
This commit is contained in:
@@ -55,6 +55,7 @@ void ServerModule::startServer(int p) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ServerModule::stopServer() {
|
void ServerModule::stopServer() {
|
||||||
|
disconnectAllClients();
|
||||||
running = false;
|
running = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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();
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|
||||||
|
|||||||
@@ -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()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user