Crossfire Server, Trunk
logger.cpp
Go to the documentation of this file.
1 /*
2  * Crossfire -- cooperative multi-player graphical RPG and adventure game
3  *
4  * Copyright (c) 1999-2014 Mark Wedel and the Crossfire Development Team
5  * Copyright (c) 1992 Frank Tore Johansen
6  *
7  * Crossfire is free software and comes with ABSOLUTELY NO WARRANTY. You are
8  * welcome to redistribute it under certain conditions. For details, please
9  * see COPYING and LICENSE.
10  *
11  * The authors can be reached via e-mail at <crossfire@metalforge.org>.
12  */
13 
19 #include "global.h"
20 
21 #include <stdarg.h>
22 #include <stdlib.h>
23 
24 #include "sproto.h"
25 
26 int reopen_logfile = 0; /* May be set in SIGHUP handler */
27 
31 const char *const loglevel_names[] = {
32  "[EE] ",
33  "[II] ",
34  "[DD] ",
35  "[MM] ",
36 };
37 
51 void LOG(LogLevel logLevel, const char *format, ...) {
52  char buf[20480]; /* This needs to be really really big - larger
53  * than any other buffer, since that buffer may
54  * need to be put in this one.
55  */
56 
57  char time_buf[2048];
58 
59  va_list ap;
60  va_start(ap, format);
61 
62  if (settings.log_callback) {
63  settings.log_callback(logLevel, format, ap);
64  va_end(ap);
65  return;
66  }
67 
68  buf[0] = '\0';
69  if (logLevel <= settings.debug) {
70  time_buf[0] = '\0';
71  if (settings.log_timestamp == TRUE) {
72  struct tm *time_tmp;
73  time_t now = time((time_t *)NULL);
74 
75  time_tmp = localtime(&now);
76  if (time_tmp != NULL) {
77  if (strftime(time_buf, sizeof(time_buf), settings.log_timestamp_format, time_tmp) == 0) {
78  time_buf[0] = '\0';
79  }
80  }
81  }
82 
83  vsnprintf(buf, sizeof(buf), format, ap);
84 #ifdef WIN32 /* ---win32 change log handling for win32 */
85  if (time_buf[0] != 0) {
86  fputs(time_buf, logfile);
87  fputs(" ", logfile);
88  }
89  fputs(loglevel_names[logLevel], logfile); /* wrote to file or stdout */
90  fputs(buf, logfile); /* wrote to file or stdout */
91  fflush(logfile); /* always force flushing! */
92  if (logfile != stderr) { /* if was it a logfile wrote it to screen too */
93  if (time_buf[0] != 0) {
94  fputs(time_buf, stderr);
95  fputs(" ", stderr);
96  }
97  fputs(loglevel_names[logLevel], stderr);
98  fputs(buf, stderr);
99  fflush(stderr);
100  }
101 #else /* not WIN32 */
102  if (reopen_logfile) {
103  reopen_logfile = 0;
104  if (fclose(logfile) != 0) {
105  /* stderr has been closed if -detach was used, but it's better
106  * to try to report about this anyway. */
107  perror("tried to close log file after SIGHUP in logger.c:LOG()");
108  }
109  if ((logfile = fopen(settings.logfilename, "a")) == NULL) {
110  /* There's likely to be something very wrong with the OS anyway
111  * if reopening fails. */
112  perror("tried to open log file after SIGHUP in logger.c:LOG()");
113  emergency_save(0);
114  clean_tmp_files();
115  exit(1);
116  }
117  setvbuf(logfile, NULL, _IOLBF, 0);
118  LOG(llevInfo, "logfile reopened\n");
119  }
120 
121  if (time_buf[0] != 0) {
122  fputs(time_buf, logfile);
123  fputs(" ", logfile);
124  }
125  fputs(loglevel_names[logLevel], logfile);
126  fputs(buf, logfile);
127 #endif
128  }
129  if (!exiting
131  && logLevel == llevError
132  && ++nroferrors > MAX_ERRORS) {
133  exiting = 1;
135  emergency_save(0);
136  }
137  va_end(ap);
138 }
global.h
settings
struct Settings settings
Definition: init.cpp:139
Settings::log_timestamp_format
char * log_timestamp_format
Definition: global.h:319
emergency_save
void emergency_save(int flag)
Definition: main.cpp:347
llevError
@ llevError
Definition: logger.h:11
LOG
void LOG(LogLevel logLevel, const char *format,...)
Definition: logger.cpp:51
Settings::debug
LogLevel debug
Definition: global.h:243
MAX_ERRORS
#define MAX_ERRORS
Definition: config.h:522
time
non standard information is not specified or uptime this means how long since the executable has been started A particular host may have been running a server for quite a long time
Definition: arch-handbook.txt:206
Settings::log_timestamp
int log_timestamp
Definition: global.h:318
buf
StringBuffer * buf
Definition: readable.cpp:1552
trying_emergency_save
long trying_emergency_save
Definition: init.cpp:111
nroferrors
long nroferrors
Definition: init.cpp:112
sproto.h
logfile
FILE * logfile
Definition: init.cpp:114
Settings::log_callback
logHook log_callback
Definition: global.h:244
reopen_logfile
int reopen_logfile
Definition: logger.cpp:26
Settings::logfilename
const char * logfilename
Definition: global.h:241
llevInfo
@ llevInfo
Definition: logger.h:12
clean_tmp_files
void clean_tmp_files(void)
Definition: main.cpp:351
loglevel_names
const char *const loglevel_names[]
Definition: logger.cpp:31
format
Python Guilds Quick outline Add a guild(mapmakers) this is still a problem *after dropping the token to gain access to the stove a woodfloor now appears which is Toolshed Token(found in Guild_HQ) *Note also have multiple gates in place to protect players and items from the mana explosion drop x for Jewelers room *Jewelers room works just need to determine what x is drop x for Thaumaturgy room *Thaumaturgy room works just need to determine what x is drop gold dropping the Firestar named fearless allows access to but I suspect that the drop location of the chest is not as intended because the player is in the way once you enter the chest the exit back to the basement is things such as the message et al reside on teleporters which then transport items to the map as they are when the map is already purchased items reappear in that area From my this does not cause any problems at the moment But this should be corrected fixed Major it s now possible to buy guilds Ryo Update Uploaded guild package to CVS Changes the cauldrons and the charging room I spent a while agonizing over They were natural guild enhancements but much too much value for any reasonable expense to buy them Then I thought that they should be pay access but at a greatly reduced rate SO when you buy a forge or whatever for your guild it is available on a perplayer daily rate but it will be accessable for testing and to DMs to play with Like I said lots still to do with the especially comingt up with quest items for buying things like the new workshops and stuff One of the things I would like some input on would be proposals for additional fields for either the guildhouses or guild datafiles to play with Currently the Guildhouse but there is no reason we can t have more than one measure of a guild perhaps have dues relate to Dues and use points for some other suspended or inactive or when a guild is founded inactive active Guilds have the format
Definition: README.txt:140
exit
Install Bug reporting Credits but rather whatever guild name you are using *With the current map and server there are three they and GreenGoblin *Whatever name you give the folder should but it will still use GUILD_TEMPLATE *You can change what guild it uses by editing the map files Modify Map or objects if you want to use the optional Python based Guild Storage hall The first three are on the main the next two are in the guild_hq and the final one is in hallofjoining Withe the Storage three objects are found on the main floor and the last two are in the basement It s not that but you will need a map editor You find the object that has the click edit and change the line script options(which currently is "GUILD_TEMPALTE") to the guild you wish to use. And make sure you use the same one for all of them or it won 't work. Here 's a quick HOWTO for using the map editor to make these changes edit the mainfloor map exit(x15, y29 - set to/Edit/This/Exit/Path in the template) back to the world map as well. If you are using the Storage Hall map(storage_hall)
now
Crossfire Protocol most of the time after the actual code was already omit certain important and possibly make life miserable any new developer or curious player should be able to find most of the relevant information here If inconsistencies are found or this documentation proves to be consider the latest server side protocol code in the public source code repository as the authoritative reference Introduction If you were ever curious enough to telnet or netcat to a Crossfire chances are you were sorely disappointed While the protocol may seem to use plain text at it actually uses a mix of ASCII and binary data This handbook attempts to document various aspects of the Crossfire protocol As consult the README file to find out how to get in touch with helpful people via mailing and more History the communications plan was set to be a text based system It was up to the server and client to parse these messages and determine what to do These messages were assumed to be line per message At a reasonably early stage of Eric Anderson wrote a then the data itself you could send many data and after the other end could decode these commands This works fairly but I think the creation of numerous sub packets has some performance hit the eutl was not especially well so writing a client for a different platform became more Eric left to work on other products shortly after writing his which didn t really leave anyone with a full understanding of the socket code I have decided to remove the eutl dependency At least one advantage is that having this network related code directly in the client and server makes error handling a bit easier cleaner Packet Format the outside packet method the byte size for the size information is not included here Eutl originally used bytes for the size to bytes seems it makes a least some sense The actual data is something of the nature of the commands listed below It is a text followed by possible other data The remaining data can be binary it is up to the client and server to decode what it sent The commands as described below is just the data portion of the packet If writing a new remember that you must take into account the size of the packet There is no termination of other than knowing how long it should be For now
Definition: protocol.txt:71
LogLevel
LogLevel
Definition: logger.h:10
TRUE
#define TRUE
Definition: compat.h:11
exiting
int exiting
Definition: init.cpp:115