ServerAuthHandlerMinKills.cpp

Go to the documentation of this file.
00001 ////////////////////////////////////////////////////////////////////////////////
00002 //    Scorched3D (c) 2000-2009
00003 //
00004 //    This file is part of Scorched3D.
00005 //
00006 //    Scorched3D is free software; you can redistribute it and/or modify
00007 //    it under the terms of the GNU General Public License as published by
00008 //    the Free Software Foundation; either version 2 of the License, or
00009 //    (at your option) any later version.
00010 //
00011 //    Scorched3D is distributed in the hope that it will be useful,
00012 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //    GNU General Public License for more details.
00015 //
00016 //    You should have received a copy of the GNU General Public License
00017 //    along with Scorched3D; if not, write to the Free Software
00018 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 ////////////////////////////////////////////////////////////////////////////////
00020 
00021 #include <server/ServerAuthHandlerMinKills.h>
00022 #include <server/ScorchedServer.h>
00023 #include <common/StatsLogger.h>
00024 #include <common/Logger.h>
00025 #include <common/OptionsScorched.h>
00026 #include <common/Defines.h>
00027 
00028 ServerAuthHandlerMinKills::ServerAuthHandlerMinKills() : 
00029         minKills_(-1), maxKills_(-1)
00030 {
00031 }
00032 
00033 ServerAuthHandlerMinKills::~ServerAuthHandlerMinKills()
00034 {
00035 }
00036 
00037 void createAuthentication(ComsConnectAuthMessage &authMessage)
00038 {
00039 }
00040 
00041 void ServerAuthHandlerMinKills::createAuthentication(ComsConnectAuthMessage &authMessage)
00042 {
00043 }
00044 
00045 bool ServerAuthHandlerMinKills::authenticateUser(ComsConnectAuthMessage &authMessage, 
00046         std::string &message)
00047 {
00048         setup();
00049 
00050         int killCount = StatsLogger::instance()->getKillCount(authMessage.getUniqueId());
00051         if (minKills_ > 0 && killCount < minKills_)
00052         {
00053                 message = S3D::formatStringBuffer(
00054                         "You need to have at least %i kills to play on this server.\n"
00055                         "You only have %i kills.\n",
00056                         minKills_, killCount);
00057                 return false;
00058         }
00059         if (maxKills_ > 0 && killCount > maxKills_)
00060         {
00061                 message = S3D::formatStringBuffer(
00062                         "You have too many kills to play on this server.\n"
00063                         "You have %i kills and the server allows %i kills.\n",
00064                         killCount, maxKills_);
00065                 return false;
00066         }       
00067         
00068         return true;
00069 }
00070 
00071 bool ServerAuthHandlerMinKills::authenticateUserName(const char *uniqueId, 
00072         const LangString &playername)
00073 {
00074         return true;
00075 }
00076 
00077 void ServerAuthHandlerMinKills::banUser(const char *uniqueId)
00078 {
00079 }
00080 
00081 void ServerAuthHandlerMinKills::setup()
00082 {
00083         if (minKills_ != -1) return;
00084 
00085         XMLFile file;
00086         std::string fileName = S3D::getSettingsFile(S3D::formatStringBuffer("minkills-%i.xml",
00087                 ScorchedServer::instance()->getOptionsGame().getPortNo()));
00088 
00089         if (!file.readFile(fileName) ||
00090                 !file.getRootNode())
00091         {
00092                 Logger::log(S3D::formatStringBuffer("Failed to parse %s settings file. Error: %s", 
00093                         fileName.c_str(),
00094                         file.getParserError()));
00095                 return;
00096         }
00097 
00098         if (!file.getRootNode()->getNamedChild("minkills", minKills_) ||
00099                 !file.getRootNode()->getNamedChild("maxkills", maxKills_)) 
00100         {
00101                 Logger::log(S3D::formatStringBuffer("Failed to parse %s settings file.", fileName.c_str()));
00102                 return;
00103         }
00104         Logger::log(S3D::formatStringBuffer("ServerAuthHandlerMinKills : minkills=%i, maxkills=%i",
00105                 minKills_, maxKills_));
00106 }

Generated on Mon Feb 16 15:14:53 2009 for Scorched3D by  doxygen 1.5.3