本文整理汇总了C++中AString::compare方法的典型用法代码示例。如果您正苦于以下问题:C++ AString::compare方法的具体用法?C++ AString::compare怎么用?C++ AString::compare使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AString
的用法示例。
在下文中一共展示了AString::compare方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: StringToBiome
EMCSBiome StringToBiome(const AString & a_BiomeString)
{
// If it is a number, return it:
int res = atoi(a_BiomeString.c_str());
if ((res != 0) || (a_BiomeString.compare("0") == 0))
{
if ((res >= biFirstBiome) && (res < biNumBiomes))
{
return (EMCSBiome)res;
}
else if ((res >= biFirstVariantBiome) && (res < biNumVariantBiomes))
{
return (EMCSBiome)res;
}
// It was an invalid number
return biInvalidBiome;
}
for (size_t i = 0; i < ARRAYCOUNT(g_BiomeMap); i++)
{
if (NoCaseCompare(g_BiomeMap[i].m_String, a_BiomeString) == 0)
{
return g_BiomeMap[i].m_Biome;
}
} // for i - BiomeMap[]
return biInvalidBiome;
}
示例2: LoadWorlds
void cRoot::LoadWorlds(void)
{
cIniFile IniFile("settings.ini"); IniFile.ReadFile();
// First get the default world
AString DefaultWorldName = IniFile.GetValueSet("Worlds", "DefaultWorld", "world");
m_pDefaultWorld = new cWorld( DefaultWorldName.c_str() );
m_WorldsByName[ DefaultWorldName ] = m_pDefaultWorld;
// Then load the other worlds
unsigned int KeyNum = IniFile.FindKey("Worlds");
unsigned int NumWorlds = IniFile.GetNumValues( KeyNum );
if (NumWorlds <= 0)
{
return;
}
for (unsigned int i = 0; i < NumWorlds; i++)
{
AString ValueName = IniFile.GetValueName(KeyNum, i );
if (ValueName.compare("World") != 0)
{
continue;
}
AString WorldName = IniFile.GetValue(KeyNum, i );
if (WorldName.empty())
{
continue;
}
cWorld* NewWorld = new cWorld( WorldName.c_str() );
m_WorldsByName[ WorldName ] = NewWorld;
} // for i - Worlds
}
示例3: GetFoldersToLoad
AStringVector cPluginManager::GetFoldersToLoad(cSettingsRepositoryInterface & a_Settings)
{
// Check if the Plugins section exists.
if (!a_Settings.KeyExists("Plugins"))
{
InsertDefaultPlugins(a_Settings);
}
// Get the list of plugins to load:
AStringVector res;
auto Values = a_Settings.GetValues("Plugins");
for (auto NameValue : Values)
{
AString ValueName = NameValue.first;
if (ValueName.compare("Plugin") == 0)
{
AString PluginFile = NameValue.second;
if (!PluginFile.empty())
{
res.push_back(PluginFile);
}
}
} // for i - ini values
return res;
}
示例4: IsInGroup
bool cPlayer::IsInGroup( const AString & a_Group )
{
for( GroupList::iterator itr = m_ResolvedGroups.begin(); itr != m_ResolvedGroups.end(); ++itr )
{
if( a_Group.compare( (*itr)->GetName().c_str() ) == 0 )
return true;
}
return false;
}
示例5: ReloadPluginsNow
void cPluginManager::ReloadPluginsNow(cIniFile & a_SettingsIni)
{
LOG("-- Loading Plugins --");
m_bReloadPlugins = false;
UnloadPluginsNow();
FindPlugins();
cServer::BindBuiltInConsoleCommands();
// Check if the Plugins section exists.
int KeyNum = a_SettingsIni.FindKey("Plugins");
// If it does, how many plugins are there?
int NumPlugins = ((KeyNum != -1) ? (a_SettingsIni.GetNumValues(KeyNum)) : 0);
if (KeyNum == -1)
{
InsertDefaultPlugins(a_SettingsIni);
}
else if (NumPlugins > 0)
{
for (int i = 0; i < NumPlugins; i++)
{
AString ValueName = a_SettingsIni.GetValueName(KeyNum, i);
if (ValueName.compare("Plugin") == 0)
{
AString PluginFile = a_SettingsIni.GetValue(KeyNum, i);
if (!PluginFile.empty())
{
if (m_Plugins.find(PluginFile) != m_Plugins.end())
{
LoadPlugin(PluginFile);
}
}
}
}
}
size_t NumLoadedPlugins = GetNumPlugins();
if (NumLoadedPlugins == 0)
{
LOG("-- No Plugins Loaded --");
}
else if (NumLoadedPlugins > 1)
{
LOG("-- Loaded %i Plugins --", (int)NumLoadedPlugins);
}
else
{
LOG("-- Loaded 1 Plugin --");
}
CallHookPluginsLoaded();
}
示例6: BlockStringToType
BLOCKTYPE BlockStringToType(const AString & a_BlockTypeString)
{
int res = atoi(a_BlockTypeString.c_str());
if ((res != 0) || (a_BlockTypeString.compare("0") == 0))
{
// It was a valid number, return that
return res;
}
return gsBlockIDMap.Resolve(TrimString(a_BlockTypeString));
}
示例7: SetState
// for debugging
void cMonster::SetState(const AString & a_State)
{
if (a_State.compare("Idle") == 0)
{
m_EMState = IDLE;
}
else if (a_State.compare("Attacking") == 0)
{
m_EMState = ATTACKING;
}
else if (a_State.compare("Chasing") == 0)
{
m_EMState = CHASING;
}
else
{
LOGD("cMonster::SetState(): Invalid state");
ASSERT(!"Invalid state");
}
}
示例8: StringToBiome
EMCSBiome StringToBiome(const AString & a_BiomeString)
{
// If it is a number, return it:
int res = atoi(a_BiomeString.c_str());
if ((res != 0) || (a_BiomeString.compare("0") == 0))
{
// It was a valid number
return (EMCSBiome)res;
}
// Convert using the built-in map:
static struct {
EMCSBiome m_Biome;
const char * m_String;
} BiomeMap[] =
{
{biOcean, "Ocean"} ,
{biPlains, "Plains"},
{biDesert, "Desert"},
{biExtremeHills, "ExtremeHills"},
{biForest, "Forest"},
{biTaiga, "Taiga"},
{biSwampland, "Swampland"},
{biRiver, "River"},
{biNether, "Hell"},
{biNether, "Nether"},
{biEnd, "Sky"},
{biEnd, "End"},
{biFrozenOcean, "FrozenOcean"},
{biFrozenRiver, "FrozenRiver"},
{biIcePlains, "IcePlains"},
{biIcePlains, "Tundra"},
{biIceMountains, "IceMountains"},
{biMushroomIsland, "MushroomIsland"},
{biMushroomShore, "MushroomShore"},
{biBeach, "Beach"},
{biDesertHills, "DesertHills"},
{biForestHills, "ForestHills"},
{biTaigaHills, "TaigaHills"},
{biExtremeHillsEdge, "ExtremeHillsEdge"},
{biJungle, "Jungle"},
{biJungleHills, "JungleHills"},
} ;
for (int i = 0; i < ARRAYCOUNT(BiomeMap); i++)
{
if (NoCaseCompare(BiomeMap[i].m_String, a_BiomeString) == 0)
{
return BiomeMap[i].m_Biome;
}
} // for i - BiomeMap[]
return (EMCSBiome)-1;
}
示例9: BlockStringToType
int BlockStringToType(const AString & a_BlockTypeString)
{
int res = atoi(a_BlockTypeString.c_str());
if ((res != 0) || (a_BlockTypeString.compare("0") == 0))
{
// It was a valid number, return that
return res;
}
if (!gsBlockIDMap.m_bHasRunInit)
{
gsBlockIDMap.init();
}
return gsBlockIDMap.Resolve(TrimString(a_BlockTypeString));
}
示例10: ReloadPluginsNow
void cPluginManager::ReloadPluginsNow(cIniFile & a_SettingsIni)
{
LOG("-- Loading Plugins --");
m_bReloadPlugins = false;
UnloadPluginsNow();
FindPlugins();
cServer::BindBuiltInConsoleCommands();
unsigned int KeyNum = a_SettingsIni.FindKey("Plugins");
unsigned int NumPlugins = ((KeyNum != -1) ? (a_SettingsIni.GetNumValues(KeyNum)) : 0);
if (KeyNum == -1)
{
InsertDefaultPlugins(a_SettingsIni);
}
else if (NumPlugins > 0)
{
for(unsigned int i = 0; i < NumPlugins; i++)
{
AString ValueName = a_SettingsIni.GetValueName(KeyNum, i);
if (ValueName.compare("Plugin") == 0)
{
AString PluginFile = a_SettingsIni.GetValue(KeyNum, i);
if (!PluginFile.empty())
{
if (m_Plugins.find(PluginFile) != m_Plugins.end())
{
LoadPlugin( PluginFile );
}
}
}
}
}
if (GetNumPlugins() == 0)
{
LOG("-- No Plugins Loaded --");
}
else if (GetNumPlugins() > 1)
{
LOG("-- Loaded %i Plugins --", GetNumPlugins());
}
else
{
LOG("-- Loaded 1 Plugin --");
}
}
示例11: LoadWorlds
void cRoot::LoadWorlds(cIniFile & IniFile)
{
// First get the default world
AString DefaultWorldName = IniFile.GetValueSet("Worlds", "DefaultWorld", "world");
m_pDefaultWorld = new cWorld(DefaultWorldName.c_str());
m_WorldsByName[ DefaultWorldName ] = m_pDefaultWorld;
// Then load the other worlds
int KeyNum = IniFile.FindKey("Worlds");
int NumWorlds = IniFile.GetNumValues(KeyNum);
if (NumWorlds <= 0)
{
return;
}
bool FoundAdditionalWorlds = false;
for (int i = 0; i < NumWorlds; i++)
{
AString ValueName = IniFile.GetValueName(KeyNum, i);
if (ValueName.compare("World") != 0)
{
continue;
}
AString WorldName = IniFile.GetValue(KeyNum, i);
if (WorldName.empty())
{
continue;
}
FoundAdditionalWorlds = true;
cWorld* NewWorld = new cWorld( WorldName.c_str());
m_WorldsByName[ WorldName ] = NewWorld;
} // for i - Worlds
if (!FoundAdditionalWorlds)
{
if (IniFile.GetKeyComment("Worlds", 0) != " World=secondworld")
{
IniFile.DeleteKeyComment("Worlds", 0);
IniFile.AddKeyComment("Worlds", " World=secondworld");
}
}
}
示例12: LoadWorlds
void cRoot::LoadWorlds(cSettingsRepositoryInterface & a_Settings)
{
// First get the default world
AString DefaultWorldName = a_Settings.GetValueSet("Worlds", "DefaultWorld", "world");
m_pDefaultWorld = new cWorld(DefaultWorldName.c_str());
m_WorldsByName[ DefaultWorldName ] = m_pDefaultWorld;
// Then load the other worlds
auto Worlds = a_Settings.GetValues("Worlds");
if (Worlds.size() <= 0)
{
return;
}
bool FoundAdditionalWorlds = false;
for (auto WorldNameValue : Worlds)
{
AString ValueName = WorldNameValue.first;
if (ValueName.compare("World") != 0)
{
continue;
}
AString WorldName = WorldNameValue.second;
if (WorldName.empty())
{
continue;
}
FoundAdditionalWorlds = true;
cWorld * NewWorld = new cWorld(WorldName.c_str());
m_WorldsByName[WorldName] = NewWorld;
} // for i - Worlds
if (!FoundAdditionalWorlds)
{
if (a_Settings.GetKeyComment("Worlds", 0) != " World=secondworld")
{
a_Settings.DeleteKeyComment("Worlds", 0);
a_Settings.AddKeyComment("Worlds", " World=secondworld");
}
}
}
示例13: AuthWithYggdrasil
bool cAuthenticator::AuthWithYggdrasil(AString & a_UserName, const AString & a_ServerId, AString & a_UUID, Json::Value & a_Properties)
{
LOGD("Trying to authenticate user %s", a_UserName.c_str());
// Create the GET request:
AString ActualAddress = m_Address;
ReplaceString(ActualAddress, "%USERNAME%", a_UserName);
ReplaceString(ActualAddress, "%SERVERID%", a_ServerId);
AString Request;
Request += "GET " + ActualAddress + " HTTP/1.0\r\n";
Request += "Host: " + m_Server + "\r\n";
Request += "User-Agent: MCServer\r\n";
Request += "Connection: close\r\n";
Request += "\r\n";
AString Response;
if (!cMojangAPI::SecureRequest(m_Server, Request, Response))
{
return false;
}
// Check the HTTP status line:
const AString Prefix("HTTP/1.1 200 OK");
AString HexDump;
if (Response.compare(0, Prefix.size(), Prefix))
{
LOGINFO("User %s failed to auth, bad HTTP status line received", a_UserName.c_str());
LOGD("Response: \n%s", CreateHexDump(HexDump, Response.data(), Response.size(), 16).c_str());
return false;
}
// Erase the HTTP headers from the response:
size_t idxHeadersEnd = Response.find("\r\n\r\n");
if (idxHeadersEnd == AString::npos)
{
LOGINFO("User %s failed to authenticate, bad HTTP response header received", a_UserName.c_str());
LOGD("Response: \n%s", CreateHexDump(HexDump, Response.data(), Response.size(), 16).c_str());
return false;
}
Response.erase(0, idxHeadersEnd + 4);
// Parse the Json response:
if (Response.empty())
{
return false;
}
Json::Value root;
Json::Reader reader;
if (!reader.parse(Response, root, false))
{
LOGWARNING("cAuthenticator: Cannot parse received data (authentication) to JSON!");
return false;
}
a_UserName = root.get("name", "Unknown").asString();
a_UUID = cMojangAPI::MakeUUIDShort(root.get("id", "").asString());
a_Properties = root["properties"];
// Store the player's profile in the MojangAPI caches:
cRoot::Get()->GetMojangAPI().AddPlayerProfile(a_UserName, a_UUID, a_Properties);
return true;
}
示例14: LoadFromSchematicNBT
bool cBlockArea::LoadFromSchematicNBT(cParsedNBT & a_NBT)
{
int TMaterials = a_NBT.FindChildByName(a_NBT.GetRoot(), "Materials");
if ((TMaterials > 0) && (a_NBT.GetType(TMaterials) == TAG_String))
{
AString Materials = a_NBT.GetString(TMaterials);
if (Materials.compare("Alpha") != 0)
{
LOG("Materials tag is present and \"%s\" instead of \"Alpha\". Possibly a wrong-format schematic file.", Materials.c_str());
return false;
}
}
int TSizeX = a_NBT.FindChildByName(a_NBT.GetRoot(), "Width");
int TSizeY = a_NBT.FindChildByName(a_NBT.GetRoot(), "Height");
int TSizeZ = a_NBT.FindChildByName(a_NBT.GetRoot(), "Length");
if (
(TSizeX < 0) || (TSizeY < 0) || (TSizeZ < 0) ||
(a_NBT.GetType(TSizeX) != TAG_Short) ||
(a_NBT.GetType(TSizeY) != TAG_Short) ||
(a_NBT.GetType(TSizeZ) != TAG_Short)
)
{
LOG("Dimensions are missing from the schematic file (%d, %d, %d), (%d, %d, %d)",
TSizeX, TSizeY, TSizeZ,
a_NBT.GetType(TSizeX), a_NBT.GetType(TSizeY), a_NBT.GetType(TSizeZ)
);
return false;
}
int SizeX = a_NBT.GetShort(TSizeX);
int SizeY = a_NBT.GetShort(TSizeY);
int SizeZ = a_NBT.GetShort(TSizeZ);
if ((SizeX < 1) || (SizeY < 1) || (SizeZ < 1))
{
LOG("Dimensions are invalid in the schematic file: %d, %d, %d", SizeX, SizeY, SizeZ);
return false;
}
int TBlockTypes = a_NBT.FindChildByName(a_NBT.GetRoot(), "Blocks");
int TBlockMetas = a_NBT.FindChildByName(a_NBT.GetRoot(), "Data");
if ((TBlockTypes < 0) || (a_NBT.GetType(TBlockTypes) != TAG_ByteArray))
{
LOG("BlockTypes are invalid in the schematic file: %d", TBlockTypes);
return false;
}
bool AreMetasPresent = (TBlockMetas > 0) && (a_NBT.GetType(TBlockMetas) == TAG_ByteArray);
Clear();
SetSize(SizeX, SizeY, SizeZ, AreMetasPresent ? (baTypes | baMetas) : baTypes);
// Copy the block types and metas:
int NumBytes = m_SizeX * m_SizeY * m_SizeZ;
if (a_NBT.GetDataLength(TBlockTypes) < NumBytes)
{
LOG("BlockTypes truncated in the schematic file (exp %d, got %d bytes). Loading partial.",
NumBytes, a_NBT.GetDataLength(TBlockTypes)
);
NumBytes = a_NBT.GetDataLength(TBlockTypes);
}
memcpy(m_BlockTypes, a_NBT.GetData(TBlockTypes), NumBytes);
if (AreMetasPresent)
{
int NumBytes = m_SizeX * m_SizeY * m_SizeZ;
if (a_NBT.GetDataLength(TBlockMetas) < NumBytes)
{
LOG("BlockMetas truncated in the schematic file (exp %d, got %d bytes). Loading partial.",
NumBytes, a_NBT.GetDataLength(TBlockMetas)
);
NumBytes = a_NBT.GetDataLength(TBlockMetas);
}
memcpy(m_BlockMetas, a_NBT.GetData(TBlockMetas), NumBytes);
}
return true;
}
示例15: LoadWorlds
void cRoot::LoadWorlds(cSettingsRepositoryInterface & a_Settings, bool a_IsNewIniFile)
{
if (a_IsNewIniFile)
{
a_Settings.AddValue("Worlds", "DefaultWorld", "world");
a_Settings.AddValue("Worlds", "World", "world_nether");
a_Settings.AddValue("Worlds", "World", "world_end");
m_pDefaultWorld = new cWorld("world");
m_WorldsByName["world"] = m_pDefaultWorld;
m_WorldsByName["world_nether"] = new cWorld("world_nether", dimNether, "world");
m_WorldsByName["world_end"] = new cWorld("world_end", dimEnd, "world");
return;
}
// First get the default world
AString DefaultWorldName = a_Settings.GetValueSet("Worlds", "DefaultWorld", "world");
m_pDefaultWorld = new cWorld(DefaultWorldName.c_str());
m_WorldsByName[ DefaultWorldName ] = m_pDefaultWorld;
auto Worlds = a_Settings.GetValues("Worlds");
// Then load the other worlds
if (Worlds.size() <= 0)
{
return;
}
/* Here are the world creation rules. Note that these only apply for a world which is in settings.ini but has no world.ini file.
If an ini file is present, it overrides the world linkages and the dimension type in cWorld::start()
The creation rules are as follows:
- If a world exists in settings.ini but has no world.ini, then:
- If the world name is x_nether, create a world.ini with the dimension type "nether".
- If a world called x exists, set it as x_nether's overworld.
- Otherwise set the default world as x_nether's overworld.
- If the world name is x_end, create a world.ini with the dimension type "end".
- If a world called x exists, set it as x_end's overworld.
- Otherwise set the default world as x_end's overworld.
- If the world name is x (and doesn't end with _end or _nether)
- Create a world.ini with a dimension type of "overworld".
- If a world called x_nether exists, set it as x's nether world.
- Otherwise set x's nether world to blank.h
- If a world called x_end exists, set it as x's end world.
- Otherwise set x's nether world to blank.
*/
bool FoundAdditionalWorlds = false;
for (auto WorldNameValue : Worlds)
{
AString ValueName = WorldNameValue.first;
if (ValueName.compare("World") != 0)
{
continue;
}
AString WorldName = WorldNameValue.second;
if (WorldName.empty())
{
continue;
}
FoundAdditionalWorlds = true;
cWorld * NewWorld;
AString LowercaseName = StrToLower(WorldName);
AString NetherAppend="_nether";
AString EndAppend="_end";
// if the world is called x_nether
if ((LowercaseName.size() > NetherAppend.size()) && (LowercaseName.substr(LowercaseName.size() - NetherAppend.size()) == NetherAppend))
{
// The world is called x_nether, see if a world called x exists. If yes, choose it as the linked world,
// otherwise, choose the default world as the linked world.
// As before, any ini settings will completely override this if an ini is already present.
AString LinkTo = WorldName.substr(0, WorldName.size() - NetherAppend.size());
if (GetWorld(LinkTo) == nullptr)
{
LinkTo = DefaultWorldName;
}
NewWorld = new cWorld(WorldName.c_str(), dimNether, LinkTo);
}
// if the world is called x_end
else if ((LowercaseName.size() > EndAppend.size()) && (LowercaseName.substr(LowercaseName.size() - EndAppend.size()) == EndAppend))
{
// The world is called x_end, see if a world called x exists. If yes, choose it as the linked world,
// otherwise, choose the default world as the linked world.
// As before, any ini settings will completely override this if an ini is already present.
AString LinkTo = WorldName.substr(0, WorldName.size() - EndAppend.size());
if (GetWorld(LinkTo) == nullptr)
{
LinkTo = DefaultWorldName;
}
NewWorld = new cWorld(WorldName.c_str(), dimEnd, LinkTo);
}
else
{
NewWorld = new cWorld(WorldName.c_str());
}
m_WorldsByName[WorldName] = NewWorld;
//.........这里部分代码省略.........