コード例 #1
0
ファイル: session.py プロジェクト: nelodvn/corvogame
 def __init__(self, unknown_connection):
     self.username = unknown_connection.username
     ClientHandler.__init__(self, unknown_connection.socket)
     self.obuffer = self.obuffer + unknown_connection.obuffer
     self.message_handler = unknown_connection.message_handler
     self.read_handler = self.handle_session_messages
     self.incoming_message_handler = None
コード例 #2
0
ファイル: session.py プロジェクト: igoralmeida/corvogame
 def __init__(self, unknown_connection):
     self.username = unknown_connection.username
     ClientHandler.__init__(self, unknown_connection.socket)
     self.obuffer = self.obuffer + unknown_connection.obuffer
     self.message_handler = unknown_connection.message_handler
     self.read_handler = self.handle_session_messages
     self.incoming_message_handler = None
     self.user_id = uuid.uuid1().get_hex()
     self.close_handler = None
     self.data_holder = {}
     self.message_validators =  {}
コード例 #3
0
ファイル: session.py プロジェクト: igoralmeida/corvogame
    def shutdown(self):
        logging.debug("shutdown, close handler is {0}".format(self.close_handler))

        if self.close_handler:
            self.close_handler(self)

        ClientHandler.shutdown(self)

        self.message_handler = None
        self.read_handler = None
        self.incoming_message_handler = None
        self.close_handler = None
コード例 #4
0
    def __init__(self, ip, port, sock = None):
        ClientHandler.__init__(self)

        self.message_handler = Handler("\r\n")
        self.action_handlers = { "connection_response" : self.handle_connection_response , 
                                 'session_logon' : self.handle_session_logon, 
                                 'ping' : self.handle_ping, 
                                 'lobby_session_logon' : self.session_logon,
                                 'lobby_info' : self.handle_lobby_info,
                                 'logon_response' : self.handle_session_logon,
                                 'lobby_create_game' : self.handle_game_create,
                                 'wargame_lobby_join' : self.handle_join_game,
                                 'wargame_startup_info' : self.handle_startup_info,
                                 'wargame_handshake' : self.handle_wargame_handshake }

        lobby_actions = [ ('say something' , { 'action' : 'lobby_chat', 'fields' : [ ('message', str, True) ] }),
                          ('create game' , { 'action' : 'lobby_create_game', 'fields' : [('game_type', str, True), ('room_name', str, True) ] } ),
                          ('join game', { 'action' : 'lobby_join_game' , 'fields' : [('room_id', str, True) ] } )  ]
        
        game_lobby_actions  = [ ('say something' , { 'action' : 'wargame_lobby_chat', 'fields' : [ ('message', str, True) ] }),
                                ('change color', { 'action' : 'wargame_lobby_set_self_color', 'fields' : [ ('color', str, True) ] } ),
                                ('set ready' , { 'action' : 'wargame_lobby_set_self_ready', 'fields' : [ ('ready', str, True) ] }),
                                ('start game', { 'action' : 'wargame_lobby_start_game' , 'fields' : [] } )]
        
        in_game_actions = [ ('remove a piece', {'action' : 'wargame_remove_piece', 'fields' : [ ('from', str, True) , ('quantity', int, True ) ] } ),
                            ('add a piece', {'action' : 'wargame_add_piece', 'fields' : [ ('to', str, True) , ('quantity', int, True ) ] } ),
                            ('say something' , { 'action' : 'wargame_chat', 'fields' : [ ('message', str, True ) ] } ),
                            ('attack a land', {'action' : 'wargame_attack_land', 'fields' : [ ('quantity', str, True), ('from', str, True), ('to', str, True) ] } ),
                            ('end turn' , { 'action' : 'wargame_end_turn', 'fields' : [] }  ) ]                                               
        
        self.menu = [ lobby_actions, game_lobby_actions, in_game_actions ]
        
        self.current_state = self.LOBBY
        
        self.read_handler = self.handle_message

        self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
        self.connect((ip , port))
        
        self.showing_menu = False
コード例 #5
0
ファイル: session.py プロジェクト: nelodvn/corvogame
 def write(self, message):
     logging.debug("Writting message {0} to user {1}".format(message, self.username))
     ClientHandler.write(self, self.message_handler.to_string(message))
コード例 #6
0
 def write(self, message):
     ClientHandler.write(self, self.message_handler.to_string(message))