Exemplo n.º 1
0
 def get_op(self, op, reply_op_parent="info"):
     if not hasattr(op, "arg") or not hasattr(op.arg, "id"):
         self.reply_operation(op, atlas.Operation(reply_op_parent, self.server_object()))
         return
     id = op.arg.id
     obj = self.server.objects.get(id)
     if obj:
         self.reply_operation(op, atlas.Operation(reply_op_parent, obj))
     else:
         self.send_error(op, "no object with id " + id)
Exemplo n.º 2
0
 def talk_op(self, op):
     if print_debug:
         print(repr(str(op)))
     self.server.str_op = str(op)
     reply = atlas.Operation("sound",
                             atlas.Operation("talk",
                                             atlas.Object(say="Hello %s!" %
                                                          op.from_),
                                             from_=op.from_),
                             from_=op.from_)
     self.reply_operation(op, reply)
     self.server.waiting = 0
Exemplo n.º 3
0
 def get_op(self, op):
     print "!!"
     if not self.done:
         print "feeding..."
         for obj in self.server.objects:
             self.send_operation(atlas.Operation("info", obj))
         self.done = 1
Exemplo n.º 4
0
def test_speed(max):
    for i in range(max):
        account = atlas.Object()
        account.id="foo"
        account.password="******"
        op = atlas.Operation("login",account)
        s = str(op)
Exemplo n.º 5
0
 def send_error(self, op, msg):
     err = atlas.Object(message=msg, op=op)
     try:
         refid = op.id
     except AttributeError:
         refid = ""
     self.send_operation(atlas.Operation("error", err, refid=refid))
Exemplo n.º 6
0
 def get_op(self, op):
     id = op.arg.id
     obj = self.server.objects.get(id)
     if obj:
         self.reply_operation(op, atlas.Operation("info", obj))
     else:
         self.send_error(op, "no object with id " + id)
 def talk(self, name, say):
     self.send_operation(
         atlas.Operation("talk",
                         atlas.Object(say=say),
                         from_=name,
                         id="gateway"))
     print("ATLAS: talk:", name, say)
Exemplo n.º 8
0
 def send(self, id, value, op_id, recursion_id=""):
     """go parentwise collecting id until at root object, then send it"""
     #print "SharedObject:", id, value, op_id, recursion_id
     if recursion_id:
         if self._id: recursion_id = self._id + "." + recursion_id
     else:
         recursion_id = self._id
     #print "->", recursion_id
     self._changed = 1
     if self._parent:
         if op_id == "create": op_id = "set"
         self._parent.send(id, value, op_id, recursion_id)
     else:
         if op_id == "delete":
             if recursion_id: id = recursion_id + "." + id
             obj = atlas.Object(id=id)
         else:
             if recursion_id:
                 obj = atlas.Object()
                 obj[id] = value
                 obj.id = recursion_id
             else:
                 obj = atlas.Object()
                 obj.update(value)
                 obj.id = id
         op = atlas.Operation(op_id, obj)
         #print "<<", op, ">>"
         self.send_op(op)
Exemplo n.º 9
0
 def login_op(self, op):
     account = op.arg.id
     if self.server.has_account(account):
         self.send_error(op, "somebody already in with that id")
     else:
         self.id = account
         ent = atlas.Object(parents=["player"], id=account)
         self.reply_operation(op, atlas.Operation("info", ent, to=account))
Exemplo n.º 10
0
 def ask(self, id_lst):
     for id in id_lst:
         id = atlas.get_base_id(id)
         #print "?"*60, id, len(id_lst)
         if id and id not in self.pending and id not in self.objects:
             print("?", id)
             op = atlas.Operation("get", atlas.Object(id=id))
             self.send_operation(op)
             self.pending[id] = id
Exemplo n.º 11
0
 def loop(self):
     op = atlas.Operation("talk",
                          atlas.Object(say="Hello world!"),
                          from_="Joe")
     self.send_operation(op)
     self.waiting = 1
     while self.waiting:
         time.sleep(0.1)
         self.process_communication()
Exemplo n.º 12
0
 def ask(self, id_lst):
     for id in id_lst:
         id = atlas.get_base_id(id)
         #print "?"*60, id, len(id_lst)
         if id and not self.pending.has_key(
                 id) and not self.objects.has_key(id):
             print "?", id
             op = atlas.Operation("get", atlas.Object(id=id))
             self.send_operation(op)
             self.pending[id] = id
Exemplo n.º 13
0
 def set_op(self, op):
     self.server.log_op(op)
     obj = self.fetch_object(op.arg.id)
     #print "set:", op.arg.id, "->", obj
     if obj:
         for key, value in op.arg.items():
             if key == "id": continue
             obj[key] = value
         self.server.reply_all(op, atlas.Operation("info", op))
     else:
         self.send_error(op, "no object with id " + op.arg.id)
     self.server.save()
Exemplo n.º 14
0
 def delete_op(self, op):
     self.server.log_op(op)
     obj, id = self.fetch_object_id(op.arg.id)
     #print "delete:", op.arg.id, "->", obj, id
     if obj:
         try:
             id_lst = string.split(op.arg.id, ".")
             if len(id_lst) == 1:
                 root_obj = obj[id]
             else:
                 root_obj = None
             del obj[id]
             self.server.reply_all(op, atlas.Operation("info", op))
             self.server.check_bidirectional(root_obj, "delete")
         except KeyError, IndexError:
             obj = None
Exemplo n.º 15
0
 def create_op(self, op):
     self.server.log_op(op)
     obj = op.arg
     if hasattr(obj, "id"):
         id = obj.id
     else:
         id = self.server.next_id()
     obj = self.server.objects.get(id)
     if obj:
         self.send_error(op, "object with id " + id + " already exists")
     else:
         obj = op.arg
         obj.id = id
         self.server.objects[id] = obj
         self.server.check_bidirectional(obj)
         self.server.reply_all(op, atlas.Operation("info", op))
     self.server.save()
Exemplo n.º 16
0
 def talk(nick, text, send_op=send_op):
     send_op(atlas.Operation("talk", atlas.Object(say=text),
                             from_=nick))
#This library is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
#Lesser General Public License for more details.

#You should have received a copy of the GNU Lesser General Public
#License along with this library; if not, write to the Free Software
#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

from __future__ import print_function
from builtins import input
import sys, time
sys.path.append("..")
from atlas.transport.TCP.client import TcpClient
from atlas.transport.connection import args2address
import atlas


class HelloWorldClient(TcpClient):
    def sound_op(self, op):
        talk_op = op.arg
        print("%s said %s" % (op.from_, talk_op.arg.say))


if __name__ == "__main__":
    s = HelloWorldClient("Hello World client", args2address(sys.argv))
    name = input("Nick/Name to use: ")
    s.send_operation(
        atlas.Operation("talk", atlas.Object(say="Hello World!"), from_=name))
    s.loop()
Exemplo n.º 18
0
 def send_all(self, op):
     for client in self.clients:
         if hasattr(client, "id"):
             client.send_operation(
                 atlas.Operation("sound", op, from_=op.from_, to=client.id))
Exemplo n.º 19
0
 def send_others(self, op, original_client):
     for client in self.clients:
         if client != original_client:
             client.send_operation(
                 atlas.Operation("sound", op, from_=op.from_))
 def create_character(self, name):
     char = atlas.Object(id=name, objtype="object", parents=["character"])
     self.send_operation(atlas.Operation("create", char))
     print("ATLAS: create_character:", name)
Exemplo n.º 21
0
def default(mapeditor):
    print("Test logging")
    sys.stdout.write("Test stdout\n")
    sys.stderr.write("Test stderr\n")

    print("Test operation")
    operation = atlas.Operation("move")
    assert (len(operation) == 0)
    operation = atlas.Operation("move", atlas.Entity("1"))
    assert (len(operation) == 1)
    assert (operation[0].id == "1")
    operation = atlas.Operation("move", atlas.Entity("2"), atlas.Entity("3"))
    assert (len(operation) == 2)
    assert (operation[0].id == "2")
    assert (operation[1].id == "3")
    operation = atlas.Operation("move", atlas.Entity("4"), atlas.Entity("5"),
                                atlas.Entity("6"))
    assert (len(operation) == 3)
    assert (operation[0].id == "4")
    assert (operation[1].id == "5")
    assert (operation[2].id == "6")
    operation = atlas.Operation("move", atlas.Entity("7"), to="8", from_="9")
    assert (len(operation) == 1)
    assert (operation[0].id == "7")
    assert (operation.to == "8")
    assert (operation.from_ == "9")

    assert (operation.get_serialno() != 452)
    assert (operation.get_refno() != 567)
    assert (operation.get_from() != "10")
    assert (operation.get_to() != "11")
    assert (operation.get_seconds() != 577)
    assert (operation.get_future_seconds() != 345)

    operation.set_serialno(452)
    operation.set_refno(567)
    operation.set_from("10")
    operation.set_to("11")
    operation.set_seconds(577.5)
    operation.set_future_seconds(345.5)
    operation.set_args([atlas.Operation("set")])

    assert (operation.get_serialno() == 452)
    assert (operation.get_refno() == 567)
    assert (operation.get_from() == "10")
    assert (operation.get_to() == "11")
    assert (operation.get_seconds() == 577.5)
    assert (operation.get_future_seconds() == 345.5)
    assert (len(operation.get_args()) == 1)

    print("Test location")
    a = 1
    if atlas.isLocation(a):
        raise AssertionError("atlas.isLocation returned true on an integer")
    location = rules.Location()
    if not atlas.isLocation(location):
        raise AasertionError("atlas.isLocation returned false on a Location")

    # FIXME No current way to create an entity
    # location=rules.Location('23')
    # location=rules.Location('42', Vector3D(1,0,0))

    print("Test entity")
    entity = atlas.Entity()
    entity = atlas.Entity("1")
    assert (entity.id == "1")
    # FIXME other methods

    print("Test message")
    message = atlas.Oplist()
    assert (len(message) == 0)
    message.append(atlas.Operation("move"))
    assert (len(message) == 1)
    message = atlas.Oplist(atlas.Operation("move"))
    assert (len(message) == 1)
    # FIXME other methods

    print("Test vector")
    vector = Vector3D.Vector3D()
    vector = Vector3D.Vector3D([0, 0, 1])
    vector = Vector3D.Vector3D([0.1, 0.1, 1.1])
    vector = Vector3D.Vector3D(0, 0, 1)
    vector = Vector3D.Vector3D(0.1, 0.1, 1.1)
    # FIXME other methods

    print("Test point")
    vector = Point3D.Point3D()
    vector = Point3D.Point3D([0, 0, 1])
    vector = Point3D.Point3D([0.1, 0.1, 1.1])
    vector = Point3D.Point3D(0, 0, 1)
    vector = Point3D.Point3D(0.1, 0.1, 1.1)
Exemplo n.º 22
0
 def ask(self, id):
     op = atlas.Operation("get", atlas.Object(id=id))
     self.send_operation(op)
     self.waiting[id] = 1
Exemplo n.º 23
0
 def talk_op(self, op):
     self.reply_operation(op, atlas.Operation("sound", op, from_=op.from_))
     self.server.send_others(op, self)
Exemplo n.º 24
0
## #print str(o)

## op = atlas.Operation("move",o,from_="bah")

sock=atlas.TCPSocket()
print sock.getSock()
print "Connect:", sock.connect("localhost",6767)
xml = atlas.XMLProtocol()
codec = atlas.Codec(xml)
client = atlas.Client(sock, codec)

account = atlas.Object()
account.id="foo"
account.password="******"
op = atlas.Operation("login",account)
print str(op)

#5.64s 10000kpl
##         account = atlas.Object()
##         account.id="foo"
##         account.password="******"
##         op = atlas.Operation("login",account)
#17.42s with following added
##         s = str(op)
#10.99s with 100kpl and 100 times data=printCodec->encodeMessage(*obj->obj);
#16.28s using PackedProtocol instead of XMLProtocol
#11.03s with 100kpl and 100 times data=printCodec->encodeMessage(*obj->obj);

#4.83s libAtlasPy
##         account = Entity("foo",password="******")
Exemplo n.º 25
0
        self.bridge = Bridge(NegotiationServer(), functions=self)


class TestClient(Common):
    def __init__(self):
        Common.__init__(self)
        self.bridge = Bridge(NegotiationClient(), functions=self)


bserver = TestServer()
bclient = TestClient()
bserver.other = bclient
bclient.other = bserver

bclient.bridge.process_operation(
    atlas.Operation("talk", atlas.Object(say="Hello world!"), from_="Joe"))

if print_debug:
    print "=" * 60

bserver.bridge.process_operation(
    atlas.Operation(
        "sound",
        atlas.Operation("talk", atlas.Object(say="Hello Joe!"), from_="Joe")))

assert (bclient.data_list == [
    'ATLAS client\012',
    'ICAN Bach_beta2\012ICAN XML\012ICAN XML2_test\012ICAN Packed\012ICAN Binary1_beta\012ICAN Binary2_test\012\012',
    '[\012\011{\012\011\011arg: {\012\011\011\011say: "Hello world!"\012\011\011},\012\011\011from: "Joe",\012\011\011objtype: "op",\012\011\011parents: ["talk"]\012\011}'
])
assert (len(bclient.op_list) == 1)
Exemplo n.º 26
0
 def talk_op(self, op):
     sound_op = atlas.Operation("sound", op)
     if hasattr(op, "from_"): sound_op.from_ = op.from_
     self.server.reply_all(op, sound_op)
Exemplo n.º 27
0
 def after_connection_setup(self):
     self.send_operation(atlas.Operation("get"))
     self.verbose = 1
     self.triggers = {}
     self.pending = {}
     self.resolver = atlas.analyse.Resolver(self.objects)