def parse_friend_connecting(self, value):
     a = value.split(',')
     friend_username = a[0]
     ip = a[1]
     port = a[2]
     print 'friend connecting: ' + friend_username + ' at ' + ip + ':'+  port
     
     friend = Shared.get_friend_by_username(friend_username)
     if friend:
         friend.sock = Shared.server.sock
         Shared.server.create_new_socket()
         Shared.server.login()
         threading.Thread(target=friend.start_punching, args=[(ip, int(port))]).start()
     else:
         print 'Connecting friend is not on friends list'
 def parse(self, input):
     if input.strip() == 'exit':
         return True
     if input.strip() == 'help':
         print '''\nAvailable commands:
 > connect to friend: friend_username
 > send: friend_username: message to send
 > friend request: friend_username
 > accept friend request: friend_username
 > decline friend request: friend_username
 '''
         return False
         
     a = input.split(':')
     a[0] = a[0].lower().strip()
     a[1] = a[1].strip()
     
     
     #connect to friend: friend_username
     if a[0].startswith('connect to friend'):
         Shared.server.message(OpCodes.connect_to_friend, a[1])
     
     #send: friend_username: message to send
     elif a[0].startswith('send'):
         friend = Shared.get_friend_by_username(a[1])
         if friend:
             friend.message(input[input.find(':',input.find(':')+1) + 1:])
         else:
             print 'User ' + a[1] + ' not on friends list'
     
     #send friend request: friend_username
     elif a[0].startswith('friend request'):
         Shared.server.message(OpCodes.send_friend_request, a[1])
     
     #accept friend request: friend_username
     elif a[0].startswith('accept friend request'):
         Shared.server.message(OpCodes.accept_friend_request, a[1])
         Shared.friends_list.append(Friend.Friend(a[1], True))
     
     #decline friend request: friend_username
     elif a[0].startswith('decline friend request'):
         Shared.server.message(OpCodes.decline_friend_request, a[1])
         
     return False
 def parse_friend_state_changed(self, value):
     friend_username, state = value.split(',')
     friend = Shared.get_friend_by_username(friend_username)
     if friend:
         print 'Friend ' + friend_username + ' is now ' + state
         friend.change_state(state)