diff options
| author | 2023-11-05 19:03:42 +0000 | |
|---|---|---|
| committer | 2023-11-05 19:03:42 +0000 | |
| commit | 94dbb3872a43eeb0130ef5c0e1eaf44cfa5a61e5 (patch) | |
| tree | a15eb073803830c8ee66675a414b63c87d4e9935 /include/clientprotocol.h | |
| parent | Merge branch 'insp3' into master. (diff) | |
| parent | When copying a message also copy the source string. (diff) | |
Merge branch 'insp3' into master.
Diffstat (limited to 'include/clientprotocol.h')
| -rw-r--r-- | include/clientprotocol.h | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/include/clientprotocol.h b/include/clientprotocol.h index e9f3c0ad5..465b00b30 100644 --- a/include/clientprotocol.h +++ b/include/clientprotocol.h @@ -92,8 +92,10 @@ public: class CoreExport ClientProtocol::MessageSource { + protected: User* sourceuser; const std::string* sourcestr; + bool sourceowned:1; public: /** Constructor, sets the source to be the full host of a user or sets it to be nothing. @@ -102,10 +104,17 @@ public: * Optional, defaults to NULL. */ MessageSource(User* Sourceuser = nullptr) + : sourceowned(false) { SetSourceUser(Sourceuser); } + ~MessageSource() + { + if (sourceowned && sourcestr) + delete sourcestr; + } + /** Constructor, sets the source to the supplied string and optionally sets the source user. * @param Sourcestr String to use as message source for serialization purposes. Must remain valid * as long as this object is alive. @@ -114,6 +123,7 @@ public: * Useful when the source string is synthesized but it is still related to a User. */ MessageSource(const std::string& Sourcestr, User* Sourceuser = nullptr) + : sourceowned(false) { SetSource(Sourcestr, Sourceuser); } @@ -462,6 +472,12 @@ public: ReplaceParam(idx, param); idx++; } + + if (GetSource()) + { + sourcestr = new std::string(*GetSource()); + sourceowned = true; + } } void SetSideEffect(bool Sideeffect) { sideeffect = Sideeffect; } |
