From 48f7fa6b11a0a6b1526c54914e60ddbe51ede8c4 Mon Sep 17 00:00:00 2001 From: attilamolnar Date: Sun, 14 Apr 2013 18:20:02 +0200 Subject: Extract UID/SID generation logic into a new class: UIDGenerator --- include/uid.h | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'include/uid.h') diff --git a/include/uid.h b/include/uid.h index 3783e7ada..8be003628 100644 --- a/include/uid.h +++ b/include/uid.h @@ -25,3 +25,35 @@ */ #define UUID_LENGTH 10 +class TestSuite; + +class CoreExport UIDGenerator +{ + friend class TestSuite; + + /** Holds the current UID. Used to generate the next one. + */ + char current_uid[UUID_LENGTH]; + + /** Increments the current UID by one. + */ + void IncrementUID(unsigned int pos); + + public: + /** Initializes this UID generator with the given SID + * @param sid SID that conforms to InspIRCd::IsSID() + */ + void init(const std::string& sid); + + /** Returns the next available UID for this server. + */ + std::string GetUID(); + + /** Generates a pseudorandom SID based on a servername and a description + * Guaranteed to return the same if invoked with the same parameters + * @param servername The server name to use as seed + * @param serverdesc The server description to use as seed + * @return A valid SID + */ + static std::string GenerateSID(const std::string& servername, const std::string& serverdesc); +}; -- cgit v1.2.3