summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/crsm.cpp191
-rw-r--r--src/crsm.hpp2
2 files changed, 83 insertions, 110 deletions
diff --git a/src/crsm.cpp b/src/crsm.cpp
index 8c9e371..7dadc59 100644
--- a/src/crsm.cpp
+++ b/src/crsm.cpp
@@ -153,6 +153,65 @@ ClientInfo* CRSM::parseClientInfo(QString& message)
return nullptr;
}
+QString CRSM::findClientByName(ClientInfo &info, const QString &name)
+{
+ if(Session.Clonk.Clients.contains(name))
+ {
+ info = Session.Clonk.Clients.value(name);
+ return "";
+ }
+ else
+ {
+ for(const QString& pcName : Session.Clonk.Clients.keys())
+ {
+ if(pcName.compare(name, Qt::CaseInsensitive) == 0)
+ {
+ info = Session.Clonk.Clients.value(pcName);
+ return "";
+ }
+ }
+ }
+
+ bool notFound = true;
+ for(const ClientInfo& client : Session.Clonk.Clients)
+ {
+ bool foundHere = false;
+ if(client.nick.compare(name, Qt::CaseInsensitive) == 0)
+ {
+ foundHere = true;
+ }
+ else
+ {
+ for(const QString& player : client.players)
+ {
+ if(name.compare(player, Qt::CaseInsensitive) == 0)
+ {
+ foundHere = true;
+ }
+ }
+ }
+
+ if(foundHere)
+ {
+ if(!notFound && info != client)
+ {
+ return "Name " + name + " ist nicht eindeutig. Bitte PC-Namen verwenden.\n";
+ }
+
+ info = client;
+ notFound = false;
+ }
+ }
+ if(notFound)
+ {
+ return name + " wurde nicht gefunden!\n";
+ }
+ else
+ {
+ return "";
+ }
+}
+
void CRSM::readServerOutput()
{
QString what(processManager->readLine().trimmed());
@@ -1019,26 +1078,6 @@ QString CRSM::scenPath(QString scenName)
QString folderName = caseInsensitive(split.first(), "", ".c4f");
if(!folderName.isEmpty())
{
-// QDir dir(Config.Auto.Volatile.Clonk.Directory + folderName);
-// if(dir.exists())
-// {
-// QString file = caseInsensitive(name, folderName);
-// if(!file.isEmpty())
-// {
-// if(isAlias)
-// {
-// return aliasName;
-// }
-// else
-// {
-// return folderName + '/' + file;
-// }
-// }
-// else
-// {
-// return QString();
-// }
-// }
QFile lstFile(Config.CRSM.ListFolder + folderName + ".lst");
if(lstFile.exists())
{
@@ -1720,58 +1759,29 @@ void CRSM::ircCheckUserStatus(const ClientInfo &requester, const ClientInfo &sub
void CRSM::setIngameAdmin(const ClientInfo &client, const QString& newAdmin)
{
- if(Session.Clonk.Clients.contains(newAdmin))
+ if(newAdmin == Config.Auto.Volatile.Clonk.ServerNick || newAdmin == Config.Auto.Volatile.Clonk.ServerPCName)
{
- const ClientInfo& info = Session.Clonk.Clients.value(newAdmin);
- if(Session.Clonk.Admin == info)
- {
- respond(client, info.toString() + " ist bereits Rundenadmin.\n");
- return;
- }
- Session.Clonk.Admin = info;
+ respond(client, "Der Server kann nicht als Rundenadmin eingetragen werden!\n");
+ return;
}
- else if(newAdmin == Config.Auto.Volatile.Clonk.ServerNick || newAdmin == Config.Auto.Volatile.Clonk.ServerPCName)
+
+ ClientInfo info;
+ QString msg = findClientByName(info, newAdmin);
+
+ if(!msg.isEmpty())
{
- respond(client, "Der Server kann nicht als Rundenadmin eingetragen werden!\n");
+ respond(client, msg);
return;
}
- else
+
+ if(Session.Clonk.Admin == info)
{
- bool notFound = true, ambigous = false;
- ClientInfo foundClient;
- foreach(const ClientInfo& client, Session.Clonk.Clients)
- {
- if(client.nick == newAdmin)
- {
- if(!notFound)
- {
- ambigous = true;
- break;
- }
- foundClient = client;
- notFound = false;
- }
- }
- if(ambigous)
- {
- respond(client, "Chat-Nickname " + newAdmin + " ist nicht eindeutig. Bitte PC-Namen verwenden.\n");
- return;
- }
- else if(notFound)
- {
- respond(client, newAdmin + " wurde nicht gefunden!\n");
- return;
- }
- else if(Session.Clonk.Admin == foundClient)
- {
- respond(client, Session.Clonk.Admin.toString() + " ist bereits Rundenadmin!\n");
- return;
- }
- else
- {
- Session.Clonk.Admin = foundClient;
- }
+ respond(client, info.toString() + " ist bereits Rundenadmin.\n");
+ return;
}
+
+ Session.Clonk.Admin = info;
+
afkAdminTimer.stop();
Session.AfkAdmin = false;
respond(client, Session.Clonk.Admin.toString() + " wurde als Rundenadmin eingetragen.\n");
@@ -2921,53 +2931,14 @@ CMD_FUNCTION_IMPL(passToClonkPcName)
return Success;
}
ClientInfo info;
- if(Session.Clonk.Clients.contains(args))
- {
- info = Session.Clonk.Clients.value(args);
- }
- else
- {
- foreach(const QString& pcName, Session.Clonk.Clients.keys())
- {
- if(pcName.compare(args, Qt::CaseInsensitive) == 0)
- {
- info = Session.Clonk.Clients.value(pcName);
- break;
- }
- }
- }
- if(info.empty())
+ QString msg = findClientByName(info, args);
+
+ if(!msg.isEmpty())
{
- bool notFound = true, ambigous = false;
- ClientInfo foundClient;
- foreach(const ClientInfo& client, Session.Clonk.Clients)
- {
- if(client.nick.compare(args, Qt::CaseInsensitive) == 0)
- {
- if(!notFound)
- {
- ambigous = true;
- break;
- }
- foundClient = client;
- notFound = false;
- }
- }
- if(ambigous)
- {
- respond(client, "Chat-Nickname " + args + " ist nicht eindeutig. Bitte PC-Namen verwenden.\n");
- return Success;
- }
- else if(notFound)
- {
- respond(client, args + " wurde nicht gefunden!\n");
- return Success;
- }
- else
- {
- info = foundClient;
- }
+ respond(client, msg);
+ return Success;
}
+
if(cmd == "kick" && clientUserType(info) > userType)
{
respond(client, "Moderatoren können nur von anderen Moderatoren gekickt werden.\n");
diff --git a/src/crsm.hpp b/src/crsm.hpp
index bac0584..4936f40 100644
--- a/src/crsm.hpp
+++ b/src/crsm.hpp
@@ -306,6 +306,8 @@ private:
ClientInfo& getClientInfo(const QString& pcName, int cuid, const QString& user);
ClientInfo* parseClientInfo(QString& message);
+ QString findClientByName(ClientInfo& info, const QString& name);
+
void exit();
void applyConfig();