Beispiel #1
0
 def redirect_user(self, user):
     """ After """
     if user is None:
         mc_client().set("temp:{0}".format(self.session_id),
                         self.user_id, time=60*5)
         self.redirect(self.get_argument("next", "/user/create"))
     else:
         mc_client().set(self.session_id, user, time=60*60*24*7)
         self.redirect(self.get_argument("next", "/lobby"))
Beispiel #2
0
def add_ship(session_id, event):
    """ Add a ship to the fleet """
    user = mc_client().get(session_id)['user_id']

    current_fleet = yield async(fleet.add_ship, user, event['fleet_id'],
                                event['ship'])
    mediator.publish_to_socketio([session_id], "hq.fleet.update",
                                 {'fleet': current_fleet})
Beispiel #3
0
    def on_open(self, request):
        session_id = request.get_cookie("session_id").value
        user = mc_client().get(session_id)

        if not user:
            mediator.register_socket(session_id, self)
            mediator.publish_to_socketio([session_id], "chat.add_message",
                                         {"message": "Please login"})
            mediator.destroy_socket(session_id)
        else:
            self.session_id = session_id
            mediator.register_socket(session_id, self)
Beispiel #4
0
    def post(self):
        username = self.get_argument('username')
        session_id = self.get_cookie("session_id")

        if username == "":
            self.write(render('create_account.html', {
                "silly_header": silly_header(),
                "message": "Don't be silly. You can think of a "
                           "better name than nothing."
            }))

        elif (len(username) > 20):
            self.write(render('create_account.html', {
                "silly_header": silly_header(),
                "message": "That's way too epic. Try a shorter nickname "
                           "(20 characters or less)."
            }))
        else:
            user = yield async(get_user_by_username, username)
            if user is None:
                user_id = mc_client().get("temp:{0}".format(session_id))
                user = yield async(add_user, user_id, username)

                user_info = {
                    "username": username,
                    "user_id": user_id
                }
                mc_client().set(session_id, user_info, time=60*60*24*7)
                self.redirect(self.get_argument("next", "/lobby"))
            else:
                self.write(render(
                    'create_account.html',
                    {
                        "silly_header": silly_header(),
                        "message": "You're not special - someone else already "
                                   " has that username. Try again."
                    }
                ))

        self.finish()
Beispiel #5
0
def say_event(session_id, event):
    """ Publish a chat message to all clients """

    data = {
        "message_type": "self_chat",
        "message": "You said: {0}".format(event['message'])
    }
    mediator.publish_to_socketio([session_id], "chat.add_message", data)

    user = mc_client().get(session_id)['username']
    data = {
        "message_type": "another_player_chat",
        "message": "{0} says: {1}".format(user, event['message'])
    }

    mediator.publish_to_socketio(mediator.get_other_users(session_id),
                                 "chat.add_message", data)
Beispiel #6
0
 def current_user(self):
     return mc_client().get(self.get_cookie('session_id'))
Beispiel #7
0
def change_name(session_id, event):
    """ Change the name of a fleet """
    user = mc_client().get(session_id)['user_id']
    yield async(fleet.change_name, user, event['fleet_id'], event['name'])
Beispiel #8
0
def get_fleet(session_id, event):
    """ Get a fleet """
    user = mc_client().get(session_id)['user_id']
    current_fleet = yield async(fleet.get_fleet, user, event['fleet_id'])
    mediator.publish_to_socketio([session_id], "hq.fleet.update",
                                 {'fleet': current_fleet})