mirror of
https://github.com/worldforge/cyphesis
synced 2026-08-13 12:26:04 -04:00
* client/CharacterClient.cpp, client/CharacterClient.h, client/CommClient.cpp, common/BaseEntity.cpp, common/BaseEntity.h, common/OOGThing.cpp, common/OOGThing.h, common/op_switch.h, rulesets/BaseMind.cpp, rulesets/BaseMind.h, rulesets/Character.cpp, rulesets/Character.h, rulesets/Creator.cpp, rulesets/Creator.h, rulesets/Entity.cpp, rulesets/Entity.h, rulesets/Food.cpp, rulesets/Food.h, rulesets/Missile.h, rulesets/Plant.cpp, rulesets/Plant.h, rulesets/PythonMindScript.cpp, rulesets/PythonThingScript.cpp, rulesets/Stackable.cpp, rulesets/Stackable.h, rulesets/Thing.cpp, rulesets/Thing.h, rulesets/World.cpp, rulesets/World.h, server/Account.cpp, server/Account.h, server/Admin.cpp, server/Admin.h, server/CommClient.cpp, server/Connection.cpp, server/Connection.h, server/ExternalMind.cpp, server/ExternalMind.h, server/Lobby.cpp, server/Lobby.h, server/Player.cpp, server/Player.h, server/WorldRouter.cpp: Re-work basic op dispatch mechanism so result is passed by a reference argument rather than returning by value.
96 lines
2.6 KiB
C++
96 lines
2.6 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) 2001 Alistair Riddoch
|
|
|
|
#include "CharacterClient.h"
|
|
|
|
#include "ClientConnection.h"
|
|
|
|
#include "common/debug.h"
|
|
|
|
#include <Atlas/Objects/Operation/RootOperation.h>
|
|
|
|
static const bool debug_flag = false;
|
|
|
|
CharacterClient::CharacterClient(const std::string & id,
|
|
const std::string & name,
|
|
ClientConnection & c) :
|
|
BaseMind(id,name), connection(c)
|
|
{
|
|
}
|
|
|
|
void CharacterClient::sightImaginaryOperation(const Sight &,
|
|
Imaginary &, OpVector &)
|
|
{
|
|
}
|
|
|
|
void CharacterClient::soundTalkOperation(const Sound & , Talk &, OpVector &)
|
|
{
|
|
}
|
|
|
|
#if 0
|
|
//FIXME Dunno what all this trigger lark is about.
|
|
bad_type CharacterClient::add_trigger(bad_type event_name, bad_type func) {
|
|
dictlist.add_value(CharacterClient::event_triggers,event_name, func);
|
|
}
|
|
bad_type CharacterClient::call_triggers(bad_type op) {
|
|
event_name, sub_op = CharacterClient::get_op_name_and_sub(op);
|
|
reply = Message();
|
|
for (/*func in CharacterClient::event_triggers.get(event_name,[])*/) {
|
|
reply = reply + func(op, sub_op);
|
|
}
|
|
return reply;
|
|
}
|
|
bad_type CharacterClient::set_from_op(bad_type op) {
|
|
op.from_=self;
|
|
}
|
|
bad_type CharacterClient::set_from(bad_type msg) {
|
|
CharacterClient::apply_to_operation(CharacterClient::set_from_op,msg);
|
|
}
|
|
#endif
|
|
|
|
void CharacterClient::send(RootOperation & op)
|
|
{
|
|
op.setFrom(getId());
|
|
connection.send(op);
|
|
}
|
|
|
|
inline bool CharacterClient::findRefnoOp(const RootOperation & op, long refno)
|
|
{
|
|
if (refno == op.getRefno()) {
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
inline bool CharacterClient::findRefno(const RootOperation & msg, long refno)
|
|
{
|
|
return findRefnoOp(msg,refno);
|
|
}
|
|
|
|
OpVector CharacterClient::sendAndWaitReply(RootOperation & op)
|
|
{
|
|
send(op);
|
|
long no = op.getSerialno();
|
|
while (true) {
|
|
if (connection.pending()) {
|
|
RootOperation * input=CharacterClient::connection.pop();
|
|
if (input != NULL) {
|
|
// What the hell is this!
|
|
OpVector result;
|
|
operation(*input, result);
|
|
OpVector::const_iterator I;
|
|
for (I=result.begin();I!=result.end();I++) {
|
|
send(*(*I));
|
|
}
|
|
|
|
if (findRefno(*input,no)) {
|
|
return OpVector(1,input);
|
|
}
|
|
delete input;
|
|
}
|
|
} else if (connection.wait()) {
|
|
return OpVector();
|
|
}
|
|
}
|
|
}
|