00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <common/StatsLoggerFile.h>
00022 #include <common/OptionsScorched.h>
00023 #include <common/LoggerI.h>
00024 #include <common/Defines.h>
00025 #include <server/ScorchedServer.h>
00026 #include <weapons/Accessory.h>
00027 #include <weapons/Shield.h>
00028 #include <stdlib.h>
00029
00030 StatsLoggerFile::StatsLoggerFile() : statsLogger_(0)
00031 {
00032
00033 }
00034
00035 StatsLoggerFile::~StatsLoggerFile()
00036 {
00037 }
00038
00039 int StatsLoggerFile::getKillCount(const char *uniqueId)
00040 {
00041 return 0;
00042 }
00043
00044 void StatsLoggerFile::createLogger()
00045 {
00046 if (!statsLogger_)
00047 {
00048 char buffer[256];
00049 snprintf(buffer, 256, "StatsLog-%i-",
00050 ScorchedServer::instance()->getOptionsGame().getPortNo());
00051 statsLogger_ = new FileLogger(buffer);
00052 }
00053 }
00054
00055 void StatsLoggerFile::gameStart(std::list<Tank *> &tanks)
00056 {
00057 createLogger();
00058 if (!statsLogger_) return;
00059
00060 time_t theTime = time(0);
00061 char *time = ctime(&theTime);
00062 char *nl = strchr(time, '\n');
00063 if (nl) *nl = '\0';
00064
00065 LoggerInfo info("startgame", time);
00066 statsLogger_->logMessage(info);
00067 }
00068
00069 void StatsLoggerFile::roundStart(std::list<Tank *> &tanks)
00070 {
00071 createLogger();
00072 if (!statsLogger_) return;
00073
00074 time_t theTime = time(0);
00075 char *time = ctime(&theTime);
00076 char *nl = strchr(time, '\n');
00077 if (nl) *nl = '\0';
00078
00079 LoggerInfo info("startround", time);
00080 statsLogger_->logMessage(info);
00081 }
00082
00083 void StatsLoggerFile::updateStats(Tank *tank)
00084 {
00085 }
00086
00087 std::string StatsLoggerFile::allocateId()
00088 {
00089 static char buffer[128];
00090 snprintf(buffer, 128, "%i-%i-%i", rand(), rand(), rand());
00091 return buffer;
00092 }
00093
00094 unsigned int StatsLoggerFile::getStatsId(const char *uniqueId)
00095 {
00096 return 0;
00097 }
00098
00099 std::string StatsLoggerFile::getTopRanks()
00100 {
00101 return "";
00102 }
00103
00104 std::string StatsLoggerFile::getPlayerInfo(const char *player)
00105 {
00106 return "";
00107 }
00108
00109 void StatsLoggerFile::combinePlayers(unsigned int player1, unsigned int player2)
00110 {
00111 }
00112
00113 void StatsLoggerFile::periodicUpdate()
00114 {
00115 }
00116
00117 std::list<std::string> StatsLoggerFile::getAliases(const char *unqiueId)
00118 {
00119 std::list<std::string> result;
00120 return result;
00121 }
00122
00123 std::list<std::string> StatsLoggerFile::getIpAliases(const char *unqiueId)
00124 {
00125 std::list<std::string> result;
00126 return result;
00127 }
00128
00129 void StatsLoggerFile::tankFired(Tank *firedTank, Weapon *weapon)
00130 {
00131 createLogger();
00132 if (!statsLogger_) return;
00133
00134 time_t theTime = time(0);
00135 char *time = ctime(&theTime);
00136 char *nl = strchr(time, '\n');
00137 if (nl) *nl = '\0';
00138
00139 char message[1024];
00140 snprintf(message, 1024, "fired \"%s\" [%s] \"%s\"",
00141 firedTank->getCStrName().c_str(),
00142 firedTank->getUniqueId(),
00143 weapon->getParent()->getName());
00144
00145 LoggerInfo info(message, time);
00146 statsLogger_->logMessage(info);
00147 }
00148
00149 void StatsLoggerFile::tankResigned(Tank *resignedTank)
00150 {
00151 createLogger();
00152 if (!statsLogger_) return;
00153
00154 time_t theTime = time(0);
00155 char *time = ctime(&theTime);
00156 char *nl = strchr(time, '\n');
00157 if (nl) *nl = '\0';
00158
00159 char message[1024];
00160 snprintf(message, 1024, "resigined \"%s\" [%s]",
00161 resignedTank->getCStrName().c_str(),
00162 resignedTank->getUniqueId());
00163 LoggerInfo info(message, time);
00164 statsLogger_->logMessage(info);
00165 }
00166
00167 void StatsLoggerFile::tankJoined(Tank *tank)
00168 {
00169 createLogger();
00170 if (!statsLogger_) return;
00171
00172 time_t theTime = time(0);
00173 char *time = ctime(&theTime);
00174 char *nl = strchr(time, '\n');
00175 if (nl) *nl = '\0';
00176
00177 char message[1024];
00178 snprintf(message, 1024, "joined \"%s\" [%s]",
00179 tank->getCStrName().c_str(),
00180 tank->getUniqueId());
00181 LoggerInfo info(message, time);
00182 statsLogger_->logMessage(info);
00183 }
00184
00185 void StatsLoggerFile::tankConnected(Tank *tank)
00186 {
00187 createLogger();
00188 if (!statsLogger_) return;
00189
00190 time_t theTime = time(0);
00191 char *time = ctime(&theTime);
00192 char *nl = strchr(time, '\n');
00193 if (nl) *nl = '\0';
00194
00195 char message[1024];
00196 snprintf(message, 1024, "connected \"%s\" [%s]",
00197 tank->getCStrName().c_str(),
00198 tank->getUniqueId());
00199 LoggerInfo info(message, time);
00200 statsLogger_->logMessage(info);
00201 }
00202
00203 void StatsLoggerFile::tankDisconnected(Tank *tank)
00204 {
00205 createLogger();
00206 if (!statsLogger_) return;
00207
00208 time_t theTime = time(0);
00209 char *time = ctime(&theTime);
00210 char *nl = strchr(time, '\n');
00211 if (nl) *nl = '\0';
00212
00213 char message[1024];
00214 snprintf(message, 1024, "disconnected \"%s\" [%s]",
00215 tank->getCStrName().c_str(),
00216 tank->getUniqueId());
00217 LoggerInfo info(message, time);
00218 statsLogger_->logMessage(info);
00219 }
00220
00221 void StatsLoggerFile::tankKilled(Tank *firedTank, Tank *deadTank, Weapon *weapon)
00222 {
00223 createLogger();
00224 if (!statsLogger_) return;
00225
00226 time_t theTime = time(0);
00227 char *time = ctime(&theTime);
00228 char *nl = strchr(time, '\n');
00229 if (nl) *nl = '\0';
00230
00231 char message[1024];
00232 snprintf(message, 1024, "killed \"%s\" [%s] \"%s\" [%s] \"%s\"",
00233 firedTank->getCStrName().c_str(), firedTank->getUniqueId(),
00234 deadTank->getCStrName().c_str(), deadTank->getUniqueId(),
00235 weapon->getParent()->getName());
00236 LoggerInfo info(message, time);
00237 statsLogger_->logMessage(info);
00238 }
00239
00240 void StatsLoggerFile::tankTeamKilled(Tank *firedTank, Tank *deadTank, Weapon *weapon)
00241 {
00242 createLogger();
00243 if (!statsLogger_) return;
00244
00245 time_t theTime = time(0);
00246 char *time = ctime(&theTime);
00247 char *nl = strchr(time, '\n');
00248 if (nl) *nl = '\0';
00249
00250 char message[1024];
00251 snprintf(message, 1024, "teamkilled \"%s\" [%s] \"%s\" [%s] \"%s\"",
00252 firedTank->getCStrName().c_str(), firedTank->getUniqueId(),
00253 deadTank->getCStrName().c_str(), deadTank->getUniqueId(),
00254 weapon->getParent()->getName());
00255 LoggerInfo info(message, time);
00256 statsLogger_->logMessage(info);
00257 }
00258
00259 void StatsLoggerFile::tankSelfKilled(Tank *firedTank, Weapon *weapon)
00260 {
00261 createLogger();
00262 if (!statsLogger_) return;
00263
00264 time_t theTime = time(0);
00265 char *time = ctime(&theTime);
00266 char *nl = strchr(time, '\n');
00267 if (nl) *nl = '\0';
00268
00269 char message[1024];
00270 snprintf(message, 1024, "selfkilled \"%s\" [%s] \"%s\"",
00271 firedTank->getCStrName().c_str(),
00272 firedTank->getUniqueId(),
00273 weapon->getParent()->getName());
00274 LoggerInfo info(message, time);
00275 statsLogger_->logMessage(info);
00276 }
00277
00278 void StatsLoggerFile::tankWon(Tank *tank)
00279 {
00280 createLogger();
00281 if (!statsLogger_) return;
00282
00283 time_t theTime = time(0);
00284 char *time = ctime(&theTime);
00285 char *nl = strchr(time, '\n');
00286 if (nl) *nl = '\0';
00287
00288 char message[1024];
00289 snprintf(message, 1024, "won \"%s\" [%s]",
00290 tank->getCStrName().c_str(), tank->getUniqueId());
00291 LoggerInfo info(message, time);
00292 statsLogger_->logMessage(info);
00293 }
00294
00295 void StatsLoggerFile::tankOverallWinner(Tank *tank)
00296 {
00297 createLogger();
00298 if (!statsLogger_) return;
00299
00300 time_t theTime = time(0);
00301 char *time = ctime(&theTime);
00302 char *nl = strchr(time, '\n');
00303 if (nl) *nl = '\0';
00304
00305 char message[1024];
00306 snprintf(message, 1024, "overallwinner \"%s\" [%s]",
00307 tank->getCStrName().c_str(), tank->getUniqueId());
00308 LoggerInfo info(message, time);
00309 statsLogger_->logMessage(info);
00310 }
00311
00312 void StatsLoggerFile::weaponFired(Weapon *weapon, bool deathAni)
00313 {
00314 createLogger();
00315 if (!statsLogger_) return;
00316
00317 time_t theTime = time(0);
00318 char *time = ctime(&theTime);
00319 char *nl = strchr(time, '\n');
00320 if (nl) *nl = '\0';
00321
00322 char message[1024];
00323 snprintf(message, 1024, "weaponfired \"%s\"", weapon->getParent()->getName());
00324 LoggerInfo info(message, time);
00325 statsLogger_->logMessage(info);
00326 }
00327
00328 void StatsLoggerFile::weaponKilled(Weapon *weapon, bool deathAni)
00329 {
00330 createLogger();
00331 if (!statsLogger_) return;
00332
00333 time_t theTime = time(0);
00334 char *time = ctime(&theTime);
00335 char *nl = strchr(time, '\n');
00336 if (nl) *nl = '\0';
00337
00338 char message[1024];
00339 snprintf(message, 1024, "weaponkilled \"%s\"", weapon->getParent()->getName());
00340 LoggerInfo info(message, time);
00341 statsLogger_->logMessage(info);
00342 }