github / src / session.py @ master
1 |
# Copyright (c) 2016-2020, LE GOFF Vincent
|
---|---|
2 |
# All rights reserved.
|
3 |
|
4 |
# Redistribution and use in source and binary forms, with or without
|
5 |
# modification, are permitted provided that the following conditions are met:
|
6 |
|
7 |
# * Redistributions of source code must retain the above copyright notice, this
|
8 |
# list of conditions and the following disclaimer.
|
9 |
|
10 |
# * Redistributions in binary form must reproduce the above copyright notice,
|
11 |
# this list of conditions and the following disclaimer in the documentation
|
12 |
# and/or other materials provided with the distribution.
|
13 |
|
14 |
# * Neither the name of ytranslate nor the names of its
|
15 |
# contributors may be used to endorse or promote products derived from
|
16 |
# this software without specific prior written permission.
|
17 |
|
18 |
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
19 |
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
20 |
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
21 |
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
22 |
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
23 |
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
24 |
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
25 |
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
26 |
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
27 |
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
28 |
|
29 |
"""This file contains the Session class."""
|
30 |
|
31 |
from log import client as log |
32 |
from sharp.engine import SharpScript |
33 |
|
34 |
class Session: |
35 |
|
36 |
"""A class representing a session.
|
37 |
|
38 |
A session is an object linking together a world, a client and the
|
39 |
GUI tab behind it. Several sessions can be connected to the same
|
40 |
world, using various clients.
|
41 |
|
42 |
"""
|
43 |
|
44 |
current_sid = 0
|
45 |
|
46 |
def __init__(self, client, world): |
47 |
self.sid = self.current_sid |
48 |
type(self).current_sid += 1 |
49 |
self.client = client
|
50 |
self.world = world
|
51 |
self.character = None |
52 |
self.engine = None |
53 |
self._sharp_engine = None |
54 |
|
55 |
def __repr__(self): |
56 |
return f"<Session {self.sid} to the world {self.world and self.world.name or 'unknown'}>" |
57 |
|
58 |
@property
|
59 |
def sharp_engine(self): |
60 |
if self._sharp_engine: |
61 |
return self._sharp_engine |
62 |
|
63 |
log.debug(f"Creating a SharpEngine for session {self.sid} (world: {'yes' if self.world else 'no'}, client: {'yes' if self.client else 'no'}, character: {'yes' if self.character else 'no'}, engine: {'yes' if self.engine else 'no'})")
|
64 |
self._sharp_engine = SharpScript(self.engine, self.client, self.world) |
65 |
return self._sharp_engine |