Crossfire Server, Trunk
LicenseManager.cpp
Go to the documentation of this file.
1 /*
2  * Crossfire -- cooperative multi-player graphical RPG and adventure game
3  *
4  * Copyright (c) 2021-2022 the Crossfire Development Team
5  *
6  * Crossfire is free software and comes with ABSOLUTELY NO WARRANTY. You are
7  * welcome to redistribute it under certain conditions. For details, please
8  * see COPYING and LICENSE.
9  *
10  * The authors can be reached via e-mail at <crossfire@metalforge.org>.
11  */
12 
13 #include "LicenseManager.h"
14 
15 #include "global.h"
16 #include "bufferreader.h"
17 #include <memory>
18 
20 }
21 
23 }
24 
26  char *c;
27  std::unique_ptr<char, void(*)(void*)> dup(strdup(filename), free);
28 
29  c = strrchr(dup.get(), '.');
30  if (!c) {
31  LOG(llevError, "LicenseManager: invalid filename %s\n", filename);
32  return;
33  }
34  (*c) = '\0';
35  c = strrchr(dup.get(), '.');
36  if (!c) {
37  LOG(llevError, "LicenseManager: invalid filename %s\n", filename);
38  return;
39  }
40  (*c) = '\0';
41  c++;
42 
43  std::string faceset(c);
44 
45  c = strrchr(dup.get(), '/');
46  if (!c) {
47  LOG(llevError, "LicenseManager: invalid filename %s\n", filename);
48  return;
49  }
50  c++;
51 
52  auto &licenses = m_licenses[c];
53  auto &items = licenses[faceset];
54  parseLicenseFile(reader, filename, items);
55 }
56 
57 void LicenseManager::parseLicenseFile(BufferReader *reader, const char *filename, std::vector<LicenseItem> &items) {
58  char *line, *c;
59  while ((line = bufferreader_next_line(reader)) != nullptr) {
60  if (line[0] == '\0')
61  continue;
62  c = strchr(line, ' ');
63  if (!c) {
64  LOG(llevError, "LicenseManager: malformed line '%s' in %s:%zu\n", line, filename, bufferreader_current_line(reader));
65  continue;
66  }
67 
68  (*c) = '\0';
69  c++;
70 
71  items.push_back(std::make_pair(line, c));
72  }
73 }
74 
76  auto search = m_licenses.find(licenseNameFromFaceName(face));
77  if (search != m_licenses.end()) {
78  return search->second;
79  }
80  return LicenseItems();
81 }
82 
83 std::string LicenseManager::licenseNameFromFaceName(const std::string &face) {
84  auto dot = face.find('.');
85  if (dot == std::string::npos)
86  {
87  return std::string();
88  }
89  return face.substr(0, dot);
90 }
global.h
line
Install Bug reporting Credits so make sure you have version or later There are files involved in the automatic convert convertall and filelist py GuildList has the list of guilds for the server GuildLocations is what is used by the install script for setting up the maps It has columns in the first is the name of the no spaces The second is the region of the the third is the destination folder for the the fourth is the exit the fifth and sixth are the x and y coords within the exit the seventh eighth and ninth are the exit location for the storage hall If field seven is then it uses the same exit map as for the guild hall itself filelist py has a list of which files to process for each guild hall convert py takes all the files in filelist py and customises them to the specific guild then outputs them into a in the same order that they are listed in GuildLocations convertall py reads the lines from GuildLocations and runs line by line
Definition: README.txt:12
LicenseManager.h
bufferreader_current_line
size_t bufferreader_current_line(BufferReader *br)
Definition: bufferreader.cpp:140
llevError
@ llevError
Definition: logger.h:11
LicenseManager::licenseNameFromFaceName
static std::string licenseNameFromFaceName(const std::string &face)
Definition: LicenseManager.cpp:83
LOG
void LOG(LogLevel logLevel, const char *format,...)
Definition: logger.cpp:51
c
static event_registration c
Definition: citylife.cpp:425
LicenseManager::LicenseItems
std::map< std::string, std::vector< LicenseItem > > LicenseItems
Definition: LicenseManager.h:29
LicenseManager::getForFace
LicenseItems getForFace(const std::string &face)
Definition: LicenseManager.cpp:75
npc_dialog.filename
filename
Definition: npc_dialog.py:99
LicenseManager::~LicenseManager
virtual ~LicenseManager()
Definition: LicenseManager.cpp:22
bufferreader.h
nlohmann::detail::void
j template void())
Definition: json.hpp:4099
LicenseManager::LicenseManager
LicenseManager()
Definition: LicenseManager.cpp:19
LicenseManager::readLicense
void readLicense(BufferReader *reader, const char *filename)
Definition: LicenseManager.cpp:25
BufferReader
Definition: bufferreader.cpp:21
LicenseManager::m_licenses
std::map< std::string, LicenseItems > m_licenses
Definition: LicenseManager.h:71
LicenseManager::parseLicenseFile
static void parseLicenseFile(BufferReader *reader, const char *filename, std::vector< LicenseItem > &items)
Definition: LicenseManager.cpp:57
bufferreader_next_line
char * bufferreader_next_line(BufferReader *br)
Definition: bufferreader.cpp:102