mirror of
https://bitbucket.org/theswgsource/src-1.2.git
synced 2026-08-01 02:15:54 -04:00
Added ServerConsole application
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
// ConfigServerConsole.cpp
|
||||
// Copyright 2000-02, Sony Online Entertainment Inc., all rights reserved.
|
||||
// Author: Justin Randall
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
#include "FirstServerConsole.h"
|
||||
#include "sharedFoundation/ConfigFile.h"
|
||||
#include "ConfigServerConsole.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
namespace ConfigServerConsoleNamespace
|
||||
{
|
||||
const char * serverAddress;
|
||||
int serverPort;
|
||||
}
|
||||
|
||||
using namespace ConfigServerConsoleNamespace;
|
||||
|
||||
#define KEY_INT(a,b) (a = ConfigFile::getKeyInt("ServerConsole", #a, b))
|
||||
#define KEY_BOOL(a,b) (a = ConfigFile::getKeyBool("ServerConsole", #a, b))
|
||||
// #define KEY_REAL(a,b) (data->a = ConfigFile::getKeyReal("LoginServer", #a, b))
|
||||
#define KEY_STRING(a,b) (a = ConfigFile::getKeyString("ServerConsole", #a, b))
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
ConfigServerConsole::ConfigServerConsole()
|
||||
{
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
ConfigServerConsole::~ConfigServerConsole()
|
||||
{
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
const char * const ConfigServerConsole::getServerAddress()
|
||||
{
|
||||
return serverAddress;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
unsigned short ConfigServerConsole::getServerPort()
|
||||
{
|
||||
return static_cast<unsigned short>(serverPort);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void ConfigServerConsole::install()
|
||||
{
|
||||
KEY_STRING(serverAddress, "127.0.0.1");
|
||||
KEY_INT(serverPort, 61000);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void ConfigServerConsole::remove()
|
||||
{
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
// ConfigServerConsole.h
|
||||
// Copyright 2000-02, Sony Online Entertainment Inc., all rights reserved.
|
||||
// Author: Justin Randall
|
||||
|
||||
#ifndef _INCLUDED_ConfigServerConsole_H
|
||||
#define _INCLUDED_ConfigServerConsole_H
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
class ConfigServerConsole
|
||||
{
|
||||
public:
|
||||
ConfigServerConsole();
|
||||
~ConfigServerConsole();
|
||||
|
||||
static const char * const getServerAddress ();
|
||||
static unsigned short getServerPort ();
|
||||
|
||||
static void install();
|
||||
static void remove();
|
||||
|
||||
private:
|
||||
ConfigServerConsole & operator = (const ConfigServerConsole & rhs);
|
||||
ConfigServerConsole(const ConfigServerConsole & source);
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
#endif // _INCLUDED_ConfigServerConsole_H
|
||||
@@ -0,0 +1,9 @@
|
||||
// FirstServerConsole.cpp
|
||||
// Copyright 2000-02, Sony Online Entertainment Inc., all rights reserved.
|
||||
// Author: Justin Randall
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
#include "FirstServerConsole.h"
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@@ -0,0 +1,14 @@
|
||||
// FirstServerConsole.h
|
||||
// Copyright 2000-02, Sony Online Entertainment Inc., all rights reserved.
|
||||
// Author: Justin Randall
|
||||
|
||||
#ifndef _INCLUDED_FirstServerConsole_H
|
||||
#define _INCLUDED_FirstServerConsole_H
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
#include "sharedFoundation/FirstSharedFoundation.h"
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
#endif // _INCLUDED_FirstServerConsole_H
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
// ServerConsole.h
|
||||
// Copyright 2000-03, Sony Online Entertainment Inc., all rights reserved.
|
||||
// Author: Justin Randall
|
||||
|
||||
#ifndef _INCLUDED_ServerConsole_H
|
||||
#define _INCLUDED_ServerConsole_H
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
class ServerConsole
|
||||
{
|
||||
public:
|
||||
ServerConsole();
|
||||
~ServerConsole();
|
||||
|
||||
static void run();
|
||||
static void done();
|
||||
|
||||
private:
|
||||
ServerConsole & operator = (const ServerConsole & rhs);
|
||||
ServerConsole(const ServerConsole & source);
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
#endif // _INCLUDED_ServerConsole_H
|
||||
@@ -0,0 +1,69 @@
|
||||
// ServerConsoleConnection.cpp
|
||||
// Copyright 2000-02, Sony Online Entertainment Inc., all rights reserved.
|
||||
// Author: Justin Randall
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
#include "FirstServerConsole.h"
|
||||
#include "ServerConsole.h"
|
||||
#include "ServerConsoleConnection.h"
|
||||
#include "sharedNetwork/NetworkSetupData.h"
|
||||
#include "sharedNetworkMessages/ConsoleChannelMessages.h"
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
ServerConsoleConnection::ServerConsoleConnection(const std::string & address, const unsigned short port) :
|
||||
Connection(address, port, NetworkSetupData())
|
||||
{
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
ServerConsoleConnection::~ServerConsoleConnection()
|
||||
{
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void ServerConsoleConnection::onConnectionClosed()
|
||||
{
|
||||
ServerConsole::done();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void ServerConsoleConnection::onConnectionOpened()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void ServerConsoleConnection::onReceive(const Archive::ByteStream & bs)
|
||||
{
|
||||
Archive::ReadIterator ri = bs.begin();
|
||||
GameNetworkMessage m(ri);
|
||||
ri = bs.begin();
|
||||
|
||||
if(m.isType("ConGenericMessage"))
|
||||
{
|
||||
ConGenericMessage msg(ri);
|
||||
fprintf(stdout, "%s", msg.getMsg().c_str());
|
||||
}
|
||||
else if(m.isType("RequestDisconnect"))
|
||||
{
|
||||
disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void ServerConsoleConnection::send(const GameNetworkMessage & msg)
|
||||
{
|
||||
Archive::ByteStream bs;
|
||||
msg.pack(bs);
|
||||
Connection::send(bs, true);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
// ServerConsoleConnection.h
|
||||
// Copyright 2000-02, Sony Online Entertainment Inc., all rights reserved.
|
||||
// Author: Justin Randall
|
||||
|
||||
#ifndef _INCLUDED_ServerConsoleConnection_H
|
||||
#define _INCLUDED_ServerConsoleConnection_H
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
#include "sharedNetwork/Connection.h"
|
||||
#include "sharedNetworkMessages/GameNetworkMessage.h"
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
class ServerConsoleConnection : public Connection
|
||||
{
|
||||
public:
|
||||
ServerConsoleConnection(const std::string & address, const unsigned short port);
|
||||
~ServerConsoleConnection();
|
||||
|
||||
void onConnectionClosed ();
|
||||
void onConnectionOpened ();
|
||||
void onReceive (const Archive::ByteStream & bs);
|
||||
void send (const GameNetworkMessage &);
|
||||
|
||||
private:
|
||||
ServerConsoleConnection & operator = (const ServerConsoleConnection & rhs);
|
||||
ServerConsoleConnection(const ServerConsoleConnection & source);
|
||||
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
#endif // _INCLUDED_ServerConsoleConnection_H
|
||||
Reference in New Issue
Block a user