Ejemplo n.º 1
0
def main(argv):
    c = Client("Coders blackboard client", args2address(argv))
    print "Connecting..."
    c.connect_and_negotiate()
    print "ok"
    app = BlackboardApp("Blackbord", c)
    c.after_connection_setup()
    app.MainLoop()
Ejemplo n.º 2
0
def main(argv):
    c = Client("Coders blackboard client", args2address(argv))
    print "Connecting..."
    c.connect_and_negotiate()
    print "ok"
    app = BlackboardApp("Blackbord", c)
    c.after_connection_setup()
    app.MainLoop()
Ejemplo n.º 3
0
def main(argv):
    c = Client("Coders map client", args2address(argv))
    print "Connecting..."
    c.connect_and_negotiate()
    print "ok"
    app = MapClientApp("Coders map client", c)
    c.after_connection_setup()
    app.register_triggers()
    app.MainLoop()
Ejemplo n.º 4
0
            self.server.reply_all(op, atlas.Operation("info", op))
        self.server.save()

    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
        if obj == None:
            self.send_error(op, "no object with id " + op.arg.id)
        self.server.save()


if __name__ == "__main__":
    try:
        s = SimpleCoreServer(server_name, args2address(sys.argv), SimpleCoreClient)
        s.loop()
    except KeyboardInterrupt:
        s.log.close()
Ejemplo n.º 5
0
            if hasattr(client, "id") and client.id == id:
                return 1
        return 0


class ChatClient(TcpClient):
    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))

    create_op = login_op

    def talk_op(self, op):
        ##        if hasattr(self, "id"):
        ##            op.from_ = self.id
        ##            self.server.send_all(op)
        if hasattr(self, "id") and not op.from_:
            op.from_ = self.id
        self.server.send_all(op)


if __name__ == "__main__":
    s = ChatServer("Simple OOG chat server", args2address(sys.argv),
                   ChatClient)
    s.loop()
#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()
Ejemplo n.º 7
0
        self.str_op = str(op)
        if print_debug:
            print(repr(str(op)))

    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()


tserver = TestServer("test server", args2address(sys.argv), TestConnection)

res = os.fork()
if res == 0:
    tclient = TestClient("test client", args2address(sys.argv))
    tclient.connect_and_negotiate()
    tclient.loop()
    assert (
        tclient.str_op ==
        '{\012\011arg: {\012\011\011arg: {\012\011\011\011say: "Hello Joe!"\012\011\011},\012\011\011from: "Joe",\012\011\011objtype: "op",\012\011\011parents: ["talk"]\012\011},\012\011from: "Joe",\012\011objtype: "op",\012\011parents: ["sound"]\012}\012'
    )
    if print_debug:
        print("client exits")
else:
    tserver.loop()
    assert (
Ejemplo n.º 8
0
ICAN Bach_beta2

[
{parents:["get"], objtype:"op"}
]
""" #"


class File2ClientServer(SocketServer):
    def setup(self):
        self.objects = read_file(file_name)


class FeedClient(TcpClient):
    def setup(self):
        self.done = 0
        print "??"

    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


if __name__ == "__main__":
    s = File2ClientServer(server_name, args2address(sys.argv), FeedClient)
    s.loop()
Ejemplo n.º 9
0
#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


import sys
sys.path.append("..")
from atlas.transport.TCP.server import SocketServer, TcpClient
import atlas
from atlas.transport.connection import args2address


class HelloWorldServer(SocketServer):
    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_))

class HelloWorldClient(TcpClient):
    def talk_op(self, op):
        self.reply_operation(op, atlas.Operation("sound", op, from_ = op.from_))
        self.server.send_others(op, self)


if __name__=="__main__":
    s = HelloWorldServer("Hello World server", args2address(sys.argv), HelloWorldClient)
    s.loop()
Ejemplo n.º 10
0
simple_core_server.save_file_name = "simple_world_save%i.atlas"
simple_core_server.log_file_name = "simple_world_log.atlas"
simple_core_server.server_name = "Simple world server"
simple_core_server.server_id = "simple_world_server"


class SimpleWorldServer(simple_core_server.SimpleCoreServer):
    pass

class SimpleWorldClient(simple_core_server.SimpleCoreClient):
    def setup(self):
        self.comm_log = open(self.id + ".log", "w")
    
    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)

    def login_op(self, op):
        self.create_op(op)

    def look_op(self, op):
        self.get_op(op, reply_op_parent="sight")

if __name__=="__main__":
    try:
        s = SimpleWorldServer(simple_core_server.server_name, args2address(sys.argv), SimpleWorldClient)
        s.loop()
    except KeyboardInterrupt:
        s.log.close()
Ejemplo n.º 11
0
"""
ATLAS telnet client
ICAN Bach_beta2

[
{parents:["get"], objtype:"op"}
]
""" #"

class File2ClientServer(SocketServer):
    def setup(self):
        self.objects = read_file(file_name)

class FeedClient(TcpClient):
    def setup(self):
        self.done = 0
        print "??"
    
    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

if __name__=="__main__":
    s = File2ClientServer(server_name, args2address(sys.argv), FeedClient)
    s.loop()
Ejemplo n.º 12
0
#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

import sys
sys.path.append("..")
from atlas.transport.TCP.server import SocketServer, TcpClient
import atlas
from atlas.transport.connection import args2address


class HelloWorldServer(SocketServer):
    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_))


class HelloWorldClient(TcpClient):
    def talk_op(self, op):
        self.reply_operation(op, atlas.Operation("sound", op, from_=op.from_))
        self.server.send_others(op, self)


if __name__ == "__main__":
    s = HelloWorldServer("Hello World server", args2address(sys.argv),
                         HelloWorldClient)
    s.loop()
Ejemplo n.º 13
0
from atlas.transport.connection import args2address
import atlas
from atlas.transport.file import read_and_analyse
"""
Usage elsewhere than Atlas-Python directory:
export PYTHONPATH=where_Atlas-Python_resides
copy atlas.bach to directory you run it or modify filename in code
"""


class MediaServer(SocketServer):
    def setup(self):
        #self.objects = read_and_analyse("media.bach")
        self.objects = read_and_analyse("simple_core.atlas")
        print len(self.objects), "objects loaded"


class MediaClient(TcpClient):
    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)


if __name__ == "__main__":
    s = MediaServer("Simple media server", args2address(sys.argv), MediaClient)
    s.loop()
Ejemplo n.º 14
0
from atlas.transport.TCP.client import TcpClient
from atlas.transport.connection import args2address
import atlas

class Client(TcpClient):
    def setup(self):
        self.waiting = {}

    def ask(self, id):
        op = atlas.Operation("get", atlas.Object(id=id))
        self.send_operation(op)
        self.waiting[id] = 1
        
    def info_op(self, op):
        ent = op.arg
        print ent
        del self.waiting[ent.id]
        for id in ent.children:
            self.ask(id)

    def loop(self):
        self.ask("root")
        while self.waiting:
            time.sleep(0.1)
            self.process_communication()

if __name__=="__main__":
    s = Client("Inheritance hierarchy fetch client", args2address(sys.argv))
    s.connect_and_negotiate()
    s.loop()
Ejemplo n.º 15
0
            self.server.reply_all(op, atlas.Operation("info", op))
        self.server.save()

    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
        if obj == None:
            self.send_error(op, "no object with id " + op.arg.id)
        self.server.save()

if __name__ == "__main__":
    try:
        s = SimpleCoreServer(server_name, args2address(sys.argv),
                             SimpleCoreClient)
        s.loop()
    except KeyboardInterrupt:
        s.log.close()
Ejemplo n.º 16
0
simple_core_server.server_id = "simple_world_server"


class SimpleWorldServer(simple_core_server.SimpleCoreServer):
    pass


class SimpleWorldClient(simple_core_server.SimpleCoreClient):
    def setup(self):
        self.comm_log = open(self.id + ".log", "w")

    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)

    def login_op(self, op):
        self.create_op(op)

    def look_op(self, op):
        self.get_op(op, reply_op_parent="sight")


if __name__ == "__main__":
    try:
        s = SimpleWorldServer(simple_core_server.server_name,
                              args2address(sys.argv), SimpleWorldClient)
        s.loop()
    except KeyboardInterrupt:
        s.log.close()
Ejemplo n.º 17
0
        self.str_op = str(op)
        if print_debug:
            print repr(str(op))

    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()


tserver = TestServer("test server", args2address(sys.argv), TestConnection)

res = os.fork()
if res==0:
    tclient = TestClient("test client", args2address(sys.argv))
    tclient.connect_and_negotiate()
    tclient.loop()
    assert(tclient.str_op=='{\012\011arg: {\012\011\011arg: {\012\011\011\011say: "Hello Joe!"\012\011\011},\012\011\011from: "Joe",\012\011\011objtype: "op",\012\011\011parents: ["talk"]\012\011},\012\011from: "Joe",\012\011objtype: "op",\012\011parents: ["sound"]\012}\012')
    if print_debug:
        print "client exits"
else:
    tserver.loop()
    assert(tserver.str_op=='{\012\011arg: {\012\011\011say: "Hello world!"\012\011},\012\011from: "Joe",\012\011objtype: "op",\012\011parents: ["talk"]\012}\012')
    if print_debug:
        print "server exits"
    os.wait()
Ejemplo n.º 18
0
#This library is free software; you can redistribute it and/or
#modify it under the terms of the GNU Lesser General Public
#License as published by the Free Software Foundation; either
#version 2.1 of the License, or (at your option) any later version.

#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

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 = raw_input("Nick/Name to use: ")
    s.send_operation(atlas.Operation("talk", atlas.Object(say="Hello World!"), from_ = name))
    s.loop()
Ejemplo n.º 19
0
import atlas


class Client(TcpClient):
    def setup(self):
        self.waiting = {}

    def ask(self, id):
        op = atlas.Operation("get", atlas.Object(id=id))
        self.send_operation(op)
        self.waiting[id] = 1

    def info_op(self, op):
        ent = op.arg
        print ent
        del self.waiting[ent.id]
        for id in ent.children:
            self.ask(id)

    def loop(self):
        self.ask("root")
        while self.waiting:
            time.sleep(0.1)
            self.process_communication()


if __name__ == "__main__":
    s = Client("Inheritance hierarchy fetch client", args2address(sys.argv))
    s.connect_and_negotiate()
    s.loop()
Ejemplo n.º 20
0
        for client in self.clients:
            if hasattr(client, "id") and client.id == id:
                return 1
        return 0

class ChatClient(TcpClient):
    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))

    create_op = login_op

    def talk_op(self, op):
##        if hasattr(self, "id"):
##            op.from_ = self.id
##            self.server.send_all(op)
        if hasattr(self, "id") and not op.from_:
            op.from_ = self.id
        self.server.send_all(op)

if __name__=="__main__":
    s = ChatServer("Simple OOG chat server", args2address(sys.argv), ChatClient)
    s.loop()
Ejemplo n.º 21
0
sys.path.append("..")
from atlas.transport.TCP.server import SocketServer, TcpClient
from atlas.transport.connection import args2address
import atlas
from atlas.transport.file import read_and_analyse

"""
Usage elsewhere than Atlas-Python directory:
export PYTHONPATH=where_Atlas-Python_resides
copy atlas.bach to directory you run it or modify filename in code
"""

class MediaServer(SocketServer):
    def setup(self):
        #self.objects = read_and_analyse("media.bach")
        self.objects = read_and_analyse("simple_core.atlas")
        print len(self.objects), "objects loaded"

class MediaClient(TcpClient):
    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)

if __name__=="__main__":
    s = MediaServer("Simple media server", args2address(sys.argv), MediaClient)
    s.loop()