예제 #1
0
 def __init__(self, host, port, sock=None):
     Handler.__init__(self, host, port, sock=sock)
     # ip_port is set when the peer connects to me and sends a 'join' message
     # or when I open the connection to that peer (I know the peer's ip_port)
     self.ip_port = None
     self.box = None  # updated when that player moves
     peers.add(self)
예제 #2
0
파일: peer.py 프로젝트: crista/swarch
 def __init__(self, host, port, sock=None):
     Handler.__init__(self, host, port, sock=sock)
     # ip_port is set when the peer connects to me and sends a 'join' message
     # or when I open the connection to that peer (I know the peer's ip_port)
     self.ip_port = None
     self.box = None  # updated when that player moves
     peers.add(self)
예제 #3
0
파일: bot.py 프로젝트: ronvenna/INF123
 def __init__(self):
     Handler.__init__(self,'localhost', 8888)
     print "Connected!"
     self.borders = []
     self.pellets = []
     self.players = {}
     self.myname = None
     self.game_over = False
예제 #4
0
 def __init__(self, model, view, port):
     self.host = HOST
     self.port = port
     self.model = model
     self.view = view
     self.file_writer = fileWriter.FileWriter()
     self.quit_requested = False
     self.conversation_started = False
     Handler.__init__(self, self.host, self.port) ##old style Class can't use super() constructor
예제 #5
0
 def __init__(self):
     Handler.__init__(self,'localhost', 8888)
     print "Server is connected."
     self.players = {}
     self.borders = [[0, 0, 2, 300],
                     [0, 0, 400, 2],
                     [398, 0, 2, 300],
                     [0, 298, 400, 2]]
     self.pellets = [ [randint(10, 380), randint(10, 280), 5, 5] 
                     for _ in range(4) ]
     self.myname = None
     self.game_over = False
     self.mydir = self.cmd_directions['down']  # start direction: down
     self.mybox = [200, 150, 10, 10]  # start in middle of the screen
예제 #6
0
    def on_msg(self, msg):
        if 'join' in  msg:
            handlers[self] = msg['join']
            users = ''
            for handler in handlers:
                if users == '':
                    users += handlers[handler]
                else:
                    users += ', ' + handlers[handler]
            for handler in handlers:
                handler.do_send({'join':msg['join'], 'users':users})
        elif 'speak' in msg and msg['txt'] != '':
            for handler in handlers:
                if handlers[handler] != msg['speak']:
                    handler.do_send({'name':msg['speak'], 'txt':msg['txt']})

port = 8888
server = Listener(port, MyHandler)

while 1:
    try:
        poll(timeout=0.05) # in seconds
    except KeyboardInterrupt:
        print "Closing server, Bye: "
        for client in handlers:
            print client
            Handler.do_close(handlers[client])
        print handlers.keys()

        print "Server Shutdown Complete..."
        sys.exit()
예제 #7
0
 def __init__(self, m):
     Handler.__init__(self,'localhost', 8888)
     self.m = m
예제 #8
0
 def __init__(self, host, port):
     self.directory_received = False
     Handler.__init__(self, host, port)
예제 #9
0
 def __init__(self, manager):
     host, port = 'localhost', 8888
     Handler.__init__(self, host, port)
     self.manager = manager
     self.do_send({'join': myname})
예제 #10
0
 def __init__(self, model, host, port):
     Handler.__init__(self, host, port)
     self.m = model
예제 #11
0
 def __init__(self, m):
     self.m = m
     host, port = 'localhost', 8888
     Handler.__init__(self, host, port)
예제 #12
0
파일: client.py 프로젝트: bpaff/WerewolfTag
 def __init__(self, model, host, port):
     Handler.__init__(self, host, port)
     self.m = model
예제 #13
0
파일: peer.py 프로젝트: chelseealee/swarch
 def __init__(self, host, port, sock=None):
     self.ip_port = None # set when that player sends a 'join' message
     self.box = None # updated when that player moves
     Handler.__init__(self, host, port, sock=sock)
예제 #14
0
파일: peer.py 프로젝트: chelseealee/swarch
 def __init__(self, host, port):
     self.directory_received = False
     Handler.__init__(self, host, port)
예제 #15
0
	def __init__(self, host, port):
		Handler.__init__(self, host, port)
예제 #16
0
파일: agent.py 프로젝트: delian7/inf124-irc
	def __init__(self, host, port, sock=None):
		Handler.__init__(self, host, port, sock)
		self.log = []
예제 #17
0
파일: bot.py 프로젝트: jeffs5/INFX123
 def __init__(self, model):
     Handler.__init__(self, 'localhost', 8888)   # connect asynchronously
     self.model = model
예제 #18
0
    def on_msg(self, msg):
	global whoJustWent, FirstRoundFlag
        if 'join' in msg:
            print msg['join'] + " has joined."
            handlers[msg['join']] = self

	    #calculate how many handlers are in the map
	    print "map Length: " + str(len(handlers))
	    NumberOfHandlers = len(handlers)

	    if(NumberOfHandlers >= 2):
	        key1, valueHandler1 = handlers.popitem();
	        key2, valueHandler2 = handlers.popitem();

	        print "1User: "******"2User: "******"Connected! Playing with: " +  key2}
		valueHandler1.do_send(msg)

		msg = {'txt' : "Connected! Playing with: " +  key1}
		valueHandler2.do_send(msg)

	    print "Handler Map Length: " + str(len(handlers))
	    print "MatchMaker Map Length: " + str(len(MatchMakerMap))
		
	        

            
            #need to figure out the type of what self is and need to delete the correct one
##            print handlers.keys()
        if 'txt' in msg:
            if msg['txt'] == 'quit':
                print msg['speak'] + " has left..."
                del handlers[msg['speak']]
##                print self.__class__.__name__
                Handler.do_close(self)

## handle broadcast clicking event
        if 'row_clicked' in msg:

	    #msg = {'txt' : "HelloooAfterClickFrom other player!!"}

	    #MatchMakerMap[self].do_send(msg)
	     
	    #if the same guy that just went clicked do not broadcast any change 
	    if(MatchMakerMap.has_key(self) and MatchMakerMap[self][1] == True):
	    	## broadcast to each client that has joined
	        msg = {'updateGameBoard': "", 'row_clicked': msg['row_clicked'] , 'col_clicked': msg['col_clicked']}

	        MatchMakerMap[self][0].do_send(msg)
	        MatchMakerMap[MatchMakerMap[self][0]][0].do_send(msg)

	        MatchMakerMap[self][1] = False
	        MatchMakerMap[MatchMakerMap[self][0]][1] = True 
	    elif(MatchMakerMap.has_key(self) == False):
	        msg = {'txt' : "Wait For Other Players To Automatically Connect When Avaiable"}
		self.do_send(msg)
	    else:
	        msg = {'txt' : "Not Your Turn"}
		self.do_send(msg)
예제 #19
0
	def __init__(self, host, port):
	    Handler.__init__(self, host, port)
	    print 'client built'