Beispiel #1
0
 def auth(self):
     """auth the client."""
     if self.client in status.LOBBY:
         character = self.load_character(self.name)
         if character:
             if character.get_password() == self.password:
                 origin_player = None
                 #. check current in game?
                 if self.player_was_login(self.name):
                     self.client.send('\nThis name was login, kick the user!\n')
                     origin_player = self.get_origin_player()
                     character = copy.deepcopy(origin_player.character) #. copy the character object, because the origin character object wiil be drop
                 #. send notice to origin player
                 if origin_player:
                     origin_player.send("Somebody login from %s, see you again!\n" % (self.client.addrport()) )
                     #. drop origin Player
                     SCHEDULER.add(.2, origin_player.deactivate)
                 #. become player
                 self.promote(character)
                 broadcast('%s enter the world.\n' % self.name )
                 print ('** Client %s login success with name: %s.' % (self.client.addrport(), self.name))
                 return True
             else:
                 print ('!! Client %s login fail with name: %s.' % (self.client.addrport(), self.client) )
                 return False
     return False
Beispiel #2
0
 def check_retry(self):
     """check if reach to RETRY_LIMIT"""
     if not self.quit and self.retry >= RETRY_LIMIT:
         self.quit = True
         self.client.send("Retry too many times, bye!\n")
         print "!! Client reach to the login limit: %s, kicking! " % (RETRY_LIMIT)
         SCHEDULER.add(.2, self.client.deactivate)
Beispiel #3
0
def quit(player, args):
    """
    exit the game.
    useage: quit
    """
    player.send('\nSee you next time ! \n')
    SCHEDULER.add(.2, player.deactivate)
Beispiel #4
0
def kick_idle():
    """
    Looks for idle clients and disconnects them by setting active to False.
    """
    #. TODO: clean reconnecnt sessions 
    for player in status.PLAYERS.values():
        if player.idle() > status.IDLE_TIMEOUT:
            print('-- Kicking idle lobby client from %s' % player.addrport())
            player.send('Idle timeout, see you next time!\n')
            SCHEDULER.add(.2, player.deactivate)
Beispiel #5
0
def dump_status():
    """docstring for dump_status"""
    print ""
    print "DEBUG - LOBBY:%s" % (status.LOBBY)
    print "DEBUG - _PLAYERS:%s" % (status._PLAYERS)
    print "DEBUG - PLAYERS:%s" % (status.PLAYERS)
    print "DEBUG - SCHEDULER:%s" % (SCHEDULER.get_events())
    for map_ in status.WORLD.get_maps():
        print "DEBUG - %s" % (repr(map_))
    print "DEBUD - %s" % (status.LANG)
    print ""
Beispiel #6
0
#       Initial Cycles
#------------------------------------------------------------------------------
    Cycle(.1, process_lobby)
    Cycle(.1, process_players)
    Cycle(2, kick_idle)
    Cycle(5, fight)
    Cycle(10, mob_actions)
    #Cycle(2, dump_status)

#------------------------------------------------------------------------------
#       Initial Telnet Server
#------------------------------------------------------------------------------
    telnet_server = TelnetServer(
        port=status.SERVER_CONFIG.port,
        address=status.SERVER_CONFIG.address,
        on_connect=on_connect,
        on_disconnect=on_disconnect,
        timeout=status.SERVER_CONFIG.timeout,
        )
    print(">> Listening for connections on port %d.  CTRL-C to break."
        % telnet_server.port)

#------------------------------------------------------------------------------
#       Main Server Loop
#------------------------------------------------------------------------------
    while status.SERVER_RUN:
        telnet_server.poll()
        SCHEDULER.tick()

    print(">> Server shutdown.")