mirror of
https://github.com/worldforge/cyphesis
synced 2026-08-13 12:26:04 -04:00
* tools/cycmd.cpp, client/CommClient.h, client/CommClient.cpp: Fixed up client code so it does not rely on username being the same as account id. * tools/cycmd.cpp: Added look and logout commands to administrate users logged in. * server/server.cpp: Fixed metaserver code so it only sends termination packet if metaserver functionality is enabled. * server/Connection.h, server/Connection.cpp, server/CommServer.cpp, server/CommClient.h, server/Account.cpp: Fix logouts so they do cause the client connection to be closed. * Finished switch from Fire operation to Burn.
110 lines
3.2 KiB
C++
110 lines
3.2 KiB
C++
// This file may be redistributed and modified only under the terms of
|
|
// the GNU General Public License (See COPYING for details).
|
|
// Copyright (C) 2000,2001 Alistair Riddoch
|
|
|
|
#include "CommClient.h"
|
|
|
|
#include "CreatorClient.h"
|
|
|
|
#include <common/debug.h>
|
|
#include <common/BaseEntity.h>
|
|
|
|
static const bool debug_flag = false;
|
|
|
|
using Atlas::Message::Object;
|
|
|
|
CommClient::CommClient()
|
|
{
|
|
}
|
|
|
|
Object::MapType
|
|
CommClient::createPlayer(const std::string & name,
|
|
const std::string & password)
|
|
{
|
|
playerName = name;
|
|
Object::MapType player_ent;
|
|
player_ent["username"] = name;
|
|
player_ent["password"] = password;
|
|
player_ent["parents"] = Object::ListType(1, "player");
|
|
|
|
debug(std::cout << "Loggin " << name << " in with " << password << " as password"
|
|
<< std::endl << std::flush;);
|
|
|
|
Login loginAccountOp(Login::Instantiate());
|
|
loginAccountOp.SetArgs(Object::ListType(1,player_ent));
|
|
send(loginAccountOp);
|
|
|
|
if (connection.wait()) {
|
|
Create createAccountOp(Create::Instantiate());
|
|
createAccountOp.SetArgs(Object::ListType(1,player_ent));
|
|
send(createAccountOp);
|
|
if (connection.wait()) {
|
|
std::cerr << "ERROR: Failed to log into server" << std::endl
|
|
<< std::flush;
|
|
return Object::MapType();
|
|
}
|
|
}
|
|
|
|
Object::MapType ent = connection.getReply();
|
|
|
|
Object::MapType::const_iterator I = ent.find("id");
|
|
if (I == ent.end() || !I->second.IsString()) {
|
|
std::cerr << "ERROR: Logged in, but account has no id" << std::endl
|
|
<< std::flush;
|
|
} else {
|
|
playerId = I->second.AsString();
|
|
}
|
|
//if (ent.find("characters") != ent.end()) {
|
|
//}
|
|
|
|
return ent;
|
|
}
|
|
|
|
CreatorClient * CommClient::createCharacter(const std::string & type)
|
|
{
|
|
Object::MapType character;
|
|
character["name"] = playerName;
|
|
character["parents"] = Object::ListType(1,type);
|
|
|
|
Create createOp=Create::Instantiate();
|
|
createOp.SetFrom(playerId);
|
|
createOp.SetArgs(Object::ListType(1,character));
|
|
send(createOp);
|
|
|
|
if (connection.wait()) {
|
|
std::cerr << "ERROR: Failed to create character type: "
|
|
<< type << std::endl << std::flush;
|
|
return NULL;
|
|
}
|
|
Object::MapType body=connection.getReply();
|
|
|
|
const std::string & id = body.find("id")->second.AsString();
|
|
|
|
EntityDict tmp;
|
|
|
|
CreatorClient * obj = new CreatorClient(id, type, connection);
|
|
obj->merge(body);
|
|
obj->getLocation(body, tmp);
|
|
// obj = EntityFactory::instance()->newThing(type, body, tmp);
|
|
// FIXME Do we need to create a local entity for this as is done in
|
|
// the python version? If so, do we need to keep track of a full world
|
|
// model here, or just in the minds (when we become an AI client
|
|
return obj;
|
|
}
|
|
|
|
// I'm making this pure virtual, to see if that is desired.
|
|
//void CommClient::idle() {
|
|
// time.sleep(0.1);
|
|
//}
|
|
|
|
void CommClient::handleNet()
|
|
{
|
|
RootOperation * input;
|
|
while ((input = connection.pop()) != NULL) {
|
|
OpVector result = character->message(*input);
|
|
for (OpVector::const_iterator I=result.begin(); I != result.end(); I++) {
|
|
send(*(*I));
|
|
}
|
|
delete input;
|
|
}
|
|
}
|