Browse files

* alle printfs durch fprintf(stderr ersetzt

 * demo schreiben per config parameter konfigurierbar       
 * falls DAEMONIZING definiert ist, wird daemonize.h eingebunden und daemonize(argc, argv) aufgerufen.


git-svn-id: http://infon.googlecode.com/svn/trunk@96 8171fb75-e542-0410-96e4-03d5dd800671
  • Loading branch information...
1 parent e92950c commit d64509485223b66d2aa9ebcb01368ce13fab665e @dividuum committed Nov 22, 2006
Showing with 74 additions and 26 deletions.
  1. +4 −4 client.c
  2. +15 −3 config.lua
  3. +18 −5 game.c
  4. +10 −1 infond.c
  5. +14 −0 infond.lua
  6. +2 −2 listener.c
  7. +6 −6 packet.c
  8. +3 −2 player.c
  9. +2 −3 server.lua
View
8 client.c
@@ -128,8 +128,8 @@ static void client_handle_packet(packet_t *packet) {
gui_creature_from_network(packet);
break;
case PACKET_QUIT_MSG:
- printf("server wants us to disconnect: %.*s\n",
- packet->len, packet->data);
+ fprintf(stderr, "server wants us to disconnect: %.*s\n",
+ packet->len, packet->data);
client_destroy("done");
break;
case PACKET_KOTH_UPDATE:
@@ -160,7 +160,7 @@ static void client_handle_packet(packet_t *packet) {
client_handshake_from_network(packet);
break;
default:
- printf("packet->type %d unknown\n", packet->type);
+ fprintf(stderr, "packet->type %d unknown\n", packet->type);
break;
}
}
@@ -416,7 +416,7 @@ void client_init(char *source, char *demo_save_name) {
void client_destroy(const char *reason) {
assert(clientfd != -1);
- printf("datasource destroyed: %s\n", reason);
+ fprintf(stderr, "datasource destroyed: %s\n", reason);
evbuffer_free(in_buf);
evbuffer_free(out_buf);
View
18 config.lua
@@ -1,12 +1,24 @@
+-- ip and port to bind listen socket
listenaddr = "0.0.0.0"
listenport = 1234
--- Password for the 'shell' command. Disabled if empty.
+-- password for the 'shell' command. disabled if empty or missing.
debugpass = ""
+-- message displayed every 10 seconds
join_info = "this message can be changed in config.lua"
+
+-- maps to rotate
maps = {"foo", "gpn", "water", "cn"}
+
+-- rules file to use.
rules = "default"
-time_limit = nil -- Zeitlimit in Millisekunden
-score_limit= 500 -- Scorelimit
+-- filename prefix for demo files. disabled if unset.
+-- demo = "infond"
+
+-- time limit for each map
+time_limit = nil
+
+-- score limit for each map
+score_limit= 500
View
23 game.c
@@ -144,11 +144,24 @@ void game_one_round() {
player_round_start();
// Demo Aufnahme starten
- static char demoname[128];
- snprintf(demoname, sizeof(demoname), "infond-%08X.demo", (int)time(0));
- client_t *demowriter = server_start_demo_writer(demoname);
- if (!demowriter)
- fprintf(stderr, "couldn't start demo file\n");
+ client_t *demowriter = NULL;
+
+ lua_pushliteral(L, "onNewGameDemoStart");
+ lua_rawget(L, LUA_GLOBALSINDEX);
+ if (lua_pcall(L, 0, 1, 0) != 0) {
+ fprintf(stderr, "error calling onNewGameDemoStart: %s\n", lua_tostring(L, -1));
+ } else {
+ char *demoname = lua_tostring(L, -1);
+ if (demoname) {
+ demowriter = server_start_demo_writer(demoname);
+ if (demowriter) {
+ fprintf(stderr, "started recording demo %s\n", demoname);
+ } else {
+ fprintf(stderr, "couldn't start demo file %s\n", demoname);
+ }
+ }
+ }
+ lua_pop(L, 1);
while (!game_exit && !should_end_round) {
int tick = get_tick();
View
11 infond.c
@@ -23,6 +23,10 @@
#include <sys/resource.h>
#endif
+#ifdef DAEMONIZING
+#include "daemonize.h"
+#endif
+
#include <signal.h>
#include <stdlib.h>
#include <stdio.h>
@@ -65,12 +69,17 @@ int main(int argc, char *argv[]) {
L = luaL_newstate();
luaL_openlibs(L);
- luaL_dofile(L, "infond.lua");
+ if (luaL_dofile(L, "infond.lua"))
+ die("cannot read 'infond.lua'");
game_init();
server_init();
player_init();
+#ifdef DAEMONIZING
+ daemonize(argc, argv);
+#endif
+
while (!game_exit) {
game_one_round();
}
View
14 infond.lua
@@ -234,6 +234,20 @@ function server_tick()
end
-----------------------------------------------------------
+-- Game C Callbacks
+-----------------------------------------------------------
+
+function onNewGameDemoStart()
+ if type(demo) == "string" then
+ return string.format("%s-%08X.demo", demo, os.time());
+ elseif type(demo) == "function" then
+ return demo()
+ else
+ return nil
+ end
+end
+
+-----------------------------------------------------------
-- World Funktionen
-----------------------------------------------------------
View
4 listener.c
@@ -79,7 +79,7 @@ int listener_init() {
lua_rawget(L, LUA_GLOBALSINDEX);
if (!lua_isnumber(L, -1)) {
- fprintf(stdout, "listenport nicht definiert\n");
+ fprintf(stderr, "listenport not defined\n");
lua_pop(L, 1);
goto error;
}
@@ -88,7 +88,7 @@ int listener_init() {
lua_rawget(L, LUA_GLOBALSINDEX);
if (!lua_isstring(L, -1)) {
- fprintf(stdout, "listaddr nicht definiert\n");
+ fprintf(stderr, "listaddr not defined\n");
lua_pop(L, 2);
goto error;
}
View
12 packet.c
@@ -41,7 +41,7 @@ void packet_init(packet_t *packet, int type) {
int packet_read08(packet_t *packet, uint8_t *data) {
if (packet->len - packet->offset < 1) {
- printf("reading beyond end\n");
+ fprintf(stderr, "reading beyond end\n");
return 0;
}
*data = packet->data[packet->offset];
@@ -62,7 +62,7 @@ int packet_read16(packet_t *packet, uint16_t *data) {
int packet_read32(packet_t *packet, uint32_t *data) {
if (packet->len - packet->offset < 4) {
- printf("reading beyond end\n");
+ fprintf(stderr, "reading beyond end\n");
return 0;
}
*data = ntohl(*(uint32_t*)&packet->data[packet->offset]);
@@ -72,7 +72,7 @@ int packet_read32(packet_t *packet, uint32_t *data) {
int packet_readXX(packet_t *packet, void *data, int len) {
if (packet->len - packet->offset < len) {
- printf("reading beyond end\n");
+ fprintf(stderr, "reading beyond end\n");
return 0;
}
memcpy(data, &packet->data[packet->offset], len);
@@ -82,7 +82,7 @@ int packet_readXX(packet_t *packet, void *data, int len) {
int packet_write08(packet_t *packet, uint8_t data) {
if (sizeof(packet->data) - packet->offset <= 1) {
- printf("packet too full\n");
+ fprintf(stderr, "packet too full\n");
return 0;
}
*((uint8_t*)&packet->data[packet->offset]) = data;
@@ -101,7 +101,7 @@ int packet_write16(packet_t *packet, uint16_t data) {
int packet_write32(packet_t *packet, uint32_t data) {
if (sizeof(packet->data) - packet->offset <= 4) {
- printf("packet too full\n");
+ fprintf(stderr, "packet too full\n");
return 0;
}
*((uint32_t*)&packet->data[packet->offset]) = htonl(data);
@@ -111,7 +111,7 @@ int packet_write32(packet_t *packet, uint32_t data) {
int packet_writeXX(packet_t *packet, const void *data, int len) {
if (sizeof(packet->data) - packet->offset <= len) {
- printf("packet too full\n");
+ fprintf(stderr, "packet too full\n");
return 0;
}
memcpy(&packet->data[packet->offset], data, len);
View
5 player.c
@@ -74,7 +74,8 @@ void player_score(player_t *player, int scoredelta, const char *reason) {
lua_pop(L, 1);
}
- printf("stat: %10d %3d '%10s' %5d: %s\n", game_time, player_num(player), player->name, player->score, reason);
+ fprintf(stderr, "stat: %10d %3d '%10s' %5d: %s\n",
+ game_time, player_num(player), player->name, player->score, reason);
}
void player_init_events(player_t *player) {
@@ -188,7 +189,7 @@ void player_on_created(player_t *player) {
}
static int player_at_panic(lua_State *L) {
- printf("Aeiik! LUA panic. Cannot continue. Please file a bug report\n");
+ fprintf(stderr, "Aeiik! LUA panic. Cannot continue. Please file a bug report\n");
abort();
return 0; // never reached
}
View
5 server.lua
@@ -149,7 +149,7 @@ function Client:shell()
if self.authorized then
ok = true
else
- if debugpass == "" then
+ if not debugpass or debugpass == "" then
self:writeln("password must be set in config.lua")
return
end
@@ -328,13 +328,12 @@ end
function ServerMain()
scroller_add("Welcome to " .. GAME_NAME .. "!")
- scroller_add(join_info)
local info_time = game_info()
while true do
if game_info() > info_time + 10000 then
info_time = game_info()
- if join_info ~= "" then
+ if join_info and join_info ~= "" then
scroller_add(join_info)
end
end

0 comments on commit d645094

Please sign in to comment.