minor improvments
This commit is contained in:
parent
2287ddd6f1
commit
db2e6c4f15
14 changed files with 39 additions and 120 deletions
28
server.py
28
server.py
|
|
@ -11,24 +11,11 @@ import session
|
|||
HOST = "localhost"
|
||||
PORT = 8764
|
||||
|
||||
token_refs = {}
|
||||
|
||||
# Makes instance of a Messenger session for every client that connects.
|
||||
async def launch_session(token, connection):
|
||||
async def launch_session(crimata_id, connection):
|
||||
|
||||
# Create the session.
|
||||
s = session.Session(connection)
|
||||
|
||||
# Login if token.
|
||||
if token in token_refs.keys():
|
||||
crimata_id = token_refs.get(token)
|
||||
s.crimata_id = crimata_id
|
||||
|
||||
print(f"Reconnected: {crimata_id}")
|
||||
|
||||
# Update client's login token.
|
||||
intent = typs.Intent("token", params={"text": token})
|
||||
await s.send_agent_intent(intent)
|
||||
s = session.Session(connection, crimata_id)
|
||||
|
||||
# Run core loops.
|
||||
await asyncio.gather(
|
||||
|
|
@ -39,20 +26,13 @@ async def launch_session(token, connection):
|
|||
|
||||
)
|
||||
|
||||
# Update state before end.
|
||||
token_refs.update({token: s.crimata_id})
|
||||
|
||||
print("Ended session.")
|
||||
|
||||
async def main(connection, path):
|
||||
token = await connection.recv()
|
||||
|
||||
# Create Session ID if None.
|
||||
if token not in token_refs.keys():
|
||||
token = str(uuid.uuid4())
|
||||
crimata_id = await connection.recv()
|
||||
|
||||
# Start session with token.
|
||||
await launch_session(token, connection) #! Not stopping on disconnect
|
||||
await launch_session(crimata_id, connection) #! Not stopping on disconnect
|
||||
|
||||
# Run run for every new connection.
|
||||
async def lift():
|
||||
|
|
|
|||
Loading…
Reference in a new issue