Added ServerConsole application

This commit is contained in:
Anonymous
2014-01-21 06:08:34 -07:00
parent 24eb9956f8
commit aebef8d9f5
13 changed files with 530 additions and 0 deletions
@@ -0,0 +1,89 @@
// ServerConsole.cpp
// Copyright 2000-02, Sony Online Entertainment Inc., all rights reserved.
// Author: Justin Randall
//-----------------------------------------------------------------------
#include "FirstServerConsole.h"
#include "ConfigServerConsole.h"
#include "sharedFoundation/Os.h"
#include "sharedNetwork/Connection.h"
#include "sharedNetworkMessages/ConsoleChannelMessages.h"
#include "ServerConsole.h"
#include "ServerConsoleConnection.h"
#include <cstdio>
#include <string>
//-----------------------------------------------------------------------
namespace ServerConsoleNamespace
{
ServerConsoleConnection * s_serverConnection = 0;
bool s_done = false;
}
using namespace ServerConsoleNamespace;
//-----------------------------------------------------------------------
ServerConsole::ServerConsole()
{
}
//-----------------------------------------------------------------------
ServerConsole::~ServerConsole()
{
}
//-----------------------------------------------------------------------
void ServerConsole::done()
{
s_done = true;
}
//-----------------------------------------------------------------------
void ServerConsole::run()
{
if(!ConfigServerConsole::getServerAddress())
return;
if(!ConfigServerConsole::getServerPort())
return;
if(stdin)
{
std::string input;
char inBuf[1024] = {"\0"};
while(! feof(stdin))
{
fread(inBuf, 1024, 1, stdin);
input += inBuf;
memset(inBuf, 0, sizeof(inBuf));
}
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");
}
}
}
//-----------------------------------------------------------------------