Fixed ServerConsole

This commit is contained in:
seefo
2019-04-18 20:58:22 -04:00
parent f36ee7ed77
commit a66c0d1a91

View File

@@ -13,6 +13,7 @@
#include "ServerConsoleConnection.h"
#include <cstdio>
#include <string>
#include <iostream>
//-----------------------------------------------------------------------
@@ -53,37 +54,21 @@ void ServerConsole::run()
if(!ConfigServerConsole::getServerPort())
return;
if(stdin)
{
std::string input;
char inBuf[1024] = {"\0"};
while(! feof(stdin))
{
if (fread(inBuf, 1024, 1, stdin)) {
input += inBuf;
memset(inBuf, 0, sizeof(inBuf));
}
}
std::string input;
getline(std::cin, input);
s_serverConnection = new ServerConsoleConnection(ConfigServerConsole::getServerAddress(), ConfigServerConsole::getServerPort());
ConGenericMessage msg(input);
s_serverConnection->send(msg);
while(! s_done)
{
NetworkHandler::update();
NetworkHandler::dispatch();
Os::sleep(1);
}
if(input.length() > 0)
{
// connect to the server
s_serverConnection = new ServerConsoleConnection(ConfigServerConsole::getServerAddress(), ConfigServerConsole::getServerPort());
ConGenericMessage msg(input);
s_serverConnection->send(msg);
while(! s_done)
{
NetworkHandler::update();
NetworkHandler::dispatch();
Os::sleep(1);
}
}
else
{
fprintf(stderr, "Nothing to send to the server. Aborting");
}
}
fprintf(stdout, "\n");
}
//-----------------------------------------------------------------------