Compare commits

...

4 Commits

Author SHA1 Message Date
Tristan B. Velloza Kildaire 0ff10c3e47 Session
- Added some TODOs
2023-11-26 14:06:21 +02:00
Tristan B. Velloza Kildaire 398dae480b Connection
- Added some TODOs
2023-11-26 14:06:13 +02:00
Tristan B. Velloza Kildaire 2b95cc3410 Session
- Added a `toString()`
2023-11-26 13:56:51 +02:00
Tristan B. Velloza Kildaire 6841da02ea Server
- Check first that the `Session*` is not `null` and then continue
- Added debug prints for both cases
2023-11-26 13:53:04 +02:00
3 changed files with 37 additions and 8 deletions

View File

@ -111,6 +111,8 @@ public class Connection : Thread
logger.dbg("There was no response, not sending anything.");
}
}
// TODO: Call cleanup+notify server
}
// FIXME: These should be part of the auth details
@ -396,9 +398,9 @@ public class Connection : Thread
import renaissance.server.messagemanager : Message;
public bool incomingMessage(Message message)
{
// TODO: Implement message
logger.info("Delivering message '", message, "' to this link (", this, ")");
// TODO: Implement message
return true;
}

View File

@ -4,7 +4,7 @@ import renaissance.connection.connection : Connection;
import renaissance.server.users : User;
import core.sync.mutex : Mutex;
import renaissance.logging;
import std.conv : to;
// TODO: One of these should be opened as soon as auth is
// ... done and stored in server so as to be able to map to it
@ -87,6 +87,22 @@ public struct Session
return this.links.dup;
}
public string toString()
{
// Lock the session
this.lock.lock();
// On exit
scope(exit)
{
// Unlock the session
this.lock.unlock();
}
// TODO: Use getLinks() rather and getUser() (both should be MT sfae, make the latter exist+MTSafe)
return "Session [user: "~to!(string)(this.user)~", links: "~to!(string)(this.links.length)~"]";
}
}
public class SessionManager

View File

@ -342,16 +342,27 @@ public class Server : MessageDeliveryTransport
// Obtain the session of the destination user
Session* toSession = this.sessionManager.getSession(curDest);
// TODO: Handle case where user is offline (no Connection[]s)
// ... the message manager must do this if false is returned
foreach(Connection toLink; toSession.getLinks())
// If such a session exists (TODO (Case?): In case all links went off line? - not yet implemented)
if(toSession != null)
{
logger.dbg("Delivering message '", latest, "' to link ", toLink, " of user '", curDest, "'");
if(!toLink.incomingMessage(latest))
logger.dbg("Mapped user ", *curDest, " to session ", *toSession);
// TODO: Handle case where user is offline (no Connection[]s)
// ... the message manager must do this if false is returned
foreach(Connection toLink; toSession.getLinks())
{
// TODO: Handle failed message?
logger.dbg("Delivering message '", latest, "' to link ", toLink, " of user '", curDest, "'");
if(!toLink.incomingMessage(latest))
{
// TODO: Handle failed message?
}
}
}
// If the suer could not be mapped to a session
else
{
logger.error("Could not map user ", *curDest, " to a session");
}
}