Skip to content

Commit 63e7137

Browse files
committedNov 9, 2015
Put ChatEvent handler into own function
Comply with line limit.
1 parent 889f893 commit 63e7137

File tree

2 files changed

+22
-15
lines changed

2 files changed

+22
-15
lines changed
 

Diff for: ‎src/server.cpp

+20-15
Original file line numberDiff line numberDiff line change
@@ -585,21 +585,7 @@ void Server::AsyncRunStep(bool initial_step)
585585
MutexAutoLock lock(m_env_mutex);
586586
while (!m_admin_chat->command_queue.empty()) {
587587
ChatEvent *evt = m_admin_chat->command_queue.pop_frontNoEx();
588-
if (evt->type == CET_NICK_ADD) {
589-
// The terminal informed us of its nick choice
590-
m_admin_nick = ((ChatEventNick *)evt)->nick;
591-
if (!m_script->getAuth(m_admin_nick, NULL, NULL)) {
592-
errorstream << "You haven't set up an account." << std::endl
593-
<< "Please log in using the client as '"
594-
<< m_admin_nick << "' with a secure password." << std::endl
595-
<< "Until then, you can't execute admin tasks via the console," << std::endl
596-
<< "and everybody can claim the user account instead of you," << std::endl
597-
<< "giving them full control over this server." << std::endl;
598-
}
599-
} else {
600-
assert(evt->type == CET_CHAT);
601-
handleAdminChat((ChatEventChat *)evt);
602-
}
588+
handleChatInterfaceEvent(evt);
603589
delete evt;
604590
}
605591
}
@@ -2749,6 +2735,25 @@ void Server::UpdateCrafting(Player* player)
27492735
plist->changeItem(0, preview);
27502736
}
27512737

2738+
void Server::handleChatInterfaceEvent(ChatEvent *evt)
2739+
{
2740+
if (evt->type == CET_NICK_ADD) {
2741+
// The terminal informed us of its nick choice
2742+
m_admin_nick = ((ChatEventNick *)evt)->nick;
2743+
if (!m_script->getAuth(m_admin_nick, NULL, NULL)) {
2744+
errorstream << "You haven't set up an account." << std::endl
2745+
<< "Please log in using the client as '"
2746+
<< m_admin_nick << "' with a secure password." << std::endl
2747+
<< "Until then, you can't execute admin tasks via the console," << std::endl
2748+
<< "and everybody can claim the user account instead of you," << std::endl
2749+
<< "giving them full control over this server." << std::endl;
2750+
}
2751+
} else {
2752+
assert(evt->type == CET_CHAT);
2753+
handleAdminChat((ChatEventChat *)evt);
2754+
}
2755+
}
2756+
27522757
std::wstring Server::handleChat(const std::string &name, const std::wstring &wname,
27532758
const std::wstring &wmessage, u16 peer_id_to_avoid_sending)
27542759
{

Diff for: ‎src/server.h

+2
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,8 @@ class Server : public con::PeerHandler, public MapEventReceiver,
476476
void DeleteClient(u16 peer_id, ClientDeletionReason reason);
477477
void UpdateCrafting(Player *player);
478478

479+
void handleChatInterfaceEvent(ChatEvent *evt);
480+
479481
// This returns the answer to the sender of wmessage, or "" if there is none
480482
std::wstring handleChat(const std::string &name, const std::wstring &wname,
481483
const std::wstring &wmessage,

0 commit comments

Comments
 (0)
Please sign in to comment.