예제 #1
0
파일: screen.py 프로젝트: UCSD-PL/kraken
  def main(self):
    self.thread_lock = threading.Lock()

    window = gtk.Window() #gtk.WINDOW_TOPLEVEL) 
    window.set_decorated(False)
    window.set_app_paintable(True)
    screen = window.get_screen()
    rgba = screen.get_rgba_colormap()
    window.set_colormap(rgba)
    
    window.set_title("Quark Web Browser Output")
    window.set_default_size(1100,710)
    window.set_decorated(False)
    window.connect("destroy", self.window_destroyed)
    window.connect('expose-event', self.expose)
    window.move(100,300)
    self.win = window
                
    window.show_all()

    (x,y,width,height,depth) = self.win.window.get_geometry()
    self.pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False, 8, width, height)

    msg.init()
    gobject.io_add_watch(msg.KCHAN.fileno(), gobject.IO_IN, self.handle_msgs)

    gtk.main()
예제 #2
0
파일: test.py 프로젝트: UCSD-PL/kraken
def main():
    msg.init()
    while True:
        msg.send('M', 'Hello world!')
        m = msg.recv()
        print(m)
        time.sleep(1)
예제 #3
0
def main():
  msg.init()
  debug("Spawned")
  while True:
    m = msg.recv()
    s = str(m)
    try:
      if m[0] == msg.ACLoginReq:
        [_, user, password, compid, rfile, wfile] = m
        try: ok = password == credentials[user]
        except KeyError: ok = False
        if ok:
          debug(user + " logged in")
          debug("RFile: " + str(rfile))
          debug("WFile: " + str(wfile))
          msg.send(msg.ACLoginResT, user, compid, rfile, wfile)
        else:
          debug(user + " refused (wrong password)")
          msg.send(msg.ACLoginResF, user, compid)
      elif m[0] == msg.ACFileReq:
        [_, user, compid, request] = m
        try: ok = user in owners[request]
        except KeyError: ok = False
        if ok:
          debug(user + " access to " + request + " authorized")
          msg.send(msg.ACFileResT, user, compid, request)
        else:
          debug(user + " access to " + request + " refused")
          msg.send(msg.ACFileResF, user, compid, request)
      else:
        debug("Unhandled message " + s)
    except ValueError:
      debug("Unexpected payload " + s)
예제 #4
0
파일: test.py 프로젝트: UCSD-PL/kraken
def main():
  msg.init()
  while True:
    msg.send('M', 'Hello world!')
    m = msg.recv()
    print(m)
    time.sleep(1)
예제 #5
0
파일: disk.py 프로젝트: UCSD-PL/kraken
def main():
    msg.init()
    debug("Spawned")
    while True:
        m = msg.recv()
        if m[0] == msg.DFileReq:
            [_, user, compid, request] = m
            fd = open("../../../test/webserver/" + request)
            msg.send(msg.DFileRes, user, compid, request, fd)
        else:
            debug("Unhandled message " + str(m))
        debug(str(m))
예제 #6
0
파일: disk.py 프로젝트: UCSD-PL/kraken
def main():
  msg.init()
  debug("Spawned")
  while True:
    m = msg.recv()
    if m[0] == msg.DFileReq:
      [_, user, compid, request] = m
      fd = open("../../../test/webserver/" + request)
      msg.send(msg.DFileRes, user, compid, request, fd)
    else:
      debug("Unhandled message " + str(m))
    debug(str(m))
예제 #7
0
파일: client.py 프로젝트: UCSD-PL/kraken
def main():
  msg.init()
  debug("Spawned")

  m = msg.recv()
  if m[0] == msg.InitClient:
    rfile = m[1]
    wfile = m[2]
  else:
    debug("should have received InitClient message first")

  signal.signal(signal.SIGTERM, mkhandler(rfile, wfile))

  rdy = []
  while rdy == []:
    rdy, _, _ = select.select([rfile], [], [])
  data = rfile.readline()
  if data:
    req = HTTPRequest(rfile, data)
    if hasattr(req, 'path'):
      print('Resource: ' + req.path)
      msg.send(msg.FileReq, req.path)
      m = msg.recv()
      if m[0] == msg.FileRes:
        [_, name, fd] = m
        response = fd.read()
        contents = (
          "HTTP/1.0 200 OK\r\n"
          + "Content-Length: " + str(len(response)) + "\r\n"
          + "Content-Type: text/html\r\n\r\n"
          + response
        )
        debug("access to file " + name + " was authorized")
        wfile.write(contents)
      elif m[0] == msg.FileResF:
        debug("access to file " + m[1] + " was refused")
        response = "Access Forbidden"
        wfile.write(
          "HTTP/1.0 403 Forbidden\r\n"
          + "Content-Length: " + str(len(response)) + "\r\n"
          + "Content-Type: text/html\r\n\r\n"
          + response
        )
      else:
        debug("unexpected message " + str(m))

  debug('Shutting down')
  rfile.close()
  wfile.close()

  # YOU MUSTN'T DIE SOLDIER!
  while True:
    time.sleep(3600)
예제 #8
0
def main():
    msg.init()
    e = event()
    e.start()
    try:
        while True:
            #uin = raw_input("\n")
            #if uin == ':new':
            #    pass
            #msg.send(msg.NewTab)
            #else:
            #        msg.send(msg.KeyPress, uin)
            pass
    except EOFError:
        pass
예제 #9
0
def main():
  msg.init()
  e = event()
  e.start()
  try:
    while True:
      #uin = raw_input("\n")
      #if uin == ':new':
      #    pass
          #msg.send(msg.NewTab)
      #else:
#        msg.send(msg.KeyPress, uin)
          pass
  except EOFError:
    pass
예제 #10
0
파일: client.py 프로젝트: UCSD-PL/kraken
def main():
    msg.init()
    debug("Spawned")

    m = msg.recv()
    if m[0] == msg.InitClient:
        rfile = m[1]
        wfile = m[2]
    else:
        debug("should have received InitClient message first")

    signal.signal(signal.SIGTERM, mkhandler(rfile, wfile))

    rdy = []
    while rdy == []:
        rdy, _, _ = select.select([rfile], [], [])
    data = rfile.readline()
    if data:
        req = HTTPRequest(rfile, data)
        if hasattr(req, 'path'):
            print('Resource: ' + req.path)
            msg.send(msg.FileReq, req.path)
            m = msg.recv()
            if m[0] == msg.FileRes:
                [_, name, fd] = m
                response = fd.read()
                contents = ("HTTP/1.0 200 OK\r\n" + "Content-Length: " +
                            str(len(response)) + "\r\n" +
                            "Content-Type: text/html\r\n\r\n" + response)
                debug("access to file " + name + " was authorized")
                wfile.write(contents)
            elif m[0] == msg.FileResF:
                debug("access to file " + m[1] + " was refused")
                response = "Access Forbidden"
                wfile.write("HTTP/1.0 403 Forbidden\r\n" + "Content-Length: " +
                            str(len(response)) + "\r\n" +
                            "Content-Type: text/html\r\n\r\n" + response)
            else:
                debug("unexpected message " + str(m))

    debug('Shutting down')
    rfile.close()
    wfile.close()

    # YOU MUSTN'T DIE SOLDIER!
    while True:
        time.sleep(3600)
예제 #11
0
    def open(self):
        id = getRandom()
        self.player = Player(id, self)
        players[id] = self.player
        sockets[self] = id

        print 'connection opened with id =', id

        self.write_message(msg.init(id))
예제 #12
0
파일: tab.py 프로젝트: UCSD-PL/kraken
  def main(self):
    self.shm_obj = sharedmem.Shm()
    self.shm_obj.init()
    msg.init()
    gobject.io_add_watch(msg.KCHAN.fileno(), gobject.IO_IN, self.handle_msgs)

    #WK.start_gtk_thread()
    #win, box, self.browser, web_recv, web_send = (
    #  WK.synchronous_gtk_message(WK.launch_browser)('http://www.google.com'))

    self.browser = webkit.WebView()
    self.browser.connect_after('expose-event', self.expose)
    self.browser.add_events(gtk.gdk.KEY_PRESS_MASK | gtk.gdk.BUTTON_PRESS_MASK)
    win = gtk.OffscreenWindow()
    win.set_default_size(1100,700)
    win.add(self.browser)
    win.show_all()

    gtk.main()
예제 #13
0
파일: tab.py 프로젝트: UCSD-PL/kraken
    def main(self):
        self.shm_obj = sharedmem.Shm()
        self.shm_obj.init()
        msg.init()
        gobject.io_add_watch(msg.KCHAN.fileno(), gobject.IO_IN,
                             self.handle_msgs)

        #WK.start_gtk_thread()
        #win, box, self.browser, web_recv, web_send = (
        #  WK.synchronous_gtk_message(WK.launch_browser)('http://www.google.com'))

        self.browser = webkit.WebView()
        self.browser.connect_after('expose-event', self.expose)
        self.browser.add_events(gtk.gdk.KEY_PRESS_MASK
                                | gtk.gdk.BUTTON_PRESS_MASK)
        win = gtk.OffscreenWindow()
        win.set_default_size(1100, 700)
        win.add(self.browser)
        win.show_all()

        gtk.main()
예제 #14
0
def main():
    msg.init()
    debug("Spawned")
    while True:
        m = msg.recv()
        s = str(m)
        try:
            if m[0] == msg.ACLoginReq:
                [_, user, password, compid, rfile, wfile] = m
                try:
                    ok = password == credentials[user]
                except KeyError:
                    ok = False
                if ok:
                    debug(user + " logged in")
                    debug("RFile: " + str(rfile))
                    debug("WFile: " + str(wfile))
                    msg.send(msg.ACLoginResT, user, compid, rfile, wfile)
                else:
                    debug(user + " refused (wrong password)")
                    msg.send(msg.ACLoginResF, user, compid)
            elif m[0] == msg.ACFileReq:
                [_, user, compid, request] = m
                try:
                    ok = user in owners[request]
                except KeyError:
                    ok = False
                if ok:
                    debug(user + " access to " + request + " authorized")
                    msg.send(msg.ACFileResT, user, compid, request)
                else:
                    debug(user + " access to " + request + " refused")
                    msg.send(msg.ACFileResF, user, compid, request)
            else:
                debug("Unhandled message " + s)
        except ValueError:
            debug("Unexpected payload " + s)
예제 #15
0
    def open(self):
        id = getRandom()
        player = Player(id, self)
        players[id] = player
        sockets[self] = id

        print 'connection opened with id =', id

        self.write_message(msg.init(id))

        if len(free_players) != 0:
            print 'match waiting player'
            another_player = free_players.pop()
            Game(player, another_player).start()
        else:
            print 'wait for another player'
            free_players.append(player)
예제 #16
0
파일: listener.py 프로젝트: UCSD-PL/kraken
#!/usr/bin/env python2.7

import msg, socket, time
import uuid

HOST_NAME = 'localhost'  # !!!REMEMBER TO CHANGE THIS!!!
PORT_NUMBER = 9000  # Maybe set this to 9000.


def debug(s):
    print(" L: " + s)


if __name__ == '__main__':
    msg.init()
    debug("Spawned")
    s = socket.socket()
    try:
        s.bind((HOST_NAME, PORT_NUMBER))
        print time.asctime(), "Server Starts - %s:%s" % (HOST_NAME,
                                                         PORT_NUMBER)
        while True:
            s.listen(0)
            (bs, addr) = s.accept()
            debug('Accepting: ' + str(addr))
            msg.send(msg.LoginReq, 'default', ' ', str(uuid.uuid4()), bs, bs)
    except:
        s.close()
        print time.asctime(), "Server Stops - %s:%s" % (HOST_NAME, PORT_NUMBER)
예제 #17
0
파일: listener.py 프로젝트: UCSD-PL/kraken
#!/usr/bin/env python2.7

import msg, socket, time
import uuid

HOST_NAME = 'localhost' # !!!REMEMBER TO CHANGE THIS!!!
PORT_NUMBER = 9000 # Maybe set this to 9000.

def debug(s):
  print(" L: " + s)

if __name__ == '__main__':
  msg.init()
  debug("Spawned")
  s = socket.socket()
  try:
    s.bind((HOST_NAME, PORT_NUMBER))
    print time.asctime(), "Server Starts - %s:%s" % (HOST_NAME, PORT_NUMBER)
    while True:
      s.listen(0)
      (bs, addr) = s.accept()
      debug('Accepting: ' + str(addr))
      msg.send(msg.LoginReq, 'default', ' ', str(uuid.uuid4()), bs, bs)
  except:
    s.close()
    print time.asctime(), "Server Stops - %s:%s" % (HOST_NAME, PORT_NUMBER)