Merge branch 'fixes' into main/rendor-staging
[ryzomcore.git] / ryzom / common / src / game_share / shard_names.h
blob5b43c183ec14b1c5e50c8582fcc2216f9c6c9530
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #ifndef SHARD_NAMES_H
19 #define SHARD_NAMES_H
21 #include "nel/misc/types_nl.h"
22 #include "nel/misc/config_file.h"
23 #include "nel/misc/singleton.h"
24 #include "game_share/r2_basic_types.h"
27 /** This class provide a standard way to deal with shard names.
28 * It allow to convert from shardID to shard name and vice versa
29 * as well as to build or parse full character name (ie. character names
30 * that include the shard name).
32 class CShardNames : public NLMISC::CSingleton<CShardNames>
34 public:
35 struct TSessionName
37 /// The home mainland session Id for this shard
38 TSessionId SessionId;
39 /// Display name, as displayed in user interface and appended to player character names
40 std::string DisplayName;
41 /// pre mapped name (in string mapper)
42 NLMISC::TStringId DisplayNameId;
43 /// short name used in user commands like "/tell [<shortName>.]<userName>"
44 std::string ShortName;
47 // This container is just a vector because it is very small and brute force parsing will be faster
48 typedef std::vector<TSessionName> TSessionNames;
49 private:
50 /// Table of home session names
51 TSessionNames _SessionNames;
53 /// Typically For Shard when no SU, do not append () in makeFullName() if the session is not found
54 bool _AppendParenthesisWhenSessionNotFound;
56 public:
58 /** ctor */
59 CShardNames()
61 _AppendParenthesisWhenSessionNotFound= true;
64 /** init the shard names by reading the content of "HomeMainlandNames" var
66 void init(NLMISC::CConfigFile &configFile);
68 /** Build as a vector of string, for serial or message of the shardname configuration
70 void saveShardNames(std::vector<std::string> &outData) const;
72 /** Load as a vector of string, for serial or message of the shardname configuration
74 void loadShardNames(const std::vector<std::string> &inData);
76 /** Return the vector of names session */
77 const TSessionNames &getSessionNames() const
79 return _SessionNames;
82 /** Return the name of the shard, empty string if no match is found */
83 const std::string &getShardName(TSessionId shardId);
85 /** Return the index in the shard names table of the shard. Return 0xffffffff if shard is not found */
86 uint32 getShardIndex(TSessionId shardId);
88 /** Return the shard/session id from i the shard name. Return 0 if no match is found*/
89 TSessionId getShardId(const std::string &shardName);
91 /** Parse the submitted character name using the submitted context and
92 * return the deduced character short name and character home session Id
93 * Input name can be :
94 * - a short name, session id is deduced to be the same as context session id
95 * - a located name (<shortShardName>.<characterName> : the session is
96 * is deduced from the short shard name
97 * - a full name (<characterName>(<shardName>) : the session is deduced
98 * from the shard name.
100 void parseRelativeName(TSessionId contextSessionId, const std::string &inputCharName, std::string &outCharName, TSessionId &outSessionId);
102 /** Build a full player name according to it's name and home session id
103 * The returned name as the following format :
104 * <characterName>'('<sessionName>')'
105 * If no shard name is found for the given session id, then
106 * an empty parenthesys pair is returned (e.g. "toto()" )
108 std::string makeFullName(const std::string &charName, TSessionId homeSessionId);
110 /** Build a full name by parsing a relative name (a helper that make
111 * use of parseRelativeName() and makeFullName() to build
112 * a full name from a relative name in only 1 call.
114 std::string makeFullNameFromRelative(TSessionId contextSessionId, const std::string &inputcharName);
120 #endif // SHARD_NAMES_H